Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CATGUI/CATMenu.h Source File

CATMenu.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATMenu.h
00003 /// \brief Text label for GUI
00004 /// \ingroup CATGUI
00005 ///
00006 /// Copyright (c) 2003-2008 by Michael Ellison.
00007 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00008 ///
00009 // $Author: mikeellison $
00010 // $Date: 2008-01-25 05:11:25 -0600 (Fri, 25 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //---------------------------------------------------------------------------
00014 #ifndef _GGMenu_H_
00015 #define _GGMenu_H_
00016 
00017 #include "CATControl.h"
00018 #include <vector>
00019 
00020 class CATMenu;
00021 
00022 
00023 /// Menu item structure
00024 struct CATMENUITEM
00025 {
00026     CATString                 DisplayText;
00027     bool                      IsSubMenu;
00028     void*                     DataPtr;
00029     struct CATMENUITEM*       Parent;
00030     std::vector<CATMENUITEM*> Children;
00031     CATInt32                  ItemHandle;
00032     CATMenu*                  BaseMenu;
00033     CATString                 AltCommand;
00034 };
00035 
00036 /// GGMENUSTYLE - types of menus.
00037 enum GGMENUSTYLE
00038 {
00039     CATMENUSTYLE_UP,            /// Menu pops upwards from menu label location
00040     CATMENUSTYLE_DOWN,          /// Menu pops downwards from menu label loc
00041     CATMENUSTYLE_UPMOUSE,       /// Menu pops upwards from mouse location
00042     CATMENUSTYLE_DOWNMOUSE  /// Menu pops downwards from mouse location
00043 };
00044 
00045 /// \class CATMenu CATMenu.h
00046 /// \brief Text label for GUI
00047 /// \ingroup CATGUI
00048 class CATMenu : public CATControl
00049 {
00050 public:
00051     /// CATMenu constructor (inherited from CATControl->CATXMLObject)
00052     /// \param element - Type name ("Label")
00053     /// \param attribs - attribute information for the window
00054     /// \param parent - parent XML object (should be a "Window" element)
00055     /// \param rootDir - root directory of skin for bin/png load
00056     CATMenu(    const CATString&             element, 
00057         const CATString&             rootDir);
00058 
00059     virtual ~CATMenu();          
00060 
00061     /// IsFocusable() returns true if the control can receive
00062     /// focus, and false otherwise.
00063     virtual bool         IsFocusable() const;
00064 
00065 
00066     /// PostDraw() draws any stuff that requires an OS-specific draw
00067     /// context.
00068     virtual void   PostDraw(CATDRAWCONTEXT drawContext, const CATRect& dirtyRect);
00069 
00070     /// ParseAttributes() parses the known attributes for an object.
00071     virtual CATResult ParseAttributes();
00072 
00073 
00074     // SetString only affects text displayed when no item is selected.
00075     virtual void SetString ( const CATString& text );
00076 
00077     // GetString retrieves current string, which is either the nulltext
00078     // or whatever is selected.
00079     virtual CATString GetString () const;
00080 
00081     /// Event handler
00082     virtual CATResult OnEvent(const CATEvent& event, CATInt32& retVal);
00083 
00084 
00085     /// Get the currently selected item data
00086     /// \return CATMENUITEM* - current item data, or null
00087     virtual CATMENUITEM* GetCurItem();
00088     /// Set the current item
00089     /// \param item - CATMENUITEM* of current item (or null to select none)
00090     /// \return CAT_SUCCESS on success
00091     virtual CATResult    SetCurItem(CATMENUITEM* item);
00092 
00093     /// GetNumTopNodes() returns the number of nodes in the top menu
00094     /// \return CATUInt32 - number of top-level menu nodes
00095     virtual CATUInt32     GetNumTopNodes();
00096 
00097     /// GetTopNode() returns the requested top-level menu node by index
00098     /// \param index - index to top-level node (from 0 to GetNumTopNodes())
00099     /// \return CATMENUITEM* - requested menu node, or 0 if it doesn't exist
00100     virtual CATMENUITEM* GetTopNode( CATUInt32 index );
00101 
00102     /// Insert() inserts an item into the menu's tree.
00103     /// \param displayText - text to display for item in menu
00104     /// \param parent - ptr to parent menu item
00105     /// \param newItemRef - ref to ptr to receive created menu item on success
00106     /// \param dataPtr - void* to store caller's data for menu item
00107     /// \param subMenu - if true, item has no dataPtr and extends to a sub menu
00108     /// \param index - index to insert at. -1 is at end of current menu
00109     /// \param altCommand - if true, then instead of sending the scripted menu's command
00110     ///                     and using dataPtr for information, the item will send the
00111     ///                     altCommand to the window.
00112     /// \return CATResult - CAT_SUCCESS on success
00113     virtual CATResult    Insert( const CATString&  displayText,
00114                                  CATMENUITEM*      parent,
00115                                  CATMENUITEM*&     newItemRef,
00116                                  void*             dataPtr,
00117                                  bool              subMenu     = false,                                  
00118                                  CATUInt32         index       = -1,
00119                                  const CATString&  altCommand  = "");
00120 
00121     /// InsertSeperator() inserts a seperator into the menu
00122     /// \param parent - parent menu item or 0 for top-level nodes
00123     /// \param index - index to insert seperator at or -1 for end of current menu
00124     /// \return CATResult - CAT_SUCCESS on success
00125     virtual CATResult     InsertSeperator( CATMENUITEM*  parent = 0, 
00126                                            CATUInt32     index  = -1);
00127 
00128     /// Remove() removes the specified menu item and its children.
00129     /// \param item - ref to ptr of menu item to remove. set to 0 afterwards
00130     /// \return CAT_SUCCESS if found and removed.
00131     virtual CATResult    Remove( CATMENUITEM*&     item);
00132 
00133     /// Clear() clears the menu
00134     virtual CATResult    Clear();
00135 
00136     /// OnMouseClick() is called if the mouse was pressed, then released within
00137     /// a control.
00138     virtual void        OnMouseClick();
00139 
00140     /// GetCommand() returns the command for the control.
00141     /// \return CATCommand - command from control
00142     virtual CATCommand  GetCommand() const;
00143 
00144     /// GetHint() retrieves the menu's hint text
00145     /// \return CATString - hint text for menu
00146     virtual CATString   GetHint() const;
00147 
00148     /// SetItalics() sets the menu's italicized state
00149     /// \param italics - if true, menu label is drawn italicized.
00150     virtual void        SetItalics( bool italics );
00151 
00152     /// GetItalics() retrieves the menu's italicized state
00153     /// \return bool - true if italicized
00154     virtual bool        GetItalics() const;      
00155 
00156     /// HasSelectionMark() returns true if menu displays a selection mark when drawn on current item.
00157     virtual bool        HasSelectionMark();
00158 
00159     virtual bool        ForceWidth() const;
00160 #ifdef _WIN32
00161     /// Called by OS to measure the items
00162     virtual void        OSOnMeasureItem( CATMENUITEM* menuItem, CATUInt32& width, CATUInt32& height);
00163 
00164     /// Called by OS to draw the items
00165     virtual void        OSOnDrawItem(    CATMENUITEM* menuItem, bool selected, CATDRAWCONTEXT hDC, CATRect rect );
00166 
00167     virtual CATUInt32     GetAccessRole() {return CAT_ROLE_SYSTEM_PUSHBUTTON;}
00168     
00169 #endif // WIN32
00170 
00171     /// Do the menu
00172     virtual void        DoMenu();   
00173 
00174 protected:
00175     /// Recursive fill of menu from existing data
00176     void BuildMenu();
00177     
00178     /// Clear local menu
00179     void ClearMenu();
00180     void ClearMenuItem(CATMENUITEM* item);
00181 
00182 #ifdef _WIN32
00183     /// Win32-only submenu creation 
00184     void CreateSubMenu( std::vector<CATMENUITEM*>& itemList, HMENU parentMenu);
00185 
00186     CATStack<HMENU>                      fMenuStack;
00187     std::map<CATUInt32, CATMENUITEM*>    fIdMap;
00188 #endif
00189     bool                        fUpdateTextOnSel;    // Update the current text on selections?
00190 
00191     bool                        fShowSel;            // Show the current selection with a mark...
00192     CATMENUITEM*                fCurSel;
00193     std::vector<CATMENUITEM*>   fRootList;
00194     bool                        fMenuDirty;
00195     bool                        fItalics;
00196     GGMENUSTYLE                 fMenuStyle;
00197     // platform-specific menu id/handle
00198     CATUInt32                   fMenuId;
00199     CATUInt32                   fIdCount;
00200     bool                        fWindowBuilt;
00201     bool                        fOutline;
00202     bool                        fForceWidth;
00203 };
00204 
00205 #endif // _GGMenu_H_
00206 
00207 

Generated on Mon Feb 11 04:09:55 2008 for Game Accessibility Suite by doxygen 1.5.4