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. * *
* IMPORTANT: This class is not intended to be subclassed. *
*/ public class TreeItem extends Item { Tree parent; int index; /** * Constructs a new instance of this class given its parent * (which must be aTree
or a TreeItem
)
* and a style value describing its behavior and appearance.
* The item is added to the end of the items maintained by its parent.
*
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* for all SWT widget classes should include a comment which
* describes the style constants which are applicable to the class.
*
Tree
or a TreeItem
),
* a style value describing its behavior and appearance, and the index
* at which to place it in the items maintained by its parent.
*
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* for all SWT widget classes should include a comment which
* describes the style constants which are applicable to the class.
*
Tree
or a TreeItem
)
* and a style value describing its behavior and appearance.
* The item is added to the end of the items maintained by its parent.
*
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* for all SWT widget classes should include a comment which
* describes the style constants which are applicable to the class.
*
Tree
or a TreeItem
),
* a style value describing its behavior and appearance, and the index
* at which to place it in the items maintained by its parent.
*
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* for all SWT widget classes should include a comment which
* describes the style constants which are applicable to the class.
*
CHECK style, return false.
*
*
* @return the checked state
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public boolean getChecked () {
checkWidget();
if ((parent.style & SWT.CHECK) == 0) return false;
int ctree = parent.handle;
int [] pixmap = new int [1];
OS.gtk_ctree_get_node_info (ctree, handle, null, null, pixmap, null, null, null, null, null);
return pixmap [0] == parent.check;
}
public Display getDisplay () {
if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
return parent.getDisplay ();
}
/**
* Returns true
if the receiver is expanded,
* and false otherwise.
*
*
* @return the expanded state
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public boolean getExpanded () {
checkWidget();
int ctree = parent.handle;
boolean [] buffer = new boolean [1];
OS.gtk_ctree_get_node_info (ctree, handle, null, null, null, null, null, null, null, buffer);
return buffer [0];
}
/**
* Returns the foreground color that the receiver will use to draw.
*
* @return the receiver's foreground color
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*
* @since 2.0
*
*/
public Color getForeground () {
checkWidget ();
Tree parent = getParent();
return parent.getForeground();
}
/**
* Returns true
if the receiver is grayed,
* and false otherwise. When the parent does not have
* the CHECK style, return false.
*
*
* @return the grayed state
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public boolean getGrayed() {
checkWidget();
return false;
}
/**
* Returns the number of items contained in the receiver
* that are direct item children of the receiver.
*
* @return the number of items
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public int getItemCount () {
checkWidget();
return parent.getItemCount (handle);
}
/**
* Returns an array of TreeItem
s which are the
* direct item children of the receiver.
*
* 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.
*
*
* @return the receiver's items
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public TreeItem [] getItems () {
checkWidget();
return parent.getItems (handle);
}
/**
* Returns the receiver's parent, which must be a Tree
.
*
* @return the receiver's parent
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public Tree getParent () {
checkWidget();
return parent;
}
/**
* Returns the receiver's parent item, which must be a
* TreeItem
or null when the receiver is a
* root.
*
* @return the receiver's parent item
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public TreeItem getParentItem () {
checkWidget();
int data = OS.g_list_nth_data (handle, 0);
GtkCTreeRow row = new GtkCTreeRow ();
OS.memmove (row, data, GtkCTreeRow.sizeof);
if (row.parent == 0) return null;
int ctree = parent.handle;
int index = OS.gtk_ctree_node_get_row_data (ctree, row.parent) - 1;
return parent.items [index];
}
void releaseChild () {
super.releaseChild ();
parent.destroyItem (this);
}
void releaseWidget () {
super.releaseWidget ();
parent = null;
}
/**
* 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
* - ERROR_INVALID_ARGUMENT - if the argument has been disposed
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*
* @since 2.0
*
*/
public void setBackground (Color color) {
checkWidget ();
if (color != null && color.isDisposed ())
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
/**
* Sets the checked state of the receiver.
*
*
* @param checked the new checked state
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public void setChecked (boolean checked) {
checkWidget();
if ((parent.style & SWT.CHECK) == 0) return;
int ctree = parent.handle;
byte [] spacing = new byte [1];
int [] pixmap = new int [1], mask = new int [1];
boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
byte [] buffer = Converter.wcsToMbcs (null, text, true);
OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap, mask, pixmap, mask, is_leaf, expanded);
if (checked && pixmap [0] == parent.check) return;
if (!checked && pixmap [0] == parent.uncheck) return;
pixmap [0] = checked ? parent.check : parent.uncheck;
OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap [0], mask [0], pixmap [0], mask [0], is_leaf [0], expanded [0]);
}
/**
* Sets the receiver's foreground 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)
*
* @since 2.0
*
* @exception IllegalArgumentException
* - ERROR_INVALID_ARGUMENT - if the argument has been disposed
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*
* @since 2.0
*
*/
public void setForeground (Color color) {
checkWidget ();
if (color != null && color.isDisposed ())
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
}
/**
* Sets the grayed state of the receiver.
*
*
* @param checked the new grayed state
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public void setGrayed (boolean grayed) {
checkWidget();
}
/**
* Sets the expanded state of the receiver.
*
*
* @param expanded the new expanded state
*
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
public void setExpanded (boolean expanded) {
checkWidget();
int ctree = parent.handle;
if (expanded) {
OS.gtk_signal_handler_block_by_data (ctree, SWT.Expand);
OS.gtk_ctree_expand (ctree, handle);
OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Expand);
} else {
OS.gtk_signal_handler_block_by_data (ctree, SWT.Collapse);
OS.gtk_ctree_collapse (ctree, handle);
OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Collapse);
}
}
public void setImage (Image image) {
checkWidget();
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
if ((parent.style & SWT.CHECK) != 0) return;
this.image = image;
int pixmap = 0, mask = 0;
if (image != null) {
pixmap = image.pixmap;
mask = image.mask;
}
int ctree = parent.handle;
byte [] spacing = new byte [1];
boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
byte [] buffer = Converter.wcsToMbcs (null, text, true);
OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, null, null, null, null, is_leaf, expanded);
OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap, mask, pixmap, mask, is_leaf [0], expanded [0]);
}
/**
* 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);
int ctree = parent.handle;
byte [] buffer = Converter.wcsToMbcs (null, string, true);
byte [] spacing = new byte [1];
boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap_closed [0], mask_closed [0], pixmap_opened [0], mask_opened [0], is_leaf [0], expanded [0]);
}
}