Mercurial > projects > dwt-linux
annotate dwt/widgets/Item.d @ 259:c0d810de7093
Update SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 29 Jun 2008 14:33:38 +0200 |
parents | 5a30aa9820f3 |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
47 | 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 | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
47 | 12 *******************************************************************************/ |
13 module dwt.widgets.Item; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
47 | 17 |
18 import dwt.widgets.Widget; | |
71 | 19 import dwt.DWT; |
47 | 20 import dwt.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> | |
259 | 32 * |
33 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
47 | 34 */ |
35 | |
36 public abstract class Item : Widget { | |
238 | 37 String text; |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
38 Image image; |
47 | 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 | |
71 | 46 * class <code>DWT</code> which is applicable to instances of this |
47 | 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 | |
71 | 49 * of those <code>DWT</code> style constants. The class description |
47 | 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> | |
71 | 60 * @exception DWTException <ul> |
47 | 61 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
62 * </ul> | |
63 * | |
71 | 64 * @see DWT |
47 | 65 * @see Widget#getStyle |
66 */ | |
67 public this (Widget parent, int style) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
68 super (parent, style); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
69 text = ""; |
47 | 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 | |
71 | 79 * class <code>DWT</code> which is applicable to instances of this |
47 | 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 | |
71 | 82 * of those <code>DWT</code> style constants. The class description |
47 | 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> | |
71 | 95 * @exception DWTException <ul> |
47 | 96 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
97 * </ul> | |
98 * | |
71 | 99 * @see DWT |
47 | 100 * @see Widget#getStyle |
101 */ | |
102 public this (Widget parent, int style, int index) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
103 this (parent, style); |
47 | 104 } |
105 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
106 protected override void checkSubclass () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
107 /* Do Nothing - Subclassing is allowed */ |
47 | 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 * | |
71 | 116 * @exception DWTException <ul> |
47 | 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 () { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
122 checkWidget (); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
123 return image; |
47 | 124 } |
125 | |
238 | 126 override String getNameText () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
127 return getText (); |
47 | 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 * | |
71 | 136 * @exception DWTException <ul> |
47 | 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 */ | |
238 | 141 public String getText () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
142 checkWidget(); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
143 return text; |
47 | 144 } |
145 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
146 override void releaseWidget () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
147 super.releaseWidget (); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
148 text = null; |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
149 image = null; |
47 | 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> | |
71 | 161 * @exception DWTException <ul> |
47 | 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) { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
167 checkWidget (); |
71 | 168 if (image !is null && image.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
169 this.image = image; |
47 | 170 } |
171 | |
172 /** | |
173 * Sets the receiver's text. | |
174 * | |
175 * @param string the new text | |
176 * | |
71 | 177 * @exception DWTException <ul> |
47 | 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 */ | |
238 | 182 public void setText (String string) { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
47
diff
changeset
|
183 checkWidget (); |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
184 // DWT extension: allow null for zero length string |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
185 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
186 text = string.dup; |
47 | 187 } |
188 | |
189 } |