javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MenuItem.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.*;
       
    17 import org.eclipse.swt.graphics.*;
       
    18 import org.eclipse.swt.internal.qt.OS;
       
    19 import org.eclipse.swt.internal.qt.WidgetState;
       
    20 import org.eclipse.swt.events.*;
       
    21 
       
    22 /**
       
    23  * Instances of this class represent a selectable user interface object
       
    24  * that issues notification when pressed and released. 
       
    25  * <dl>
       
    26  * <dt><b>Styles:</b></dt>
       
    27  * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
       
    28  * <dt><b>Events:</b></dt>
       
    29  * <dd>Arm, Selection</dd>
       
    30  * </dl>
       
    31  * <p>
       
    32  * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
       
    33  * may be specified.
       
    34  * </p><p>
       
    35  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
       
    36  * </p>
       
    37  */
       
    38 public class MenuItem extends Item {
       
    39     Menu parent, menu;
       
    40     int accelerator;
       
    41     
       
    42 /**
       
    43  * Constructs a new instance of this class given its parent
       
    44  * (which must be a <code>Menu</code>) and a style value
       
    45  * describing its behavior and appearance. The item is added
       
    46  * to the end of the items maintained by its parent.
       
    47  * <p>
       
    48  * The style value is either one of the style constants defined in
       
    49  * class <code>SWT</code> which is applicable to instances of this
       
    50  * class, or must be built by <em>bitwise OR</em>'ing together 
       
    51  * (that is, using the <code>int</code> "|" operator) two or more
       
    52  * of those <code>SWT</code> style constants. The class description
       
    53  * lists the style constants that are applicable to the class.
       
    54  * Style bits are also inherited from superclasses.
       
    55  * </p>
       
    56  *
       
    57  * @param parent a menu control which will be the parent of the new instance (cannot be null)
       
    58  * @param style the style of control to construct
       
    59  *
       
    60  * @exception IllegalArgumentException <ul>
       
    61  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
       
    62  * </ul>
       
    63  * @exception SWTException <ul>
       
    64  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
    65  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
    66  * </ul>
       
    67  *
       
    68  * @see SWT#CHECK
       
    69  * @see SWT#CASCADE
       
    70  * @see SWT#PUSH
       
    71  * @see SWT#RADIO
       
    72  * @see SWT#SEPARATOR
       
    73  * @see Widget#checkSubclass
       
    74  * @see Widget#getStyle
       
    75  */
       
    76 public MenuItem (Menu parent, int style) {
       
    77     super (parent, checkStyle (style));
       
    78     this.parent = parent;
       
    79     createWidget (parent.getItemCount ());
       
    80     parent.menuItemAdded();
       
    81 }
       
    82 
       
    83 /**
       
    84  * Constructs a new instance of this class given its parent
       
    85  * (which must be a <code>Menu</code>), a style value
       
    86  * describing its behavior and appearance, and the index
       
    87  * at which to place it in the items maintained by its parent.
       
    88  * <p>
       
    89  * The style value is either one of the style constants defined in
       
    90  * class <code>SWT</code> which is applicable to instances of this
       
    91  * class, or must be built by <em>bitwise OR</em>'ing together 
       
    92  * (that is, using the <code>int</code> "|" operator) two or more
       
    93  * of those <code>SWT</code> style constants. The class description
       
    94  * lists the style constants that are applicable to the class.
       
    95  * Style bits are also inherited from superclasses.
       
    96  * </p>
       
    97  *
       
    98  * @param parent a menu control which will be the parent of the new instance (cannot be null)
       
    99  * @param style the style of control to construct
       
   100  * @param index the zero-relative index to store the receiver in its parent
       
   101  *
       
   102  * @exception IllegalArgumentException <ul>
       
   103  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
       
   104  *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
       
   105  * </ul>
       
   106  * @exception SWTException <ul>
       
   107  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
       
   108  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
       
   109  * </ul>
       
   110  *
       
   111  * @see SWT#CHECK
       
   112  * @see SWT#CASCADE
       
   113  * @see SWT#PUSH
       
   114  * @see SWT#RADIO
       
   115  * @see SWT#SEPARATOR
       
   116  * @see Widget#checkSubclass
       
   117  * @see Widget#getStyle
       
   118  */
       
   119 public MenuItem (Menu parent, int style, int index) {
       
   120     super (parent, checkStyle (style));
       
   121     this.parent = parent;
       
   122     int count = parent.getItemCount ();
       
   123     if (!(0 <= index && index <= count)) {
       
   124         error (SWT.ERROR_INVALID_RANGE);
       
   125     }
       
   126     createWidget (index);
       
   127     parent.menuItemAdded();
       
   128 }
       
   129 
       
   130 /**
       
   131  * Adds the listener to the collection of listeners who will
       
   132  * be notified when the menu item is selected by the user, by sending
       
   133  * it one of the messages defined in the <code>SelectionListener</code>
       
   134  * interface.
       
   135  * <p>
       
   136  * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
       
   137  * <code>widgetDefaultSelected</code> is not called.
       
   138  * </p>
       
   139  *
       
   140  * @param listener the listener which should be notified when the menu item is selected by the user
       
   141  *
       
   142  * @exception IllegalArgumentException <ul>
       
   143  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   144  * </ul>
       
   145  * @exception SWTException <ul>
       
   146  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   147  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   148  * </ul>
       
   149  *
       
   150  * @see SelectionListener
       
   151  * @see #removeSelectionListener
       
   152  * @see SelectionEvent
       
   153  */
       
   154 public void addSelectionListener (SelectionListener listener) {
       
   155     checkWidget();
       
   156     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   157     TypedListener typedListener = new TypedListener(listener);
       
   158     addListener (SWT.Selection,typedListener);
       
   159     addListener (SWT.DefaultSelection,typedListener);
       
   160 }
       
   161 
       
   162 static int checkStyle (int style) {
       
   163     return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
       
   164 }
       
   165 
       
   166 protected void checkSubclass () {
       
   167     if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
       
   168 }
       
   169 
       
   170 void createHandle_pp (int index) {
       
   171     topHandle = handle = OS.QAction_new( parent.handle );
       
   172     state |= WidgetState.HANDLE;
       
   173     
       
   174     if ((parent.style & SWT.BAR) != 0){
       
   175         OS.QMenuBar_addAction( parent.handle, handle );
       
   176     }
       
   177     else{
       
   178         int itemCount = parent.getItemCount();
       
   179         if( itemCount > 0 && index < itemCount ){
       
   180             int beforeHandle = parent.getItems()[index].handle;
       
   181             OS.QWidget_insertAction(parent.handle, beforeHandle, handle );
       
   182         }
       
   183         else{
       
   184             OS.QMenu_addAction(parent.handle, handle );
       
   185         }
       
   186     }
       
   187     int bits = SWT.CHECK | SWT.RADIO | SWT.PUSH | SWT.SEPARATOR ;
       
   188     switch (style & bits) {
       
   189         case SWT.SEPARATOR:
       
   190             OS.QAction_setSeparator( handle, true );
       
   191             break;
       
   192         case SWT.RADIO:
       
   193             if (parent.actionGroupHandle == 0){
       
   194                 parent.actionGroupHandle = OS.QActionGroup_new( parent.handle );
       
   195                 if ((parent.style & SWT.NO_RADIO_GROUP ) != 0 ){
       
   196                     OS.QActionGroup_setExclusive(parent.actionGroupHandle, false);
       
   197                 }
       
   198             }
       
   199             OS.QAction_setCheckable( handle, true );
       
   200             OS.QActionGroup_addAction( parent.actionGroupHandle, handle );
       
   201             break;
       
   202         case SWT.CHECK:
       
   203             OS.QAction_setCheckable( handle, true );
       
   204             break;
       
   205         case SWT.PUSH:
       
   206         default:
       
   207             break;
       
   208     }
       
   209 }
       
   210 
       
   211 void fixMenus (Decorations newParent) {
       
   212 //Commented for now. Needed for the reparenting of the Controls
       
   213 //  if (menu != null) menu.fixMenus (newParent);
       
   214 }
       
   215 
       
   216 /**
       
   217  * Returns the widget accelerator.  An accelerator is the bit-wise
       
   218  * OR of zero or more modifier masks and a key. Examples:
       
   219  * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
       
   220  * The default value is zero, indicating that the menu item does
       
   221  * not have an accelerator.
       
   222  *
       
   223  * @return the accelerator or 0
       
   224  *
       
   225  * </ul>
       
   226  * @exception SWTException <ul>
       
   227  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   228  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   229  * </ul>
       
   230  */
       
   231 public int getAccelerator () {
       
   232     checkWidget();
       
   233     return accelerator;
       
   234 }
       
   235 
       
   236 /**
       
   237  * Returns <code>true</code> if the receiver is enabled, and
       
   238  * <code>false</code> otherwise. A disabled menu item is typically
       
   239  * not selectable from the user interface and draws with an
       
   240  * inactive or "grayed" look.
       
   241  *
       
   242  * @return the receiver's enabled state
       
   243  *
       
   244  * @exception SWTException <ul>
       
   245  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   246  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   247  * </ul>
       
   248  * 
       
   249  * @see #isEnabled
       
   250  */
       
   251 public boolean getEnabled () {
       
   252     checkWidget();
       
   253     return OS.QAction_isEnabled( handle );
       
   254 }
       
   255 
       
   256 /**
       
   257  * Returns the receiver's cascade menu if it has one or null
       
   258  * if it does not. Only <code>CASCADE</code> menu items can have
       
   259  * a pull down menu. The sequence of key strokes, button presses 
       
   260  * and/or button releases that are used to request a pull down
       
   261  * menu is platform specific.
       
   262  *
       
   263  * @return the receiver's menu
       
   264  *
       
   265  * @exception SWTException <ul>
       
   266  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   267  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   268  * </ul>
       
   269  */
       
   270 public Menu getMenu () {
       
   271     checkWidget();
       
   272     return menu;
       
   273 }
       
   274 
       
   275 String getNameText () {
       
   276     if ((style & SWT.SEPARATOR) != 0) return "|";
       
   277     return super.getNameText ();
       
   278 }
       
   279 
       
   280 /**
       
   281  * Returns the receiver's parent, which must be a <code>Menu</code>.
       
   282  *
       
   283  * @return the receiver's parent
       
   284  *
       
   285  * @exception SWTException <ul>
       
   286  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   287  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   288  * </ul>
       
   289  */
       
   290 public Menu getParent () {
       
   291     checkWidget();
       
   292     return parent;
       
   293 }
       
   294 
       
   295 /**
       
   296  * Returns <code>true</code> if the receiver is selected,
       
   297  * and false otherwise.
       
   298  * <p>
       
   299  * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
       
   300  * it is selected when it is checked.
       
   301  *
       
   302  * @return the selection state
       
   303  *
       
   304  * @exception SWTException <ul>
       
   305  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   306  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   307  * </ul>
       
   308  */
       
   309 public boolean getSelection () {
       
   310     checkWidget();
       
   311     if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
       
   312     return OS.QAction_isChecked( handle );
       
   313 }
       
   314 
       
   315 void qt_signal_triggered_pp( boolean checked ) {
       
   316     Event event = new Event ();
       
   317     sendEvent (SWT.Selection, event);
       
   318 }
       
   319 
       
   320 void qt_signal_hover() {
       
   321     sendEvent (SWT.Arm);
       
   322 }
       
   323 
       
   324 void hookEvents_pp () {
       
   325     super.hookEvents_pp ();
       
   326     if ((style & SWT.CASCADE) == 0 ){
       
   327         int triggeredProxy = OS.SignalHandler_new(handle, OS.QSIGNAL_TRIGGERED);
       
   328         OS.QObject_connectOrThrow(handle, "triggered(bool)", triggeredProxy, "widgetSignal(bool)", OS.QT_AUTOCONNECTION);
       
   329     }
       
   330     int hoveredProxy = OS.SignalHandler_new(handle, OS.QSIGNAL_HOVER );
       
   331     OS.QObject_connectOrThrow(handle, "hovered()", hoveredProxy, "widgetSignal()", OS.QT_AUTOCONNECTION);
       
   332 }
       
   333 
       
   334 /**
       
   335  * Returns <code>true</code> if the receiver is enabled and all
       
   336  * of the receiver's ancestors are enabled, and <code>false</code>
       
   337  * otherwise. A disabled menu item is typically not selectable from the
       
   338  * user interface and draws with an inactive or "grayed" look.
       
   339  *
       
   340  * @return the receiver's enabled state
       
   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  * @see #getEnabled
       
   348  */
       
   349 public boolean isEnabled () {
       
   350     return getEnabled () && parent.isEnabled ();
       
   351 }
       
   352 
       
   353 void releaseChildren_pp (boolean destroy) {
       
   354     if (menu != null) {
       
   355         menu.release (false);
       
   356         menu = null;
       
   357     }
       
   358     super.releaseChildren_pp (destroy);
       
   359 }
       
   360 
       
   361 void releaseParent_pp () {
       
   362     super.releaseParent_pp ();
       
   363     if (menu != null) {
       
   364         menu.dispose ();
       
   365     }
       
   366     menu = null;
       
   367     parent.menuItemRemoved();
       
   368 }
       
   369 
       
   370 void releaseWidget_pp () {
       
   371     if( (style & SWT.RADIO) != 0 ){
       
   372         if (parent.actionGroupHandle != 0){
       
   373             OS.QActionGroup_removeAction(parent.actionGroupHandle, handle);
       
   374         }
       
   375     }
       
   376     OS.QWidget_removeAction( parent.handle, handle );
       
   377     super.releaseWidget_pp ();
       
   378     accelerator = 0;
       
   379     parent = null;
       
   380 }
       
   381 
       
   382 /**
       
   383  * Removes the listener from the collection of listeners who will
       
   384  * be notified when the control is selected by the user.
       
   385  *
       
   386  * @param listener the listener which should no longer be notified
       
   387  *
       
   388  * @exception IllegalArgumentException <ul>
       
   389  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
       
   390  * </ul>
       
   391  * @exception SWTException <ul>
       
   392  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   393  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   394  * </ul>
       
   395  *
       
   396  * @see SelectionListener
       
   397  * @see #addSelectionListener
       
   398  */
       
   399 public void removeSelectionListener (SelectionListener listener) {
       
   400     checkWidget();
       
   401     if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   402     if (eventTable == null) return;
       
   403     eventTable.unhook (SWT.Selection, listener);
       
   404     eventTable.unhook (SWT.DefaultSelection,listener);  
       
   405 }
       
   406 
       
   407 /**
       
   408  * Sets the widget accelerator.  An accelerator is the bit-wise
       
   409  * OR of zero or more modifier masks and a key. Examples:
       
   410  * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
       
   411  * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
       
   412  * The default value is zero, indicating that the menu item does
       
   413  * not have an accelerator.
       
   414  *
       
   415  * @param accelerator an integer that is the bit-wise OR of masks and a key
       
   416  *
       
   417  * </ul>
       
   418  * @exception SWTException <ul>
       
   419  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   420  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   421  * </ul>
       
   422  */
       
   423 public void setAccelerator (int accelerator) {
       
   424     checkWidget();
       
   425     if (this.accelerator == accelerator) return;
       
   426     int mask = 0;
       
   427     if ((accelerator & SWT.ALT) != 0) mask |= OS.QT_ALTMODIFIER;
       
   428     if ((accelerator & SWT.SHIFT) != 0) mask |= OS.QT_SHIFTMODIFIER;
       
   429     if ((accelerator & SWT.CONTROL) != 0) mask |= OS.QT_CONTROLMODIFIER;
       
   430     int keysym = accelerator & SWT.KEY_MASK;
       
   431     int newKey = Display.untranslateKey (keysym);
       
   432     if (newKey != 0) {
       
   433         keysym = newKey;
       
   434     }
       
   435     int keySequenceHandle = OS.QKeySequence_new( mask + keysym );
       
   436     OS.QAction_setShortcut( handle, keySequenceHandle );
       
   437     this.accelerator = accelerator;
       
   438     OS.QKeySequence_delete( keySequenceHandle );
       
   439 }
       
   440 
       
   441 /**
       
   442  * Enables the receiver if the argument is <code>true</code>,
       
   443  * and disables it otherwise. A disabled menu item is typically
       
   444  * not selectable from the user interface and draws with an
       
   445  * inactive or "grayed" look.
       
   446  *
       
   447  * @param enabled the new enabled state
       
   448  *
       
   449  * @exception SWTException <ul>
       
   450  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   451  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   452  * </ul>
       
   453  */
       
   454 public void setEnabled (boolean enabled) {
       
   455     checkWidget();
       
   456     OS.QAction_setEnabled(handle, enabled);
       
   457 
       
   458 }
       
   459 
       
   460 /**
       
   461  * Sets the image the receiver will display to the argument.
       
   462  * <p>
       
   463  * Note: This operation is a hint and is not supported on
       
   464  * platforms that do not have this concept (for example, Windows NT).
       
   465  * </p>
       
   466  *
       
   467  * @param image the image to display
       
   468  *
       
   469  * @exception SWTException <ul>
       
   470  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   471  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   472  * </ul>
       
   473  */
       
   474 public void setImage (Image image) {
       
   475     checkWidget();
       
   476     if ((style & SWT.SEPARATOR) != 0) return;
       
   477     super.setImage (image);
       
   478     if (image != null ) {
       
   479         OS.QAction_setIcon(handle, Internal_GfxPackageSupport.getIconHandle(image));
       
   480     } else {
       
   481         OS.QAction_setIcon(handle, Internal_GfxPackageSupport.getNullIconHandle());
       
   482     }
       
   483 }
       
   484 
       
   485 /**
       
   486  * Sets the receiver's pull down menu to the argument.
       
   487  * Only <code>CASCADE</code> menu items can have a
       
   488  * pull down menu. The sequence of key strokes, button presses
       
   489  * and/or button releases that are used to request a pull down
       
   490  * menu is platform specific.
       
   491  * <p>
       
   492  * Note: Disposing of a menu item that has a pull down menu
       
   493  * will dispose of the menu.  To avoid this behavior, set the
       
   494  * menu to null before the menu item is disposed.
       
   495  * </p>
       
   496  *
       
   497  * @param menu the new pull down menu
       
   498  *
       
   499  * @exception IllegalArgumentException <ul>
       
   500  *    <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
       
   501  *    <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
       
   502  *    <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
       
   503  *    <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
       
   504  * </ul>
       
   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 void setMenu (Menu menu) {
       
   511     checkWidget ();
       
   512 
       
   513     /* Check to make sure the new menu is valid */
       
   514     if ((style & SWT.CASCADE) == 0) {
       
   515         error (SWT.ERROR_MENUITEM_NOT_CASCADE);
       
   516     }
       
   517     int menuHandle = 0;
       
   518     if (menu != null) {
       
   519         if ((menu.style & SWT.DROP_DOWN) == 0) {
       
   520             error (SWT.ERROR_MENU_NOT_DROP_DOWN);
       
   521         }
       
   522         if (menu.parent != parent.parent) {
       
   523             error (SWT.ERROR_INVALID_PARENT);
       
   524         }
       
   525         menuHandle = menu.handle;
       
   526     }
       
   527     /* Assign the new menu */
       
   528     Menu oldMenu = this.menu;
       
   529     if (oldMenu == menu) return;
       
   530     if (oldMenu != null) oldMenu.cascade = null;
       
   531     OS.QAction_setMenu( handle, menuHandle );
       
   532     this.menu = menu;
       
   533     if( this.menu != null )this.menu.cascade = this;
       
   534 }
       
   535 
       
   536 
       
   537 /**
       
   538  * Sets the selection state of the receiver.
       
   539  * <p>
       
   540  * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
       
   541  * it is selected when it is checked.
       
   542  *
       
   543  * @param selected the new selection state
       
   544  *
       
   545  * @exception SWTException <ul>
       
   546  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   547  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   548  * </ul>
       
   549  */
       
   550 public void setSelection (boolean selected) {
       
   551     checkWidget();
       
   552     if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
       
   553     OS.QAction_setChecked( handle, selected );
       
   554 }
       
   555 
       
   556 /**
       
   557  * Sets the receiver's text. The string may include
       
   558  * the mnemonic character and accelerator text.
       
   559  * <p>
       
   560  * Mnemonics are indicated by an '&amp;' that causes the next
       
   561  * character to be the mnemonic.  When the user presses a
       
   562  * key sequence that matches the mnemonic, a selection
       
   563  * event occurs. On most platforms, the mnemonic appears
       
   564  * underlined but may be emphasised in a platform specific
       
   565  * manner.  The mnemonic indicator character '&amp;' can be
       
   566  * escaped by doubling it in the string, causing a single
       
   567  * '&amp;' to be displayed.
       
   568  * </p>
       
   569  * <p>
       
   570  * Accelerator text is indicated by the '\t' character.
       
   571  * On platforms that support accelerator text, the text
       
   572  * that follows the '\t' character is displayed to the user,
       
   573  * typically indicating the key stroke that will cause
       
   574  * the item to become selected.  On most platforms, the
       
   575  * accelerator text appears right aligned in the menu.
       
   576  * Setting the accelerator text does not install the
       
   577  * accelerator key sequence. The accelerator key sequence
       
   578  * is installed using #setAccelerator.
       
   579  * </p>
       
   580  * 
       
   581  * @param string the new text
       
   582  *
       
   583  * @exception IllegalArgumentException <ul>
       
   584  *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
       
   585  * </ul>
       
   586  * @exception SWTException <ul>
       
   587  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
       
   588  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
       
   589  * </ul>
       
   590  * 
       
   591  * @see #setAccelerator
       
   592  */
       
   593 public void setText (String string) {
       
   594     checkWidget();
       
   595     if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
       
   596     if ((style & SWT.SEPARATOR) != 0) return;
       
   597     if (text.equals (string)) return;
       
   598     OS.QAction_setText(handle, string);
       
   599     text = string;
       
   600 }
       
   601 
       
   602 }