void redraw() { if ((OS.GTK_WIDGET_FLAGS(parent.handle) & OS.GTK_REALIZED) != 0) { int /*long*/ parentHandle = parent.handle; int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle); GdkRectangle rect = new GdkRectangle(); OS.gtk_tree_view_get_cell_area(parentHandle, path, 0, rect); OS.gtk_tree_path_free(path); int /*long*/ window = OS.gtk_tree_view_get_bin_window(parentHandle); rect.x = 0; int[] w = new int[1], h = new int[1]; OS.gdk_drawable_get_size(window, w, h); rect.width = w[0]; OS.gdk_window_invalidate_rect(window, rect, false); } }
/** * Returns a rectangle describing the size and location relative to its parent of an image at a * column in the table. An empty rectangle is returned if index exceeds the index of the table's * last column. * * @param index the index that specifies the column * @return the receiver's bounding image 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 getImageBounds(int index) { checkWidget(); if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED); int /*long*/ parentHandle = parent.handle; int /*long*/ column = 0; if (index >= 0 && index < parent.columnCount) { column = parent.columns[index].handle; } else { column = OS.gtk_tree_view_get_column(parentHandle, index); } if (column == 0) return new Rectangle(0, 0, 0, 0); int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column); if (pixbufRenderer == 0) return new Rectangle(0, 0, 0, 0); GdkRectangle rect = new GdkRectangle(); int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle); OS.gtk_widget_realize(parentHandle); OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect); OS.gtk_tree_path_free(path); if ((parent.getStyle() & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth() - rect.width - rect.x; /* * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image, * not the width of the area in which the image is drawn. * New API was added in GTK 2.1.3 for determining the full width of the renderer area. * For earlier versions of GTK, the result is only correct if all rows have images of the same * width. */ if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) { int[] x = new int[1], w = new int[1]; OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, x, w); rect.x += x[0]; rect.width = w[0]; } else { int[] w = new int[1]; OS.gtk_tree_view_column_cell_set_cell_data(column, parent.modelHandle, handle, false, false); OS.gtk_cell_renderer_get_size(pixbufRenderer, parentHandle, null, null, null, w, null); rect.width = w[0]; } int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width : 0; return new Rectangle(rect.x, rect.y, width, rect.height + 1); }
/** * Returns a rectangle describing the receiver's size and location relative to its parent at a * column in the table. * * @param index the index that specifies the column * @return the receiver's bounding column 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(int index) { checkWidget(); if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED); int /*long*/ parentHandle = parent.handle; int /*long*/ column = 0; if (index >= 0 && index < parent.columnCount) { column = parent.columns[index].handle; } else { column = OS.gtk_tree_view_get_column(parentHandle, index); } if (column == 0) return new Rectangle(0, 0, 0, 0); int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle); OS.gtk_widget_realize(parentHandle); GdkRectangle rect = new GdkRectangle(); OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect); OS.gtk_tree_path_free(path); if ((parent.getStyle() & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth() - rect.width - rect.x; if (index == 0 && (parent.style & SWT.CHECK) != 0) { if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) { int[] x = new int[1], w = new int[1]; OS.gtk_tree_view_column_cell_get_position(column, parent.checkRenderer, x, w); rect.x += x[0] + w[0]; rect.width -= x[0] + w[0]; } else { int[] w = new int[1]; OS.gtk_cell_renderer_get_size( parent.checkRenderer, parentHandle, null, null, null, w, null); int[] buffer = new int[1]; OS.gtk_widget_style_get(parentHandle, OS.horizontal_separator, buffer, 0); rect.x += w[0] + buffer[0]; rect.width -= w[0] + buffer[0]; } } int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0; return new Rectangle(rect.x, rect.y, width, rect.height + 1); }
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; }
/** * Returns a rectangle describing the size and location relative to its parent of the text at a * column in the table. An empty rectangle is returned if index exceeds the index of the table's * last column. * * @param index the index that specifies the column * @return the receiver's bounding text 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 3.3 */ public Rectangle getTextBounds(int index) { checkWidget(); if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED); int count = Math.max(1, parent.getColumnCount()); if (0 > index || index > count - 1) return new Rectangle(0, 0, 0, 0); // TODO fully test on early and later versions of GTK // shifted a bit too far right on later versions of GTK - however, old Tree also had this // problem int /*long*/ parentHandle = parent.handle; int /*long*/ column = 0; if (index >= 0 && index < parent.columnCount) { column = parent.columns[index].handle; } else { column = OS.gtk_tree_view_get_column(parentHandle, index); } if (column == 0) return new Rectangle(0, 0, 0, 0); int /*long*/ textRenderer = parent.getTextRenderer(column); int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column); if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle(0, 0, 0, 0); int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle); OS.gtk_widget_realize(parentHandle); boolean isExpander = OS.gtk_tree_model_iter_n_children(parent.modelHandle, handle) > 0; boolean isExpanded = OS.gtk_tree_view_row_expanded(parentHandle, path); OS.gtk_tree_view_column_cell_set_cell_data( column, parent.modelHandle, handle, isExpander, isExpanded); GdkRectangle rect = new GdkRectangle(); OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect); OS.gtk_tree_path_free(path); if ((parent.getStyle() & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth() - rect.width - rect.x; int right = rect.x + rect.width; int[] x = new int[1], w = new int[1]; parent.ignoreSize = true; OS.gtk_cell_renderer_get_size(textRenderer, parentHandle, null, null, null, w, null); parent.ignoreSize = false; int[] buffer = new int[1]; if (OS.gtk_tree_view_get_expander_column(parentHandle) == column) { OS.gtk_widget_style_get(parentHandle, OS.expander_size, buffer, 0); rect.x += buffer[0] + TreeItem.EXPANDER_EXTRA_PADDING; } OS.gtk_widget_style_get(parentHandle, OS.horizontal_separator, buffer, 0); int horizontalSeparator = buffer[0]; rect.x += horizontalSeparator; if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) { OS.gtk_tree_view_column_cell_get_position(column, textRenderer, x, null); rect.x += x[0]; } else { if ((parent.style & SWT.CHECK) != 0) { OS.gtk_cell_renderer_get_size( parent.checkRenderer, parentHandle, null, null, null, w, null); rect.x += w[0] + horizontalSeparator; } OS.gtk_cell_renderer_get_size(pixbufRenderer, parentHandle, null, null, null, w, null); rect.x += w[0] + horizontalSeparator; } if (parent.columnCount > 0) { if (rect.x + rect.width > right) { rect.width = Math.max(0, right - rect.x); } } int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0; return new Rectangle(rect.x, rect.y, width, rect.height + 1); }