javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Control.java
branchRCL_3
changeset 65 ae942d28ec0e
equal deleted inserted replaced
60:6c158198356e 65:ae942d28ec0e
       
     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 java.util.Vector;
       
    16 
       
    17 import org.eclipse.ercp.swt.mobile.Command;
       
    18 import org.eclipse.swt.SWT;
       
    19 import org.eclipse.swt.SWTException;
       
    20 import org.eclipse.swt.events.ControlListener;
       
    21 import org.eclipse.swt.events.FocusListener;
       
    22 import org.eclipse.swt.events.KeyListener;
       
    23 import org.eclipse.swt.events.MouseListener;
       
    24 import org.eclipse.swt.events.MouseMoveListener;
       
    25 import org.eclipse.swt.events.PaintListener;
       
    26 import org.eclipse.swt.events.TraverseListener;
       
    27 import org.eclipse.swt.graphics.Color;
       
    28 import org.eclipse.swt.graphics.Drawable;
       
    29 import org.eclipse.swt.graphics.Font;
       
    30 import org.eclipse.swt.graphics.GC;
       
    31 import org.eclipse.swt.graphics.Image;
       
    32 import org.eclipse.swt.graphics.Internal_GfxPackageSupport;
       
    33 import org.eclipse.swt.graphics.Point;
       
    34 import org.eclipse.swt.graphics.Rectangle;
       
    35 import org.eclipse.swt.internal.qt.CommandUtils;
       
    36 import org.eclipse.swt.internal.qt.GCData;
       
    37 import org.eclipse.swt.internal.qt.OS;
       
    38 import org.eclipse.swt.internal.qt.QObjectDeleteWrapper;
       
    39 import org.eclipse.swt.internal.qt.SharedGCWrapper;
       
    40 import org.eclipse.swt.internal.qt.WidgetConstant;
       
    41 import org.eclipse.swt.internal.qt.WidgetState;
       
    42 import org.eclipse.swt.internal.qt.graphics.NativeCommandBuffer;
       
    43 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
       
    44 
       
    45 /**
       
    46  * Control is the abstract superclass of all windowed user interface classes.
       
    47  * <p>
       
    48  * <dl>
       
    49  * <dt><b>Styles:</b>
       
    50  * <dd>BORDER</dd>
       
    51  * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
       
    52  * <dt><b>Events:</b>
       
    53  * <dd>FocusIn, FocusOut, KeyDown, KeyUp, MouseDoubleClick, MouseDown,
       
    54  *     MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
       
    55  * </dl>
       
    56  * <p>
       
    57  * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
       
    58  * </p><p>
       
    59  * IMPORTANT: This class is intended to be subclassed <em>only</em>
       
    60  * within the SWT implementation.
       
    61  * </p>
       
    62  */
       
    63 public abstract class Control extends Widget implements Drawable {
       
    64     Composite parent;
       
    65     int frameHandle, extraStyle;
       
    66     Menu menu;
       
    67     Font font;
       
    68     boolean toolTipTextExists;
       
    69     Object layoutData;
       
    70     Color foreground, background;
       
    71     Image backgroundImage;
       
    72     private Command[] commandList;
       
    73 
       
    74     // Flags controlling traverse key event handling
       
    75     boolean traverseDoit, traverseCancel;
       
    76 
       
    77     // Each external GC has its own buffer for now.
       
    78     // Not possible to bind several GCs to one buffer.
       
    79     Vector/*<GraphicsContext>*/ bufferedGcs;
       
    80     Vector/*<Buffer>*/ gcBuffers;
       
    81 
       
    82     private byte isPainting;
       
    83     boolean bufferFlush;
       
    84 
       
    85 Control() {
       
    86 }
       
    87 
       
    88 /**
       
    89  * Constructs a new instance of this class given its parent
       
    90  * and a style value describing its behavior and appearance.
       
    91  * <p>
       
    92  * The style value is either one of the style constants defined in
       
    93  * class <code>SWT</code> which is applicable to instances of this
       
    94  * class, or must be built by <em>bitwise OR</em>'ing together
       
    95  * (that is, using the <code>int</code> "|" operator) two or more
       
    96  * of those <code>SWT</code> style constants. The class description
       
    97  * lists the style constants that are applicable to the class.
       
    98  * Style bits are also inherited from superclasses.
       
    99  * </p>
       
   100  *
       
   101  * @param parent a composite control which will be the parent of the new instance (cannot be null)
       
   102  * @param style the style of control to construct
       
   103  *
       
   104  * @exception IllegalArgumentException <ul>
       
   105  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
       
   106  * </ul>
       
   107  * @exception SWTException <ul>
       
   108  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   109  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   110  * </ul>
       
   111  *
       
   112  * @see SWT#BORDER
       
   113  * @see Widget#checkSubclass
       
   114  * @see Widget#getStyle
       
   115  */
       
   116 public Control(Composite parent, int style) {
       
   117     this(parent, style, 0, null, false);
       
   118 }
       
   119 
       
   120 /**
       
   121  * <p>
       
   122  * <b>IMPORTANT:</b> This constructor is <em>not</em> part of the SWT
       
   123  * public API. It should never be referenced from application code.
       
   124  * </p>
       
   125  */
       
   126 protected Control(Composite parent, int style, int extraStyle, Object packageProxy,
       
   127         boolean isExtended) {
       
   128     super(parent, style, extraStyle, packageProxy, isExtended);
       
   129     this.parent = parent;
       
   130     this.extraStyle = extraStyle;
       
   131     createWidget(0);
       
   132     OS.QWidget_setParent(topHandle, parent.handle);
       
   133     OS.QWidget_resize(topHandle, 0, 0);
       
   134     if(isParentMirrored()) {
       
   135         Point size = OS.QWidget_size(topHandle);
       
   136         OS.QWidget_move(topHandle, parent.getClientWidth() - size.x, 0);
       
   137     }
       
   138     OS.QWidget_setVisible(topHandle, true);
       
   139     if(this.parent.packageProxy != null) {
       
   140         this.parent.packageProxy.addControl(this);
       
   141     } else {
       
   142         this.parent.addControl_pp(this);
       
   143     }
       
   144 }
       
   145 
       
   146 void addCommand(final Command command) {
       
   147     if (command.control != this)
       
   148         return;
       
   149     if (commandList == null) {
       
   150         commandList = new Command[1];
       
   151         commandList[0] = command;
       
   152         return;
       
   153     }
       
   154     int size = commandList.length;
       
   155 
       
   156     for (int i = 0; i < size; i++) {
       
   157         if (commandList[i] == command)
       
   158             return;
       
   159     }
       
   160     Command[] newList = new Command[size + 1];
       
   161     System.arraycopy(commandList, 0, newList, 0, size);
       
   162     newList[size] = command;
       
   163     commandList = newList;
       
   164 }
       
   165 
       
   166 /**
       
   167  * Adds the listener to the collection of listeners who will be notified when
       
   168  * the control is moved or resized, by sending it one of the messages defined in
       
   169  * the <code>ControlListener</code> interface.
       
   170  *
       
   171  * @param listener
       
   172  *            the listener which should be notified
       
   173  *
       
   174  * @exception IllegalArgumentException
       
   175  *                <ul>
       
   176  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   177  *                </ul>
       
   178  * @exception SWTException
       
   179  *                <ul>
       
   180  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
       
   181  *                </li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   182  *                thread that created the receiver</li>
       
   183  *                </ul>
       
   184  *
       
   185  * @see ControlListener
       
   186  * @see #removeControlListener
       
   187  */
       
   188 public void addControlListener(ControlListener listener) {
       
   189     checkWidget();
       
   190     if (listener == null)
       
   191         error(SWT.ERROR_NULL_ARGUMENT);
       
   192     TypedListener typedListener = new TypedListener(listener);
       
   193     addListener(SWT.Resize, typedListener);
       
   194     addListener(SWT.Move, typedListener);
       
   195 }
       
   196 
       
   197 /**
       
   198  * Adds the listener to the collection of listeners who will be notified when
       
   199  * the control gains or loses focus, by sending it one of the messages defined
       
   200  * in the <code>FocusListener</code> interface.
       
   201  *
       
   202  * @param listener
       
   203  *            the listener which should be notified
       
   204  *
       
   205  * @exception IllegalArgumentException
       
   206  *                <ul>
       
   207  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   208  *                </ul>
       
   209  * @exception SWTException
       
   210  *                <ul>
       
   211  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
       
   212  *                </li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   213  *                thread that created the receiver</li>
       
   214  *                </ul>
       
   215  *
       
   216  * @see FocusListener
       
   217  * @see #removeFocusListener
       
   218  */
       
   219 public void addFocusListener(FocusListener listener) {
       
   220     checkWidget();
       
   221     if (listener == null)
       
   222         error(SWT.ERROR_NULL_ARGUMENT);
       
   223     TypedListener typedListener = new TypedListener(listener);
       
   224     addListener(SWT.FocusIn, typedListener);
       
   225     addListener(SWT.FocusOut, typedListener);
       
   226 }
       
   227 
       
   228 /**
       
   229  * Adds the listener to the collection of listeners who will be notified when
       
   230  * keys are pressed and released on the system keyboard, by sending it one of
       
   231  * the messages defined in the <code>KeyListener</code> interface.
       
   232  * <p>
       
   233  * When a key listener is added to a control, the control will take part in
       
   234  * widget traversal. By default, all traversal keys (such as the tab key and so
       
   235  * on) are delivered to the control. In order for a control to take part in
       
   236  * traversal, it should listen for traversal events. Otherwise, the user can
       
   237  * traverse into a control but not out. Note that native controls such as table
       
   238  * and tree implement key traversal in the operating system. It is not necessary
       
   239  * to add traversal listeners for these controls, unless you want to override
       
   240  * the default traversal.
       
   241  * </p>
       
   242  *
       
   243  * @param listener
       
   244  *            the listener which should be notified
       
   245  *
       
   246  * @exception IllegalArgumentException
       
   247  *                <ul>
       
   248  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   249  *                </ul>
       
   250  * @exception SWTException
       
   251  *                <ul>
       
   252  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   253  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   254  *                thread that created the receiver</li>
       
   255  *                </ul>
       
   256  *
       
   257  * @see KeyListener
       
   258  * @see #removeKeyListener
       
   259  */
       
   260 public void addKeyListener(KeyListener listener) {
       
   261     checkWidget();
       
   262     if (listener == null)
       
   263         error(SWT.ERROR_NULL_ARGUMENT);
       
   264     TypedListener typedListener = new TypedListener(listener);
       
   265     addListener(SWT.KeyUp, typedListener);
       
   266     addListener(SWT.KeyDown, typedListener);
       
   267 }
       
   268 
       
   269 /**
       
   270  * Adds the listener to the collection of listeners who will be notified when
       
   271  * mouse buttons are pressed and released, by sending it one of the messages
       
   272  * defined in the <code>MouseListener</code> interface.
       
   273  *
       
   274  * @param listener
       
   275  *            the listener which should be notified
       
   276  *
       
   277  * @exception IllegalArgumentException
       
   278  *                <ul>
       
   279  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   280  *                </ul>
       
   281  * @exception SWTException
       
   282  *                <ul>
       
   283  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   284  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   285  *                thread that created the receiver</li>
       
   286  *                </ul>
       
   287  *
       
   288  * @see MouseListener
       
   289  * @see #removeMouseListener
       
   290  */
       
   291 public void addMouseListener(MouseListener listener) {
       
   292     checkWidget();
       
   293     if (listener == null)
       
   294         error(SWT.ERROR_NULL_ARGUMENT);
       
   295     TypedListener typedListener = new TypedListener(listener);
       
   296     addListener(SWT.MouseDown, typedListener);
       
   297     addListener(SWT.MouseUp, typedListener);
       
   298     addListener(SWT.MouseDoubleClick, typedListener);
       
   299 }
       
   300 
       
   301 /**
       
   302  * Adds the listener to the collection of listeners who will be notified when
       
   303  * the mouse moves, by sending it one of the messages defined in the
       
   304  * <code>MouseMoveListener</code> interface.
       
   305  *
       
   306  * @param listener
       
   307  *            the listener which should be notified
       
   308  *
       
   309  * @exception IllegalArgumentException
       
   310  *                <ul>
       
   311  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   312  *                </ul>
       
   313  * @exception SWTException
       
   314  *                <ul>
       
   315  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   316  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   317  *                thread that created the receiver</li>
       
   318  *                </ul>
       
   319  *
       
   320  * @see MouseMoveListener
       
   321  * @see #removeMouseMoveListener
       
   322  */
       
   323 public void addMouseMoveListener(MouseMoveListener listener) {
       
   324     checkWidget();
       
   325     if (listener == null)
       
   326         error(SWT.ERROR_NULL_ARGUMENT);
       
   327     TypedListener typedListener = new TypedListener(listener);
       
   328     addListener(SWT.MouseMove, typedListener);
       
   329 }
       
   330 
       
   331 /**
       
   332  * Adds the listener to the collection of listeners who will be notified when
       
   333  * the receiver needs to be painted, by sending it one of the messages defined
       
   334  * in the <code>PaintListener</code> interface.
       
   335  *
       
   336  * @param listener
       
   337  *            the listener which should be notified
       
   338  *
       
   339  * @exception IllegalArgumentException
       
   340  *                <ul>
       
   341  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   342  *                </ul>
       
   343  * @exception SWTException
       
   344  *                <ul>
       
   345  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   346  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   347  *                thread that created the receiver</li>
       
   348  *                </ul>
       
   349  *
       
   350  * @see PaintListener
       
   351  * @see #removePaintListener
       
   352  */
       
   353 public void addPaintListener(PaintListener listener) {
       
   354     checkWidget();
       
   355     if (listener == null)
       
   356         error(SWT.ERROR_NULL_ARGUMENT);
       
   357     TypedListener typedListener = new TypedListener(listener);
       
   358     addListener(SWT.Paint, typedListener);
       
   359 }
       
   360 
       
   361 /**
       
   362  * Adds the listener to the collection of listeners who will be notified when
       
   363  * traversal events occur, by sending it one of the messages defined in the
       
   364  * <code>TraverseListener</code> interface.
       
   365  *
       
   366  * @param listener
       
   367  *            the listener which should be notified
       
   368  *
       
   369  * @exception IllegalArgumentException
       
   370  *                <ul>
       
   371  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   372  *                </ul>
       
   373  * @exception SWTException
       
   374  *                <ul>
       
   375  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   376  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   377  *                thread that created the receiver</li>
       
   378  *                </ul>
       
   379  *
       
   380  * @see TraverseListener
       
   381  * @see #removeTraverseListener
       
   382  */
       
   383 public void addTraverseListener(TraverseListener listener) {
       
   384     checkWidget();
       
   385     if (listener == null)
       
   386         error(SWT.ERROR_NULL_ARGUMENT);
       
   387     TypedListener typedListener = new TypedListener(listener);
       
   388     addListener(SWT.Traverse, typedListener);
       
   389 }
       
   390 
       
   391 //This is called with the background control's background color
       
   392 void applyBackgroundColor(Color color) {
       
   393     // Get a temporary copy of the widget's palette, modify the background
       
   394     // color, and set the palette back to the widget.
       
   395     int palette = OS.QWidget_swt_palette_new(topHandle);
       
   396     try {
       
   397         setPaletteBgColor(palette, color);
       
   398         OS.QWidget_setPalette(topHandle, palette);
       
   399     } finally {
       
   400         OS.QPalette_delete(palette);
       
   401     }
       
   402     updateAutoFillBackground();
       
   403 }
       
   404 
       
   405 //This is called with the background control's background image
       
   406 void applyBackgroundImage(Image image) {
       
   407     // Get a temporary copy of the widget's palette, modify the background
       
   408     // texture, and set the palette back to the widget.
       
   409     int palette = OS.QWidget_swt_palette_new(topHandle);
       
   410     try {
       
   411         setPaletteBgImage(palette, image);
       
   412         OS.QWidget_setPalette(topHandle, palette);
       
   413     } finally {
       
   414         OS.QPalette_delete(palette);
       
   415     }
       
   416     updateAutoFillBackground();
       
   417 }
       
   418 
       
   419 /*
       
   420  * Some widgets need to know when background texture is taken into use. They can
       
   421  * override this to hook in. E.g. scrolling can't be done but whole area needs
       
   422  * repainting if there's a non-single color background in use.
       
   423  */
       
   424 void backgroundImageApplied_pp(Image image) {
       
   425 }
       
   426 
       
   427 /*
       
   428  * Some widgets need to know when background texture of parent taken into use.
       
   429  * They can override this to hook in. E.g. Combo can inherit texture only for
       
   430  * some sub-widgets and for some it needs to draw the background image by
       
   431  * itself.
       
   432  */
       
   433 void backgroundImageInherited(Image image) {
       
   434 }
       
   435 
       
   436 /*
       
   437  * Controls that return true here will use null brush for their background
       
   438  * role(s) when inheriting a background image. This means they don't draw the
       
   439  * background but depend on the parent to draw it. This doesn't work well with
       
   440  * some built-in widgets and they will return false here. When this returns
       
   441  * false then the background image drawing will be handled by the control itself
       
   442  * and the image will appear starting from the control's own origin instead of
       
   443  * the parent's.
       
   444  */
       
   445 boolean canInheritBackgroundImage() {
       
   446     return true;
       
   447 }
       
   448 
       
   449 void checkBackground () {
       
   450     Shell shell = getShell ();
       
   451     if (this == shell) return;
       
   452     state &= ~WidgetState.PARENT_BACKGROUND;
       
   453     Composite composite = parent;
       
   454     do {
       
   455         int mode = composite.backgroundMode;
       
   456         if (mode != SWT.INHERIT_NONE) {
       
   457             // On some platforms INHERIT_DEFAULT depends on the
       
   458             // THEME_BACKGROUND. With Qt we don't have any such criteria
       
   459             // but INHERIT_DEFAULT and INHERIT_FORCE have the same effect.
       
   460             state |= WidgetState.PARENT_BACKGROUND;
       
   461             return;
       
   462         }
       
   463         if (composite == shell) break;
       
   464         composite = composite.parent;
       
   465     } while (true);
       
   466 }
       
   467 
       
   468 void checkBorder_pp() {
       
   469     if (frameHandle != 0) {
       
   470         if ((style & SWT.BORDER) == 0) {
       
   471             OS.QFrame_setFrameStyle(frameHandle, OS.QT_NOFRAME);
       
   472         } else {
       
   473             int qStyle = OS.QFrame_frameShape(frameHandle);
       
   474             if ((qStyle & (OS.QT_FRAMEPANEL | OS.QT_FRAMEWINPANEL
       
   475                     | OS.QT_FRAMESTYLEDPANEL | OS.QT_FRAMEBOX)) == 0) {
       
   476                 OS.QFrame_setFrameStyle(frameHandle, qStyle
       
   477                         | OS.QT_FRAMESTYLEDPANEL);
       
   478             }
       
   479         }
       
   480     }
       
   481 
       
   482     // a control has to manage the border by itself if it can't provide a frame
       
   483     // handle .
       
   484 
       
   485     if (getBorderWidth() == 0)
       
   486         // remove border flag if there is no border
       
   487         style &= ~SWT.BORDER;
       
   488 }
       
   489 
       
   490 void checkBuffered() {
       
   491     style &= ~SWT.DOUBLE_BUFFERED;
       
   492 }
       
   493 
       
   494 void checkMirrored() {
       
   495     if ((style & SWT.RIGHT_TO_LEFT) != 0) {
       
   496         style |= SWT.MIRRORED;
       
   497     } else {
       
   498         style &= ~SWT.MIRRORED;
       
   499     }
       
   500 }
       
   501 
       
   502 void checkNoBackground() {
       
   503     style &= ~SWT.NO_BACKGROUND;
       
   504 }
       
   505 
       
   506 void checkNoFocus() {
       
   507 // Nothing to be done for Control by default. Override case by case.
       
   508 }
       
   509 
       
   510 void checkNoRedrawResize() {
       
   511     style &= ~SWT.NO_REDRAW_RESIZE;
       
   512 }
       
   513 
       
   514 /**
       
   515  * Returns the preferred size of the receiver.
       
   516  * <p>
       
   517  * The <em>preferred size</em> of a control is the size that it would best be
       
   518  * displayed at. The width hint and height hint arguments allow the caller to
       
   519  * ask a control questions such as "Given a particular width, how high does the
       
   520  * control need to be to show all of the contents?" To indicate that the caller
       
   521  * does not wish to constrain a particular dimension, the constant
       
   522  * <code>SWT.DEFAULT</code> is passed for the hint.
       
   523  * </p>
       
   524  *
       
   525  * @param wHint
       
   526  *            the width hint (can be <code>SWT.DEFAULT</code>)
       
   527  * @param hHint
       
   528  *            the height hint (can be <code>SWT.DEFAULT</code>)
       
   529  * @return the preferred size of the control
       
   530  *
       
   531  * @exception SWTException
       
   532  *                <ul>
       
   533  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   534  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   535  *                thread that created the receiver</li>
       
   536  *                </ul>
       
   537  *
       
   538  * @see Layout
       
   539  * @see #getBorderWidth
       
   540  * @see #getBounds
       
   541  * @see #getSize
       
   542  * @see #pack(boolean)
       
   543  * @see "computeTrim, getClientArea for controls that implement them"
       
   544  */
       
   545 public Point computeSize(int wHint, int hHint) {
       
   546     return computeSize(wHint, hHint, true);
       
   547 }
       
   548 
       
   549 /**
       
   550  * Returns the preferred size of the receiver.
       
   551  * <p>
       
   552  * The <em>preferred size</em> of a control is the size that it would best be
       
   553  * displayed at. The width hint and height hint arguments allow the caller to
       
   554  * ask a control questions such as "Given a particular width, how high does the
       
   555  * control need to be to show all of the contents?" To indicate that the caller
       
   556  * does not wish to constrain a particular dimension, the constant
       
   557  * <code>SWT.DEFAULT</code> is passed for the hint.
       
   558  * </p>
       
   559  * <p>
       
   560  * If the changed flag is <code>true</code>, it indicates that the receiver's
       
   561  * <em>contents</em> have changed, therefore any caches that a layout manager
       
   562  * containing the control may have been keeping need to be flushed. When the
       
   563  * control is resized, the changed flag will be <code>false</code>, so layout
       
   564  * manager caches can be retained.
       
   565  * </p>
       
   566  *
       
   567  * @param wHint
       
   568  *            the width hint (can be <code>SWT.DEFAULT</code>)
       
   569  * @param hHint
       
   570  *            the height hint (can be <code>SWT.DEFAULT</code>)
       
   571  * @param changed
       
   572  *            <code>true</code> if the control's contents have changed, and
       
   573  *            <code>false</code> otherwise
       
   574  * @return the preferred size of the control.
       
   575  *
       
   576  * @exception SWTException
       
   577  *                <ul>
       
   578  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   579  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   580  *                thread that created the receiver</li>
       
   581  *                </ul>
       
   582  *
       
   583  * @see Layout
       
   584  * @see #getBorderWidth
       
   585  * @see #getBounds
       
   586  * @see #getSize
       
   587  * @see #pack(boolean)
       
   588  * @see "computeTrim, getClientArea for controls that implement them"
       
   589  */
       
   590 public Point computeSize(int wHint, int hHint, boolean changed) {
       
   591     checkWidget();
       
   592 
       
   593     if (changed) {
       
   594         OS.QWidget_updateGeometry(topHandle);
       
   595     }
       
   596 
       
   597     // The border, if enabled, is already included in the native size hint
       
   598     Point res = OS.QWidget_sizeHint(topHandle);
       
   599     if (res.x < 0) {
       
   600         res.x = WidgetConstant.DEFAULT_WIDTH;
       
   601     }
       
   602     if (res.y < 0) {
       
   603         res.y = WidgetConstant.DEFAULT_HEIGHT;
       
   604     }
       
   605 
       
   606     int border = getBorderWidth();
       
   607     if (wHint != SWT.DEFAULT) {
       
   608         res.x = wHint + 2 * border;
       
   609     }
       
   610     if (hHint != SWT.DEFAULT) {
       
   611         res.y = hHint + 2 * border;
       
   612     }
       
   613 
       
   614     return res;
       
   615 }
       
   616 
       
   617 Control computeTabGroup() {
       
   618     if (isTabGroup())
       
   619         return this;
       
   620     return parent.computeTabGroup();
       
   621 }
       
   622 
       
   623 Control[] computeTabList() {
       
   624     if (isTabGroup()) {
       
   625         if (getVisible() && getEnabled()) {
       
   626             return new Control[] { this };
       
   627         }
       
   628     }
       
   629     return new Control[0];
       
   630 }
       
   631 
       
   632 Control computeTabRoot() {
       
   633     Control[] tabList = parent._getTabList();
       
   634     if (tabList != null) {
       
   635         int index = 0;
       
   636         while (index < tabList.length) {
       
   637             if (tabList[index] == this)
       
   638                 break;
       
   639             index++;
       
   640         }
       
   641         if (index == tabList.length) {
       
   642             if (isTabGroup())
       
   643                 return this;
       
   644         }
       
   645     }
       
   646     return parent.computeTabRoot();
       
   647 }
       
   648 
       
   649 void createWidget(int index) {
       
   650     checkOrientation(parent);
       
   651     super.createWidget(index);
       
   652     checkBuffered();
       
   653     checkMirrored();
       
   654     if(packageProxy != null) {
       
   655         packageProxy.checkBorder();
       
   656     } else {
       
   657         checkBorder_pp();
       
   658     }
       
   659     checkNoBackground();
       
   660     checkNoRedrawResize();
       
   661     checkNoFocus();
       
   662     checkBackground();
       
   663     if ((style & SWT.RIGHT_TO_LEFT) != 0){
       
   664         OS.QWidget_setLayoutDirection(topHandle, OS.QT_RIGHTTOLEFT);
       
   665     } else {
       
   666         OS.QWidget_setLayoutDirection(topHandle, OS.QT_LEFTTORIGHT);
       
   667     }
       
   668     // This creates a custom palette for the control
       
   669     if(packageProxy != null) {
       
   670         packageProxy.setBackground();
       
   671     } else {
       
   672         setBackground_pp();
       
   673     }
       
   674 }
       
   675 
       
   676 boolean doHandleMouseEvent(int type, int widgetHandle, int button, int x,
       
   677         int y, int state, int buttons) {
       
   678     if (!isEnabled()) {
       
   679         // In SWT parent is supposed to receive events of a disabled
       
   680         // control.
       
   681         // Many Qt widgets consume the events when they are disabled.
       
   682         // To get SWT behavior, a new event is sent to the parent and the
       
   683         // native event is cancelled.
       
   684         mouseToParent(type, widgetHandle, button, x, y, state, buttons);
       
   685         return true;
       
   686     }
       
   687     Point p = mapToClientArea(widgetHandle, x, y);
       
   688     return sendMouseEvent(type, button, false, p.x, p.y, state, buttons);
       
   689 }
       
   690 
       
   691 /*
       
   692  * Processes a mnemonic hit. Called on the focused control when some control
       
   693  * gets a shortcut event. Focused control is then sent traversal/key events.
       
   694  */
       
   695 boolean doProcessShortCut(int key, int modifier, int character) {
       
   696     // Send traverse/key event
       
   697     Event event = sendTraverseEvent(SWT.TRAVERSE_MNEMONIC, key, modifier,
       
   698             character);
       
   699     if (isDisposed())
       
   700         return true;
       
   701     if (event.doit) {
       
   702         // Traversal is done respective to the control which has the
       
   703         // mnemonic.
       
   704         if (doTraversal(event)) {
       
   705             return true; // Cancel the shortcut event
       
   706         }
       
   707     }
       
   708     sendKeyEvent(SWT.KeyDown, key, modifier, character, 0);
       
   709 
       
   710     return true; // Cancel the shortcut event
       
   711 }
       
   712 
       
   713 void doRedraw() {
       
   714     OS.QWidget_update(handle);
       
   715 }
       
   716 
       
   717 void doRedraw(int x, int y, int width, int height) {
       
   718     OS.QWidget_update(handle, x, y, width, height);
       
   719 }
       
   720 
       
   721 boolean doTraversal(Event event) {
       
   722     if (!event.doit)
       
   723         return false;
       
   724     switch (event.detail) {
       
   725     case SWT.TRAVERSE_NONE:
       
   726         return true;
       
   727     case SWT.TRAVERSE_ESCAPE:
       
   728         return traverseEscape();
       
   729     case SWT.TRAVERSE_RETURN:
       
   730         return traverseReturn();
       
   731     case SWT.TRAVERSE_TAB_NEXT:
       
   732         return traverseGroup(true);
       
   733     case SWT.TRAVERSE_TAB_PREVIOUS:
       
   734         return traverseGroup(false);
       
   735     case SWT.TRAVERSE_ARROW_NEXT:
       
   736         return traverseItem(true);
       
   737     case SWT.TRAVERSE_ARROW_PREVIOUS:
       
   738         return traverseItem(false);
       
   739     case SWT.TRAVERSE_MNEMONIC:
       
   740         return traverseMnemonic(event.character);
       
   741     case SWT.TRAVERSE_PAGE_NEXT:
       
   742         return traversePage(true);
       
   743     case SWT.TRAVERSE_PAGE_PREVIOUS:
       
   744         return traversePage(false);
       
   745     }
       
   746     return false;
       
   747 }
       
   748 
       
   749 void enableWidget(boolean enabled) {
       
   750     // Disabling a widget implicitly disables all its children. Enabling
       
   751     // respectively enables all child widgets unless they have been explicitly
       
   752     // disabled.
       
   753     OS.QWidget_setEnabled(topHandle, enabled);
       
   754 }
       
   755 
       
   756 Control findBackgroundControl () {
       
   757     if (background != null || backgroundImage != null) return this;
       
   758     return (state & WidgetState.PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
       
   759 }
       
   760 
       
   761 Menu[] findMenus(Control control) {
       
   762     if (menu != null && this != control)
       
   763         return new Menu[] { menu };
       
   764     return new Menu[0];
       
   765 }
       
   766 
       
   767 /*
       
   768  * Finds the next control in the parent's child array.
       
   769  *
       
   770  * @param loopOver
       
   771  *            If this control is the last one, should the search loop over and
       
   772  *            return the first control as the next one.
       
   773  * @return The next control with the same parent or null.
       
   774  */
       
   775 Control findNextControl(boolean loopOver) {
       
   776     Composite parent = getParent();
       
   777     if (parent == null)
       
   778         return null;
       
   779     Control nextChild = null;
       
   780     boolean next = false;
       
   781     Control[] children = parent._getChildren();
       
   782     for (int i = 0; i < children.length; i++) {
       
   783         Control child = children[i];
       
   784         if (!next) {
       
   785             if (child.equals(this)) {
       
   786                 next = true;
       
   787             }
       
   788         } else {
       
   789             nextChild = children[i];
       
   790         }
       
   791     }
       
   792     if (nextChild == null && loopOver && children.length > 0
       
   793             && children[0] != this) {
       
   794         nextChild = children[0];
       
   795     }
       
   796     return nextChild;
       
   797 }
       
   798 
       
   799 void fixFocus (Control focusControl) {
       
   800     Shell shell = getShell ();
       
   801     Control control = this;
       
   802     while (control != shell && (control = control.parent) != null) {
       
   803         if (control.setFixedFocus ()) return;
       
   804     }
       
   805     shell.setSavedFocus (focusControl);
       
   806 
       
   807     // Set the focus to desktop as the last resort
       
   808     int desktopWidget = OS.QApplication_desktop();
       
   809     if(desktopWidget != 0) {
       
   810         OS.QWidget_setFocus(desktopWidget, OS.QT_OTHERFOCUSREASON);
       
   811     }
       
   812 }
       
   813 
       
   814 void fixMousePropagation() {
       
   815     // In SWT mouse events are not supposed to propagate to the parent like in
       
   816     // Qt. Thus, the default is never to propagate. 
       
   817     if(handle != 0) {
       
   818         OS.QWidget_setAttribute(handle, OS.QT_WA_NOMOUSEPROPAGATION, true);
       
   819     }
       
   820 }
       
   821 
       
   822 void flushBuffers() {
       
   823     if (bufferedGcs != null) {
       
   824         for (int i = 0; i < bufferedGcs.size(); i++) {
       
   825             GraphicsContext igc = (GraphicsContext)bufferedGcs.elementAt(i);
       
   826             NativeCommandBuffer buf = (NativeCommandBuffer)gcBuffers.elementAt(i);
       
   827             igc.releaseTarget();
       
   828             igc.bindTarget(this);
       
   829             igc.render(buf);
       
   830             igc.releaseTarget();
       
   831             igc.bindTarget(buf, this);
       
   832         }
       
   833     }
       
   834 }
       
   835 
       
   836 /**
       
   837  * Forces the receiver to have the <em>keyboard focus</em>, causing all keyboard
       
   838  * events to be delivered to it.
       
   839  *
       
   840  * @return <code>true</code> if the control got focus, and <code>false</code> if
       
   841  *         it was unable to.
       
   842  *
       
   843  * @exception SWTException
       
   844  *                <ul>
       
   845  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   846  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   847  *                thread that created the receiver</li>
       
   848  *                </ul>
       
   849  *
       
   850  * @see #setFocus
       
   851  */
       
   852 public boolean forceFocus() {
       
   853     checkWidget();
       
   854     return forceFocus(OS.QT_OTHERFOCUSREASON);
       
   855 }
       
   856 
       
   857 boolean forceFocus(int focusReason) {
       
   858     if (Display.focusEvent == SWT.FocusOut) return false;
       
   859     Decorations shell = menuShell();
       
   860     shell.setSavedFocus(this);
       
   861     if (!isEnabled() || !isVisible() || !isActive())
       
   862         return false;
       
   863     if (isFocusControl())
       
   864         return true;
       
   865     shell.setSavedFocus(null);
       
   866     shell.bringToTop(false);
       
   867 
       
   868     // Wait for requests sent in bringToTop to complete. This doesn't guarantee
       
   869     // that focus has moved after this.
       
   870     if (OS.windowServer == OS.WS_X11) {
       
   871         waitXRequestComplete();
       
   872         if (isDisposed())
       
   873             return false;
       
   874     }
       
   875 
       
   876     // Gives focus to a widget regardless of its focus policy.
       
   877     // If widget is hidden then it'll get focus when it's shown.
       
   878     OS.QWidget_setFocus(handle, focusReason);
       
   879 
       
   880     if (isDisposed())
       
   881         return false;
       
   882     shell.setSavedFocus(this);
       
   883 
       
   884     // Because focus transition cannot be guaranteed to have completed a fixed
       
   885     // return value needs to be returned for consistent focus behavior.
       
   886     if (OS.windowServer == OS.WS_X11)
       
   887         return true;
       
   888 
       
   889     return (packageProxy != null ? packageProxy._isFocusControl() : _isFocusControl_pp());
       
   890 }
       
   891 
       
   892 /**
       
   893  * Returns the receiver's background color.
       
   894  *
       
   895  * @return the background color
       
   896  *
       
   897  * @exception SWTException
       
   898  *                <ul>
       
   899  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   900  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   901  *                thread that created the receiver</li>
       
   902  *                </ul>
       
   903  */
       
   904 public Color getBackground() {
       
   905     checkWidget();
       
   906     Control control = findBackgroundControl ();
       
   907     if (control == null) control = this;
       
   908     if (control.background != null) {
       
   909         // Return a copy
       
   910         return Internal_GfxPackageSupport.newColor(display, control.background.handle);
       
   911     }
       
   912     int palette = 0;
       
   913     int[] rgb;
       
   914     try {
       
   915         palette = OS.QWidget_swt_palette_new(topHandle);
       
   916         rgb = OS.QPalette_color(palette,
       
   917                 OS.QPALETTE_COLORGROUP_NORMAL, getBackgroundColorRole());
       
   918     } finally {
       
   919         OS.QPalette_delete(palette);
       
   920     }
       
   921     return Internal_GfxPackageSupport.newColor(display, (rgb[0] & 0xFF) | ((rgb[1] & 0xFF) << 8) | ((rgb[2] & 0xFF) << 16));
       
   922 }
       
   923 
       
   924 int getBackgroundColorRole() {
       
   925     return OS.QPALETTE_COLORROLE_WINDOW;
       
   926 }
       
   927 
       
   928 /**
       
   929  * Returns the receiver's background image.
       
   930  *
       
   931  * @return the background image
       
   932  *
       
   933  * @exception SWTException <ul>
       
   934  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   935  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   936  * </ul>
       
   937  *
       
   938  * @since 3.2
       
   939  */
       
   940 public Image getBackgroundImage () {
       
   941     checkWidget ();
       
   942     Control control = findBackgroundControl ();
       
   943     if (control == null) control = this;
       
   944     return control.backgroundImage;
       
   945 }
       
   946 
       
   947 int[] getBackgroundColorRoles() {
       
   948     return new int[] { OS.QPALETTE_COLORROLE_WINDOW,
       
   949             OS.QPALETTE_COLORROLE_BASE, OS.QPALETTE_COLORROLE_BUTTON };
       
   950 }
       
   951 
       
   952 int[] getBackgroundImageRoles() {
       
   953     // For some reason button color role becomes black if pixmap is set to it.
       
   954     // At least with Cleanlooks style this happened.
       
   955     return new int[] { OS.QPALETTE_COLORROLE_WINDOW,
       
   956             OS.QPALETTE_COLORROLE_BASE/*, OS.QPALETTE_COLORROLE_BUTTON */};
       
   957 }
       
   958 
       
   959 /**
       
   960  * Returns the receiver's border width.
       
   961  *
       
   962  * @return the border width
       
   963  *
       
   964  * @exception SWTException
       
   965  *                <ul>
       
   966  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   967  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   968  *                thread that created the receiver</li>
       
   969  *                </ul>
       
   970  */
       
   971 public int getBorderWidth() {
       
   972     checkWidget();
       
   973     if (frameHandle != 0) {
       
   974         return OS.QFrame_frameWidth(frameHandle);
       
   975 
       
   976     }
       
   977     // a control should overwrite this method if it has border but a frame
       
   978     // handle.
       
   979     return 0;
       
   980 }
       
   981 
       
   982 /**
       
   983  * Returns a rectangle describing the receiver's size and location relative to
       
   984  * its parent (or its display if its parent is null), unless the receiver is a
       
   985  * shell. In this case, the location is relative to the display.
       
   986  *
       
   987  * @return the receiver's bounding rectangle
       
   988  *
       
   989  * @exception SWTException
       
   990  *                <ul>
       
   991  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   992  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
   993  *                thread that created the receiver</li>
       
   994  *                </ul>
       
   995  */
       
   996 public Rectangle getBounds() {
       
   997     checkWidget();
       
   998     // This can return
       
   999     // - display relative main window coordinates (if top-level shell)
       
  1000     // - parent's viewport relative coordinates
       
  1001     Rectangle bounds = OS.QWidget_frameGeometry(topHandle);
       
  1002     if (isParentMirrored()) {
       
  1003         bounds.x = parent.getClientWidth() - bounds.width - bounds.x;
       
  1004     }
       
  1005     return bounds;
       
  1006 }
       
  1007 
       
  1008 int getClientWidth() {
       
  1009     return OS.QWidget_rect(handle).width;
       
  1010 }
       
  1011 
       
  1012 Command[] getCommands() {
       
  1013     return commandList == null ? new Command[0] : commandList;
       
  1014 }
       
  1015 
       
  1016 /**
       
  1017  * Returns <code>true</code> if the receiver is enabled, and <code>false</code>
       
  1018  * otherwise. A disabled control is typically not selectable from the user
       
  1019  * interface and draws with an inactive or "grayed" look.
       
  1020  *
       
  1021  * @return the receiver's enabled state
       
  1022  *
       
  1023  * @exception SWTException
       
  1024  *                <ul>
       
  1025  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1026  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1027  *                thread that created the receiver</li>
       
  1028  *                </ul>
       
  1029  *
       
  1030  * @see #isEnabled
       
  1031  */
       
  1032 public boolean getEnabled() {
       
  1033     checkWidget();
       
  1034     return _getEnabled();
       
  1035 }
       
  1036 
       
  1037 boolean _getEnabled() {
       
  1038     return (state & WidgetState.DISABLED) == 0;
       
  1039 }
       
  1040 
       
  1041 /**
       
  1042  * Returns the font that the receiver will use to paint textual information.
       
  1043  *
       
  1044  * @return the receiver's font
       
  1045  *
       
  1046  * @exception SWTException
       
  1047  *                <ul>
       
  1048  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1049  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1050  *                thread that created the receiver</li>
       
  1051  *                </ul>
       
  1052  */
       
  1053 public Font getFont() {
       
  1054     checkWidget();
       
  1055     return font != null ? font : Internal_GfxPackageSupport.newFont(display, OS.SwtFontCache_cache(OS.QWidget_swt_font_new(topHandle)));
       
  1056 }
       
  1057 
       
  1058 /**
       
  1059  * Returns the foreground color that the receiver will use to draw.
       
  1060  *
       
  1061  * @return the receiver's foreground color
       
  1062  *
       
  1063  * @exception SWTException
       
  1064  *                <ul>
       
  1065  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1066  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1067  *                thread that created the receiver</li>
       
  1068  *                </ul>
       
  1069  */
       
  1070 public Color getForeground() {
       
  1071     checkWidget();
       
  1072     if (foreground != null) {
       
  1073         return Internal_GfxPackageSupport.newColor(display, foreground.handle);
       
  1074     }
       
  1075     int paletteHandle = 0;
       
  1076     int[] rgb;
       
  1077     try {
       
  1078         paletteHandle = OS.QWidget_swt_palette_new(handle);
       
  1079         rgb = OS.QPalette_color(paletteHandle,
       
  1080                 OS.QPALETTE_COLORGROUP_NORMAL, getForegroundColorRole());
       
  1081     } finally {
       
  1082         OS.QPalette_delete(paletteHandle);
       
  1083     }
       
  1084     foreground = Internal_GfxPackageSupport.newColor(display, (rgb[0] & 0xFF) | ((rgb[1] & 0xFF) << 8) | ((rgb[2] & 0xFF) << 16));
       
  1085     return Internal_GfxPackageSupport.newColor(display, foreground.handle);
       
  1086 }
       
  1087 
       
  1088 int getForegroundColorRole() {
       
  1089     return OS.QPALETTE_COLORROLE_WINDOWTEXT;
       
  1090 }
       
  1091 
       
  1092 /**
       
  1093  * Returns layout data which is associated with the receiver.
       
  1094  *
       
  1095  * @return the receiver's layout data
       
  1096  *
       
  1097  * @exception SWTException
       
  1098  *                <ul>
       
  1099  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1100  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1101  *                thread that created the receiver</li>
       
  1102  *                </ul>
       
  1103  */
       
  1104 public Object getLayoutData() {
       
  1105     checkWidget();
       
  1106     return layoutData;
       
  1107 }
       
  1108 
       
  1109 /**
       
  1110  * Returns a point describing the receiver's location relative to its parent (or
       
  1111  * its display if its parent is null), unless the receiver is a shell. In this
       
  1112  * case, the point is relative to the display.
       
  1113  *
       
  1114  * @return the receiver's location
       
  1115  *
       
  1116  * @exception SWTException
       
  1117  *                <ul>
       
  1118  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1119  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1120  *                thread that created the receiver</li>
       
  1121  *                </ul>
       
  1122  */
       
  1123 public Point getLocation() {
       
  1124     checkWidget();
       
  1125     Point p = OS.QWidget_pos(topHandle);
       
  1126     if (isParentMirrored()) {
       
  1127         p.x = parent.getClientWidth() - p.x - OS.QWidget_geometry(topHandle).width;
       
  1128     }
       
  1129     return p;
       
  1130 }
       
  1131 
       
  1132 /**
       
  1133  * Returns the receiver's pop up menu if it has one, or null if it does not. All
       
  1134  * controls may optionally have a pop up menu that is displayed when the user
       
  1135  * requests one for the control. The sequence of key strokes, button presses
       
  1136  * and/or button releases that are used to request a pop up menu is platform
       
  1137  * specific.
       
  1138  *
       
  1139  * @return the receiver's menu
       
  1140  *
       
  1141  * @exception SWTException
       
  1142  *                <ul>
       
  1143  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1144  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1145  *                thread that created the receiver</li>
       
  1146  *                </ul>
       
  1147  */
       
  1148 public Menu getMenu() {
       
  1149     checkWidget();
       
  1150     return menu;
       
  1151 }
       
  1152 
       
  1153 /**
       
  1154  * Returns the receiver's parent, which must be a <code>Composite</code> or null
       
  1155  * when the receiver is a shell that was created with null or a display for a
       
  1156  * parent.
       
  1157  *
       
  1158  * @return the receiver's parent
       
  1159  *
       
  1160  * @exception SWTException
       
  1161  *                <ul>
       
  1162  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1163  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1164  *                thread that created the receiver</li>
       
  1165  *                </ul>
       
  1166  */
       
  1167 public Composite getParent() {
       
  1168     checkWidget();
       
  1169     return parent;
       
  1170 }
       
  1171 
       
  1172 int getParentClientWidth() {
       
  1173     if(parent != null) {
       
  1174         return parent.getClientWidth();
       
  1175     } else {
       
  1176         return display.getClientArea().width;
       
  1177     }
       
  1178 }
       
  1179 
       
  1180 /**
       
  1181  * Returns the receiver's shell. For all controls other than shells, this simply
       
  1182  * returns the control's nearest ancestor shell. Shells return themselves, even
       
  1183  * if they are children of other shells.
       
  1184  *
       
  1185  * @return the receiver's shell
       
  1186  *
       
  1187  * @exception SWTException
       
  1188  *                <ul>
       
  1189  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1190  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1191  *                thread that created the receiver</li>
       
  1192  *                </ul>
       
  1193  *
       
  1194  * @see #getParent
       
  1195  */
       
  1196 public Shell getShell() {
       
  1197     checkWidget();
       
  1198     return _getShell();
       
  1199 }
       
  1200 
       
  1201 Shell _getShell() {
       
  1202     return parent._getShell();
       
  1203 }
       
  1204 
       
  1205 /*
       
  1206  * Returns the control that will handle the shortcut event. I.e. shortcut
       
  1207  * parameters are delivered to that control in a doProcessShortcut call.
       
  1208  */
       
  1209 Control getShortcutHandler() {
       
  1210     // By default the focused control handles the shortcut.
       
  1211     return display.getFocusControl();
       
  1212 }
       
  1213 
       
  1214 /**
       
  1215  * Returns a point describing the receiver's size. The x coordinate of the
       
  1216  * result is the width of the receiver. The y coordinate of the result is the
       
  1217  * height of the receiver.
       
  1218  *
       
  1219  * @return the receiver's size
       
  1220  *
       
  1221  * @exception SWTException
       
  1222  *                <ul>
       
  1223  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1224  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1225  *                thread that created the receiver</li>
       
  1226  *                </ul>
       
  1227  */
       
  1228 public Point getSize() {
       
  1229     checkWidget();
       
  1230     return OS.QWidget_frameSize(topHandle);
       
  1231 }
       
  1232 
       
  1233 /**
       
  1234  * Returns the receiver's tool tip text, or null if it has not been set.
       
  1235  *
       
  1236  * @return the receiver's tool tip text
       
  1237  *
       
  1238  * @exception SWTException
       
  1239  *                <ul>
       
  1240  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1241  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1242  *                thread that created the receiver</li>
       
  1243  *                </ul>
       
  1244  */
       
  1245 public String getToolTipText() {
       
  1246     checkWidget();
       
  1247     String toolTip = null;
       
  1248     if (toolTipTextExists) {
       
  1249         toolTip = OS.QWidget_toolTip(handle);
       
  1250     }
       
  1251     return toolTip;
       
  1252 }
       
  1253 
       
  1254 int getTraversalTypeForKey(int key, int modifier, int character) {
       
  1255     int type = -1;
       
  1256     switch (key) {
       
  1257     case OS.QT_KEY_ESCAPE: {
       
  1258         if (modifier != 0)
       
  1259             break;
       
  1260         type = SWT.TRAVERSE_ESCAPE;
       
  1261         break;
       
  1262     }
       
  1263     case OS.QT_KEY_ENTER:
       
  1264     case OS.QT_KEY_RETURN: {
       
  1265         if (modifier == 0
       
  1266                 || (((modifier & OS.QT_KEYPADMODIFIER) != 0) && key == OS.QT_KEY_ENTER)) {
       
  1267             type = SWT.TRAVERSE_RETURN;
       
  1268         }
       
  1269         break;
       
  1270     }
       
  1271     case OS.QT_KEY_TAB: {
       
  1272         if (modifier != 0)
       
  1273             break;
       
  1274         type = SWT.TRAVERSE_TAB_NEXT;
       
  1275         break;
       
  1276     }
       
  1277     case OS.QT_KEY_BACKTAB: {
       
  1278         if ((modifier & ~OS.QT_SHIFTMODIFIER) != 0)
       
  1279             break;
       
  1280         type = SWT.TRAVERSE_TAB_PREVIOUS;
       
  1281         break;
       
  1282     }
       
  1283     case OS.QT_KEY_UP:
       
  1284     case OS.QT_KEY_LEFT:
       
  1285     case OS.QT_KEY_DOWN:
       
  1286     case OS.QT_KEY_RIGHT: {
       
  1287         if (modifier != 0)
       
  1288             break;
       
  1289         boolean next = (key == OS.QT_KEY_DOWN || key == OS.QT_KEY_RIGHT);
       
  1290         if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
       
  1291             if (key == OS.QT_KEY_LEFT || key == OS.QT_KEY_RIGHT)
       
  1292                 next = !next;
       
  1293         }
       
  1294         // Perform tab group traversal also for arrow keys
       
  1295         type = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
       
  1296         break;
       
  1297     }
       
  1298     case OS.QT_KEY_PAGEUP:
       
  1299     case OS.QT_KEY_PAGEDOWN: {
       
  1300         if (modifier != 0)
       
  1301             break;
       
  1302         type = (key == OS.QT_KEY_PAGEDOWN ? SWT.TRAVERSE_PAGE_NEXT
       
  1303                 : SWT.TRAVERSE_PAGE_PREVIOUS);
       
  1304         break;
       
  1305     }
       
  1306     default:
       
  1307         break;
       
  1308     }
       
  1309     return type;
       
  1310 }
       
  1311 
       
  1312 /**
       
  1313  * Returns <code>true</code> if the receiver is visible, and <code>false</code>
       
  1314  * otherwise.
       
  1315  * <p>
       
  1316  * If one of the receiver's ancestors is not visible or some other condition
       
  1317  * makes the receiver not visible, this method may still indicate that it is
       
  1318  * considered visible even though it may not actually be showing.
       
  1319  * </p>
       
  1320  *
       
  1321  * @return the receiver's visibility state
       
  1322  *
       
  1323  * @exception SWTException
       
  1324  *                <ul>
       
  1325  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1326  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1327  *                thread that created the receiver</li>
       
  1328  *                </ul>
       
  1329  */
       
  1330 public boolean getVisible() {
       
  1331     checkWidget();
       
  1332     return !OS.QWidget_isHidden(topHandle);
       
  1333 }
       
  1334 
       
  1335 final boolean hasFocus() {
       
  1336     return this == display.getFocusControl();
       
  1337 }
       
  1338 
       
  1339 /**
       
  1340  * Invokes platform specific functionality to dispose a GC.
       
  1341  * <p>
       
  1342  * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
       
  1343  * <code>Control</code>. It is marked public only so that it can be shared
       
  1344  * within the packages provided by SWT. It is not available on all platforms,
       
  1345  * and should never be called from application code.
       
  1346  * </p>
       
  1347  *
       
  1348  * @param data
       
  1349  *            the platform specific GC data
       
  1350  */
       
  1351 public void internal_dispose_GC(GCData data) {
       
  1352     checkWidget();
       
  1353     data.internalGc.releaseTarget();
       
  1354 
       
  1355     // If the GraphicsContext we just released is the shared GraphicsContext
       
  1356     // used by all paint listeners then don't really destroy it.
       
  1357     if(data.internalGc == SharedGCWrapper.getSharedGC()) {
       
  1358         return;
       
  1359     }
       
  1360 
       
  1361     if (bufferedGcs != null) {
       
  1362         int i = bufferedGcs.indexOf(data.internalGc);
       
  1363         if (i >= 0) {
       
  1364             bufferedGcs.removeElementAt(i);
       
  1365             gcBuffers.removeElementAt(i);
       
  1366         }
       
  1367     }
       
  1368 
       
  1369     data.internalGc.dispose();
       
  1370 }
       
  1371 
       
  1372 /**
       
  1373  * Invokes platform specific functionality to allocate a new GC handle.
       
  1374  * <p>
       
  1375  * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
       
  1376  * <code>Control</code>. It is marked public only so that it can be shared
       
  1377  * within the packages provided by SWT. It is not available on all platforms,
       
  1378  * and should never be called from application code.
       
  1379  * </p>
       
  1380  *
       
  1381  * @param data
       
  1382  *            the platform specific GC data
       
  1383  * @return the platform specific GC handle
       
  1384  */
       
  1385 public int internal_new_GC(GCData data) {
       
  1386     checkWidget();
       
  1387 
       
  1388     // Try obtaining the shared internal GraphicsContext instance for paint
       
  1389     // listener drawing if it's available. For outside paint listener drawing
       
  1390     // always create a new one.
       
  1391     GraphicsContext sharedGc;
       
  1392     if(isPainting>0 && (sharedGc = SharedGCWrapper.getSharedGC()) != null) {
       
  1393         data.internalGc = sharedGc;
       
  1394     } else {
       
  1395         data.internalGc = new GraphicsContext();
       
  1396     }
       
  1397 
       
  1398     data.drawable = OS.QWidget_swt_paintDevice(handle);
       
  1399     data.device = display;
       
  1400     data.background = getBackground();
       
  1401     data.foreground = getForeground();
       
  1402     data.font = getFont();
       
  1403 
       
  1404     int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
       
  1405     if ((data.style & mask) == 0) {
       
  1406         data.style |= style & (mask | SWT.MIRRORED);
       
  1407     } else {
       
  1408         if ((data.style & SWT.RIGHT_TO_LEFT) != 0) {
       
  1409             data.style |= SWT.MIRRORED;
       
  1410         }
       
  1411     }
       
  1412 
       
  1413     if (isPainting>0) {
       
  1414         data.buffered = false;
       
  1415         data.internalGc.bindTarget(this);
       
  1416     }
       
  1417     else {
       
  1418         data.buffered = true;
       
  1419         if (bufferedGcs == null) {
       
  1420             bufferedGcs = new Vector();
       
  1421         }
       
  1422         if (gcBuffers == null) {
       
  1423             gcBuffers = new Vector();
       
  1424         }
       
  1425         NativeCommandBuffer buf = new NativeCommandBuffer();
       
  1426         data.internalGc.bindTarget(buf, this);
       
  1427         bufferedGcs.addElement(data.internalGc);
       
  1428         gcBuffers.addElement(buf);
       
  1429     }
       
  1430 
       
  1431     return data.internalGc.getHandle();
       
  1432 }
       
  1433 
       
  1434 boolean isActive() {
       
  1435     Dialog dialog = Display.getModalDialog();
       
  1436     if (dialog != null) {
       
  1437         Shell dialogShell = dialog.parent;
       
  1438         if (dialogShell != null && !dialogShell.isDisposed()) {
       
  1439             if (dialogShell != getShell())
       
  1440                 return false;
       
  1441         }
       
  1442     }
       
  1443     Shell shell = null;
       
  1444     Shell[] modalShells = Display.modalShells;
       
  1445     if (modalShells != null) {
       
  1446         int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
       
  1447         int index = modalShells.length;
       
  1448         while (--index >= 0) {
       
  1449             Shell modal = modalShells[index];
       
  1450             if (modal != null) {
       
  1451                 if ((modal.style & bits) != 0) {
       
  1452                     Control control = this;
       
  1453                     while (control != null) {
       
  1454                         if (control == modal)
       
  1455                             break;
       
  1456                         control = control.parent;
       
  1457                     }
       
  1458                     if (control != modal)
       
  1459                         return false;
       
  1460                     break;
       
  1461                 }
       
  1462                 if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
       
  1463                     if (shell == null)
       
  1464                         shell = getShell();
       
  1465                     if (modal.parent == shell)
       
  1466                         return false;
       
  1467                 }
       
  1468             }
       
  1469         }
       
  1470     }
       
  1471     if (shell == null)
       
  1472         shell = getShell();
       
  1473     return shell.getEnabled();
       
  1474 }
       
  1475 
       
  1476 /**
       
  1477  * Returns <code>true</code> if the receiver is enabled and all ancestors up to
       
  1478  * and including the receiver's nearest ancestor shell are enabled. Otherwise,
       
  1479  * <code>false</code> is returned. A disabled control is typically not
       
  1480  * selectable from the user interface and draws with an inactive or "grayed"
       
  1481  * look.
       
  1482  *
       
  1483  * @return the receiver's enabled state
       
  1484  *
       
  1485  * @exception SWTException
       
  1486  *                <ul>
       
  1487  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1488  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1489  *                thread that created the receiver</li>
       
  1490  *                </ul>
       
  1491  *
       
  1492  * @see #getEnabled
       
  1493  */
       
  1494 public boolean isEnabled() {
       
  1495     checkWidget();
       
  1496     return getEnabled() && parent.isEnabled();
       
  1497 }
       
  1498 
       
  1499 boolean isFocusAncestor(Control control) {
       
  1500     while (control != null && control != this && !(control instanceof Shell)) {
       
  1501         control = control.parent;
       
  1502     }
       
  1503     return control == this;
       
  1504 }
       
  1505 
       
  1506 /**
       
  1507  * Returns <code>true</code> if the receiver has the user-interface focus, and
       
  1508  * <code>false</code> otherwise.
       
  1509  *
       
  1510  * @return the receiver's focus state
       
  1511  *
       
  1512  * @exception SWTException
       
  1513  *                <ul>
       
  1514  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1515  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1516  *                thread that created the receiver</li>
       
  1517  *                </ul>
       
  1518  */
       
  1519 public boolean isFocusControl() {
       
  1520     checkWidget();
       
  1521     boolean isFocusControl = (packageProxy != null ? packageProxy._isFocusControl() : _isFocusControl_pp());
       
  1522     if (isFocusControl && !isDisposed()) {
       
  1523         return true;
       
  1524     }
       
  1525     return false;
       
  1526 }
       
  1527 
       
  1528 boolean _isFocusControl_pp() {
       
  1529     int focusHandle = handle;
       
  1530     int proxy = OS.QWidget_focusProxy(handle);
       
  1531     if (proxy != 0)
       
  1532         focusHandle = proxy;
       
  1533     return (OS.QApplication_focusWidget() == focusHandle);
       
  1534 }
       
  1535 
       
  1536 boolean isMirrored() {
       
  1537     return (style & SWT.MIRRORED) != 0;
       
  1538 }
       
  1539 
       
  1540 boolean isParentMirrored() {
       
  1541     if(parent != null) {
       
  1542         return parent.isMirrored();
       
  1543     } else {
       
  1544         // Display is never mirrored
       
  1545         return false;
       
  1546     }
       
  1547 }
       
  1548 
       
  1549 /**
       
  1550  * Returns <code>true</code> if the underlying operating system supports this
       
  1551  * reparenting, otherwise <code>false</code>
       
  1552  *
       
  1553  * @return <code>true</code> if the widget can be reparented, otherwise
       
  1554  *         <code>false</code>
       
  1555  *
       
  1556  * @exception SWTException
       
  1557  *                <ul>
       
  1558  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1559  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1560  *                thread that created the receiver</li>
       
  1561  *                </ul>
       
  1562  */
       
  1563 public boolean isReparentable() {
       
  1564     checkWidget();
       
  1565     return false; // Qt supports but not implemented
       
  1566 }
       
  1567 
       
  1568 final boolean isShowing() {
       
  1569     /*
       
  1570      * This is not complete. Need to check if the widget is obscurred by a
       
  1571      * parent or sibling.
       
  1572      */
       
  1573     if (!isVisible())
       
  1574         return false;
       
  1575     Control control = this;
       
  1576     while (control != null) {
       
  1577         Point size = control.getSize();
       
  1578         if (size.x == 0 || size.y == 0) {
       
  1579             return false;
       
  1580         }
       
  1581         control = control.parent;
       
  1582     }
       
  1583     return true;
       
  1584 }
       
  1585 
       
  1586 boolean isTabGroup() {
       
  1587     // If in tablist then a tabgroup
       
  1588     Control[] tabList = parent._getTabList();
       
  1589     if (tabList != null) {
       
  1590         for (int i = 0; i < tabList.length; i++) {
       
  1591             if (tabList[i] == this)
       
  1592                 return true;
       
  1593         }
       
  1594     }
       
  1595     // If accepts focus by tabbing then a group
       
  1596     int bits = OS.QWidget_focusPolicy(topHandle);
       
  1597     return (bits & OS.QT_FOCUSPOLICY_TABFOCUS) != 0;
       
  1598 }
       
  1599 
       
  1600 boolean isTabItem() {
       
  1601     // If in tablist then not a tabitem but a group
       
  1602     Control[] tabList = parent._getTabList();
       
  1603     if (tabList != null) {
       
  1604         for (int i = 0; i < tabList.length; i++) {
       
  1605             if (tabList[i] == this)
       
  1606                 return false;
       
  1607         }
       
  1608     }
       
  1609     // If accepts focus by tabbing then not a tabitem but a group
       
  1610     int bits = OS.QWidget_focusPolicy(topHandle);
       
  1611     if ((bits & OS.QT_FOCUSPOLICY_TABFOCUS) != 0)
       
  1612         return false;
       
  1613     return true;
       
  1614 }
       
  1615 
       
  1616 boolean isTraversalKey(int key, int modifier, int character) {
       
  1617     return getTraversalTypeForKey(key, modifier, character) != -1;
       
  1618 }
       
  1619 
       
  1620 /**
       
  1621  * Returns <code>true</code> if the receiver is visible and all ancestors up to
       
  1622  * and including the receiver's nearest ancestor shell are visible. Otherwise,
       
  1623  * <code>false</code> is returned.
       
  1624  *
       
  1625  * @return the receiver's visibility state
       
  1626  *
       
  1627  * @exception SWTException
       
  1628  *                <ul>
       
  1629  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1630  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1631  *                thread that created the receiver</li>
       
  1632  *                </ul>
       
  1633  *
       
  1634  * @see #getVisible
       
  1635  */
       
  1636 public boolean isVisible() {
       
  1637     checkWidget();
       
  1638     return getVisible() && parent.isVisible();
       
  1639 }
       
  1640 
       
  1641 Event makeMouseEvent(int type, int button, int x, int y, int modifiers,
       
  1642         int buttons) {
       
  1643     Event event = new Event();
       
  1644     event.button = Display.translateButton(button);
       
  1645     event.detail = 0;
       
  1646     event.count = 0;
       
  1647     if(isMirrored()) {
       
  1648         event.x = getClientWidth() - x;
       
  1649     } else {
       
  1650         event.x = x;
       
  1651     }
       
  1652     event.y = y;
       
  1653     event.stateMask = (Display.translateModifiers(modifiers) | Display
       
  1654             .translateButtons(buttons));
       
  1655     event.stateMask &= ~Display.translateButtons(button);
       
  1656     if (type == SWT.MouseUp)
       
  1657         event.stateMask |= Display.translateButtons(button);
       
  1658     return event;
       
  1659 }
       
  1660 
       
  1661 /*
       
  1662  * The coordinates are mapped to the client area widget if some other widget
       
  1663  * received the event.
       
  1664  */
       
  1665 final Point mapToClientArea(int widgetHandle, int x, int y) {
       
  1666     if (widgetHandle == handle) {
       
  1667         return new Point(x, y);
       
  1668     } else { // scroll area
       
  1669         Point global = OS.QWidget_mapToGlobal(widgetHandle, x, y);
       
  1670         return OS.QWidget_mapFromGlobal(handle, global.x, global.y);
       
  1671     }
       
  1672 }
       
  1673 
       
  1674 void markLayout(boolean changed, boolean all) {
       
  1675     /* Do nothing */
       
  1676 }
       
  1677 
       
  1678 Decorations menuShell() {
       
  1679     return parent.menuShell();
       
  1680 }
       
  1681 
       
  1682 void mouseToParent(int type, int widgetHandle, int button, int x, int y,
       
  1683         int state, int buttons) {
       
  1684     Composite parent = getParent();
       
  1685     if (parent != null) {
       
  1686         Point p = parent.mapToClientArea(widgetHandle, x, y);
       
  1687         Event event = parent.makeMouseEvent(type, button, p.x, p.y, state, buttons);
       
  1688         event.widget = parent;
       
  1689         event.type = type;
       
  1690         display.post(event);
       
  1691     }
       
  1692 }
       
  1693 
       
  1694 /**
       
  1695  * Moves the receiver above the specified control in the drawing order. If the
       
  1696  * argument is null, then the receiver is moved to the top of the drawing order.
       
  1697  * The control at the top of the drawing order will not be covered by other
       
  1698  * controls even if they occupy intersecting areas.
       
  1699  *
       
  1700  * @param control
       
  1701  *            the sibling control (or null)
       
  1702  *
       
  1703  * @exception IllegalArgumentException
       
  1704  *                <ul>
       
  1705  *                <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
       
  1706  *                </ul>
       
  1707  * @exception SWTException
       
  1708  *                <ul>
       
  1709  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1710  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1711  *                thread that created the receiver</li>
       
  1712  *                </ul>
       
  1713  *
       
  1714  * @see Control#moveBelow
       
  1715  * @see Composite#getChildren
       
  1716  */
       
  1717 public void moveAbove(Control control) {
       
  1718     checkWidget();
       
  1719     if (control != null) {
       
  1720         if (control.isDisposed())
       
  1721             error(SWT.ERROR_INVALID_ARGUMENT);
       
  1722         if (parent != control.parent)
       
  1723             return;
       
  1724 
       
  1725         // There's no QWidget::stackOver, only stackUnder. The z order is
       
  1726         // determined by the order of QObject children. Find out the control
       
  1727         // that is above the control that we should move above of. Then use
       
  1728         // stackUnder on that.
       
  1729         Control controlAbove = null;
       
  1730         int parentHandle = 0;
       
  1731         if (parent == null) {
       
  1732             parentHandle = Display.handle;
       
  1733         } else {
       
  1734             parentHandle = parent.handle;
       
  1735         }
       
  1736         int children[] = OS.QObject_children(parentHandle);
       
  1737         int iChild = 0;
       
  1738         boolean next = false;
       
  1739         for (; iChild < children.length; ++iChild) {
       
  1740             if (!next && children[iChild] == control.topHandle) {
       
  1741                 // The next widget we should move below of.
       
  1742                 next = true;
       
  1743                 continue;
       
  1744             }
       
  1745             if (next) {
       
  1746                 Widget widget = Display.getWidget(children[iChild]);
       
  1747                 if (widget != null && widget != this) {
       
  1748                     if (widget instanceof org.eclipse.swt.widgets.Control) {
       
  1749                         controlAbove = (Control) widget;
       
  1750                         break;
       
  1751                     }
       
  1752                 }
       
  1753             }
       
  1754         }
       
  1755         if (controlAbove != null) {
       
  1756             moveBelow(controlAbove);
       
  1757         } else {
       
  1758             // There was no child after the target so move to top.
       
  1759             OS.QWidget_raise(topHandle);
       
  1760         }
       
  1761     } else {
       
  1762         OS.QWidget_raise(topHandle);
       
  1763     }
       
  1764 }
       
  1765 
       
  1766 /**
       
  1767  * Moves the receiver below the specified control in the drawing order. If the
       
  1768  * argument is null, then the receiver is moved to the bottom of the drawing
       
  1769  * order. The control at the bottom of the drawing order will be covered by all
       
  1770  * other controls which occupy intersecting areas.
       
  1771  *
       
  1772  * @param control
       
  1773  *            the sibling control (or null)
       
  1774  *
       
  1775  * @exception IllegalArgumentException
       
  1776  *                <ul>
       
  1777  *                <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
       
  1778  *                </ul>
       
  1779  * @exception SWTException
       
  1780  *                <ul>
       
  1781  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1782  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1783  *                thread that created the receiver</li>
       
  1784  *                </ul>
       
  1785  *
       
  1786  * @see Control#moveAbove
       
  1787  * @see Composite#getChildren
       
  1788  */
       
  1789 public void moveBelow(Control control) {
       
  1790     checkWidget();
       
  1791     if (control != null) {
       
  1792         if (control.isDisposed())
       
  1793             error(SWT.ERROR_INVALID_ARGUMENT);
       
  1794         if (parent != control.parent)
       
  1795             return;
       
  1796         OS.QWidget_stackUnder(topHandle, control.topHandle);
       
  1797 
       
  1798     } else {
       
  1799         OS.QWidget_lower(topHandle);
       
  1800     }
       
  1801 }
       
  1802 
       
  1803 /**
       
  1804  * Causes the receiver to be resized to its preferred size. For a composite,
       
  1805  * this involves computing the preferred size from its layout, if there is one.
       
  1806  *
       
  1807  * @exception SWTException
       
  1808  *                <ul>
       
  1809  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1810  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1811  *                thread that created the receiver</li>
       
  1812  *                </ul>
       
  1813  *
       
  1814  * @see #computeSize(int, int, boolean)
       
  1815  */
       
  1816 public void pack() {
       
  1817     pack(true);
       
  1818 }
       
  1819 
       
  1820 /**
       
  1821  * Causes the receiver to be resized to its preferred size. For a composite,
       
  1822  * this involves computing the preferred size from its layout, if there is one.
       
  1823  * <p>
       
  1824  * If the changed flag is <code>true</code>, it indicates that the receiver's
       
  1825  * <em>contents</em> have changed, therefore any caches that a layout manager
       
  1826  * containing the control may have been keeping need to be flushed. When the
       
  1827  * control is resized, the changed flag will be <code>false</code>, so layout
       
  1828  * manager caches can be retained.
       
  1829  * </p>
       
  1830  *
       
  1831  * @param changed
       
  1832  *            whether or not the receiver's contents have changed
       
  1833  *
       
  1834  * @exception SWTException
       
  1835  *                <ul>
       
  1836  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1837  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  1838  *                thread that created the receiver</li>
       
  1839  *                </ul>
       
  1840  *
       
  1841  * @see #computeSize(int, int, boolean)
       
  1842  */
       
  1843 public void pack(boolean changed) {
       
  1844     setSize(computeSize(SWT.DEFAULT, SWT.DEFAULT, changed));
       
  1845 }
       
  1846 
       
  1847 
       
  1848 
       
  1849 boolean qt_event_contextmenu(int x, int y, int reason) {
       
  1850     Event event = new Event();
       
  1851     event.x = x;
       
  1852     event.y = y;
       
  1853     sendEvent(SWT.MenuDetect, event);
       
  1854     if (event.doit && !isDisposed()) {
       
  1855         // Check if there is a menu or commands to show.
       
  1856         if ((commandList == null || commandList.length == 0) && menu == null)
       
  1857             return true;
       
  1858 
       
  1859         int menuHandle = 0;
       
  1860         boolean commandMenu = this.menu == null || menu.isDisposed();
       
  1861         if (commandMenu) {
       
  1862             menuHandle = OS.QMenu_new(handle);
       
  1863         } else {
       
  1864             menuHandle = menu.handle;
       
  1865         }
       
  1866 
       
  1867         // Add the actions that may be added by CommandArranger
       
  1868          if(commandList != null) {
       
  1869             CommandUtils.sort(commandList);
       
  1870             for (int i = 0; i < commandList.length; i++) {
       
  1871                 OS.QMenu_addAction(menuHandle, Internal_PackageSupport.topHandle(commandList[i]));
       
  1872             }
       
  1873          }
       
  1874 
       
  1875         OS.QMenu_exec(menuHandle, event.x, event.y, 0);
       
  1876 
       
  1877         // Clean-up the QActions from CommandArranger and QMenu
       
  1878         if(commandList != null && menuHandle != 0)   {
       
  1879             for (int i = 0; i < commandList.length; i++) {
       
  1880                 int action = Internal_PackageSupport.topHandle(commandList[i]);
       
  1881                 if(action != 0) {
       
  1882                     OS.QWidget_removeAction(menuHandle, action);
       
  1883                 }
       
  1884             }
       
  1885         }
       
  1886         if (commandMenu) {
       
  1887             QObjectDeleteWrapper.deleteSafely(menuHandle);
       
  1888             menuHandle = 0;
       
  1889         }
       
  1890     }
       
  1891     return true;
       
  1892 }
       
  1893 
       
  1894 boolean qt_event_keypress_pp(int widgetHandle, int key, int modifier,
       
  1895         int character, int nativeScanCode) {
       
  1896     if (!hasFocus()) {
       
  1897         return true;
       
  1898     }
       
  1899 
       
  1900     // Try if traversal would consume the key
       
  1901     int traversalType = getTraversalTypeForKey(key, modifier, character);
       
  1902     boolean isTraversalKey = traversalType != -1 ? true : false;
       
  1903     if (isTraversalKey) {
       
  1904         Event event = sendTraverseEvent(traversalType, key, modifier, character);
       
  1905         if (isDisposed())
       
  1906             return true;
       
  1907 
       
  1908         if (event.doit) {
       
  1909             if (doTraversal(event))
       
  1910                 return true; // Key used for traversal
       
  1911         }
       
  1912     }
       
  1913 
       
  1914 
       
  1915     // Proceed with sending the key event since it wasn't consumed by
       
  1916     // traversal.
       
  1917 
       
  1918     // Call key listener
       
  1919     boolean cancelInKeyListener = super.qt_event_keypress_pp(widgetHandle, key,
       
  1920             modifier, character, nativeScanCode);
       
  1921     // If KeyListener set doit=false then always obey that
       
  1922     if (cancelInKeyListener) {
       
  1923         return true;
       
  1924     }
       
  1925     // By default the key event is not passed to native widget if it was a
       
  1926     // traversal key. Otherwise it would still traverse when traversal doIt
       
  1927     // has been changed to false. But if Java widget needs to pass the
       
  1928     // traverse key to native widget anyway then do it.
       
  1929     return isTraversalKey ? traverseCancel : false;
       
  1930 }
       
  1931 
       
  1932 boolean qt_event_keyrelease_pp( int widgetHandle, int key, int modifier, int character, int nativeScanCode )
       
  1933 {
       
  1934     // Focus checking is necessary because it
       
  1935     // 1. stops the  key delivery to listeners () when control does not have focus;
       
  1936     // 2. stops the key delivery to native QWidget if the key event has been consumed as traversal key.
       
  1937     if (!hasFocus()) {
       
  1938         return true;
       
  1939     }
       
  1940 
       
  1941     if (((state & WidgetState.NO_KEY_PROPAGATE) != 0) && (widgetHandle != handle)) {
       
  1942         return true;
       
  1943     }
       
  1944     return sendKeyEvent( SWT.KeyUp, key, modifier, character, nativeScanCode );
       
  1945 }
       
  1946 
       
  1947 
       
  1948 boolean qt_event_mouseButtonDblClick_pp(int widgetHandle, int button,
       
  1949         int x, int y, int state, int buttons) {
       
  1950     if (((this.state & WidgetState.NO_MOUSE_PROPAGATE) != 0) && (widgetHandle != handle)) {
       
  1951         return true;
       
  1952     }
       
  1953     return doHandleMouseEvent(SWT.MouseDoubleClick, widgetHandle, button, x, y,
       
  1954             state, buttons);
       
  1955 }
       
  1956 
       
  1957 boolean qt_event_mouseButtonPress_pp(int widgetHandle, int button,
       
  1958         int x, int y, int state, int buttons) {
       
  1959     if (((this.state & WidgetState.NO_MOUSE_PROPAGATE) != 0) && (widgetHandle != handle)) {
       
  1960         return true;
       
  1961     }
       
  1962     return doHandleMouseEvent(SWT.MouseDown, widgetHandle, button, x, y, state,
       
  1963             buttons);
       
  1964 }
       
  1965 
       
  1966 boolean qt_event_mouseButtonRelease_pp(int widgetHandle, int button,
       
  1967         int x, int y, int state, int buttons) {
       
  1968     if (((this.state & WidgetState.NO_MOUSE_PROPAGATE) != 0) && (widgetHandle != handle)) {
       
  1969         return true;
       
  1970     }
       
  1971     return doHandleMouseEvent(SWT.MouseUp, widgetHandle, button, x, y, state,
       
  1972             buttons);
       
  1973 }
       
  1974 
       
  1975 boolean qt_event_mouseMove(int widgetHandle, int button, int x, int y,
       
  1976         int state, int buttons) {
       
  1977     return doHandleMouseEvent(SWT.MouseMove, widgetHandle, button, x, y, state,
       
  1978             buttons);
       
  1979 }
       
  1980 
       
  1981 void qt_swt_event_widgetMoved(int widgetHandle) {
       
  1982     // Resize events are sent only for top native widget,
       
  1983     // as some Controls are made of multiple native widgets.
       
  1984     if (widgetHandle == topHandle)
       
  1985         sendEvent(SWT.Move);
       
  1986 }
       
  1987 
       
  1988 void qt_swt_event_widgetResized_pp(int widgetHandle, int oldWidth, int oldHeight, int width, int height, boolean sendResizeEvent) {
       
  1989     // Resize events are sent only for top native widget,
       
  1990     // as some Controls are made of multiple native widgets.
       
  1991     if (widgetHandle == topHandle && sendResizeEvent)
       
  1992         sendEvent(SWT.Resize);
       
  1993 }
       
  1994 
       
  1995 boolean qt_event_shortcut(int key, int modifier, int character) {
       
  1996     Display.mnemonicControl = this;
       
  1997     Control shortcutHandler = getShortcutHandler();
       
  1998     if (shortcutHandler == null) {
       
  1999         // If there's no shortcut handler then just activate the shortcut.
       
  2000         return false;
       
  2001     }
       
  2002     return shortcutHandler.doProcessShortCut(key, modifier, character);
       
  2003 }
       
  2004 
       
  2005 void qt_swt_event_bufferFlush() {
       
  2006     // Next paint event is a buffer flush event
       
  2007     bufferFlush = true;
       
  2008 }
       
  2009 
       
  2010 void qt_swt_event_focusWasGained() {
       
  2011     try {
       
  2012         Display.focusEvent = SWT.FocusIn;
       
  2013         sendEvent(SWT.FocusIn);
       
  2014     } finally {
       
  2015         if(display != null && !display.isDisposed()) {
       
  2016             Display.focusEvent = SWT.None;
       
  2017         }
       
  2018     }
       
  2019     
       
  2020     
       
  2021 }
       
  2022 void qt_swt_event_focusWasLost() {
       
  2023     try {
       
  2024         Display.focusEvent = SWT.FocusOut;
       
  2025         sendEvent(SWT.FocusOut);
       
  2026     } finally {
       
  2027         if(display != null && !display.isDisposed()) {
       
  2028             Display.focusEvent = SWT.None;
       
  2029         }
       
  2030     }
       
  2031 }
       
  2032 
       
  2033 void qt_swt_event_widgetPainted(int widgetHandle, int x, int y, int width,
       
  2034     int height, int regionHandle) {
       
  2035     try {
       
  2036         isPainting = 1;
       
  2037         qt_swt_event_widgetPainted_handler(widgetHandle, x, y, width, height,
       
  2038                 regionHandle);
       
  2039     } finally {
       
  2040         isPainting = 0;
       
  2041     }
       
  2042 }
       
  2043 
       
  2044 private void qt_swt_event_widgetPainted_handler(int widgetHandle, int x,
       
  2045     int y, int width, int height, int regionHandle) {
       
  2046     if ((state & WidgetState.OBSCURED) != 0)
       
  2047         return;
       
  2048 
       
  2049     // In the case there are multiple native widgets, the paint event is
       
  2050     // sent only to the "handle".
       
  2051     if (widgetHandle != handle) {
       
  2052         return;
       
  2053     }
       
  2054 
       
  2055     // Render the buffers created outside the paint event, if any
       
  2056     flushBuffers();
       
  2057 
       
  2058     // If this is only a buffer flush event then stop here
       
  2059     if(bufferFlush) {
       
  2060         bufferFlush = false;
       
  2061         return;
       
  2062     }
       
  2063 
       
  2064     if (!hooks(SWT.Paint) && !filters(SWT.Paint))
       
  2065         return;
       
  2066 
       
  2067     GC gc = new GC(this);
       
  2068     Event event = new Event();
       
  2069     event.count = 0;
       
  2070     if(isMirrored()) {
       
  2071         event.x = getClientWidth() - x - width;
       
  2072     } else {
       
  2073         event.x = x;
       
  2074     }
       
  2075     event.y = y;
       
  2076     event.width = width;
       
  2077     event.height = height;
       
  2078     event.gc = gc;
       
  2079     try {
       
  2080         event.gc.setClipping(x, y, width - 1, height - 1);
       
  2081         sendEvent(SWT.Paint, event);
       
  2082     } finally {
       
  2083         // Painting needs to be ended also in the case the Control gets disposed in
       
  2084         // the paint listener. After the control is disposed it's not possible to
       
  2085         // call GC.dispose() because it will throw an exception.
       
  2086         if(!gc.isDisposed()) {
       
  2087             if(isDisposed()) {
       
  2088                 GCData data = gc.getGCData();
       
  2089                 data.internalGc.releaseTarget();
       
  2090             }
       
  2091             gc.dispose(); // Will throw if control is disposed
       
  2092         }
       
  2093     }
       
  2094 }
       
  2095 
       
  2096 /**
       
  2097  * Causes the entire bounds of the receiver to be marked as needing to be
       
  2098  * redrawn. The next time a paint request is processed, the control will be
       
  2099  * completely painted, including the background.
       
  2100  *
       
  2101  * @exception SWTException
       
  2102  *                <ul>
       
  2103  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2104  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2105  *                thread that created the receiver</li>
       
  2106  *                </ul>
       
  2107  *
       
  2108  * @see #update()
       
  2109  * @see PaintListener
       
  2110  * @see SWT#Paint
       
  2111  * @see SWT#NO_BACKGROUND
       
  2112  * @see SWT#NO_REDRAW_RESIZE
       
  2113  * @see SWT#NO_MERGE_PAINTS
       
  2114  */
       
  2115 public void redraw() {
       
  2116     checkWidget();
       
  2117     doRedraw();
       
  2118 }
       
  2119 
       
  2120 /**
       
  2121  * Causes the rectangular area of the receiver specified by the arguments to be
       
  2122  * marked as needing to be redrawn. The next time a paint request is processed,
       
  2123  * that area of the receiver will be painted, including the background. If the
       
  2124  * <code>all</code> flag is <code>true</code>, any children of the receiver
       
  2125  * which intersect with the specified area will also paint their intersecting
       
  2126  * areas. If the <code>all</code> flag is <code>false</code>, the children will
       
  2127  * not be painted.
       
  2128  *
       
  2129  * @param x
       
  2130  *            the x coordinate of the area to draw
       
  2131  * @param y
       
  2132  *            the y coordinate of the area to draw
       
  2133  * @param width
       
  2134  *            the width of the area to draw
       
  2135  * @param height
       
  2136  *            the height of the area to draw
       
  2137  * @param all
       
  2138  *            <code>true</code> if children should redraw, and
       
  2139  *            <code>false</code> otherwise
       
  2140  *
       
  2141  * @exception SWTException
       
  2142  *                <ul>
       
  2143  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2144  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2145  *                thread that created the receiver</li>
       
  2146  *                </ul>
       
  2147  *
       
  2148  * @see #update()
       
  2149  * @see PaintListener
       
  2150  * @see SWT#Paint
       
  2151  * @see SWT#NO_BACKGROUND
       
  2152  * @see SWT#NO_REDRAW_RESIZE
       
  2153  * @see SWT#NO_MERGE_PAINTS
       
  2154  */
       
  2155 public void redraw(int x, int y, int width, int height, boolean all) {
       
  2156     checkWidget();
       
  2157     if(isMirrored()) {
       
  2158         x = getClientWidth() - x - width;
       
  2159     }
       
  2160     doRedraw(x, y, width, height);
       
  2161     if (all) {
       
  2162         redrawChildren();
       
  2163     }
       
  2164 }
       
  2165 
       
  2166 void redrawChildren() {
       
  2167 }
       
  2168 
       
  2169 void releaseChildren_pp(boolean destroy) {
       
  2170     Command[] cmds = getCommands();
       
  2171     for (int i = 0; i < cmds.length; i++) {
       
  2172         Command child = cmds[i];
       
  2173         if (child != null && !child.isDisposed()) {
       
  2174             child.dispose();
       
  2175         }
       
  2176     }
       
  2177     super.releaseChildren_pp(destroy);
       
  2178 }
       
  2179 
       
  2180 void releaseHandle_pp() {
       
  2181     super.releaseHandle_pp();
       
  2182     parent = null;
       
  2183 }
       
  2184 
       
  2185 void releaseParent_pp() {
       
  2186     if(parent.packageProxy != null) {
       
  2187         parent.packageProxy.removeControl(this);
       
  2188     } else {
       
  2189         parent.removeControl_pp(this);
       
  2190     }
       
  2191 }
       
  2192 
       
  2193 void releaseWidget_pp() {
       
  2194     super.releaseWidget_pp();
       
  2195 
       
  2196     if (menu != null && !menu.isDisposed()) {
       
  2197         menu.dispose();
       
  2198     }
       
  2199     menu = null;
       
  2200 
       
  2201     layoutData = null;
       
  2202     background = null;
       
  2203     foreground = null;
       
  2204 }
       
  2205 
       
  2206 void removeCommand(final Command command) {
       
  2207     if (command.control != this)
       
  2208         return;
       
  2209     if (commandList == null || commandList.length == 0)
       
  2210         return;
       
  2211     if (commandList.length == 1 && command == commandList[0]) {
       
  2212         commandList = null;
       
  2213         return;
       
  2214     }
       
  2215 
       
  2216     int size = commandList.length;
       
  2217     Command[] newList = new Command[size - 1];
       
  2218     int counter = 0;
       
  2219     for (int i = 0; i < size; i++) {
       
  2220         if (command != commandList[i]) {
       
  2221             newList[counter] = commandList[i];
       
  2222             counter++;
       
  2223         }
       
  2224     }
       
  2225     if (counter == newList.length) {
       
  2226         commandList = newList;
       
  2227     }
       
  2228 }
       
  2229 
       
  2230 /**
       
  2231  * Removes the listener from the collection of listeners who will be notified
       
  2232  * when the control is moved or resized.
       
  2233  *
       
  2234  * @param listener
       
  2235  *            the listener which should no longer be notified
       
  2236  *
       
  2237  * @exception IllegalArgumentException
       
  2238  *                <ul>
       
  2239  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2240  *                </ul>
       
  2241  * @exception SWTException
       
  2242  *                <ul>
       
  2243  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2244  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2245  *                thread that created the receiver</li>
       
  2246  *                </ul>
       
  2247  *
       
  2248  * @see ControlListener
       
  2249  * @see #addControlListener
       
  2250  */
       
  2251 public void removeControlListener(ControlListener listener) {
       
  2252     checkWidget();
       
  2253     if (listener == null)
       
  2254         error(SWT.ERROR_NULL_ARGUMENT);
       
  2255     if (eventTable == null)
       
  2256         return;
       
  2257     eventTable.unhook(SWT.Move, listener);
       
  2258     eventTable.unhook(SWT.Resize, listener);
       
  2259 }
       
  2260 
       
  2261 /**
       
  2262  * Removes the listener from the collection of listeners who will be notified
       
  2263  * when the control gains or loses focus.
       
  2264  *
       
  2265  * @param listener
       
  2266  *            the listener which should no longer be notified
       
  2267  *
       
  2268  * @exception IllegalArgumentException
       
  2269  *                <ul>
       
  2270  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2271  *                </ul>
       
  2272  * @exception SWTException
       
  2273  *                <ul>
       
  2274  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2275  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2276  *                thread that created the receiver</li>
       
  2277  *                </ul>
       
  2278  *
       
  2279  * @see FocusListener
       
  2280  * @see #addFocusListener
       
  2281  */
       
  2282 public void removeFocusListener(FocusListener listener) {
       
  2283     checkWidget();
       
  2284     if (listener == null)
       
  2285         error(SWT.ERROR_NULL_ARGUMENT);
       
  2286     if (eventTable == null)
       
  2287         return;
       
  2288     eventTable.unhook(SWT.FocusIn, listener);
       
  2289     eventTable.unhook(SWT.FocusOut, listener);
       
  2290 }
       
  2291 
       
  2292 /**
       
  2293  * Removes the listener from the collection of listeners who will be notified
       
  2294  * when keys are pressed and released on the system keyboard.
       
  2295  *
       
  2296  * @param listener
       
  2297  *            the listener which should no longer be notified
       
  2298  *
       
  2299  * @exception IllegalArgumentException
       
  2300  *                <ul>
       
  2301  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2302  *                </ul>
       
  2303  * @exception SWTException
       
  2304  *                <ul>
       
  2305  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2306  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2307  *                thread that created the receiver</li>
       
  2308  *                </ul>
       
  2309  *
       
  2310  * @see KeyListener
       
  2311  * @see #addKeyListener
       
  2312  */
       
  2313 public void removeKeyListener(KeyListener listener) {
       
  2314     checkWidget();
       
  2315     if (listener == null)
       
  2316         error(SWT.ERROR_NULL_ARGUMENT);
       
  2317     if (eventTable == null)
       
  2318         return;
       
  2319     eventTable.unhook(SWT.KeyUp, listener);
       
  2320     eventTable.unhook(SWT.KeyDown, listener);
       
  2321 }
       
  2322 
       
  2323 /**
       
  2324  * Removes the listener from the collection of listeners who will be notified
       
  2325  * when mouse buttons are pressed and released.
       
  2326  *
       
  2327  * @param listener
       
  2328  *            the listener which should no longer be notified
       
  2329  *
       
  2330  * @exception IllegalArgumentException
       
  2331  *                <ul>
       
  2332  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2333  *                </ul>
       
  2334  * @exception SWTException
       
  2335  *                <ul>
       
  2336  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2337  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2338  *                thread that created the receiver</li>
       
  2339  *                </ul>
       
  2340  *
       
  2341  * @see MouseListener
       
  2342  * @see #addMouseListener
       
  2343  */
       
  2344 public void removeMouseListener(MouseListener listener) {
       
  2345     checkWidget();
       
  2346     if (listener == null)
       
  2347         error(SWT.ERROR_NULL_ARGUMENT);
       
  2348     if (eventTable == null)
       
  2349         return;
       
  2350     eventTable.unhook(SWT.MouseDown, listener);
       
  2351     eventTable.unhook(SWT.MouseUp, listener);
       
  2352     eventTable.unhook(SWT.MouseDoubleClick, listener);
       
  2353 }
       
  2354 
       
  2355 /**
       
  2356  * Removes the listener from the collection of listeners who will be notified
       
  2357  * when the mouse moves.
       
  2358  *
       
  2359  * @param listener
       
  2360  *            the listener which should no longer be notified
       
  2361  *
       
  2362  * @exception IllegalArgumentException
       
  2363  *                <ul>
       
  2364  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2365  *                </ul>
       
  2366  * @exception SWTException
       
  2367  *                <ul>
       
  2368  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2369  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2370  *                thread that created the receiver</li>
       
  2371  *                </ul>
       
  2372  *
       
  2373  * @see MouseMoveListener
       
  2374  * @see #addMouseMoveListener
       
  2375  */
       
  2376 public void removeMouseMoveListener(MouseMoveListener listener) {
       
  2377     checkWidget();
       
  2378     if (listener == null)
       
  2379         error(SWT.ERROR_NULL_ARGUMENT);
       
  2380     if (eventTable == null)
       
  2381         return;
       
  2382     eventTable.unhook(SWT.MouseMove, listener);
       
  2383 }
       
  2384 
       
  2385 /**
       
  2386  * Removes the listener from the collection of listeners who will be notified
       
  2387  * when the receiver needs to be painted.
       
  2388  *
       
  2389  * @param listener
       
  2390  *            the listener which should no longer be notified
       
  2391  *
       
  2392  * @exception IllegalArgumentException
       
  2393  *                <ul>
       
  2394  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2395  *                </ul>
       
  2396  * @exception SWTException
       
  2397  *                <ul>
       
  2398  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2399  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2400  *                thread that created the receiver</li>
       
  2401  *                </ul>
       
  2402  *
       
  2403  * @see PaintListener
       
  2404  * @see #addPaintListener
       
  2405  */
       
  2406 public void removePaintListener(PaintListener listener) {
       
  2407     checkWidget();
       
  2408     if (listener == null)
       
  2409         error(SWT.ERROR_NULL_ARGUMENT);
       
  2410     if (eventTable == null)
       
  2411         return;
       
  2412     eventTable.unhook(SWT.Paint, listener);
       
  2413 }
       
  2414 
       
  2415 /**
       
  2416  * Removes the listener from the collection of listeners who will be notified
       
  2417  * when traversal events occur.
       
  2418  *
       
  2419  * @param listener
       
  2420  *            the listener which should no longer be notified
       
  2421  *
       
  2422  * @exception IllegalArgumentException
       
  2423  *                <ul>
       
  2424  *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  2425  *                </ul>
       
  2426  * @exception SWTException
       
  2427  *                <ul>
       
  2428  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2429  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2430  *                thread that created the receiver</li>
       
  2431  *                </ul>
       
  2432  *
       
  2433  * @see TraverseListener
       
  2434  * @see #addTraverseListener
       
  2435  */
       
  2436 public void removeTraverseListener(TraverseListener listener) {
       
  2437     checkWidget();
       
  2438     if (listener == null)
       
  2439         error(SWT.ERROR_NULL_ARGUMENT);
       
  2440     if (eventTable == null)
       
  2441         return;
       
  2442     eventTable.unhook(SWT.Traverse, listener);
       
  2443 }
       
  2444 
       
  2445 final boolean sendMouseEvent(int type, int button, boolean send, int x, int y,
       
  2446         int modifiers, int buttons) {
       
  2447     Event event = makeMouseEvent(type, button, x, y, modifiers, buttons);
       
  2448     if (send) {
       
  2449         sendEvent(type, event);
       
  2450         if (isDisposed())
       
  2451             return true;
       
  2452     } else {
       
  2453         postEvent(type, event);
       
  2454     }
       
  2455     return !event.doit;
       
  2456 }
       
  2457 
       
  2458 Event sendTraverseEvent(int traversalType, int key, int modifier, int character) {
       
  2459     // Make traverse event
       
  2460     Event event = makeKeyEvent(key, modifier, character, 0);
       
  2461     event.detail = traversalType;
       
  2462     event.stateMask = Display.translateModifiers(modifier);
       
  2463 
       
  2464     // Ask from the control if it would traverse with this key
       
  2465     // and if it should go to the native widget.
       
  2466     if(packageProxy != null) {
       
  2467         packageProxy.setTraversalFlags(traversalType, key, modifier, character);
       
  2468     } else {
       
  2469         setTraversalFlags_pp(traversalType, key, modifier, character);
       
  2470     }
       
  2471     event.doit = traverseDoit;
       
  2472 
       
  2473     // Event to the listener
       
  2474     if (hooks(SWT.Traverse) || filters(SWT.Traverse)) {
       
  2475         sendEvent(SWT.Traverse, event);
       
  2476     }
       
  2477 
       
  2478     return event;
       
  2479 }
       
  2480 
       
  2481 void setBackground_pp () {
       
  2482     if(backgroundImage != null) {
       
  2483         applyBackgroundImage(backgroundImage);
       
  2484         return;
       
  2485     }
       
  2486     if(background != null) {
       
  2487         applyBackgroundColor (background);
       
  2488         return;
       
  2489     }
       
  2490     Control control = findBackgroundControl ();
       
  2491     if(control == null) control = this;
       
  2492     if(control.backgroundImage != null) {
       
  2493         applyBackgroundImage(control.backgroundImage);
       
  2494         return;
       
  2495     }
       
  2496     // If this is null then it will reset the default background
       
  2497     applyBackgroundColor(control.background);
       
  2498 }
       
  2499 
       
  2500 /**
       
  2501  * Sets the receiver's background color to the color specified by the argument,
       
  2502  * or to the default system color for the control if the argument is null.
       
  2503  * <p>
       
  2504  * Note: This operation is a hint and may be overridden by the platform. For
       
  2505  * example, on Windows the background of a Button cannot be changed.
       
  2506  * </p>
       
  2507  *
       
  2508  * @param color
       
  2509  *            the new color (or null)
       
  2510  *
       
  2511  * @exception IllegalArgumentException
       
  2512  *                <ul>
       
  2513  *                <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
       
  2514  *                </li>
       
  2515  *                </ul>
       
  2516  * @exception SWTException
       
  2517  *                <ul>
       
  2518  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2519  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2520  *                thread that created the receiver</li>
       
  2521  *                </ul>
       
  2522  */
       
  2523 public void setBackground(Color color) {
       
  2524     checkWidget();
       
  2525     if (color != null) {
       
  2526         if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
       
  2527     }
       
  2528     if (background == null && color == null) {
       
  2529         return;
       
  2530     }
       
  2531     if(color == null) {
       
  2532         background = null;
       
  2533     } else {
       
  2534         // Store a copy
       
  2535         background = Internal_GfxPackageSupport.newColor(display, color.handle);
       
  2536     }
       
  2537     // Propagate background color change
       
  2538     updateBackground();
       
  2539 }
       
  2540 
       
  2541 /**
       
  2542  * Sets the receiver's background image to the image specified by the argument,
       
  2543  * or to the default system color for the control if the argument is null. The
       
  2544  * background image is tiled to fill the available space.
       
  2545  * <p>
       
  2546  * Note: This operation is a hint and may be overridden by the platform. For
       
  2547  * example, on Windows the background of a Button cannot be changed.
       
  2548  * </p>
       
  2549  *
       
  2550  * @param image
       
  2551  *            the new image (or null)
       
  2552  *
       
  2553  * @exception IllegalArgumentException
       
  2554  *                <ul>
       
  2555  *                <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
       
  2556  *                </li>
       
  2557  *                <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
       
  2558  *                </ul>
       
  2559  * @exception SWTException
       
  2560  *                <ul>
       
  2561  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2562  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2563  *                thread that created the receiver</li>
       
  2564  *                </ul>
       
  2565  *
       
  2566  * @since 3.2
       
  2567  */
       
  2568 public void setBackgroundImage(Image image) {
       
  2569     checkWidget();
       
  2570     if(image == null && backgroundImage == null) {
       
  2571         return;
       
  2572     }
       
  2573     if (image != null) {
       
  2574         if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
       
  2575         if (image.type != SWT.BITMAP) error (SWT.ERROR_INVALID_ARGUMENT);
       
  2576     }
       
  2577     if (backgroundImage == image) return;
       
  2578     backgroundImage = image;
       
  2579     // Propagate background image change
       
  2580     updateBackground();
       
  2581 }
       
  2582 
       
  2583 /**
       
  2584  * Sets the receiver's size and location to the rectangular area specified by
       
  2585  * the arguments. The <code>x</code> and <code>y</code> arguments are relative
       
  2586  * to the receiver's parent (or its display if its parent is null), unless the
       
  2587  * receiver is a shell. In this case, the <code>x</code> and <code>y</code>
       
  2588  * arguments are relative to the display.
       
  2589  * <p>
       
  2590  * Note: Attempting to set the width or height of the receiver to a negative
       
  2591  * number will cause that value to be set to zero instead.
       
  2592  * </p>
       
  2593  *
       
  2594  * @param x
       
  2595  *            the new x coordinate for the receiver
       
  2596  * @param y
       
  2597  *            the new y coordinate for the receiver
       
  2598  * @param width
       
  2599  *            the new width for the receiver
       
  2600  * @param height
       
  2601  *            the new height for the receiver
       
  2602  *
       
  2603  * @exception SWTException
       
  2604  *                <ul>
       
  2605  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2606  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2607  *                thread that created the receiver</li>
       
  2608  *                </ul>
       
  2609  */
       
  2610 public void setBounds(int x, int y, int width, int height) {
       
  2611     checkWidget();
       
  2612     setBounds(x, y, Math.max(0, width), Math.max(0, height), true, true);
       
  2613 }
       
  2614 
       
  2615 int setBounds(int x, int y, int width, int height, boolean move,
       
  2616         boolean resize) {
       
  2617     int result = 0;
       
  2618     Point oldSize = OS.QWidget_size(topHandle);
       
  2619     Point oldPos = OS.QWidget_pos(topHandle);
       
  2620     if (resize) {
       
  2621         if (oldSize.x != width || oldSize.y != height) {
       
  2622             if(isParentMirrored()) {
       
  2623                 try {
       
  2624                     Display.blockedQtEventType = OS.QSWTEVENT_WIDGETMOVED;
       
  2625                     OS.QWidget_move(topHandle, oldPos.x - (width - oldSize.x), oldPos.y);
       
  2626                 } finally {
       
  2627                     Display.blockedQtEventType = OS.QEVENT_NONE;
       
  2628                 }
       
  2629             }
       
  2630             // This will send a resize event
       
  2631             OS.QWidget_resize(topHandle, width, height);
       
  2632             result |= WidgetState.RESIZED;
       
  2633         }
       
  2634     }
       
  2635     if (move) {
       
  2636         if(isParentMirrored()) {
       
  2637             x = parent.getClientWidth() - x - OS.QWidget_size(topHandle).x;
       
  2638         }
       
  2639         if (oldPos.x != x || oldPos.y != y) {
       
  2640             // This will send a move event
       
  2641             OS.QWidget_move(topHandle, x, y);
       
  2642             result |= WidgetState.MOVED;
       
  2643         }
       
  2644     }
       
  2645     return result;
       
  2646 }
       
  2647 
       
  2648 /**
       
  2649  * Sets the receiver's size and location to the rectangular area specified by
       
  2650  * the argument. The <code>x</code> and <code>y</code> fields of the rectangle
       
  2651  * are relative to the receiver's parent (or its display if its parent is null).
       
  2652  * <p>
       
  2653  * Note: Attempting to set the width or height of the receiver to a negative
       
  2654  * number will cause that value to be set to zero instead.
       
  2655  * </p>
       
  2656  *
       
  2657  * @param rect
       
  2658  *            the new bounds for the receiver
       
  2659  *
       
  2660  * @exception SWTException
       
  2661  *                <ul>
       
  2662  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2663  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2664  *                thread that created the receiver</li>
       
  2665  *                </ul>
       
  2666  */
       
  2667 public void setBounds(Rectangle rect) {
       
  2668     checkWidget();
       
  2669     if (rect == null)
       
  2670         error(SWT.ERROR_NULL_ARGUMENT);
       
  2671     setBounds(rect.x, rect.y, Math.max(0, rect.width),
       
  2672             Math.max(0, rect.height), true, true);
       
  2673 }
       
  2674 
       
  2675 /**
       
  2676  * If the argument is <code>true</code>, causes the receiver to have all mouse
       
  2677  * events delivered to it until the method is called with <code>false</code> as
       
  2678  * the argument.
       
  2679  *
       
  2680  * @param capture
       
  2681  *            <code>true</code> to capture the mouse, and <code>false</code> to
       
  2682  *            release it
       
  2683  *
       
  2684  * @exception SWTException
       
  2685  *                <ul>
       
  2686  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2687  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2688  *                thread that created the receiver</li>
       
  2689  *                </ul>
       
  2690  */
       
  2691 public void setCapture(boolean capture) {
       
  2692     checkWidget();
       
  2693     if(capture) {
       
  2694         OS.QWidget_grabMouse(handle);
       
  2695     } else {
       
  2696         OS.QWidget_releaseMouse(handle);
       
  2697     }
       
  2698 }
       
  2699 
       
  2700 /**
       
  2701  * Enables the receiver if the argument is <code>true</code>, and disables it
       
  2702  * otherwise. A disabled control is typically not selectable from the user
       
  2703  * interface and draws with an inactive or "grayed" look.
       
  2704  *
       
  2705  * @param enabled
       
  2706  *            the new enabled state
       
  2707  *
       
  2708  * @exception SWTException
       
  2709  *                <ul>
       
  2710  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2711  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2712  *                thread that created the receiver</li>
       
  2713  *                </ul>
       
  2714  */
       
  2715 public void setEnabled(boolean enabled) {
       
  2716     checkWidget();
       
  2717     if (enabled) {
       
  2718         state &= ~WidgetState.DISABLED;
       
  2719     } else {
       
  2720         state |= WidgetState.DISABLED;
       
  2721     }
       
  2722     Control control = null;
       
  2723     boolean fixFocus = false;
       
  2724     if (!enabled) {
       
  2725         if (Display.focusEvent != SWT.FocusOut) {
       
  2726             control = display.getFocusControl ();
       
  2727             fixFocus = isFocusAncestor (control);
       
  2728         }
       
  2729     }
       
  2730     enableWidget(enabled);
       
  2731     if (fixFocus) fixFocus (control);
       
  2732 }
       
  2733 
       
  2734 boolean setFixedFocus () {
       
  2735     if ((style & SWT.NO_FOCUS) != 0) return false;
       
  2736     return forceFocus (OS.QT_OTHERFOCUSREASON);
       
  2737 }
       
  2738 
       
  2739 /**
       
  2740  * Causes the receiver to have the <em>keyboard focus</em>, such that all
       
  2741  * keyboard events will be delivered to it. Focus reassignment will respect
       
  2742  * applicable platform constraints.
       
  2743  *
       
  2744  * @return <code>true</code> if the control got focus, and <code>false</code> if
       
  2745  *         it was unable to.
       
  2746  *
       
  2747  * @exception SWTException
       
  2748  *                <ul>
       
  2749  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2750  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2751  *                thread that created the receiver</li>
       
  2752  *                </ul>
       
  2753  *
       
  2754  * @see #forceFocus
       
  2755  */
       
  2756 public boolean setFocus() {
       
  2757     checkWidget();
       
  2758     return setFocus(OS.QT_OTHERFOCUSREASON);
       
  2759 }
       
  2760 
       
  2761 boolean setFocus(int focusReason) {
       
  2762     if ((style & SWT.NO_FOCUS) != 0)
       
  2763         return false;
       
  2764     return forceFocus(focusReason);
       
  2765 }
       
  2766 
       
  2767 /**
       
  2768  * Sets the font that the receiver will use to paint textual information to the
       
  2769  * font specified by the argument, or to the default font for that kind of
       
  2770  * control if the argument is null.
       
  2771  *
       
  2772  * @param font
       
  2773  *            the new font (or null)
       
  2774  *
       
  2775  * @exception IllegalArgumentException
       
  2776  *                <ul>
       
  2777  *                <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
       
  2778  *                </li>
       
  2779  *                </ul>
       
  2780  * @exception SWTException
       
  2781  *                <ul>
       
  2782  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2783  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2784  *                thread that created the receiver</li>
       
  2785  *                </ul>
       
  2786  */
       
  2787 public void setFont(Font font) {
       
  2788     checkWidget();
       
  2789     if (((state & WidgetState.FONT) == 0) && font == null)
       
  2790         return;
       
  2791     this.font = font;
       
  2792 
       
  2793     if (font == null) {
       
  2794         OS.QWidget_setFont(topHandle, OS.SwtFontCache_cache(OS.QApplication_swt_font_new(topHandle)));
       
  2795     } else {
       
  2796         if (font.isDisposed())
       
  2797             SWT.error(SWT.ERROR_INVALID_ARGUMENT);
       
  2798         OS.QWidget_setFont(topHandle, font.handle);
       
  2799     }
       
  2800 
       
  2801     if (font == null) {
       
  2802         state &= ~WidgetState.FONT;
       
  2803     } else {
       
  2804         state |= WidgetState.FONT;
       
  2805     }
       
  2806 }
       
  2807 
       
  2808 /**
       
  2809  * Sets the receiver's foreground color to the color specified by the argument,
       
  2810  * or to the default system color for the control if the argument is null.
       
  2811  * <p>
       
  2812  * Note: This operation is a hint and may be overridden by the platform.
       
  2813  * </p>
       
  2814  *
       
  2815  * @param color
       
  2816  *            the new color (or null)
       
  2817  *
       
  2818  * @exception IllegalArgumentException
       
  2819  *                <ul>
       
  2820  *                <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
       
  2821  *                </li>
       
  2822  *                </ul>
       
  2823  * @exception SWTException
       
  2824  *                <ul>
       
  2825  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2826  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2827  *                thread that created the receiver</li>
       
  2828  *                </ul>
       
  2829  */
       
  2830 public void setForeground(Color color) {
       
  2831     checkWidget();
       
  2832     if (color != null) {
       
  2833         if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
       
  2834     }
       
  2835     if (foreground == null && color == null) {
       
  2836         return;
       
  2837     }
       
  2838     // Get a temporary copy of the widgets current palette, modify the
       
  2839     // foreground color, and set the modified palette back to the widget.
       
  2840     int palette = OS.QWidget_swt_palette_new(topHandle);
       
  2841     try {
       
  2842         if(color == null) {
       
  2843             foreground = null;
       
  2844         } else {
       
  2845             // Store a copy
       
  2846             foreground = Internal_GfxPackageSupport.newColor(display, color.handle);
       
  2847         }
       
  2848         setPaletteFgColor(palette, color);
       
  2849         OS.QWidget_setPalette(topHandle, palette);
       
  2850     } finally {
       
  2851         OS.QPalette_delete(palette);
       
  2852     }
       
  2853 }
       
  2854 
       
  2855 /**
       
  2856  * Sets the layout data associated with the receiver to the argument.
       
  2857  *
       
  2858  * @param layoutData
       
  2859  *            the new layout data for the receiver.
       
  2860  *
       
  2861  * @exception SWTException
       
  2862  *                <ul>
       
  2863  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2864  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2865  *                thread that created the receiver</li>
       
  2866  *                </ul>
       
  2867  */
       
  2868 public void setLayoutData(Object layoutData) {
       
  2869     checkWidget();
       
  2870     this.layoutData = layoutData;
       
  2871 }
       
  2872 
       
  2873 /**
       
  2874  * Sets the receiver's location to the point specified by the arguments which
       
  2875  * are relative to the receiver's parent (or its display if its parent is null),
       
  2876  * unless the receiver is a shell. In this case, the point is relative to the
       
  2877  * display.
       
  2878  *
       
  2879  * @param x
       
  2880  *            the new x coordinate for the receiver
       
  2881  * @param y
       
  2882  *            the new y coordinate for the receiver
       
  2883  *
       
  2884  * @exception SWTException
       
  2885  *                <ul>
       
  2886  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2887  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2888  *                thread that created the receiver</li>
       
  2889  *                </ul>
       
  2890  */
       
  2891 public void setLocation(int x, int y) {
       
  2892     checkWidget();
       
  2893     setBounds(x, y, 0, 0, true, false);
       
  2894 }
       
  2895 
       
  2896 /**
       
  2897  * Sets the receiver's location to the point specified by the arguments which
       
  2898  * are relative to the receiver's parent (or its display if its parent is null),
       
  2899  * unless the receiver is a shell. In this case, the point is relative to the
       
  2900  * display.
       
  2901  *
       
  2902  * @param location
       
  2903  *            the new location for the receiver
       
  2904  *
       
  2905  * @exception SWTException
       
  2906  *                <ul>
       
  2907  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2908  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2909  *                thread that created the receiver</li>
       
  2910  *                </ul>
       
  2911  */
       
  2912 public void setLocation(Point location) {
       
  2913     checkWidget();
       
  2914     if (location == null)
       
  2915         error(SWT.ERROR_NULL_ARGUMENT);
       
  2916     setBounds(location.x, location.y, 0, 0, true, false);
       
  2917 }
       
  2918 
       
  2919 /**
       
  2920  * Sets the receiver's pop up menu to the argument. All controls may optionally
       
  2921  * have a pop up menu that is displayed when the user requests one for the
       
  2922  * control. The sequence of key strokes, button presses and/or button releases
       
  2923  * that are used to request a pop up menu is platform specific.
       
  2924  * <p>
       
  2925  * Note: Disposing of a control that has a pop up menu will dispose of the menu.
       
  2926  * To avoid this behavior, set the menu to null before the control is disposed.
       
  2927  * </p>
       
  2928  *
       
  2929  * @param menu
       
  2930  *            the new pop up menu
       
  2931  *
       
  2932  * @exception IllegalArgumentException
       
  2933  *                <ul>
       
  2934  *                <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
       
  2935  *                <li>ERROR_INVALID_PARENT - if the menu is not in the same
       
  2936  *                widget tree</li>
       
  2937  *                <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
       
  2938  *                </ul>
       
  2939  * @exception SWTException
       
  2940  *                <ul>
       
  2941  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  2942  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  2943  *                thread that created the receiver</li>
       
  2944  *                </ul>
       
  2945  */
       
  2946 public void setMenu(Menu menu) {
       
  2947     checkWidget();
       
  2948     if (menu != null) {
       
  2949         if ((menu.style & SWT.POP_UP) == 0) {
       
  2950             error(SWT.ERROR_MENU_NOT_POP_UP);
       
  2951         }
       
  2952         if (menu.parent != menuShell()) {
       
  2953             error(SWT.ERROR_INVALID_PARENT);
       
  2954         }
       
  2955     }
       
  2956     this.menu = menu;
       
  2957 }
       
  2958 
       
  2959 private final void setPaletteBgColor(int paletteHandle, Color color) {
       
  2960     int[] bkRoles = getBackgroundColorRoles();
       
  2961     if (color != null) {
       
  2962         for (int j = 0; j < bkRoles.length; j++) {
       
  2963             OS.QPalette_setColor(paletteHandle, bkRoles[j], color.getRed(),
       
  2964                     color.getGreen(), color.getBlue());
       
  2965         }
       
  2966     } else { // Restore the default colors from application palette
       
  2967         int defaultPalette = OS.QApplication_swt_palette_new();
       
  2968         try {
       
  2969             for (int j = 0; j < bkRoles.length; j++) {
       
  2970                 OS.QPalette_swt_copyBrushFromPalette(paletteHandle,
       
  2971                         defaultPalette, bkRoles[j]);
       
  2972             }
       
  2973         } finally {
       
  2974             OS.QPalette_delete(defaultPalette);
       
  2975         }
       
  2976     }
       
  2977 }
       
  2978 
       
  2979 private final void setPaletteBgImage(int paletteHandle, Image image) {
       
  2980     int[] bkRoles = getBackgroundImageRoles();
       
  2981     if (image != null) {
       
  2982         for (int j = 0; j < bkRoles.length; j++) {
       
  2983             if ((findBackgroundControl () != this) && canInheritBackgroundImage()) {
       
  2984                 // If background is inherited then brush is set to null
       
  2985                 OS.QPalette_swt_setBrush(paletteHandle, bkRoles[j], 0);
       
  2986                 backgroundImageInherited(image);
       
  2987             } else {
       
  2988                 OS.QPalette_swt_setBrush(paletteHandle, bkRoles[j], Internal_GfxPackageSupport.getPixmapHandle(image));
       
  2989                 if(packageProxy != null) {
       
  2990                     packageProxy.backgroundImageApplied(image);
       
  2991                 } else {
       
  2992                     backgroundImageApplied_pp(image);
       
  2993                 }
       
  2994             }
       
  2995         }
       
  2996     } else { // Restore the default brushes from application palette
       
  2997         int defaultPalette = OS.QApplication_swt_palette_new();
       
  2998         try {
       
  2999             for (int j = 0; j < bkRoles.length; j++) {
       
  3000                 OS.QPalette_swt_copyBrushFromPalette(paletteHandle,
       
  3001                         defaultPalette, bkRoles[j]);
       
  3002             }
       
  3003         } finally {
       
  3004             OS.QPalette_delete(defaultPalette);
       
  3005         }
       
  3006     }
       
  3007 }
       
  3008 
       
  3009 private final void setPaletteFgColor(int paletteHandle, Color color) {
       
  3010     int[] fgRoles = new int[] { OS.QPALETTE_COLORROLE_WINDOWTEXT,
       
  3011             OS.QPALETTE_COLORROLE_TEXT, OS.QPALETTE_COLORROLE_BUTTONTEXT };
       
  3012     if (color != null) {
       
  3013         for (int j = 0; j < fgRoles.length; j++) {
       
  3014             OS.QPalette_setColor(paletteHandle, fgRoles[j], color.getRed(),
       
  3015                     color.getGreen(), color.getBlue());
       
  3016         }
       
  3017     } else { // Restore the default colors from application palette
       
  3018         int defaultPalette = OS.QApplication_swt_palette_new();
       
  3019         try {
       
  3020             for (int j = 0; j < fgRoles.length; j++) {
       
  3021                 OS.QPalette_swt_copyBrushFromPalette(paletteHandle,
       
  3022                         defaultPalette, fgRoles[j]);
       
  3023             }
       
  3024         } finally {
       
  3025             OS.QPalette_delete(defaultPalette);
       
  3026         }
       
  3027     }
       
  3028 }
       
  3029 
       
  3030 /**
       
  3031  * Changes the parent of the widget to be the one provided if the underlying
       
  3032  * operating system supports this feature. Returns <code>true</code> if the
       
  3033  * parent is successfully changed.
       
  3034  *
       
  3035  * @param parent
       
  3036  *            the new parent for the control.
       
  3037  * @return <code>true</code> if the parent is changed and <code>false</code>
       
  3038  *         otherwise.
       
  3039  *
       
  3040  * @exception IllegalArgumentException
       
  3041  *                <ul>
       
  3042  *                <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
       
  3043  *                </li>
       
  3044  *                <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
       
  3045  *                </ul>
       
  3046  * @exception SWTException
       
  3047  *                <ul>
       
  3048  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3049  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3050  *                thread that created the receiver</li>
       
  3051  *                </ul>
       
  3052  */
       
  3053 public boolean setParent(Composite parent) {
       
  3054     checkWidget();
       
  3055     if (parent == null)
       
  3056         error(SWT.ERROR_NULL_ARGUMENT);
       
  3057     if (parent.isDisposed())
       
  3058         SWT.error(SWT.ERROR_INVALID_ARGUMENT);
       
  3059     if (this.parent == parent)
       
  3060         return true;
       
  3061     if (!isReparentable())
       
  3062         return false;
       
  3063     return false;
       
  3064 }
       
  3065 
       
  3066 boolean setRadioFocus(boolean tabbing) {
       
  3067     return false;
       
  3068 }
       
  3069 
       
  3070 boolean setRadioSelection(boolean value) {
       
  3071     return false;
       
  3072 }
       
  3073 
       
  3074 /**
       
  3075  * If the argument is <code>false</code>, causes subsequent drawing operations
       
  3076  * in the receiver to be ignored. No drawing of any kind can occur in the
       
  3077  * receiver until the flag is set to true. Graphics operations that occurred
       
  3078  * while the flag was <code>false</code> are lost. When the flag is set to
       
  3079  * <code>true</code>, the entire widget is marked as needing to be redrawn.
       
  3080  * Nested calls to this method are stacked.
       
  3081  * <p>
       
  3082  * Note: This operation is a hint and may not be supported on some platforms or
       
  3083  * for some widgets.
       
  3084  * </p>
       
  3085  *
       
  3086  * @param redraw
       
  3087  *            the new redraw state
       
  3088  *
       
  3089  * @exception SWTException
       
  3090  *                <ul>
       
  3091  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3092  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3093  *                thread that created the receiver</li>
       
  3094  *                </ul>
       
  3095  *
       
  3096  * @see #redraw(int, int, int, int, boolean)
       
  3097  * @see #update()
       
  3098  */
       
  3099 public void setRedraw(boolean redraw) {
       
  3100     checkWidget();
       
  3101     OS.QWidget_setUpdatesEnabled(handle, redraw);
       
  3102 }
       
  3103 
       
  3104 /**
       
  3105  * Sets the receiver's size to the point specified by the arguments.
       
  3106  * <p>
       
  3107  * Note: Attempting to set the width or height of the receiver to a negative
       
  3108  * number will cause that value to be set to zero instead.
       
  3109  * </p>
       
  3110  *
       
  3111  * @param width
       
  3112  *            the new width for the receiver
       
  3113  * @param height
       
  3114  *            the new height for the receiver
       
  3115  *
       
  3116  * @exception SWTException
       
  3117  *                <ul>
       
  3118  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3119  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3120  *                thread that created the receiver</li>
       
  3121  *                </ul>
       
  3122  */
       
  3123 public void setSize(int width, int height) {
       
  3124     checkWidget();
       
  3125     setBounds(0, 0, Math.max(0, width), Math.max(0, height), false, true);
       
  3126 }
       
  3127 
       
  3128 /**
       
  3129  * Sets the receiver's size to the point specified by the argument.
       
  3130  * <p>
       
  3131  * Note: Attempting to set the width or height of the receiver to a negative
       
  3132  * number will cause them to be set to zero instead.
       
  3133  * </p>
       
  3134  *
       
  3135  * @param size
       
  3136  *            the new size for the receiver
       
  3137  *
       
  3138  * @exception IllegalArgumentException
       
  3139  *                <ul>
       
  3140  *                <li>ERROR_NULL_ARGUMENT - if the point is null</li>
       
  3141  *                </ul>
       
  3142  * @exception SWTException
       
  3143  *                <ul>
       
  3144  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3145  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3146  *                thread that created the receiver</li>
       
  3147  *                </ul>
       
  3148  */
       
  3149 public void setSize(Point size) {
       
  3150     checkWidget();
       
  3151     if (size == null)
       
  3152         error(SWT.ERROR_NULL_ARGUMENT);
       
  3153     setBounds(0, 0, Math.max(0, size.x), Math.max(0, size.y), false, true);
       
  3154 }
       
  3155 
       
  3156 boolean setTabGroupFocus_pp() {
       
  3157     return setTabItemFocus();
       
  3158 }
       
  3159 
       
  3160 boolean setTabItemFocus() {
       
  3161     if (!isShowing())
       
  3162         return false;
       
  3163     return forceFocus(OS.QT_TABFOCUSREASON);
       
  3164 }
       
  3165 
       
  3166 /**
       
  3167  * Sets the receiver's tool tip text to the argument, which may be null
       
  3168  * indicating that no tool tip text should be shown.
       
  3169  *
       
  3170  * @param string
       
  3171  *            the new tool tip text (or null)
       
  3172  *
       
  3173  * @exception SWTException
       
  3174  *                <ul>
       
  3175  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3176  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3177  *                thread that created the receiver</li>
       
  3178  *                </ul>
       
  3179  */
       
  3180 public void setToolTipText(String string) {
       
  3181     checkWidget();
       
  3182     if (string == null) {
       
  3183         string = "";
       
  3184         toolTipTextExists = false;
       
  3185     } else {
       
  3186         toolTipTextExists = true;
       
  3187     }
       
  3188     OS.QWidget_setToolTip(handle, string);
       
  3189 }
       
  3190 
       
  3191 void setTraversalFlags_pp(int type, int key, int modifier, int character) {
       
  3192     if ((state & WidgetState.NO_TRAVERSE) != 0) {
       
  3193         traverseDoit = false;
       
  3194         traverseCancel = false;
       
  3195         return;
       
  3196     }
       
  3197 
       
  3198     // Set doIt to true for the types that will actually traverse
       
  3199     int traversalFlags = SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS
       
  3200             | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS
       
  3201             | SWT.TRAVERSE_MNEMONIC;
       
  3202     traverseDoit = ((type & traversalFlags) != 0);
       
  3203 
       
  3204     // If there's a default button then offer invoking it
       
  3205     if (type == SWT.TRAVERSE_RETURN) {
       
  3206         traverseDoit = (menuShell().defaultButton != null);
       
  3207     }
       
  3208 
       
  3209     // Cancel the traverse key event so that the key is not delivered
       
  3210     // to the native widget. Key events that will cause native widget
       
  3211     // to traverse must never go through. However, if it is known that
       
  3212     // the traverse key will not traverse in the current state of the widget
       
  3213     // then it can be let through by setting this flag.
       
  3214     traverseCancel = true;
       
  3215 }
       
  3216 
       
  3217 /**
       
  3218  * Marks the receiver as visible if the argument is <code>true</code>, and marks
       
  3219  * it invisible otherwise.
       
  3220  * <p>
       
  3221  * If one of the receiver's ancestors is not visible or some other condition
       
  3222  * makes the receiver not visible, marking it visible may not actually cause it
       
  3223  * to be displayed.
       
  3224  * </p>
       
  3225  *
       
  3226  * @param visible
       
  3227  *            the new visibility state
       
  3228  *
       
  3229  * @exception SWTException
       
  3230  *                <ul>
       
  3231  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3232  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3233  *                thread that created the receiver</li>
       
  3234  *                </ul>
       
  3235  */
       
  3236 public void setVisible(boolean visible) {
       
  3237     checkWidget();
       
  3238     if (getVisible() == visible)
       
  3239         return;
       
  3240     OS.QWidget_setVisible(topHandle, visible);
       
  3241     if (visible) {
       
  3242         sendEvent(SWT.Show);
       
  3243         if(isDisposed()) return;
       
  3244     }
       
  3245     Control control = null;
       
  3246     boolean fixFocus = false;
       
  3247     if (!visible) {
       
  3248         if (Display.focusEvent != SWT.FocusOut) {
       
  3249             control = display.getFocusControl ();
       
  3250             fixFocus = isFocusAncestor (control);
       
  3251         }
       
  3252     }
       
  3253     if (!visible) {
       
  3254         sendEvent(SWT.Hide);
       
  3255         if (isDisposed ()) return;
       
  3256     }
       
  3257     if (fixFocus) fixFocus (control);
       
  3258 }
       
  3259 
       
  3260 /**
       
  3261  * Returns a point which is the result of converting the argument, which is
       
  3262  * specified in display relative coordinates, to coordinates relative to the
       
  3263  * receiver.
       
  3264  * <p>
       
  3265  *
       
  3266  * @param x
       
  3267  *            the x coordinate to be translated
       
  3268  * @param y
       
  3269  *            the y coordinate to be translated
       
  3270  * @return the translated coordinates
       
  3271  *
       
  3272  * @exception SWTException
       
  3273  *                <ul>
       
  3274  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
       
  3275  *                </li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3276  *                thread that created the receiver</li>
       
  3277  *                </ul>
       
  3278  *
       
  3279  * @since 2.1
       
  3280  */
       
  3281 public Point toControl(int x, int y) {
       
  3282     checkWidget();
       
  3283     Point p = OS.QWidget_mapFromGlobal(handle, x, y);
       
  3284     if(isMirrored()) {
       
  3285         p.x = getClientWidth() - p.x;
       
  3286     }
       
  3287     return p;
       
  3288 }
       
  3289 
       
  3290 /**
       
  3291  * Returns a point which is the result of converting the argument, which is
       
  3292  * specified in display relative coordinates, to coordinates relative to the
       
  3293  * receiver.
       
  3294  * <p>
       
  3295  *
       
  3296  * @param point
       
  3297  *            the point to be translated (must not be null)
       
  3298  * @return the translated coordinates
       
  3299  *
       
  3300  * @exception IllegalArgumentException
       
  3301  *                <ul>
       
  3302  *                <li>ERROR_NULL_ARGUMENT - if the point is null</li>
       
  3303  *                </ul>
       
  3304  * @exception SWTException
       
  3305  *                <ul>
       
  3306  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
       
  3307  *                </li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3308  *                thread that created the receiver</li>
       
  3309  *                </ul>
       
  3310  */
       
  3311 public Point toControl(Point point) {
       
  3312     checkWidget();
       
  3313     if (point == null)
       
  3314         error(SWT.ERROR_NULL_ARGUMENT);
       
  3315     return toControl(point.x, point.y);
       
  3316 }
       
  3317 
       
  3318 /**
       
  3319  * Returns a point which is the result of converting the argument, which is
       
  3320  * specified in coordinates relative to the receiver, to display relative
       
  3321  * coordinates.
       
  3322  * <p>
       
  3323  *
       
  3324  * @param x
       
  3325  *            the x coordinate to be translated
       
  3326  * @param y
       
  3327  *            the y coordinate to be translated
       
  3328  * @return the translated coordinates
       
  3329  *
       
  3330  * @exception SWTException
       
  3331  *                <ul>
       
  3332  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
       
  3333  *                </li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3334  *                thread that created the receiver</li>
       
  3335  *                </ul>
       
  3336  *
       
  3337  * @since 2.1
       
  3338  */
       
  3339 public Point toDisplay(int x, int y) {
       
  3340     checkWidget();
       
  3341     if(isMirrored()) {
       
  3342         x = getClientWidth() - x;
       
  3343     }
       
  3344     return OS.QWidget_mapToGlobal(handle, x, y);
       
  3345 }
       
  3346 
       
  3347 /**
       
  3348  * Returns a point which is the result of converting the argument, which is
       
  3349  * specified in coordinates relative to the receiver, to display relative
       
  3350  * coordinates.
       
  3351  * <p>
       
  3352  *
       
  3353  * @param point
       
  3354  *            the point to be translated (must not be null)
       
  3355  * @return the translated coordinates
       
  3356  *
       
  3357  * @exception IllegalArgumentException
       
  3358  *                <ul>
       
  3359  *                <li>ERROR_NULL_ARGUMENT - if the point is null</li>
       
  3360  *                </ul>
       
  3361  * @exception SWTException
       
  3362  *                <ul>
       
  3363  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
       
  3364  *                </li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3365  *                thread that created the receiver</li>
       
  3366  *                </ul>
       
  3367  */
       
  3368 public Point toDisplay(Point point) {
       
  3369     checkWidget();
       
  3370     if (point == null)
       
  3371         error(SWT.ERROR_NULL_ARGUMENT);
       
  3372     return toDisplay(point.x, point.y);
       
  3373 }
       
  3374 
       
  3375 /**
       
  3376  * Based on the argument, perform one of the expected platform traversal action.
       
  3377  * The argument should be one of the constants: <code>SWT.TRAVERSE_ESCAPE</code>
       
  3378  * , <code>SWT.TRAVERSE_RETURN</code>, <code>SWT.TRAVERSE_TAB_NEXT</code>,
       
  3379  * <code>SWT.TRAVERSE_TAB_PREVIOUS</code>, <code>SWT.TRAVERSE_ARROW_NEXT</code>
       
  3380  * and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
       
  3381  *
       
  3382  * @param traversal
       
  3383  *            the type of traversal
       
  3384  * @return true if the traversal succeeded
       
  3385  *
       
  3386  * @exception SWTException
       
  3387  *                <ul>
       
  3388  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3389  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3390  *                thread that created the receiver</li>
       
  3391  *                </ul>
       
  3392  */
       
  3393 public boolean traverse(int traversal) {
       
  3394     checkWidget();
       
  3395     Event event = new Event();
       
  3396     event.doit = true;
       
  3397     event.detail = traversal;
       
  3398     sendEvent(SWT.Traverse, event);
       
  3399     if (isDisposed())
       
  3400         return true;
       
  3401 
       
  3402     // It doesn't make sense to activate mnemonic traversal by calling this
       
  3403     // but if it's done then traversal is attempted relative to this control.
       
  3404     // Normally it would be done relative to the control that had the
       
  3405     // shortcut event.
       
  3406     Display.mnemonicControl = this;
       
  3407 
       
  3408     return doTraversal(event);
       
  3409 }
       
  3410 
       
  3411 boolean traverseEscape() {
       
  3412     // Not implemented, in mobile devices there's usually no esc key
       
  3413     return false;
       
  3414 }
       
  3415 
       
  3416 boolean traverseGroup(boolean next) {
       
  3417     Control root = computeTabRoot();
       
  3418     Control group = computeTabGroup();
       
  3419     Control[] list = root.computeTabList();
       
  3420 
       
  3421     // Find this Control, traversal is done respective to that
       
  3422     int length = list.length;
       
  3423     int index = 0;
       
  3424     while (index < length) {
       
  3425         if (list[index] == group)
       
  3426             break;
       
  3427         index++;
       
  3428     }
       
  3429     if (index >= length)
       
  3430         return false;
       
  3431 
       
  3432     // Traverse to the next or previous, looping around from the end or the
       
  3433     // beginning of the array.
       
  3434     int start = index, offset = (next) ? 1 : -1;
       
  3435     while ((index = ((index + offset + length) % length)) != start) {
       
  3436         Control control = list[index];
       
  3437         if (!control.isDisposed() &&
       
  3438                 (control.packageProxy != null ? control.packageProxy.setTabGroupFocus() : control.setTabGroupFocus_pp())) {
       
  3439             return true;
       
  3440         }
       
  3441     }
       
  3442     if (group.isDisposed())
       
  3443         return false;
       
  3444     return (group.packageProxy != null ? group.packageProxy.setTabGroupFocus() : group.setTabGroupFocus_pp());
       
  3445 }
       
  3446 
       
  3447 boolean traverseItem(boolean next) {
       
  3448     // Mobile devices often don't have tab keys, only the arrows.
       
  3449     // Therefore the platform always suggests tab group traversal.
       
  3450     // However, it's possible to attempt item traversal by using
       
  3451     // TraverseEvents
       
  3452     // to override the default behavior or by calling the traverse method
       
  3453     // with
       
  3454     // item traversal type.
       
  3455 
       
  3456     // Find this Control, traversal is done respective to that
       
  3457     Control[] children = parent._getChildren();
       
  3458     int length = children.length;
       
  3459     int index = 0;
       
  3460     while (index < length) {
       
  3461         if (children[index] == this)
       
  3462             break;
       
  3463         index++;
       
  3464     }
       
  3465     if (index == length)
       
  3466         return false;
       
  3467 
       
  3468     // Traverse to the next or previous, looping around from the end or the
       
  3469     // beginning of the array.
       
  3470     int start = index, offset = (next) ? 1 : -1;
       
  3471     while ((index = (index + offset + length) % length) != start) {
       
  3472         Control child = children[index];
       
  3473         if (!child.isDisposed() && child.isTabItem()) {
       
  3474             if (child.setTabItemFocus())
       
  3475                 return true;
       
  3476         }
       
  3477     }
       
  3478     return false;
       
  3479 }
       
  3480 
       
  3481 /*
       
  3482  * Traverses to the next control of the control that received the last shortcut
       
  3483  * event.
       
  3484  */
       
  3485 boolean traverseMnemonic(char key) {
       
  3486 
       
  3487     // SWT checks for mnemonic hit here
       
  3488 
       
  3489     if (Display.mnemonicControl == null)
       
  3490         return false;
       
  3491     Control nextControl = Display.mnemonicControl.findNextControl(false);
       
  3492     if (nextControl != null) {
       
  3493         nextControl.setFocus(OS.QT_TABFOCUSREASON);
       
  3494         return true;
       
  3495     }
       
  3496     return false;
       
  3497 }
       
  3498 
       
  3499 boolean traversePage(boolean next) {
       
  3500     // Not implemented, should implement for MultiPageDialog
       
  3501     return false;
       
  3502 }
       
  3503 
       
  3504 boolean traverseReturn() {
       
  3505     return menuShell().invokeDefaultButton();
       
  3506 }
       
  3507 
       
  3508 /**
       
  3509  * Forces all outstanding paint requests for the widget to be processed before
       
  3510  * this method returns. If there are no outstanding paint request, this method
       
  3511  * does nothing.
       
  3512  * <p>
       
  3513  * Note: This method does not cause a redraw.
       
  3514  * </p>
       
  3515  *
       
  3516  * @exception SWTException
       
  3517  *                <ul>
       
  3518  *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  3519  *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
       
  3520  *                thread that created the receiver</li>
       
  3521  *                </ul>
       
  3522  *
       
  3523  * @see #redraw()
       
  3524  * @see #redraw(int, int, int, int, boolean)
       
  3525  * @see PaintListener
       
  3526  * @see SWT#Paint
       
  3527  */
       
  3528 public void update() {
       
  3529     checkWidget();
       
  3530     _update();
       
  3531 }
       
  3532 
       
  3533 void _update() {
       
  3534     // This has a problem that it dispatches other than paint events too.
       
  3535     OS.QCoreApplication_processEvents(Display.handle,
       
  3536             OS.QEVENTLOOP_EXCLUDEUSERINPUTEVENTS);
       
  3537     if (isDisposed())
       
  3538         return;
       
  3539     OS.QCoreApplication_sendPostedEvents(Display.handle, handle,
       
  3540             OS.QEVENT_PAINT);
       
  3541 }
       
  3542 
       
  3543 private void updateAutoFillBackground() {
       
  3544     Control control = findBackgroundControl();
       
  3545     boolean enabled = false;
       
  3546     if(control != null) {
       
  3547         enabled = (control.background != null || control.backgroundImage != null);
       
  3548     }
       
  3549     OS.QWidget_setAutoFillBackground(topHandle, enabled);
       
  3550 }
       
  3551 
       
  3552 void updateBackground() {
       
  3553     if(packageProxy != null) {
       
  3554         packageProxy.setBackground();
       
  3555     } else {
       
  3556         setBackground_pp();
       
  3557     }
       
  3558 }
       
  3559 
       
  3560 void updateBackgroundMode () {
       
  3561     int oldState = state & WidgetState.PARENT_BACKGROUND;
       
  3562     checkBackground ();
       
  3563     if (oldState != (state & WidgetState.PARENT_BACKGROUND)) {
       
  3564         if(packageProxy != null) {
       
  3565             packageProxy.setBackground();
       
  3566         } else {
       
  3567             setBackground_pp ();
       
  3568         }
       
  3569     }
       
  3570 }
       
  3571 
       
  3572 void updateImages () {
       
  3573     // Override to update any images that should be updated after a settings change
       
  3574 }
       
  3575 
       
  3576 void updateLayout(boolean all) {
       
  3577     /* Do nothing */
       
  3578 }
       
  3579 
       
  3580 void waitXRequestComplete() {
       
  3581     // Make XServer process all queued requests not discarding any events.
       
  3582     // Note that this is heavy and slow. Here goes everything, not only the
       
  3583     // one event we are waiting for.
       
  3584     OS.QApplication_syncX();
       
  3585     // Make Qt process all XEvents.
       
  3586     Display.noInterrupt = true;
       
  3587     OS.QCoreApplication_processEvents(Display.handle,
       
  3588             OS.QEVENTLOOP_EXCLUDEUSERINPUTEVENTS);
       
  3589     Display.noInterrupt = false;
       
  3590 }
       
  3591 }