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