javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Widget.java
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2000, 2007 IBM Corporation and others.
       
     3  * Portion Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     4  * All rights reserved. This program and the accompanying materials
       
     5  * are made available under the terms of the Eclipse Public License v1.0
       
     6  * which accompanies this distribution, and is available at
       
     7  * http://www.eclipse.org/legal/epl-v10.html
       
     8  *
       
     9  * Contributors:
       
    10  *     IBM Corporation - initial API and implementation
       
    11  *     Nokia Corporation - Qt implementation
       
    12  *******************************************************************************/
       
    13 package org.eclipse.swt.widgets;
       
    14 
       
    15 
       
    16 import org.eclipse.ercp.swt.mobile.Command;
       
    17 import org.eclipse.swt.SWT;
       
    18 import org.eclipse.swt.events.DisposeListener;
       
    19 import org.eclipse.swt.internal.SWTEventListener;
       
    20 import org.eclipse.swt.internal.qt.OS;
       
    21 import org.eclipse.swt.internal.qt.PackageProxy;
       
    22 import org.eclipse.swt.internal.qt.QObjectDeleteWrapper;
       
    23 import org.eclipse.swt.internal.qt.WidgetConstant;
       
    24 import org.eclipse.swt.internal.qt.WidgetState;
       
    25 
       
    26 /**
       
    27  * This class is the abstract superclass of all user interface objects.
       
    28  * Widgets are created, disposed and issue notification to listeners
       
    29  * when events occur which affect them.
       
    30  * <dl>
       
    31  * <dt><b>Styles:</b></dt>
       
    32  * <dd>(none)</dd>
       
    33  * <dt><b>Events:</b></dt>
       
    34  * <dd>Dispose</dd>
       
    35  * </dl>
       
    36  * <p>
       
    37  * IMPORTANT: This class is intended to be subclassed <em>only</em>
       
    38  * within the SWT implementation. However, it has not been marked
       
    39  * final to allow those outside of the SWT development team to implement
       
    40  * patched versions of the class in order to get around specific
       
    41  * limitations in advance of when those limitations can be addressed
       
    42  * by the team.  Any class built using subclassing to access the internals
       
    43  * of this class will likely fail to compile or run between releases and
       
    44  * may be strongly platform specific. Subclassing should not be attempted
       
    45  * without an intimate and detailed understanding of the workings of the
       
    46  * hierarchy. No support is provided for user-written classes which are
       
    47  * implemented as subclasses of this class.
       
    48  * </p>
       
    49  *
       
    50  * @see #checkSubclass
       
    51  */
       
    52 public abstract class Widget {
       
    53     int handle, topHandle;
       
    54     
       
    55     int style, state;
       
    56     Display display;
       
    57     EventTable eventTable;
       
    58     Object data;
       
    59 
       
    60     PackageProxy packageProxy;
       
    61     
       
    62 static final int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
       
    63     int mask = int0 | int1 | int2 | int3 | int4 | int5;
       
    64     if ((style & mask) == 0) style |= int0;
       
    65     if ((style & int0) != 0) style = (style & ~mask) | int0;
       
    66     if ((style & int1) != 0) style = (style & ~mask) | int1;
       
    67     if ((style & int2) != 0) style = (style & ~mask) | int2;
       
    68     if ((style & int3) != 0) style = (style & ~mask) | int3;
       
    69     if ((style & int4) != 0) style = (style & ~mask) | int4;
       
    70     if ((style & int5) != 0) style = (style & ~mask) | int5;
       
    71     return style;
       
    72 }
       
    73 
       
    74 /**
       
    75  * Prevents uninitialized instances from being created outside the package.
       
    76  */
       
    77 Widget () {}
       
    78 
       
    79 /**
       
    80  * Constructs a new instance of this class given its parent
       
    81  * and a style value describing its behavior and appearance.
       
    82  * <p>
       
    83  * The style value is either one of the style constants defined in
       
    84  * class <code>SWT</code> which is applicable to instances of this
       
    85  * class, or must be built by <em>bitwise OR</em>'ing together
       
    86  * (that is, using the <code>int</code> "|" operator) two or more
       
    87  * of those <code>SWT</code> style constants. The class description
       
    88  * lists the style constants that are applicable to the class.
       
    89  * Style bits are also inherited from superclasses.
       
    90  * </p>
       
    91  *
       
    92  * @param parent a widget which will be the parent of the new instance (cannot be null)
       
    93  * @param style the style of widget to construct
       
    94  *
       
    95  * @exception IllegalArgumentException <ul>
       
    96  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
       
    97  *    <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
       
    98  * </ul>
       
    99  * @exception SWTException <ul>
       
   100  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   101  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   102  * </ul>
       
   103  *
       
   104  * @see SWT
       
   105  * @see #checkSubclass
       
   106  * @see #getStyle
       
   107  */
       
   108 public Widget (Widget parent, int style) {
       
   109     this(parent, style, 0, null, false);
       
   110 }
       
   111 
       
   112 /**
       
   113  * <p>
       
   114  * <b>IMPORTANT:</b> This constructor is <em>not</em> part of the SWT
       
   115  * public API. It should never be referenced from application code. 
       
   116  * </p>
       
   117  */
       
   118 protected Widget (Widget parent, int style, int extraStyle, Object packageProxy, 
       
   119         boolean isExtended) {
       
   120     checkSubclass ();
       
   121     checkParent (parent);
       
   122     this.style = style;
       
   123     if(isExtended) state |= WidgetState.IS_EXTENDED;
       
   124     display = parent.display;
       
   125     setPackageProxy(packageProxy);
       
   126 }
       
   127 
       
   128 /**
       
   129  * Adds the listener to the collection of listeners who will
       
   130  * be notified when the widget is disposed. When the widget is
       
   131  * disposed, the listener is notified by sending it the
       
   132  * <code>widgetDisposed()</code> message.
       
   133  *
       
   134  * @param listener the listener which should be notified when the receiver is disposed
       
   135  *
       
   136  * @exception IllegalArgumentException <ul>
       
   137  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   138  * </ul>
       
   139  * @exception SWTException <ul>
       
   140  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   141  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   142  * </ul>
       
   143  *
       
   144  * @see DisposeListener
       
   145  * @see #removeDisposeListener
       
   146  */
       
   147 public void addDisposeListener (DisposeListener listener) {
       
   148     checkWidget ();
       
   149     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   150     TypedListener typedListener = new TypedListener (listener);
       
   151     addListener (SWT.Dispose, typedListener);
       
   152 }
       
   153 
       
   154 /**
       
   155  * Adds the listener to the collection of listeners who will
       
   156  * be notified when an event of the given type occurs. When the
       
   157  * event does occur in the widget, the listener is notified by
       
   158  * sending it the <code>handleEvent()</code> message. The event
       
   159  * type is one of the event constants defined in class <code>SWT</code>.
       
   160  *
       
   161  * @param eventType the type of event to listen for
       
   162  * @param listener the listener which should be notified when the event occurs
       
   163  *
       
   164  * @exception IllegalArgumentException <ul>
       
   165  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   166  * </ul>
       
   167  * @exception SWTException <ul>
       
   168  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   169  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   170  * </ul>
       
   171  *
       
   172  * @see Listener
       
   173  * @see SWT
       
   174  * @see #removeListener(int, Listener)
       
   175  * @see #notifyListeners
       
   176  */
       
   177 public void addListener (int eventType, Listener listener) {
       
   178     checkWidget ();
       
   179     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   180     _addListener (eventType, listener);
       
   181 }
       
   182 
       
   183 void _addListener (int eventType, Listener listener) {
       
   184     if (eventTable == null) eventTable = new EventTable ();
       
   185     eventTable.hook (eventType, listener);
       
   186 }
       
   187 
       
   188 final void addWidget (int handle) {
       
   189     display.addWidget(handle, this);
       
   190 }
       
   191 
       
   192 final void checkOrientation (Widget parent) {
       
   193     style &= ~SWT.MIRRORED;
       
   194     
       
   195     // If orientation explicitly specified then always use that
       
   196     if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
       
   197         if (parent != null) {
       
   198             // Inherit the flag from parent
       
   199             if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
       
   200             if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
       
   201             
       
   202             // If the parent follows the system language direction this widget
       
   203             // does too (unless the user explicitly specified the direction). 
       
   204             state |= (parent.state & WidgetState.FOLLOWS_SYSLANG_DIRECTION);
       
   205         } else {
       
   206             // Use the default determined by a system property. 
       
   207             // Setting RIGHT_TO_LEFT flag triggers the coordinate mirroring. 
       
   208             if(display.defaultOrientation != SWT.LEFT_TO_RIGHT) {
       
   209                 style |= display.defaultOrientation;
       
   210             }
       
   211             
       
   212             // If there's no parent this widget follows the system language 
       
   213             // direction if that's the default behavior configured by a system 
       
   214             // property. 
       
   215             if(display.defaultOrientationIsSysLangDirection)
       
   216                 state |= WidgetState.FOLLOWS_SYSLANG_DIRECTION;
       
   217         }
       
   218     }
       
   219     style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
       
   220 }
       
   221 
       
   222 /*
       
   223  * Throws an exception if the specified widget can not be
       
   224  * used as a parent for the receiver.
       
   225  *
       
   226  * @exception IllegalArgumentException <ul>
       
   227  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
       
   228  *    <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
       
   229  * </ul>
       
   230  * @exception SWTException <ul>
       
   231  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   232  * </ul>
       
   233  */
       
   234 final void checkParent (Widget parent) {
       
   235     if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   236     if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
       
   237     parent.checkWidget ();
       
   238 }
       
   239 
       
   240 /**
       
   241  * Checks that this class can be subclassed.
       
   242  * <p>
       
   243  * The SWT class library is intended to be subclassed
       
   244  * only at specific, controlled points (most notably,
       
   245  * <code>Composite</code> and <code>Canvas</code> when
       
   246  * implementing new widgets). This method enforces this
       
   247  * rule unless it is overridden.
       
   248  * </p><p>
       
   249  * <em>IMPORTANT:</em> By providing an implementation of this
       
   250  * method that allows a subclass of a class which does not
       
   251  * normally allow subclassing to be created, the implementer
       
   252  * agrees to be fully responsible for the fact that any such
       
   253  * subclass will likely fail between SWT releases and will be
       
   254  * strongly platform specific. No support is provided for
       
   255  * user-written classes which are implemented in this fashion.
       
   256  * </p><p>
       
   257  * The ability to subclass outside of the allowed SWT classes
       
   258  * is intended purely to enable those not on the SWT development
       
   259  * team to implement patches in order to get around specific
       
   260  * limitations in advance of when those limitations can be
       
   261  * addressed by the team. Subclassing should not be attempted
       
   262  * without an intimate and detailed understanding of the hierarchy.
       
   263  * </p>
       
   264  *
       
   265  * @exception SWTException <ul>
       
   266  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   267  * </ul>
       
   268  */
       
   269 protected void checkSubclass () {
       
   270     if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
       
   271 }
       
   272 
       
   273 /**
       
   274  * Throws an <code>SWTException</code> if the receiver can not
       
   275  * be accessed by the caller. This may include both checks on
       
   276  * the state of the receiver and more generally on the entire
       
   277  * execution context. This method <em>should</em> be called by
       
   278  * widget implementors to enforce the standard SWT invariants.
       
   279  * <p>
       
   280  * Currently, it is an error to invoke any method (other than
       
   281  * <code>isDisposed()</code>) on a widget that has had its
       
   282  * <code>dispose()</code> method called. It is also an error
       
   283  * to call widget methods from any thread that is different
       
   284  * from the thread that created the widget.
       
   285  * </p><p>
       
   286  * In future releases of SWT, there may be more or fewer error
       
   287  * checks and exceptions may be thrown for different reasons.
       
   288  * </p>
       
   289  *
       
   290  * @exception SWTException <ul>
       
   291  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   292  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   293  * </ul>
       
   294  */
       
   295 protected void checkWidget () {
       
   296     Display display = this.display;
       
   297     if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
       
   298     if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
       
   299     if ((state & WidgetState.DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
       
   300 }
       
   301 
       
   302 /*
       
   303  * _pp means that some widgets want to "override" this method in another 
       
   304  * package. If this is such a widget then there is a 'package proxy' (pp) that 
       
   305  * must be called instead of the implementation in this package. 
       
   306  */ 
       
   307 void createHandle_pp (int index) {
       
   308 }
       
   309 
       
   310 void createWidget (int index) {
       
   311     if(packageProxy != null) {
       
   312         packageProxy.createHandle(index);
       
   313     } else {
       
   314         createHandle_pp (index);
       
   315     }
       
   316     // If subclasses didn't specify topHandle then it's assumed that there's
       
   317     // only one QWidget. I.e. handle is the root widget. 
       
   318     if(topHandle == 0) topHandle = handle;
       
   319     if(packageProxy != null) {
       
   320         packageProxy.hookEvents();
       
   321     } else {
       
   322         hookEvents_pp();
       
   323     }
       
   324     if(packageProxy != null) {
       
   325         packageProxy.register();
       
   326     } else {
       
   327         register_pp();
       
   328     }
       
   329 }
       
   330 
       
   331 void deregister_pp () {
       
   332     if (handle != 0) display.removeWidget (handle);
       
   333 }
       
   334 
       
   335 void destroyWidget () {
       
   336     int _topHandle = topHandle;
       
   337     if(packageProxy != null) {
       
   338         packageProxy.releaseHandle();
       
   339     } else {
       
   340         releaseHandle_pp ();
       
   341     }
       
   342     if (_topHandle != 0 && (state & WidgetState.HANDLE) != 0) {
       
   343         QObjectDeleteWrapper.deleteSafely( _topHandle );
       
   344     }
       
   345 }
       
   346 
       
   347 /**
       
   348  * Disposes of the operating system resources associated with
       
   349  * the receiver and all its descendants. After this method has
       
   350  * been invoked, the receiver and all descendants will answer
       
   351  * <code>true</code> when sent the message <code>isDisposed()</code>.
       
   352  * Any internal connections between the widgets in the tree will
       
   353  * have been removed to facilitate garbage collection.
       
   354  * <p>
       
   355  * NOTE: This method is not called recursively on the descendants
       
   356  * of the receiver. This means that, widget implementers can not
       
   357  * detect when a widget is being disposed of by re-implementing
       
   358  * this method, but should instead listen for the <code>Dispose</code>
       
   359  * event.
       
   360  * </p>
       
   361  *
       
   362  * @exception SWTException <ul>
       
   363  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   364  * </ul>
       
   365  *
       
   366  * @see #addDisposeListener
       
   367  * @see #removeDisposeListener
       
   368  * @see #checkWidget
       
   369  */
       
   370 public void dispose () {
       
   371     if (isDisposed ()) return;
       
   372     if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
       
   373     release (true);
       
   374 }
       
   375 
       
   376 final void error (int code) {
       
   377     SWT.error (code);
       
   378 }
       
   379 
       
   380 final boolean filters (int eventType) {
       
   381     return display.filters (eventType);
       
   382 }
       
   383 
       
   384 static final Command[] getCommands(Control control) {
       
   385     return control.getCommands();
       
   386 }
       
   387 
       
   388 /**
       
   389  * Returns the application defined widget data associated
       
   390  * with the receiver, or null if it has not been set. The
       
   391  * <em>widget data</em> is a single, unnamed field that is
       
   392  * stored with every widget.
       
   393  * <p>
       
   394  * Applications may put arbitrary objects in this field. If
       
   395  * the object stored in the widget data needs to be notified
       
   396  * when the widget is disposed of, it is the application's
       
   397  * responsibility to hook the Dispose event on the widget and
       
   398  * do so.
       
   399  * </p>
       
   400  *
       
   401  * @return the widget data
       
   402  *
       
   403  * @exception SWTException <ul>
       
   404  *    <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
       
   405  *    <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
       
   406  * </ul>
       
   407  *
       
   408  * @see #setData(Object)
       
   409  */
       
   410 public Object getData () {
       
   411     checkWidget();
       
   412     return (state & WidgetState.KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
       
   413 }
       
   414 
       
   415 /**
       
   416  * Returns the application defined property of the receiver
       
   417  * with the specified name, or null if it has not been set.
       
   418  * <p>
       
   419  * Applications may have associated arbitrary objects with the
       
   420  * receiver in this fashion. If the objects stored in the
       
   421  * properties need to be notified when the widget is disposed
       
   422  * of, it is the application's responsibility to hook the
       
   423  * Dispose event on the widget and do so.
       
   424  * </p>
       
   425  *
       
   426  * @param   key the name of the property
       
   427  * @return the value of the property or null if it has not been set
       
   428  *
       
   429  * @exception IllegalArgumentException <ul>
       
   430  *    <li>ERROR_NULL_ARGUMENT - if the key is null</li>
       
   431  * </ul>
       
   432  * @exception SWTException <ul>
       
   433  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   434  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   435  * </ul>
       
   436  *
       
   437  * @see #setData(String, Object)
       
   438  */
       
   439 public Object getData (String key) {
       
   440     checkWidget();
       
   441     if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   442     if ((state & WidgetState.KEYED_DATA) != 0) {
       
   443         Object [] table = (Object []) data;
       
   444         for (int i=1; i<table.length; i+=2) {
       
   445             if (key.equals (table [i])) return table [i+1];
       
   446         }
       
   447     }
       
   448     return null;
       
   449 }
       
   450 
       
   451 /**
       
   452  * Returns the <code>Display</code> that is associated with
       
   453  * the receiver.
       
   454  * <p>
       
   455  * A widget's display is either provided when it is created
       
   456  * (for example, top level <code>Shell</code>s) or is the
       
   457  * same as its parent's display.
       
   458  * </p>
       
   459  *
       
   460  * @return the receiver's display
       
   461  *
       
   462  * @exception SWTException <ul>
       
   463  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   464  * </ul>
       
   465  */
       
   466 public Display getDisplay () {
       
   467     Display display = this.display;
       
   468     if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
       
   469     return display;
       
   470 }
       
   471 
       
   472 String getName () {
       
   473     String string = getClass ().getName ();
       
   474     int index = string.length ();
       
   475     while ((--index > 0) && (string.charAt (index) != '.')) {}
       
   476     return string.substring (index + 1, string.length ());
       
   477 }
       
   478 
       
   479 String getNameText () {
       
   480     return "";
       
   481 }
       
   482 
       
   483 String getPhoneNumber_pp() {
       
   484     if (packageProxy != null) {
       
   485         return packageProxy.getPhoneNumber();
       
   486     }
       
   487     return null;
       
   488 }
       
   489 
       
   490 /**
       
   491  * Returns the receiver's style information.
       
   492  * <p>
       
   493  * Note that the value which is returned by this method <em>may
       
   494  * not match</em> the value which was provided to the constructor
       
   495  * when the receiver was created. This can occur when the underlying
       
   496  * operating system does not support a particular combination of
       
   497  * requested styles. For example, if the platform widget used to
       
   498  * implement a particular SWT widget always has scroll bars, the
       
   499  * result of calling this method would always have the
       
   500  * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
       
   501  * </p>
       
   502  *
       
   503  * @return the style bits
       
   504  *
       
   505  * @exception SWTException <ul>
       
   506  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   507  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   508  * </ul>
       
   509  */
       
   510 public int getStyle () {
       
   511     checkWidget ();
       
   512     return style;
       
   513 }
       
   514 
       
   515 // Experimental support for StyleSheets
       
   516 public String getStyleSheet(){
       
   517     checkWidget();
       
   518     return OS.QWidget_styleSheet(handle);
       
   519 }
       
   520 
       
   521 void hookEvents_pp () {
       
   522 }
       
   523 
       
   524 /*
       
   525  * Returns <code>true</code> if the specified eventType is
       
   526  * hooked, and <code>false</code> otherwise. Implementations
       
   527  * of SWT can avoid creating objects and sending events
       
   528  * when an event happens in the operating system but
       
   529  * there are no listeners hooked for the event.
       
   530  *
       
   531  * @param eventType the event to be checked
       
   532  *
       
   533  * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise
       
   534  *
       
   535  * @see #isListening
       
   536  */
       
   537 final boolean hooks (int eventType) {
       
   538     if (eventTable == null) return false;
       
   539     return eventTable.hooks (eventType);
       
   540 }
       
   541 
       
   542 /**
       
   543  * Returns <code>true</code> if the widget has been disposed,
       
   544  * and <code>false</code> otherwise.
       
   545  * <p>
       
   546  * This method gets the dispose state for the widget.
       
   547  * When a widget has been disposed, it is an error to
       
   548  * invoke any other method using the widget.
       
   549  * </p>
       
   550  *
       
   551  * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
       
   552  */
       
   553 public boolean isDisposed () {
       
   554     return (state & WidgetState.DISPOSED) != 0;
       
   555 }
       
   556 
       
   557 /**
       
   558  * Returns <code>true</code> if there are any listeners
       
   559  * for the specified event type associated with the receiver,
       
   560  * and <code>false</code> otherwise. The event type is one of
       
   561  * the event constants defined in class <code>SWT</code>.
       
   562  *
       
   563  * @param eventType the type of event
       
   564  * @return true if the event is hooked
       
   565  *
       
   566  * @exception SWTException <ul>
       
   567  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   568  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   569  * </ul>
       
   570  *
       
   571  * @see SWT
       
   572  */
       
   573 public boolean isListening (int eventType) {
       
   574     checkWidget ();
       
   575     return hooks (eventType);
       
   576 }
       
   577 
       
   578 /*
       
   579  * Checks if key or character code corresponds to selection key
       
   580  * @param key Key code
       
   581  * @param character Character code
       
   582  * @return true if key/character is a selection key, false otherwise
       
   583  */
       
   584 final boolean isSelectionKey(int key, int character) {
       
   585     if(OS.windowServer == OS.WS_X11) {
       
   586         if (character == ' ') {
       
   587             return true;
       
   588         }
       
   589     } else if (OS.windowServer == OS.WS_SYMBIAN_S60) {
       
   590         if (key == OS.QT_KEY_RETURN || character == -5) {
       
   591             return true;
       
   592         }
       
   593     }
       
   594 
       
   595     return false;
       
   596 }
       
   597 
       
   598 final boolean isValidSubclass() {
       
   599     return Display.isValidClass(getClass());
       
   600 }
       
   601 
       
   602 final boolean isValidThread () {
       
   603     return getDisplay ().isValidThread ();
       
   604 }
       
   605 
       
   606 final Event makeKeyEvent(int key, int modifier, int character, int nativeScanCode) {
       
   607     Event event = new Event ();
       
   608     switch (key) {
       
   609     case OS.QT_KEY_CONTROL: //intentional fall through
       
   610     case OS.QT_KEY_ALT:
       
   611     case OS.QT_KEY_META:
       
   612     case OS.QT_KEY_UP:
       
   613     case OS.QT_KEY_DOWN:
       
   614     case OS.QT_KEY_LEFT:
       
   615     case OS.QT_KEY_RIGHT:
       
   616         event.character = 0;
       
   617         break;
       
   618     case OS.QT_KEY_ENTER : //intentional fall through
       
   619     case OS.QT_KEY_RETURN :     event.character = SWT.CR; break;
       
   620     case OS.QT_KEY_BACKSPACE:   event.character = SWT.BS; break;
       
   621     case OS.QT_KEY_DELETE:      event.character = SWT.DEL; break;
       
   622     case OS.QT_KEY_ESCAPE:      event.character = SWT.ESC; break;
       
   623     case OS.QT_KEY_TAB:         event.character = SWT.TAB; break;
       
   624     case OS.QT_KEY_SHIFT:       event.character = (char)SWT.SHIFT; break;
       
   625     default:
       
   626         event.character = (char)character; break;
       
   627     }
       
   628 
       
   629     boolean keypad = (modifier & OS.QT_KEYPADMODIFIER) != 0 ;
       
   630     event.keyCode = Display.translateKey( key, keypad );
       
   631     if ( event.keyCode == 0 ){// keyCode defaults to unicode value of character.
       
   632         event.keyCode = character;
       
   633     }
       
   634     if( (modifier & OS.QT_NOMODIFIER) == 0  ){
       
   635         event.stateMask = Display.translateModifiers(modifier);
       
   636     }
       
   637     if (keypad) {
       
   638         event.keyLocation = SWT.KEYPAD;
       
   639     }
       
   640     
       
   641     event.keyLocation |= Display.translateKeyLocation(nativeScanCode);
       
   642 
       
   643     return event;
       
   644 }
       
   645 
       
   646 /**
       
   647  * Notifies all of the receiver's listeners for events
       
   648  * of the given type that one such event has occurred by
       
   649  * invoking their <code>handleEvent()</code> method.  The
       
   650  * event type is one of the event constants defined in class
       
   651  * <code>SWT</code>.
       
   652  *
       
   653  * @param eventType the type of event which has occurred
       
   654  * @param event the event data
       
   655  *
       
   656  * @exception SWTException <ul>
       
   657  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   658  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   659  * </ul>
       
   660  *
       
   661  * @see SWT
       
   662  * @see #addListener
       
   663  * @see #removeListener(int, Listener)
       
   664  */
       
   665 public void notifyListeners (int eventType, Event event) {
       
   666     checkWidget();
       
   667     if (event == null) event = new Event ();
       
   668     sendEvent (eventType, event);
       
   669 }
       
   670 
       
   671 final void postEvent (int eventType) {
       
   672     sendEvent (eventType, null, false);
       
   673 }
       
   674 
       
   675 final void postEvent (int eventType, Event event) {
       
   676     sendEvent (eventType, event, false);
       
   677 }
       
   678 
       
   679 /*
       
   680  *  Qt Events
       
   681  */
       
   682 boolean qt_event_close() {
       
   683     return false;
       
   684 }
       
   685 
       
   686 boolean qt_event_contextmenu(int x, int y, int reason) {
       
   687     return false;
       
   688 }
       
   689 
       
   690 boolean qt_event_focusIn( int reason ) {
       
   691     return false;
       
   692 }
       
   693 
       
   694 boolean qt_event_focusOut( int reason ) {
       
   695     return false;
       
   696 }
       
   697 
       
   698 boolean qt_event_keypress_pp( int widgetHandle, int key, int modifier, int character, int nativeScanCode ) {
       
   699     if (((state & WidgetState.NO_KEY_PROPAGATE) != 0) && (widgetHandle != handle)) {
       
   700         return true;
       
   701     }
       
   702     return sendKeyEvent( SWT.KeyDown, key, modifier, character, nativeScanCode );
       
   703 }
       
   704 
       
   705 boolean qt_event_keyrelease_pp( int widgetHandle, int key, int modifier, int character, int nativeScanCode ) {
       
   706     if (((state & WidgetState.NO_KEY_PROPAGATE) != 0) && (widgetHandle != handle)) {
       
   707         return true;
       
   708     }
       
   709     return sendKeyEvent( SWT.KeyUp, key, modifier, character, nativeScanCode );
       
   710 }
       
   711 
       
   712 boolean qt_event_mouseButtonDblClick_pp( int widgetHandle, int button, int x, int y, int state, int buttons ) {
       
   713     return false;
       
   714 }
       
   715 
       
   716 boolean qt_event_mouseButtonPress_pp (int widgetHandle, int button, int x, int y, int state, int buttons) {
       
   717     return false;
       
   718 }
       
   719 
       
   720 boolean qt_event_mouseButtonRelease_pp ( int widgetHandle, int button, int x, int y, int state, int buttons  ) {
       
   721     return false;
       
   722 }
       
   723 
       
   724 boolean qt_event_mouseMove ( int widgetHandle, int button, int x, int y, int state, int buttons  ) {
       
   725     return false;
       
   726 }
       
   727 
       
   728 boolean qt_event_paint( int widgetHandle, int x, int y, int width, int height, int regionHandle ) {
       
   729     return false;
       
   730 }
       
   731 
       
   732 boolean qt_event_shortcut(int key, int modifier, int character) {
       
   733     return false;
       
   734 }
       
   735 
       
   736 boolean qt_event_windowActivate(int widgetHandle) {
       
   737     return false;
       
   738 }
       
   739 
       
   740 boolean qt_event_windowDeactivate(int widgetHandle) {
       
   741     return false;
       
   742 }
       
   743 
       
   744 boolean qt_event_windowStateChange(int widgetHandle, int oldState) {
       
   745     return false;
       
   746 }
       
   747 
       
   748 /*
       
   749  *  Qt Signals
       
   750  */
       
   751 void qt_signal_aboutToHide() {
       
   752 }
       
   753 
       
   754 void qt_signal_aboutToShow() {
       
   755 }
       
   756 
       
   757 void qt_signal_clicked() {
       
   758 }
       
   759 
       
   760 void qt_signal_qapplication_focusChanged_pp(int old, int now) {
       
   761 }
       
   762 
       
   763 void qt_signal_current_tab_changed_pp(int index) {
       
   764 }
       
   765 
       
   766 void qt_signal_dateedit_dateTimeChanged_pp() {
       
   767 }
       
   768 
       
   769 void qt_signal_hover() {
       
   770 }
       
   771 
       
   772 void qt_signal_linkActivated_pp(String link) {
       
   773 }
       
   774 
       
   775 void qt_signal_list_itemActivated_pp(int selectionHandle) {
       
   776 }
       
   777 
       
   778 void qt_signal_list_itemDoubleClicked_pp(int selectionHandle) {
       
   779 }
       
   780 
       
   781 void qt_signal_list_itemSelectionChanged_pp() {
       
   782 }
       
   783 
       
   784 void qt_signal_pressed() {
       
   785 }
       
   786 
       
   787 void qt_signal_released() {
       
   788 }
       
   789 
       
   790 void qt_signal_requestCompleted_pp(int value){
       
   791 }
       
   792 
       
   793 void qt_signal_return_pressed_pp() {
       
   794 }
       
   795 
       
   796 void qt_signal_selectionChanged_pp(int selectionHandle, int deSelectionHandle) {
       
   797 }
       
   798 
       
   799 void qt_signal_slider_action_triggered(int action) {
       
   800 }
       
   801 
       
   802 void qt_signal_slider_changed(int value) {
       
   803 }
       
   804 
       
   805 void qt_signal_slider_released(){
       
   806 }
       
   807 
       
   808 void qt_signal_table_cellActivated(int row, int column) {
       
   809 }
       
   810 
       
   811 void qt_signal_table_cellChanged(int row, int column) {
       
   812 }
       
   813 
       
   814 void qt_signal_table_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) {
       
   815 }
       
   816 
       
   817 void qt_signal_table_itemSelectionChanged() {
       
   818 }
       
   819 
       
   820 void qt_signal_text_changed_pp(String text) {
       
   821 }
       
   822 
       
   823 void qt_signal_text_cursorPositionChanged_pp(int oldPos, int newPos) {
       
   824 }
       
   825 
       
   826 void qt_signal_text_selectionChanged_pp() {
       
   827 }
       
   828 
       
   829 void qt_signal_tray_activated(int arg1) {
       
   830 }
       
   831 
       
   832 void qt_signal_tree_itemActivated(int selectionHandle, int column) {
       
   833 }
       
   834 
       
   835 void qt_signal_tree_itemCollapsed(int selectionHandle) {
       
   836 }
       
   837 
       
   838 void qt_signal_tree_itemExpanded(int selectionHandle) {
       
   839 }
       
   840 
       
   841 void qt_signal_tree_itemSelectionChanged() {
       
   842 }
       
   843 
       
   844 void qt_signal_triggered_pp(boolean checked) {
       
   845 }
       
   846 
       
   847 void qt_signal_abstractitemview_activated_pp(int row, int column) {
       
   848 }
       
   849 
       
   850 /*
       
   851  * QtSwt Events
       
   852  */
       
   853 void qt_swt_event_bufferFlush() {
       
   854 }
       
   855 
       
   856 void qt_swt_event_focusWasGained() {
       
   857 }
       
   858 
       
   859 void qt_swt_event_focusWasLost() {
       
   860 }
       
   861 
       
   862 void qt_swt_event_widgetMoved(int widgetHandle) {
       
   863 }
       
   864 
       
   865 void qt_swt_event_widgetPainted(int widgetHandle, int x, int y, int width, int height, int regionHandle) {
       
   866 }
       
   867 
       
   868 void qt_swt_event_widgetResized_pp(int widgetHandle, int oldWidth, int oldHeight, int width, int height) {
       
   869 }
       
   870 
       
   871 void register_pp () {
       
   872     if (handle == 0) return;
       
   873     if ((state & WidgetState.HANDLE) != 0) display.addWidget (handle, this);
       
   874 }
       
   875 
       
   876 void release (boolean destroy) {
       
   877     if ((state & WidgetState.DISPOSE_SENT) == 0) {
       
   878         state |= WidgetState.DISPOSE_SENT;
       
   879         sendEvent (SWT.Dispose);
       
   880     }
       
   881     if ((state & WidgetState.DISPOSED) == 0) {
       
   882         if(packageProxy != null) {
       
   883             packageProxy.releaseChildren(destroy);
       
   884         } else {
       
   885             releaseChildren_pp(destroy);
       
   886         }
       
   887     }
       
   888     if ((state & WidgetState.RELEASED) == 0) {
       
   889         state |= WidgetState.RELEASED;
       
   890         if (destroy) {
       
   891             if(packageProxy != null) {
       
   892                 packageProxy.releaseParent();
       
   893                 packageProxy.releaseWidget();
       
   894             } else {
       
   895                 releaseParent_pp();
       
   896                 releaseWidget_pp();
       
   897             }
       
   898             destroyWidget ();
       
   899         } else {
       
   900             if(packageProxy != null) {
       
   901                 packageProxy.releaseWidget ();
       
   902                 packageProxy.releaseHandle();
       
   903             } else {
       
   904                 releaseWidget_pp ();
       
   905                 releaseHandle_pp ();
       
   906             }
       
   907         }
       
   908     }
       
   909 }
       
   910 
       
   911 void releaseChildren_pp (boolean destroy) {
       
   912 }
       
   913 
       
   914 void releaseHandle_pp () {
       
   915     handle = topHandle = 0;
       
   916     state |= WidgetState.DISPOSED;
       
   917     display = null;
       
   918 }
       
   919 
       
   920 void releaseParent_pp () {
       
   921     /* Do nothing */
       
   922 }
       
   923 
       
   924 void releaseWidget_pp () {
       
   925     if(packageProxy != null) {
       
   926         packageProxy.deregister();
       
   927     } else {
       
   928         deregister_pp();
       
   929     }
       
   930     eventTable = null;
       
   931     data = null;
       
   932 }
       
   933 
       
   934 /**
       
   935  * Removes the listener from the collection of listeners who will
       
   936  * be notified when the widget is disposed.
       
   937  *
       
   938  * @param listener the listener which should no longer be notified when the receiver is disposed
       
   939  *
       
   940  * @exception IllegalArgumentException <ul>
       
   941  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   942  * </ul>
       
   943  * @exception SWTException <ul>
       
   944  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   945  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   946  * </ul>
       
   947  *
       
   948  * @see DisposeListener
       
   949  * @see #addDisposeListener
       
   950  */
       
   951 public void removeDisposeListener (DisposeListener listener) {
       
   952     checkWidget ();
       
   953     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   954     if (eventTable == null) return;
       
   955     eventTable.unhook (SWT.Dispose, listener);
       
   956 }
       
   957 
       
   958 /**
       
   959  * Removes the listener from the collection of listeners who will
       
   960  * be notified when an event of the given type occurs. The event
       
   961  * type is one of the event constants defined in class <code>SWT</code>.
       
   962  *
       
   963  * @param eventType the type of event to listen for
       
   964  * @param listener the listener which should no longer be notified when the event occurs
       
   965  *
       
   966  * @exception IllegalArgumentException <ul>
       
   967  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   968  * </ul>
       
   969  * @exception SWTException <ul>
       
   970  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   971  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   972  * </ul>
       
   973  *
       
   974  * @see Listener
       
   975  * @see SWT
       
   976  * @see #addListener
       
   977  * @see #notifyListeners
       
   978  */
       
   979 public void removeListener (int eventType, Listener handler) {
       
   980     checkWidget ();
       
   981     if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   982     if (eventTable == null) return;
       
   983     eventTable.unhook (eventType, handler);
       
   984 }
       
   985 
       
   986 /**
       
   987  * Removes the listener from the collection of listeners who will
       
   988  * be notified when an event of the given type occurs.
       
   989  * <p>
       
   990  * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
       
   991  * public API. It is marked public only so that it can be shared
       
   992  * within the packages provided by SWT. It should never be
       
   993  * referenced from application code.
       
   994  * </p>
       
   995  *
       
   996  * @param eventType the type of event to listen for
       
   997  * @param listener the listener which should no longer be notified when the event occurs
       
   998  *
       
   999  * @exception IllegalArgumentException <ul>
       
  1000  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
  1001  * </ul>
       
  1002  * @exception SWTException <ul>
       
  1003  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1004  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
  1005  * </ul>
       
  1006  *
       
  1007  * @see Listener
       
  1008  * @see #addListener
       
  1009  */
       
  1010 protected void removeListener (int eventType, SWTEventListener handler) {
       
  1011     checkWidget ();
       
  1012     if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
       
  1013     if (eventTable == null) return;
       
  1014     eventTable.unhook (eventType, handler);
       
  1015 }
       
  1016 
       
  1017 final Widget removeWidget (int handle) {
       
  1018     return display.removeWidget(handle);
       
  1019 }
       
  1020 
       
  1021 final void sendEvent (Event event) {
       
  1022     Display display = event.display;
       
  1023     if (!display.filterEvent (event)) {
       
  1024         if (eventTable != null) eventTable.sendEvent (event);
       
  1025     }
       
  1026 }
       
  1027 
       
  1028 final void sendEvent (int eventType) {
       
  1029     sendEvent (eventType, null, true);
       
  1030 }
       
  1031 
       
  1032 final void sendEvent (int eventType, Event event) {
       
  1033     sendEvent (eventType, event, true);
       
  1034 }
       
  1035 
       
  1036 final void sendEvent (int eventType, Event event, boolean send) {
       
  1037     if (eventTable == null && !display.filters (eventType)) {
       
  1038         return;
       
  1039     }
       
  1040     if (event == null) event = new Event ();
       
  1041     event.type = eventType;
       
  1042     event.display = display;
       
  1043     event.widget = this;
       
  1044     if (event.time == 0) {
       
  1045         event.time = display.getLastEventTime ();
       
  1046     }
       
  1047     if (send) {
       
  1048         sendEvent (event);
       
  1049     } else {
       
  1050         display.postEvent (event);
       
  1051     }
       
  1052 }
       
  1053 
       
  1054 final boolean sendKeyEvent ( int type, int key, int modifier, int character, int nativeScanCode ) {
       
  1055     Event event = makeKeyEvent(key, modifier, character, nativeScanCode);
       
  1056     sendEvent (type, event);
       
  1057     if (isDisposed () ) return true;
       
  1058     return !event.doit;
       
  1059 }
       
  1060 
       
  1061 /**
       
  1062  * Sets the application defined widget data associated
       
  1063  * with the receiver to be the argument. The <em>widget
       
  1064  * data</em> is a single, unnamed field that is stored
       
  1065  * with every widget.
       
  1066  * <p>
       
  1067  * Applications may put arbitrary objects in this field. If
       
  1068  * the object stored in the widget data needs to be notified
       
  1069  * when the widget is disposed of, it is the application's
       
  1070  * responsibility to hook the Dispose event on the widget and
       
  1071  * do so.
       
  1072  * </p>
       
  1073  *
       
  1074  * @param data the widget data
       
  1075  *
       
  1076  * @exception SWTException <ul>
       
  1077  *    <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
       
  1078  *    <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
       
  1079  * </ul>
       
  1080  *
       
  1081  * @see #getData()
       
  1082  */
       
  1083 public void setData (Object data) {
       
  1084     checkWidget();
       
  1085     if ((state & WidgetState.KEYED_DATA) != 0) {
       
  1086         ((Object []) this.data) [0] = data;
       
  1087     } else {
       
  1088         this.data = data;
       
  1089     }
       
  1090 }
       
  1091 
       
  1092 /**
       
  1093  * Sets the application defined property of the receiver
       
  1094  * with the specified name to the given value.
       
  1095  * <p>
       
  1096  * Applications may associate arbitrary objects with the
       
  1097  * receiver in this fashion. If the objects stored in the
       
  1098  * properties need to be notified when the widget is disposed
       
  1099  * of, it is the application's responsibility to hook the
       
  1100  * Dispose event on the widget and do so.
       
  1101  * </p>
       
  1102  *
       
  1103  * @param key the name of the property
       
  1104  * @param value the new value for the property
       
  1105  *
       
  1106  * @exception IllegalArgumentException <ul>
       
  1107  *    <li>ERROR_NULL_ARGUMENT - if the key is null</li>
       
  1108  * </ul>
       
  1109  * @exception SWTException <ul>
       
  1110  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
  1111  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
  1112  * </ul>
       
  1113  *
       
  1114  * @see #getData(String)
       
  1115  */
       
  1116 public void setData (String key, Object value) {
       
  1117     checkWidget();
       
  1118     if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
       
  1119     
       
  1120     if (key.equals (WidgetConstant.SET_CANVAS_STATE_KEY)) {
       
  1121         boolean enabled = ((Boolean)value).booleanValue();
       
  1122         if (enabled) {
       
  1123             this.state |= WidgetState.CANVAS;
       
  1124         }
       
  1125         else {
       
  1126             this.state &= ~WidgetState.CANVAS;
       
  1127         }
       
  1128         return;
       
  1129     }
       
  1130 
       
  1131     if (key.equals (WidgetConstant.SET_NO_TRAVERSE_STATE_KEY)) {
       
  1132         boolean enabled = ((Boolean)value).booleanValue();
       
  1133         if (enabled) {
       
  1134             this.state |= WidgetState.NO_TRAVERSE;
       
  1135         }
       
  1136         else {
       
  1137             this.state &= ~WidgetState.NO_TRAVERSE;
       
  1138         }
       
  1139         return;
       
  1140     }
       
  1141 
       
  1142     if (key.equals (WidgetConstant.SET_NO_KEY_PROPAGATE_STATE_KEY)) {
       
  1143         boolean enabled = ((Boolean)value).booleanValue();
       
  1144         if (enabled) {
       
  1145             this.state |= WidgetState.NO_KEY_PROPAGATE;
       
  1146         }
       
  1147         else {
       
  1148             this.state &= ~WidgetState.NO_KEY_PROPAGATE;
       
  1149         }
       
  1150         return;
       
  1151     }
       
  1152 
       
  1153     if (key.equals (WidgetConstant.SET_NO_MOUSE_PROPAGATE_STATE_KEY)) {
       
  1154         boolean enabled = ((Boolean)value).booleanValue();
       
  1155         if (enabled) {
       
  1156             this.state |= WidgetState.NO_MOUSE_PROPAGATE;
       
  1157         }
       
  1158         else {
       
  1159             this.state &= ~WidgetState.NO_MOUSE_PROPAGATE;
       
  1160         }
       
  1161         return;
       
  1162     }
       
  1163 
       
  1164     if (key.equals (WidgetConstant.SET_EMBEDDED_SCROLLBARS_STATE_KEY)) {
       
  1165         boolean enabled = ((Boolean)value).booleanValue();
       
  1166         if (enabled) {
       
  1167             this.state |= WidgetState.EMBEDDED_SCROLLBARS;
       
  1168         }
       
  1169         else {
       
  1170             this.state &= ~WidgetState.EMBEDDED_SCROLLBARS;
       
  1171         }
       
  1172         return;
       
  1173     }
       
  1174 
       
  1175     if(key.equals(WidgetConstant.CSS_ID)){
       
  1176     	OS.QObject_setObjectName(handle,(String)value);
       
  1177     	// Do not return here and let Widget store the key
       
  1178     	// value.
       
  1179     }
       
  1180     
       
  1181     int index = 1;
       
  1182     Object [] table = null;
       
  1183     if ((state & WidgetState.KEYED_DATA) != 0) {
       
  1184         table = (Object []) data;
       
  1185         while (index < table.length) {
       
  1186             if (key.equals (table [index])) break;
       
  1187             index += 2;
       
  1188         }
       
  1189     }
       
  1190     if (value != null) {
       
  1191         if ((state & WidgetState.KEYED_DATA) != 0) {
       
  1192             if (index == table.length) {
       
  1193                 Object [] newTable = new Object [table.length + 2];
       
  1194                 System.arraycopy (table, 0, newTable, 0, table.length);
       
  1195                 data = table = newTable;
       
  1196             }
       
  1197         } else {
       
  1198             table = new Object [3];
       
  1199             table [0] = data;
       
  1200             data = table;
       
  1201             state |= WidgetState.KEYED_DATA;
       
  1202         }
       
  1203         table [index] = key;
       
  1204         table [index + 1] = value;
       
  1205     } else {
       
  1206         if ((state & WidgetState.KEYED_DATA) != 0) {
       
  1207             if (index != table.length) {
       
  1208                 int length = table.length - 2;
       
  1209                 if (length == 1) {
       
  1210                     data = table [0];
       
  1211                     state &= ~WidgetState.KEYED_DATA;
       
  1212                 } else {
       
  1213                     Object [] newTable = new Object [length];
       
  1214                     System.arraycopy (table, 0, newTable, 0, index);
       
  1215                     System.arraycopy (table, index + 2, newTable, index, length - index);
       
  1216                     data = newTable;
       
  1217                 }
       
  1218             }
       
  1219         }
       
  1220     }
       
  1221 }
       
  1222 
       
  1223 final void setPackageProxy(Object packageProxy) {
       
  1224     // If the subclass is in another package then it provides a proxy object 
       
  1225     // which implements the methods that "override" the package private
       
  1226     // implementations from this package. We must call the proxy object
       
  1227     // implementations if they are provided. 
       
  1228     if(packageProxy != null) {
       
  1229         PackageProxy proxyObject = (PackageProxy)packageProxy; 
       
  1230         proxyObject.setWidget(this);
       
  1231         this.packageProxy = proxyObject;
       
  1232     }
       
  1233 }
       
  1234 
       
  1235 /**
       
  1236  * Returns a string containing a concise, human-readable
       
  1237  * description of the receiver.
       
  1238  *
       
  1239  * @return a string representation of the receiver
       
  1240  */
       
  1241 public String toString () {
       
  1242     String string = "*Disposed*";
       
  1243     if (!isDisposed ()) {
       
  1244         string = "*Wrong Thread*";
       
  1245         if (isValidThread ()) string = getNameText ();
       
  1246     }
       
  1247     return getName () + " {" + string + "}";
       
  1248 }
       
  1249 
       
  1250 }