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); }
/** * Returns the number of items contained in the receiver. * * @return the number of items * @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 int getItemCount() { checkWidget(); long /*int*/ list = OS.gtk_container_get_children(handle); if (list == 0) return 0; int itemCount = OS.g_list_length(list); OS.g_list_free(list); return itemCount; }
void createItem(TabItem item, int index) { long /*int*/ list = OS.gtk_container_get_children(handle); int itemCount = 0; if (list != 0) { itemCount = OS.g_list_length(list); OS.g_list_free(list); } if (!(0 <= index && index <= itemCount)) error(SWT.ERROR_INVALID_RANGE); if (itemCount == items.length) { TabItem[] newItems = new TabItem[items.length + 4]; System.arraycopy(items, 0, newItems, 0, items.length); items = newItems; } long /*int*/ boxHandle = gtk_box_new(OS.GTK_ORIENTATION_HORIZONTAL, false, 0); if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES); long /*int*/ labelHandle = OS.gtk_label_new_with_mnemonic(null); if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES); long /*int*/ imageHandle = OS.gtk_image_new(); if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES); OS.gtk_container_add(boxHandle, imageHandle); OS.gtk_container_add(boxHandle, labelHandle); long /*int*/ pageHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0); if (pageHandle == 0) error(SWT.ERROR_NO_HANDLES); if (OS.GTK3) { OS.gtk_widget_override_background_color(pageHandle, OS.GTK_STATE_FLAG_NORMAL, new GdkRGBA()); long /*int*/ region = OS.gdk_region_new(); OS.gtk_widget_input_shape_combine_region(pageHandle, region); OS.gdk_region_destroy(region); } OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); OS.gtk_notebook_insert_page(handle, pageHandle, boxHandle, index); OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); OS.gtk_widget_show(boxHandle); OS.gtk_widget_show(labelHandle); OS.gtk_widget_show(pageHandle); item.state |= HANDLE; item.handle = boxHandle; item.labelHandle = labelHandle; item.imageHandle = imageHandle; item.pageHandle = pageHandle; System.arraycopy(items, index, items, index + 1, itemCount++ - index); items[index] = item; if ((state & FOREGROUND) != 0) { item.setForegroundColor(getForegroundColor()); } if ((state & FONT) != 0) { item.setFontDescription(getFontDescription()); } if (itemCount == 1) { OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); OS.gtk_notebook_set_current_page(handle, 0); OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); Event event = new Event(); event.item = items[0]; sendSelectionEvent(SWT.Selection, event, false); // the widget could be destroyed at this point } }
/** * Returns the item at the given, zero-relative index in the receiver. Throws an exception if the * index is out of range. * * @param index the index of the item to return * @return the item at the given index * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the * list minus 1 (inclusive) * </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 TabItem getItem(int index) { checkWidget(); if (!(0 <= index && index < getItemCount())) error(SWT.ERROR_INVALID_RANGE); long /*int*/ list = OS.gtk_container_get_children(handle); if (list == 0) error(SWT.ERROR_CANNOT_GET_ITEM); int itemCount = OS.g_list_length(list); OS.g_list_free(list); if (!(0 <= index && index < itemCount)) error(SWT.ERROR_CANNOT_GET_ITEM); return items[index]; }
/** * Searches the receiver's list starting at the first item (index 0) until an item is found that * is equal to the argument, and returns the index of that item. If no item is found, returns -1. * * @param item the search item * @return the index of the item * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the item is null * </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 int indexOf(TabItem item) { checkWidget(); if (item == null) error(SWT.ERROR_NULL_ARGUMENT); long /*int*/ list = OS.gtk_container_get_children(handle); if (list == 0) return -1; int count = OS.g_list_length(list); OS.g_list_free(list); for (int i = 0; i < count; i++) { if (items[i] == item) return i; } return -1; }
void reskinChildren(int flags) { if (items != null) { long /*int*/ list = OS.gtk_container_get_children(handle); if (list != 0) { int count = OS.g_list_length(list); OS.g_list_free(list); for (int i = 0; i < count; i++) { TabItem item = items[i]; if (item != null) item.reskin(flags); } } } super.reskinChildren(flags); }
/** * Returns the tab item at the given point in the receiver or null if no such item exists. The * point is in the coordinate system of the receiver. * * @param point the point used to locate the item * @return the tab item at the given point, or null if the point is not in a tab item * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the point is null * </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.4 */ public TabItem getItem(Point point) { checkWidget(); if (point == null) error(SWT.ERROR_NULL_ARGUMENT); long /*int*/ list = OS.gtk_container_get_children(handle); if (list == 0) return null; int itemCount = OS.g_list_length(list); OS.g_list_free(list); for (int i = 0; i < itemCount; i++) { TabItem item = items[i]; Rectangle rect = item.getBounds(); if (rect.contains(point)) return item; } return null; }
ToolItem[] _getItems() { long /*int*/ list = OS.gtk_container_get_children(handle); if (list == 0) return new ToolItem[0]; int count = OS.g_list_length(list); ToolItem[] items = new ToolItem[count]; long /*int*/ originalList = list; int index = 0; for (int i = 0; i < count; i++) { long /*int*/ data = OS.g_list_data(list); Widget widget = display.getWidget(data); if (widget != null) items[index++] = (ToolItem) widget; list = OS.g_list_next(list); } OS.g_list_free(originalList); if (index != items.length) { ToolItem[] newItems = new ToolItem[index]; System.arraycopy(items, 0, newItems, 0, index); items = newItems; } return items; }
Image getDragSourceImage(DragSourceEvent event) { if (dragSourceImage != null) dragSourceImage.dispose(); dragSourceImage = null; Table table = (Table) control; if (OS.GTK_VERSION < OS.VERSION(2, 2, 0)) return null; // TEMPORARY CODE if (table.isListening(SWT.EraseItem) || table.isListening(SWT.PaintItem)) return null; /* * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults * in versions smaller than 2.2.4 if the model is NULL. The fix is * to give a valid pointer instead. */ long /*int*/ handle = table.handle; long /*int*/ selection = OS.gtk_tree_view_get_selection(handle); long /*int*/[] model = OS.GTK_VERSION < OS.VERSION(2, 2, 4) ? new long /*int*/[1] : null; long /*int*/ list = OS.gtk_tree_selection_get_selected_rows(selection, model); if (list == 0) return null; int count = Math.min(10, OS.g_list_length(list)); Display display = table.getDisplay(); if (count == 1) { long /*int*/ path = OS.g_list_nth_data(list, 0); long /*int*/ pixmap = OS.gtk_tree_view_create_row_drag_icon(handle, path); dragSourceImage = Image.gtk_new(display, SWT.ICON, pixmap, 0); } else { int width = 0, height = 0; int[] w = new int[1], h = new int[1]; int[] yy = new int[count], hh = new int[count]; long /*int*/[] pixmaps = new long /*int*/[count]; GdkRectangle rect = new GdkRectangle(); for (int i = 0; i < count; i++) { long /*int*/ path = OS.g_list_nth_data(list, i); OS.gtk_tree_view_get_cell_area(handle, path, 0, rect); pixmaps[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path); OS.gdk_drawable_get_size(pixmaps[i], w, h); width = Math.max(width, w[0]); height = rect.y + h[0] - yy[0]; yy[i] = rect.y; hh[i] = h[0]; } long /*int*/ source = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1); long /*int*/ gcSource = OS.gdk_gc_new(source); long /*int*/ mask = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, 1); long /*int*/ gcMask = OS.gdk_gc_new(mask); GdkColor color = new GdkColor(); color.pixel = 0; OS.gdk_gc_set_foreground(gcMask, color); OS.gdk_draw_rectangle(mask, gcMask, 1, 0, 0, width, height); color.pixel = 1; OS.gdk_gc_set_foreground(gcMask, color); for (int i = 0; i < count; i++) { OS.gdk_draw_drawable(source, gcSource, pixmaps[i], 0, 0, 0, yy[i] - yy[0], -1, -1); OS.gdk_draw_rectangle(mask, gcMask, 1, 0, yy[i] - yy[0], width, hh[i]); OS.g_object_unref(pixmaps[i]); } OS.g_object_unref(gcSource); OS.g_object_unref(gcMask); dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask); } OS.g_list_free(list); return dragSourceImage; }