public void setImage(Image image) { checkWidget(); if ((style & SWT.SEPARATOR) != 0) return; if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); super.setImage(image); updateImages(getEnabled() && parent.getEnabled()); }
/** * 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; }
public void setImage(Image image) { super.setImage(image); if (imageList != null) imageList.dispose(); imageList = null; if (image != null) { if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); imageList = new ImageList(); int imageIndex = imageList.add(image); long /*int*/ pixbuf = imageList.getPixbuf(imageIndex); OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf); if (text.length() == 0) OS.gtk_widget_hide(labelHandle); OS.gtk_widget_show(imageHandle); } else { OS.gtk_image_set_from_pixbuf(imageHandle, 0); OS.gtk_widget_show(labelHandle); OS.gtk_widget_hide(imageHandle); } }