Mercurial > projects > dwt-linux
annotate dwt/widgets/ToolItem.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 |
---|---|
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
75 | 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> | |
75 | 12 *******************************************************************************/ |
13 module dwt.widgets.ToolItem; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
75 | 17 |
18 | |
19 import dwt.DWT; | |
20 import dwt.DWTException; | |
21 import dwt.events.SelectionEvent; | |
22 import dwt.events.SelectionListener; | |
23 import dwt.graphics.Image; | |
24 import dwt.graphics.Rectangle; | |
25 import dwt.internal.gtk.OS; | |
26 import dwt.widgets.Item; | |
27 import dwt.widgets.ToolBar; | |
28 import dwt.widgets.Control; | |
29 import dwt.widgets.Shell; | |
30 import dwt.widgets.TypedListener; | |
31 import dwt.widgets.Event; | |
32 import dwt.widgets.ImageList; | |
33 | |
34 /** | |
35 * Instances of this class represent a selectable user interface object | |
36 * that represents a button in a tool bar. | |
37 * <dl> | |
38 * <dt><b>Styles:</b></dt> | |
39 * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd> | |
40 * <dt><b>Events:</b></dt> | |
41 * <dd>Selection</dd> | |
42 * </dl> | |
43 * <p> | |
44 * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN | |
45 * may be specified. | |
46 * </p><p> | |
47 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
48 * </p> | |
259 | 49 * |
50 * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a> | |
51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
75 | 52 */ |
53 public class ToolItem : Item { | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
54 |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
55 alias Item.setForegroundColor setForegroundColor; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
56 |
75 | 57 GtkWidget* boxHandle, arrowHandle, arrowBoxHandle, separatorHandle, labelHandle, imageHandle; |
58 ToolBar parent; | |
59 Control control; | |
60 Image hotImage, disabledImage; | |
238 | 61 String toolTipText; |
75 | 62 bool drawHotImage; |
63 | |
64 /** | |
65 * Constructs a new instance of this class given its parent | |
66 * (which must be a <code>ToolBar</code>) and a style value | |
67 * describing its behavior and appearance. The item is added | |
68 * to the end of the items maintained by its parent. | |
69 * <p> | |
70 * The style value is either one of the style constants defined in | |
71 * class <code>DWT</code> which is applicable to instances of this | |
72 * class, or must be built by <em>bitwise OR</em>'ing together | |
73 * (that is, using the <code>int</code> "|" operator) two or more | |
74 * of those <code>DWT</code> style constants. The class description | |
75 * lists the style constants that are applicable to the class. | |
76 * Style bits are also inherited from superclasses. | |
77 * </p> | |
78 * | |
79 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
80 * @param style the style of control to construct | |
81 * | |
82 * @exception IllegalArgumentException <ul> | |
83 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
84 * </ul> | |
85 * @exception DWTException <ul> | |
86 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
87 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
88 * </ul> | |
89 * | |
90 * @see DWT#PUSH | |
91 * @see DWT#CHECK | |
92 * @see DWT#RADIO | |
93 * @see DWT#SEPARATOR | |
94 * @see DWT#DROP_DOWN | |
95 * @see Widget#checkSubclass | |
96 * @see Widget#getStyle | |
97 */ | |
98 public this (ToolBar parent, int style) { | |
99 super (parent, checkStyle (style)); | |
100 this.parent = parent; | |
101 createWidget (parent.getItemCount ()); | |
102 } | |
103 | |
104 /** | |
105 * Constructs a new instance of this class given its parent | |
106 * (which must be a <code>ToolBar</code>), a style value | |
107 * describing its behavior and appearance, and the index | |
108 * at which to place it in the items maintained by its parent. | |
109 * <p> | |
110 * The style value is either one of the style constants defined in | |
111 * class <code>DWT</code> which is applicable to instances of this | |
112 * class, or must be built by <em>bitwise OR</em>'ing together | |
113 * (that is, using the <code>int</code> "|" operator) two or more | |
114 * of those <code>DWT</code> style constants. The class description | |
115 * lists the style constants that are applicable to the class. | |
116 * Style bits are also inherited from superclasses. | |
117 * </p> | |
118 * | |
119 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
120 * @param style the style of control to construct | |
121 * @param index the zero-relative index to store the receiver in its parent | |
122 * | |
123 * @exception IllegalArgumentException <ul> | |
124 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
125 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
126 * </ul> | |
127 * @exception DWTException <ul> | |
128 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
129 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
130 * </ul> | |
131 * | |
132 * @see DWT#PUSH | |
133 * @see DWT#CHECK | |
134 * @see DWT#RADIO | |
135 * @see DWT#SEPARATOR | |
136 * @see DWT#DROP_DOWN | |
137 * @see Widget#checkSubclass | |
138 * @see Widget#getStyle | |
139 */ | |
140 public this (ToolBar parent, int style, int index) { | |
141 super (parent, checkStyle (style)); | |
142 this.parent = parent; | |
143 int count = parent.getItemCount (); | |
144 if (!(0 <= index && index <= count)) { | |
145 error (DWT.ERROR_INVALID_RANGE); | |
146 } | |
147 createWidget (index); | |
148 } | |
149 | |
150 /** | |
151 * Adds the listener to the collection of listeners who will | |
152 * be notified when the control is selected by the user, by sending | |
153 * it one of the messages defined in the <code>SelectionListener</code> | |
154 * interface. | |
155 * <p> | |
156 * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool, | |
157 * the event object detail field contains the value <code>DWT.ARROW</code>. | |
158 * <code>widgetDefaultSelected</code> is not called. | |
159 * </p> | |
160 * | |
161 * @param listener the listener which should be notified when the control is selected by the user, | |
162 * | |
163 * @exception IllegalArgumentException <ul> | |
164 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
165 * </ul> | |
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 * @see SelectionListener | |
172 * @see #removeSelectionListener | |
173 * @see SelectionEvent | |
174 */ | |
175 public void addSelectionListener(SelectionListener listener) { | |
176 checkWidget(); | |
177 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
178 TypedListener typedListener = new TypedListener (listener); | |
179 addListener (DWT.Selection,typedListener); | |
180 addListener (DWT.DefaultSelection,typedListener); | |
181 } | |
182 | |
183 static int checkStyle (int style) { | |
184 return checkBits (style, DWT.PUSH, DWT.CHECK, DWT.RADIO, DWT.SEPARATOR, DWT.DROP_DOWN, 0); | |
185 } | |
186 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
187 protected override void checkSubclass () { |
75 | 188 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
189 } | |
190 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
191 override void createHandle (int index) { |
75 | 192 state |= HANDLE; |
193 if ((style & DWT.SEPARATOR) is 0) { | |
194 boxHandle = cast(GtkWidget*)((parent.style & DWT.RIGHT) !is 0 ? OS.gtk_hbox_new (false, 0) : OS.gtk_vbox_new (false, 0)); | |
195 if (boxHandle is null) error (DWT.ERROR_NO_HANDLES); | |
196 labelHandle = OS.gtk_label_new_with_mnemonic (null); | |
197 if (labelHandle is null) error (DWT.ERROR_NO_HANDLES); | |
198 imageHandle = OS.gtk_image_new (); | |
199 if (imageHandle is null) error (DWT.ERROR_NO_HANDLES); | |
200 OS.gtk_container_add (boxHandle, imageHandle); | |
201 OS.gtk_container_add (boxHandle, labelHandle); | |
202 if ((parent.style & DWT.VERTICAL) !is 0) { | |
203 // Align text and images to the left | |
204 OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START); | |
205 OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 2, OS.GTK_PACK_START); | |
206 } | |
207 } | |
208 int bits = DWT.SEPARATOR | DWT.RADIO | DWT.CHECK | DWT.PUSH | DWT.DROP_DOWN; | |
209 switch (style & bits) { | |
210 case DWT.SEPARATOR: | |
211 handle = cast(GtkWidget*)OS.gtk_hbox_new (false, 0); | |
212 if (handle is null) error (DWT.ERROR_NO_HANDLES); | |
213 bool isVertical = (parent.style & DWT.VERTICAL) !is 0; | |
214 separatorHandle = isVertical ? OS.gtk_hseparator_new() : OS.gtk_vseparator_new(); | |
215 if (separatorHandle is null) error (DWT.ERROR_NO_HANDLES); | |
216 OS.gtk_widget_set_size_request (separatorHandle, isVertical ? 15 : 6, isVertical ? 6 : 15); | |
217 OS.gtk_widget_set_size_request (handle, isVertical ? 15 : 6, isVertical ? 6 : 15); | |
218 OS.gtk_container_add (handle, separatorHandle); | |
219 break; | |
220 case DWT.DROP_DOWN: | |
221 handle = OS.gtk_button_new (); | |
222 if (handle is null) error (DWT.ERROR_NO_HANDLES); | |
223 arrowBoxHandle = cast(GtkWidget*)OS.gtk_hbox_new (false, 0); | |
224 if (arrowBoxHandle is null) error(DWT.ERROR_NO_HANDLES); | |
225 arrowHandle = OS.gtk_arrow_new (OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE); | |
226 if (arrowHandle is null) error (DWT.ERROR_NO_HANDLES); | |
227 OS.gtk_widget_set_size_request (arrowHandle, 8, 6); | |
228 OS.gtk_container_add (handle, arrowBoxHandle); | |
229 OS.gtk_container_add (arrowBoxHandle, boxHandle); | |
230 OS.gtk_container_add (arrowBoxHandle, arrowHandle); | |
231 break; | |
232 case DWT.RADIO: | |
233 /* | |
234 * This code is intentionally commented. Because GTK | |
235 * enforces radio behavior in a button group a radio group | |
236 * is not created for each set of contiguous buttons, each | |
237 * radio button will not draw unpressed. The fix is to use | |
238 * toggle buttons instead. | |
239 */ | |
240 // handle = OS.gtk_radio_button_new (0); | |
241 // if (handle is 0) error (DWT.ERROR_NO_HANDLES); | |
242 // OS.gtk_toggle_button_set_mode (handle, false); | |
243 // OS.gtk_container_add (handle, boxHandle); | |
244 // break; | |
245 case DWT.CHECK: | |
246 handle = OS.gtk_toggle_button_new (); | |
247 if (handle is null) error (DWT.ERROR_NO_HANDLES); | |
248 OS.gtk_toggle_button_set_mode (handle, false); | |
249 OS.gtk_container_add (handle, boxHandle); | |
250 break; | |
251 case DWT.PUSH: | |
252 default: | |
253 handle = OS.gtk_button_new (); | |
254 if (handle is null) error (DWT.ERROR_NO_HANDLES); | |
255 OS.gtk_container_add (handle, boxHandle); | |
256 break; | |
257 } | |
258 if ((style & DWT.SEPARATOR) is 0) { | |
259 int relief; | |
260 OS.gtk_widget_style_get1 (parent.handle, OS.button_relief.ptr, &relief); | |
261 OS.gtk_button_set_relief (handle, relief ); | |
262 } | |
263 OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
264 // This code is intentionally commented. | |
265 // int /*long*/ fontHandle = parent.fontHandle (); | |
266 // GdkColor color = new GdkColor (); | |
267 // int /*long*/ style = OS.gtk_widget_get_style (fontHandle); | |
268 // OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, color); | |
269 // int /*long*/ font = OS.gtk_style_get_font_desc (style); | |
270 // setForegroundColor (color); | |
271 // setFontDescription (font); | |
272 if ((parent.state & FOREGROUND) !is 0) { | |
273 setForegroundColor (parent.getForegroundColor()); | |
274 } | |
275 if ((parent.state & FONT) !is 0) { | |
276 setFontDescription (parent.getFontDescription()); | |
277 } | |
278 } | |
279 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
280 override void createWidget (int index) { |
75 | 281 super.createWidget (index); |
282 showWidget (index); | |
283 parent.relayout (); | |
284 } | |
285 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
286 override void deregister() { |
75 | 287 super.deregister (); |
288 if (labelHandle !is null) display.removeWidget (labelHandle); | |
289 } | |
290 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
291 public override void dispose () { |
75 | 292 if (isDisposed ()) return; |
293 ToolBar parent = this.parent; | |
294 super.dispose (); | |
295 parent.relayout (); | |
296 } | |
297 | |
298 /** | |
299 * Returns a rectangle describing the receiver's size and location | |
300 * relative to its parent. | |
301 * | |
302 * @return the receiver's bounding rectangle | |
303 * | |
304 * @exception DWTException <ul> | |
305 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
306 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
307 * </ul> | |
308 */ | |
309 public Rectangle getBounds () { | |
310 checkWidget(); | |
311 parent.forceResize (); | |
312 auto topHandle = topHandle (); | |
313 int x, y, width, height; | |
314 /* | |
315 * Bug in GTK. Toolbar items are only allocated their minimum size | |
316 * in versions before 2.4.0. The fix is to use the total size | |
317 * available minus any borders. | |
318 */ | |
319 if (OS.GTK_VERSION < OS.buildVERSION (2, 4, 0) && control !is null && !control.isDisposed ()) { | |
320 int border = OS.gtk_container_get_border_width (parent.handle); | |
321 int shadow; | |
322 OS.gtk_widget_style_get1 (parent.handle, "shadow_type".ptr, &shadow); | |
323 if (shadow !is OS.GTK_SHADOW_NONE) { | |
324 border += OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (parent.handle)); | |
325 } | |
326 if ((parent.style & DWT.VERTICAL) !is 0) { | |
327 x = border; | |
328 y = OS.GTK_WIDGET_Y (topHandle) + border; | |
329 width = OS.GTK_WIDGET_WIDTH (parent.handle) - border*2; | |
330 height = OS.GTK_WIDGET_HEIGHT (topHandle); | |
331 } else { | |
332 x = OS.GTK_WIDGET_X (topHandle) + border; | |
333 y = border; | |
334 width = OS.GTK_WIDGET_WIDTH (topHandle); | |
335 height = OS.GTK_WIDGET_HEIGHT (parent.handle) - border*2; | |
336 } | |
337 } else { | |
338 x = OS.GTK_WIDGET_X (topHandle); | |
339 y = OS.GTK_WIDGET_Y (topHandle); | |
340 width = OS.GTK_WIDGET_WIDTH (topHandle); | |
341 height = OS.GTK_WIDGET_HEIGHT (topHandle); | |
342 } | |
240 | 343 if ((parent.style & DWT.MIRRORED) !is 0) x = parent.getClientWidth () - width - x; |
344 if ((style & DWT.SEPARATOR) !is 0 && control !is null) height = Math.max (height, 23); | |
75 | 345 return new Rectangle (x, y, width, height); |
346 } | |
347 | |
348 /** | |
349 * Returns the control that is used to fill the bounds of | |
350 * the item when the item is a <code>SEPARATOR</code>. | |
351 * | |
352 * @return the control | |
353 * | |
354 * @exception DWTException <ul> | |
355 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
356 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
357 * </ul> | |
358 */ | |
359 public Control getControl () { | |
360 checkWidget(); | |
361 return control; | |
362 } | |
363 | |
364 /** | |
365 * Returns the receiver's disabled image if it has one, or null | |
366 * if it does not. | |
367 * <p> | |
368 * The disabled image is displayed when the receiver is disabled. | |
369 * </p> | |
370 * | |
371 * @return the receiver's disabled image | |
372 * | |
373 * @exception DWTException <ul> | |
374 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
375 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
376 * </ul> | |
377 */ | |
378 public Image getDisabledImage () { | |
379 checkWidget(); | |
380 return disabledImage; | |
381 } | |
382 | |
383 /** | |
384 * Returns <code>true</code> if the receiver is enabled, and | |
385 * <code>false</code> otherwise. A disabled control is typically | |
386 * not selectable from the user interface and draws with an | |
387 * inactive or "grayed" look. | |
388 * | |
389 * @return the receiver's enabled state | |
390 * | |
391 * @exception DWTException <ul> | |
392 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
393 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
394 * </ul> | |
395 * | |
396 * @see #isEnabled | |
397 */ | |
398 public bool getEnabled () { | |
399 checkWidget(); | |
400 auto topHandle = topHandle (); | |
401 return OS.GTK_WIDGET_SENSITIVE (topHandle); | |
402 } | |
403 | |
404 /** | |
405 * Returns the receiver's hot image if it has one, or null | |
406 * if it does not. | |
407 * <p> | |
408 * The hot image is displayed when the mouse enters the receiver. | |
409 * </p> | |
410 * | |
411 * @return the receiver's hot image | |
412 * | |
413 * @exception DWTException <ul> | |
414 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
415 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
416 * </ul> | |
417 */ | |
418 public Image getHotImage () { | |
419 checkWidget(); | |
420 return hotImage; | |
421 } | |
422 | |
423 /** | |
424 * Returns the receiver's parent, which must be a <code>ToolBar</code>. | |
425 * | |
426 * @return the receiver's parent | |
427 * | |
428 * @exception DWTException <ul> | |
429 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
430 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
431 * </ul> | |
432 */ | |
433 public ToolBar getParent () { | |
434 checkWidget(); | |
435 if (parent is null) error (DWT.ERROR_WIDGET_DISPOSED); | |
436 return parent; | |
437 } | |
438 | |
439 /** | |
440 * Returns <code>true</code> if the receiver is selected, | |
441 * and false otherwise. | |
442 * <p> | |
443 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, | |
444 * it is selected when it is checked (which some platforms draw as a | |
445 * pushed in button). If the receiver is of any other type, this method | |
446 * returns false. | |
447 * </p> | |
448 * | |
449 * @return the selection state | |
450 * | |
451 * @exception DWTException <ul> | |
452 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
453 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
454 * </ul> | |
455 */ | |
456 public bool getSelection () { | |
457 checkWidget(); | |
458 if ((style & (DWT.CHECK | DWT.RADIO)) is 0) return false; | |
459 return cast(bool)OS.gtk_toggle_button_get_active (handle); | |
460 } | |
461 | |
462 /** | |
463 * Returns the receiver's tool tip text, or null if it has not been set. | |
464 * | |
465 * @return the receiver's tool tip text | |
466 * | |
467 * @exception DWTException <ul> | |
468 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
469 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
470 * </ul> | |
471 */ | |
238 | 472 public String getToolTipText () { |
75 | 473 checkWidget(); |
474 return toolTipText; | |
475 } | |
476 | |
477 /** | |
478 * Gets the width of the receiver. | |
479 * | |
480 * @return the width | |
481 * | |
482 * @exception DWTException <ul> | |
483 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
484 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
485 * </ul> | |
486 */ | |
487 public int getWidth () { | |
488 checkWidget(); | |
489 parent.forceResize (); | |
490 auto topHandle = topHandle (); | |
491 return OS.GTK_WIDGET_WIDTH (topHandle); | |
492 } | |
493 | |
494 override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* gdkEvent) { | |
495 double x = gdkEvent.x; | |
496 gdkEvent.x += OS.GTK_WIDGET_X (handle); | |
497 double y = gdkEvent.y; | |
498 gdkEvent.y += OS.GTK_WIDGET_Y (handle); | |
499 auto result = parent.gtk_button_press_event (widget, gdkEvent); | |
500 gdkEvent.x = x; | |
501 gdkEvent.y = y; | |
502 return result; | |
503 } | |
504 | |
505 override int /*long*/ gtk_button_release_event (GtkWidget* widget, GdkEventButton* gdkEvent) { | |
506 double x = gdkEvent.x; | |
507 gdkEvent.x += OS.GTK_WIDGET_X (handle); | |
508 double y = gdkEvent.y; | |
509 gdkEvent.y += OS.GTK_WIDGET_Y (handle); | |
510 auto result = parent.gtk_button_release_event (widget, gdkEvent); | |
511 gdkEvent.x = x; | |
512 gdkEvent.y = y; | |
513 return result; | |
514 } | |
515 | |
516 override int /*long*/ gtk_clicked (GtkWidget* widget) { | |
517 Event event = new Event (); | |
518 if ((style & DWT.DROP_DOWN) !is 0) { | |
519 auto eventPtr = OS.gtk_get_current_event (); | |
520 if (eventPtr !is null) { | |
521 GdkEvent* gdkEvent = cast(GdkEvent*)eventPtr; | |
522 switch (gdkEvent.type) { | |
523 case OS.GDK_BUTTON_PRESS: | |
524 case OS.GDK_2BUTTON_PRESS: | |
525 case OS.GDK_BUTTON_RELEASE: { | |
526 double x_win; | |
527 double y_win; | |
528 OS.gdk_event_get_coords (eventPtr, &x_win, &y_win); | |
529 int x = OS.GTK_WIDGET_X (arrowHandle) - OS.GTK_WIDGET_X (handle); | |
530 int width = OS.GTK_WIDGET_WIDTH (arrowHandle); | |
240 | 531 if ((((parent.style & DWT.RIGHT_TO_LEFT) is 0) && x <= cast(int)x_win) |
532 || (((parent.style & DWT.RIGHT_TO_LEFT) !is 0) && cast(int)x_win <= x + width)) { | |
75 | 533 event.detail = DWT.ARROW; |
534 auto topHandle = topHandle (); | |
535 event.x = OS.GTK_WIDGET_X (topHandle); | |
240 | 536 if ((parent.style & DWT.MIRRORED) !is 0) event.x = parent.getClientWidth () - OS.GTK_WIDGET_WIDTH (topHandle) - event.x; |
75 | 537 event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle); |
538 } | |
539 break; | |
540 } | |
541 default: | |
542 } | |
543 OS.gdk_event_free (eventPtr); | |
544 } | |
545 } | |
546 if ((style & DWT.RADIO) !is 0) { | |
547 if ((parent.getStyle () & DWT.NO_RADIO_GROUP) is 0) { | |
548 selectRadio (); | |
549 } | |
550 } | |
551 postEvent (DWT.Selection, event); | |
552 return 0; | |
553 } | |
554 | |
555 override int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
556 parent.gtk_enter_notify_event (widget, event); | |
557 drawHotImage = (parent.style & DWT.FLAT) !is 0 && hotImage !is null; | |
558 if (drawHotImage && imageHandle !is null) { | |
559 ImageList imageList = parent.imageList; | |
560 if (imageList !is null) { | |
561 int index = imageList.indexOf (hotImage); | |
562 if (index !is -1) { | |
563 auto pixbuf = imageList.getPixbuf (index); | |
564 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
565 } | |
566 } | |
567 } | |
568 return 0; | |
569 } | |
570 | |
571 override int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* gdkEvent) { | |
572 switch (gdkEvent.type) { | |
573 case OS.GDK_BUTTON_PRESS: { | |
574 GdkEventButton* gdkEventButton = cast(GdkEventButton*)gdkEvent; | |
575 if (gdkEventButton.button is 3) { | |
576 parent.showMenu (cast(int) gdkEventButton.x_root, cast(int) gdkEventButton.y_root); | |
577 } | |
578 break; | |
579 default: | |
580 } | |
581 } | |
582 return 0; | |
583 } | |
584 | |
585 override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { | |
586 OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
587 parent.lastFocus = this; | |
588 return 0; | |
589 } | |
590 | |
591 override int /*long*/ gtk_leave_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
592 parent.gtk_leave_notify_event (widget, event); | |
593 if (drawHotImage) { | |
594 drawHotImage = false; | |
595 if (imageHandle !is null && image !is null) { | |
596 ImageList imageList = parent.imageList; | |
597 if (imageList !is null) { | |
598 int index = imageList.indexOf (image); | |
599 if (index !is -1) { | |
600 auto pixbuf = imageList.getPixbuf (index); | |
601 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
602 } | |
603 } | |
604 } | |
605 } | |
606 return 0; | |
607 } | |
608 | |
609 override int /*long*/ gtk_map (GtkWidget* widget) { | |
610 parent.fixZOrder (); | |
611 return 0; | |
612 } | |
613 | |
614 override int /*long*/ gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) { | |
615 return parent.gtk_mnemonic_activate (widget, arg1); | |
616 } | |
617 | |
618 bool hasFocus () { | |
619 return OS.GTK_WIDGET_HAS_FOCUS (handle); | |
620 } | |
621 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
622 override void hookEvents () { |
75 | 623 super.hookEvents (); |
624 if ((style & DWT.SEPARATOR) !is 0) return; | |
625 OS.g_signal_connect_closure (handle, OS.clicked.ptr, display.closures [CLICKED], false); | |
626 OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); | |
627 OS.g_signal_connect_closure_by_id (handle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); | |
628 if (labelHandle !is null) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); | |
629 | |
630 OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); | |
631 | |
632 /* | |
633 * Feature in GTK. Usually, GTK widgets propagate all events to their | |
634 * parent when they are done their own processing. However, in contrast | |
635 * to other widgets, the buttons that make up the tool items, do not propagate | |
636 * the mouse up/down events. It is interesting to note that they DO propagate | |
637 * mouse motion events. The fix is to explicitly forward mouse up/down events | |
638 * to the parent. | |
639 */ | |
640 int mask = | |
641 OS.GDK_EXPOSURE_MASK | OS.GDK_POINTER_MOTION_MASK | | |
642 OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | | |
643 OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | | |
644 OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | | |
645 OS.GDK_FOCUS_CHANGE_MASK; | |
646 OS.gtk_widget_add_events (handle, mask); | |
647 OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); | |
648 OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); | |
649 OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures[EVENT_AFTER], false); | |
650 | |
651 auto topHandle = topHandle (); | |
652 OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true); | |
653 } | |
654 | |
655 /** | |
656 * Returns <code>true</code> if the receiver is enabled and all | |
657 * of the receiver's ancestors are enabled, and <code>false</code> | |
658 * otherwise. A disabled control is typically not selectable from the | |
659 * user interface and draws with an inactive or "grayed" look. | |
660 * | |
661 * @return the receiver's enabled state | |
662 * | |
663 * @exception DWTException <ul> | |
664 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
665 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
666 * </ul> | |
667 * | |
668 * @see #getEnabled | |
669 */ | |
670 public bool isEnabled () { | |
671 checkWidget(); | |
672 return getEnabled () && parent.isEnabled (); | |
673 } | |
674 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
675 override void register () { |
75 | 676 super.register (); |
677 if (labelHandle !is null) display.addWidget (labelHandle, this); | |
678 } | |
679 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
680 override void releaseHandle () { |
75 | 681 super.releaseHandle (); |
682 boxHandle = arrowHandle = separatorHandle = labelHandle = imageHandle = null; | |
683 } | |
684 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
685 override void releaseWidget () { |
75 | 686 super.releaseWidget (); |
687 if (parent.lastFocus is this) parent.lastFocus = null; | |
688 parent = null; | |
689 control = null; | |
690 hotImage = disabledImage = null; | |
691 toolTipText = null; | |
692 } | |
693 | |
694 /** | |
695 * Removes the listener from the collection of listeners who will | |
696 * be notified when the control is selected by the user. | |
697 * | |
698 * @param listener the listener which should no longer be notified | |
699 * | |
700 * @exception IllegalArgumentException <ul> | |
701 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
702 * </ul> | |
703 * @exception DWTException <ul> | |
704 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
705 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
706 * </ul> | |
707 * | |
708 * @see SelectionListener | |
709 * @see #addSelectionListener | |
710 */ | |
711 public void removeSelectionListener(SelectionListener listener) { | |
712 checkWidget(); | |
713 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
714 if (eventTable is null) return; | |
715 eventTable.unhook (DWT.Selection, listener); | |
716 eventTable.unhook (DWT.DefaultSelection,listener); | |
717 } | |
718 | |
719 void resizeControl () { | |
720 if (control !is null && !control.isDisposed ()) { | |
721 if (separatorHandle !is null) OS.gtk_widget_hide (separatorHandle); | |
722 /* | |
723 * Set the size and location of the control | |
724 * separately to minimize flashing in the | |
725 * case where the control does not resize | |
726 * to the size that was requested. This | |
727 * case can occur when the control is a | |
728 * combo box. | |
729 */ | |
730 Rectangle itemRect = getBounds (); | |
731 control.setSize (itemRect.width, itemRect.height); | |
240 | 732 OS.gtk_widget_set_size_request (handle, itemRect.width, itemRect.height); |
75 | 733 Rectangle rect = control.getBounds (); |
734 rect.x = itemRect.x + (itemRect.width - rect.width) / 2; | |
735 rect.y = itemRect.y + (itemRect.height - rect.height) / 2; | |
736 control.setLocation (rect.x, rect.y); | |
737 } else { | |
738 if (separatorHandle !is null) OS.gtk_widget_show (separatorHandle); | |
739 } | |
740 } | |
741 | |
742 void selectRadio () { | |
743 int index = 0; | |
744 ToolItem [] items = parent.getItems (); | |
745 while (index < items.length && items [index] !is this) index++; | |
746 int i = index - 1; | |
747 while (i >= 0 && items [i].setRadioSelection (false)) --i; | |
748 int j = index + 1; | |
749 while (j < items.length && items [j].setRadioSelection (false)) j++; | |
750 setSelection (true); | |
751 } | |
752 | |
753 /** | |
754 * Sets the control that is used to fill the bounds of | |
755 * the item when the item is a <code>SEPARATOR</code>. | |
756 * | |
757 * @param control the new control | |
758 * | |
759 * @exception IllegalArgumentException <ul> | |
760 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> | |
761 * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> | |
762 * </ul> | |
763 * @exception DWTException <ul> | |
764 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
765 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
766 * </ul> | |
767 */ | |
768 public void setControl (Control control) { | |
769 checkWidget (); | |
770 if (control !is null) { | |
771 if (control.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); | |
772 if (control.parent !is parent) error (DWT.ERROR_INVALID_PARENT); | |
773 } | |
774 if ((style & DWT.SEPARATOR) is 0) return; | |
775 if (this.control is control) return; | |
776 this.control = control; | |
777 parent.relayout (); | |
778 } | |
779 | |
780 /** | |
781 * Sets the receiver's disabled image to the argument, which may be | |
782 * null indicating that no disabled image should be displayed. | |
783 * <p> | |
784 * The disabled image is displayed when the receiver is disabled. | |
785 * </p> | |
786 * | |
787 * @param image the disabled image to display on the receiver (may be null) | |
788 * | |
789 * @exception IllegalArgumentException <ul> | |
790 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
791 * </ul> | |
792 * @exception DWTException <ul> | |
793 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
794 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
795 * </ul> | |
796 */ | |
797 public void setDisabledImage (Image image) { | |
798 checkWidget(); | |
799 if ((style & DWT.SEPARATOR) !is 0) return; | |
800 disabledImage = image; | |
801 } | |
802 | |
803 /** | |
804 * Enables the receiver if the argument is <code>true</code>, | |
805 * and disables it otherwise. | |
806 * <p> | |
807 * A disabled control is typically | |
808 * not selectable from the user interface and draws with an | |
809 * inactive or "grayed" look. | |
810 * </p> | |
811 * | |
812 * @param enabled the new enabled state | |
813 * | |
814 * @exception DWTException <ul> | |
815 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
816 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
817 * </ul> | |
818 */ | |
819 public void setEnabled (bool enabled) { | |
820 checkWidget(); | |
821 auto topHandle = topHandle (); | |
822 OS.gtk_widget_set_sensitive (topHandle, enabled); | |
823 if (enabled) { | |
824 /* | |
825 * Bug in GTK. GtkButton requires an enter notify before it | |
826 * allows the button to be pressed, but events are dropped when | |
827 * widgets are insensitive. The fix is to hide and show the | |
828 * button if the pointer is within its bounds. | |
829 */ | |
830 int x, y; | |
831 OS.gdk_window_get_pointer (parent.paintWindow (), &x, &y, null); | |
832 if (getBounds ().contains (x, y)) { | |
833 OS.gtk_widget_hide (handle); | |
834 OS.gtk_widget_show (handle); | |
835 } | |
836 } | |
837 } | |
838 | |
839 bool setFocus () { | |
840 if ((style & DWT.SEPARATOR) !is 0) return false; | |
841 if (!OS.gtk_widget_get_child_visible (handle)) return false; | |
842 OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
843 OS.gtk_widget_grab_focus (handle); | |
844 bool result = cast(bool)OS.gtk_widget_is_focus (handle); | |
845 if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
846 return result; | |
847 } | |
848 | |
849 void setFontDescription (PangoFontDescription* font) { | |
850 OS.gtk_widget_modify_font (handle, font); | |
851 if (labelHandle !is null) OS.gtk_widget_modify_font (labelHandle, font); | |
852 if (imageHandle !is null) OS.gtk_widget_modify_font (imageHandle, font); | |
853 } | |
854 | |
855 alias Item.setForegroundColor setForegroundColor; | |
856 void setForegroundColor (GdkColor* color) { | |
857 setForegroundColor (handle, color); | |
858 if (labelHandle !is null) setForegroundColor (labelHandle, color); | |
859 if (imageHandle !is null) setForegroundColor (imageHandle, color); | |
860 } | |
861 | |
862 /** | |
863 * Sets the receiver's hot image to the argument, which may be | |
864 * null indicating that no hot image should be displayed. | |
865 * <p> | |
866 * The hot image is displayed when the mouse enters the receiver. | |
867 * </p> | |
868 * | |
869 * @param image the hot image to display on the receiver (may be null) | |
870 * | |
871 * @exception IllegalArgumentException <ul> | |
872 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
873 * </ul> | |
874 * @exception DWTException <ul> | |
875 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
876 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
877 * </ul> | |
878 */ | |
879 public void setHotImage (Image image) { | |
880 checkWidget(); | |
881 if ((style & DWT.SEPARATOR) !is 0) return; | |
882 hotImage = image; | |
883 if (image !is null) { | |
884 ImageList imageList = parent.imageList; | |
885 if (imageList is null) imageList = parent.imageList = new ImageList (); | |
886 int imageIndex = imageList.indexOf (image); | |
887 if (imageIndex is -1) { | |
888 imageIndex = imageList.add (image); | |
889 } else { | |
890 imageList.put (imageIndex, image); | |
891 } | |
892 } | |
893 } | |
894 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
895 public override void setImage (Image image) { |
75 | 896 checkWidget(); |
897 if ((style & DWT.SEPARATOR) !is 0) return; | |
898 super.setImage (image); | |
899 if (imageHandle is null) return; | |
900 if (image !is null) { | |
901 ImageList imageList = parent.imageList; | |
902 if (imageList is null) imageList = parent.imageList = new ImageList (); | |
903 int imageIndex = imageList.indexOf (image); | |
904 if (imageIndex is -1) { | |
905 imageIndex = imageList.add (image); | |
906 } else { | |
907 imageList.put (imageIndex, image); | |
908 } | |
909 auto pixbuf = imageList.getPixbuf (imageIndex); | |
910 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
911 OS.gtk_widget_show (imageHandle); | |
912 } else { | |
913 OS.gtk_image_set_from_pixbuf (imageHandle, null); | |
914 OS.gtk_widget_hide (imageHandle); | |
915 } | |
916 parent.relayout (); | |
917 } | |
918 | |
919 void setOrientation () { | |
920 if ((parent.style & DWT.RIGHT_TO_LEFT) !is 0) { | |
921 if (handle !is null) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); | |
922 if (labelHandle !is null) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); | |
923 if (imageHandle !is null) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); | |
924 if (separatorHandle !is null) OS.gtk_widget_set_direction (separatorHandle, OS.GTK_TEXT_DIR_RTL); | |
925 if (arrowHandle !is null) OS.gtk_widget_set_direction (arrowHandle, OS.GTK_TEXT_DIR_RTL); | |
926 if (boxHandle !is null) OS.gtk_widget_set_direction (boxHandle, OS.GTK_TEXT_DIR_RTL); | |
927 if (arrowBoxHandle !is null) OS.gtk_widget_set_direction (arrowBoxHandle, OS.GTK_TEXT_DIR_RTL); | |
928 } | |
929 } | |
930 | |
931 bool setRadioSelection (bool value) { | |
932 if ((style & DWT.RADIO) is 0) return false; | |
933 if (getSelection () !is value) { | |
934 setSelection (value); | |
935 postEvent (DWT.Selection); | |
936 } | |
937 return true; | |
938 } | |
939 | |
940 /** | |
941 * Sets the selection state of the receiver. | |
942 * <p> | |
943 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, | |
944 * it is selected when it is checked (which some platforms draw as a | |
945 * pushed in button). | |
946 * </p> | |
947 * | |
948 * @param selected the new selection state | |
949 * | |
950 * @exception DWTException <ul> | |
951 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
952 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
953 * </ul> | |
954 */ | |
955 public void setSelection (bool selected) { | |
956 checkWidget (); | |
957 if ((style & (DWT.CHECK | DWT.RADIO)) is 0) return; | |
958 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCLICKED); | |
959 OS.gtk_toggle_button_set_active (handle, selected); | |
960 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCLICKED); | |
961 } | |
962 | |
963 /** | |
964 * Sets the receiver's text. The string may include | |
965 * the mnemonic character. | |
966 * </p> | |
967 * <p> | |
968 * Mnemonics are indicated by an '&' that causes the next | |
969 * character to be the mnemonic. When the user presses a | |
970 * key sequence that matches the mnemonic, a selection | |
971 * event occurs. On most platforms, the mnemonic appears | |
972 * underlined but may be emphasised in a platform specific | |
973 * manner. The mnemonic indicator character '&' can be | |
974 * escaped by doubling it in the string, causing a single | |
975 * '&' to be displayed. | |
976 * </p> | |
977 * | |
978 * @param string the new text | |
979 * | |
980 * @exception DWTException <ul> | |
981 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
982 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
983 * </ul> | |
984 */ | |
238 | 985 public override void setText (String string) { |
75 | 986 checkWidget(); |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
248
diff
changeset
|
987 // 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:
248
diff
changeset
|
988 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
75 | 989 if ((style & DWT.SEPARATOR) !is 0) return; |
990 super.setText (string); | |
991 if (labelHandle is null) return; | |
992 char [] chars = fixMnemonic (string); | |
248
34409a2fc053
Fix call OS.gtk_label_set_text_with_mnemonic with valid ptr, even for zero length strings.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
993 OS.gtk_label_set_text_with_mnemonic (labelHandle, chars.toStringzValidPtr()); |
75 | 994 if (string.length !is 0) { |
995 OS.gtk_widget_show (labelHandle); | |
996 } else { | |
997 OS.gtk_widget_hide (labelHandle); | |
998 } | |
999 parent.relayout (); | |
1000 } | |
1001 | |
1002 /** | |
1003 * Sets the receiver's tool tip text to the argument, which | |
1004 * may be null indicating that no tool tip text should be shown. | |
1005 * | |
1006 * @param string the new tool tip text (or null) | |
1007 * | |
1008 * @exception DWTException <ul> | |
1009 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1010 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1011 * </ul> | |
1012 */ | |
238 | 1013 public void setToolTipText (String string) { |
75 | 1014 checkWidget(); |
1015 if (parent.toolTipText is null) { | |
1016 Shell shell = parent._getShell (); | |
1017 setToolTipText (shell, string); | |
1018 } | |
1019 toolTipText = string; | |
1020 } | |
1021 | |
238 | 1022 void setToolTipText (Shell shell, String newString) { |
75 | 1023 shell.setToolTipText (handle, newString); |
1024 } | |
1025 | |
1026 /** | |
1027 * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems. | |
1028 * | |
1029 * @param width the new width | |
1030 * | |
1031 * @exception DWTException <ul> | |
1032 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1033 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1034 * </ul> | |
1035 */ | |
1036 public void setWidth (int width) { | |
1037 checkWidget(); | |
1038 if ((style & DWT.SEPARATOR) is 0) return; | |
1039 if (width < 0) return; | |
240 | 1040 bool isVertical = (parent.style & DWT.VERTICAL) !is 0; |
1041 OS.gtk_widget_set_size_request (separatorHandle, width, isVertical ? 6 : 15); | |
1042 OS.gtk_widget_set_size_request (handle, width, isVertical ? 6 : 15); | |
75 | 1043 parent.relayout (); |
1044 } | |
1045 | |
1046 void showWidget (int index) { | |
1047 if (handle !is null) OS.gtk_widget_show (handle); | |
1048 if (boxHandle !is null) OS.gtk_widget_show (boxHandle); | |
1049 if (separatorHandle !is null) OS.gtk_widget_show (separatorHandle); | |
1050 if (arrowBoxHandle !is null) OS.gtk_widget_show (arrowBoxHandle); | |
1051 if (arrowHandle !is null) OS.gtk_widget_show (arrowHandle); | |
1052 OS.gtk_toolbar_insert_widget (parent.handle, handle, null, null, index); | |
1053 } | |
1054 } |