static void drawTorus(float r, float R, int nsides, int rings) { float ringDelta = 2.0f * (float) Math.PI / rings; float sideDelta = 2.0f * (float) Math.PI / nsides; float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; for (int i = rings - 1; i >= 0; i--) { float theta1 = theta + ringDelta; float cosTheta1 = (float) Math.cos(theta1); float sinTheta1 = (float) Math.sin(theta1); GL11.glBegin(GL11.GL_QUAD_STRIP); float phi = 0.0f; for (int j = nsides; j >= 0; j--) { phi += sideDelta; float cosPhi = (float) Math.cos(phi); float sinPhi = (float) Math.sin(phi); float dist = R + r * cosPhi; GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); } GL11.glEnd(); theta = theta1; cosTheta = cosTheta1; sinTheta = sinTheta1; } }
Point minimumSize(int wHint, int hHint, boolean flushCache) { Control[] children = _getChildren(); int width = 0, height = 0; for (int i = 0; i < children.length; i++) { Control child = children[i]; int index = 0; int count = 0; long /*int*/ list = OS.gtk_container_get_children(handle); if (list != 0) { count = OS.g_list_length(list); OS.g_list_free(list); } while (index < count) { if (items[index].control == child) break; index++; } if (index == count) { Rectangle rect = child.getBounds(); width = Math.max(width, rect.x + rect.width); height = Math.max(height, rect.y + rect.height); } else { Point size = child.computeSize(wHint, hHint, flushCache); width = Math.max(width, size.x); height = Math.max(height, size.y); } } return new Point(width, height); }
void updateBar(int selection, int minimum, int maximum, int thumb) { NSScroller widget = (NSScroller) view; selection = Math.max(minimum, Math.min(maximum - thumb, selection)); float fraction = minimum == maximum ? 1 : (float) (selection - minimum) / (maximum - thumb - minimum); float knob = minimum == maximum ? 1 : (float) (thumb - minimum) / (maximum - minimum); widget.setFloatValue(fraction, knob); }
/** * Set the label's margins, in pixels. * * @param leftMargin the left margin. * @param topMargin the top margin. * @param rightMargin the right margin. * @param bottomMargin the bottom margin. * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> * * @since 3.6 */ public void setMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) { checkWidget(); this.leftMargin = Math.max(0, leftMargin); this.topMargin = Math.max(0, topMargin); this.rightMargin = Math.max(0, rightMargin); this.bottomMargin = Math.max(0, bottomMargin); redraw(); }
private void setHoverLocation( org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) { org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds(); org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds(); shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0); shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0); shell.setBounds(shellBounds); }
void setBounds(int x, int y, int width, int height) { /* * Feature in Motif. Motif will not allow a window * to have a zero width or zero height. The fix is * to ensure these values are never zero. */ int newWidth = Math.max(width, 1), newHeight = Math.max(height, 1); OS.XtConfigureWidget(handle, x, y, newWidth, newHeight, 0); }
/** * Sets the minimum value. If this value is negative or greater than or equal to the maximum, the * value is ignored. If necessary, first the thumb and then the selection are adjusted to fit * within the new range. * * @param value the new minimum * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setMinimum(int value) { checkWidget(); if (value < 0) return; if (value >= maximum) return; if (maximum - value < thumb) { thumb = maximum - value; } int selection = Math.min(maximum - thumb, Math.max(getSelection(), value)); this.minimum = value; updateBar(selection, value, maximum, thumb); }
/** * Sets the maximum. If this value is negative or less than or equal to the minimum, the value is * ignored. If necessary, first the thumb and then the selection are adjusted to fit within the * new range. * * @param value the new maximum, which must be greater than the current minimum * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setMaximum(int value) { checkWidget(); if (value < 0) return; if (value <= minimum) return; if (value - minimum < thumb) { thumb = value - minimum; } int selection = Math.max(minimum, Math.min(getSelection(), value - thumb)); this.maximum = value; updateBar(selection, minimum, value, thumb); }
int XPointerMotion(int w, int client_data, int call_data, int continue_to_dispatch) { int result = super.XPointerMotion(w, client_data, call_data, continue_to_dispatch); if (result != 0) return result; XMotionEvent xEvent = new XMotionEvent(); OS.memmove(xEvent, call_data, XMotionEvent.sizeof); if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result; short[] x_root = new short[1], y_root = new short[1]; OS.XtTranslateCoords(handle, (short) 0, (short) 0, x_root, y_root); int eventX = xEvent.x_root - x_root[0], eventY = xEvent.y_root - y_root[0]; int[] argList1 = { OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0 }; OS.XtGetValues(handle, argList1, argList1.length / 2); int border = argList1[9], x = ((short) argList1[1]) - border, y = ((short) argList1[3]) - border; int width = argList1[5] + (border * 2), height = argList1[7] + (border * 2); int[] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; OS.XtGetValues(parent.handle, argList2, argList2.length / 2); int parentBorder = argList2[5]; int parentWidth = argList2[1] + (parentBorder * 2); int parentHeight = argList2[3] + (parentBorder * 2); int newX = lastX, newY = lastY; if ((style & SWT.VERTICAL) != 0) { newX = Math.min(Math.max(0, eventX + x - startX - parentBorder), parentWidth - width); } else { newY = Math.min(Math.max(0, eventY + y - startY - parentBorder), parentHeight - height); } if (newX == lastX && newY == lastY) return result; drawBand(lastX, lastY, width, height); Event event = new Event(); event.time = xEvent.time; event.x = newX; event.y = newY; event.width = width; event.height = height; if ((style & SWT.SMOOTH) == 0) { event.detail = SWT.DRAG; } sendEvent(SWT.Selection, event); if (isDisposed()) return result; if (event.doit) { lastX = event.x; lastY = event.y; } parent.update(true); drawBand(lastX, lastY, width, height); if ((style & SWT.SMOOTH) != 0) { setBounds(lastX, lastY, width, height); // widget could be disposed at this point } return result; }
public void show(int effect, int x, int y) { effect = checkEffect(effect); int handle = table.handle; Point coordinates = new Point(x, y); coordinates = table.toControl(coordinates); LVHITTESTINFO pinfo = new LVHITTESTINFO(); pinfo.x = coordinates.x; pinfo.y = coordinates.y; OS.SendMessage(handle, OS.LVM_HITTEST, 0, pinfo); if ((effect & DND.FEEDBACK_SCROLL) == 0) { scrollBeginTime = 0; scrollIndex = -1; } else { if (pinfo.iItem != -1 && scrollIndex == pinfo.iItem && scrollBeginTime != 0) { if (System.currentTimeMillis() >= scrollBeginTime) { int top = Math.max(0, OS.SendMessage(handle, OS.LVM_GETTOPINDEX, 0, 0)); int count = OS.SendMessage(handle, OS.LVM_GETITEMCOUNT, 0, 0); int index = (scrollIndex - 1 < top) ? Math.max(0, scrollIndex - 1) : Math.min(count - 1, scrollIndex + 1); OS.SendMessage(handle, OS.LVM_ENSUREVISIBLE, index, 0); scrollBeginTime = 0; scrollIndex = -1; } } else { scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; scrollIndex = pinfo.iItem; } } LVITEM lvItem = new LVITEM(); lvItem.stateMask = OS.LVIS_DROPHILITED; OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem); if (pinfo.iItem != -1 && (effect & DND.FEEDBACK_SELECT) != 0) { lvItem.state = OS.LVIS_DROPHILITED; OS.SendMessage(handle, OS.LVM_SETITEMSTATE, pinfo.iItem, lvItem); } // Insert mark only supported on Windows XP with manifest // if (OS.COMCTL32_MAJOR >= 6) { // if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0 || (effect & DND.FEEDBACK_INSERT_AFTER) != 0) // { // LVINSERTMARK lvinsertmark = new LVINSERTMARK(); // lvinsertmark.cbSize = LVINSERTMARK.sizeof; // lvinsertmark.dwFlags = (effect & DND.FEEDBACK_INSERT_BEFORE) != 0 ? 0 : OS.LVIM_AFTER; // lvinsertmark.iItem = pinfo.iItem == -1 ? 0 : pinfo.iItem; // int hItem = pinfo.iItem; // OS.SendMessage (handle, OS.LVM_SETINSERTMARK, 0, lvinsertmark); // } else { // OS.SendMessage (handle, OS.LVM_SETINSERTMARK, 0, 0); // } // } return; }
public Point computeSize(int wHint, int hHint, boolean changed) { checkWidget(); Point size = super.computeSize(wHint, hHint, changed); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; boolean scrollable = OS.gtk_notebook_get_scrollable(handle); OS.gtk_notebook_set_scrollable(handle, false); Point notebookSize = computeNativeSize(handle, wHint, hHint, changed); OS.gtk_notebook_set_scrollable(handle, scrollable); size.x = Math.max(notebookSize.x, size.x); size.y = Math.max(notebookSize.y, size.y); return size; }
/** * Sets the width of the receiver. * * @param width the new width * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setWidth(int width) { checkWidget(); if (width < 0) return; // TODO how to differentiate 0 and 1 cases? width = Math.max(0, width - Tree.CELL_GAP); nsColumn.setWidth(width); }
/** * Sets the font that the receiver will use to paint textual information for the specified cell in * this item to the font specified by the argument, or to the default font for that kind of * control if the argument is null. * * @param index the column index * @param font the new font (or null) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> * * @since 3.0 */ public void setFont(int index, Font font) { checkWidget(); if (font != null && font.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } int count = Math.max(1, parent.getColumnCount()); if (0 > index || index > count - 1) return; if (cellFont == null) { if (font == null) return; cellFont = new Font[count]; } Font oldFont = cellFont[index]; if (oldFont == font) return; cellFont[index] = font; if (oldFont != null && oldFont.equals(font)) return; int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex; int /*long*/ fontHandle = font != null ? font.handle : 0; OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -1); /* * Bug in GTK. When using fixed-height-mode, * row changes do not cause the row to be repainted. The fix is to * invalidate the row when it is cleared. */ if ((parent.style & SWT.VIRTUAL) != 0) { if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) { redraw(); } } cached = true; if (font != null) { boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns[index].customDraw; if (!customDraw) { if ((parent.style & SWT.VIRTUAL) == 0) { int /*long*/ parentHandle = parent.handle; int /*long*/ column = 0; if (parent.columnCount > 0) { column = parent.columns[index].handle; } else { column = OS.gtk_tree_view_get_column(parentHandle, index); } if (column == 0) return; int /*long*/ textRenderer = parent.getTextRenderer(column); int /*long*/ imageRenderer = parent.getPixbufRenderer(column); OS.gtk_tree_view_column_set_cell_data_func( column, textRenderer, display.cellDataProc, parentHandle, 0); OS.gtk_tree_view_column_set_cell_data_func( column, imageRenderer, display.cellDataProc, parentHandle, 0); } if (parent.columnCount == 0) { parent.firstCustomDraw = true; } else { parent.columns[index].customDraw = true; } } } }
/** * Sets the size of the receiver's thumb relative to the difference between its maximum and * minimum values. This new value will be ignored if it is less than one, and will be clamped if * it exceeds the receiver's current range. * * @param value the new thumb value, which must be at least one and not larger than the size of * the current range * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setThumb(int value) { checkWidget(); if (value < 1) return; value = Math.min(value, maximum - minimum); this.thumb = value; updateBar(getSelection(), minimum, maximum, value); }
/** * Returns the font that the receiver will use to paint textual information for the specified cell * in this item. * * @param index the column index * @return the receiver's font * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> * * @since 3.0 */ public Font getFont(int index) { checkWidget(); if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED); int count = Math.max(1, parent.columnCount); if (0 > index || index > count - 1) return getFont(); if (cellFont == null || cellFont[index] == null) return getFont(); return cellFont[index]; }
/** * Sets the receiver's image at a column. * * @param index the column index * @param image the new image * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setImage(int index, Image image) { checkWidget(); if (image != null && image.isDisposed()) { error(SWT.ERROR_INVALID_ARGUMENT); } if (image != null && image.type == SWT.ICON) { if (image.equals(_getImage(index))) return; } int count = Math.max(1, parent.getColumnCount()); if (0 > index || index > count - 1) return; int /*long*/ pixbuf = 0; if (image != null) { ImageList imageList = parent.imageList; if (imageList == null) imageList = parent.imageList = new ImageList(); int imageIndex = imageList.indexOf(image); if (imageIndex == -1) imageIndex = imageList.add(image); pixbuf = imageList.getPixbuf(imageIndex); } int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex; OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -1); /* * Bug in GTK. When using fixed-height-mode, * row changes do not cause the row to be repainted. The fix is to * invalidate the row when it is cleared. */ if ((parent.style & SWT.VIRTUAL) != 0) { if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) { redraw(); } } /* * Bug in GTK. When in fixed height mode, GTK does not recalculate the cell renderer width * when the image is changed in the model. The fix is to force it to recalculate the width if * more space is required. */ if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) { if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2)) { if (image != null) { int /*long*/ parentHandle = parent.handle; int /*long*/ column = OS.gtk_tree_view_get_column(parentHandle, index); int[] w = new int[1]; int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column); OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, null, w); if (w[0] < image.getBounds().width) { /* * There is no direct way to clear the cell renderer width so we * are relying on the fact that it is done as part of modifying * the style. */ int /*long*/ style = OS.gtk_widget_get_modifier_style(parentHandle); parent.modifyStyle(parentHandle, style); } } } } cached = true; }
void setBounds(int x, int y, int width, int height, boolean move, boolean size) { redraw(); int headerHeight = parent.getBandHeight(); if (move) { if (imageHeight > headerHeight) { y += (imageHeight - headerHeight); } this.x = x; this.y = y; redraw(); } if (size) { this.width = width; this.height = height; redraw(); } if (control != null && !control.isDisposed()) { if (move) control.setLocation(x + BORDER, y + headerHeight); if (size) control.setSize(Math.max(0, width - 2 * BORDER), Math.max(0, height - BORDER)); } }
public Color[] getCellForegrounds() { int columnCount = Math.max(1, getParent().getColumnCount()); Color[] result = new Color[columnCount]; if (data != null) { for (int i = 0; i < data.length; i++) { if (data[i] != null) { result[i] = data[i].foreground; } } } return result; }
public Font[] getCellFonts() { int columnCount = Math.max(1, getParent().getColumnCount()); Font[] result = new Font[columnCount]; if (data != null) { for (int i = 0; i < data.length; i++) { if (data[i] != null) { result[i] = data[i].font; } } } return result; }
Color _getForeground(int index) { int count = Math.max(1, parent.columnCount); if (0 > index || index > count - 1) return _getForeground(); int /*long*/[] ptr = new int /*long*/[1]; int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex; OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, ptr, -1); if (ptr[0] == 0) return _getForeground(); GdkColor gdkColor = new GdkColor(); OS.memmove(gdkColor, ptr[0], GdkColor.sizeof); return Color.gtk_new(display, gdkColor); }
/** Compute the minimum size. */ private Point getTotalSize(Image image, String text) { Point size = new Point(0, 0); if (image != null) { Rectangle r = image.getBounds(); size.x += r.width; size.y += r.height; } GC gc = new GC(this); if (text != null && text.length() > 0) { Point e = gc.textExtent(text, DRAW_FLAGS); size.x += e.x; size.y = Math.max(size.y, e.y); if (image != null) size.x += GAP; } else { size.y = Math.max(size.y, gc.getFontMetrics().getHeight()); } gc.dispose(); return size; }
Image _getImage(int index) { int count = Math.max(1, parent.getColumnCount()); if (0 > index || index > count - 1) return null; int /*long*/[] ptr = new int /*long*/[1]; int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex; OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, ptr, -1); if (ptr[0] == 0) return null; ImageList imageList = parent.imageList; int imageIndex = imageList.indexOf(ptr[0]); if (imageIndex == -1) return null; return imageList.get(imageIndex); }
/** * Returns a rectangle describing the receiver's size and location relative to its parent. * * @return the receiver's bounding rectangle * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public Rectangle getBounds() { checkWidget(); parent.forceResize(); long /*int*/ topHandle = topHandle(); int x, y, width, height; x = OS.GTK_WIDGET_X(topHandle); y = OS.GTK_WIDGET_Y(topHandle); width = OS.GTK_WIDGET_WIDTH(topHandle); height = OS.GTK_WIDGET_HEIGHT(topHandle); if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth() - width - x; if ((style & SWT.SEPARATOR) != 0 && control != null) height = Math.max(height, 23); return new Rectangle(x, y, width, height); }
static int[] circle(int r, int offsetX, int offsetY) { int[] polygon = new int[8 * r + 4]; // x^2 + y^2 = r^2 for (int i = 0; i < 2 * r + 1; i++) { int x = i - r; int y = (int) Math.sqrt(r * r - x * x); polygon[2 * i] = offsetX + x; polygon[2 * i + 1] = offsetY + y; polygon[8 * r - 2 * i - 2] = offsetX + x; polygon[8 * r - 2 * i - 1] = offsetY - y; } return polygon; }
/** * Sets the receiver's selection, minimum value, maximum value, thumb, increment and page * increment all at once. * * <p>Note: This is similar to setting the values individually using the appropriate methods, but * may be implemented in a more efficient fashion on some platforms. * * @param selection the new selection value * @param minimum the new minimum value * @param maximum the new maximum value * @param thumb the new thumb value * @param increment the new increment value * @param pageIncrement the new pageIncrement value * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setValues( int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { checkWidget(); if (minimum < 0) return; if (maximum < 0) return; if (thumb < 1) return; if (increment < 1) return; if (pageIncrement < 1) return; thumb = Math.min(thumb, maximum - minimum); this.increment = increment; this.pageIncrement = pageIncrement; updateBar(selection, minimum, maximum, thumb); }
/** * Returns a rectangle describing the receiver's size and location relative to its parent. * * @return the receiver's bounding rectangle * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> * * @since 1.3 */ public Rectangle getBounds() { checkWidget(); Rectangle result = new Rectangle(0, 0, 0, 0); int index = parent.indexOf(this); if (index != -1) { int selectionIndex = parent.getSelectionIndex(); boolean selected = index == selectionIndex; Rectangle padding = parent.getItemPadding(selected); String text = getText(); if (text != null) { Point extent = Graphics.stringExtent(parent.getFont(), text); result.width = extent.x; result.height = extent.y; } Image image = getImage(); if (image != null) { Rectangle imageSize = image.getBounds(); result.width += imageSize.width + IMAGE_TEXT_SPACING; result.height = Math.max(result.height, imageSize.height); } result.width += 2 * ITEM_BORDER + padding.width; result.height += ITEM_BORDER + padding.height; if (selected) { result.height += SELECTED_ITEM_BORDER; } if (selectionIndex != -1) { if (index + 1 == selectionIndex || index - 1 == selectionIndex) { result.width -= ITEM_BORDER; } } if (isBarTop()) { if (index != selectionIndex) { result.y += SELECTED_ITEM_BORDER; } } else { result.y = parent.getBounds().height - 2 * parent.getBorderWidth() - result.height; if (index != selectionIndex) { result.y -= SELECTED_ITEM_BORDER; } } if (index > 0) { TabItem leftItem = parent.getItem(index - 1); Rectangle leftItemBounds = leftItem.getBounds(); result.x = leftItemBounds.x + leftItemBounds.width + TABS_SPACING; if (index == selectionIndex || index - 1 == selectionIndex) { result.x -= TABS_SPACING; } } } return result; }
String _getText(int index) { int count = Math.max(1, parent.getColumnCount()); if (0 > index || index > count - 1) return ""; int /*long*/[] ptr = new int /*long*/[1]; int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex; OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, ptr, -1); if (ptr[0] == 0) return ""; int length = OS.strlen(ptr[0]); byte[] buffer = new byte[length]; OS.memmove(buffer, ptr[0], length); OS.g_free(ptr[0]); return new String(Converter.mbcsToWcs(null, buffer)); }
/** * Sets the font that the receiver will use to paint textual information for the specified cell in * this item to the font specified by the argument, or to the default font for that kind of * control if the argument is null. * * @param index the column index * @param font the new font (or null) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setFont(final int index, final Font font) { checkWidget(); if (font != null && font.isDisposed()) { error(SWT.ERROR_INVALID_ARGUMENT); } int count = Math.max(1, parent.getColumnCount()); if (index >= 0 && index < count) { ensureData(index, count); if (!equals(font, data[index].font)) { data[index].font = font; markCached(); parent.redraw(); } } }
/** * Sets the foreground color at the given column index in the receiver to the color specified by * the argument, or to the default system color for the item if the argument is null. * * @param index the column index * @param color the new color (or null) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setForeground(final int index, final Color color) { checkWidget(); if (color != null && color.isDisposed()) { error(SWT.ERROR_INVALID_ARGUMENT); } int count = Math.max(1, parent.getColumnCount()); if (index >= 0 && index < count) { ensureData(index, count); if (!equals(data[index].foreground, color)) { data[index].foreground = color; markCached(); parent.redraw(); } } }
/** * Causes the receiver to be resized to its preferred size. For a composite, this involves * computing the preferred size from its layout, if there is one. * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void pack() { checkWidget(); int width = 0; /* compute header width */ NSTableHeaderCell headerCell = nsColumn.headerCell(); NSSize size = headerCell.cellSize(); width += Math.ceil(size.width); if (image != null) { NSSize imageSize = image.handle.size(); width += Math.ceil(imageSize.width) + MARGIN; } if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) { NSRect sortRect = headerCell.sortIndicatorRectForBounds(new NSRect()); width += Math.ceil(sortRect.width + 2 * MARGIN); } /* compute item widths down column */ GC gc = new GC(parent); width = Math.max(width, parent.calculateWidth(parent.items, parent.indexOf(this), gc, true)); gc.dispose(); setWidth(width); }