1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module org.eclipse.swt.widgets.Item;
14 
15 import java.lang.all;
16 
17 
18 import org.eclipse.swt.widgets.Widget;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Image;
21 
22 /**
23  * This class is the abstract superclass of all non-windowed
24  * user interface objects that occur within specific controls.
25  * For example, a tree will contain tree items.
26  * <dl>
27  * <dt><b>Styles:</b></dt>
28  * <dd>(none)</dd>
29  * <dt><b>Events:</b></dt>
30  * <dd>(none)</dd>
31  * </dl>
32  *
33  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
34  */
35 
36 public abstract class Item : Widget {
37     String text;
38     Image image;
39 
40 /**
41  * Constructs a new instance of this class given its parent
42  * and a style value describing its behavior and appearance.
43  * The item is added to the end of the items maintained by its parent.
44  * <p>
45  * The style value is either one of the style constants defined in
46  * class <code>SWT</code> which is applicable to instances of this
47  * class, or must be built by <em>bitwise OR</em>'ing together
48  * (that is, using the <code>int</code> "|" operator) two or more
49  * of those <code>SWT</code> style constants. The class description
50  * lists the style constants that are applicable to the class.
51  * Style bits are also inherited from superclasses.
52  * </p>
53  *
54  * @param parent a widget which will be the parent of the new instance (cannot be null)
55  * @param style the style of item to construct
56  *
57  * @exception IllegalArgumentException <ul>
58  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
59  * </ul>
60  * @exception SWTException <ul>
61  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
62  * </ul>
63  *
64  * @see SWT
65  * @see Widget#getStyle
66  */
67 public this (Widget parent, int style) {
68     super (parent, style);
69     text = "";
70 }
71 
72 /**
73  * Constructs a new instance of this class given its parent
74  * and a style value describing its behavior and appearance,
75  * and the index at which to place it in the items maintained
76  * by its parent.
77  * <p>
78  * The style value is either one of the style constants defined in
79  * class <code>SWT</code> which is applicable to instances of this
80  * class, or must be built by <em>bitwise OR</em>'ing together
81  * (that is, using the <code>int</code> "|" operator) two or more
82  * of those <code>SWT</code> style constants. The class description
83  * lists the style constants that are applicable to the class.
84  * Style bits are also inherited from superclasses.
85  * </p>
86  *
87  * @param parent a widget which will be the parent of the new instance (cannot be null)
88  * @param style the style of item to construct
89  * @param index the zero-relative index at which to store the receiver in its parent
90  *
91  * @exception IllegalArgumentException <ul>
92  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
93  *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
94  * </ul>
95  * @exception SWTException <ul>
96  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
97  * </ul>
98  *
99  * @see SWT
100  * @see Widget#getStyle
101  */
102 public this (Widget parent, int style, int index) {
103     this (parent, style);
104 }
105 
106 protected override void checkSubclass () {
107     /* Do Nothing - Subclassing is allowed */
108 }
109 
110 /**
111  * Returns the receiver's image if it has one, or null
112  * if it does not.
113  *
114  * @return the receiver's image
115  *
116  * @exception SWTException <ul>
117  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
118  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
119  * </ul>
120  */
121 public Image getImage () {
122     checkWidget ();
123     return image;
124 }
125 
126 override String getNameText () {
127     return getText ();
128 }
129 
130 /**
131  * Returns the receiver's text, which will be an empty
132  * string if it has never been set.
133  *
134  * @return the receiver's text
135  *
136  * @exception SWTException <ul>
137  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
138  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
139  * </ul>
140  */
141 public String getText () {
142     checkWidget();
143     return text;
144 }
145 
146 override void releaseWidget () {
147     super.releaseWidget ();
148     text = null;
149     image = null;
150 }
151 
152 /**
153  * Sets the receiver's image to the argument, which may be
154  * null indicating that no image should be displayed.
155  *
156  * @param image the image to display on the receiver (may be null)
157  *
158  * @exception IllegalArgumentException <ul>
159  *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
160  * </ul>
161  * @exception SWTException <ul>
162  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
163  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
164  * </ul>
165  */
166 public void setImage (Image image) {
167     checkWidget ();
168     if (image !is null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
169     this.image = image;
170 }
171 
172 /**
173  * Sets the receiver's text.
174  *
175  * @param string the new text
176  *
177  * @exception SWTException <ul>
178  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
179  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
180  * </ul>
181  */
182 public void setText (String string) {
183     checkWidget ();
184     // SWT extension: allow null for zero length string
185     //if (string is null) error (SWT.ERROR_NULL_ARGUMENT);
186     text = string._idup();
187 }
188 
189 }