Mercurial > projects > dwt-linux
annotate dwt/widgets/TabItem.d @ 238:380bad9f6852
reverted char[] to String
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:42:55 +0200 |
parents | 17f8449522fd |
children | ce446666f5a2 |
rev | line source |
---|---|
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
87 | 2 * Copyright (c) 2000, 2007 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 | |
108 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
87 | 12 *******************************************************************************/ |
13 module dwt.widgets.TabItem; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
87 | 17 |
18 | |
19 import dwt.DWT; | |
20 import dwt.DWTException; | |
21 import dwt.graphics.Image; | |
22 import dwt.internal.gtk.OS; | |
23 import dwt.widgets.Item; | |
24 import dwt.widgets.Control; | |
25 import dwt.widgets.TabFolder; | |
26 import dwt.widgets.ImageList; | |
27 | |
28 static import tango.stdc.stringz; | |
29 | |
30 /** | |
31 * Instances of this class represent a selectable user interface object | |
32 * corresponding to a tab for a page in a tab folder. | |
33 * <dl> | |
34 * <dt><b>Styles:</b></dt> | |
35 * <dd>(none)</dd> | |
36 * <dt><b>Events:</b></dt> | |
37 * <dd>(none)</dd> | |
38 * </dl> | |
39 * <p> | |
40 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
41 * </p> | |
42 */ | |
43 public class TabItem : Item { | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
44 |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
45 alias Item.setForegroundColor setForegroundColor; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
46 |
87 | 47 GtkWidget* labelHandle, imageHandle, pageHandle; |
48 Control control; | |
49 TabFolder parent; | |
238 | 50 String toolTipText; |
87 | 51 |
52 /** | |
53 * Constructs a new instance of this class given its parent | |
54 * (which must be a <code>TabFolder</code>) and a style value | |
55 * describing its behavior and appearance. The item is added | |
56 * to the end of the items maintained by its parent. | |
57 * <p> | |
58 * The style value is either one of the style constants defined in | |
59 * class <code>DWT</code> which is applicable to instances of this | |
60 * class, or must be built by <em>bitwise OR</em>'ing together | |
61 * (that is, using the <code>int</code> "|" operator) two or more | |
62 * of those <code>DWT</code> style constants. The class description | |
63 * lists the style constants that are applicable to the class. | |
64 * Style bits are also inherited from superclasses. | |
65 * </p> | |
66 * | |
67 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
68 * @param style the style of control to construct | |
69 * | |
70 * @exception IllegalArgumentException <ul> | |
71 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
72 * </ul> | |
73 * @exception DWTException <ul> | |
74 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
75 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
76 * </ul> | |
77 * | |
78 * @see DWT | |
79 * @see Widget#checkSubclass | |
80 * @see Widget#getStyle | |
81 */ | |
82 public this (TabFolder parent, int style) { | |
83 super (parent, style); | |
84 this.parent = parent; | |
85 createWidget (parent.getItemCount ()); | |
86 } | |
87 | |
88 /** | |
89 * Constructs a new instance of this class given its parent | |
90 * (which must be a <code>TabFolder</code>), a style value | |
91 * describing its behavior and appearance, and the index | |
92 * at which to place it in the items maintained by its parent. | |
93 * <p> | |
94 * The style value is either one of the style constants defined in | |
95 * class <code>DWT</code> which is applicable to instances of this | |
96 * class, or must be built by <em>bitwise OR</em>'ing together | |
97 * (that is, using the <code>int</code> "|" operator) two or more | |
98 * of those <code>DWT</code> style constants. The class description | |
99 * lists the style constants that are applicable to the class. | |
100 * Style bits are also inherited from superclasses. | |
101 * </p> | |
102 * | |
103 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
104 * @param style the style of control to construct | |
105 * @param index the zero-relative index to store the receiver in its parent | |
106 * | |
107 * @exception IllegalArgumentException <ul> | |
108 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
109 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
110 * </ul> | |
111 * @exception DWTException <ul> | |
112 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
113 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
114 * </ul> | |
115 * | |
116 * @see DWT | |
117 * @see Widget#checkSubclass | |
118 * @see Widget#getStyle | |
119 */ | |
120 public this (TabFolder parent, int style, int index) { | |
121 super (parent, style); | |
122 this.parent = parent; | |
123 createWidget (index); | |
124 } | |
125 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
126 protected override void checkSubclass () { |
87 | 127 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
128 } | |
129 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
130 override void createWidget (int index) { |
87 | 131 parent.createItem (this, index); |
132 setOrientation (); | |
133 hookEvents (); | |
134 register (); | |
135 text = ""; | |
136 } | |
137 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
138 override void deregister() { |
87 | 139 super.deregister (); |
140 if (labelHandle !is null) display.removeWidget (labelHandle); | |
141 } | |
142 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
143 override void destroyWidget () { |
87 | 144 parent.destroyItem (this); |
145 releaseHandle (); | |
146 } | |
147 | |
148 /** | |
149 * Returns the control that is used to fill the client area of | |
150 * the tab folder when the user selects the tab item. If no | |
151 * control has been set, return <code>null</code>. | |
152 * <p> | |
153 * @return the control | |
154 * | |
155 * @exception DWTException <ul> | |
156 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
157 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
158 * </ul> | |
159 */ | |
160 public Control getControl () { | |
161 checkWidget (); | |
162 return control; | |
163 } | |
164 | |
165 /** | |
166 * Returns the receiver's parent, which must be a <code>TabFolder</code>. | |
167 * | |
168 * @return the receiver's parent | |
169 * | |
170 * @exception DWTException <ul> | |
171 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
172 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
173 * </ul> | |
174 */ | |
175 public TabFolder getParent () { | |
176 checkWidget (); | |
177 return parent; | |
178 } | |
179 | |
180 /** | |
181 * Returns the receiver's tool tip text, or null if it has | |
182 * not been set. | |
183 * | |
184 * @return the receiver's tool tip text | |
185 * | |
186 * @exception DWTException <ul> | |
187 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
188 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
189 * </ul> | |
190 */ | |
238 | 191 public String getToolTipText () { |
87 | 192 checkWidget (); |
193 return toolTipText; | |
194 } | |
195 | |
196 override int gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
197 parent.gtk_enter_notify_event (widget, event); | |
198 return 0; | |
199 } | |
200 | |
201 override int gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) { | |
202 return parent.gtk_mnemonic_activate (widget, arg1); | |
203 } | |
204 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
205 override void hookEvents () { |
87 | 206 super.hookEvents (); |
207 if (labelHandle !is null) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); | |
208 OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); | |
209 } | |
210 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
211 override void register () { |
87 | 212 super.register (); |
213 if (labelHandle !is null) display.addWidget (labelHandle, this); | |
214 } | |
215 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
216 override void releaseHandle () { |
87 | 217 super.releaseHandle (); |
218 pageHandle = labelHandle = imageHandle = null; | |
219 parent = null; | |
220 } | |
221 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
222 override void releaseParent () { |
87 | 223 super.releaseParent (); |
224 int index = parent.indexOf (this); | |
225 if (index is parent.getSelectionIndex ()) { | |
226 if (control !is null) control.setVisible (false); | |
227 } | |
228 } | |
229 | |
230 /** | |
231 * Sets the control that is used to fill the client area of | |
232 * the tab folder when the user selects the tab item. | |
233 * <p> | |
234 * @param control the new control (or null) | |
235 * | |
236 * @exception IllegalArgumentException <ul> | |
237 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> | |
238 * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> | |
239 * </ul> | |
240 * @exception DWTException <ul> | |
241 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
242 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
243 * </ul> | |
244 */ | |
245 public void setControl (Control control) { | |
246 checkWidget (); | |
247 if (control !is null) { | |
248 if (control.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
249 if (control.parent !is parent) error (DWT.ERROR_INVALID_PARENT); | |
250 } | |
251 Control oldControl = this.control, newControl = control; | |
252 this.control = control; | |
253 int index = parent.indexOf (this); | |
254 if (index !is parent.getSelectionIndex ()) { | |
255 if (newControl !is null) newControl.setVisible (false); | |
256 return; | |
257 } | |
258 if (newControl !is null) { | |
259 newControl.setBounds (parent.getClientArea ()); | |
260 newControl.setVisible (true); | |
261 } | |
262 if (oldControl !is null) oldControl.setVisible (false); | |
263 } | |
264 | |
265 void setFontDescription (PangoFontDescription* font) { | |
266 OS.gtk_widget_modify_font (labelHandle, font); | |
267 OS.gtk_widget_modify_font (imageHandle, font); | |
268 } | |
269 | |
270 void setForegroundColor (GdkColor* color) { | |
271 /* Don't set the color in vbox handle (it doesn't draw) */ | |
272 setForegroundColor (labelHandle, color); | |
273 setForegroundColor (imageHandle, color); | |
274 } | |
275 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
276 public override void setImage (Image image) { |
87 | 277 checkWidget (); |
278 super.setImage (image); | |
279 if (image !is null) { | |
280 ImageList imageList = parent.imageList; | |
281 if (imageList is null) imageList = parent.imageList = new ImageList (); | |
282 int imageIndex = imageList.indexOf (image); | |
283 if (imageIndex is -1) { | |
284 imageIndex = imageList.add (image); | |
285 } else { | |
286 imageList.put (imageIndex, image); | |
287 } | |
288 auto pixbuf = imageList.getPixbuf (imageIndex); | |
289 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
290 OS.gtk_widget_show (imageHandle); | |
291 } else { | |
292 OS.gtk_image_set_from_pixbuf (imageHandle, null); | |
293 OS.gtk_widget_hide (imageHandle); | |
294 } | |
295 } | |
296 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
297 override void setOrientation () { |
87 | 298 if ((parent.style & DWT.RIGHT_TO_LEFT) !is 0) { |
299 if (handle !is null) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); | |
300 if (labelHandle !is null) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); | |
301 if (imageHandle !is null) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); | |
302 if (pageHandle !is null) OS.gtk_widget_set_direction (pageHandle, OS.GTK_TEXT_DIR_RTL); | |
303 } | |
304 } | |
305 | |
306 /** | |
307 * Sets the receiver's text. The string may include | |
308 * the mnemonic character. | |
309 * </p> | |
310 * <p> | |
311 * Mnemonics are indicated by an '&' that causes the next | |
312 * character to be the mnemonic. When the user presses a | |
313 * key sequence that matches the mnemonic, a selection | |
314 * event occurs. On most platforms, the mnemonic appears | |
315 * underlined but may be emphasised in a platform specific | |
316 * manner. The mnemonic indicator character '&' can be | |
317 * escaped by doubling it in the string, causing a single | |
318 * '&' to be displayed. | |
319 * </p> | |
320 * | |
321 * @param string the new text | |
322 * | |
323 * @exception IllegalArgumentException <ul> | |
324 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
325 * </ul> | |
326 * @exception DWTException <ul> | |
327 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
328 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
329 * </ul> | |
330 * | |
331 */ | |
238 | 332 public override void setText (String string) { |
87 | 333 checkWidget (); |
334 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
335 super.setText (string); | |
336 char [] chars = fixMnemonic (string); | |
337 char* buffer = tango.stdc.stringz.toStringz( chars); | |
338 OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); | |
339 if (string.length !is 0) { | |
340 OS.gtk_widget_show (labelHandle); | |
341 } else { | |
342 OS.gtk_widget_hide (labelHandle); | |
343 } | |
344 } | |
345 | |
346 /** | |
347 * Sets the receiver's tool tip text to the argument, which | |
348 * may be null indicating that no tool tip text should be shown. | |
349 * | |
350 * @param string the new tool tip text (or null) | |
351 * | |
352 * @exception DWTException <ul> | |
353 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
354 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
355 * </ul> | |
356 */ | |
238 | 357 public void setToolTipText (String string) { |
87 | 358 checkWidget (); |
359 toolTipText = string; | |
360 } | |
361 | |
362 } |