FILE COMPARISON
Produced: 2/18/2011 1:30:45 AM
   
Mode:  All Lines  
Left base folder: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\eSWT-1.2.orig  
Right base folder: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\eSWT-1.2.today  
   
File: org.eclipse.ercp.swt.core.win\src-platform\org\eclipse\swt\widgets\MenuItem.java  
1 /******************************************************************************* = 1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.   2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials   3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0   4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at   5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html   6 * http://www.eclipse.org/legal/epl-v10.html
7 *   7 *
8 * Contributors:   8 * Contributors:
9 *     IBM Corporation - initial API and implementation   9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/   10 *******************************************************************************/
    <> 11  
      12 /*******************************************************************************
      13 * Additions/modifications to this source file by Oracle America, Inc. 2011
      14 *******************************************************************************/
      15  
11 package org.eclipse.swt.widgets; = 16 package org.eclipse.swt.widgets;
12     17  
13     18  
14 import org.eclipse.swt.*;   19 import org.eclipse.swt.*;
15 import org.eclipse.swt.events.*;   20 import org.eclipse.swt.events.*;
16 import org.eclipse.swt.graphics.Image;   21 import org.eclipse.swt.graphics.Image;
17     22  
18 import com.ibm.ugl.eswt.OS;   23 import com.ibm.ugl.eswt.OS;
19     24  
20 /**   25 /**
21 * Instances of this class represent a selectable user interface object   26 * Instances of this class represent a selectable user interface object
22 * that issues notification when pressed and released.   27 * that issues notification when pressed and released.
23 * <dl>   28 * <dl>
24 * <dt><b>Styles:</b></dt>   29 * <dt><b>Styles:</b></dt>
25 * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>   30 * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
26 * <dt><b>Events:</b></dt>   31 * <dt><b>Events:</b></dt>
27 * <dd>Selection</dd>   32 * <dd>Selection</dd>
28 * </dl>   33 * </dl>
29 * <p>   34 * <p>
30 * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR   35 * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
31 * may be specified.   36 * may be specified.
32 * </p><p>   37 * </p><p>
33 * IMPORTANT: This class is <em>not</em> intended to be subclassed.   38 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
34 * </p>   39 * </p>
35 */   40 */
36 public class MenuItem extends Item {   41 public class MenuItem extends Item {
37         Menu parent, menu;   42         Menu parent, menu;
38         int accelerator;   43         int accelerator;
39         boolean enabled=true;   44         boolean enabled=true;
40         boolean selected=false;   45         boolean selected=false;
    -+ 46         boolean disableAutoSelection=false;
41         = 47        
42 /**   48 /**
43 * Constructs a new instance of this class given its parent   49 * Constructs a new instance of this class given its parent
44 * (which must be a <code>Menu</code>) and a style value   50 * (which must be a <code>Menu</code>) and a style value
45 * describing its behavior and appearance. The item is added   51 * describing its behavior and appearance. The item is added
46 * to the end of the items maintained by its parent.   52 * to the end of the items maintained by its parent.
47 * <p>   53 * <p>
48 * The style value is either one of the style constants defined in   54 * The style value is either one of the style constants defined in
49 * class <code>SWT</code> which is applicable to instances of this   55 * class <code>SWT</code> which is applicable to instances of this
50 * class, or must be built by <em>bitwise OR</em>'ing together   56 * class, or must be built by <em>bitwise OR</em>'ing together
51 * (that is, using the <code>int</code> "|" operator) two or more   57 * (that is, using the <code>int</code> "|" operator) two or more
52 * of those <code>SWT</code> style constants. The class description   58 * of those <code>SWT</code> style constants. The class description
53 * lists the style constants that are applicable to the class.   59 * lists the style constants that are applicable to the class.
54 * Style bits are also inherited from superclasses.   60 * Style bits are also inherited from superclasses.
55 * </p>   61 * </p>
56 *   62 *
57 * @param parent a menu control which will be the parent of the new instance (cannot be null)   63 * @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   64 * @param style the style of control to construct
59 *   65 *
60 * @exception IllegalArgumentException <ul>   66 * @exception IllegalArgumentException <ul>
61 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>   67 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
62 * </ul>   68 * </ul>
63 * @exception SWTException <ul>   69 * @exception SWTException <ul>
64 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>   70 *    <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>   71 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
66 * </ul>   72 * </ul>
67 *   73 *
68 * @see SWT#CHECK   74 * @see SWT#CHECK
69 * @see SWT#CASCADE   75 * @see SWT#CASCADE
70 * @see SWT#PUSH   76 * @see SWT#PUSH
71 * @see SWT#RADIO   77 * @see SWT#RADIO
72 * @see SWT#SEPARATOR   78 * @see SWT#SEPARATOR
73 * @see Widget#checkSubclass   79 * @see Widget#checkSubclass
74 * @see Widget#getStyle   80 * @see Widget#getStyle
75 */   81 */
76 public MenuItem(Menu parent, int style) {   82 public MenuItem(Menu parent, int style) {
77         super (parent, checkStyle (style));   83         super (parent, checkStyle (style));
78         this.parent = parent;   84         this.parent = parent;
79         createWidget(parent.getItemCount());   85         createWidget(parent.getItemCount());
80 }   86 }
81 /**   87 /**
82 * Constructs a new instance of this class given its parent   88 * Constructs a new instance of this class given its parent
83 * (which must be a <code>Menu</code>), a style value   89 * (which must be a <code>Menu</code>), a style value
84 * describing its behavior and appearance, and the index   90 * describing its behavior and appearance, and the index
85 * at which to place it in the items maintained by its parent.   91 * at which to place it in the items maintained by its parent.
86 * <p>   92 * <p>
87 * The style value is either one of the style constants defined in   93 * The style value is either one of the style constants defined in
88 * class <code>SWT</code> which is applicable to instances of this   94 * class <code>SWT</code> which is applicable to instances of this
89 * class, or must be built by <em>bitwise OR</em>'ing together   95 * class, or must be built by <em>bitwise OR</em>'ing together
90 * (that is, using the <code>int</code> "|" operator) two or more   96 * (that is, using the <code>int</code> "|" operator) two or more
91 * of those <code>SWT</code> style constants. The class description   97 * of those <code>SWT</code> style constants. The class description
92 * lists the style constants that are applicable to the class.   98 * lists the style constants that are applicable to the class.
93 * Style bits are also inherited from superclasses.   99 * Style bits are also inherited from superclasses.
94 * </p>   100 * </p>
95 *   101 *
96 * @param parent a menu control which will be the parent of the new instance (cannot be null)   102 * @param parent a menu control which will be the parent of the new instance (cannot be null)
97 * @param style the style of control to construct   103 * @param style the style of control to construct
98 * @param index the index to store the receiver in its parent   104 * @param index the index to store the receiver in its parent
99 *   105 *
100 * @exception IllegalArgumentException <ul>   106 * @exception IllegalArgumentException <ul>
101 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>   107 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
102 * </ul>   108 * </ul>
103 * @exception SWTException <ul>   109 * @exception SWTException <ul>
104 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>   110 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
105 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>   111 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
106 * </ul>   112 * </ul>
107 *   113 *
108 * @see SWT#CHECK   114 * @see SWT#CHECK
109 * @see SWT#CASCADE   115 * @see SWT#CASCADE
110 * @see SWT#PUSH   116 * @see SWT#PUSH
111 * @see SWT#RADIO   117 * @see SWT#RADIO
112 * @see SWT#SEPARATOR   118 * @see SWT#SEPARATOR
113 * @see Widget#checkSubclass   119 * @see Widget#checkSubclass
114 * @see Widget#getStyle   120 * @see Widget#getStyle
115 */   121 */
116 public MenuItem(Menu parent, int style, int index) {   122 public MenuItem(Menu parent, int style, int index) {
117         super(parent, checkStyle(style));   123         super(parent, checkStyle(style));
118         this.parent = parent;   124         this.parent = parent;
119         createWidget(index);   125         createWidget(index);
120 }   126 }
121     127  
122 void selectionCallback(int modifiers) {   128 void selectionCallback(int modifiers) {
123         // Ignore all events that come in when the item (or parent) is disabled   129         // Ignore all events that come in when the item (or parent) is disabled
124         // See bug 106888   130         // See bug 106888
125         if (isEnabled() == false) return;   131         if (isEnabled() == false) return;
126           132        
127         if ((internal_style & SWT.CHECK) == SWT.CHECK) {   133         if ((internal_style & SWT.CHECK) == SWT.CHECK) {
    <> 134                 if (disableAutoSelection == false) {
128                 selected = !selected;   135                         selected = !selected;
      136                 }
129         } else if ((internal_style & SWT.RADIO) == SWT.RADIO) { = 137         } else if ((internal_style & SWT.RADIO) == SWT.RADIO) {
130                 if ((parent.getStyle() & SWT.NO_RADIO_GROUP) == SWT.NO_RADIO_GROUP) {   138                 if ((parent.getStyle() & SWT.NO_RADIO_GROUP) == SWT.NO_RADIO_GROUP) {
131                         selected = !selected;   139                         selected = !selected;
132                 } else {   140                 } else {
133                         selectRadio();   141                         selectRadio();
134                 }   142                 }
135         }   143         }
136         Event event = new Event();   144         Event event = new Event();
137         setInputState(event, SWT.Selection, modifiers);   145         setInputState(event, SWT.Selection, modifiers);
138         postEvent(SWT.Selection, event);   146         postEvent(SWT.Selection, event);
139 }   147 }
140     148  
141 /**   149 /**
142 * Adds the listener to the collection of listeners who will   150 * Adds the listener to the collection of listeners who will
143 * be notified when the menu item is selected, by sending   151 * be notified when the menu item is selected, by sending
144 * it one of the messages defined in the <code>SelectionListener</code>   152 * it one of the messages defined in the <code>SelectionListener</code>
145 * interface.   153 * interface.
146 * <p>   154 * <p>
147 * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.   155 * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
148 * <code>widgetDefaultSelected</code> is not called.   156 * <code>widgetDefaultSelected</code> is not called.
149 * </p>   157 * </p>
150 *   158 *
151 * @param listener the listener which should be notified   159 * @param listener the listener which should be notified
152 *   160 *
153 * @exception IllegalArgumentException <ul>   161 * @exception IllegalArgumentException <ul>
154 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>   162 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
155 * </ul>   163 * </ul>
156 * @exception SWTException <ul>   164 * @exception SWTException <ul>
157 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   165 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
158 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   166 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
159 * </ul>   167 * </ul>
160 *   168 *
161 * @see SelectionListener   169 * @see SelectionListener
162 * @see #removeSelectionListener   170 * @see #removeSelectionListener
163 * @see SelectionEvent   171 * @see SelectionEvent
164 */   172 */
165 public void addSelectionListener(SelectionListener listener) {   173 public void addSelectionListener(SelectionListener listener) {
166         checkWidget();   174         checkWidget();
167         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);   175         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
168         TypedListener typedListener = new TypedListener(listener);   176         TypedListener typedListener = new TypedListener(listener);
169         addListener(SWT.Selection, typedListener);   177         addListener(SWT.Selection, typedListener);
170         addListener(SWT.DefaultSelection, typedListener);   178         addListener(SWT.DefaultSelection, typedListener);
171 }   179 }
172     180  
173 static int checkStyle(int style) {   181 static int checkStyle(int style) {
174         return checkBits(style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);   182         return checkBits(style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
175 }   183 }
176     184  
177 protected void internal_createHandle(int index) {   185 protected void internal_createHandle(int index) {
178         int count = parent.getItemCount();   186         int count = parent.getItemCount();
179         if (!(0 <= index && index <= count)) error(SWT.ERROR_INVALID_RANGE);   187         if (!(0 <= index && index <= count)) error(SWT.ERROR_INVALID_RANGE);
180           188        
181         int parentHandle = parent.internal_handle;   189         int parentHandle = parent.internal_handle;
182         if ((internal_style & SWT.SEPARATOR) == SWT.SEPARATOR) {   190         if ((internal_style & SWT.SEPARATOR) == SWT.SEPARATOR) {
183                 internal_handle = OS.SeparatorItem_New(parentHandle, index);   191                 internal_handle = OS.SeparatorItem_New(parentHandle, index);
184         } else   192         } else
185         if ((internal_style & SWT.RADIO) == SWT.RADIO) {   193         if ((internal_style & SWT.RADIO) == SWT.RADIO) {
186                 internal_handle = OS.StateMenuItem_New(parentHandle,index, OS.STYLE_RADIO);   194                 internal_handle = OS.StateMenuItem_New(parentHandle,index, OS.STYLE_RADIO);
187         } else   195         } else
188         if ((internal_style & SWT.CHECK) == SWT.CHECK) {   196         if ((internal_style & SWT.CHECK) == SWT.CHECK) {
189                 internal_handle = OS.StateMenuItem_New(parentHandle,index, OS.STYLE_CHECK);   197                 internal_handle = OS.StateMenuItem_New(parentHandle,index, OS.STYLE_CHECK);
190         } else   198         } else
191         if ((internal_style & SWT.PUSH) == SWT.PUSH) {   199         if ((internal_style & SWT.PUSH) == SWT.PUSH) {
192                 internal_handle = OS.PushMenuItem_New(parentHandle,index);   200                 internal_handle = OS.PushMenuItem_New(parentHandle,index);
193         } else            201         } else         
194         if ((internal_style & SWT.CASCADE) == SWT.CASCADE) {   202         if ((internal_style & SWT.CASCADE) == SWT.CASCADE) {
195                 internal_handle = OS.CascadeMenuItem_New(parentHandle,index);   203                 internal_handle = OS.CascadeMenuItem_New(parentHandle,index);
196         }   204         }
197         if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);   205         if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);
198         parent.insertItem(this, index);   206         parent.insertItem(this, index);
199 }   207 }
200     208  
201 public void dispose() {   209 public void dispose() {
202         Menu parent = this.parent;   210         Menu parent = this.parent;
203         super.dispose();   211         super.dispose();
204         if (parent != null) parent.removeItem(this);   212         if (parent != null) parent.removeItem(this);
205 }   213 }
206 /**   214 /**
207 * Returns the widget accelerator.  An accelerator is the bit-wise   215 * Returns the widget accelerator.  An accelerator is the bit-wise
208 * OR of zero or more modifier masks and a key. Examples:   216 * OR of zero or more modifier masks and a key. Examples:
209 * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.   217 * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
210 * The default value is zero, indicating that the menu item does   218 * The default value is zero, indicating that the menu item does
211 * not have an accelerator.   219 * not have an accelerator.
212 *   220 *
213 * @return the accelerator or 0   221 * @return the accelerator or 0
214 *   222 *
215 * </ul>   223 * </ul>
216 * @exception SWTException <ul>   224 * @exception SWTException <ul>
217 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   225 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
218 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   226 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
219 * </ul>   227 * </ul>
220 */   228 */
221 public int getAccelerator() {   229 public int getAccelerator() {
222         checkWidget();   230         checkWidget();
223         return accelerator;   231         return accelerator;
224 }   232 }
225     233  
226 /**   234 /**
227 * Returns <code>true</code> if the receiver is enabled, and   235 * Returns <code>true</code> if the receiver is enabled, and
228 * <code>false</code> otherwise. A disabled menu item is typically   236 * <code>false</code> otherwise. A disabled menu item is typically
229 * not selectable from the user interface and draws with an   237 * not selectable from the user interface and draws with an
230 * inactive or "grayed" look.   238 * inactive or "grayed" look.
231 *   239 *
232 * @return the receiver's enabled state   240 * @return the receiver's enabled state
233 *   241 *
234 * @exception SWTException <ul>   242 * @exception SWTException <ul>
235 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   243 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
236 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   244 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
237 * </ul>   245 * </ul>
238 *   246 *
239 * @see #isEnabled   247 * @see #isEnabled
240 */   248 */
241 public boolean getEnabled() {   249 public boolean getEnabled() {
242         checkWidget();   250         checkWidget();
243         return enabled;   251         return enabled;
244 }   252 }
245     253  
246 /**   254 /**
247 * Returns the receiver's cascade menu if it has one or null   255 * Returns the receiver's cascade menu if it has one or null
248 * if it does not. Only <code>CASCADE</code> menu items can have   256 * if it does not. Only <code>CASCADE</code> menu items can have
249 * a pull down menu. The sequence of key strokes, button presses   257 * a pull down menu. The sequence of key strokes, button presses
250 * and/or button releases that are used to request a pull down   258 * and/or button releases that are used to request a pull down
251 * menu is platform specific.   259 * menu is platform specific.
252 *   260 *
253 * @return the receiver's menu   261 * @return the receiver's menu
254 *   262 *
255 * @exception SWTException <ul>   263 * @exception SWTException <ul>
256 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   264 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
257 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   265 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
258 * </ul>   266 * </ul>
259 */   267 */
260 public Menu getMenu() {   268 public Menu getMenu() {
261         checkWidget();   269         checkWidget();
262         return menu;   270         return menu;
263 }   271 }
264     272  
265 /**   273 /**
266 * Returns the receiver's parent, which must be a <code>Menu</code>.   274 * Returns the receiver's parent, which must be a <code>Menu</code>.
267 *   275 *
268 * @return the receiver's parent   276 * @return the receiver's parent
269 *   277 *
270 * @exception SWTException <ul>   278 * @exception SWTException <ul>
271 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   279 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
272 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   280 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
273 * </ul>   281 * </ul>
274 */   282 */
275 public Menu getParent() {   283 public Menu getParent() {
276         checkWidget();   284         checkWidget();
277         return parent;   285         return parent;
278 }   286 }
279     287  
280 /**   288 /**
281 * Returns <code>true</code> if the receiver is selected,   289 * Returns <code>true</code> if the receiver is selected,
282 * and false otherwise.   290 * and false otherwise.
283 * <p>   291 * <p>
284 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,   292 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
285 * it is selected when it is checked.   293 * it is selected when it is checked.
286 *   294 *
287 * @return the selection state   295 * @return the selection state
288 *   296 *
289 * @exception SWTException <ul>   297 * @exception SWTException <ul>
290 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   298 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
291 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   299 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
292 * </ul>   300 * </ul>
293 */   301 */
294 public boolean getSelection() {   302 public boolean getSelection() {
295         checkWidget();   303         checkWidget();
296         if ((internal_style & (SWT.CHECK | SWT.RADIO)) == 0) return false;   304         if ((internal_style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
297         return selected;   305         return selected;
298 }   306 }
299     307  
300 public String getText() {   308 public String getText() {
301         checkWidget();   309         checkWidget();
302         return text;   310         return text;
303 }   311 }
304 /**   312 /**
305 * Returns <code>true</code> if the receiver is enabled and all   313 * Returns <code>true</code> if the receiver is enabled and all
306 * of the receiver's ancestors are enabled, and <code>false</code>   314 * of the receiver's ancestors are enabled, and <code>false</code>
307 * otherwise. A disabled menu item is typically not selectable from the   315 * otherwise. A disabled menu item is typically not selectable from the
308 * user interface and draws with an inactive or "grayed" look.   316 * user interface and draws with an inactive or "grayed" look.
309 *   317 *
310 * @return the receiver's enabled state   318 * @return the receiver's enabled state
311 *   319 *
312 * @exception SWTException <ul>   320 * @exception SWTException <ul>
313 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   321 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
314 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   322 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
315 * </ul>   323 * </ul>
316 *   324 *
317 * @see #getEnabled   325 * @see #getEnabled
318 */   326 */
319 public boolean isEnabled() {   327 public boolean isEnabled() {
320         checkWidget();   328         checkWidget();
321         return getEnabled () && parent.isEnabled ();   329         return getEnabled () && parent.isEnabled ();
322 }   330 }
323     331  
324 void releaseWidget() {   332 void releaseWidget() {
325         if (menu != null && !menu.isDisposed()) menu.releaseResources();   333         if (menu != null && !menu.isDisposed()) menu.releaseResources();
326         menu = null;   334         menu = null;
327         super.releaseWidget ();   335         super.releaseWidget ();
328         accelerator = 0;   336         accelerator = 0;
329         parent = null;   337         parent = null;
330 }   338 }
331     339  
332 /**   340 /**
333 * Removes the listener from the collection of listeners who will   341 * Removes the listener from the collection of listeners who will
334 * be notified when the control is selected.   342 * be notified when the control is selected.
335 *   343 *
336 * @param listener the listener which should no longer be notified   344 * @param listener the listener which should no longer be notified
337 *   345 *
338 * @exception IllegalArgumentException <ul>   346 * @exception IllegalArgumentException <ul>
339 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>   347 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
340 * </ul>   348 * </ul>
341 * @exception SWTException <ul>   349 * @exception SWTException <ul>
342 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   350 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
343 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   351 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
344 * </ul>   352 * </ul>
345 *   353 *
346 * @see SelectionListener   354 * @see SelectionListener
347 * @see #addSelectionListener   355 * @see #addSelectionListener
348 */   356 */
349 public void removeSelectionListener(SelectionListener listener) {   357 public void removeSelectionListener(SelectionListener listener) {
350         checkWidget();   358         checkWidget();
351         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);   359         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
352         if (eventTable == null) return;   360         if (eventTable == null) return;
353         eventTable.unhook(SWT.Selection, listener);   361         eventTable.unhook(SWT.Selection, listener);
354         eventTable.unhook(SWT.DefaultSelection,listener);   362         eventTable.unhook(SWT.DefaultSelection,listener);
355 }   363 }
356 /**   364 /**
357 * Sets the widget accelerator.  An accelerator is the bit-wise   365 * Sets the widget accelerator.  An accelerator is the bit-wise
358 * OR of zero or more modifier masks and a key. Examples:   366 * OR of zero or more modifier masks and a key. Examples:
359 * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.   367 * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
360 * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.   368 * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
361 * The default value is zero, indicating that the menu item does   369 * The default value is zero, indicating that the menu item does
362 * not have an accelerator.   370 * not have an accelerator.
363 *   371 *
364 * @param accelerator an integer that is the bit-wise OR of masks and a key   372 * @param accelerator an integer that is the bit-wise OR of masks and a key
365 *   373 *
366 * </ul>   374 * </ul>
367 * @exception SWTException <ul>   375 * @exception SWTException <ul>
368 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   376 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
369 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   377 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
370 * </ul>   378 * </ul>
371 */   379 */
372 public void setAccelerator(int accelerator) {   380 public void setAccelerator(int accelerator) {
373         checkWidget();   381         checkWidget();
374         this.accelerator = accelerator;   382         this.accelerator = accelerator;
375         if ((internal_style & SWT.SEPARATOR) == 0) {   383         if ((internal_style & SWT.SEPARATOR) == 0) {
376                 int keyMods = 0;   384                 int keyMods = 0;
377                 if ((accelerator & SWT.MOD3) != 0) keyMods |= OS.MODIFIER_MASK_ALT;   385                 if ((accelerator & SWT.MOD3) != 0) keyMods |= OS.MODIFIER_MASK_ALT;
378                 if ((accelerator & SWT.MOD2) != 0) keyMods |= OS.MODIFIER_MASK_SHIFT;   386                 if ((accelerator & SWT.MOD2) != 0) keyMods |= OS.MODIFIER_MASK_SHIFT;
379                 if ((accelerator & SWT.MOD1) != 0) keyMods |= OS.MODIFIER_MASK_CONTROL;   387                 if ((accelerator & SWT.MOD1) != 0) keyMods |= OS.MODIFIER_MASK_CONTROL;
380                 int key = accelerator & ~(SWT.MOD3 | SWT.MOD2 | SWT.MOD1);   388                 int key = accelerator & ~(SWT.MOD3 | SWT.MOD2 | SWT.MOD1);
381         key = Display.convertToUglKeyCode(key);   389         key = Display.convertToUglKeyCode(key);
382             int value = (keyMods << 16) | key;   390             int value = (keyMods << 16) | key;
383             OS.LabeledMenuItem_SetAccelerator(internal_handle,value);   391             OS.LabeledMenuItem_SetAccelerator(internal_handle,value);
384         }   392         }
385 }   393 }
386     394  
387 /**   395 /**
388 * Sets the image the receiver will display to the argument.   396 * Sets the image the receiver will display to the argument.
389 * <p>   397 * <p>
390 * Note: This operation is a hint and is not supported on   398 * Note: This operation is a hint and is not supported on
391 * platforms that do not have this concept (for example, Windows NT).   399 * platforms that do not have this concept (for example, Windows NT).
392 * </p>   400 * </p>
393 *   401 *
394 * @param image the image to display   402 * @param image the image to display
395 *   403 *
396 * @exception SWTException <ul>   404 * @exception SWTException <ul>
397 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   405 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
398 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   406 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
399 * </ul>   407 * </ul>
400 */   408 */
401 public void setImage(Image image){   409 public void setImage(Image image){
402                 super.setImage(image);    410                 super.setImage(image); 
403                 if ((internal_style & SWT.SEPARATOR) == 0) {   411                 if ((internal_style & SWT.SEPARATOR) == 0) {
404                     int imageHandle = 0;   412                     int imageHandle = 0;
405                     //Avoiding to throw NULL image object to native. Which will cause j9 dump   413                     //Avoiding to throw NULL image object to native. Which will cause j9 dump
406                     if (image != null) {   414                     if (image != null) {
407                         imageHandle = image.internal_handle;   415                         imageHandle = image.internal_handle;
408                         OS.LabeledMenuItem_SetImage(internal_handle, imageHandle);   416                         OS.LabeledMenuItem_SetImage(internal_handle, imageHandle);
409                     }   417                     }
410                   418                
411                 }   419                 }
412 }   420 }
413     421  
414     422  
415 /**   423 /**
416 * Enables the receiver if the argument is <code>true</code>,   424 * Enables the receiver if the argument is <code>true</code>,
417 * and disables it otherwise. A disabled menu item is typically   425 * and disables it otherwise. A disabled menu item is typically
418 * not selectable from the user interface and draws with an   426 * not selectable from the user interface and draws with an
419 * inactive or "grayed" look.   427 * inactive or "grayed" look.
420 *   428 *
421 * @param enabled the new enabled state   429 * @param enabled the new enabled state
422 *   430 *
423 * @exception SWTException <ul>   431 * @exception SWTException <ul>
424 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   432 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
425 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   433 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
426 * </ul>   434 * </ul>
427 */   435 */
428 public void setEnabled(boolean enabled) {   436 public void setEnabled(boolean enabled) {
429         checkWidget();   437         checkWidget();
430           438        
431         if (enabled == this.enabled) return;   439         if (enabled == this.enabled) return;
432           440        
433         this.enabled = enabled;   441         this.enabled = enabled;
434         if (parent.getEnabled()) {   442         if (parent.getEnabled()) {
435                 updateEnabledStatus(true);   443                 updateEnabledStatus(true);
436         } else {   444         } else {
437                 // The native widgets enabled status does not   445                 // The native widgets enabled status does not
438                 // need to change now, because the parent is disabled   446                 // need to change now, because the parent is disabled
439                 // and the correct enabled status will be reflected   447                 // and the correct enabled status will be reflected
440                 // when the parent is enabled again   448                 // when the parent is enabled again
441         }   449         }
442 }   450 }
443     451  
444 /**   452 /**
445 * Sets the receiver's pull down menu to the argument.   453 * Sets the receiver's pull down menu to the argument.
446 * Only <code>CASCADE</code> menu items can have a   454 * Only <code>CASCADE</code> menu items can have a
447 * pull down menu. The sequence of key strokes, button presses   455 * pull down menu. The sequence of key strokes, button presses
448 * and/or button releases that are used to request a pull down   456 * and/or button releases that are used to request a pull down
449 * menu is platform specific.   457 * menu is platform specific.
450 *   458 *
451 * @param menu the new pull down menu   459 * @param menu the new pull down menu
452 *   460 *
453 * @exception IllegalArgumentException <ul>   461 * @exception IllegalArgumentException <ul>
454 *    <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>   462 *    <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
455 *    <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>   463 *    <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
456 *    <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>   464 *    <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
457 *    <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>   465 *    <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
458 * </ul>   466 * </ul>
459 * @exception SWTException <ul>   467 * @exception SWTException <ul>
460 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   468 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
461 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   469 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
462 * </ul>   470 * </ul>
463 */   471 */
464 public void setMenu(Menu menu) {   472 public void setMenu(Menu menu) {
465         checkWidget();   473         checkWidget();
466         if ((internal_style & SWT.CASCADE) == 0) error(SWT.ERROR_MENUITEM_NOT_CASCADE);   474         if ((internal_style & SWT.CASCADE) == 0) error(SWT.ERROR_MENUITEM_NOT_CASCADE);
467           475        
468         int menuHandle;   476         int menuHandle;
469         if (menu != null) {   477         if (menu != null) {
470                 if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);   478                 if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
471                 if ((menu.internal_style & SWT.DROP_DOWN) == 0) error(SWT.ERROR_MENU_NOT_DROP_DOWN);   479                 if ((menu.internal_style & SWT.DROP_DOWN) == 0) error(SWT.ERROR_MENU_NOT_DROP_DOWN);
472                 if (menu.parent != parent.parent) error(SWT.ERROR_INVALID_PARENT);   480                 if (menu.parent != parent.parent) error(SWT.ERROR_INVALID_PARENT);
473                 menuHandle = menu.internal_handle;   481                 menuHandle = menu.internal_handle;
474                 this.menu = menu;   482                 this.menu = menu;
475                 this.menu.cascade = this;   483                 this.menu.cascade = this;
476         } else {   484         } else {
477                 menuHandle = 0;   485                 menuHandle = 0;
478                   486                
479                 // this.menu can be null if the menu has never been set before   487                 // this.menu can be null if the menu has never been set before
480                 if (this.menu != null) {   488                 if (this.menu != null) {
481                         this.menu.cascade = null; // reset the previous one   489                         this.menu.cascade = null; // reset the previous one
482                         this.menu = null;   490                         this.menu = null;
483                 }   491                 }
484         }   492         }
485         OS.CascadeMenuItem_SetMenu(internal_handle, menuHandle);   493         OS.CascadeMenuItem_SetMenu(internal_handle, menuHandle);
486 }   494 }
487     495  
488 void selectRadio () {   496 void selectRadio () {
489         int index = 0;   497         int index = 0;
490         MenuItem[] items = parent.getItems();   498         MenuItem[] items = parent.getItems();
491         while (index < items.length && items[index] != this) index++;   499         while (index < items.length && items[index] != this) index++;
492         int i = index - 1;   500         int i = index - 1;
493         while (i >= 0 && items[i].setRadioSelection(false)) --i;   501         while (i >= 0 && items[i].setRadioSelection(false)) --i;
494         int j = index + 1;   502         int j = index + 1;
495         while (j < items.length && items[j].setRadioSelection (false)) j++;   503         while (j < items.length && items[j].setRadioSelection (false)) j++;
496         setSelection(true);   504         setSelection(true);
497 }   505 }
498 boolean setRadioSelection(boolean value) {   506 boolean setRadioSelection(boolean value) {
499         if ((internal_style & SWT.RADIO) == 0) return false;   507         if ((internal_style & SWT.RADIO) == 0) return false;
500         if (getSelection() != value) {   508         if (getSelection() != value) {
501                 setSelection(value);   509                 setSelection(value);
502                 postEvent(SWT.Selection);   510                 postEvent(SWT.Selection);
503         }   511         }
504         return true;   512         return true;
505 }   513 }
506     514  
507 /**   515 /**
508 * Sets the selection state of the receiver.   516 * Sets the selection state of the receiver.
509 * <p>   517 * <p>
510 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,   518 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
511 * it is selected when it is checked.   519 * it is selected when it is checked.
512 *   520 *
513 * @param selected the new selection state   521 * @param selected the new selection state
514 *   522 *
515 * @exception SWTException <ul>   523 * @exception SWTException <ul>
516 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   524 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
517 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   525 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
518 * </ul>   526 * </ul>
519 */   527 */
520 public void setSelection(boolean selected) {   528 public void setSelection(boolean selected) {
521         checkWidget();   529         checkWidget();
522         if ((internal_style & (SWT.CHECK | SWT.RADIO)) == 0) return;   530         if ((internal_style & (SWT.CHECK | SWT.RADIO)) == 0) return;
523         this.selected = selected;   531         this.selected = selected;
524         OS.StateMenuItem_SetSelection(internal_handle, selected);   532         OS.StateMenuItem_SetSelection(internal_handle, selected);
525 }   533 }
526     534  
527 /**   535 /**
    <> 536 * Sets the disableAutoSelection state of the receiver.
      537 * <p>
      538 * When the receiver is of type <code>CHECK</code>,
      539 * it is selected when it is checked.
      540 *
      541 * @param disableAutoSelection the new disableAutoSelection state
      542 *
      543 * @exception SWTException <ul>
      544 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
      545 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
      546 * </ul>
      547 */
      548 public void setDisableAutoSelection(boolean disableAutoSelection) {
      549         checkWidget();
      550         if ((internal_style & (SWT.CHECK)) == 0) return;
      551         this.disableAutoSelection = disableAutoSelection;
      552         OS.StateMenuItem_DisableAutoSelection(internal_handle, disableAutoSelection);
      553 }
      554  
      555 /**
528 * Sets the receiver's text. The string may include = 556 * Sets the receiver's text. The string may include
529 * the mnemonic character and accelerator text.   557 * the mnemonic character and accelerator text.
530 * <p>   558 * <p>
531 * Mnemonics are indicated by an '&amp' that causes the next   559 * Mnemonics are indicated by an '&amp' that causes the next
532 * character to be the mnemonic.  When the user presses a   560 * character to be the mnemonic.  When the user presses a
533 * key sequence that matches the mnemonic, a selection   561 * key sequence that matches the mnemonic, a selection
534 * event occurs. On most platforms, the mnemonic appears   562 * event occurs. On most platforms, the mnemonic appears
535 * underlined but may be emphasised in a platform specific   563 * underlined but may be emphasised in a platform specific
536 * manner.  The mnemonic indicator character '&amp' can be   564 * manner.  The mnemonic indicator character '&amp' can be
537 * escaped by doubling it in the string, causing a single   565 * escaped by doubling it in the string, causing a single
538 *'&amp' to be displayed.   566 *'&amp' to be displayed.
539 * </p>   567 * </p>
540 * <p>   568 * <p>
541 * Accelerator text is indicated by the '\t' character.   569 * Accelerator text is indicated by the '\t' character.
542 * On platforms that support accelerator text, the text   570 * On platforms that support accelerator text, the text
543 * that follows the '\t' character is displayed to the user,   571 * that follows the '\t' character is displayed to the user,
544 * typically indicating the key stroke that will cause   572 * typically indicating the key stroke that will cause
545 * the item to become selected.  On most platforms, the   573 * the item to become selected.  On most platforms, the
546 * accelerator text appears right aligned in the menu.   574 * accelerator text appears right aligned in the menu.
547 * Setting the accelerator text does not install the   575 * Setting the accelerator text does not install the
548 * accelerator key sequence. The accelerator key sequence   576 * accelerator key sequence. The accelerator key sequence
549 * is installed using #setAccelerator.   577 * is installed using #setAccelerator.
550 * </p>   578 * </p>
551 *   579 *
552 * @param string the new text   580 * @param string the new text
553 *   581 *
554 * @exception IllegalArgumentException <ul>   582 * @exception IllegalArgumentException <ul>
555 *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>   583 *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
556 * </ul>   584 * </ul>
557 * @exception SWTException <ul>   585 * @exception SWTException <ul>
558 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   586 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
559 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   587 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
560 * </ul>   588 * </ul>
561 *   589 *
562 * @see #setAccelerator   590 * @see #setAccelerator
563 */   591 */
564 public void setText(String string) {   592 public void setText(String string) {
565         super.setText(string);   593         super.setText(string);
566         if ((internal_style & SWT.SEPARATOR) == 0) {   594         if ((internal_style & SWT.SEPARATOR) == 0) {
567                 String itemText = string;   595                 String itemText = string;
568                 String accelText = "";   596                 String accelText = "";
569                   597                
570                 int tab = string.indexOf('\t');   598                 int tab = string.indexOf('\t');
571                 if (tab > -1) {   599                 if (tab > -1) {
572                           600                        
573                         if (tab == 0) {   601                         if (tab == 0) {
574                                 itemText = "";   602                                 itemText = "";
575                         }   603                         }
576                         else {   604                         else {
577                                 itemText = string.substring(0,tab);   605                                 itemText = string.substring(0,tab);
578                         }   606                         }
579                           607                        
580                         int length = string.length();   608                         int length = string.length();
581                         if (tab < (length-1)) {   609                         if (tab < (length-1)) {
582                                 accelText = string.substring(tab+1,length);   610                                 accelText = string.substring(tab+1,length);
583                         }   611                         }
584                 }   612                 }
585                   613                
586                 OS.LabeledMenuItem_SetText(internal_handle, itemText, accelText);   614                 OS.LabeledMenuItem_SetText(internal_handle, itemText, accelText);
587         }   615         }
588 }   616 }
589     617  
590 void updateEnabledStatus(boolean parentEnabled) {   618 void updateEnabledStatus(boolean parentEnabled) {
591         if (internal_handle != 0) {   619         if (internal_handle != 0) {
592                 OS.AbstractMenuItem_SetEnabled(internal_handle, parentEnabled && enabled);   620                 OS.AbstractMenuItem_SetEnabled(internal_handle, parentEnabled && enabled);
593         }   621         }
594 }   622 }
595     623  
596 void fixMenus(Decorations newParent) {   624 void fixMenus(Decorations newParent) {
597         if (menu != null) menu.fixMenus(newParent);   625         if (menu != null) menu.fixMenus(newParent);
598 }   626 }
599     627  
600 }   628 }