Menu

Instances of this class are user interface objects that contain menu items. <dl> <dt><b>Styles:</b></dt> <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd> <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd> <dt><b>Events:</b></dt> <dd>Help, Hide, Show </dd> </dl> <p> Note: Only one of BAR, DROP_DOWN and POP_UP may be specified. Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified. </p><p> IMPORTANT: This class is <em>not</em> intended to be subclassed. </p>

@see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a> @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

Constructors

this
this(Control parent)

Constructs a new instance of this class given its parent, and sets the style for the instance so that the instance will be a popup menu on the given parent's shell. <p> After constructing a menu, it can be set into its parent using <code>parent.setMenu(menu)</code>. In this case, the parent may be any control in the same widget tree as the parent. </p>

this
this(Decorations parent, int style)

Constructs a new instance of this class given its parent (which must be a <code>Decorations</code>) and a style value describing its behavior and appearance. <p> The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses. </p><p> After constructing a menu or menuBar, it can be set into its parent using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>. </p>

this
this(Menu parentMenu)

Constructs a new instance of this class given its parent (which must be a <code>Menu</code>) and sets the style for the instance so that the instance will be a drop-down menu on the given parent's parent. <p> After constructing a drop-down menu, it can be set into its parentMenu using <code>parentMenu.setMenu(menu)</code>. </p>

this
this(MenuItem parentItem)

Constructs a new instance of this class given its parent (which must be a <code>MenuItem</code>) and sets the style for the instance so that the instance will be a drop-down menu on the given parent's parent menu. <p> After constructing a drop-down menu, it can be set into its parentItem using <code>parentItem.setMenu(menu)</code>. </p>

Members

Functions

addHelpListener
void addHelpListener(HelpListener listener)

Adds the listener to the collection of listeners who will be notified when help events are generated for the control, by sending it one of the messages defined in the <code>HelpListener</code> interface.

addMenuListener
void addMenuListener(MenuListener listener)

Adds the listener to the collection of listeners who will be notified when menus are hidden or shown, by sending it one of the messages defined in the <code>MenuListener</code> interface.

getDefaultItem
MenuItem getDefaultItem()

Returns the default menu item or null if none has been previously set.

getEnabled
bool getEnabled()

Returns <code>true</code> if the receiver is enabled, and <code>false</code> otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.

getItem
MenuItem getItem(int index)

Returns the item at the given, zero-relative index in the receiver. Throws an exception if the index is out of range.

getItemCount
int getItemCount()

Returns the number of items contained in the receiver.

getItems
MenuItem[] getItems()

Returns a (possibly empty) array of <code>MenuItem</code>s which are the items in the receiver. <p> Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array will not affect the receiver. </p>

getParent
Decorations getParent()

Returns the receiver's parent, which must be a <code>Decorations</code>.

getParentItem
MenuItem getParentItem()

Returns the receiver's parent item, which must be a <code>MenuItem</code> or null when the receiver is a root.

getParentMenu
Menu getParentMenu()

Returns the receiver's parent item, which must be a <code>Menu</code> or null when the receiver is a root.

getShell
Shell getShell()

Returns the receiver's shell. For all controls other than shells, this simply returns the control's nearest ancestor shell. Shells return themselves, even if they are children of other shells.

getVisible
bool getVisible()

Returns <code>true</code> if the receiver is visible, and <code>false</code> otherwise. <p> If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing. </p>

indexOf
int indexOf(MenuItem item)

Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item. If no item is found, returns -1.

isEnabled
bool isEnabled()

Returns <code>true</code> if the receiver is enabled and all of the receiver's ancestors are enabled, and <code>false</code> otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.

isVisible
bool isVisible()

Returns <code>true</code> if the receiver is visible and all of the receiver's ancestors are visible and <code>false</code> otherwise.

removeHelpListener
void removeHelpListener(HelpListener listener)

Removes the listener from the collection of listeners who will be notified when the help events are generated for the control.

removeMenuListener
void removeMenuListener(MenuListener listener)

Removes the listener from the collection of listeners who will be notified when the menu events are generated for the control.

setDefaultItem
void setDefaultItem(MenuItem item)

Sets the default menu item to the argument or removes the default emphasis when the argument is <code>null</code>.

setEnabled
void setEnabled(bool enabled)

Enables the receiver if the argument is <code>true</code>, and disables it otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.

setLocation
void setLocation(int x, int y)

Sets the location of the receiver, which must be a popup, to the point specified by the arguments which are relative to the display. <p> Note that this is different from most widgets where the location of the widget is relative to the parent. </p><p> Note that the platform window manager ultimately has control over the location of popup menus. </p>

setLocation
void setLocation(Point location)

Sets the location of the receiver, which must be a popup, to the point specified by the argument which is relative to the display. <p> Note that this is different from most widgets where the location of the widget is relative to the parent. </p><p> Note that the platform window manager ultimately has control over the location of popup menus. </p>

setVisible
void setVisible(bool visible)

Marks the receiver as visible if the argument is <code>true</code>, and marks it invisible otherwise. <p> If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed. </p>

Inherited Members

From Widget

handle
GtkWidget* handle;

the handle to the OS resource (Warning: This field is platform dependent) <p> <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code. </p>

addListener
void addListener(int eventType, Listener listener)

Adds the listener to the collection of listeners who will be notified when an event of the given type occurs. When the event does occur in the widget, the listener is notified by sending it the <code>handleEvent()</code> message. The event type is one of the event constants defined in class <code>SWT</code>.

addDisposeListener
void addDisposeListener(DisposeListener listener)

Adds the listener to the collection of listeners who will be notified when the widget is disposed. When the widget is disposed, the listener is notified by sending it the <code>widgetDisposed()</code> message.

checkParent
void checkParent(Widget parent)

Throws an exception if the specified widget can not be used as a parent for the receiver.

checkSubclass
void checkSubclass()

Checks that this class can be subclassed. <p> The SWT class library is intended to be subclassed only at specific, controlled points (most notably, <code>Composite</code> and <code>Canvas</code> when implementing new widgets). This method enforces this rule unless it is overridden. </p><p> <em>IMPORTANT:</em> By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion. </p><p> The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy. </p>

checkWidget
void checkWidget()

Throws an <code>SWTException</code> if the receiver can not be accessed by the caller. This may include both checks on the state of the receiver and more generally on the entire execution context. This method <em>should</em> be called by widget implementors to enforce the standard SWT invariants. <p> Currently, it is an error to invoke any method (other than <code>isDisposed()</code>) on a widget that has had its <code>dispose()</code> method called. It is also an error to call widget methods from any thread that is different from the thread that created the widget. </p><p> In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons. </p>

dispose
void dispose()

Disposes of the operating system resources associated with the receiver and all its descendants. After this method has been invoked, the receiver and all descendants will answer <code>true</code> when sent the message <code>isDisposed()</code>. Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection. <p> NOTE: This method is not called recursively on the descendants of the receiver. This means that, widget implementers can not detect when a widget is being disposed of by re-implementing this method, but should instead listen for the <code>Dispose</code> event. </p>

getData
Object getData()

Returns the application defined widget data associated with the receiver, or null if it has not been set. The <em>widget data</em> is a single, unnamed field that is stored with every widget. <p> Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so. </p>

getData
Object getData(String key)

Returns the application defined property of the receiver with the specified name, or null if it has not been set. <p> Applications may have associated arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so. </p>

getDisplay
Display getDisplay()

Returns the <code>Display</code> that is associated with the receiver. <p> A widget's display is either provided when it is created (for example, top level <code>Shell</code>s) or is the same as its parent's display. </p>

getListeners
Listener[] getListeners(int eventType)

Returns an array of listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in class <code>SWT</code>.

getStyle
int getStyle()

Returns the receiver's style information. <p> Note that the value which is returned by this method <em>may not match</em> the value which was provided to the constructor when the receiver was created. This can occur when the underlying operating system does not support a particular combination of requested styles. For example, if the platform widget used to implement a particular SWT widget always has scroll bars, the result of calling this method would always have the <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set. </p>

isDisposed
bool isDisposed()

Returns <code>true</code> if the widget has been disposed, and <code>false</code> otherwise. <p> This method gets the dispose state for the widget. When a widget has been disposed, it is an error to invoke any other method using the widget. </p>

isListening
bool isListening(int eventType)

Returns <code>true</code> if there are any listeners for the specified event type associated with the receiver, and <code>false</code> otherwise. The event type is one of the event constants defined in class <code>SWT</code>.

notifyListeners
void notifyListeners(int eventType, Event event)

Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking their <code>handleEvent()</code> method. The event type is one of the event constants defined in class <code>SWT</code>.

removeListener
void removeListener(int eventType, Listener handler)

Removes the listener from the collection of listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in class <code>SWT</code>.

removeListener
void removeListener(int eventType, SWTEventListener handler)

Removes the listener from the collection of listeners who will be notified when an event of the given type occurs. <p> <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It should never be referenced from application code. </p>

removeDisposeListener
void removeDisposeListener(DisposeListener listener)

Removes the listener from the collection of listeners who will be notified when the widget is disposed.

setData
void setData(Object data)

Sets the application defined widget data associated with the receiver to be the argument. The <em>widget data</em> is a single, unnamed field that is stored with every widget. <p> Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so. </p>

setData
void setData(String key, Object value)

Sets the application defined property of the receiver with the specified name to the given value. <p> Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so. </p>

toString
String toString()

Returns a string containing a concise, human-readable description of the receiver.

Meta