/** * Sets the checked state of the checkbox for this item. This state change only applies if the * Table was created with the SWT.CHECK style. * * @param checked the new checked state of the checkbox * @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 setChecked(boolean checked) { checkWidget(); if ((parent.style & SWT.CHECK) == 0) return; if (_getChecked() == checked) return; OS.gtk_list_store_set(parent.modelHandle, handle, Table.CHECKED_COLUMN, checked, -1); /* * GTK+'s "inconsistent" state does not match SWT's concept of grayed. To * show checked+grayed differently from unchecked+grayed, we must toggle the * grayed state on check and uncheck. */ OS.gtk_list_store_set( parent.modelHandle, handle, Table.GRAYED_COLUMN, !checked ? false : grayed, -1); cached = true; }
/** * 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 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; }
/** * Sets the grayed state of the checkbox for this item. This state change only applies if the * Table was created with the SWT.CHECK style. * * @param grayed the new grayed state of the checkbox; * @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 setGrayed(boolean grayed) { checkWidget(); if ((parent.style & SWT.CHECK) == 0) return; if (this.grayed == grayed) return; this.grayed = grayed; /* * GTK+'s "inconsistent" state does not match SWT's concept of grayed. * Render checked+grayed as "inconsistent", unchecked+grayed as blank. */ int /*long*/[] ptr = new int /*long*/[1]; OS.gtk_tree_model_get(parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1); OS.gtk_list_store_set( parent.modelHandle, handle, Table.GRAYED_COLUMN, ptr[0] == 0 ? false : grayed, -1); cached = true; }
/** * Sets the receiver's background color to the color specified by the argument, or to the default * system color for the item if the argument is null. * * @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> * * @since 2.0 */ public void setBackground(Color color) { checkWidget(); if (color != null && color.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } if (_getBackground().equals(color)) return; GdkColor gdkColor = color != null ? color.handle : null; OS.gtk_list_store_set(parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor, -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; }
void clear() { if (parent.currentItem == this) return; if (cached || (parent.style & SWT.VIRTUAL) == 0) { int columnCount = OS.gtk_tree_model_get_n_columns(parent.modelHandle); for (int i = 0; i < columnCount; i++) { OS.gtk_list_store_set(parent.modelHandle, handle, i, 0, -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 = false; font = null; cellFont = null; }
/** * Sets the receiver's text at a column * * @param index the column index * @param string the new text * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the text 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 void setText(int index, String string) { checkWidget(); if (string == null) error(SWT.ERROR_NULL_ARGUMENT); if (_getText(index).equals(string)) return; int count = Math.max(1, parent.getColumnCount()); if (0 > index || index > count - 1) return; byte[] buffer = Converter.wcsToMbcs(null, string, true); int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex; OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, buffer, -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; }
/** * Sets the font that the receiver will use to paint textual information for 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 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(Font font) { checkWidget(); if (font != null && font.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } Font oldFont = this.font; if (oldFont == font) return; this.font = font; if (oldFont != null && oldFont.equals(font)) return; int /*long*/ fontHandle = font != null ? font.handle : 0; OS.gtk_list_store_set(parent.modelHandle, handle, Table.FONT_COLUMN, 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; }