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