javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java
changeset 21 2a9601315dfc
child 26 dc7c549001d5
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2000, 2007 IBM Corporation and others.
       
     3  * Portion Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     4  * All rights reserved. This program and the accompanying materials
       
     5  * are made available under the terms of the Eclipse Public License v1.0
       
     6  * which accompanies this distribution, and is available at
       
     7  * http://www.eclipse.org/legal/epl-v10.html
       
     8  *
       
     9  * Contributors:
       
    10  *     IBM Corporation - initial API and implementation
       
    11  *     Nokia Corporation - Qt implementation
       
    12  *******************************************************************************/
       
    13 package org.eclipse.swt.widgets;
       
    14 
       
    15 import org.eclipse.swt.SWT;
       
    16 import org.eclipse.swt.events.ShellListener;
       
    17 import org.eclipse.swt.graphics.Point;
       
    18 import org.eclipse.swt.graphics.Rectangle;
       
    19 import org.eclipse.swt.internal.qt.OS;
       
    20 import org.eclipse.swt.internal.qt.WidgetState;
       
    21 import org.eclipse.swt.internal.qt.graphics.WindowSurface;
       
    22 
       
    23 /**
       
    24  * Instances of this class represent the "windows"
       
    25  * which the desktop or "window manager" is managing.
       
    26  * Instances that do not have a parent (that is, they
       
    27  * are built using the constructor, which takes a 
       
    28  * <code>Display</code> as the argument) are described
       
    29  * as <em>top level</em> shells. Instances that do have
       
    30  * a parent are described as <em>secondary</em> or
       
    31  * <em>dialog</em> shells.
       
    32  * <p>
       
    33  * Instances are always displayed in one of the maximized, 
       
    34  * minimized or normal states:
       
    35  * <ul>
       
    36  * <li>
       
    37  * When an instance is marked as <em>maximized</em>, the
       
    38  * window manager will typically resize it to fill the
       
    39  * entire visible area of the display, and the instance
       
    40  * is usually put in a state where it can not be resized 
       
    41  * (even if it has style <code>RESIZE</code>) until it is
       
    42  * no longer maximized.
       
    43  * </li><li>
       
    44  * When an instance is in the <em>normal</em> state (neither
       
    45  * maximized or minimized), its appearance is controlled by
       
    46  * the style constants which were specified when it was created
       
    47  * and the restrictions of the window manager (see below).
       
    48  * </li><li>
       
    49  * When an instance has been marked as <em>minimized</em>,
       
    50  * its contents (client area) will usually not be visible,
       
    51  * and depending on the window manager, it may be
       
    52  * "iconified" (that is, replaced on the desktop by a small
       
    53  * simplified representation of itself), relocated to a
       
    54  * distinguished area of the screen, or hidden. Combinations
       
    55  * of these changes are also possible.
       
    56  * </li>
       
    57  * </ul>
       
    58  * </p><p>
       
    59  * The <em>modality</em> of an instance may be specified using
       
    60  * style bits. The modality style bits are used to determine
       
    61  * whether input is blocked for other shells on the display.
       
    62  * The <code>PRIMARY_MODAL</code> style allows an instance to block
       
    63  * input to its parent. The <code>APPLICATION_MODAL</code> style
       
    64  * allows an instance to block input to every other shell in the
       
    65  * display. The <code>SYSTEM_MODAL</code> style allows an instance
       
    66  * to block input to all shells, including shells belonging to
       
    67  * different applications.
       
    68  * </p><p>
       
    69  * Note: The styles supported by this class are treated
       
    70  * as <em>HINT</em>s, since the window manager for the
       
    71  * desktop on which the instance is visible has ultimate
       
    72  * control over the appearance and behavior of decorations
       
    73  * and modality. For example, some window managers only
       
    74  * support resizable windows and will always assume the
       
    75  * RESIZE style, even if it is not set. In addition, if a
       
    76  * modality style is not supported, it is "upgraded" to a
       
    77  * more restrictive modality style that is supported. For
       
    78  * example, if <code>PRIMARY_MODAL</code> is not supported,
       
    79  * it would be upgraded to <code>APPLICATION_MODAL</code>.
       
    80  * A modality style may also be "downgraded" to a less
       
    81  * restrictive style. For example, most operating systems
       
    82  * no longer support <code>SYSTEM_MODAL</code> because
       
    83  * it can freeze up the desktop, so this is typically
       
    84  * downgraded to <code>APPLICATION_MODAL</code>.
       
    85  * <dl>
       
    86  * <dt><b>Styles:</b></dt>
       
    87  * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
       
    88  * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
       
    89  * <dt><b>Events:</b></dt>
       
    90  * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
       
    91  * </dl>
       
    92  * Class <code>SWT</code> provides two "convenience constants"
       
    93  * for the most commonly required style combinations:
       
    94  * <dl>
       
    95  * <dt><code>SHELL_TRIM</code></dt>
       
    96  * <dd>
       
    97  * the result of combining the constants which are required
       
    98  * to produce a typical application top level shell: (that 
       
    99  * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
       
   100  * </dd>
       
   101  * <dt><code>DIALOG_TRIM</code></dt>
       
   102  * <dd>
       
   103  * the result of combining the constants which are required
       
   104  * to produce a typical application dialog shell: (that 
       
   105  * is, <code>TITLE | CLOSE | BORDER</code>)
       
   106  * </dd>
       
   107  * </dl>
       
   108  * </p>
       
   109  * <p>
       
   110  * Note: Only one of the styles APPLICATION_MODAL, MODELESS, 
       
   111  * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
       
   112  * </p><p>
       
   113  * IMPORTANT: This class is not intended to be subclassed.
       
   114  * </p>
       
   115  *
       
   116  * @see Decorations
       
   117  * @see SWT
       
   118  */
       
   119 public class Shell extends Decorations {
       
   120     
       
   121 /**
       
   122  * Handle of the QMainWindow for a top-level Shell.
       
   123  * For non top-level Shells this handle is zero.
       
   124  */
       
   125 int mainWindowHandle;
       
   126 
       
   127 /**
       
   128  * Handle of the QWidget that owns the window for a dialog Shell. For non-dialog
       
   129  * Shells this handle is zero.
       
   130  */
       
   131 int dialogWindowHandle;
       
   132 
       
   133 Rectangle defBounds;
       
   134 
       
   135 /**
       
   136  * The WindowSurface wrapper for top level shells. Window surface
       
   137  * provides access for Qt created draw surface.
       
   138  */
       
   139 WindowSurface windowSurface;
       
   140 
       
   141 /**
       
   142  * Constructs a new instance of this class. This is equivalent
       
   143  * to calling <code>Shell((Display) null)</code>.
       
   144  *
       
   145  * @exception SWTException <ul>
       
   146  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   147  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   148  * </ul>
       
   149  */
       
   150 public Shell () {
       
   151     this ((Display) null);
       
   152 }
       
   153 /**
       
   154  * Constructs a new instance of this class given only the style
       
   155  * value describing its behavior and appearance. This is equivalent
       
   156  * to calling <code>Shell((Display) null, style)</code>.
       
   157  * <p>
       
   158  * The style value is either one of the style constants defined in
       
   159  * class <code>SWT</code> which is applicable to instances of this
       
   160  * class, or must be built by <em>bitwise OR</em>'ing together 
       
   161  * (that is, using the <code>int</code> "|" operator) two or more
       
   162  * of those <code>SWT</code> style constants. The class description
       
   163  * lists the style constants that are applicable to the class.
       
   164  * Style bits are also inherited from superclasses.
       
   165  * </p>
       
   166  *
       
   167  * @param style the style of control to construct
       
   168  *
       
   169  * @exception SWTException <ul>
       
   170  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   171  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   172  * </ul>
       
   173  * 
       
   174  * @see SWT#BORDER
       
   175  * @see SWT#CLOSE
       
   176  * @see SWT#MIN
       
   177  * @see SWT#MAX
       
   178  * @see SWT#RESIZE
       
   179  * @see SWT#TITLE
       
   180  * @see SWT#NO_TRIM
       
   181  * @see SWT#SHELL_TRIM
       
   182  * @see SWT#DIALOG_TRIM
       
   183  * @see SWT#MODELESS
       
   184  * @see SWT#PRIMARY_MODAL
       
   185  * @see SWT#APPLICATION_MODAL
       
   186  * @see SWT#SYSTEM_MODAL
       
   187  */
       
   188 public Shell (int style) {
       
   189     this ((Display) null, style);
       
   190 }
       
   191 
       
   192 /**
       
   193  * Constructs a new instance of this class given only the display
       
   194  * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
       
   195  * <p>
       
   196  * Note: Currently, null can be passed in for the display argument.
       
   197  * This has the effect of creating the shell on the currently active
       
   198  * display if there is one. If there is no current display, the 
       
   199  * shell is created on a "default" display. <b>Passing in null as
       
   200  * the display argument is not considered to be good coding style,
       
   201  * and may not be supported in a future release of SWT.</b>
       
   202  * </p>
       
   203  *
       
   204  * @param display the display to create the shell on
       
   205  *
       
   206  * @exception SWTException <ul>
       
   207  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   208  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   209  * </ul>
       
   210  */
       
   211 public Shell (Display display) {
       
   212     this (display, SWT.SHELL_TRIM);
       
   213 }
       
   214 /**
       
   215  * Constructs a new instance of this class given the display
       
   216  * to create it on and a style value describing its behavior
       
   217  * and appearance.
       
   218  * <p>
       
   219  * The style value is either one of the style constants defined in
       
   220  * class <code>SWT</code> which is applicable to instances of this
       
   221  * class, or must be built by <em>bitwise OR</em>'ing together 
       
   222  * (that is, using the <code>int</code> "|" operator) two or more
       
   223  * of those <code>SWT</code> style constants. The class description
       
   224  * lists the style constants that are applicable to the class.
       
   225  * Style bits are also inherited from superclasses.
       
   226  * </p><p>
       
   227  * Note: Currently, null can be passed in for the display argument.
       
   228  * This has the effect of creating the shell on the currently active
       
   229  * display if there is one. If there is no current display, the 
       
   230  * shell is created on a "default" display. <b>Passing in null as
       
   231  * the display argument is not considered to be good coding style,
       
   232  * and may not be supported in a future release of SWT.</b>
       
   233  * </p>
       
   234  *
       
   235  * @param display the display to create the shell on
       
   236  * @param style the style of control to construct
       
   237  *
       
   238  * @exception SWTException <ul>
       
   239  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   240  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   241  * </ul>
       
   242  * 
       
   243  * @see SWT#BORDER
       
   244  * @see SWT#CLOSE
       
   245  * @see SWT#MIN
       
   246  * @see SWT#MAX
       
   247  * @see SWT#RESIZE
       
   248  * @see SWT#TITLE
       
   249  * @see SWT#NO_TRIM
       
   250  * @see SWT#SHELL_TRIM
       
   251  * @see SWT#DIALOG_TRIM
       
   252  * @see SWT#MODELESS
       
   253  * @see SWT#PRIMARY_MODAL
       
   254  * @see SWT#APPLICATION_MODAL
       
   255  * @see SWT#SYSTEM_MODAL
       
   256  */
       
   257 public Shell (Display display, int style) {
       
   258     this (display, null, style, null);
       
   259 }
       
   260 
       
   261 /**
       
   262  * <p>
       
   263  * <b>IMPORTANT:</b> This constructor is <em>not</em> part of the SWT
       
   264  * public API. It should never be referenced from application code. 
       
   265  * </p>
       
   266  */
       
   267 protected Shell (Display display, Shell parent, int style, Object packageProxy) {
       
   268     super ();
       
   269     checkSubclass ();
       
   270     setPackageProxy(packageProxy);
       
   271     if (display == null) display = Display.getCurrent ();
       
   272     if (display == null) display = Display.getDefault ();
       
   273     if (!display.isValidThread ()) {
       
   274         error (SWT.ERROR_THREAD_INVALID_ACCESS);
       
   275     }
       
   276     if (parent != null && parent.isDisposed ()) {
       
   277         error (SWT.ERROR_INVALID_ARGUMENT); 
       
   278     }
       
   279     this.style = checkStyle (style, parent);
       
   280     this.parent = parent;
       
   281     this.display = display;
       
   282     createWidget (0);
       
   283 }
       
   284 
       
   285 /**
       
   286  * Constructs a new instance of this class given only its
       
   287  * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
       
   288  * <p>
       
   289  * Note: Currently, null can be passed in for the parent.
       
   290  * This has the effect of creating the shell on the currently active
       
   291  * display if there is one. If there is no current display, the 
       
   292  * shell is created on a "default" display. <b>Passing in null as
       
   293  * the parent is not considered to be good coding style,
       
   294  * and may not be supported in a future release of SWT.</b>
       
   295  * </p>
       
   296  *
       
   297  * @param parent a shell which will be the parent of the new instance
       
   298  *
       
   299  * @exception IllegalArgumentException <ul>
       
   300  *    <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> 
       
   301  * </ul>
       
   302  * @exception SWTException <ul>
       
   303  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   304  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   305  * </ul>
       
   306  */
       
   307 public Shell (Shell parent) {
       
   308     this (parent, SWT.DIALOG_TRIM);
       
   309 }
       
   310 
       
   311 /**
       
   312  * Constructs a new instance of this class given its parent
       
   313  * and a style value describing its behavior and appearance.
       
   314  * <p>
       
   315  * The style value is either one of the style constants defined in
       
   316  * class <code>SWT</code> which is applicable to instances of this
       
   317  * class, or must be built by <em>bitwise OR</em>'ing together 
       
   318  * (that is, using the <code>int</code> "|" operator) two or more
       
   319  * of those <code>SWT</code> style constants. The class description
       
   320  * lists the style constants that are applicable to the class.
       
   321  * Style bits are also inherited from superclasses.
       
   322  * </p><p>
       
   323  * Note: Currently, null can be passed in for the parent.
       
   324  * This has the effect of creating the shell on the currently active
       
   325  * display if there is one. If there is no current display, the 
       
   326  * shell is created on a "default" display. <b>Passing in null as
       
   327  * the parent is not considered to be good coding style,
       
   328  * and may not be supported in a future release of SWT.</b>
       
   329  * </p>
       
   330  *
       
   331  * @param parent a shell which will be the parent of the new instance
       
   332  * @param style the style of control to construct
       
   333  *
       
   334  * @exception IllegalArgumentException <ul>
       
   335  *    <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> 
       
   336  * </ul>
       
   337  * @exception SWTException <ul>
       
   338  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   339  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   340  * </ul>
       
   341  * 
       
   342  * @see SWT#BORDER
       
   343  * @see SWT#CLOSE
       
   344  * @see SWT#MIN
       
   345  * @see SWT#MAX
       
   346  * @see SWT#RESIZE
       
   347  * @see SWT#TITLE
       
   348  * @see SWT#NO_TRIM
       
   349  * @see SWT#SHELL_TRIM
       
   350  * @see SWT#DIALOG_TRIM
       
   351  * @see SWT#ON_TOP
       
   352  * @see SWT#MODELESS
       
   353  * @see SWT#PRIMARY_MODAL
       
   354  * @see SWT#APPLICATION_MODAL
       
   355  * @see SWT#SYSTEM_MODAL
       
   356  */
       
   357 public Shell (Shell parent, int style) {
       
   358     this (parent != null ? parent.display : null, parent, style, null);
       
   359 }
       
   360 
       
   361 final static int checkStyle (int style, Composite parent) {
       
   362     style = Decorations.checkStyle (style, parent);
       
   363     style &= ~SWT.TRANSPARENT;
       
   364     if(OS.windowServer == OS.WS_SYMBIAN_S60) {
       
   365         // Set the RESIZE flag to prevent fixing the size so that the
       
   366         // always-maximized top-level Shell will be automatically resized
       
   367         // when available space changes. 
       
   368         if (parent == null) {
       
   369             style |= SWT.RESIZE;
       
   370         }
       
   371     }
       
   372     int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
       
   373     int bits = style & ~mask;
       
   374     if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
       
   375     if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
       
   376     if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
       
   377     return bits;
       
   378 }
       
   379 
       
   380 /**
       
   381  * Adds the listener to the collection of listeners who will
       
   382  * be notified when operations are performed on the receiver,
       
   383  * by sending the listener one of the messages defined in the
       
   384  * <code>ShellListener</code> interface.
       
   385  *
       
   386  * @param listener the listener which should be notified
       
   387  *
       
   388  * @exception IllegalArgumentException <ul>
       
   389  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   390  * </ul>
       
   391  * @exception SWTException <ul>
       
   392  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   393  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   394  * </ul>
       
   395  *
       
   396  * @see ShellListener
       
   397  * @see #removeShellListener
       
   398  */
       
   399 public void addShellListener (ShellListener listener) {
       
   400     checkWidget();
       
   401     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   402     TypedListener typedListener = new TypedListener (listener);
       
   403     addListener (SWT.Close,typedListener);
       
   404     addListener (SWT.Iconify,typedListener);
       
   405     addListener (SWT.Deiconify,typedListener);
       
   406     addListener (SWT.Activate, typedListener);
       
   407     addListener (SWT.Deactivate, typedListener);
       
   408 }
       
   409 
       
   410 /**
       
   411  * Requests that the window manager close the receiver in
       
   412  * the same way it would be closed when the user clicks on
       
   413  * the "close box" or performs some other platform specific
       
   414  * key or mouse combination that indicates the window
       
   415  * should be removed.
       
   416  *
       
   417  * @exception SWTException <ul>
       
   418  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   419  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   420  * </ul>
       
   421  *
       
   422  * @see SWT#Close
       
   423  * @see #dispose
       
   424  */
       
   425 public void close () {
       
   426     checkWidget ();
       
   427     closeWidget ();
       
   428 }
       
   429 
       
   430 public Point computeSize (int wHint, int hHint, boolean changed) {
       
   431     // On Symbian the top-level Shells are always maximized. 
       
   432     // They have no trim. No need to compute anything. Just return the size. 
       
   433     if(OS.windowServer == OS.WS_SYMBIAN_S60 && parent == null) {
       
   434         return OS.QWidget_size(topHandle);
       
   435     }
       
   436     
       
   437     Point size = super.computeSize(wHint, hHint, changed);
       
   438     
       
   439     if(OS.windowServer == OS.WS_X11) {
       
   440         if((style & SWT.RESIZE) != 0) {
       
   441             // Resizeable windows won't go smaller than this
       
   442             if(size.x < 81) size.x = 81;
       
   443             if(size.y < 100) size.y = 100;
       
   444         } else if(willBeDecorated()) {
       
   445             // Windows won't go smaller than their trim
       
   446             size.x = Math.max(size.x, windowFrameTrim() * 2);
       
   447             size.y = Math.max(size.y, windowFrameTrim() * 2);
       
   448         }
       
   449     }
       
   450     return size;
       
   451 }
       
   452 
       
   453 /*
       
   454  * On non-Symbian platform the Shell size is initially set to some nice
       
   455  * looking default. On Symbian platform Qt implements automatic resizing for
       
   456  * maximized widgets. Thus, top-level Shells are always maximized and it's
       
   457  * prevented from the application to set their size freely. 
       
   458  */
       
   459 Point setInitialSize () {
       
   460     Rectangle area = display.getClientArea();
       
   461     if(OS.windowServer != OS.WS_SYMBIAN_S60) {
       
   462         area.width /= 3;
       
   463         area.height /= 3;
       
   464     }
       
   465     Point size =  computeSize(area.width, area.height, true);
       
   466     size.x -= windowFrameTrim() * 2;
       
   467     size.y -= windowTitleTrim() + windowFrameTrim();
       
   468     if(OS.windowServer == OS.WS_SYMBIAN_S60 && parent == null) {
       
   469         setRestoreState(OS.QT_WINDOWMAXIMIZED, false);
       
   470     } else {
       
   471         OS.QWidget_resize(topHandle, size.x, size.y);
       
   472     }
       
   473     return size;
       
   474 }
       
   475 
       
   476 public Rectangle computeTrim (int x, int y, int width, int height) {
       
   477     checkWidget();
       
   478     Rectangle scrollableTrim = super.computeTrim (x, y, width, height);
       
   479 
       
   480     // Normally window frame is learned on setVisible(true). If it has not been
       
   481     // called then try to learn the window trim dimensions here. 
       
   482     learnTrim();
       
   483     
       
   484     int leftTrim, rightTrim, topTrim, bottomTrim;
       
   485     leftTrim = rightTrim = bottomTrim = windowFrameTrim();
       
   486     topTrim = windowTitleTrim();
       
   487     
       
   488     scrollableTrim.x -= leftTrim;
       
   489     scrollableTrim.width += (leftTrim + rightTrim);
       
   490     scrollableTrim.y -= topTrim;
       
   491     scrollableTrim.height += (topTrim + bottomTrim);
       
   492     
       
   493     return scrollableTrim;
       
   494 }
       
   495 
       
   496 boolean bypassWindowManager() {
       
   497     return ((style & SWT.ON_TOP) != 0) && ((style & SWT.NO_FOCUS) != 0)
       
   498             && ((style & SWT.NO_TRIM) != 0);
       
   499 }
       
   500 
       
   501 final int windowFlagsFromStyle() {
       
   502     // Bypassing window manager won't work with dialog-flag. If that is desired
       
   503     // then window-flag is used. 
       
   504     int flags = (parent == null || bypassWindowManager() ? OS.QT_WINDOWFLAGS_WINDOW
       
   505             : OS.QT_WINDOWFLAGS_DIALOG);
       
   506     flags |= OS.QT_WINDOWFLAGS_CUSTOMIZEWINDOWHINT;
       
   507     if((style & SWT.CLOSE) != 0) flags |= OS.QT_WINDOWFLAGS_WINDOWSYSTEMMENUHINT |
       
   508                                           OS.QT_WINDOWFLAGS_WINDOWCLOSEBUTTONHINT;
       
   509     if((style & SWT.MIN) != 0) flags |= OS.QT_WINDOWFLAGS_WINDOWMINIMIZEBUTTONHINT;
       
   510     if((style & SWT.MAX) != 0) flags |= OS.QT_WINDOWFLAGS_WINDOWMAXIMIZEBUTTONHINT;
       
   511     if((style & SWT.NO_TRIM) != 0) flags |= OS.QT_WINDOWFLAGS_FRAMELESSWINDOWHINT;
       
   512     if((style & SWT.TITLE) != 0) flags |= OS.QT_WINDOWFLAGS_WINDOWTITLEHINT;
       
   513     if((style & SWT.ON_TOP) != 0) flags |= OS.QT_WINDOWFLAGS_WINDOWSTAYSONTOPHINT;
       
   514     
       
   515     // Don't use tooltip flag on Symbian, it causes nothing to be focusable. 
       
   516     if(OS.windowServer != OS.WS_SYMBIAN_S60 && bypassWindowManager()) {
       
   517         flags |= OS.QT_WINDOWFLAGS_TOOLTIP;
       
   518     }
       
   519     
       
   520     return flags;
       
   521 }
       
   522 
       
   523 void createHandle_pp (int index) {
       
   524     if(parent == null) {
       
   525         // Top-level Shell 
       
   526         topHandle = mainWindowHandle = OS.QMainWindow_new(0,  windowFlagsFromStyle());
       
   527         frameHandle = scrollAreaHandle = OS.QScrollArea_new(mainWindowHandle);
       
   528         handle = OS.QAbstractScrollArea_viewPort(scrollAreaHandle);
       
   529 
       
   530         // Scrollarea is the central widget of the QMainWindow. This
       
   531         // connects it to the main window's layout. 
       
   532         // At least on X11 this call has a side effect that mainWindow can't 
       
   533         // be made very small anymore. The minimumSize still returns (0,0) 
       
   534         // though. 
       
   535         OS.QMainWindow_setCentralWidget(mainWindowHandle, scrollAreaHandle);
       
   536     } else {
       
   537         // Dialog Shell 
       
   538         topHandle = dialogWindowHandle = OS.QDialog_new(parent.handle, windowFlagsFromStyle());
       
   539         frameHandle = scrollAreaHandle = OS.QScrollArea_new(dialogWindowHandle);
       
   540         handle = OS.QAbstractScrollArea_viewPort(scrollAreaHandle);
       
   541 
       
   542         // A QLayout is needed where menubar can be inserted. 
       
   543         // Dialog window takes ownership of the layout instance. 
       
   544         int layoutHandle = OS.QVBoxLayout_new(dialogWindowHandle);
       
   545         OS.QLayout_addWidget(layoutHandle, scrollAreaHandle);
       
   546         OS.QLayout_setContentsMargins(layoutHandle, 0, 0, 0, 0);
       
   547     }
       
   548 
       
   549     // To make getClientArea return correct location already before
       
   550     // setVisible(true) move it to it's final position here. 
       
   551     OS.QWidget_move(handle, 0, 0);
       
   552     
       
   553     // If no size is set Qt returns completely weird "pre-initial" values before
       
   554     // the Shell is made visible. 
       
   555     Point size = setInitialSize();
       
   556 
       
   557     defBounds = OS.QWidget_rect(topHandle);
       
   558     
       
   559     // Set size constraints. See QLayout::SizeConstraint. 
       
   560     if((style & SWT.RESIZE) == 0) {
       
   561         // Setting min/max sizes to the same value disables the resize handle in the
       
   562         // window corner. There's no window style for this purpose. 
       
   563         OS.QWidget_setFixedSize(topHandle, size.x, size.y);
       
   564     } else {
       
   565         // If no-one has set size constraints then Qt will apply a default
       
   566         // constraint. Prevent this or the Shell won't go very small. 
       
   567         int layoutHandle = OS.QWidget_layout(topHandle);
       
   568         if(layoutHandle  != 0) {
       
   569             if(OS.QLayout_sizeConstraint(layoutHandle) == OS.QLAYOUT_SIZECONSTRAINT_SETDEFAULTCONSTRAINT)
       
   570                 OS.QLayout_setSizeConstraint(layoutHandle, OS.QLAYOUT_SIZECONSTRAINT_SETNOCONSTRAINT);
       
   571         }
       
   572     }
       
   573     
       
   574     // Shell must not by default accept focus by clicking. 
       
   575     int policy = OS.QWidget_focusPolicy(topHandle) & ~OS.QT_FOCUSPOLICY_CLICKFOCUS;
       
   576     OS.QWidget_setFocusPolicy(topHandle, policy);
       
   577 
       
   578     // Stand-alone Composites, Shells, Canvases set the CANVAS flag
       
   579     state |= WidgetState.HANDLE | WidgetState.CANVAS;
       
   580 }
       
   581 
       
   582 Composite findDeferredControl () {
       
   583     return layoutCount > 0 ? this : null;
       
   584 }
       
   585 
       
   586 public boolean isEnabled () {
       
   587     checkWidget ();
       
   588     return getEnabled ();
       
   589 }
       
   590 
       
   591 boolean isParentMirrored() {
       
   592     // Shells are positioned in Display coordinate system which is always LTR. 
       
   593     return false;
       
   594 }
       
   595 
       
   596 public boolean isVisible () {
       
   597     checkWidget();
       
   598     return getVisible ();
       
   599 }
       
   600 
       
   601 void register_pp () {
       
   602     // Viewport & scroll area
       
   603     super.register_pp ();
       
   604     // Main window, if top-level
       
   605     if(mainWindowHandle != 0) display.addWidget (mainWindowHandle, this);    
       
   606     // Dialog window, if a dialog Shell
       
   607     if(dialogWindowHandle != 0) display.addWidget (dialogWindowHandle, this);    
       
   608 }
       
   609 
       
   610 void releaseParent_pp () {
       
   611     /* Do nothing */
       
   612 }
       
   613 
       
   614 /**
       
   615  * Returns the receiver's alpha value. The alpha value
       
   616  * is between 0 (transparent) and 255 (opaque).
       
   617  *
       
   618  * @return the alpha value
       
   619  *
       
   620  * @exception SWTException <ul>
       
   621  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   622  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   623  * </ul>
       
   624  * 
       
   625  * @since 3.4
       
   626  */
       
   627 public int getAlpha () {
       
   628     checkWidget ();
       
   629     double opacity = OS.QWidget_windowOpacity(topHandle);
       
   630     return (int)(255*opacity);
       
   631 }
       
   632 
       
   633 public boolean getMaximized () {
       
   634     checkWidget();
       
   635     return !hasState(OS.QT_WINDOWFULLSCREEN) && super.getMaximized ();
       
   636 }
       
   637 
       
   638 /**
       
   639  * Returns the receiver's input method editor mode. This
       
   640  * will be the result of bitwise OR'ing together one or
       
   641  * more of the following constants defined in class
       
   642  * <code>SWT</code>:
       
   643  * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>, 
       
   644  * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
       
   645  *
       
   646  * @return the IME mode
       
   647  *
       
   648  * @exception SWTException <ul>
       
   649  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   650  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   651  * </ul>
       
   652  *
       
   653  * @see SWT
       
   654  */
       
   655 public int getImeInputMode () {
       
   656     checkWidget();
       
   657     return SWT.NONE;
       
   658 }
       
   659 
       
   660 Shell _getShell () {
       
   661     return this;
       
   662 }
       
   663 
       
   664 /**
       
   665  * Returns an array containing all shells which are 
       
   666  * descendants of the receiver.
       
   667  * <p>
       
   668  * @return the dialog shells
       
   669  *
       
   670  * @exception SWTException <ul>
       
   671  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   672  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   673  * </ul>
       
   674  */
       
   675 public Shell [] getShells () {
       
   676     checkWidget();
       
   677     int count = 0;
       
   678     Shell [] shells = display.getShells ();
       
   679     for (int i=0; i<shells.length; i++) {
       
   680         Control shell = shells [i];
       
   681         do {
       
   682             shell = shell.getParent ();
       
   683         } while (shell != null && shell != this);
       
   684         if (shell == this) count++;
       
   685     }
       
   686     int index = 0;
       
   687     Shell [] result = new Shell [count];
       
   688     for (int i=0; i<shells.length; i++) {
       
   689         Control shell = shells [i];
       
   690         do {
       
   691             shell = shell.getParent ();
       
   692         } while (shell != null && shell != this);
       
   693         if (shell == this) {
       
   694             result [index++] = shells [i];
       
   695         }
       
   696     }
       
   697     return result;
       
   698 }
       
   699 
       
   700 /**
       
   701  * Moves the receiver to the top of the drawing order for
       
   702  * the display on which it was created (so that all other
       
   703  * shells on that display, which are not the receiver's
       
   704  * children will be drawn behind it), marks it visible,
       
   705  * sets the focus and asks the window manager to make the
       
   706  * shell active.
       
   707  *
       
   708  * @exception SWTException <ul>
       
   709  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   710  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   711  * </ul>
       
   712  *
       
   713  * @see Control#moveAbove
       
   714  * @see Control#setFocus
       
   715  * @see Control#setVisible
       
   716  * @see Display#getActiveShell
       
   717  * @see Decorations#setDefaultButton(Button)
       
   718  * @see Shell#setActive
       
   719  * @see Shell#forceActive
       
   720  */
       
   721 public void open () {
       
   722     checkWidget ();
       
   723     setVisible (true);
       
   724     bringToTop (false);
       
   725     if (isDisposed ()) return;
       
   726     if (!restoreFocus () && !traverseGroup (true)) setFocus (OS.QT_OTHERFOCUSREASON);
       
   727 }
       
   728 
       
   729 /**
       
   730  * Removes the listener from the collection of listeners who will
       
   731  * be notified when operations are performed on the receiver.
       
   732  *
       
   733  * @param listener the listener which should no longer be notified
       
   734  *
       
   735  * @exception IllegalArgumentException <ul>
       
   736  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   737  * </ul>
       
   738  * @exception SWTException <ul>
       
   739  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   740  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   741  * </ul>
       
   742  *
       
   743  * @see ShellListener
       
   744  * @see #addShellListener
       
   745  */
       
   746 public void removeShellListener (ShellListener listener) {
       
   747     checkWidget();
       
   748     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   749     if (eventTable == null) return;
       
   750     eventTable.unhook (SWT.Close, listener);
       
   751     eventTable.unhook (SWT.Iconify,listener);
       
   752     eventTable.unhook (SWT.Deiconify,listener);
       
   753     eventTable.unhook (SWT.Activate, listener);
       
   754     eventTable.unhook (SWT.Deactivate, listener);
       
   755 }
       
   756 
       
   757 /**
       
   758  * If the receiver is visible, moves it to the top of the 
       
   759  * drawing order for the display on which it was created 
       
   760  * (so that all other shells on that display, which are not 
       
   761  * the receiver's children will be drawn behind it) and asks 
       
   762  * the window manager to make the shell active 
       
   763  *
       
   764  * @exception SWTException <ul>
       
   765  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   766  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   767  * </ul>
       
   768  *
       
   769  * @since 2.0
       
   770  * @see Control#moveAbove
       
   771  * @see Control#setFocus
       
   772  * @see Control#setVisible
       
   773  * @see Display#getActiveShell
       
   774  * @see Decorations#setDefaultButton(Button)
       
   775  * @see Shell#open
       
   776  * @see Shell#setActive
       
   777  */
       
   778 public void setActive () {
       
   779     checkWidget ();
       
   780     bringToTop (false);
       
   781     
       
   782     // Wait for active window to change unless the widget isn't visible.
       
   783     // Then setActive won't do anything.
       
   784     if(OS.windowServer == OS.WS_X11 && OS.QWidget_isVisible(topHandle)) { 
       
   785         waitXRequestComplete();
       
   786     }
       
   787 }
       
   788 
       
   789 /**
       
   790  * Sets the receiver's alpha value which must be
       
   791  * between 0 (transparent) and 255 (opaque).
       
   792  * <p>
       
   793  * This operation requires the operating system's advanced
       
   794  * widgets subsystem which may not be available on some
       
   795  * platforms.
       
   796  * </p>
       
   797  * @param alpha the alpha value
       
   798  *
       
   799  * @exception SWTException <ul>
       
   800  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   801  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   802  * </ul>
       
   803  * 
       
   804  * @since 3.4
       
   805  */
       
   806 public void setAlpha (int alpha) {
       
   807     checkWidget ();
       
   808     if(alpha < 0 || alpha > 255) return;
       
   809     OS.QWidget_setWindowOpacity(topHandle, ((double)alpha)/255);
       
   810 }
       
   811 
       
   812 public Point getSize() {
       
   813     checkWidget();
       
   814     Point size = OS.QWidget_size(topHandle);
       
   815     size.x += windowFrameTrim() * 2;
       
   816     size.y += windowFrameTrim() + windowTitleTrim();
       
   817     return size;    
       
   818 }
       
   819 
       
   820 public Rectangle getBounds() {
       
   821     checkWidget();
       
   822     Rectangle bounds = OS.QWidget_geometry(topHandle);
       
   823     bounds.x -= windowFrameTrim();
       
   824     bounds.y -= windowTitleTrim();
       
   825     bounds.width += windowFrameTrim() * 2;
       
   826     bounds.height += windowFrameTrim() + windowTitleTrim();
       
   827     return bounds;
       
   828 }
       
   829 
       
   830 int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
       
   831     // On Symbian platform top-level Shells are forced to maximized
       
   832     if(OS.windowServer == OS.WS_SYMBIAN_S60 && parent == null) {
       
   833         return 0;
       
   834     }
       
   835     
       
   836     if (hasState(OS.QT_WINDOWFULLSCREEN)) {
       
   837         setRestoreState(OS.QT_WINDOWFULLSCREEN, true);
       
   838     }
       
   839 
       
   840     Rectangle geometry = OS.QWidget_geometry(topHandle);
       
   841     int result = 0;
       
   842     if(move) {
       
   843         int oldX = geometry.x - windowFrameTrim();
       
   844         int oldY = geometry.y - windowTitleTrim();
       
   845         if(oldX != x || oldY != y) {
       
   846             result |= WidgetState.MOVED;
       
   847         }
       
   848     }
       
   849     if(resize) {
       
   850         int oldW = geometry.width + windowFrameTrim() * 2;
       
   851         int oldH = geometry.height + windowTitleTrim() + windowFrameTrim();
       
   852         if(oldW != width || oldH != height) {
       
   853             result |= WidgetState.RESIZED;
       
   854         }
       
   855     }
       
   856     if((result & WidgetState.MOVED) != 0) {
       
   857         int newX = x + windowFrameTrim();
       
   858         int newY = y + windowTitleTrim();
       
   859         OS.QWidget_setGeometry(topHandle, newX, newY, geometry.width, geometry.height);
       
   860     }
       
   861     if((result & WidgetState.RESIZED) != 0) {
       
   862         int newW = width - windowFrameTrim() * 2;
       
   863         int newH = height - (windowFrameTrim() + windowTitleTrim());
       
   864         
       
   865         // If size has been fixed it needs to be temporarily unfixed
       
   866         if((style & SWT.RESIZE) == 0) unlockSize();
       
   867         
       
   868         OS.QWidget_resize(topHandle, newW, newH);
       
   869 
       
   870         // Fix the new size if not resizeable
       
   871         if((style & SWT.RESIZE) == 0) {
       
   872             OS.QWidget_setFixedSize(topHandle, Math.max(0, newW), 
       
   873                     Math.max(0, newH));
       
   874         }
       
   875     }
       
   876     return result;
       
   877 }
       
   878 
       
   879 public Point getLocation() {
       
   880     checkWidget();
       
   881     Rectangle geometry = OS.QWidget_geometry(topHandle);
       
   882     Point pos = new Point(geometry.x, geometry.y);
       
   883     pos.x -= windowFrameTrim();
       
   884     pos.y -= windowTitleTrim();
       
   885     return pos;
       
   886 }
       
   887 
       
   888 public void setEnabled (boolean enabled) {
       
   889     checkWidget ();
       
   890     if (((state & WidgetState.DISABLED) == 0) == enabled) return;
       
   891     super.setEnabled (enabled);
       
   892     if (enabled && topHandle == OS.QApplication_activeWindow()) {
       
   893         if (!restoreFocus ()) traverseGroup (true);
       
   894     }
       
   895 }
       
   896 
       
   897 void enableWidget(boolean enabled) {
       
   898     Control oldFocus = display._getFocusControl();
       
   899     super.enableWidget(enabled);
       
   900     if(!enabled) {
       
   901         // All children were looped through and disabled by QWidget unless they
       
   902         // were explicitly disabled. SWT behavior is not to disable the dialog
       
   903         // Shells so we have to restore their states.
       
   904         Shell shells[] = getShells();
       
   905         for(int i = 0; i < shells.length; ++i) {
       
   906             if(shells[i].parent == this) {
       
   907                 if(shells[i]._getEnabled()) {
       
   908                     OS.QWidget_setEnabled(shells[i].topHandle, true);
       
   909                 }
       
   910             }
       
   911         }
       
   912         // Because dialog Shell might have been temporarily disabled the focus might
       
   913         // have been lost and must be restored. 
       
   914         if(oldFocus != null) oldFocus.menuShell().restoreFocus();
       
   915     }
       
   916 }
       
   917 
       
   918 /**
       
   919  * Sets the input method editor mode to the argument which 
       
   920  * should be the result of bitwise OR'ing together one or more
       
   921  * of the following constants defined in class <code>SWT</code>:
       
   922  * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>, 
       
   923  * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
       
   924  *
       
   925  * @param mode the new IME mode
       
   926  *
       
   927  * @exception SWTException <ul>
       
   928  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   929  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   930  * </ul>
       
   931  *
       
   932  * @see SWT
       
   933  */
       
   934 public void setImeInputMode (int mode) {
       
   935     checkWidget();
       
   936 }
       
   937 
       
   938 private final int modalityFromStyle() {
       
   939     int modality = OS.QT_WINDOWMODALITY_NONMODAL;
       
   940     if((style & SWT.SYSTEM_MODAL) != 0)
       
   941         return OS.QT_WINDOWMODALITY_APPLICATIONMODAL;
       
   942     if((style & SWT.APPLICATION_MODAL) != 0)
       
   943         return OS.QT_WINDOWMODALITY_APPLICATIONMODAL;
       
   944     if((style & SWT.PRIMARY_MODAL) != 0) {
       
   945         return OS.QT_WINDOWMODALITY_APPLICATIONMODAL;
       
   946     }
       
   947     return modality;
       
   948 }
       
   949 
       
   950 public void setVisible (boolean visible) {
       
   951     checkWidget();
       
   952     
       
   953    int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
       
   954     if ((style & mask) != 0) {
       
   955         if (visible) {
       
   956             display.setModalShell (this);
       
   957             if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
       
   958                 display.setModalDialog (null);
       
   959             }
       
   960             Control control = display._getFocusControl();
       
   961             if (control != null && !control.isActive()) {
       
   962                 bringToTop(false);
       
   963                 if (isDisposed()) return;
       
   964             }
       
   965             OS.QWidget_setWindowModality(topHandle, modalityFromStyle());
       
   966             int mouseGrabber = OS.QWidget_mouseGrabber();
       
   967             if(mouseGrabber != 0) {
       
   968                 OS.QWidget_releaseMouse(mouseGrabber);
       
   969             }
       
   970         } else {
       
   971             display.clearModal (this);
       
   972         }
       
   973     } else {
       
   974         updateModal ();
       
   975     }
       
   976     
       
   977     // This shell
       
   978     super.setVisible(visible);
       
   979     if(isDisposed()) return;
       
   980         
       
   981     // Dialog shells. 
       
   982     // SWT behavior is that when a Shell gets setVisible(false) then dialog Shells
       
   983     // after that have getVisible == isVisible == false.  
       
   984     Shell dialogShells[] = getShells();
       
   985     for(int i = 0; i < dialogShells.length; ++i) {
       
   986         Shell child = dialogShells[i];
       
   987         if(child.isVisible() != visible) {
       
   988             child.setVisible(visible);
       
   989             if(isDisposed()) return;
       
   990         }
       
   991     }
       
   992 
       
   993     // Ensure that the state is updated
       
   994     if(OS.windowServer == OS.WS_X11) {
       
   995         waitXRequestComplete();
       
   996     }
       
   997     if(isDisposed()) return;    
       
   998     learnTrim();
       
   999 }
       
  1000 
       
  1001 boolean traverseEscape () {
       
  1002     if (parent == null) return false;
       
  1003     if (!isVisible () || !isEnabled ()) return false;
       
  1004     close ();
       
  1005     return true;
       
  1006 }
       
  1007 
       
  1008 void updateModal () {
       
  1009     // Nothing to do, the method is here so that modality logic can be similar
       
  1010     // across the platforms
       
  1011 }
       
  1012 
       
  1013 void deregister_pp () {
       
  1014     super.deregister_pp ();
       
  1015     if(mainWindowHandle != 0) {
       
  1016         display.removeWidget(mainWindowHandle);
       
  1017     }
       
  1018     if(dialogWindowHandle != 0) {
       
  1019         display.removeWidget(dialogWindowHandle);
       
  1020     }
       
  1021 }
       
  1022 
       
  1023 /**
       
  1024  * If the receiver is visible, moves it to the top of the 
       
  1025  * drawing order for the display on which it was created 
       
  1026  * (so that all other shells on that display, which are not 
       
  1027  * the receiver's children will be drawn behind it) and forces 
       
  1028  * the window manager to make the shell active.
       
  1029  *
       
  1030  * @exception SWTException <ul>
       
  1031  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1032  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
  1033  * </ul>
       
  1034  *
       
  1035  * @since 2.0
       
  1036  * @see Control#moveAbove
       
  1037  * @see Control#setFocus
       
  1038  * @see Control#setVisible
       
  1039  * @see Display#getActiveShell
       
  1040  * @see Decorations#setDefaultButton(Button)
       
  1041  * @see Shell#open
       
  1042  * @see Shell#setActive
       
  1043  */
       
  1044 public void forceActive () {
       
  1045     checkWidget ();
       
  1046     bringToTop (true);
       
  1047 }
       
  1048 
       
  1049 public void moveAbove (Control control) {
       
  1050     if(parent == null) {
       
  1051         // There's no way to move windows above other windows in Qt.
       
  1052         // Therefore here it's raised to the top despite of the control
       
  1053         // parameter.  
       
  1054         // Also this sends the window on top of ALL windows including the
       
  1055         // windows of other applications.
       
  1056         OS.QWidget_raise(topHandle);
       
  1057     } else {
       
  1058         super.moveAbove(control);
       
  1059     }
       
  1060 }
       
  1061 
       
  1062 public void moveBelow (Control control) {
       
  1063     if(parent == null) {
       
  1064         // There's no way to move windows below other windows in Qt.
       
  1065         // Therefore here it's lowered to the bottom despite of the control
       
  1066         // parameter. 
       
  1067         // Also this sends the window below ALL the windows including the
       
  1068         // windows of other applications.
       
  1069         OS.QWidget_lower(topHandle);
       
  1070     } else {
       
  1071         super.moveBelow(control);
       
  1072     }
       
  1073 }
       
  1074 
       
  1075 void releaseHandle_pp () {
       
  1076     mainWindowHandle = 0;
       
  1077     dialogWindowHandle = 0;
       
  1078     super.releaseHandle_pp ();
       
  1079 }
       
  1080 
       
  1081 void releaseChildren_pp (boolean destroy) {
       
  1082     Shell [] shells = getShells ();
       
  1083     for (int i=0; i<shells.length; i++) {
       
  1084         Shell shell = shells [i];
       
  1085         if (shell != null && !shell.isDisposed ()) {
       
  1086             shell.release(true);
       
  1087         }
       
  1088     }
       
  1089     super.releaseChildren_pp (destroy);
       
  1090 }
       
  1091 
       
  1092 void releaseWidget_pp () {
       
  1093     super.releaseWidget_pp ();
       
  1094     display.clearModal (this);
       
  1095     if(windowSurface != null) {
       
  1096     	windowSurface.dispose();
       
  1097     	windowSurface = null;
       
  1098     }
       
  1099 }
       
  1100 
       
  1101 boolean qt_event_keypress_pp(int widgetHandle, int key,
       
  1102         int modifier, int character, int nativeScanCode) {
       
  1103     super.qt_event_keypress_pp(widgetHandle, key, modifier, character, nativeScanCode);
       
  1104     // Key event is canceled to prevent propagation from viewport to its parent
       
  1105     return true;
       
  1106 }
       
  1107 
       
  1108 boolean qt_event_keyrelease_pp( int widgetHandle, int key, int modifier, int character, int nativeScanCode )
       
  1109 {
       
  1110     super.qt_event_keyrelease_pp(widgetHandle, key, modifier, character, nativeScanCode);
       
  1111     // Key event is canceled to prevent propagation from viewport to its parent
       
  1112     return true;
       
  1113 }
       
  1114 
       
  1115 public Rectangle internal_getDefaultBounds() {
       
  1116     return defBounds;
       
  1117 }
       
  1118 
       
  1119 WindowSurface getWindowSurface() {
       
  1120 	checkWidget();
       
  1121 	// Only top level shells have window surface
       
  1122 	if (parent != null) {
       
  1123 		return null;
       
  1124 	}
       
  1125 	if(windowSurface == null) {
       
  1126 		windowSurface = new WindowSurface(this, true);
       
  1127 	}
       
  1128 	return windowSurface;
       
  1129 }
       
  1130 
       
  1131 }