comparison dwt/widgets/Shell.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 649b8e223d5a
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
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.Shell;
12
13 import dwt.dwthelper.utils;
14
15 import dwt.DWT;
16 import dwt.DWTException;
17 import dwt.events.ShellListener;
18 import dwt.graphics.Cursor;
19 import dwt.graphics.GC;
20 import dwt.graphics.Point;
21 import dwt.graphics.Rectangle;
22 import dwt.graphics.Region;
23 import dwt.internal.cocoa.NSEvent;
24 import dwt.internal.cocoa.NSPoint;
25 import dwt.internal.cocoa.NSRect;
26 import dwt.internal.cocoa.NSScrollView;
27 import dwt.internal.cocoa.NSSize;
28 import dwt.internal.cocoa.NSString;
29 import dwt.internal.cocoa.NSView;
30 import dwt.internal.cocoa.NSWindow;
31 import dwt.internal.cocoa.OS;
32 import dwt.internal.cocoa.SWTWindow;
33 import dwt.internal.cocoa.SWTWindowDelegate;
34
35 /**
36 * Instances of this class represent the "windows"
37 * which the desktop or "window manager" is managing.
38 * Instances that do not have a parent (that is, they
39 * are built using the constructor, which takes a
40 * <code>Display</code> as the argument) are described
41 * as <em>top level</em> shells. Instances that do have
42 * a parent are described as <em>secondary</em> or
43 * <em>dialog</em> shells.
44 * <p>
45 * Instances are always displayed in one of the maximized,
46 * minimized or normal states:
47 * <ul>
48 * <li>
49 * When an instance is marked as <em>maximized</em>, the
50 * window manager will typically resize it to fill the
51 * entire visible area of the display, and the instance
52 * is usually put in a state where it can not be resized
53 * (even if it has style <code>RESIZE</code>) until it is
54 * no longer maximized.
55 * </li><li>
56 * When an instance is in the <em>normal</em> state (neither
57 * maximized or minimized), its appearance is controlled by
58 * the style constants which were specified when it was created
59 * and the restrictions of the window manager (see below).
60 * </li><li>
61 * When an instance has been marked as <em>minimized</em>,
62 * its contents (client area) will usually not be visible,
63 * and depending on the window manager, it may be
64 * "iconified" (that is, replaced on the desktop by a small
65 * simplified representation of itself), relocated to a
66 * distinguished area of the screen, or hidden. Combinations
67 * of these changes are also possible.
68 * </li>
69 * </ul>
70 * </p><p>
71 * The <em>modality</em> of an instance may be specified using
72 * style bits. The modality style bits are used to determine
73 * whether input is blocked for other shells on the display.
74 * The <code>PRIMARY_MODAL</code> style allows an instance to block
75 * input to its parent. The <code>APPLICATION_MODAL</code> style
76 * allows an instance to block input to every other shell in the
77 * display. The <code>SYSTEM_MODAL</code> style allows an instance
78 * to block input to all shells, including shells belonging to
79 * different applications.
80 * </p><p>
81 * Note: The styles supported by this class are treated
82 * as <em>HINT</em>s, since the window manager for the
83 * desktop on which the instance is visible has ultimate
84 * control over the appearance and behavior of decorations
85 * and modality. For example, some window managers only
86 * support resizable windows and will always assume the
87 * RESIZE style, even if it is not set. In addition, if a
88 * modality style is not supported, it is "upgraded" to a
89 * more restrictive modality style that is supported. For
90 * example, if <code>PRIMARY_MODAL</code> is not supported,
91 * it would be upgraded to <code>APPLICATION_MODAL</code>.
92 * A modality style may also be "downgraded" to a less
93 * restrictive style. For example, most operating systems
94 * no longer support <code>SYSTEM_MODAL</code> because
95 * it can freeze up the desktop, so this is typically
96 * downgraded to <code>APPLICATION_MODAL</code>.
97 * <dl>
98 * <dt><b>Styles:</b></dt>
99 * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
100 * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
101 * <dt><b>Events:</b></dt>
102 * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
103 * </dl>
104 * Class <code>DWT</code> provides two "convenience constants"
105 * for the most commonly required style combinations:
106 * <dl>
107 * <dt><code>SHELL_TRIM</code></dt>
108 * <dd>
109 * the result of combining the constants which are required
110 * to produce a typical application top level shell: (that
111 * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
112 * </dd>
113 * <dt><code>DIALOG_TRIM</code></dt>
114 * <dd>
115 * the result of combining the constants which are required
116 * to produce a typical application dialog shell: (that
117 * is, <code>TITLE | CLOSE | BORDER</code>)
118 * </dd>
119 * </dl>
120 * </p>
121 * <p>
122 * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
123 * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
124 * </p><p>
125 * IMPORTANT: This class is not intended to be subclassed.
126 * </p>
127 *
128 * @see Decorations
129 * @see DWT
130 */
131 public class Shell extends Decorations {
132 NSWindow window;
133 SWTWindowDelegate windowDelegate;
134 bool opened, moved, resized, fullScreen;
135 // bool resized, moved, drawing, reshape, update, deferDispose, active, disposed, opened, fullScreen;
136 Control lastActive;
137 Region region;
138 Rectangle normalBounds;
139
140 static int DEFAULT_CLIENT_WIDTH = -1;
141 static int DEFAULT_CLIENT_HEIGHT = -1;
142
143 /**
144 * Constructs a new instance of this class. This is equivalent
145 * to calling <code>Shell((Display) null)</code>.
146 *
147 * @exception DWTException <ul>
148 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
149 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
150 * </ul>
151 */
152 public Shell () {
153 this ((Display) null);
154 }
155
156 /**
157 * Constructs a new instance of this class given only the style
158 * value describing its behavior and appearance. This is equivalent
159 * to calling <code>Shell((Display) null, style)</code>.
160 * <p>
161 * The style value is either one of the style constants defined in
162 * class <code>DWT</code> which is applicable to instances of this
163 * class, or must be built by <em>bitwise OR</em>'ing together
164 * (that is, using the <code>int</code> "|" operator) two or more
165 * of those <code>DWT</code> style constants. The class description
166 * lists the style constants that are applicable to the class.
167 * Style bits are also inherited from superclasses.
168 * </p>
169 *
170 * @param style the style of control to construct
171 *
172 * @exception DWTException <ul>
173 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
174 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
175 * </ul>
176 *
177 * @see DWT#BORDER
178 * @see DWT#CLOSE
179 * @see DWT#MIN
180 * @see DWT#MAX
181 * @see DWT#RESIZE
182 * @see DWT#TITLE
183 * @see DWT#NO_TRIM
184 * @see DWT#SHELL_TRIM
185 * @see DWT#DIALOG_TRIM
186 * @see DWT#MODELESS
187 * @see DWT#PRIMARY_MODAL
188 * @see DWT#APPLICATION_MODAL
189 * @see DWT#SYSTEM_MODAL
190 */
191 public Shell (int style) {
192 this ((Display) null, style);
193 }
194
195 /**
196 * Constructs a new instance of this class given only the display
197 * to create it on. It is created with style <code>DWT.SHELL_TRIM</code>.
198 * <p>
199 * Note: Currently, null can be passed in for the display argument.
200 * This has the effect of creating the shell on the currently active
201 * display if there is one. If there is no current display, the
202 * shell is created on a "default" display. <b>Passing in null as
203 * the display argument is not considered to be good coding style,
204 * and may not be supported in a future release of DWT.</b>
205 * </p>
206 *
207 * @param display the display to create the shell on
208 *
209 * @exception DWTException <ul>
210 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
211 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
212 * </ul>
213 */
214 public Shell (Display display) {
215 this (display, DWT.SHELL_TRIM);
216 }
217
218 /**
219 * Constructs a new instance of this class given the display
220 * to create it on and a style value describing its behavior
221 * and appearance.
222 * <p>
223 * The style value is either one of the style constants defined in
224 * class <code>DWT</code> which is applicable to instances of this
225 * class, or must be built by <em>bitwise OR</em>'ing together
226 * (that is, using the <code>int</code> "|" operator) two or more
227 * of those <code>DWT</code> style constants. The class description
228 * lists the style constants that are applicable to the class.
229 * Style bits are also inherited from superclasses.
230 * </p><p>
231 * Note: Currently, null can be passed in for the display argument.
232 * This has the effect of creating the shell on the currently active
233 * display if there is one. If there is no current display, the
234 * shell is created on a "default" display. <b>Passing in null as
235 * the display argument is not considered to be good coding style,
236 * and may not be supported in a future release of DWT.</b>
237 * </p>
238 *
239 * @param display the display to create the shell on
240 * @param style the style of control to construct
241 *
242 * @exception DWTException <ul>
243 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
244 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
245 * </ul>
246 *
247 * @see DWT#BORDER
248 * @see DWT#CLOSE
249 * @see DWT#MIN
250 * @see DWT#MAX
251 * @see DWT#RESIZE
252 * @see DWT#TITLE
253 * @see DWT#NO_TRIM
254 * @see DWT#SHELL_TRIM
255 * @see DWT#DIALOG_TRIM
256 * @see DWT#MODELESS
257 * @see DWT#PRIMARY_MODAL
258 * @see DWT#APPLICATION_MODAL
259 * @see DWT#SYSTEM_MODAL
260 */
261 public Shell (Display display, int style) {
262 this (display, null, style, 0, false);
263 }
264
265 Shell (Display display, Shell parent, int style, int handle, bool embedded) {
266 super ();
267 checkSubclass ();
268 if (display is null) display = Display.getCurrent ();
269 if (display is null) display = Display.getDefault ();
270 if (!display.isValidThread ()) {
271 error (DWT.ERROR_THREAD_INVALID_ACCESS);
272 }
273 if (parent !is null && parent.isDisposed ()) {
274 error (DWT.ERROR_INVALID_ARGUMENT);
275 }
276 this.style = checkStyle (style);
277 this.parent = parent;
278 this.display = display;
279 if (handle !is 0) {
280 if (embedded) {
281 view = new NSView(handle);
282 } else {
283 window = new NSWindow(handle);
284 state |= FOREIGN_HANDLE;
285 }
286 }
287 createWidget ();
288 }
289
290 /**
291 * Constructs a new instance of this class given only its
292 * parent. It is created with style <code>DWT.DIALOG_TRIM</code>.
293 * <p>
294 * Note: Currently, null can be passed in for the parent.
295 * This has the effect of creating the shell on the currently active
296 * display if there is one. If there is no current display, the
297 * shell is created on a "default" display. <b>Passing in null as
298 * the parent is not considered to be good coding style,
299 * and may not be supported in a future release of DWT.</b>
300 * </p>
301 *
302 * @param parent a shell which will be the parent of the new instance
303 *
304 * @exception IllegalArgumentException <ul>
305 * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
306 * </ul>
307 * @exception DWTException <ul>
308 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
309 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
310 * </ul>
311 */
312 public Shell (Shell parent) {
313 this (parent, DWT.DIALOG_TRIM);
314 }
315
316 /**
317 * Constructs a new instance of this class given its parent
318 * and a style value describing its behavior and appearance.
319 * <p>
320 * The style value is either one of the style constants defined in
321 * class <code>DWT</code> which is applicable to instances of this
322 * class, or must be built by <em>bitwise OR</em>'ing together
323 * (that is, using the <code>int</code> "|" operator) two or more
324 * of those <code>DWT</code> style constants. The class description
325 * lists the style constants that are applicable to the class.
326 * Style bits are also inherited from superclasses.
327 * </p><p>
328 * Note: Currently, null can be passed in for the parent.
329 * This has the effect of creating the shell on the currently active
330 * display if there is one. If there is no current display, the
331 * shell is created on a "default" display. <b>Passing in null as
332 * the parent is not considered to be good coding style,
333 * and may not be supported in a future release of DWT.</b>
334 * </p>
335 *
336 * @param parent a shell which will be the parent of the new instance
337 * @param style the style of control to construct
338 *
339 * @exception IllegalArgumentException <ul>
340 * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
341 * </ul>
342 * @exception DWTException <ul>
343 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
344 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
345 * </ul>
346 *
347 * @see DWT#BORDER
348 * @see DWT#CLOSE
349 * @see DWT#MIN
350 * @see DWT#MAX
351 * @see DWT#RESIZE
352 * @see DWT#TITLE
353 * @see DWT#NO_TRIM
354 * @see DWT#SHELL_TRIM
355 * @see DWT#DIALOG_TRIM
356 * @see DWT#ON_TOP
357 * @see DWT#TOOL
358 * @see DWT#MODELESS
359 * @see DWT#PRIMARY_MODAL
360 * @see DWT#APPLICATION_MODAL
361 * @see DWT#SYSTEM_MODAL
362 */
363 public Shell (Shell parent, int style) {
364 this (parent !is null ? parent.display : null, parent, style, 0, false);
365 }
366
367 public static Shell internal_new (Display display, int handle) {
368 return new Shell (display, null, DWT.NO_TRIM, handle, false);
369 }
370
371 static int checkStyle (int style) {
372 style = Decorations.checkStyle (style);
373 style &= ~DWT.TRANSPARENT;
374 int mask = DWT.SYSTEM_MODAL | DWT.APPLICATION_MODAL | DWT.PRIMARY_MODAL;
375 int bits = style & ~mask;
376 if ((style & DWT.SYSTEM_MODAL) !is 0) return bits | DWT.SYSTEM_MODAL;
377 if ((style & DWT.APPLICATION_MODAL) !is 0) return bits | DWT.APPLICATION_MODAL;
378 if ((style & DWT.PRIMARY_MODAL) !is 0) return bits | DWT.PRIMARY_MODAL;
379 return bits;
380 }
381
382 /**
383 * Adds the listener to the collection of listeners who will
384 * be notified when operations are performed on the receiver,
385 * by sending the listener one of the messages defined in the
386 * <code>ShellListener</code> interface.
387 *
388 * @param listener the listener which should be notified
389 *
390 * @exception IllegalArgumentException <ul>
391 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
392 * </ul>
393 * @exception DWTException <ul>
394 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
395 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
396 * </ul>
397 *
398 * @see ShellListener
399 * @see #removeShellListener
400 */
401 public void addShellListener(ShellListener listener) {
402 checkWidget();
403 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
404 TypedListener typedListener = new TypedListener (listener);
405 addListener(DWT.Activate,typedListener);
406 addListener(DWT.Close,typedListener);
407 addListener(DWT.Deactivate,typedListener);
408 addListener(DWT.Iconify,typedListener);
409 addListener(DWT.Deiconify,typedListener);
410 }
411
412 void bringToTop (bool force) {
413 if (getMinimized ()) return;
414 if (force) {
415 forceActive ();
416 } else {
417 setActive ();
418 }
419 }
420
421 void checkOpen () {
422 if (!opened) resized = false;
423 }
424
425 /**
426 * Requests that the window manager close the receiver in
427 * the same way it would be closed when the user clicks on
428 * the "close box" or performs some other platform specific
429 * key or mouse combination that indicates the window
430 * should be removed.
431 *
432 * @exception DWTException <ul>
433 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
434 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
435 * </ul>
436 *
437 * @see DWT#Close
438 * @see #dispose
439 */
440 public void close () {
441 checkWidget();
442 closeWidget ();
443 }
444
445 void closeWidget () {
446 Event event = new Event ();
447 sendEvent (DWT.Close, event);
448 if (event.doit && !isDisposed ()) dispose ();
449 }
450
451 public Rectangle computeTrim (int x, int y, int width, int height) {
452 checkWidget();
453 Rectangle trim = super.computeTrim(x, y, width, height);
454 NSRect rect = new NSRect ();
455 rect.x = trim.x;
456 rect.y = trim.y;
457 rect.width = trim.width;
458 rect.height = trim.height;
459 rect = NSWindow.static_frameRectForContentRect_styleMask_(rect, window.styleMask());
460 return new Rectangle ((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
461 }
462
463 void createHandle () {
464 state |= CANVAS;// | GRAB | HIDDEN;
465 if (window !is null) {
466 view = window.contentView();
467 return;
468 } else {
469 SWTWindow swtWindow = (SWTWindow) new SWTWindow ().alloc ();
470 swtWindow.setTag(jniRef);
471 window = (NSWindow)swtWindow;
472 NSRect rect = new NSRect();
473 Monitor monitor = getMonitor ();
474 Rectangle clientArea = monitor.getClientArea ();
475 rect.width = clientArea.width * 5 / 8;
476 rect.height = clientArea.height * 5 / 8;
477 int styleMask = OS.NSBorderlessWindowMask;
478 if ((style & DWT.NO_TRIM) is 0) {
479 styleMask = OS.NSTitledWindowMask;
480 if ((style & DWT.CLOSE) !is 0) styleMask |= OS.NSClosableWindowMask;
481 if ((style & DWT.MIN) !is 0) styleMask |= OS.NSMiniaturizableWindowMask;
482 if ((style & DWT.MAX) !is 0) styleMask |= OS.NSResizableWindowMask;
483 if ((style & DWT.RESIZE) !is 0) styleMask |= OS.NSResizableWindowMask;
484 }
485 window = window.initWithContentRect_styleMask_backing_defer_(rect, styleMask, OS.NSBackingStoreBuffered, false);
486 display.cascade = window.cascadeTopLeftFromPoint(display.cascade);
487 if ((style & DWT.ON_TOP) !is 0) {
488 window.setLevel(OS.NSFloatingWindowLevel);
489 }
490 }
491
492 createHandle (null);
493
494 window.setContentView (topView());
495 windowDelegate = (SWTWindowDelegate)new SWTWindowDelegate().alloc().init();
496 windowDelegate.setTag(jniRef);
497 window.setDelegate(windowDelegate);
498 }
499
500 void destroyWidget () {
501 NSWindow window = this.window;
502 releaseHandle ();
503 if (window !is null) window.close();
504 }
505
506 Control findBackgroundControl () {
507 return background !is null || backgroundImage !is null ? this : null;
508 }
509
510 Composite findDeferredControl () {
511 return layoutCount > 0 ? this : null;
512 }
513
514 Cursor findCursor () {
515 return cursor;
516 }
517
518 void fixShell (Shell newShell, Control control) {
519 if (this is newShell) return;
520 // if (control is lastActive) setActiveControl (null);
521 }
522
523 void flagsChanged(int theEvent) {
524 Display display = this.display;
525 NSEvent nsEvent = new NSEvent(theEvent);
526 int modifiers = nsEvent.modifierFlags();
527 int lastModifiers = display.lastModifiers;
528 // int chord = OS.GetCurrentEventButtonState ();
529 int type = DWT.KeyUp;
530 if ((modifiers & OS.NSAlphaShiftKeyMask) !is 0 && (lastModifiers & OS.NSAlphaShiftKeyMask) is 0) type = DWT.KeyDown;
531 if ((modifiers & OS.NSAlternateKeyMask) !is 0 && (lastModifiers & OS.NSAlternateKeyMask) is 0) type = DWT.KeyDown;
532 if ((modifiers & OS.NSShiftKeyMask) !is 0 && (lastModifiers & OS.NSShiftKeyMask) is 0) type = DWT.KeyDown;
533 if ((modifiers & OS.NSControlKeyMask) !is 0 && (lastModifiers & OS.NSControlKeyMask) is 0) type = DWT.KeyDown;
534 if ((modifiers & OS.NSCommandKeyMask) !is 0 && (lastModifiers & OS.NSCommandKeyMask) is 0) type = DWT.KeyDown;
535 Control target = display.getFocusControl();
536 if (type is DWT.KeyUp && (modifiers & OS.NSAlphaShiftKeyMask) is 0 && (lastModifiers & OS.NSAlphaShiftKeyMask) !is 0) {
537 if (target !is null) {
538 Event event = new Event ();
539 event.keyCode = DWT.CAPS_LOCK;
540 // setInputState (event, DWT.KeyDown, chord, modifiers);
541 target.sendKeyEvent (DWT.KeyDown, event);
542 }
543 }
544 Event event = new Event ();
545 // setInputState (event, type, chord, modifiers);
546 if (event.keyCode is 0 && event.character is 0) return;
547 bool result = sendKeyEvent (type, event);
548 if (type is DWT.KeyDown && (modifiers & OS.NSAlphaShiftKeyMask) !is 0 && (lastModifiers & OS.NSAlphaShiftKeyMask) is 0) {
549 if (target !is null) {
550 event = new Event ();
551 event.keyCode = DWT.CAPS_LOCK;
552 // setInputState (event, DWT.KeyUp, chord, modifiers);
553 target.sendKeyEvent (DWT.KeyUp, event);
554 }
555 }
556 display.lastModifiers = modifiers;
557 }
558
559 /**
560 * If the receiver is visible, moves it to the top of the
561 * drawing order for the display on which it was created
562 * (so that all other shells on that display, which are not
563 * the receiver's children will be drawn behind it) and forces
564 * the window manager to make the shell active.
565 *
566 * @exception DWTException <ul>
567 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
568 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
569 * </ul>
570 *
571 * @since 2.0
572 * @see Control#moveAbove
573 * @see Control#setFocus
574 * @see Control#setVisible
575 * @see Display#getActiveShell
576 * @see Decorations#setDefaultButton(Button)
577 * @see Shell#open
578 * @see Shell#setActive
579 */
580 public void forceActive () {
581 checkWidget ();
582 if (!isVisible ()) return;
583 // OS.SelectWindow (shellHandle);
584 // OS.SetFrontProcessWithOptions (new int [] {0, OS.kCurrentProcess}, OS.kSetFrontProcessFrontWindowOnly);
585 }
586
587 public int getAlpha () {
588 checkWidget ();
589 return (int)(window.alphaValue() * 255);
590 }
591
592 public Rectangle getBounds () {
593 checkWidget();
594 NSRect frame = window.frame ();
595 return new Rectangle ((int)frame.x, (int) frame.y, (int) frame.width, (int) frame.height);
596 }
597
598 public Rectangle getClientArea () {
599 checkWidget();
600 //TODO why super implementation fails
601 NSRect rect = window.contentRectForFrameRect_(window.frame());
602 int width = (int)rect.width, height = (int)rect.height;
603 if (scrollView !is null) {
604 NSSize size = new NSSize();
605 size.width = width;
606 size.height = height;
607 size = NSScrollView.contentSizeForFrameSize(size, (style & DWT.H_SCROLL) !is 0, (style & DWT.V_SCROLL) !is 0, OS.NSNoBorder);
608 width = (int)size.width;
609 height = (int)size.height;
610 }
611 return new Rectangle (0, 0, width, height);
612 }
613
614 int getDrawCount (int control) {
615 if (!isTrimHandle (control)) return drawCount;
616 return 0;
617 }
618
619 public bool getFullScreen () {
620 checkWidget();
621 return fullScreen;
622 }
623
624 /**
625 * Returns the receiver's input method editor mode. This
626 * will be the result of bitwise OR'ing together one or
627 * more of the following constants defined in class
628 * <code>DWT</code>:
629 * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
630 * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
631 *
632 * @return the IME mode
633 *
634 * @exception DWTException <ul>
635 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
636 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
637 * </ul>
638 *
639 * @see DWT
640 */
641 public int getImeInputMode () {
642 checkWidget();
643 return DWT.NONE;
644 }
645
646 public Point getLocation () {
647 checkWidget();
648 NSRect frame = window.frame ();
649 return new Point ((int) frame.x, (int) frame.y);
650 }
651
652 public bool getMaximized () {
653 checkWidget();
654 //NOT DONE
655 return !fullScreen && super.getMaximized ();
656 }
657
658 public bool getMinimized () {
659 checkWidget();
660 if (!getVisible ()) return super.getMinimized ();
661 // return OS.IsWindowCollapsed (shellHandle);
662 return false;
663 }
664
665 /**
666 * Returns a point describing the minimum receiver's size. The
667 * x coordinate of the result is the minimum width of the receiver.
668 * The y coordinate of the result is the minimum height of the
669 * receiver.
670 *
671 * @return the receiver's size
672 *
673 * @exception DWTException <ul>
674 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
675 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
676 * </ul>
677 *
678 * @since 3.1
679 */
680 public Point getMinimumSize () {
681 checkWidget();
682 // Rect rect = new Rect ();
683 // OS.GetWindowStructureWidths (shellHandle, rect);
684 // CGPoint inMinLimits = new CGPoint (), inMaxLimits = new CGPoint ();
685 // OS.GetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
686 // int width = Math.max (1, (int) inMinLimits.x + (rect.left + rect.right));
687 // int height = Math.max (1, (int) inMinLimits.y + (rect.top + rect.bottom));
688 // return new Point (width, height);
689 return null;
690 }
691
692 float [] getParentBackground () {
693 return null;
694 }
695
696 /**
697 * Returns the region that defines the shape of the shell,
698 * or null if the shell has the default shape.
699 *
700 * @return the region that defines the shape of the shell (or null)
701 *
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 * @since 3.0
708 *
709 */
710 public Region getRegion () {
711 /* This method is needed for the @since 3.0 Javadoc */
712 checkWidget ();
713 return region;
714 }
715
716 public Shell getShell () {
717 checkWidget();
718 return this;
719 }
720
721 /**
722 * Returns an array containing all shells which are
723 * descendants of the receiver.
724 * <p>
725 * @return the dialog shells
726 *
727 * @exception DWTException <ul>
728 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
729 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
730 * </ul>
731 */
732 public Shell [] getShells () {
733 checkWidget();
734 int count = 0;
735 Shell [] shells = display.getShells ();
736 for (int i=0; i<shells.length; i++) {
737 Control shell = shells [i];
738 do {
739 shell = shell.parent;
740 } while (shell !is null && shell !is this);
741 if (shell is this) count++;
742 }
743 int index = 0;
744 Shell [] result = new Shell [count];
745 for (int i=0; i<shells.length; i++) {
746 Control shell = shells [i];
747 do {
748 shell = shell.parent;
749 } while (shell !is null && shell !is this);
750 if (shell is this) {
751 result [index++] = shells [i];
752 }
753 }
754 return result;
755 }
756
757 public Point getSize () {
758 checkWidget();
759 NSRect frame = window.frame ();
760 return new Point ((int) frame.width, (int) frame.height);
761 }
762
763 bool hasBorder () {
764 return false;
765 }
766
767 void helpRequested(int theEvent) {
768 Control control = display.getFocusControl();
769 while (control !is null) {
770 if (control.hooks (DWT.Help)) {
771 control.postEvent (DWT.Help);
772 break;
773 }
774 control = control.parent;
775 }
776 }
777
778 public bool isEnabled () {
779 checkWidget();
780 return getEnabled ();
781 }
782
783 bool isEnabledCursor () {
784 return true;
785 }
786
787 public bool isVisible () {
788 checkWidget();
789 return getVisible ();
790 }
791
792 /**
793 * Moves the receiver to the top of the drawing order for
794 * the display on which it was created (so that all other
795 * shells on that display, which are not the receiver's
796 * children will be drawn behind it), marks it visible,
797 * sets the focus and asks the window manager to make the
798 * shell active.
799 *
800 * @exception DWTException <ul>
801 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
802 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
803 * </ul>
804 *
805 * @see Control#moveAbove
806 * @see Control#setFocus
807 * @see Control#setVisible
808 * @see Display#getActiveShell
809 * @see Decorations#setDefaultButton(Button)
810 * @see Shell#setActive
811 * @see Shell#forceActive
812 */
813 public void open () {
814 checkWidget();
815 setWindowVisible (true, true);
816 if (isDisposed ()) return;
817 // if (active) {
818 if (!restoreFocus () && !traverseGroup (true)) setFocus ();
819 // }
820 }
821
822 public bool print (GC gc) {
823 checkWidget ();
824 if (gc is null) error (DWT.ERROR_NULL_ARGUMENT);
825 if (gc.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT);
826 // int [] outImage = new int [1];
827 // CGRect outFrame = new CGRect ();
828 // if (OS.HIViewCreateOffscreenImage (handle, 0, outFrame, outImage) is OS.noErr) {
829 // int width = OS.CGImageGetWidth (outImage [0]);
830 // int height = OS.CGImageGetHeight (outImage [0]);
831 // CGRect rect = new CGRect();
832 // rect.width = width;
833 // rect.height = height;
834 // //TODO - does not draw the browser (cocoa widgets?)
835 // OS.HIViewDrawCGImage (gc.handle, rect, outImage [0]);
836 // OS.CGImageRelease (outImage [0]);
837 // }
838 // return true;
839 return false;
840 }
841
842 void releaseChildren (bool destroy) {
843 Shell [] shells = getShells ();
844 for (int i=0; i<shells.length; i++) {
845 Shell shell = shells [i];
846 if (shell !is null && !shell.isDisposed ()) {
847 shell.dispose ();
848 }
849 }
850 super.releaseChildren (destroy);
851 }
852
853 void releaseHandle () {
854 window.setDelegate(null);
855 if (windowDelegate !is null) windowDelegate.release();
856 windowDelegate = null;
857 super.releaseHandle ();
858 window = null;
859 }
860
861 void releaseParent () {
862 /* Do nothing */
863 }
864
865 void releaseWidget () {
866 super.releaseWidget ();
867 // disposed = true;
868 lastActive = null;
869 }
870
871 /**
872 * Removes the listener from the collection of listeners who will
873 * be notified when operations are performed on the receiver.
874 *
875 * @param listener the listener which should no longer be notified
876 *
877 * @exception IllegalArgumentException <ul>
878 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
879 * </ul>
880 * @exception DWTException <ul>
881 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
882 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
883 * </ul>
884 *
885 * @see ShellListener
886 * @see #addShellListener
887 */
888 public void removeShellListener(ShellListener listener) {
889 checkWidget();
890 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
891 if (eventTable is null) return;
892 eventTable.unhook(DWT.Activate, listener);
893 eventTable.unhook(DWT.Close, listener);
894 eventTable.unhook(DWT.Deactivate, listener);
895 eventTable.unhook(DWT.Iconify,listener);
896 eventTable.unhook(DWT.Deiconify,listener);
897 }
898
899 /**
900 * If the receiver is visible, moves it to the top of the
901 * drawing order for the display on which it was created
902 * (so that all other shells on that display, which are not
903 * the receiver's children will be drawn behind it) and asks
904 * the window manager to make the shell active
905 *
906 * @exception DWTException <ul>
907 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
908 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
909 * </ul>
910 *
911 * @since 2.0
912 * @see Control#moveAbove
913 * @see Control#setFocus
914 * @see Control#setVisible
915 * @see Display#getActiveShell
916 * @see Decorations#setDefaultButton(Button)
917 * @see Shell#open
918 * @see Shell#setActive
919 */
920 public void setActive () {
921 checkWidget ();
922 if (!isVisible ()) return;
923 // OS.SelectWindow (shellHandle);
924 }
925
926 void setActiveControl (Control control) {
927 if (control !is null && control.isDisposed ()) control = null;
928 if (lastActive !is null && lastActive.isDisposed ()) lastActive = null;
929 if (lastActive is control) return;
930
931 /*
932 * Compute the list of controls to be activated and
933 * deactivated by finding the first common parent
934 * control.
935 */
936 Control [] activate = (control is null) ? new Control[0] : control.getPath ();
937 Control [] deactivate = (lastActive is null) ? new Control[0] : lastActive.getPath ();
938 lastActive = control;
939 int index = 0, length = Math.min (activate.length, deactivate.length);
940 while (index < length) {
941 if (activate [index] !is deactivate [index]) break;
942 index++;
943 }
944
945 /*
946 * It is possible (but unlikely), that application
947 * code could have destroyed some of the widgets. If
948 * this happens, keep processing those widgets that
949 * are not disposed.
950 */
951 for (int i=deactivate.length-1; i>=index; --i) {
952 if (!deactivate [i].isDisposed ()) {
953 deactivate [i].sendEvent (DWT.Deactivate);
954 }
955 }
956 for (int i=activate.length-1; i>=index; --i) {
957 if (!activate [i].isDisposed ()) {
958 activate [i].sendEvent (DWT.Activate);
959 }
960 }
961 }
962
963 public void setAlpha (int alpha) {
964 checkWidget ();
965 alpha &= 0xFF;
966 window.setAlphaValue (alpha / 255f);
967 }
968
969 int setBounds (int x, int y, int width, int height, bool move, bool resize) {
970 // if (fullScreen) setFullScreen (false);
971 if (move && resize) {
972 NSRect rect = new NSRect ();
973 rect.x = x;
974 //TODO - get the screen for the point
975 int screenHeight = (int) window.screen().frame().height;
976 rect.y = screenHeight - y;
977 rect.width = width;
978 rect.height = height;
979 window.setFrame_display_(rect, false);
980 } else {
981 if (move) {
982 NSPoint point = new NSPoint();
983 point.x = x;
984 //TODO - get the screen for the point
985 int screenHeight = (int) window.screen().frame().height;
986 point.y = screenHeight - y;
987 window.setFrameTopLeftPoint (point);
988 } else {
989 if (resize) {
990 NSRect rect = window.frame();
991 rect.width = width;
992 rect.height = height;
993 window.setFrame_display_(rect, false);
994 }
995 }
996 }
997 return 0;
998 }
999
1000 public void setEnabled (bool enabled) {
1001 checkWidget();
1002 if (((state & DISABLED) is 0) is enabled) return;
1003 super.setEnabled (enabled);
1004 // if (enabled && OS.IsWindowActive (shellHandle)) {
1005 // if (!restoreFocus ()) traverseGroup (false);
1006 // }
1007 }
1008
1009 public void setFullScreen (bool fullScreen) {
1010 checkWidget ();
1011 this.fullScreen = fullScreen;
1012 // if (fullScreen) {
1013 // normalBounds = getBounds ();
1014 // OS.ChangeWindowAttributes (shellHandle, OS.kWindowNoTitleBarAttribute, OS.kWindowResizableAttribute | OS.kWindowLiveResizeAttribute);
1015 // updateSystemUIMode ();
1016 // Rectangle screen = getMonitor ().getBounds ();
1017 // if (menuBar !is null && getMonitor ().equals(display.getPrimaryMonitor ())) {
1018 // Rect rect = new Rect ();
1019 // int gdevice = OS.GetMainDevice ();
1020 // OS.GetAvailableWindowPositioningBounds (gdevice, rect);
1021 // screen.height -= rect.top;
1022 // screen.y += rect.top;
1023 // }
1024 // Rect rect = new Rect ();
1025 // OS.SetRect (rect, (short) screen.x, (short) screen.y, (short) (screen.x + screen.width), (short) (screen.y + screen.height));
1026 // OS.SetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
1027 // } else {
1028 // int attributes = 0;
1029 // if ((style & DWT.RESIZE) !is 0) {
1030 // attributes |= OS.kWindowResizableAttribute;
1031 // /*
1032 // * Bug in the Macintosh. For some reason, a window has no title bar
1033 // * and the kWindowResizableAttribute, no rubber banding feedback is
1034 // * given while the window is resizing. The fix is to create the window
1035 // * with kWindowLiveResizeAttribute in this case. This is inconsistent
1036 // * with other windows, but the user will get feedback when resizing.
1037 // */
1038 // if ((style & DWT.TITLE) is 0) attributes |= OS.kWindowLiveResizeAttribute;
1039 // if (!OS.__BIG_ENDIAN__()) attributes |= OS.kWindowLiveResizeAttribute;
1040 // }
1041 // OS.ChangeWindowAttributes (shellHandle, attributes, OS.kWindowNoTitleBarAttribute);
1042 // OS.SetSystemUIMode (OS.kUIModeNormal, 0);
1043 // if (maximized) {
1044 // setMaximized (true);
1045 // } else {
1046 // Rect rect = new Rect ();
1047 // if (normalBounds !is null) OS.SetRect (rect, (short) normalBounds.x, (short) normalBounds.y, (short) (normalBounds.x + normalBounds.width), (short) (normalBounds.y + normalBounds.height));
1048 // OS.SetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
1049 // }
1050 // normalBounds = null;
1051 // }
1052 }
1053
1054 public void setMenuBar (Menu menu) {
1055 checkWidget();
1056 super.setMenuBar (menu);
1057 if (display.getActiveShell () is this) {
1058 display.setMenuBar (menuBar);
1059 }
1060 }
1061
1062 /**
1063 * Sets the input method editor mode to the argument which
1064 * should be the result of bitwise OR'ing together one or more
1065 * of the following constants defined in class <code>DWT</code>:
1066 * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
1067 * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
1068 *
1069 * @param mode the new IME mode
1070 *
1071 * @exception DWTException <ul>
1072 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1073 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1074 * </ul>
1075 *
1076 * @see DWT
1077 */
1078 public void setImeInputMode (int mode) {
1079 checkWidget();
1080 }
1081
1082 public void setMaximized (bool maximized) {
1083 checkWidget();
1084 super.setMaximized (maximized);
1085 // dwt.internal.carbon.Point pt = new dwt.internal.carbon.Point ();
1086 // if (maximized) {
1087 // Rect rect = new Rect ();
1088 // int gdevice = OS.GetMainDevice ();
1089 // OS.GetAvailableWindowPositioningBounds (gdevice, rect);
1090 // pt.h = (short) (rect.right - rect.left);
1091 // pt.v = (short) (rect.bottom - rect.top);
1092 // }
1093 // short inPartCode = (short) (maximized ? OS.inZoomOut : OS.inZoomIn);
1094 // OS.ZoomWindowIdeal (shellHandle, inPartCode, pt);
1095 }
1096
1097 public void setMinimized (bool minimized) {
1098 checkWidget();
1099 if (this.minimized is minimized) return;
1100 super.setMinimized (minimized);
1101 // if (!minimized && OS.IsWindowCollapsed (shellHandle)) {
1102 // OS.SelectWindow (shellHandle);
1103 // }
1104 // OS.CollapseWindow (shellHandle, minimized);
1105 }
1106
1107 /**
1108 * Sets the receiver's minimum size to the size specified by the arguments.
1109 * If the new minimum size is larger than the current size of the receiver,
1110 * the receiver is resized to the new minimum size.
1111 *
1112 * @param width the new minimum width for the receiver
1113 * @param height the new minimum height for the receiver
1114 *
1115 * @exception DWTException <ul>
1116 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1117 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1118 * </ul>
1119 *
1120 * @since 3.1
1121 */
1122 public void setMinimumSize (int width, int height) {
1123 checkWidget();
1124 // int clientWidth = 0, clientHeight = 0;
1125 // int trim = DWT.TITLE | DWT.CLOSE | DWT.MIN | DWT.MAX;
1126 // if ((style & DWT.NO_TRIM) is 0 && (style & trim) !is 0) {
1127 // clientWidth = DEFAULT_CLIENT_WIDTH;
1128 // clientHeight = DEFAULT_CLIENT_HEIGHT;
1129 // }
1130 // Rect rect = new Rect ();
1131 // OS.GetWindowStructureWidths (shellHandle, rect);
1132 // CGPoint inMinLimits = new CGPoint (), inMaxLimits = new CGPoint ();
1133 // OS.GetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
1134 // width = Math.max (width, clientWidth + rect.left + rect.right);
1135 // height = Math.max (height, clientHeight + rect.top + rect.bottom);
1136 // inMinLimits.x = width - (rect.left + rect.right);
1137 // inMinLimits.y = height - (rect.top + rect.bottom);
1138 // OS.SetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
1139 // Point size = getSize ();
1140 // int newWidth = Math.max (size.x, width), newHeight = Math.max (size.y, height);
1141 // if (newWidth !is size.x || newHeight !is size.y) setSize (newWidth, newHeight);
1142 }
1143
1144 /**
1145 * Sets the receiver's minimum size to the size specified by the argument.
1146 * If the new minimum size is larger than the current size of the receiver,
1147 * the receiver is resized to the new minimum size.
1148 *
1149 * @param size the new minimum size for the receiver
1150 *
1151 * @exception IllegalArgumentException <ul>
1152 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
1153 * </ul>
1154 * @exception DWTException <ul>
1155 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1156 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1157 * </ul>
1158 *
1159 * @since 3.1
1160 */
1161 public void setMinimumSize (Point size) {
1162 checkWidget();
1163 if (size is null) error (DWT.ERROR_NULL_ARGUMENT);
1164 setMinimumSize (size.x, size.y);
1165 }
1166
1167 /**
1168 * Sets the shape of the shell to the region specified
1169 * by the argument. When the argument is null, the
1170 * default shape of the shell is restored. The shell
1171 * must be created with the style DWT.NO_TRIM in order
1172 * to specify a region.
1173 *
1174 * @param region the region that defines the shape of the shell (or null)
1175 *
1176 * @exception IllegalArgumentException <ul>
1177 * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
1178 * </ul>
1179 * @exception DWTException <ul>
1180 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1181 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1182 * </ul>
1183 *
1184 * @since 3.0
1185 *
1186 */
1187 public void setRegion (Region region) {
1188 checkWidget ();
1189 if ((style & DWT.NO_TRIM) is 0) return;
1190 if (region !is null && region.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
1191 // if (region is null) {
1192 // rgnRect = null;
1193 // } else {
1194 // if (rgnRect is null) {
1195 // rgnRect = new Rect ();
1196 // OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rgnRect);
1197 // OS.SetRect (rgnRect, (short) 0, (short) 0, (short) (rgnRect.right - rgnRect.left), (short) (rgnRect.bottom - rgnRect.top));
1198 // }
1199 // }
1200 // this.region = region;
1201 // /*
1202 // * Bug in the Macintosh. Calling ReshapeCustomWindow() from a
1203 // * kEventWindowDrawContent handler originating from ShowWindow()
1204 // * will deadlock. The fix is to detected this case and only call
1205 // * ReshapeCustomWindow() after the default handler is done.
1206 // */
1207 // if (drawing) {
1208 // reshape = true;
1209 // } else {
1210 // OS.ReshapeCustomWindow (shellHandle);
1211 // redrawWidget (handle, true);
1212 // }
1213 }
1214
1215 public void setText (String string) {
1216 checkWidget();
1217 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1218 super.setText (string);
1219 NSString str = NSString.stringWith(string);
1220 window.setTitle(str);
1221 // str.release();
1222 }
1223
1224 public void setVisible (bool visible) {
1225 checkWidget();
1226 setWindowVisible (visible, false);
1227 }
1228
1229 void setWindowVisible (bool visible, bool key) {
1230 if (window.isVisible() is visible) return;
1231 if (visible) {
1232 sendEvent (DWT.Show);
1233 if (isDisposed ()) return;
1234 if (key) {
1235 window.makeKeyAndOrderFront (null);
1236 } else {
1237 window.orderFront (null);
1238 }
1239 opened = true;
1240 if (!moved) {
1241 moved = true;
1242 sendEvent (DWT.Move);
1243 if (isDisposed ()) return;
1244 }
1245 if (!resized) {
1246 resized = true;
1247 sendEvent (DWT.Resize);
1248 if (isDisposed ()) return;
1249 if (layout !is null) {
1250 markLayout (false, false);
1251 updateLayout (false);
1252 }
1253 }
1254 } else {
1255 window.orderOut (null);
1256 sendEvent (DWT.Hide);
1257 }
1258 }
1259
1260 void setZOrder () {
1261 // if (scrolledHandle !is 0) OS.HIViewAddSubview (scrolledHandle, handle);
1262 }
1263
1264 void setZOrder (Control control, bool above) {
1265 // if (above) {
1266 // //NOT DONE - move one window above another
1267 // OS.BringToFront (shellHandle);
1268 // } else {
1269 // int window = control is null ? 0 : OS.GetControlOwner (control.handle);
1270 // OS.SendBehind (shellHandle, window);
1271 // }
1272 }
1273
1274 bool traverseEscape () {
1275 if (parent is null) return false;
1276 if (!isVisible () || !isEnabled ()) return false;
1277 close ();
1278 return true;
1279 }
1280
1281 void updateSystemUIMode () {
1282 if (!getMonitor ().equals (display.getPrimaryMonitor ())) return;
1283 bool isActive = false;
1284 Shell activeShell = display.getActiveShell ();
1285 Shell current = this;
1286 while (current !is null) {
1287 if (current.equals (activeShell)) {
1288 isActive = true;
1289 break;
1290 }
1291 current = (Shell) current.parent;
1292 }
1293 if (!isActive) return;
1294 // if (fullScreen) {
1295 // int mode = OS.kUIModeAllHidden;
1296 // if (menuBar !is null) {
1297 // mode = OS.kUIModeContentHidden;
1298 // }
1299 // OS.SetSystemUIMode (mode, 0);
1300 // } else {
1301 // OS.SetSystemUIMode (OS.kUIModeNormal, 0);
1302 // }
1303 }
1304
1305 void windowDidBecomeKey(int notification) {
1306 super.windowDidBecomeKey(notification);
1307 Display display = this.display;
1308 display.setMenuBar (menuBar);
1309 sendEvent (DWT.Activate);
1310 // if (!isDisposed ()) {
1311 // if (!restoreFocus () && !traverseGroup (true)) setFocus ();
1312 // }
1313 }
1314
1315 void windowDidMove(int notification) {
1316 moved = true;
1317 sendEvent(DWT.Move);
1318 }
1319
1320 void windowDidResize(int notification) {
1321 resized = true;
1322 sendEvent (DWT.Resize);
1323 if (isDisposed ()) return;
1324 if (layout !is null) {
1325 markLayout (false, false);
1326 updateLayout (false);
1327 }
1328 }
1329
1330 void windowDidResignKey(int notification) {
1331 super.windowDidResignKey(notification);
1332 Display display = this.display;
1333 sendEvent (DWT.Deactivate);
1334 if (isDisposed ()) return;
1335 // saveFocus ();
1336 // if (savedFocus !is null) {
1337 // /*
1338 // * Bug in the Macintosh. When ClearKeyboardFocus() is called,
1339 // * the control that has focus gets two kEventControlSetFocus
1340 // * events indicating that focus was lost. The fix is to ignore
1341 // * both of these and send the focus lost event explicitly.
1342 // */
1343 // display.ignoreFocus = true;
1344 // OS.ClearKeyboardFocus (shellHandle);
1345 // display.ignoreFocus = false;
1346 // if (!savedFocus.isDisposed ()) savedFocus.sendFocusEvent (DWT.FocusOut, false);
1347 // }
1348 display.setMenuBar (null);
1349 }
1350
1351 bool windowShouldClose(int window) {
1352 closeWidget ();
1353 return false;
1354 }
1355
1356 void windowWillClose(int notification) {
1357 }
1358
1359 void windowSendEvent(int id, int event) {
1360 NSEvent nsEvent = new NSEvent(event);
1361 int type = nsEvent.type();
1362 if (type is OS.NSKeyDown || type is OS.NSKeyUp) {
1363 Control eventTarget = display.getFocusControl();
1364 if (eventTarget !is null) {
1365 if (type is OS.NSKeyDown) {
1366 bool[] consume = new bool[1];
1367 int key = nsEvent.keyCode();
1368 if (eventTarget.translateTraversal(key, nsEvent, consume)) return;
1369 if (consume[0]) return;
1370 if (eventTarget.isDisposed()) return;
1371 }
1372 if (!eventTarget.sendKeyEvent(nsEvent, type is OS.NSKeyDown ? DWT.KeyDown : DWT.KeyUp)) return;
1373 }
1374 }
1375 super.windowSendEvent(id, event);
1376 }
1377
1378 }