diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java | 544 |
1 files changed, 272 insertions, 272 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java index 862665c731..226329cb51 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java @@ -1,35 +1,35 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class TreeItem extends Item {
- Tree parent;
- boolean grayed;
-
+ +import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.gtk.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class represent a selectable user interface object + * that represents a hierarchy of tree items in a tree widget. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + */ +public class TreeItem extends Item { + Tree parent; + boolean grayed; + /** * Constructs a new instance of this class given its parent * (which must be a <code>Tree</code> or a <code>TreeItem</code>) @@ -60,12 +60,12 @@ public class TreeItem extends Item { * @see Widget#checkSubclass * @see Widget#getStyle */ -public TreeItem (Tree parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, 0, -1);
-}
-
+public TreeItem (Tree parent, int style) { + super (parent, style); + this.parent = parent; + parent.createItem (this, 0, -1); +} + /** * Constructs a new instance of this class given its parent * (which must be a <code>Tree</code> or a <code>TreeItem</code>), @@ -97,13 +97,13 @@ public TreeItem (Tree parent, int style) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public TreeItem (Tree parent, int style, int index) {
- super (parent, style);
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- parent.createItem (this, 0, index);
-}
-
+public TreeItem (Tree parent, int style, int index) { + super (parent, style); + if (index < 0) error (SWT.ERROR_INVALID_RANGE); + this.parent = parent; + parent.createItem (this, 0, index); +} + /** * Constructs a new instance of this class given its parent * (which must be a <code>Tree</code> or a <code>TreeItem</code>) @@ -134,12 +134,12 @@ public TreeItem (Tree parent, int style, int index) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public TreeItem (TreeItem parentItem, int style) {
- super (checkNull (parentItem).parent, style);
- this.parent = parentItem.parent;
- parent.createItem (this, parentItem.handle, -1);
-}
-
+public TreeItem (TreeItem parentItem, int style) { + super (checkNull (parentItem).parent, style); + this.parent = parentItem.parent; + parent.createItem (this, parentItem.handle, -1); +} + /** * Constructs a new instance of this class given its parent * (which must be a <code>Tree</code> or a <code>TreeItem</code>), @@ -171,41 +171,41 @@ public TreeItem (TreeItem parentItem, int style) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public TreeItem (TreeItem parentItem, int style, int index) {
- super (checkNull (parentItem).parent, style);
- if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- this.parent = parentItem.parent;
- parent.createItem (this, parentItem.handle, index);
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- int[] ptr = new int[1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, 3, ptr, -1);
- if (ptr [0] == 0) return parent.getBackground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (getDisplay (), gdkColor);
-}
-
+public TreeItem (TreeItem parentItem, int style, int index) { + super (checkNull (parentItem).parent, style); + if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED); + this.parent = parentItem.parent; + parent.createItem (this, parentItem.handle, index); +} + +static TreeItem checkNull (TreeItem item) { + if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + return item; +} + +/** + * Returns the receiver's background color. + * + * @return the background color + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 2.0 + * + */ +public Color getBackground () { + checkWidget (); + int[] ptr = new int[1]; + OS.gtk_tree_model_get (parent.modelHandle, handle, 3, ptr, -1); + if (ptr [0] == 0) return parent.getBackground (); + GdkColor gdkColor = new GdkColor (); + OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); + return Color.gtk_new (getDisplay (), gdkColor); +} + /** * Returns a rectangle describing the receiver's size and location * relative to its parent. @@ -217,17 +217,17 @@ public Color getBackground () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public Rectangle getBounds () {
- checkWidget ();
- int parentHandle = parent.handle;
- GdkRectangle rect = new GdkRectangle ();
- int column = OS.gtk_tree_view_get_column (parentHandle, 0);
- int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- OS.gtk_tree_path_free (path);
- return new Rectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
+public Rectangle getBounds () { + checkWidget (); + int parentHandle = parent.handle; + GdkRectangle rect = new GdkRectangle (); + int column = OS.gtk_tree_view_get_column (parentHandle, 0); + int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); + OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); + OS.gtk_tree_path_free (path); + return new Rectangle (rect.x, rect.y, rect.width, rect.height); +} + /** * Returns <code>true</code> if the receiver is checked, * and false otherwise. When the parent does not have @@ -241,19 +241,19 @@ public Rectangle getBounds () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public boolean getChecked () {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return false;
- int [] ptr = new int [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, 5, ptr, -1);
- return ptr [0] != 0;
-}
-
-public Display getDisplay () {
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public boolean getChecked () { + checkWidget(); + if ((parent.style & SWT.CHECK) == 0) return false; + int [] ptr = new int [1]; + OS.gtk_tree_model_get (parent.modelHandle, handle, 5, ptr, -1); + return ptr [0] != 0; +} + +public Display getDisplay () { + if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); + return parent.getDisplay (); +} + /** * Returns <code>true</code> if the receiver is expanded, * and false otherwise. @@ -266,37 +266,37 @@ public Display getDisplay () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public boolean getExpanded () {
- checkWidget();
- int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- boolean answer = OS.gtk_tree_view_row_expanded (parent.handle, path);
- OS.gtk_tree_path_free (path);
- return answer;
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
+public boolean getExpanded () { + checkWidget(); + int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); + boolean answer = OS.gtk_tree_view_row_expanded (parent.handle, path); + OS.gtk_tree_path_free (path); + return answer; +} + +/** + * Returns the foreground color that the receiver will use to draw. + * + * @return the receiver's foreground color + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 2.0 + * */ -public Color getForeground () {
- checkWidget ();
- int [] ptr = new int [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, 2, ptr, -1);
- if (ptr [0]==0) return parent.getForeground();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (getDisplay (), gdkColor);
-}
-
+public Color getForeground () { + checkWidget (); + int [] ptr = new int [1]; + OS.gtk_tree_model_get (parent.modelHandle, handle, 2, ptr, -1); + if (ptr [0]==0) return parent.getForeground(); + GdkColor gdkColor = new GdkColor (); + OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); + return Color.gtk_new (getDisplay (), gdkColor); +} + /** * Returns <code>true</code> if the receiver is grayed, * and false otherwise. When the parent does not have @@ -310,12 +310,12 @@ public Color getForeground () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public boolean getGrayed() {
- checkWidget();
- //NOT IMPLEMENTED
- return grayed;
-}
-
+public boolean getGrayed() { + checkWidget(); + //NOT IMPLEMENTED + return grayed; +} + /** * Returns the number of items contained in the receiver * that are direct item children of the receiver. @@ -327,32 +327,32 @@ public boolean getGrayed() { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int getItemCount () {
- checkWidget();
- return OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle);
-}
-
-/**
- * Returns an array of <code>TreeItem</code>s which are the
- * direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getItemCount () { + checkWidget(); + return OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle); +} + +/** + * Returns an array of <code>TreeItem</code>s which are the + * direct item children of the receiver. + * <p> + * Note: This is not the actual structure used by the receiver + * to maintain its list of items, so modifying the array will + * not affect the receiver. + * </p> + * + * @return the receiver's items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public TreeItem [] getItems () {
- checkWidget();
- return parent.getItems (handle);
-}
-
+public TreeItem [] getItems () { + checkWidget(); + return parent.getItems (handle); +} + /** * Returns the receiver's parent, which must be a <code>Tree</code>. * @@ -363,11 +363,11 @@ public TreeItem [] getItems () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public Tree getParent () {
- checkWidget();
- return parent;
-}
-
+public Tree getParent () { + checkWidget(); + return parent; +} + /** * Returns the receiver's parent item, which must be a * <code>TreeItem</code> or null when the receiver is a @@ -380,35 +380,35 @@ public Tree getParent () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public TreeItem getParentItem () {
- checkWidget();
- int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- if (OS.gtk_tree_path_get_depth (path) < 2) {
- OS.gtk_tree_path_free (path);
- return null;
- }
- OS.gtk_tree_path_up (path);
- int iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_get_iter (parent.modelHandle, iter, path);
- int [] index = new int [1];
- OS.gtk_tree_model_get (parent.modelHandle, iter, 4, index, -1);
- OS.g_free (iter);
- OS.gtk_tree_path_free (path);
- return parent.items [index [0]];
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (handle != 0) OS.g_free (handle);
- handle = 0;
- parent = null;
-}
-
+public TreeItem getParentItem () { + checkWidget(); + int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); + if (OS.gtk_tree_path_get_depth (path) < 2) { + OS.gtk_tree_path_free (path); + return null; + } + OS.gtk_tree_path_up (path); + int iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); + OS.gtk_tree_model_get_iter (parent.modelHandle, iter, path); + int [] index = new int [1]; + OS.gtk_tree_model_get (parent.modelHandle, iter, 4, index, -1); + OS.g_free (iter); + OS.gtk_tree_path_free (path); + return parent.items [index [0]]; +} + +void releaseChild () { + super.releaseChild (); + parent.destroyItem (this); +} + +void releaseWidget () { + super.releaseWidget (); + if (handle != 0) OS.g_free (handle); + handle = 0; + parent = null; +} + /** * Sets the receiver's background color to the color specified * by the argument, or to the default system color for the item @@ -427,15 +427,15 @@ void releaseWidget () { * @since 2.0 * */ -public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_tree_store_set (parent.modelHandle, handle, 3, gdkColor, -1);
-}
-
+public void setBackground (Color color) { + checkWidget (); + if (color != null && color.isDisposed ()) { + SWT.error (SWT.ERROR_INVALID_ARGUMENT); + } + GdkColor gdkColor = color != null ? color.handle : null; + OS.gtk_tree_store_set (parent.modelHandle, handle, 3, gdkColor, -1); +} + /** * Sets the checked state of the receiver. * <p> @@ -447,12 +447,12 @@ public void setBackground (Color color) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setChecked (boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- OS.gtk_tree_store_set (parent.modelHandle, handle, 5, checked, -1);
-}
-
+public void setChecked (boolean checked) { + checkWidget(); + if ((parent.style & SWT.CHECK) == 0) return; + OS.gtk_tree_store_set (parent.modelHandle, handle, 5, checked, -1); +} + /** * Sets the grayed state of the receiver. * <p> @@ -464,12 +464,12 @@ public void setChecked (boolean checked) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setGrayed (boolean grayed) {
- checkWidget();
- //NOT IMPLEMENTED
- this.grayed = grayed;
-}
-
+public void setGrayed (boolean grayed) { + checkWidget(); + //NOT IMPLEMENTED + this.grayed = grayed; +} + /** * Sets the expanded state of the receiver. * <p> @@ -481,21 +481,21 @@ public void setGrayed (boolean grayed) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setExpanded (boolean expanded) {
- checkWidget();
- int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- if (expanded) {
- OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_EXPANDED);
- OS.gtk_tree_view_expand_row (parent.handle, path, false);
- OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_EXPANDED);
- } else {
- OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_COLLAPSED);
- OS.gtk_tree_view_collapse_row (parent.handle, path);
- OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_COLLAPSED);
- }
- OS.gtk_tree_path_free (path);
-}
-
+public void setExpanded (boolean expanded) { + checkWidget(); + int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); + if (expanded) { + OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_EXPANDED); + OS.gtk_tree_view_expand_row (parent.handle, path, false); + OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_EXPANDED); + } else { + OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_COLLAPSED); + OS.gtk_tree_view_collapse_row (parent.handle, path); + OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_COLLAPSED); + } + OS.gtk_tree_path_free (path); +} + /** * Sets the receiver's foreground color to the color specified * by the argument, or to the default system color for the item @@ -516,43 +516,43 @@ public void setExpanded (boolean expanded) { * @since 2.0 * */ -public void setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_tree_store_set (parent.modelHandle, handle, 2, gdkColor, -1);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage (image);
- int 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);
- }
- OS.gtk_tree_store_set (parent.modelHandle, handle, 1, pixbuf, -1);
-}
-
+public void setForeground (Color color){ + checkWidget (); + if (color != null && color.isDisposed ()) { + SWT.error (SWT.ERROR_INVALID_ARGUMENT); + } + GdkColor gdkColor = color != null ? color.handle : null; + OS.gtk_tree_store_set (parent.modelHandle, handle, 2, gdkColor, -1); +} + +public void setImage (Image image) { + checkWidget(); + if (image != null && image.isDisposed()) { + error(SWT.ERROR_INVALID_ARGUMENT); + } + super.setImage (image); + int 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); + } + OS.gtk_tree_store_set (parent.modelHandle, handle, 1, pixbuf, -1); +} + /** * This label will be displayed to the right of the bitmap, * or, if the receiver doesn't have a bitmap to the right of * the horizontal hierarchy connector line. */ -public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- byte[] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_tree_store_set (parent.modelHandle, handle, 0, buffer, -1);
-}
-
-}
+public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + super.setText (string); + byte[] buffer = Converter.wcsToMbcs (null, string, true); + OS.gtk_tree_store_set (parent.modelHandle, handle, 0, buffer, -1); +} + +} |