Pyro higlevel API
Classes | Public Member Functions | Friends | List of all members
os::MenuItem Class Reference

Menu item class. More...

Inheritance diagram for os::MenuItem:
os::Invoker os::CheckMenu os::MenuSeparator os::RadioMenuItem

Classes

class  Private
 

Public Member Functions

 MenuItem (const String &cLabel, Message *pcMsg, const String &cShortcut="", Image *pcImage=NULL)
 Constructor. More...
 
 MenuItem (Menu *pcMenu, Message *pcMsg, const String &cShortcut="", Image *pcImage=NULL)
 Constructor. More...
 
 ~MenuItem ()
 internal More...
 
MenuGetSubMenu () const
 Gets the Sub Menu(Menu that is inside the MenuItem)... More...
 
MenuGetSuperMenu () const
 Gets the Super Menu(Menu that holds the MenuItem)... More...
 
Rect GetFrame () const
 Gets the frame of the MenuItem... More...
 
virtual Point GetContentSize ()
 Gets the size of the MenuItem... More...
 
virtual float GetColumnWidth (int nColumn) const
 Gets the size of a column. More...
 
virtual int GetNumColumns () const
 Get number of columns. More...
 
const StringGetLabel () const
 Gets the label of the MenuItem... More...
 
void SetLabel (const os::String &cTitle)
 Sets the label of the MenuItem... More...
 
virtual void Draw ()
 Draws the os::MenuItem. More...
 
Point GetContentLocation () const
 Returns the current location of this item... More...
 
virtual bool Invoked (Message *pcMessage)
 Intercept outgoing messages. More...
 
void SetEnable (bool bEnabled)
 Tells the system to disable or enable this element... More...
 
bool IsEnabled () const
 Tells the programmer whether this element is enabled or disabled... More...
 
virtual void SetHighlighted (bool bHighlighted)
 Tells the system to highlight or unhighlight this element... More...
 
bool IsHighlighted () const
 Tells the programmer whether this element is highlighted or not highlighted... More...
 
ImageGetImage () const
 Gets the image that is attached to the MenuItem... More...
 
void SetImage (Image *pcImage, bool bRefresh=false)
 Sets the image that you want to attach to the MenuItem... More...
 
void SetShortcut (const String &cShortcut)
 Sets the shortcut for the MenuItem. More...
 
const StringGetShortcut () const
 Gets the shortcut for the menu item... More...
 
virtual bool IsSelectable () const
 Tells the system whether or not this item can be selected. More...
 
- Public Member Functions inherited from os::Invoker
 Invoker ()
 Default constructor. More...
 
 Invoker (Message *pcMessage)
 Constructor. More...
 
 Invoker (Message *pcMessage, const Handler *pcHandler, const Looper *pcLooper=NULL)
 Constructor. More...
 
 Invoker (Message *pcMessage, const Messenger &cTarget)
 Constructor. More...
 
virtual ~Invoker ()
 Destructor. More...
 
virtual status_t SetMessage (Message *pcMessage)
 Assign a new message to the invoker. More...
 
MessageGetMessage () const
 Get the message currently assigned to the invoker. More...
 
uint32 GetCode () const
 Get the code field from the currently assigned message. More...
 
virtual void TargetChanged (const Messenger &cOldTarget)
 Virtual hook called by the system after the target has been changed. More...
 
virtual void MessageChanged (const Message &cOldMsg)
 Virtual hook called by the system after the message has been changed. More...
 
virtual status_t SetTarget (const Handler *pcHandler, const Looper *pcLooper=NULL)
 Set a new message target. More...
 
virtual status_t SetTarget (const Messenger &cMessenger)
 Set a new message target. More...
 
bool IsTargetLocal () const
 Check if the target lives in our process. More...
 
HandlerGetTarget (Looper **ppcLooper=NULL) const
 Get the current target. More...
 
Messenger GetMessenger () const
 Get the messenger used to target messages sendt by the invoker. More...
 
virtual status_t SetHandlerForReply (Handler *pcHandler)
 Set a reply target for messages sendt by this messenger. More...
 
HandlerGetHandlerForReply () const
 Get the current reply target for replies on messages sendt by the invoker. More...
 
virtual status_t Invoke (Message *pcMessage=NULL)
 Send the current message to the current target. More...
 

Friends

class Menu
 

Detailed Description

Description:
The MenuItem class is what you use to insert into a menu
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx) with modifications by the Syllable team

Constructor & Destructor Documentation

MenuItem::MenuItem ( const String cLabel,
Message pcMsg,
const String cShortcut = "",
Image pcImage = NULL 
)
Description:
This MenuItem constructor will create a MenuItem with and Image attached to it.
Parameters
cLabel- The label that will be displayed.
pcMsg- The message that will be passed when invoked.
cShortcut- Keyboard shortcut.
pcImage- The image that will be attached to the MenuItem.
Example:
Menu* pcMenu = new Menu(Rect(),"main_menu",os::ITEMS_IN_ROW, CF_FOLLOW_LEFT | CF_FOLLOW_RIGHT | CF_FOLLOW_TOP ); //creates the main menu
Menu* pcSubMenu = new Menu(Rect(),"File", ITEMS_IN_COLUMN, CF_FOLLOW_LEFT | CF_FOLLOW_RIGHT | CF_FOLLOW_TOP ); //creates the file menu
File cFile = File("./options.png"); //not the best way to do this, because then options.png will need to be in the same directory as the application at all times.
Image* pcImage = new BitmapImage(&cFile);
MenuItem* pcItem("Options",NULL,pcImage) // creates the menu item with the sub menu and image.
pcSubMenu->AddItem(pcItem); //attaches the item to the file menu
pcMenu->AddItem(pcSubMenu) //attaches the file menu to the main menu
See Also
os::Menu, os::MenuSeparator
Author
Kurt Skauen(with modifications by the Syllable Team).

References os::MenuItem::Private::m_cLabel, os::MenuItem::Private::m_cShortcut, os::MenuItem::Private::m_pcMessage, and SetImage().

MenuItem::MenuItem ( Menu pcMenu,
Message pcMsg,
const String cShortcut = "",
Image pcImage = NULL 
)
Description:
This MenuItem constructor will create a menu item that holds a sub menu and attaches an image to the menuitem.
Parameters
pcMenu- The menu that will be a sub menu.
pcMsg- The message that will be passed when invoked.
cShortcut- Keyboard shortcut.
pcImage- The image that will be attached to this menu item.
Example:
Menu* pcMenu = new Menu(Rect(),"main_menu",os::ITEMS_IN_ROW, CF_FOLLOW_LEFT | CF_FOLLOW_RIGHT | CF_FOLLOW_TOP ); //creates the main menu
Menu* pcSubMenu = new Menu(Rect(),"File", ITEMS_IN_COLUMN, CF_FOLLOW_LEFT | CF_FOLLOW_RIGHT | CF_FOLLOW_TOP ); //creates the file menu
Menu* pcOptionsMenu = new Menu(Rect(),"Options", ITEMS_IN_COLUMN, CF_FOLLOW_LEFT | CF_FOLLOW_RIGHT | CF_FOLLOW_TOP ); //creates the option menu
File cFile = File("./options.png"); //not the best way to do this, because then options.png will need to be in the same directory as the application at all times.
Image* pcImage = new BitmapImage(&cFile);
MenuItem* pcItem(pcMenu,NULL,pcImage) // creates the menu item with the sub menu and image.
pcSubMenu->AddItem(pcItem); //attaches the item to the file menu
pcMenu->AddItem(pcSubMenu) //attaches the file menu to the main menu
See Also
os::Menu, os::MenuSeparator
Author
Kurt Skauen(with modifications by the Syllable Team).

References os::Menu::GetLabel(), os::MenuItem::Private::m_cLabel, os::MenuItem::Private::m_cShortcut, os::MenuItem::Private::m_pcMessage, os::MenuItem::Private::m_pcSubMenu, and SetImage().

MenuItem::~MenuItem ( )

Member Function Documentation

void MenuItem::Draw ( )
virtual
float MenuItem::GetColumnWidth ( int  nColumn) const
virtual
Description:
Gets the size of a column. Column 0 is the space used for icons, 1 is the space for text and 2 is the space normally used for shortcuts.
Returns
The width of the column
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::MenuItem::Private::GetImage(), GetLabel(), os::Image::GetSize(), GetSuperMenu(), os::View::GetTextExtent(), ICON_TO_TEXT_SPACE, os::MenuItem::Private::m_cShortcut, MIN_ICON_MARGIN, TITLE_TO_SHORTCUT_SPACE, width, os::Point::x, and os::Point::y.

Referenced by os::Menu::InvalidateLayout().

Point MenuItem::GetContentLocation ( ) const
Description:
Returns the current location of this item. It returns it as a os::Point
See Also
Author
Kurt Shauen (with modifications from the Syllable team)

References os::Rect::left, os::MenuItem::Private::m_cFrame, and os::Rect::top.

Point MenuItem::GetContentSize ( )
virtual
Rect MenuItem::GetFrame ( ) const
Description:
Gets the frame of the MenuItem.
Returns
The frame as an os::Rect
See Also
SetFrame()
Author
Kurt Skauen(with modifications from the Syllable team)

References os::MenuItem::Private::m_cFrame.

Referenced by os::RadioMenuItem::Draw(), os::CheckMenu::Draw(), Draw(), os::MenuSeparator::Draw(), os::Menu::GetItemAt(), and os::Menu::InvalidateLayout().

Image * MenuItem::GetImage ( void  ) const
Description:
Gets the image that is attached to the MenuItem.
Returns
This method will return an image pointer that is attached to the MenuItem. It will return a null Image if the Image is not set.
See Also
SetImage()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References os::MenuItem::Private::GetImage().

Referenced by Draw().

const String & MenuItem::GetLabel ( void  ) const
Description:
Gets the label of the MenuItem.
Returns
The label of the MenuItem as an os::String
Author
Kurt Skauen(with modifications from the Syllable team)

References os::MenuItem::Private::m_cLabel.

Referenced by os::RadioMenuItem::Draw(), os::CheckMenu::Draw(), Draw(), os::Menu::FindItem(), GetColumnWidth(), os::RadioMenuItem::GetContentSize(), os::CheckMenu::GetContentSize(), and GetContentSize().

int MenuItem::GetNumColumns ( ) const
virtual
Description:
Returns the number of columns. Normally there are three columns. Column 0 is the space used for icons, 1 is the space for text and 2 is the space normally used for shortcuts.
Returns
Number of columns
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

Referenced by os::Menu::InvalidateLayout().

const String & MenuItem::GetShortcut ( ) const
Description:
Gets the shortcut for the menu item...
Returns
Right now this will return a default shortcut(until we implement shortcuts)
See Also
SetShortcut()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References os::MenuItem::Private::m_cShortcut.

Menu * MenuItem::GetSubMenu ( ) const
Description:
Gets the Sub Menu(Menu that is inside the MenuItem)...
Returns
This method returns NULL if there is no Sub Menu and returns the Sub Menu(os::Menu) if there is a Sub Menu.
See Also
SetSubMenu()
Author
Kurt Skauen(with modifications from the Syllable team)

References os::MenuItem::Private::m_pcSubMenu.

Referenced by os::Menu::AddItem(), Draw(), os::Menu::FindItem(), GetContentSize(), os::Menu::GetIndexOf(), os::Menu::GetSubMenuAt(), os::Menu::KeyDown(), os::Menu::MouseUp(), os::Menu::RemoveItem(), os::Menu::SetEnable(), and os::Menu::SetTargetForItems().

Menu * MenuItem::GetSuperMenu ( ) const
Description:
Gets the Super Menu(Menu that holds the MenuItem)...
Returns
This method returns NULL if there is no Super Menu and retuns the Super Menu(os::Menu) if there is a Super Menu.
See Also
SetSuperMenu()
Author
Kurt Skauen(with modifications from the Syllable team)

References os::MenuItem::Private::m_pcSuperMenu.

Referenced by os::RadioMenuItem::Draw(), os::CheckMenu::Draw(), Draw(), os::MenuSeparator::Draw(), GetColumnWidth(), os::RadioMenuItem::GetContentSize(), os::CheckMenu::GetContentSize(), GetContentSize(), os::MenuSeparator::GetContentSize(), and os::Menu::GetSuperMenu().

bool MenuItem::Invoked ( Message pcMessage)
virtual
Description:
This member is called from Invoke() just before a message is sendt to the target.
This allow classes that inherits from os::Invoker to add data to or otherwhice modify the message before it is sendt. The message can also be canceled entirely by returning false from this member.
The message passed to Invoked() is a copy of the internal message or the message passed to Invoke() (if any) so any changes made here will not affect the internal message or the message passed to Invoke(). When this method returns the message will imidiatly be sendt to the target and then discarded (unless false is returned in which case the message is simply discarded).
The default implementation of this member does nothing and return true.
Parameters
pcMessagePointer to the message that is about to be sendt. You can do any modification you like to this message (but never delete it).
Returns
Normally you should return true to indicate that the message should be sendt. You can however return false if you for some reason want to cancel the invokation.
See Also
Invoke(), SetMessage(), SetTarget()
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

Reimplemented from os::Invoker.

Reimplemented in os::CheckMenu.

bool MenuItem::IsEnabled ( void  ) const
Description:
This method will tell programmer whether or not this element is enabled.
Returns
This method returns true if this MenuItem is enabled and false if it is not.
See Also
SetEnable()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References os::MenuItem::Private::m_bIsEnabled.

Referenced by Draw(), and os::Menu::MouseUp().

bool MenuItem::IsHighlighted ( ) const
Description:
This method will tell programmer whether this element is highlighted or not highlighted.
Returns
This method returns true if the MenuItem is highlighted and false if it is not.
See Also
SetHighlighed()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References os::MenuItem::Private::m_bIsHighlighted.

Referenced by os::Menu::FindMarked().

bool MenuItem::IsSelectable ( ) const
virtual
Description:
Tells the system whether or not this item can be selected.
Author
Rick Caudill(sylla.nosp@m.ble@.nosp@m.sylla.nosp@m.ble-.nosp@m.desk..nosp@m.tk)

Reimplemented in os::MenuSeparator, and os::CheckMenu.

References os::MenuItem::Private::m_bIsSelectable.

void MenuItem::SetEnable ( bool  bEnabled)
Description:
This method will tell the system to disable or enable this element.
Parameters
bEnabled- To enable this element set this to true(default) and to disable set this to false.
See Also
IsEnabled()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References Draw(), os::MenuItem::Private::m_bIsEnabled, and os::MenuItem::Private::m_bIsSelectable.

Referenced by os::IconDirectoryView::OpenContextMenu(), and os::Menu::SetEnable().

void MenuItem::SetHighlighted ( bool  bHighlighted)
virtual
Description:
This method will tell the system to highlight or unhighlight this element.
Parameters
bHighlighted- To highlight this element set this to true(default) and to unhighlight set this to false.
See Also
IsHighlighted()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

Reimplemented in os::MenuSeparator, os::CheckMenu, and os::RadioMenuItem.

References Draw(), and os::MenuItem::Private::m_bIsHighlighted.

Referenced by os::RadioMenuItem::SetHighlighted(), and os::CheckMenu::SetHighlighted().

void MenuItem::SetImage ( Image pcImage,
bool  bRefresh = false 
)
Description:
Sets the image that you want to attach to the MenuItem...
Parameters
pcImage- the image to be placed on the MenuItem.
bRefresh- tell the system whether to or not to redraw the MenuItem
See Also
GetImage()
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References Draw(), os::MenuItem::Private::FreeImages(), and os::MenuItem::Private::m_pcImage.

Referenced by MenuItem().

void MenuItem::SetLabel ( const os::String cLabel)
Description:
Sets the label of the MenuItem.
cLabel - The label of the MenuItem as an os::String
Author
Arno Klenke

References os::MenuItem::Private::m_cLabel.

void MenuItem::SetShortcut ( const String cShortcut)
Description:
Sets the shortcut for the MenuItem.
See Also
GetShortcut()
Parameters
cShortcut- The shortcut key that will invoke with this menuitem.
Author
Rick Caudill (sylla.nosp@m.ble_.nosp@m.deskt.nosp@m.op@h.nosp@m.otpop.nosp@m..com)

References os::MenuItem::Private::m_cShortcut.

Friends And Related Function Documentation

friend class Menu
friend