Mercurial > projects > dwt-linux
annotate dwt/widgets/Decorations.d @ 58:a5c274fa5af9
extended helloworld crashing
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 12 Jan 2008 07:02:08 +0100 |
parents | 6e625fa1612d |
children | 8cec8f536af3 |
rev | line source |
---|---|
30 | 1 /******************************************************************************* |
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 | |
10 *******************************************************************************/ | |
11 module dwt.widgets.Decorations; | |
12 | |
13 import dwt.widgets.Control; | |
14 import dwt.widgets.Menu; | |
15 import dwt.widgets.Composite; | |
16 | |
37 | 17 import dwt.SWT; |
18 import dwt.internal.gtk.OS; | |
19 //import dwt.graphics.; | |
20 import dwt.widgets.Canvas; | |
21 import dwt.graphics.Image; | |
22 import dwt.graphics.ImageData; | |
23 import dwt.widgets.Control; | |
24 import dwt.widgets.Display; | |
25 import dwt.widgets.Widget; | |
26 import dwt.widgets.Button; | |
30 | 27 |
28 /** | |
29 * Instances of this class provide the appearance and | |
30 * behavior of <code>Shells</code>, but are not top | |
31 * level shells or dialogs. Class <code>Shell</code> | |
32 * shares a significant amount of code with this class, | |
33 * and is a subclass. | |
34 * <p> | |
35 * IMPORTANT: This class was intended to be abstract and | |
36 * should <em>never</em> be referenced or instantiated. | |
37 * Instead, the class <code>Shell</code> should be used. | |
38 * </p> | |
39 * <p> | |
40 * Instances are always displayed in one of the maximized, | |
41 * minimized or normal states: | |
42 * <ul> | |
43 * <li> | |
44 * When an instance is marked as <em>maximized</em>, the | |
45 * window manager will typically resize it to fill the | |
46 * entire visible area of the display, and the instance | |
47 * is usually put in a state where it can not be resized | |
48 * (even if it has style <code>RESIZE</code>) until it is | |
49 * no longer maximized. | |
50 * </li><li> | |
51 * When an instance is in the <em>normal</em> state (neither | |
52 * maximized or minimized), its appearance is controlled by | |
53 * the style constants which were specified when it was created | |
54 * and the restrictions of the window manager (see below). | |
55 * </li><li> | |
56 * When an instance has been marked as <em>minimized</em>, | |
57 * its contents (client area) will usually not be visible, | |
58 * and depending on the window manager, it may be | |
59 * "iconified" (that is, replaced on the desktop by a small | |
60 * simplified representation of itself), relocated to a | |
61 * distinguished area of the screen, or hidden. Combinations | |
62 * of these changes are also possible. | |
63 * </li> | |
64 * </ul> | |
65 * </p> | |
66 * Note: The styles supported by this class must be treated | |
67 * as <em>HINT</em>s, since the window manager for the | |
68 * desktop on which the instance is visible has ultimate | |
69 * control over the appearance and behavior of decorations. | |
70 * For example, some window managers only support resizable | |
71 * windows and will always assume the RESIZE style, even if | |
72 * it is not set. | |
73 * <dl> | |
74 * <dt><b>Styles:</b></dt> | |
75 * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd> | |
76 * <dt><b>Events:</b></dt> | |
77 * <dd>(none)</dd> | |
78 * </dl> | |
79 * Class <code>SWT</code> provides two "convenience constants" | |
80 * for the most commonly required style combinations: | |
81 * <dl> | |
82 * <dt><code>SHELL_TRIM</code></dt> | |
83 * <dd> | |
84 * the result of combining the constants which are required | |
85 * to produce a typical application top level shell: (that | |
86 * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>) | |
87 * </dd> | |
88 * <dt><code>DIALOG_TRIM</code></dt> | |
89 * <dd> | |
90 * the result of combining the constants which are required | |
91 * to produce a typical application dialog shell: (that | |
92 * is, <code>TITLE | CLOSE | BORDER</code>) | |
93 * </dd> | |
94 * </dl> | |
95 * <p> | |
96 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
97 * within the SWT implementation. | |
98 * </p> | |
99 * | |
100 * @see #getMinimized | |
101 * @see #getMaximized | |
102 * @see Shell | |
103 * @see SWT | |
104 */ | |
37 | 105 public class Decorations : Canvas { |
106 char[] text; | |
30 | 107 Image image; |
37 | 108 Image [] images; |
109 bool minimized, maximized; | |
30 | 110 Menu menuBar; |
111 Menu [] menus; | |
112 Control savedFocus; | |
113 Button defaultButton, saveDefault; | |
37 | 114 GtkAccelGroup* accelGroup; |
38 | 115 GtkWidget* vboxHandle; |
30 | 116 |
37 | 117 this () { |
30 | 118 /* Do nothing */ |
119 } | |
120 | |
121 /** | |
122 * Constructs a new instance of this class given its parent | |
123 * and a style value describing its behavior and appearance. | |
124 * <p> | |
125 * The style value is either one of the style constants defined in | |
126 * class <code>SWT</code> which is applicable to instances of this | |
127 * class, or must be built by <em>bitwise OR</em>'ing together | |
128 * (that is, using the <code>int</code> "|" operator) two or more | |
129 * of those <code>SWT</code> style constants. The class description | |
130 * lists the style constants that are applicable to the class. | |
131 * Style bits are also inherited from superclasses. | |
132 * </p> | |
133 * | |
134 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
135 * @param style the style of control to construct | |
136 * | |
137 * @exception IllegalArgumentException <ul> | |
138 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
139 * </ul> | |
140 * @exception SWTException <ul> | |
141 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
142 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
143 * </ul> | |
144 * | |
145 * @see SWT#BORDER | |
146 * @see SWT#CLOSE | |
147 * @see SWT#MIN | |
148 * @see SWT#MAX | |
149 * @see SWT#RESIZE | |
150 * @see SWT#TITLE | |
151 * @see SWT#NO_TRIM | |
152 * @see SWT#SHELL_TRIM | |
153 * @see SWT#DIALOG_TRIM | |
154 * @see SWT#ON_TOP | |
155 * @see SWT#TOOL | |
156 * @see Widget#checkSubclass | |
157 * @see Widget#getStyle | |
158 */ | |
37 | 159 public this (Composite parent, int style) { |
30 | 160 super (parent, checkStyle (style)); |
161 } | |
162 | |
163 static int checkStyle (int style) { | |
37 | 164 if ((style & SWT.NO_TRIM) !is 0) { |
30 | 165 style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER); |
166 } | |
37 | 167 if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) !is 0) { |
30 | 168 style |= SWT.TITLE; |
169 } | |
170 return style; | |
171 } | |
172 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
173 override protected void checkSubclass () { |
30 | 174 if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); |
175 } | |
176 | |
177 void _setImages (Image [] images) { | |
37 | 178 if (images !is null && images.length > 1) { |
30 | 179 Image [] bestImages = new Image [images.length]; |
180 System.arraycopy (images, 0, bestImages, 0, images.length); | |
181 sort (bestImages); | |
182 images = bestImages; | |
183 } | |
37 | 184 GList* pixbufs; |
185 if (images !is null) { | |
30 | 186 for (int i = 0; i < images.length; i++) { |
187 Image image = images [i]; | |
37 | 188 auto pixbuf = Display.createPixbuf (image); |
30 | 189 pixbufs = OS.g_list_append (pixbufs, pixbuf); |
190 } | |
191 } | |
37 | 192 OS.gtk_window_set_icon_list (cast(GtkWindow*)topHandle (), pixbufs); |
193 GList* data; | |
194 auto temp = pixbufs; | |
195 while (temp !is null) { | |
196 data = temp; | |
197 OS.g_object_unref (data); | |
198 temp = cast(GList*)OS.g_list_next (temp); | |
30 | 199 } |
37 | 200 if (pixbufs !is null) OS.g_list_free (pixbufs); |
30 | 201 } |
202 | |
203 void addMenu (Menu menu) { | |
37 | 204 if (menus is null) menus = new Menu [4]; |
30 | 205 for (int i=0; i<menus.length; i++) { |
37 | 206 if (menus [i] is null) { |
30 | 207 menus [i] = menu; |
208 return; | |
209 } | |
210 } | |
211 Menu [] newMenus = new Menu [menus.length + 4]; | |
212 newMenus [menus.length] = menu; | |
213 System.arraycopy (menus, 0, newMenus, 0, menus.length); | |
214 menus = newMenus; | |
215 } | |
216 | |
217 int compare (ImageData data1, ImageData data2) { | |
37 | 218 if (data1.width is data2.width && data1.height is data2.height) { |
30 | 219 int transparent1 = data1.getTransparencyType (); |
220 int transparent2 = data2.getTransparencyType (); | |
37 | 221 if (transparent1 is SWT.TRANSPARENCY_ALPHA) return -1; |
222 if (transparent2 is SWT.TRANSPARENCY_ALPHA) return 1; | |
223 if (transparent1 is SWT.TRANSPARENCY_MASK) return -1; | |
224 if (transparent2 is SWT.TRANSPARENCY_MASK) return 1; | |
225 if (transparent1 is SWT.TRANSPARENCY_PIXEL) return -1; | |
226 if (transparent2 is SWT.TRANSPARENCY_PIXEL) return 1; | |
30 | 227 return 0; |
228 } | |
229 return data1.width > data2.width || data1.height > data2.height ? -1 : 1; | |
230 } | |
231 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
232 override Control computeTabGroup () { |
30 | 233 return this; |
234 } | |
235 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
236 override Control computeTabRoot () { |
30 | 237 return this; |
238 } | |
239 | |
240 void createAccelGroup () { | |
37 | 241 if (accelGroup !is null) return; |
30 | 242 accelGroup = OS.gtk_accel_group_new (); |
37 | 243 if (accelGroup is null) SWT.error (SWT.ERROR_NO_HANDLES); |
30 | 244 //FIXME - what should we do for Decorations |
37 | 245 auto shellHandle = topHandle (); |
246 OS.gtk_window_add_accel_group (cast(GtkWindow*)shellHandle, accelGroup); | |
30 | 247 } |
248 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
249 override void createWidget (int index) { |
30 | 250 super.createWidget (index); |
251 text = ""; | |
252 } | |
253 | |
254 void destroyAccelGroup () { | |
37 | 255 if (accelGroup is null) return; |
256 auto shellHandle = topHandle (); | |
257 OS.gtk_window_remove_accel_group (cast(GtkWindow*)shellHandle, accelGroup); | |
30 | 258 //TEMPORARY CODE |
259 // OS.g_object_unref (accelGroup); | |
37 | 260 accelGroup = null; |
30 | 261 } |
262 | |
263 void fixAccelGroup () { | |
37 | 264 if (menuBar is null) return; |
30 | 265 destroyAccelGroup (); |
266 createAccelGroup (); | |
267 menuBar.addAccelerators (accelGroup); | |
268 } | |
269 | |
270 void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) { | |
37 | 271 if (this is newDecorations) return; |
272 if (control is savedFocus) savedFocus = null; | |
273 if (control is defaultButton) defaultButton = null; | |
274 if (control is saveDefault) saveDefault = null; | |
275 if (menus is null) return; | |
30 | 276 Menu menu = control.menu; |
37 | 277 if (menu !is null) { |
30 | 278 int index = 0; |
279 while (index <menus.length) { | |
37 | 280 if (menus [index] is menu) { |
30 | 281 control.setMenu (null); |
282 return; | |
283 } | |
284 index++; | |
285 } | |
286 menu.fixMenus (newDecorations); | |
287 } | |
288 } | |
289 | |
290 /** | |
291 * Returns the receiver's default button if one had | |
292 * previously been set, otherwise returns null. | |
293 * | |
294 * @return the default button or null | |
295 * | |
296 * @exception SWTException <ul> | |
297 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
298 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
299 * </ul> | |
300 * | |
301 * @see #setDefaultButton(Button) | |
302 */ | |
303 public Button getDefaultButton () { | |
304 checkWidget(); | |
37 | 305 return defaultButton !is null ? defaultButton : saveDefault; |
30 | 306 } |
307 | |
308 /** | |
309 * Returns the receiver's image if it had previously been | |
310 * set using <code>setImage()</code>. The image is typically | |
311 * displayed by the window manager when the instance is | |
312 * marked as iconified, and may also be displayed somewhere | |
313 * in the trim when the instance is in normal or maximized | |
314 * states. | |
315 * <p> | |
316 * Note: This method will return null if called before | |
317 * <code>setImage()</code> is called. It does not provide | |
318 * access to a window manager provided, "default" image | |
319 * even if one exists. | |
320 * </p> | |
321 * | |
322 * @return the image | |
323 * | |
324 * @exception SWTException <ul> | |
325 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
326 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
327 * </ul> | |
328 */ | |
329 public Image getImage () { | |
330 checkWidget (); | |
331 return image; | |
332 } | |
333 | |
334 /** | |
335 * Returns the receiver's images if they had previously been | |
336 * set using <code>setImages()</code>. Images are typically | |
337 * displayed by the window manager when the instance is | |
338 * marked as iconified, and may also be displayed somewhere | |
339 * in the trim when the instance is in normal or maximized | |
340 * states. Depending where the icon is displayed, the platform | |
341 * chooses the icon with the "best" attributes. It is expected | |
342 * that the array will contain the same icon rendered at different | |
343 * sizes, with different depth and transparency attributes. | |
344 * | |
345 * <p> | |
346 * Note: This method will return an empty array if called before | |
347 * <code>setImages()</code> is called. It does not provide | |
348 * access to a window manager provided, "default" image | |
349 * even if one exists. | |
350 * </p> | |
351 * | |
352 * @return the images | |
353 * | |
354 * @exception SWTException <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 * @since 3.0 | |
360 */ | |
361 public Image [] getImages () { | |
362 checkWidget (); | |
37 | 363 if (images is null) return new Image [0]; |
30 | 364 Image [] result = new Image [images.length]; |
365 System.arraycopy (images, 0, result, 0, images.length); | |
366 return result; | |
367 } | |
368 | |
369 /** | |
370 * Returns <code>true</code> if the receiver is currently | |
371 * maximized, and false otherwise. | |
372 * <p> | |
373 * | |
374 * @return the maximized state | |
375 * | |
376 * @exception SWTException <ul> | |
377 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
378 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
379 * </ul> | |
380 * | |
381 * @see #setMaximized | |
382 */ | |
37 | 383 public bool getMaximized () { |
30 | 384 checkWidget(); |
385 return maximized; | |
386 } | |
387 | |
388 /** | |
389 * Returns the receiver's menu bar if one had previously | |
390 * been set, otherwise returns null. | |
391 * | |
392 * @return the menu bar or null | |
393 * | |
394 * @exception SWTException <ul> | |
395 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
396 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
397 * </ul> | |
398 */ | |
399 public Menu getMenuBar () { | |
400 checkWidget(); | |
401 return menuBar; | |
402 } | |
403 | |
404 /** | |
405 * Returns <code>true</code> if the receiver is currently | |
406 * minimized, and false otherwise. | |
407 * <p> | |
408 * | |
409 * @return the minimized state | |
410 * | |
411 * @exception SWTException <ul> | |
412 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
413 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
414 * </ul> | |
415 * | |
416 * @see #setMinimized | |
417 */ | |
37 | 418 public bool getMinimized () { |
30 | 419 checkWidget(); |
420 return minimized; | |
421 } | |
422 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
423 override char[] getNameText () { |
30 | 424 return getText (); |
425 } | |
426 | |
427 /** | |
428 * Returns the receiver's text, which is the string that the | |
429 * window manager will typically display as the receiver's | |
430 * <em>title</em>. If the text has not previously been set, | |
431 * returns an empty string. | |
432 * | |
433 * @return the text | |
434 * | |
435 * @exception SWTException <ul> | |
436 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
437 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
438 * </ul> | |
439 */ | |
37 | 440 public char[] getText () { |
30 | 441 checkWidget(); |
442 return text; | |
443 } | |
444 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
445 override public bool isReparentable () { |
30 | 446 checkWidget (); |
447 return false; | |
448 } | |
449 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
450 override bool isTabGroup () { |
30 | 451 return true; |
452 } | |
453 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
454 override bool isTabItem () { |
30 | 455 return false; |
456 } | |
457 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
458 override Decorations menuShell () { |
30 | 459 return this; |
460 } | |
461 | |
462 void removeMenu (Menu menu) { | |
37 | 463 if (menus is null) return; |
30 | 464 for (int i=0; i<menus.length; i++) { |
37 | 465 if (menus [i] is menu) { |
30 | 466 menus [i] = null; |
467 return; | |
468 } | |
469 } | |
470 } | |
471 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
472 override void releaseChildren (bool destroy) { |
37 | 473 if (menuBar !is null) { |
30 | 474 menuBar.release (false); |
475 menuBar = null; | |
476 } | |
477 super.releaseChildren (destroy); | |
37 | 478 if (menus !is null) { |
30 | 479 for (int i=0; i<menus.length; i++) { |
480 Menu menu = menus [i]; | |
37 | 481 if (menu !is null && !menu.isDisposed ()) { |
30 | 482 menu.dispose (); |
483 } | |
484 } | |
485 menus = null; | |
486 } | |
487 } | |
488 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
489 override void releaseHandle () { |
30 | 490 super.releaseHandle (); |
38 | 491 vboxHandle = null; |
30 | 492 } |
493 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
494 override void releaseWidget () { |
30 | 495 super.releaseWidget (); |
496 image = null; | |
497 images = null; | |
498 savedFocus = null; | |
499 defaultButton = saveDefault = null; | |
500 } | |
501 | |
37 | 502 bool restoreFocus () { |
503 if (savedFocus !is null && savedFocus.isDisposed ()) savedFocus = null; | |
504 bool restored = savedFocus !is null && savedFocus.setFocus (); | |
30 | 505 savedFocus = null; |
506 /* | |
507 * This code is intentionally commented. When no widget | |
508 * has been given focus, some platforms give focus to the | |
509 * default button. Motif doesn't do this. | |
510 */ | |
511 // if (restored) return true; | |
37 | 512 // if (defaultButton !is null && !defaultButton.isDisposed ()) { |
30 | 513 // if (defaultButton.setFocus ()) return true; |
514 // } | |
515 // return false; | |
516 return restored; | |
517 } | |
518 | |
519 /** | |
520 * If the argument is not null, sets the receiver's default | |
521 * button to the argument, and if the argument is null, sets | |
522 * the receiver's default button to the first button which | |
523 * was set as the receiver's default button (called the | |
524 * <em>saved default button</em>). If no default button had | |
525 * previously been set, or the saved default button was | |
526 * disposed, the receiver's default button will be set to | |
527 * null. | |
528 * <p> | |
529 * The default button is the button that is selected when | |
530 * the receiver is active and the user presses ENTER. | |
531 * </p> | |
532 * | |
533 * @param button the new default button | |
534 * | |
535 * @exception IllegalArgumentException <ul> | |
536 * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li> | |
537 * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> | |
538 * </ul> | |
539 * @exception SWTException <ul> | |
540 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
541 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
542 * </ul> | |
543 */ | |
544 public void setDefaultButton (Button button) { | |
545 checkWidget(); | |
37 | 546 GtkWidget* buttonHandle; |
547 if (button !is null) { | |
30 | 548 if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); |
37 | 549 if (button.menuShell () !is this) error (SWT.ERROR_INVALID_PARENT); |
30 | 550 buttonHandle = button.handle; |
551 } | |
552 saveDefault = defaultButton = button; | |
37 | 553 OS.gtk_window_set_default (cast(GtkWindow*)topHandle (), buttonHandle); |
30 | 554 } |
555 | |
556 /** | |
557 * Sets the receiver's image to the argument, which may | |
558 * be null. The image is typically displayed by the window | |
559 * manager when the instance is marked as iconified, and | |
560 * may also be displayed somewhere in the trim when the | |
561 * instance is in normal or maximized states. | |
562 * | |
563 * @param image the new image (or null) | |
564 * | |
565 * @exception IllegalArgumentException <ul> | |
566 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
567 * </ul> | |
568 * @exception SWTException <ul> | |
569 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
570 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
571 * </ul> | |
572 */ | |
573 public void setImage (Image image) { | |
574 checkWidget (); | |
575 this.image = image; | |
37 | 576 _setImages (image !is null ? [image] : null); |
30 | 577 } |
578 | |
579 /** | |
580 * Sets the receiver's images to the argument, which may | |
581 * be an empty array. Images are typically displayed by the | |
582 * window manager when the instance is marked as iconified, | |
583 * and may also be displayed somewhere in the trim when the | |
584 * instance is in normal or maximized states. Depending where | |
585 * the icon is displayed, the platform chooses the icon with | |
586 * the "best" attributes. It is expected that the array will | |
587 * contain the same icon rendered at different sizes, with | |
588 * different depth and transparency attributes. | |
589 * | |
590 * @param images the new image array | |
591 * | |
592 * @exception IllegalArgumentException <ul> | |
593 * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li> | |
594 * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li> | |
595 * </ul> | |
596 * @exception SWTException <ul> | |
597 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
598 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
599 * </ul> | |
600 * | |
601 * @since 3.0 | |
602 */ | |
603 public void setImages (Image [] images) { | |
604 checkWidget (); | |
37 | 605 if (images is null) error (SWT.ERROR_INVALID_ARGUMENT); |
30 | 606 for (int i = 0; i < images.length; i++) { |
37 | 607 if (images [i] is null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); |
30 | 608 } |
609 this.images = images; | |
610 _setImages (images); | |
611 } | |
612 | |
613 /** | |
614 * Sets the maximized state of the receiver. | |
615 * If the argument is <code>true</code> causes the receiver | |
616 * to switch to the maximized state, and if the argument is | |
617 * <code>false</code> and the receiver was previously maximized, | |
618 * causes the receiver to switch back to either the minimized | |
619 * or normal states. | |
620 * <p> | |
621 * Note: The result of intermixing calls to <code>setMaximized(true)</code> | |
622 * and <code>setMinimized(true)</code> will vary by platform. Typically, | |
623 * the behavior will match the platform user's expectations, but not | |
624 * always. This should be avoided if possible. | |
625 * </p> | |
626 * | |
627 * @param maximized the new maximized state | |
628 * | |
629 * @exception SWTException <ul> | |
630 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
631 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
632 * </ul> | |
633 * | |
634 * @see #setMinimized | |
635 */ | |
37 | 636 public void setMaximized (bool maximized) { |
30 | 637 checkWidget(); |
638 this.maximized = maximized; | |
639 } | |
640 | |
641 /** | |
642 * Sets the receiver's menu bar to the argument, which | |
643 * may be null. | |
644 * | |
645 * @param menu the new menu bar | |
646 * | |
647 * @exception IllegalArgumentException <ul> | |
648 * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li> | |
649 * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li> | |
650 * </ul> | |
651 * @exception SWTException <ul> | |
652 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
653 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
654 * </ul> | |
655 */ | |
656 public void setMenuBar (Menu menu) { | |
657 checkWidget(); | |
37 | 658 if (menuBar is menu) return; |
659 if (menu !is null) { | |
660 if ((menu.style & SWT.BAR) is 0) error (SWT.ERROR_MENU_NOT_BAR); | |
661 if (menu.parent !is this) error (SWT.ERROR_INVALID_PARENT); | |
30 | 662 } |
663 menuBar = menu; | |
664 } | |
665 | |
666 /** | |
667 * Sets the minimized stated of the receiver. | |
668 * If the argument is <code>true</code> causes the receiver | |
669 * to switch to the minimized state, and if the argument is | |
670 * <code>false</code> and the receiver was previously minimized, | |
671 * causes the receiver to switch back to either the maximized | |
672 * or normal states. | |
673 * <p> | |
674 * Note: The result of intermixing calls to <code>setMaximized(true)</code> | |
675 * and <code>setMinimized(true)</code> will vary by platform. Typically, | |
676 * the behavior will match the platform user's expectations, but not | |
677 * always. This should be avoided if possible. | |
678 * </p> | |
679 * | |
680 * @param minimized the new maximized state | |
681 * | |
682 * @exception SWTException <ul> | |
683 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
684 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
685 * </ul> | |
686 * | |
687 * @see #setMaximized | |
688 */ | |
37 | 689 public void setMinimized (bool minimized) { |
30 | 690 checkWidget(); |
691 this.minimized = minimized; | |
692 } | |
693 | |
694 void setSavedFocus (Control control) { | |
37 | 695 if (this is control) return; |
30 | 696 savedFocus = control; |
697 } | |
698 | |
699 /** | |
700 * Sets the receiver's text, which is the string that the | |
701 * window manager will typically display as the receiver's | |
702 * <em>title</em>, to the argument, which must not be null. | |
703 * | |
704 * @param string the new text | |
705 * | |
706 * @exception IllegalArgumentException <ul> | |
707 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
708 * </ul> | |
709 * @exception SWTException <ul> | |
710 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
711 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
712 * </ul> | |
713 */ | |
37 | 714 public void setText (char[] string) { |
30 | 715 checkWidget(); |
37 | 716 if (string is null) error (SWT.ERROR_NULL_ARGUMENT); |
30 | 717 text = string; |
718 } | |
719 | |
720 void sort (Image [] images) { | |
721 /* Shell Sort from K&R, pg 108 */ | |
722 int length = images.length; | |
723 if (length <= 1) return; | |
724 ImageData [] datas = new ImageData [length]; | |
725 for (int i = 0; i < length; i++) { | |
726 datas [i] = images [i].getImageData (); | |
727 } | |
728 for (int gap=length/2; gap>0; gap/=2) { | |
729 for (int i=gap; i<length; i++) { | |
730 for (int j=i-gap; j>=0; j-=gap) { | |
731 if (compare (datas [j], datas [j + gap]) >= 0) { | |
732 Image swap = images [j]; | |
733 images [j] = images [j + gap]; | |
734 images [j + gap] = swap; | |
735 ImageData swapData = datas [j]; | |
736 datas [j] = datas [j + gap]; | |
737 datas [j + gap] = swapData; | |
738 } | |
739 } | |
740 } | |
741 } | |
742 } | |
743 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
744 override bool traverseItem (bool next) { |
30 | 745 return false; |
746 } | |
747 | |
58
a5c274fa5af9
extended helloworld crashing
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
748 override bool traverseReturn () { |
37 | 749 Button button = defaultButton !is null ? defaultButton: saveDefault; |
750 if (button is null || button.isDisposed ()) return false; | |
30 | 751 /* |
752 * Bug in GTK. When a default button that is disabled is | |
753 * activated using the Enter key, GTK GP's. The fix is to | |
754 * detect this case and stop GTK from processing the Enter | |
755 * key. | |
756 */ | |
757 if (!button.isVisible () || !button.isEnabled ()) return true; | |
37 | 758 auto shellHandle = _getShell ().topHandle (); |
759 return cast(bool)OS.gtk_window_activate_default (cast(GtkWindow*)shellHandle); | |
30 | 760 } |
761 | |
762 } |