Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

NSMenuMBS.addItem(m as NSMenuItemMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Adds a menu item to the end.
Notes:
If the menuitem is nil, nothing happens.
The menuitem can only be in one menu.

The menu doesn't references to the RB classes behind, so it's up to you to keep those references if you want to get the events and avoid crashes.
The StatusItem example keeps an array with all those menu item objects it needs so RB will not destroy them.

Feedback, Comments & Corrections

NSMenuMBS.cancelTracking
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Dismisses the menu and ends all menu tracking.
Notes: Available in Mac OS X v10.5 and later.

Feedback, Comments & Corrections

NSMenuMBS.cancelTrackingWithoutAnimation
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Dismisses the menu and ends all menu tracking without displaying the associated animation.
Notes: Available in Mac OS X v10.6 and later.

Feedback, Comments & Corrections

NSMenuMBS.CarbonMenuRef as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 11.2 Yes No No Yes, macOS only No
Function: Queries the Carbon Menu Reference for this Cocoa menu.
Notes:
This is an undocumented API from Apple.
You only get a handle if the menu has been added to the menubar or popuped up.
Returns zero on failure. Returns always zero on 64 bit target.

Feedback, Comments & Corrections

NSMenuMBS.Constructor(Handle as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 15.2 Yes No No Yes, macOS only No
Function: Constructor for creating an instanced based on an existing handle.
Notes:
Useful if you get a NSMenu reference from a declare.
The object is retained.

See also:

Feedback, Comments & Corrections

NSMenuMBS.Constructor(title as string="")
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 7.4 Yes No No Yes, macOS only No
Function: Constructor for a new nsmenu.
Example:
dim m as NSMenuMBS
m=new NSMenuMBS("Hello World")
msgbox m.title // shows "Hello World"
Notes: Title is optional.

See also:

Feedback, Comments & Corrections

NSMenuMBS.indexOfItem(item as NSMenuItemMBS) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Returns the index identifying the location of a specified menu item in the receiver.
Notes: Returns the integer index of the menu item or, if no such menu item is in the menu, –1.

Feedback, Comments & Corrections

NSMenuMBS.indexOfItemWithSelector(selector as string) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 13.1 Yes No No Yes, macOS only No
Function: Searches menu items for one with the given selector.
Notes:
Returns -1 if not found.
You can use this to find menu items by their selector. Which is often more save than by index or title.

Feedback, Comments & Corrections

NSMenuMBS.indexOfItemWithSubmenu(item as NSMenuMBS) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Returns the index of the menu item in the receiver with the given submenu.
Notes:
item: A menu object that is a menu item of the receiver (that is, a submenu).

The integer index of the menu item or, if no such menu item is in the menu, –1.

Feedback, Comments & Corrections

NSMenuMBS.indexOfItemWithTag(tag as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Returns the index of the first menu item in the receiver identified by a tag.
Notes: Returns the integer index of the menu item or, if no such menu item is in the menu, –1.

Feedback, Comments & Corrections

NSMenuMBS.indexOfItemWithTitle(title as string) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Returns the index of the first menu item in the receiver that has a specified title.
Notes: The integer index of the menu item or, if no such menu item is in the menu, –1.

Feedback, Comments & Corrections

NSMenuMBS.insertItem(m as NSMenuItemMBS, index as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Inserts a menu item into the menu at a specific location.
Notes:
If the menuitem is nil, nothing happens. A menuitem can only be part of one menu.

index: An integer index identifying the location of the menu item in the menu. Zero based.

Feedback, Comments & Corrections

NSMenuMBS.Item(index as Integer) as NSMenuItemMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Returns the item with the given index.
Notes:
Index is from 0 to numberOfItems-1.
Remember: The objects returned are not the same Realbasic objects used with additem or insertitem.

Feedback, Comments & Corrections

NSMenuMBS.itemWithSelector(selector as string) as NSMenuItemMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 13.1 Yes No No Yes, macOS only No
Function: Searches menu items for one with the given selector.
Notes: You can use this to find menu items by their selector. Which is often more save than by index or title.

Feedback, Comments & Corrections

NSMenuMBS.performActionForItemAtIndex(index as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Causes the application to send the action message of a specified menu item to its target.
Notes:
If a target is not specified, the message is sent to the first responder. As a side effect, this method posts NSMenuWillSendActionNotification and NSMenuDidSendActionNotification.

In Mac OS X v10.6 and laster the performActionForItemAtIndex no longer triggers menu validation. This is because validation is typically done during menu tracking or key equivalent matching, so the subsequent performActionForItemAtIndex validation was redundant. To trigger validation explicitly, use invoke the update method.

In Mac OS X v10.6 performActionForItemAtIndex, when called, now triggers highlighting in the menu bar. It also sends out appropriate accessibility notifications indicating the item was selected.

Feedback, Comments & Corrections

NSMenuMBS.popUpMenuPositioningItem(item as NSMenuItemMBS, location as NSPointMBS, view as NSViewMBS = nil) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 14.2 Yes No No Yes, macOS only No
Function: Pops up the menu at the specified location.
Example:
// create menu
dim m as new NSMenuMBS
m.autoenablesItems = false

// add some items
dim it as new NSMenuItemMBS
it.CreateMenuItem "Hello"
it.Enabled = true
m.addItem it

it = new NSMenuItemMBS
it.CreateMenuItem "World"
it.Enabled = true
m.addItem it

// show relative to this view
dim v as NSViewMBS = window1.PushButton1.NSViewMBS

dim r as Boolean
r = m.popUpMenuPositioningItem(nil, nil, v)
// you need to use NSMenuItemMBS subclasses with action event to get an event for which item was selected...
Notes:
item: The menu item to be positioned at the specified location in the view.
location: The location in the view coordinate system to display the menu item.
view: The view to display the menu item over.

Returns true if menu tracking ended because an item was selected, and false if menu tracking was cancelled for any reason.

Pops up the receiver as a popup menu. The top left corner of the specified item (if specified, item must be present in the receiver) is positioned at the specified location in the specified view, interpreted in the view's own coordinate system.

If item is nil, the menu is positioned such that the top left of the menu content frame is at the given location.
If view is nil, the location is interpreted in the screen coordinate system. This allows you to pop up a menu disconnected from any window.

Available in OS X v10.6 and later.

Feedback, Comments & Corrections

NSMenuMBS.removeAllItems
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Removes all the menu items in the receiver.
Example:
dim n as NSMenuMBS // your menu

// for Mac OS X 10.6
n.removeAllItems

// for any Mac OS X version
for i as Integer = n.numberOfItems-1 DownTo 0
n.removeItemAtIndex i
next
Notes:
This method is more efficient than removing menu items individually.
Unlike the other remove methods, this method does not post NSMenuDidChangeItemNotification notifications.
Available in Mac OS X v10.6 and later.

Feedback, Comments & Corrections

NSMenuMBS.removeItem(m as NSMenuItemMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Removes the menuitem.
Notes:
Does nothing if menuitem is nil.

The Realbasic object used to add the menuitem must not be the same as the one you use here, but the values for the menuitems handle property must match.

Feedback, Comments & Corrections

NSMenuMBS.removeItemAtIndex(index as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Removes the menu item with the given index.
Example:
dim n as NSMenuMBS // your menu

// for Mac OS X 10.6
n.removeAllItems

// for any Mac OS X version
for i as Integer = n.numberOfItems-1 DownTo 0
n.removeItemAtIndex i
next
Notes: Index is from 0 to NumberOfItems-1.

Feedback, Comments & Corrections

NSMenuMBS.update
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Menus MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Enables or disables the receiver's menu items based on the NSMenuValidation informal protocol and sizes the menu to fit its current menu items if necessary.

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacBase Plugin.




Links
MBS FileMaker tutorial videos