Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

PG_PopupMenu Class Reference

A stand-alone or attached popup menu. More...

#include <pgpopupmenu.h>

Inheritance diagram for PG_PopupMenu:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 PG_PopupMenu (PG_Widget *parent, int x, int y, const std::string &caption=PG_NULLSTR, const std::string &style="PopupMenu")
 ~PG_PopupMenu ()
PG_PopupMenuaddSeparator ()
bool SetMenuItemSlot (int id, MenuItem::MenuItemSlot slot, PG_Pointer clientdata=NULL)
int maxItemWidth () const
void disableItem (int dd)
void enableItem (int id)
void trackMenu (int x=-1, int y=-1)
 Modal popup menu will be shown - i.e.
void openMenu (int x=-1, int y=-1)
Add a new menu item to this menu
Constructs a new menu item using the provided parameters and then adds the item to this menu.

PG_PopupMenuaddMenuItem (const std::string &caption, int ID, MenuItem::MenuItemSlot, PG_Pointer data=NULL, MenuItem::MI_FLAGS flags=MenuItem::MIF_NONE)
 Adds a menu item whose handler (if any) is set to be a stand-alone function.
PG_PopupMenuaddMenuItem (const std::string &caption, int ID, MenuItem::MI_FLAGS flags=MenuItem::MIF_NONE)
PG_PopupMenuaddMenuItem (const std::string &caption, PG_PopupMenu *sub, MenuItem::MI_FLAGS flags=MenuItem::MIF_SUBMENU)

Public Attributes

SignalSelectMenuItem sigSelectMenuItem

Protected Types

typedef std::list< MenuItem
* >::iterator 
MII

Protected Member Functions

void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
 overridable eventhandler to blit the widget contents to the screen
void eventMouseEnter ()
 eventhandler for mouse movements.
void eventMouseLeave ()
 eventhandler for mouse movements.
bool eventMouseMotion (const SDL_MouseMotionEvent *motion)
 Overridable Eventhandler for a SDL_MouseMotionEvent message.
bool eventMouseButtonDown (const SDL_MouseButtonEvent *button)
 Overridable Eventhandler for a SDL_MouseButtonEvent message.
bool eventMouseButtonUp (const SDL_MouseButtonEvent *button)
 Overridable Eventhandler for a SDL_MouseButtonEvent message.
bool eventKeyDown (const SDL_KeyboardEvent *key)
 Overridable Eventhandler for a SDL_KeyboardEvent message.
void eventMoveWidget (int x, int y)
 Callback for the MoveWidget event.
void eventShow ()
 overridable eventhandler called whenever the widget gets shown.
void eventHide ()
 overridable eventhandler called whenever the widget gets hidden.
void LoadThemeStyle (const std::string &widgettype)
 Load a specific themestyle.
void LoadThemeStyle (const std::string &widgettype, const std::string &objectname)
 Load a style from the theme definition.
virtual bool getCaptionHeight (PG_Rect &rect, bool constructing=false)
virtual void recalcRect ()
virtual void handleClick (int x, int y)
virtual void enslave (PG_PopupMenu *master)
virtual void liberate ()

Protected Attributes

std::list< MenuItem * > items
std::string myCaption
 the menu items collection
PG_Color captionActiveColor
 menu caption
PG_Color captionInactiveColor
PG_Color miNormalColor
PG_Color miSelectedColor
PG_Color miDisabledColor
PG_Color sepNormalColor
PG_Color sepShadowColor
int xPadding
int yPadding
int minTabWidth
 if a menu entry has a right justified component ( e.g.
int separatorLineWidth

Classes

class  item_with_id
class  MenuItem
 A menu item data structure. More...
class  SignalSelectMenuItem
 Signal type declaration. More...

Detailed Description

A stand-alone or attached popup menu.

Author:
Marek Habersack
A popup menu that can be attached to a menu bar or used stand-alone. In the first case, the widget sizes itself so that only the caption is visible, the menu items remain hidden until menu is activated. In the latter case menu sizes itself to encompass all of its items unless the menu size would exceed the space between the menu origin and the edge of the screen. In such case, menu displays a "scroller" button at the bottom.

Todo:
implement the scroller code (menu scrolling when it exceeds the screen height/width - a kind of specialized widgetlist).

keyboard handling (accelerators, ESC/ENTER & arrows)

Should display a scroller icon at the bottom/top of the popup menu - a'la w2k.

Definition at line 68 of file pgpopupmenu.h.


Member Typedef Documentation

typedef std::list<MenuItem*>::iterator PG_PopupMenu::MII [protected]
 

Definition at line 270 of file pgpopupmenu.h.


Constructor & Destructor Documentation

PG_PopupMenu::PG_PopupMenu PG_Widget parent,
int  x,
int  y,
const std::string &  caption = PG_NULLSTR,
const std::string &  style = "PopupMenu"
 

Definition at line 227 of file pgpopupmenu.cpp.

References getCaptionHeight(), items, LoadThemeStyle(), PG_Widget::MoveWidget(), PG_Rect::my_height, PG_Rect::my_width, PG_Rect::my_xpos, myCaption, PG_Rect::PG_Rect(), xPadding, and yPadding.

PG_PopupMenu::~PG_PopupMenu  ) 
 

Definition at line 262 of file pgpopupmenu.cpp.

References PG_FileArchive::UnloadSurface().


Member Function Documentation

PG_PopupMenu & PG_PopupMenu::addMenuItem const std::string &  caption,
PG_PopupMenu sub,
MenuItem::MI_FLAGS  flags = MenuItem::MIF_SUBMENU
 

Definition at line 318 of file pgpopupmenu.cpp.

PG_PopupMenu & PG_PopupMenu::addMenuItem const std::string &  caption,
int  ID,
MenuItem::MI_FLAGS  flags = MenuItem::MIF_NONE
 

Definition at line 308 of file pgpopupmenu.cpp.

PG_PopupMenu & PG_PopupMenu::addMenuItem const std::string &  caption,
int  ID,
MenuItem::MenuItemSlot  ,
PG_Pointer  data = NULL,
MenuItem::MI_FLAGS  flags = MenuItem::MIF_NONE
 

Adds a menu item whose handler (if any) is set to be a stand-alone function.

Parameters:
caption the item caption
ID the item identifier
data application-specific data associated with the menu item action.
flags menu item flags

Definition at line 295 of file pgpopupmenu.cpp.

References PG_Signal1< P1, datatype >::connect(), and PG_PopupMenu::MenuItem::sigSelectMenuItem.

Referenced by addSeparator(), InfoPopUp::InfoPopUp(), and XMLStartDoc().

PG_PopupMenu & PG_PopupMenu::addSeparator  ) 
 

Returns:
a reference to this menu

Definition at line 347 of file pgpopupmenu.cpp.

References addMenuItem(), PG_PopupMenu::MenuItem::MIF_SEPARATOR, and PG_NULLSTR.

Referenced by Menu::setup().

void PG_PopupMenu::disableItem int  dd  ) 
 

Definition at line 352 of file pgpopupmenu.cpp.

void PG_PopupMenu::enableItem int  id  ) 
 

Definition at line 360 of file pgpopupmenu.cpp.

void PG_PopupMenu::enslave PG_PopupMenu master  )  [protected, virtual]
 

Definition at line 488 of file pgpopupmenu.cpp.

void PG_PopupMenu::eventBlit SDL_Surface *  surface,
const PG_Rect src,
const PG_Rect dst
[protected, virtual]
 

overridable eventhandler to blit the widget contents to the screen

Parameters:
surface pointer to SDL_Surface to be blitted
src source rectangle (client coordinates)
dst destination rectangle (screen coordinates) Override this eventhandler to perform custom blitting behaviour (without drawing onto the widget surface).

Reimplemented from PG_ThemeWidget.

Definition at line 510 of file pgpopupmenu.cpp.

References captionActiveColor, PG_Widget::DrawText(), PG_Draw::DrawThemedSurface(), PG_ThemeWidget::eventBlit(), PG_Application::GetScreen(), PG_PopupMenu::MenuItem::isDisabled(), PG_PopupMenu::MenuItem::isSelected(), PG_PopupMenu::MenuItem::isSeparator(), items, PG_PopupMenu::MenuItem::measureItem(), miDisabledColor, miNormalColor, miSelectedColor, PG_Rect::my_xpos, PG_Rect::my_ypos, myCaption, PG_PopupMenu::MenuItem::paintDisabled(), PG_PopupMenu::MenuItem::paintNormal(), PG_PopupMenu::MenuItem::paintSelected(), sepNormalColor, sepShadowColor, and PG_Widget::SetFontColor().

void PG_PopupMenu::eventHide  )  [protected, virtual]
 

overridable eventhandler called whenever the widget gets hidden.

Reimplemented from PG_Widget.

Definition at line 838 of file pgpopupmenu.cpp.

References PG_Widget::eventHide(), and PG_MessageObject::ReleaseCapture().

bool PG_PopupMenu::eventKeyDown const SDL_KeyboardEvent *  key  )  [protected, virtual]
 

Overridable Eventhandler for a SDL_KeyboardEvent message.

This handler is called when a key changed it's state from unpressed to pressed. The default implementation returns 'false' which indicates that this message is not processed by this object.

Parameters:
key SDL_KeyboardEvent message
Returns:
Notifies the message pump if this message is processed by this object or it should be routed to the next message receiver.

Reimplemented from PG_MessageObject.

Definition at line 734 of file pgpopupmenu.cpp.

References PG_Widget::extractHotkey(), PG_Widget::Hide(), PG_PopupMenu::MenuItem::isDisabled(), items, PG_Widget::Redraw(), PG_PopupMenu::MenuItem::sigSelectMenuItem, sigSelectMenuItem, PG_Application::TranslateNumpadKeys(), and PG_PopupMenu::MenuItem::unselect().

bool PG_PopupMenu::eventMouseButtonDown const SDL_MouseButtonEvent *  button  )  [protected, virtual]
 

Overridable Eventhandler for a SDL_MouseButtonEvent message.

This handler is called when a mouse button is pressed. The default implementation returns 'false' which indicates that this message is not processed by this object.

Parameters:
button SDL_MouseButtonEvent message
Returns:
Notifies the message pump if this message is processed by this object or it should be routed to the next message receiver.

Reimplemented from PG_MessageObject.

Definition at line 699 of file pgpopupmenu.cpp.

References PG_MessageObject::eventMouseButtonDown().

bool PG_PopupMenu::eventMouseButtonUp const SDL_MouseButtonEvent *  button  )  [protected, virtual]
 

Overridable Eventhandler for a SDL_MouseButtonEvent message.

This handler is called when a mouse button is released. The default implementation returns 'false' which indicates that this message is not processed by this object.

Parameters:
button SDL_MouseButtonEvent message
Returns:
Notifies the message pump if this message is processed by this object or it should be routed to the next message receiver.

Reimplemented from PG_MessageObject.

Definition at line 710 of file pgpopupmenu.cpp.

References PG_MessageObject::eventMouseButtonUp(), handleClick(), PG_Widget::Hide(), and PG_PopupMenu::MenuItem::isSeparator().

void PG_PopupMenu::eventMouseEnter  )  [protected, virtual]
 

eventhandler for mouse movements.

This overrideable handler is called everytime the mouse cursor is entering the widget area.

Reimplemented from PG_Widget.

Definition at line 889 of file pgpopupmenu.cpp.

References PG_Widget::eventMouseEnter().

void PG_PopupMenu::eventMouseLeave  )  [protected, virtual]
 

eventhandler for mouse movements.

This overrideable handler is called everytime the mouse cursor is leaving the widget area.

Reimplemented from PG_Widget.

Definition at line 893 of file pgpopupmenu.cpp.

References PG_Widget::eventMouseLeave().

bool PG_PopupMenu::eventMouseMotion const SDL_MouseMotionEvent *  motion  )  [protected, virtual]
 

Overridable Eventhandler for a SDL_MouseMotionEvent message.

This handler is called when mouse movement is detected. The default implementation returns 'false' which indicates that this message is not processed by this object.

Parameters:
motion SDL_MouseMotionEvent message
Returns:
Notifies the message pump if this message is processed by this object or it should be routed to the next message receiver.

Reimplemented from PG_MessageObject.

Definition at line 646 of file pgpopupmenu.cpp.

References PG_Rect::IsInside(), items, PG_Rect::my_xpos, PG_Rect::my_ypos, PG_Widget::ProcessEvent(), PG_Widget::Redraw(), PG_MessageObject::ReleaseCapture(), PG_Point::x, and PG_Point::y.

void PG_PopupMenu::eventMoveWidget int  x,
int  y
[protected, virtual]
 

Callback for the MoveWidget event.

Parameters:
x new x position
y new y position This virtual function can be used to implement custom behavior for MoveWidget events.

Reimplemented from PG_Widget.

Definition at line 821 of file pgpopupmenu.cpp.

References PG_Widget::eventMoveWidget(), PG_Rect::my_height, PG_Rect::my_xpos, PG_Rect::my_ypos, xPadding, and yPadding.

void PG_PopupMenu::eventShow  )  [protected, virtual]
 

overridable eventhandler called whenever the widget gets shown.

Reimplemented from PG_Widget.

Definition at line 828 of file pgpopupmenu.cpp.

References PG_Widget::eventShow(), and PG_MessageObject::SetCapture().

bool PG_PopupMenu::getCaptionHeight PG_Rect rect,
bool  constructing = false
[protected, virtual]
 

Definition at line 397 of file pgpopupmenu.cpp.

References PG_Widget::GetTextSize(), PG_Rect::my_height, PG_Rect::my_width, PG_Rect::my_xpos, PG_Rect::my_ypos, and myCaption.

Referenced by PG_PopupMenu(), and recalcRect().

void PG_PopupMenu::handleClick int  x,
int  y
[protected, virtual]
 

Definition at line 462 of file pgpopupmenu.cpp.

References PG_Rect::IsInside(), PG_PopupMenu::MenuItem::isMute(), PG_PopupMenu::MenuItem::isSubMenu(), liberate(), sigSelectMenuItem, PG_PopupMenu::MenuItem::sigSelectMenuItem, PG_PopupMenu::MenuItem::unselect(), PG_Point::x, and PG_Point::y.

Referenced by eventMouseButtonUp().

void PG_PopupMenu::liberate  )  [protected, virtual]
 

Definition at line 492 of file pgpopupmenu.cpp.

References PG_Widget::Hide(), and liberate().

Referenced by handleClick(), and liberate().

void PG_PopupMenu::LoadThemeStyle const std::string &  widgettype,
const std::string &  objectname
[protected, virtual]
 

Load a style from the theme definition.

Parameters:
widgettype name of the widgettype
objectname name of the object
Loads the defined style of a given widgettype and objectname.

Reimplemented from PG_ThemeWidget.

Definition at line 885 of file pgpopupmenu.cpp.

References PG_ThemeWidget::LoadThemeStyle().

void PG_PopupMenu::LoadThemeStyle const std::string &  widgettype  )  [protected]
 

Load a specific themestyle.

Parameters:
widgettype name of widget type to load

Reimplemented from PG_ThemeWidget.

Definition at line 847 of file pgpopupmenu.cpp.

References captionActiveColor, captionInactiveColor, PG_Theme::FindGradient(), PG_Theme::FindSurface(), PG_Theme::GetColor(), PG_Theme::GetProperty(), PG_Application::GetTheme(), PG_ThemeWidget::LoadThemeStyle(), miDisabledColor, miNormalColor, minTabWidth, miSelectedColor, separatorLineWidth, sepNormalColor, sepShadowColor, xPadding, and yPadding.

Referenced by PG_PopupMenu().

int PG_PopupMenu::maxItemWidth  )  const [inline]
 

Definition at line 352 of file pgpopupmenu.h.

References xPadding.

Referenced by PG_PopupMenu::MenuItem::measureItem().

void PG_PopupMenu::openMenu int  x = -1,
int  y = -1
 

Definition at line 374 of file pgpopupmenu.cpp.

References PG_Application::GetScreenHeight(), PG_Application::GetScreenWidth(), PG_Widget::MoveWidget(), PG_Rect::my_height, PG_Rect::my_width, PG_Rect::my_xpos, PG_Rect::my_ypos, and PG_Widget::Show().

Referenced by trackMenu().

void PG_PopupMenu::recalcRect  )  [protected, virtual]
 

Definition at line 420 of file pgpopupmenu.cpp.

References getCaptionHeight(), PG_Application::GetScreenHeight(), PG_Application::GetScreenWidth(), items, PG_PopupMenu::MenuItem::measureItem(), PG_Rect::my_height, PG_Rect::my_width, PG_Rect::my_xpos, PG_Rect::my_ypos, PG_Widget::SizeWidget(), xPadding, and yPadding.

bool PG_PopupMenu::SetMenuItemSlot int  id,
MenuItem::MenuItemSlot  slot,
PG_Pointer  clientdata = NULL
 

Definition at line 897 of file pgpopupmenu.cpp.

References PG_Signal1< P1, datatype >::connect(), items, and PG_PopupMenu::MenuItem::sigSelectMenuItem.

void PG_PopupMenu::trackMenu int  x = -1,
int  y = -1
 

Modal popup menu will be shown - i.e.

all mouse/keyboard events will be captured by the menu and until the user selects any menu item (or cancels the menu by pressing ESC) no other widget will be accessible. If

 x @endcoce and @code y 
are absent, menu is popped up at its current position.

Parameters:
x xpos where the menu should pop up
y ypos where the menu should pop up

Definition at line 368 of file pgpopupmenu.cpp.

References PG_Application::GetEventSupplier(), and openMenu().

Referenced by PG_MenuBar::leaveButton().


Member Data Documentation

PG_Color PG_PopupMenu::captionActiveColor [protected]
 

menu caption

Definition at line 308 of file pgpopupmenu.h.

Referenced by eventBlit(), and LoadThemeStyle().

PG_Color PG_PopupMenu::captionInactiveColor [protected]
 

Definition at line 309 of file pgpopupmenu.h.

Referenced by LoadThemeStyle().

std::list<MenuItem*> PG_PopupMenu::items [protected]
 

Definition at line 305 of file pgpopupmenu.h.

Referenced by eventBlit(), eventKeyDown(), eventMouseMotion(), PG_PopupMenu(), recalcRect(), and SetMenuItemSlot().

PG_Color PG_PopupMenu::miDisabledColor [protected]
 

Definition at line 313 of file pgpopupmenu.h.

Referenced by eventBlit(), and LoadThemeStyle().

PG_Color PG_PopupMenu::miNormalColor [protected]
 

Definition at line 311 of file pgpopupmenu.h.

Referenced by eventBlit(), and LoadThemeStyle().

int PG_PopupMenu::minTabWidth [protected]
 

if a menu entry has a right justified component ( e.g.

"save\tctrl-s" ), this is the minimum space for the tab

Definition at line 323 of file pgpopupmenu.h.

Referenced by LoadThemeStyle(), and PG_PopupMenu::MenuItem::measureItem().

PG_Color PG_PopupMenu::miSelectedColor [protected]
 

Definition at line 312 of file pgpopupmenu.h.

Referenced by eventBlit(), and LoadThemeStyle().

std::string PG_PopupMenu::myCaption [protected]
 

the menu items collection

Definition at line 306 of file pgpopupmenu.h.

Referenced by eventBlit(), getCaptionHeight(), and PG_PopupMenu().

int PG_PopupMenu::separatorLineWidth [protected]
 

Definition at line 325 of file pgpopupmenu.h.

Referenced by LoadThemeStyle().

PG_Color PG_PopupMenu::sepNormalColor [protected]
 

Definition at line 315 of file pgpopupmenu.h.

Referenced by eventBlit(), and LoadThemeStyle().

PG_Color PG_PopupMenu::sepShadowColor [protected]
 

Definition at line 316 of file pgpopupmenu.h.

Referenced by eventBlit(), and LoadThemeStyle().

SignalSelectMenuItem PG_PopupMenu::sigSelectMenuItem
 

Definition at line 266 of file pgpopupmenu.h.

Referenced by PG_MenuBar::Add(), eventKeyDown(), and handleClick().

int PG_PopupMenu::xPadding [protected]
 

Definition at line 318 of file pgpopupmenu.h.

Referenced by eventMoveWidget(), LoadThemeStyle(), maxItemWidth(), PG_PopupMenu(), and recalcRect().

int PG_PopupMenu::yPadding [protected]
 

Definition at line 319 of file pgpopupmenu.h.

Referenced by eventMoveWidget(), LoadThemeStyle(), PG_PopupMenu(), and recalcRect().


The documentation for this class was generated from the following files:
Generated on Tue Jun 24 02:19:13 2008 for Advanced Strategic Command by  doxygen 1.4.2