javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Composite.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 
       
    16 import org.eclipse.swt.SWT;
       
    17 import org.eclipse.swt.graphics.Point;
       
    18 import org.eclipse.swt.graphics.Rectangle;
       
    19 import org.eclipse.swt.internal.qt.OS;
       
    20 import org.eclipse.swt.internal.qt.WidgetConstant;
       
    21 import org.eclipse.swt.internal.qt.WidgetState;
       
    22 
       
    23 /**
       
    24  * Instances of this class are controls which are capable
       
    25  * of containing other controls.
       
    26  * <dl>
       
    27  * <dt><b>Styles:</b></dt>
       
    28  * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP</dd>
       
    29  * <dt><b>Events:</b></dt>
       
    30  * <dd>(none)</dd>
       
    31  * </dl>
       
    32  * <p>
       
    33  * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
       
    34  * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
       
    35  * They can be used with <code>Composite</code> if you are drawing your own, but their
       
    36  * behavior is undefined if they are used with subclasses of <code>Composite</code> other
       
    37  * than <code>Canvas</code>.
       
    38  * </p><p>
       
    39  * This class may be subclassed by custom control implementors
       
    40  * who are building controls that are constructed from aggregates
       
    41  * of other controls.
       
    42  * </p>
       
    43  *
       
    44  * @see Canvas
       
    45  */
       
    46 public class Composite extends Scrollable {
       
    47     Layout layout;
       
    48     Control[] tabList;
       
    49     int layoutCount;
       
    50     int backgroundMode;
       
    51     
       
    52 /**
       
    53  * Prevents uninitialized instances from being created outside the package.
       
    54  */
       
    55 Composite () {
       
    56 }
       
    57 
       
    58 /**
       
    59  * Constructs a new instance of this class given its parent
       
    60  * and a style value describing its behavior and appearance.
       
    61  * <p>
       
    62  * The style value is either one of the style constants defined in
       
    63  * class <code>SWT</code> which is applicable to instances of this
       
    64  * class, or must be built by <em>bitwise OR</em>'ing together 
       
    65  * (that is, using the <code>int</code> "|" operator) two or more
       
    66  * of those <code>SWT</code> style constants. The class description
       
    67  * lists the style constants that are applicable to the class.
       
    68  * Style bits are also inherited from superclasses.
       
    69  * </p>
       
    70  *
       
    71  * @param parent a widget which will be the parent of the new instance (cannot be null)
       
    72  * @param style the style of widget to construct
       
    73  *
       
    74  * @exception IllegalArgumentException <ul>
       
    75  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
       
    76  * </ul>
       
    77  * @exception SWTException <ul>
       
    78  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
    79  * </ul>
       
    80  *
       
    81  * @see SWT#NO_BACKGROUND
       
    82  * @see SWT#NO_FOCUS
       
    83  * @see SWT#NO_MERGE_PAINTS
       
    84  * @see SWT#NO_REDRAW_RESIZE
       
    85  * @see SWT#NO_RADIO_GROUP
       
    86  * @see Widget#getStyle
       
    87  */
       
    88 public Composite (Composite parent, int style) {
       
    89     super (parent, style);
       
    90 }
       
    91 
       
    92 /**
       
    93  * <p>
       
    94  * <b>IMPORTANT:</b> This constructor is <em>not</em> part of the SWT
       
    95  * public API. It should never be referenced from application code. 
       
    96  * </p>
       
    97  */
       
    98 protected Composite(Composite parent, int style, int extraStyle, Object packageProxy, 
       
    99         boolean isExtended) {
       
   100     super(parent, style, extraStyle, packageProxy, isExtended);
       
   101 }
       
   102 
       
   103 void addControl_pp (Control control) {
       
   104 }
       
   105 
       
   106 void checkBuffered () {
       
   107     if ((state & WidgetState.CANVAS) == 0) {
       
   108         super.checkBuffered ();
       
   109     }
       
   110 }
       
   111 
       
   112 void checkNoBackground() {
       
   113     if((style & SWT.NO_BACKGROUND) != 0) {
       
   114         if(handle != 0) {
       
   115             OS.QWidget_setAttribute(handle, OS.QT_WA_NOSYSTEMBACKGROUND, true);
       
   116         }
       
   117     }
       
   118 }
       
   119 
       
   120 void checkNoFocus() {
       
   121     if((style & SWT.NO_FOCUS) != 0) {
       
   122         OS.QWidget_setFocusPolicy(handle, OS.QT_FOCUSPOLICY_NOFOCUS);
       
   123         int topHandle;
       
   124         if((topHandle = this.topHandle) != handle) {
       
   125             OS.QWidget_setFocusPolicy(topHandle, OS.QT_FOCUSPOLICY_NOFOCUS);
       
   126         }
       
   127     }
       
   128 }
       
   129 
       
   130 void checkNoRedrawResize() {
       
   131     if((style & SWT.NO_REDRAW_RESIZE) != 0) {
       
   132         if(handle != 0) {
       
   133             OS.QWidget_setAttribute(handle, OS.QT_WA_STATICCONTENTS, true);
       
   134         }
       
   135     }
       
   136 }
       
   137 
       
   138 protected void checkSubclass () {
       
   139     /* Do nothing - Subclassing is allowed */
       
   140 }
       
   141 
       
   142 public Point computeSize (int wHint, int hHint, boolean changed) {
       
   143     checkWidget ();
       
   144 
       
   145     if ((state & WidgetState.CANVAS) != 0) {
       
   146         Point size;
       
   147         if (layout != null) {
       
   148             if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
       
   149                 changed |= (state & WidgetState.LAYOUT_CHANGED) != 0;
       
   150                 state &= ~WidgetState.LAYOUT_CHANGED;
       
   151                 size = layout.computeSize (this, wHint, hHint, changed);
       
   152             } else {
       
   153                 size = new Point (wHint, hHint);
       
   154             }
       
   155         } else {
       
   156             size = minimumSize (wHint, hHint, changed);
       
   157         }
       
   158         if (size.x == 0) size.x = WidgetConstant.DEFAULT_WIDTH;
       
   159         if (size.y == 0) size.y = WidgetConstant.DEFAULT_HEIGHT;
       
   160         if (wHint != SWT.DEFAULT) size.x = wHint;
       
   161         if (hHint != SWT.DEFAULT) size.y = hHint;
       
   162         Rectangle trim = computeTrim (0, 0, size.x, size.y);
       
   163         return new Point (trim.width, trim.height);        
       
   164     } else {
       
   165         // If this is not a stand-alone Composite, Shell or Canvas, 
       
   166         // call Scrollable's implementation
       
   167         return super.computeSize(wHint, hHint, changed);
       
   168     }
       
   169 }
       
   170 
       
   171 Control [] computeTabList () {
       
   172     Control result [] = super.computeTabList ();
       
   173     if (result.length == 0) return result;
       
   174     Control [] list = tabList != null ? _getTabList () : _getChildren ();
       
   175     for (int i=0; i<list.length; i++) {
       
   176         Control child = list [i];
       
   177         Control [] childList = child.computeTabList ();
       
   178         if (childList.length != 0) {
       
   179             Control [] newResult = new Control [result.length + childList.length];
       
   180             System.arraycopy (result, 0, newResult, 0, result.length);
       
   181             System.arraycopy (childList, 0, newResult, result.length, childList.length);
       
   182             result = newResult;
       
   183         }
       
   184     }
       
   185     return result;
       
   186 }
       
   187 
       
   188 void createHandle_pp (int index) {
       
   189     super.createHandle_pp (index);
       
   190     frameHandle = topHandle = scrollAreaHandle = OS.QScrollArea_new(0);
       
   191     handle = OS.QAbstractScrollArea_viewPort(scrollAreaHandle);
       
   192 
       
   193     // Composite by itself must not by default accept focus by clicking.
       
   194     int policy = OS.QWidget_focusPolicy(topHandle) & ~OS.QT_FOCUSPOLICY_CLICKFOCUS;
       
   195     OS.QWidget_setFocusPolicy(topHandle, policy);
       
   196     
       
   197     // Stand-alone Composites, Shells, Canvases set the CANVAS flag
       
   198     state |= (WidgetState.HANDLE | WidgetState.CANVAS);
       
   199 }
       
   200 
       
   201 boolean doHandleMouseEvent(int type, int widgetHandle, int button, int x, int y, int state, int buttons) {
       
   202     boolean cancel = super.doHandleMouseEvent(type, widgetHandle, button, x, y, state, buttons);
       
   203     // From the CANVAS flag it's known if this is a Shell/stand-alone Composite/Canvas. 
       
   204     if((this.state & WidgetState.CANVAS) != 0) {
       
   205         // Set focus for a Canvas with no children. 
       
   206         if(type == SWT.MouseDown) {
       
   207             if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
       
   208                 Control[] children = getChildren();
       
   209                 if (children == null || children.length == 0) {
       
   210                     setFocus (OS.QT_OTHERFOCUSREASON);
       
   211                 }
       
   212             }
       
   213         }
       
   214     }
       
   215     return cancel;
       
   216 }
       
   217 
       
   218 Composite findDeferredControl () {
       
   219     return layoutCount > 0 ? this : parent.findDeferredControl ();
       
   220 }
       
   221 
       
   222 Menu [] findMenus (Control control) {
       
   223     if (control == this) return new Menu [0];
       
   224     Menu result [] = super.findMenus (control);
       
   225     Control [] children = _getChildren ();
       
   226     for (int i=0; i<children.length; i++) {
       
   227         Control child = children [i];
       
   228         Menu [] menuList = child.findMenus (control);
       
   229         if (menuList.length != 0) {
       
   230             Menu [] newResult = new Menu [result.length + menuList.length];
       
   231             System.arraycopy (result, 0, newResult, 0, result.length);
       
   232             System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
       
   233             result = newResult;
       
   234         }
       
   235     }
       
   236     return result;
       
   237 }
       
   238 
       
   239 void fixTabList (Control control) {
       
   240     if (tabList == null) return;
       
   241     int count = 0;
       
   242     for (int i=0; i<tabList.length; i++) {
       
   243         if (tabList [i] == control) count++;
       
   244     }
       
   245     if (count == 0) return;
       
   246     Control [] newList = null;
       
   247     int length = tabList.length - count;
       
   248     if (length != 0) {
       
   249         newList = new Control [length];
       
   250         int index = 0;
       
   251         for (int i=0; i<tabList.length; i++) {
       
   252             if (tabList [i] != control) {
       
   253                 newList [index++] = tabList [i];
       
   254             }
       
   255         }
       
   256     }
       
   257     tabList = newList;
       
   258 }
       
   259 
       
   260 /**
       
   261  * Returns the receiver's background drawing mode. This
       
   262  * will be one of the following constants defined in class
       
   263  * <code>SWT</code>:
       
   264  * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
       
   265  * <code>INHERTIT_FORCE</code>.
       
   266  *
       
   267  * @return the background mode
       
   268  *
       
   269  * @exception SWTException <ul>
       
   270  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   271  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   272  * </ul>
       
   273  *
       
   274  * @see SWT
       
   275  * 
       
   276  * @since 3.2
       
   277  */
       
   278 public int getBackgroundMode () {
       
   279     checkWidget ();
       
   280     return backgroundMode;
       
   281 }
       
   282 
       
   283 /**
       
   284  * Returns a (possibly empty) array containing the receiver's children.
       
   285  * Children are returned in the order that they are drawn.  The topmost
       
   286  * control appears at the beginning of the array.  Subsequent controls
       
   287  * draw beneath this control and appear later in the array.
       
   288  * <p>
       
   289  * Note: This is not the actual structure used by the receiver
       
   290  * to maintain its list of children, so modifying the array will
       
   291  * not affect the receiver. 
       
   292  * </p>
       
   293  *
       
   294  * @return an array of children
       
   295  * 
       
   296  * @see Control#moveAbove
       
   297  * @see Control#moveBelow
       
   298  *
       
   299  * @exception SWTException <ul>
       
   300  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   301  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   302  * </ul>
       
   303  */
       
   304 public Control [] getChildren () {
       
   305     checkWidget();
       
   306     return _getChildren ();
       
   307 }
       
   308 
       
   309 Control [] _getChildren() {
       
   310     
       
   311     // For some reason MultiPageDialog's children are not children of the handle
       
   312     int widgetHandle = packageProxy != null ? packageProxy.handleWithChildren() : handleWithChildren_pp();
       
   313     
       
   314     int[] list = OS.QObject_children(widgetHandle); 
       
   315     int count = list.length;
       
   316     if (count == 0) return new Control [0];
       
   317     Control [] children = new Control [count];
       
   318     int childControls = 0;
       
   319     for(int i = 0; i < count; ++i) {
       
   320         int handle = list[i];
       
   321         if (handle != 0) {
       
   322             Widget widget = Display.getWidget (handle);
       
   323             if (widget != null && widget != this) {
       
   324                 if (widget instanceof Control && !(widget instanceof Shell)) {
       
   325                     children [childControls++] = (Control) widget;
       
   326                 }
       
   327             }
       
   328         }
       
   329     }
       
   330     if (childControls == count) return children;
       
   331     Control [] newChildren = new Control [childControls];
       
   332     System.arraycopy (children, 0, newChildren, 0, childControls);
       
   333     return newChildren;
       
   334 }
       
   335 
       
   336 /**
       
   337  * Returns layout which is associated with the receiver, or
       
   338  * null if one has not been set.
       
   339  *
       
   340  * @return the receiver's layout or null
       
   341  *
       
   342  * @exception SWTException <ul>
       
   343  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   344  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   345  * </ul>
       
   346  */
       
   347 public Layout getLayout () {
       
   348     checkWidget();
       
   349     return layout;
       
   350 }
       
   351 
       
   352 /**
       
   353  * Gets the (possibly empty) tabbing order for the control.
       
   354  *
       
   355  * @return tabList the ordered list of controls representing the tab order
       
   356  *
       
   357  * @exception SWTException <ul>
       
   358  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   359  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   360  * </ul>
       
   361  * 
       
   362  * @see #setTabList
       
   363  */
       
   364 public Control [] getTabList () {
       
   365     checkWidget ();
       
   366     Control [] tabList = _getTabList ();
       
   367     if (tabList == null) {
       
   368         int count = 0;
       
   369         Control [] list =_getChildren ();
       
   370         for (int i=0; i<list.length; i++) {
       
   371             if (list [i].isTabGroup ()) count++;
       
   372         }
       
   373         tabList = new Control [count];
       
   374         int index = 0;
       
   375         for (int i=0; i<list.length; i++) {
       
   376             if (list [i].isTabGroup ()) {
       
   377                 tabList [index++] = list [i];
       
   378             }
       
   379         }
       
   380     }
       
   381     return tabList;
       
   382 }
       
   383 
       
   384 Control [] _getTabList () {
       
   385     if (tabList == null) return tabList;
       
   386     int count = 0;
       
   387     for (int i=0; i<tabList.length; i++) {
       
   388         if (!tabList [i].isDisposed ()) count++;
       
   389     }
       
   390     if (count == tabList.length) return tabList;
       
   391     Control [] newList = new Control [count];
       
   392     int index = 0;
       
   393     for (int i=0; i<tabList.length; i++) {
       
   394         if (!tabList [i].isDisposed ()) {
       
   395             newList [index++] = tabList [i];
       
   396         }
       
   397     }
       
   398     tabList = newList;
       
   399     return tabList;
       
   400 }
       
   401 
       
   402 /*
       
   403  * This method is here because MultiPageDialog for some reason has a Composite
       
   404  * which has its children not as children of the handle. It overrides this. 
       
   405  */ 
       
   406 int handleWithChildren_pp() {
       
   407     return handle; // handle == viewport
       
   408 }
       
   409 
       
   410 boolean hooksKeys () {
       
   411     return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
       
   412 }
       
   413 
       
   414 /**
       
   415  * If the receiver has a layout, asks the layout to <em>lay out</em>
       
   416  * (that is, set the size and location of) the receiver's children. 
       
   417  * If the receiver does not have a layout, do nothing.
       
   418  * <p>
       
   419  * This is equivalent to calling <code>layout(true)</code>.
       
   420  * </p>
       
   421  * <p>
       
   422  * Note: Layout is different from painting. If a child is
       
   423  * moved or resized such that an area in the parent is
       
   424  * exposed, then the parent will paint. If no child is
       
   425  * affected, the parent will not paint.
       
   426  * </p>
       
   427  * 
       
   428  * @exception SWTException <ul>
       
   429  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   430  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   431  * </ul>
       
   432  */
       
   433 public void layout () {
       
   434     checkWidget ();
       
   435     layout (true);
       
   436 }
       
   437 
       
   438 /**
       
   439  * If the receiver has a layout, asks the layout to <em>lay out</em>
       
   440  * (that is, set the size and location of) the receiver's children. 
       
   441  * If the argument is <code>true</code> the layout must not rely
       
   442  * on any information it has cached about the immediate children. If it
       
   443  * is <code>false</code> the layout may (potentially) optimize the
       
   444  * work it is doing by assuming that none of the receiver's 
       
   445  * children has changed state since the last layout.
       
   446  * If the receiver does not have a layout, do nothing.
       
   447  * <p>
       
   448  * If a child is resized as a result of a call to layout, the 
       
   449  * resize event will invoke the layout of the child.  The layout
       
   450  * will cascade down through all child widgets in the receiver's widget 
       
   451  * tree until a child is encountered that does not resize.  Note that 
       
   452  * a layout due to a resize will not flush any cached information 
       
   453  * (same as <code>layout(false)</code>).
       
   454  * </p>
       
   455  * <p>
       
   456  * Note: Layout is different from painting. If a child is
       
   457  * moved or resized such that an area in the parent is
       
   458  * exposed, then the parent will paint. If no child is
       
   459  * affected, the parent will not paint.
       
   460  * </p>
       
   461  *
       
   462  * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
       
   463  *
       
   464  * @exception SWTException <ul>
       
   465  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   466  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   467  * </ul>
       
   468  */
       
   469 public void layout (boolean changed) {
       
   470     checkWidget ();
       
   471     if (layout == null) return;
       
   472     layout (changed, false);
       
   473 }
       
   474 
       
   475 void layout (boolean changed, boolean all) {
       
   476     checkWidget ();
       
   477     if (layout == null && !all) return;
       
   478     markLayout (changed, all);
       
   479     updateLayout (all);
       
   480 }
       
   481 
       
   482 void markLayout (boolean changed, boolean all) {
       
   483     if (layout != null) {
       
   484         state |= WidgetState.LAYOUT_NEEDED;
       
   485         if (changed) state |= WidgetState.LAYOUT_CHANGED;
       
   486     }
       
   487     if (all) {
       
   488         Control [] children = _getChildren ();
       
   489         for (int i=0; i<children.length; i++) {
       
   490             children [i].markLayout (changed, all);
       
   491         }
       
   492     }
       
   493 }
       
   494 
       
   495 Point minimumSize (int wHint, int hHint, boolean changed) {
       
   496     Control [] children = _getChildren ();
       
   497     int width = 0, height = 0;
       
   498     for (int i=0; i<children.length; i++) {
       
   499         Rectangle rect = children [i].getBounds ();
       
   500         width = Math.max (width, rect.x + rect.width);
       
   501         height = Math.max (height, rect.y + rect.height);
       
   502     }
       
   503     return new Point (width, height);
       
   504 }
       
   505 
       
   506 void qt_swt_event_widgetResized_pp(int widgetHandle, int oldWidth, int oldHeight, int width, int height, boolean sendResizeEvent) {
       
   507     if (isDisposed ()) return;
       
   508     if((widgetHandle == handle) && isMirrored()) {
       
   509         // In real coordinate system the children need to be moved so that they
       
   510         // appear stationary in the emulated mirrored coordinate system. 
       
   511         final int dx = width - oldWidth;
       
   512         if(dx != 0) {
       
   513             Control[] children =_getChildren();
       
   514             try {
       
   515                 Display.blockedQtEventType = OS.QSWTEVENT_WIDGETMOVED;
       
   516                 for (int i = 0; i < children.length; ++i) {
       
   517                     Control child = children[i];
       
   518                     if (!child.isDisposed()) {
       
   519                         final int childHandle = child.topHandle;
       
   520                         Point pos = OS.QWidget_pos(childHandle);
       
   521                         OS.QWidget_move(childHandle, pos.x + dx, pos.y);
       
   522                     }
       
   523                 }
       
   524             } finally {
       
   525                 Display.blockedQtEventType = OS.QEVENT_NONE;
       
   526             }
       
   527         }
       
   528     }
       
   529     super.qt_swt_event_widgetResized_pp(widgetHandle, oldWidth, oldHeight, width, height, sendResizeEvent);
       
   530     if (layout != null) {
       
   531         markLayout (false, false);
       
   532         updateLayout (false);
       
   533     }
       
   534 }
       
   535 
       
   536 void redrawChildren () {
       
   537     super.redrawChildren ();
       
   538     Control [] children = _getChildren ();
       
   539     for (int i = 0; i < children.length; i++) {
       
   540         Control child = children [i];
       
   541         if ((child.state & WidgetState.PARENT_BACKGROUND) != 0) {
       
   542             child.redraw();
       
   543             child.redrawChildren ();
       
   544         }
       
   545     }
       
   546 }
       
   547 
       
   548 void releaseChildren_pp (boolean destroy) {
       
   549     Control [] children = _getChildren ();
       
   550     for (int i=0; i<children.length; i++) {
       
   551         Control child = children [i];
       
   552         if (child != null && !child.isDisposed ()) {
       
   553             child.release (false);
       
   554         }
       
   555     }
       
   556     super.releaseChildren_pp (destroy);
       
   557 }
       
   558 
       
   559 void releaseWidget_pp () {
       
   560     super.releaseWidget_pp ();
       
   561     layout = null;
       
   562     tabList = null;
       
   563 }
       
   564 
       
   565 void removeControl_pp (Control control) {
       
   566     fixTabList (control);
       
   567 }
       
   568 
       
   569 /**
       
   570  * Sets the background drawing mode to the argument which should
       
   571  * be one of the following constants defined in class <code>SWT</code>:
       
   572  * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
       
   573  * <code>INHERIT_FORCE</code>.
       
   574  *
       
   575  * @param mode the new background mode
       
   576  *
       
   577  * @exception SWTException <ul>
       
   578  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   579  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   580  * </ul>
       
   581  *
       
   582  * @see SWT
       
   583  * 
       
   584  * @since 3.2
       
   585  */
       
   586 public void setBackgroundMode (int mode) {
       
   587     checkWidget();
       
   588     backgroundMode = mode;
       
   589     Control [] children = _getChildren ();
       
   590     for (int i = 0; i < children.length; i++) {
       
   591         children [i].updateBackgroundMode ();       
       
   592     }
       
   593 }
       
   594 
       
   595 int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
       
   596     int result = super.setBounds (x, y, width, height, move, resize);
       
   597     if ((result & WidgetState.RESIZED) != 0 && layout != null) {
       
   598         markLayout (false, false);
       
   599         updateLayout (false);
       
   600     }
       
   601     return result;
       
   602 }
       
   603 
       
   604 public boolean setFocus () {
       
   605     checkWidget();
       
   606     return setFocus(OS.QT_OTHERFOCUSREASON);
       
   607 }
       
   608 
       
   609 // Given focus reason affects if the tabbing focus highlight is drawn. 
       
   610 // For QT_TABFOCUSREASON it is drawn.  For QT_OTHERFOCUSREASON it's not. 
       
   611 boolean setFocus (int focusReason) {
       
   612     Control [] children = _getChildren ();
       
   613     for (int i=0; i<children.length; i++) {
       
   614         Control child = children [i];
       
   615         if (child.getVisible () && child.setFocus (focusReason)) return true;
       
   616     }
       
   617     return super.setFocus (focusReason);
       
   618 }
       
   619 
       
   620 /**
       
   621  * Sets the layout which is associated with the receiver to be
       
   622  * the argument which may be null.
       
   623  *
       
   624  * @param layout the receiver's new layout or null
       
   625  *
       
   626  * @exception SWTException <ul>
       
   627  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   628  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   629  * </ul>
       
   630  */
       
   631 public void setLayout (Layout layout) {
       
   632     checkWidget();
       
   633     this.layout = layout;
       
   634 }
       
   635 
       
   636 boolean setTabGroupFocus_pp () {
       
   637     if (isTabItem ()) return setTabItemFocus ();
       
   638     boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
       
   639 
       
   640     // Canvas is getting focus only if it seems to implement key handling. 
       
   641     if ((state & WidgetState.CANVAS) != 0) {
       
   642         takeFocus = hooksKeys ();
       
   643         if ((style & SWT.EMBEDDED) != 0) takeFocus = true;
       
   644     }
       
   645     
       
   646     if (takeFocus && setTabItemFocus ()) return true;
       
   647     Control [] children = _getChildren ();
       
   648     for (int i=0; i<children.length; i++) {
       
   649         Control child = children [i];
       
   650         if (child.isTabItem () && child.setRadioFocus (true)) return true;
       
   651     }
       
   652     for (int i=0; i<children.length; i++) {
       
   653         Control child = children [i];
       
   654         if (child.isTabItem () && !child.isTabGroup () && child.setTabItemFocus ()) {
       
   655             return true;
       
   656         }
       
   657     }
       
   658     return false;
       
   659 }
       
   660 
       
   661 /**
       
   662  * Sets the tabbing order for the specified controls to
       
   663  * match the order that they occur in the argument list.
       
   664  *
       
   665  * @param tabList the ordered list of controls representing the tab order or null
       
   666  *
       
   667  * @exception IllegalArgumentException <ul>
       
   668  *    <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li> 
       
   669  *    <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
       
   670  * </ul>
       
   671  * @exception SWTException <ul>
       
   672  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   673  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   674  * </ul>
       
   675  */
       
   676 public void setTabList (Control [] tabList) {
       
   677     checkWidget ();
       
   678     if (tabList != null) {
       
   679         for (int i=0; i<tabList.length; i++) {
       
   680             Control control = tabList [i];
       
   681             if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
       
   682             if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
       
   683             if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
       
   684         }
       
   685         Control [] newList = new Control [tabList.length];
       
   686         System.arraycopy (tabList, 0, newList, 0, tabList.length);
       
   687         tabList = newList;
       
   688     } 
       
   689     this.tabList = tabList;
       
   690 }
       
   691 
       
   692 void updateBackground() {
       
   693     super.updateBackground ();
       
   694     Control [] children = _getChildren ();
       
   695     for (int i=0; i<children.length; i++) {
       
   696         if ((children [i].state & WidgetState.PARENT_BACKGROUND) != 0) {
       
   697             children [i].updateBackground ();
       
   698         }
       
   699     }
       
   700 }
       
   701 
       
   702 void updateBackgroundMode () {
       
   703     super.updateBackgroundMode ();
       
   704     Control [] children = _getChildren ();
       
   705     for (int i = 0; i < children.length; i++) {
       
   706         children [i].updateBackgroundMode ();       
       
   707     }
       
   708 }
       
   709 
       
   710 void updateLayout (boolean all) {
       
   711     Composite parent = findDeferredControl ();
       
   712     if (parent != null) {
       
   713         parent.state |= WidgetState.LAYOUT_CHILD;
       
   714         return;
       
   715     }
       
   716     if ((state & WidgetState.LAYOUT_NEEDED) != 0) {
       
   717         boolean changed = (state & WidgetState.LAYOUT_CHANGED) != 0;
       
   718         state &= ~(WidgetState.LAYOUT_NEEDED | WidgetState.LAYOUT_CHANGED);
       
   719         layout.layout (this, changed);
       
   720     }
       
   721     if (all) {
       
   722         state &= ~WidgetState.LAYOUT_CHILD;
       
   723         Control [] children = _getChildren ();
       
   724         for (int i=0; i<children.length; i++) {
       
   725             children [i].updateLayout (all);
       
   726         }
       
   727     }
       
   728 }
       
   729 }