diff options
author | Silenio Quarti <silenio> | 2011-03-03 15:19:09 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2011-03-03 15:19:09 +0000 |
commit | f1fbb8716f7eb6144440edb1c7a2f83e3f63fe10 (patch) | |
tree | d713e43f11533c28e26d1a716340568a692bf820 | |
parent | dbfdea5a6ace7254c9bcb69a7489276f3b9d3e35 (diff) | |
download | eclipse.platform.swt-f1fbb8716f7eb6144440edb1c7a2f83e3f63fe10.tar.gz eclipse.platform.swt-f1fbb8716f7eb6144440edb1c7a2f83e3f63fe10.tar.xz eclipse.platform.swt-f1fbb8716f7eb6144440edb1c7a2f83e3f63fe10.zip |
Bug 329456 - Add API to access the application menu (Mac) and system menu (win32/gtk)
22 files changed, 697 insertions, 54 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras index 7d59abaf91..e929da8c1f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras @@ -1806,6 +1806,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="itemWithTag:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="numberOfItems" swt_gen="true"> <retval swt_gen="true"></retval> </method> @@ -1842,6 +1846,9 @@ </method> </class> <class name="NSMenuItem" swt_gen="mixed"> + <method selector="action" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="attributedTitle" swt_gen="true"> <retval swt_gen="true"></retval> </method> @@ -1857,6 +1864,9 @@ <method selector="isHidden" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="isSeparatorItem" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="keyEquivalent" swt_gen="true"> <retval swt_gen="true"></retval> </method> @@ -1924,6 +1934,12 @@ <method selector="submenu" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="tag" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> + <method selector="target" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="title" swt_gen="true"> <retval swt_gen="true"></retval> </method> @@ -3603,9 +3619,6 @@ <method selector="defaultParagraphStyle" swt_gen="true"> <retval swt_gen="true"></retval> </method> - <method selector="didChangeText" swt_gen="true"> - <retval swt_gen="true"></retval> - </method> <method selector="dragSelectionWithEvent:offset:slideBack:" swt_gen="true" swt_gen_custom_callback="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenu.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenu.java index 1611c73d36..15e8b657a4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenu.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -60,6 +60,11 @@ public NSMenuItem itemAtIndex(int /*long*/ index) { return result != 0 ? new NSMenuItem(result) : null; } +public NSMenuItem itemWithTag(int /*long*/ tag) { + int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_itemWithTag_, tag); + return result != 0 ? new NSMenuItem(result) : null; +} + public int /*long*/ numberOfItems() { return OS.objc_msgSend(this.id, OS.sel_numberOfItems); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java index bc06bd40e8..3d12164508 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,6 +24,10 @@ public NSMenuItem(id id) { super(id); } +public int /*long*/ action() { + return OS.objc_msgSend(this.id, OS.sel_action); +} + public NSAttributedString attributedTitle() { int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_attributedTitle); return result != 0 ? new NSAttributedString(result) : null; @@ -43,6 +47,10 @@ public boolean isHidden() { return OS.objc_msgSend_bool(this.id, OS.sel_isHidden); } +public boolean isSeparatorItem() { + return OS.objc_msgSend_bool(this.id, OS.sel_isSeparatorItem); +} + public NSString keyEquivalent() { int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_keyEquivalent); return result != 0 ? new NSString(result) : null; @@ -118,6 +126,15 @@ public NSMenu submenu() { return result != 0 ? new NSMenu(result) : null; } +public int /*long*/ tag() { + return OS.objc_msgSend(this.id, OS.sel_tag); +} + +public id target() { + int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_target); + return result != 0 ? new id(result) : null; +} + public NSString title() { int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_title); return result != 0 ? new NSString(result) : null; diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index da2298d051..de762cd645 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -1154,7 +1154,6 @@ public static final int /*long*/ sel_deviceSize = sel_registerName("deviceSize") public static final int /*long*/ sel_dictionary = sel_registerName("dictionary"); public static final int /*long*/ sel_dictionaryWithCapacity_ = sel_registerName("dictionaryWithCapacity:"); public static final int /*long*/ sel_dictionaryWithObject_forKey_ = sel_registerName("dictionaryWithObject:forKey:"); -public static final int /*long*/ sel_didChangeText = sel_registerName("didChangeText"); public static final int /*long*/ sel_disableCursorRects = sel_registerName("disableCursorRects"); public static final int /*long*/ sel_disableFlushWindow = sel_registerName("disableFlushWindow"); public static final int /*long*/ sel_disabledControlTextColor = sel_registerName("disabledControlTextColor"); @@ -1396,6 +1395,7 @@ public static final int /*long*/ sel_isPlanar = sel_registerName("isPlanar"); public static final int /*long*/ sel_isResting = sel_registerName("isResting"); public static final int /*long*/ sel_isRowSelected_ = sel_registerName("isRowSelected:"); public static final int /*long*/ sel_isRunning = sel_registerName("isRunning"); +public static final int /*long*/ sel_isSeparatorItem = sel_registerName("isSeparatorItem"); public static final int /*long*/ sel_isSessionOnly = sel_registerName("isSessionOnly"); public static final int /*long*/ sel_isSheet = sel_registerName("isSheet"); public static final int /*long*/ sel_isVisible = sel_registerName("isVisible"); @@ -1407,6 +1407,7 @@ public static final int /*long*/ sel_itemHeight = sel_registerName("itemHeight") public static final int /*long*/ sel_itemIdentifier = sel_registerName("itemIdentifier"); public static final int /*long*/ sel_itemObjectValueAtIndex_ = sel_registerName("itemObjectValueAtIndex:"); public static final int /*long*/ sel_itemTitleAtIndex_ = sel_registerName("itemTitleAtIndex:"); +public static final int /*long*/ sel_itemWithTag_ = sel_registerName("itemWithTag:"); public static final int /*long*/ sel_jobDisposition = sel_registerName("jobDisposition"); public static final int /*long*/ sel_keyCode = sel_registerName("keyCode"); public static final int /*long*/ sel_keyDown_ = sel_registerName("keyDown:"); @@ -2062,6 +2063,7 @@ public static final int /*long*/ sel_tableViewColumnDidMove_ = sel_registerName( public static final int /*long*/ sel_tableViewColumnDidResize_ = sel_registerName("tableViewColumnDidResize:"); public static final int /*long*/ sel_tableViewSelectionDidChange_ = sel_registerName("tableViewSelectionDidChange:"); public static final int /*long*/ sel_tableViewSelectionIsChanging_ = sel_registerName("tableViewSelectionIsChanging:"); +public static final int /*long*/ sel_tag = sel_registerName("tag"); public static final int /*long*/ sel_target = sel_registerName("target"); public static final int /*long*/ sel_terminate_ = sel_registerName("terminate:"); public static final int /*long*/ sel_testPart_ = sel_registerName("testPart:"); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java index f6b031d4fa..d77514fd32 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java @@ -2126,6 +2126,24 @@ public Image getSystemImage (int id) { } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + return null; +} + +/** * Returns the single instance of the system taskBar or null * when there is no system taskBar available for the platform. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java index 6611e9355b..ba9364fb1a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java @@ -37,7 +37,7 @@ import org.eclipse.swt.internal.carbon.*; */ public class MenuItem extends Item { Menu parent, menu; - int accelerator; + int accelerator, userId; boolean acceleratorSet; // int x, y, width, height; @@ -308,6 +308,21 @@ public boolean getEnabled () { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return userId; +} + +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -671,6 +686,25 @@ public void setEnabled (boolean enabled) { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; +} + +/** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index 2d3223c18b..e4a771dfa9 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -197,7 +197,7 @@ public class Display extends Device { Menu trayItemMenu; /* Main menu bar and application menu */ - Menu appMenuBar; + Menu appMenuBar, appMenu; /* TaskBar */ TaskBar taskBar; @@ -1974,6 +1974,36 @@ public Menu getAppMenuBar () { } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + if (appMenu == null) { + NSMenu mainMenu = NSApplication.sharedApplication().mainMenu(); + NSMenu nsAppMenu = mainMenu.itemAtIndex(0).submenu(); + appMenu = new Menu(this, nsAppMenu); + + // Create menu items that correspond to the NSMenuItems. + int /*long*/ nsCount = nsAppMenu.numberOfItems(); + for (int j = 0; j < nsCount; j++) { + NSMenuItem currMenuItem = nsAppMenu.itemAtIndex(j); + new MenuItem(appMenu, currMenuItem); + } + } + return appMenu; +} + +/** * Returns the single instance of the system tray or null * when there is no system tray available for the platform. * @@ -2136,11 +2166,17 @@ protected void init () { } /* - * Call init to force the AWT delegate to re-attach itself to the application menu. + * Call init to force the AWT delegate to re-attach itself to the application menu. + * The Preferences item must have a tag of 42 or the AWT delegate won't be able to find it. + * Reset it to what we want it to be after the delegate is set up. */ + NSMenu appleMenu = application.mainMenu().itemAtIndex(0).submenu(); + NSMenuItem prefsItem = appleMenu.itemWithTag(SWT.ID_PREFERENCES); + prefsItem.setTag(42); if (currAppDelegate != null) { currAppDelegate.init(); } + prefsItem.setTag(SWT.ID_PREFERENCES); observerCallback = new Callback (this, "observerProc", 3); //$NON-NLS-1$ int /*long*/ observerProc = observerCallback.getAddress (); @@ -2290,6 +2326,32 @@ int /*long*/ createWindowSubclass(int /*long*/ baseClass, String newClass, boole return cls; } +int /*long*/ createMenuSubclass(int /*long*/ baseClass, String newClass, boolean isDynamic) { + int /*long*/ cls = OS.objc_lookUpClass(newClass); + if (cls != 0) return cls; + cls = OS.objc_allocateClassPair(baseClass, newClass, 0); + int /*long*/ proc3 = windowCallback3.getAddress(); + int /*long*/ proc4 = windowCallback4.getAddress(); + OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); + OS.class_addMethod(cls, OS.sel_menuWillOpen_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_menuDidClose_, proc3, "@:@"); + OS.class_addMethod(cls, OS.sel_menu_willHighlightItem_, proc4, "@:@@"); + OS.class_addMethod(cls, OS.sel_menuNeedsUpdate_, proc3, "@:@"); + OS.objc_registerClassPair(cls); + return cls; +} + +int /*long*/ createMenuItemSubclass(int /*long*/ baseClass, String newClass, boolean isDynamic) { + int /*long*/ cls = OS.objc_lookUpClass(newClass); + if (cls != 0) return cls; + cls = OS.objc_allocateClassPair(baseClass, newClass, 0); + int /*long*/ proc2 = windowCallback2.getAddress(); + if (!isDynamic) OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); + OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); + OS.objc_registerClassPair(cls); + return cls; +} + void initClasses () { if (OS.objc_lookUpClass ("SWTView") != 0) return; @@ -2493,20 +2555,8 @@ void initClasses () { OS.class_addMethod (cls, OS.sel_expansionFrameWithFrame_inView_, expansionFrameWithFrameProc, "@:{NSRect}@"); OS.objc_registerClassPair (cls); - className = "SWTMenu"; - cls = OS.objc_allocateClassPair(OS.class_NSMenu, className, 0); - OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); - OS.class_addMethod(cls, OS.sel_menuWillOpen_, proc3, "@:@"); - OS.class_addMethod(cls, OS.sel_menuDidClose_, proc3, "@:@"); - OS.class_addMethod(cls, OS.sel_menu_willHighlightItem_, proc4, "@:@@"); - OS.class_addMethod(cls, OS.sel_menuNeedsUpdate_, proc3, "@:@"); - OS.objc_registerClassPair(cls); - - className = "SWTMenuItem"; - cls = OS.objc_allocateClassPair(OS.class_NSMenuItem, className, 0); - OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); - OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); - OS.objc_registerClassPair(cls); + createMenuSubclass(OS.class_NSMenu, "SWTMenu", false); + createMenuItemSubclass(OS.class_NSMenuItem, "SWTMenuItem", false); className = "SWTOutlineView"; cls = OS.objc_allocateClassPair(OS.class_NSOutlineView, className, 0); @@ -3614,6 +3664,8 @@ protected void release () { disposeList = null; synchronizer.releaseSynchronizer (); synchronizer = null; + if (appMenu != null) appMenu.dispose(); + appMenu = null; if (appMenuBar != null) appMenuBar.dispose(); appMenuBar = null; releaseDisplay (); @@ -4993,6 +5045,28 @@ void applicationWillFinishLaunching (int /*long*/ id, int /*long*/ sel, int /*lo NSMenuItem ni = new NSMenuItem(ia.objectAtIndex(i)); NSString title = ni.title().stringByReplacingOccurrencesOfString(match, name); ni.setTitle(title); + int /*long*/ newTag = 0; + switch(i) { + case 0: + newTag = SWT.ID_ABOUT; + break; + case 2: + newTag = SWT.ID_PREFERENCES; + break; + case 6: + newTag = SWT.ID_HIDE; + break; + case 7: + newTag = SWT.ID_HIDE_OTHERS; + break; + case 8: + newTag = SWT.ID_SHOW_ALL; + break; + case 10: + newTag = SWT.ID_QUIT; + break; + } + if (newTag != 0) ni.setTag(newTag); } int /*long*/ quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_terminate_); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java index 2aee95603a..828b65bd35 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java @@ -212,6 +212,14 @@ Menu (Display display) { createWidget(); } +Menu (Display display, NSMenu nativeMenu) { + this.display = display; + this.style = SWT.DROP_DOWN; + this.nsMenu = nativeMenu; + reskinWidget(); + createWidget(); +} + static Control checkNull (Control control) { if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return control; @@ -328,30 +336,79 @@ public void addMenuListener (MenuListener listener) { void createHandle () { display.addMenu (this); - NSMenu widget = (NSMenu)new SWTMenu().alloc(); - widget = widget.initWithTitle(NSString.string()); - widget.setAutoenablesItems(false); - widget.setDelegate(widget); - nsMenu = widget; + if (nsMenu == null) { + NSMenu widget = (NSMenu)new SWTMenu().alloc(); + widget = widget.initWithTitle(NSString.string()); + widget.setAutoenablesItems(false); + widget.setDelegate(widget); + nsMenu = widget; + } else { + nsMenu.retain(); + int /*long*/ cls = OS.object_getClass(nsMenu.id); + int /*long*/ dynNSMenu_class = display.createMenuSubclass(cls, "SWTSystemMenu", true); + if (cls != dynNSMenu_class) { + OS.object_setClass(nsMenu.id, dynNSMenu_class); + } + nsMenu.setDelegate(nsMenu); + } } void createItem (MenuItem item, int index) { if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); - NSMenuItem nsItem = null; - if ((item.style & SWT.SEPARATOR) != 0) { - nsItem = NSMenuItem.separatorItem(); - nsItem.retain(); + boolean add = true; + NSMenuItem nsItem = item.nsItem; + if (nsItem == null) { + if ((item.style & SWT.SEPARATOR) != 0) { + nsItem = NSMenuItem.separatorItem(); + nsItem.retain(); + } else { + nsItem = (NSMenuItem)new SWTMenuItem().alloc(); + NSString empty = NSString.string(); + nsItem.initWithTitle(empty, 0, empty); + nsItem.setTarget(nsItem); + nsItem.setAction(OS.sel_sendSelection); + } + item.nsItem = nsItem; } else { - nsItem = (NSMenuItem)new SWTMenuItem().alloc(); - NSString empty = NSString.string(); - nsItem.initWithTitle(empty, 0, empty); + int /*long*/ cls = OS.object_getClass(nsItem.id); + int /*long*/ dynNSMenuItem_class = display.createMenuItemSubclass(cls, "SWTSystemMenuItem", true); + if (cls != dynNSMenuItem_class) { + OS.object_setClass(nsItem.id, dynNSMenuItem_class); + } + nsItem.retain(); + item.nsItemAction = nsItem.action(); + item.nsItemTarget = nsItem.target(); nsItem.setTarget(nsItem); nsItem.setAction(OS.sel_sendSelection); + + // Sync native item type to Item's style. + int type = SWT.PUSH; + if (nsItem.isSeparatorItem()) type = SWT.SEPARATOR; + if (nsItem.submenu() != null) type = SWT.CASCADE; + item.style |= type; + + // Sync native item text to Item's text. + item.text = nsItem.title().getString(); + + // Sync native key equivalent to MenuItem's accelerator. + // The system menu on OS X only uses command and option, so it's + // safe to just check for those two key masks. + int /*long*/ keyMask = nsItem.keyEquivalentModifierMask(); + NSString keyEquivString = nsItem.keyEquivalent(); + int /*long*/ keyEquiv = 0; + if (keyEquivString != null) { + keyEquiv = keyEquivString.characterAtIndex(0); + if ((keyMask & OS.NSCommandKeyMask) != 0) keyEquiv |= SWT.COMMAND; + if ((keyMask & OS.NSAlternateKeyMask) != 0) keyEquiv |= SWT.ALT; + item.accelerator = (int) keyEquiv; + } + add = false; } - item.nsItem = nsItem; item.createJNIRef(); item.register(); - nsMenu.insertItem(nsItem, index); + if (add) { + nsMenu.insertItem(nsItem, index); + } if (itemCount == items.length) { MenuItem [] newItems = new MenuItem [items.length + 4]; System.arraycopy (items, 0, newItems, 0, items.length); @@ -359,17 +416,19 @@ void createItem (MenuItem item, int index) { } System.arraycopy (items, index, items, index + 1, itemCount++ - index); items [index] = item; - NSMenu emptyMenu = item.createEmptyMenu (); - if (emptyMenu != null) { - nsItem.setSubmenu (emptyMenu); - emptyMenu.release(); - } - if (display.menuBar == this) { - NSApplication application = display.application; - NSMenu menubar = application.mainMenu(); - if (menubar != null) { - nsItem.setMenu(null); - menubar.insertItem(nsItem, index + 1); + if (add) { + NSMenu emptyMenu = item.createEmptyMenu (); + if (emptyMenu != null) { + nsItem.setSubmenu (emptyMenu); + emptyMenu.release(); + } + if (display.menuBar == this) { + NSApplication application = display.application; + NSMenu menubar = application.mainMenu(); + if (menubar != null) { + nsItem.setMenu(null); + menubar.insertItem(nsItem, index + 1); + } } } //TODO - find a way to disable the menu instead of each item diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java index 5c17c0a314..dcd0305b52 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java @@ -40,6 +40,8 @@ public class MenuItem extends Item { NSMenuItem nsItem; Menu parent, menu; int accelerator; + int /*long*/ nsItemAction; + id nsItemTarget; /** * Constructs a new instance of this class given its parent @@ -123,6 +125,13 @@ public MenuItem (Menu parent, int style, int index) { parent.createItem (this, index); } +MenuItem (Menu parent, NSMenuItem nsMenuItem) { + super(parent, 0); + this.parent = parent; + this.nsItem = nsMenuItem; + parent.createItem(this, parent.getItemCount ()); +} + /** * Adds the listener to the collection of listeners who will * be notified when the arm events are generated for the control, by sending @@ -279,6 +288,21 @@ public boolean getEnabled () { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return (int)nsItem.tag(); +} + +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -535,7 +559,15 @@ void sendSelection () { } } } - sendSelectionEvent (SWT.Selection); + + Event event = new Event (); + sendSelectionEvent (SWT.Selection, event, nsItemAction != 0); + if (nsItemAction != 0) { + if (event.doit) { + NSApplication app = NSApplication.sharedApplication(); + app.sendAction(nsItemAction, nsItemTarget, app); + } + } } /** @@ -597,6 +629,25 @@ public void setEnabled (boolean enabled) { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + nsItem.setTag(id); +} + +/** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java index b3c2beee4b..943e03336a 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java @@ -3977,6 +3977,66 @@ public class SWT { public static final int ALL = 1 << 0; /** + * ID for the About menu item + * + * @see org.eclipse.swt.widgets.MenuItem#setId(int) + * @see org.eclipse.swt.widgets.MenuItem#getId() + * + * @since 3.7 + */ + public static final int ID_ABOUT = -1; + + /** + * ID for the Preferences menu item + * + * @see org.eclipse.swt.widgets.MenuItem#setId(int) + * @see org.eclipse.swt.widgets.MenuItem#getId() + * + * @since 3.7 + */ + public static final int ID_PREFERENCES = -2; + + /** + * ID for the Hide menu item + * + * @see org.eclipse.swt.widgets.MenuItem#setId(int) + * @see org.eclipse.swt.widgets.MenuItem#getId() + * + * @since 3.7 + */ + public static final int ID_HIDE = -3; + + /** + * ID for the Hide Others menu item + * + * @see org.eclipse.swt.widgets.MenuItem#setId(int) + * @see org.eclipse.swt.widgets.MenuItem#getId() + * + * @since 3.7 + */ + public static final int ID_HIDE_OTHERS = -4; + + /** + * ID for the Show All menu item + * + * @see org.eclipse.swt.widgets.MenuItem#setId(int) + * @see org.eclipse.swt.widgets.MenuItem#getId() + * + * @since 3.7 + */ + public static final int ID_SHOW_ALL= -5; + + /** + * ID for the Quit menu item + * + * @see org.eclipse.swt.widgets.MenuItem#setId(int) + * @see org.eclipse.swt.widgets.MenuItem#getId() + * + * @since 3.7 + */ + public static final int ID_QUIT = -6; + + /** * Key value for setting and getting the skin class of a widget. * * @see org.eclipse.swt.widgets.Widget#getData(String) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 419ce07c73..39301a66fe 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -2198,6 +2198,24 @@ public Image getSystemImage (int id) { return null; } +/** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + return null; +} + void initializeSystemColors () { GdkColor gdkColor; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java index ab048052e3..dda0b9534b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java @@ -39,7 +39,7 @@ import org.eclipse.swt.events.*; public class MenuItem extends Item { Menu parent, menu; int /*long*/ groupHandle; - int accelerator; + int accelerator, userId; /** * Constructs a new instance of this class given its parent @@ -349,6 +349,21 @@ public boolean getEnabled () { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return userId; +} + +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -644,6 +659,25 @@ public void setEnabled (boolean enabled) { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; +} + +/** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java index 7c01c80a99..c92fc1b025 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java @@ -1975,6 +1975,23 @@ public Image getSystemImage (int style) { return Image.motif_new (this, SWT.ICON, imagePixmap, maskPixmap); } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + return null; +} +/** * Returns the single instance of the system taskBar or null * when there is no system taskBar available for the platform. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java index 5dc8c8abf7..866bc9c3cb 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java @@ -37,7 +37,7 @@ import org.eclipse.swt.events.*; * @noextend This class is not intended to be subclassed by clients. */ public class MenuItem extends Item { - int accelerator; + int accelerator, userId; Menu parent, menu; /** @@ -375,6 +375,20 @@ public boolean getEnabled () { return argList [1] != 0; } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return userId; +} +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -689,6 +703,24 @@ public void setEnabled (boolean enabled) { } } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; +} +/** * Sets the receiver's pull down menu to the argument. * Only <code>CASCADE</code> menu items can have a * pull down menu. The sequence of key strokes, button presses diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java index 1c124f22ec..470f7df0ab 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java @@ -1368,6 +1368,24 @@ public Image getSystemImage (int id) { } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + return null; +} + +/** * Returns the single instance of the system taskBar or null * when there is no system taskBar available for the platform. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java index ec4107da36..b0bac18902 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java @@ -38,7 +38,7 @@ import org.eclipse.swt.events.*; */ public class MenuItem extends Item { Menu parent, menu; - int accelerator; + int accelerator, userId; /** * Constructs a new instance of this class given its parent @@ -319,6 +319,21 @@ public boolean getEnabled () { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return userId; +} + +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -646,6 +661,25 @@ public void setEnabled (boolean enabled) { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; +} + +/** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Display.java index 556a9398a9..2cfeeb524d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Display.java @@ -1559,6 +1559,24 @@ public class Display extends Device { } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ + public Menu getSystemMenu() { + checkDevice(); + return null; + } + + /** * Returns the single instance of the system tray or null when there is no * system tray available for the platform. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MenuItem.java index 479993bdec..4ea324fd6a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/MenuItem.java @@ -55,7 +55,7 @@ import org.eclipse.swt.internal.qt.QtSWTConverter; public class MenuItem extends Item { private QAction action; Menu parent, menu; - int id, accelerator; + int id, accelerator, userId; private HashMap<Integer, Integer> modifiers = new HashMap<Integer, Integer>(); private HashMap<Integer, Integer> accelerators = new HashMap<Integer, Integer>(); @@ -444,6 +444,21 @@ public class MenuItem extends Item { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ + public int getID () { + checkWidget(); + return userId; + } + + /** * Returns the receiver's cascade menu if it has one or null if it does not. * Only <code>CASCADE</code> menu items can have a pull down menu. The * sequence of key strokes, button presses and/or button releases that are @@ -804,6 +819,25 @@ public class MenuItem extends Item { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ + public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; + } + + /** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on platforms that do diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index 2d2eb80993..836ae78484 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -2528,6 +2528,24 @@ public Image getSystemImage (int id) { } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + return null; +} + +/** * Returns the single instance of the system taskBar or null * when there is no system taskBar available for the platform. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java index 5c90969be2..1e113187a4 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java @@ -39,7 +39,7 @@ import org.eclipse.swt.events.*; public class MenuItem extends Item { Menu parent, menu; int /*long*/ hBitmap; - int id, accelerator; + int id, accelerator, userId; /* * Feature in Windows. On Windows 98, it is necessary * to add 4 pixels to the width of the image or the image @@ -420,6 +420,21 @@ public boolean getEnabled () { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return userId; +} + +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -728,6 +743,25 @@ public void setEnabled (boolean enabled) { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; +} + +/** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java index f04f18a902..d65091bc48 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java @@ -1661,6 +1661,24 @@ public Image getSystemImage (int id) { } /** + * Returns the single instance of the system-provided menu for the application. + * On platforms where no menu is provided for the application this method returns null. + * + * @return the system menu or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.7 + */ +public Menu getSystemMenu () { + checkDevice(); + return null; +} + +/** * Returns the single instance of the system taskBar or null * when there is no system taskBar available for the platform. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java index a533ba9b62..5a3b80cfda 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java @@ -38,6 +38,7 @@ import org.eclipse.swt.events.*; public class MenuItem extends Item { Menu parent, menu; + int userId; /** * Constructs a new instance of this class given its parent @@ -314,6 +315,21 @@ public boolean getEnabled () { } /** + * Gets the identifier associated with the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.7 + */ +public int getID () { + checkWidget(); + return userId; +} + +/** * Returns the receiver's cascade menu if it has one or null * if it does not. Only <code>CASCADE</code> menu items can have * a pull down menu. The sequence of key strokes, button presses @@ -587,6 +603,25 @@ public void setEnabled (boolean enabled) { } /** + * Sets the identifier associated with the receiver to the argument. + * + * @param id the new identifier. This must be a non-negative value. System-defined identifiers are negative values. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_INVALID_ARGUMENT - if called with an negative-valued argument.</li> + * </ul> + * + * @since 3.7 + */ +public void setID (int id) { + checkWidget(); + if (id < 0) error(SWT.ERROR_INVALID_ARGUMENT); + userId = id; +} + +/** * Sets the image the receiver will display to the argument. * <p> * Note: This operation is a hint and is not supported on |