All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | Protected Member Functions | Protected Attributes
GUI::Menu Class Reference

A popup menu. More...

#include <gui_tk.h>

Inheritance diagram for GUI::Menu:
GUI::TransientWindow GUI::ActionEventSource GUI::Window GUI::Window_Callback GUI::ToplevelWindow_Callback

List of all members.

Public Member Functions

template<typename STR >
 Menu (Window *parent, int x, int y, const STR name)
 Create a menu with given position.
virtual void paint (Drawable &d) const
 Paint button.
virtual bool mouseMoved (int x, int y)
 Highlight current item.
virtual bool mouseDragged (int x, int y, MouseButton button)
 Highlight current item.
virtual bool mouseDown (int x, int y, MouseButton button)
 Mouse was pressed. Returns true if event was handled.
virtual bool mouseUp (int x, int y, MouseButton button)
 Possibly select item.
virtual bool keyDown (const Key &key)
 Handle keyboard input.
template<typename T >
void addItem (const T item)
 Add a menu item at end. An empty string denotes a separator.
template<typename T >
void removeItem (const T item)
 Remove an existing menu item.
virtual void setVisible (bool v)
 Show or hide this window.
void execute ()
 Execute menu item.

Protected Member Functions

virtual void selectItem (int x, int y)
 Selects menu item at position (x,y).
virtual Size getPreferredWidth ()
virtual Size getPreferredHeight ()

Protected Attributes

std::vector< Stringitems
 List of menu items (displayed text)
int selected
 Currently selected menu item.
bool firstMouseUp
 Flag to skip the first mouseUp-event.
 Where we grabbed the mouse from.

Detailed Description

A popup menu.

Popup menus are used as context menus or as part of a menu bar. Menus are not visible when created. Menus have a name which can be used in event handlers to identify it, and it is used in Menubars as well.

Currently, menu entries are not interpreted in any way. This may change in the future. To ensure upwards compatibility, avoid the '&' character in menu entries, since it may have a special meaning in future versions. Menus use the Font named "menu".

Please note the general remarks in GUI::TransientWindow

Definition at line 1773 of file gui_tk.h.

Constructor & Destructor Documentation

template<typename STR >
GUI::Menu::Menu ( Window parent,
int  x,
int  y,
const STR  name 
) [inline]

Create a menu with given position.

Size is determined dynamically. parent is the logical parent. The true parent object is always the screen the logical parent resides on.

Definition at line 1829 of file gui_tk.h.

References setVisible().

Member Function Documentation

virtual void GUI::Menu::selectItem ( int  x,
int  y 
) [inline, protected, virtual]

Selects menu item at position (x,y).

selected is set to -1 if there is no active item at that location.

Definition at line 1790 of file gui_tk.h.

References GUI::Font::getFont(), GUI::Font::getHeight(), GUI::Window::height, items, and selected.

Referenced by mouseDragged(), mouseMoved(), and mouseUp().

virtual void GUI::Menu::setVisible ( bool  v) [inline, virtual]

Show or hide this window.

By default, most windows are shown when created. Hidden windows do not receive any events.

Reimplemented from GUI::TransientWindow.

Definition at line 1900 of file gui_tk.h.

References firstMouseUp, GUI::Window::mouseChild, and GUI::Window::parent.

Referenced by execute(), keyDown(), Menu(), GUI::ToplevelWindow::mouseDown(), and mouseUp().

Member Data Documentation

int GUI::Menu::selected [protected]

Currently selected menu item.

Can be -1 if no item is currently active.

Definition at line 1780 of file gui_tk.h.

Referenced by execute(), keyDown(), paint(), and selectItem().

The documentation for this class was generated from the following files: