menu.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/os2/menu.h
  3. // Purpose: wxMenu, wxMenuBar classes
  4. // Author: David Webster
  5. // Modified by:
  6. // Created: 10/10/99
  7. // Copyright: (c) David Webster
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MENU_H_
  11. #define _WX_MENU_H_
  12. #if wxUSE_ACCEL
  13. #include "wx/accel.h"
  14. #include "wx/list.h" // for "template" list classes
  15. #include "wx/dynarray.h"
  16. WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
  17. #endif // wxUSE_ACCEL
  18. class WXDLLIMPEXP_FWD_CORE wxFrame;
  19. void wxSetShortCutKey(wxChar* zText);
  20. // ----------------------------------------------------------------------------
  21. // Menu
  22. // ----------------------------------------------------------------------------
  23. class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
  24. {
  25. public:
  26. //
  27. // Ctors & dtor
  28. //
  29. wxMenu( const wxString& rTitle
  30. ,long lStyle = 0
  31. )
  32. : wxMenuBase( rTitle
  33. ,lStyle
  34. )
  35. {
  36. Init();
  37. }
  38. wxMenu(long lStyle = 0)
  39. : wxMenuBase(lStyle)
  40. {
  41. Init();
  42. }
  43. virtual ~wxMenu();
  44. //
  45. // Implement base class virtuals
  46. //
  47. virtual wxMenuItem* DoAppend(wxMenuItem* pItem);
  48. virtual wxMenuItem* DoInsert( size_t nPos
  49. ,wxMenuItem* pItem
  50. );
  51. virtual wxMenuItem* DoRemove(wxMenuItem* pItem);
  52. virtual void Break(void);
  53. virtual void SetTitle(const wxString& rTitle);
  54. //
  55. // Implementation only from now on
  56. // -------------------------------
  57. //
  58. virtual void Attach(wxMenuBarBase* pMenubar);
  59. bool OS2Command( WXUINT uParam
  60. ,WXWORD wId
  61. );
  62. //
  63. // Semi-private accessors
  64. //
  65. //
  66. // Get the window which contains this menu
  67. //
  68. wxWindow* GetWindow(void) const;
  69. //
  70. // Get the menu handle
  71. //
  72. WXHMENU GetHMenu() const { return m_hMenu; }
  73. #if wxUSE_ACCEL
  74. //
  75. // Called by wxMenuBar to build its accel table from the accels of all menus
  76. //
  77. bool HasAccels(void) const { return m_vAccels.IsEmpty(); }
  78. size_t GetAccelCount(void) const { return m_vAccels.GetCount(); }
  79. size_t CopyAccels(wxAcceleratorEntry* pAccels) const;
  80. //
  81. // Called by wxMenuItem when its accels changes
  82. //
  83. void UpdateAccel(wxMenuItem* pItem);
  84. //
  85. // Helper used by wxMenu itself (returns the index in m_accels)
  86. //
  87. int FindAccel(int nId) const;
  88. #endif // wxUSE_ACCEL
  89. //
  90. // OS/2 specific Find
  91. //
  92. wxMenuItem* FindItem(int id, ULONG hItem, wxMenu **menu = NULL) const;
  93. //virtual function hiding suppression
  94. int FindItem(const wxString& rsString) const
  95. { return wxMenuBase::FindItem(rsString); }
  96. wxMenuItem* FindItem(int id, wxMenu **menu = NULL) const
  97. { return wxMenuBase::FindItem(id, menu); }
  98. //
  99. // All OS/2PM Menu's have one of these
  100. //
  101. MENUITEM m_vMenuData;
  102. private:
  103. //
  104. // Common part of all ctors
  105. //
  106. void Init();
  107. //
  108. // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
  109. //
  110. bool DoInsertOrAppend( wxMenuItem* pItem
  111. ,size_t nPos = (size_t)-1
  112. );
  113. //
  114. // Terminate the current radio group, if any
  115. //
  116. void EndRadioGroup(void);
  117. //
  118. // If true, insert a breal before appending the next item
  119. //
  120. bool m_bDoBreak;
  121. //
  122. // The menu handle of this menu
  123. //
  124. WXHMENU m_hMenu;
  125. //
  126. // The helper variable for creating unique IDs.
  127. //
  128. static USHORT m_nextMenuId;
  129. //
  130. // The position of the first item in the current radio group or -1
  131. //
  132. int m_nStartRadioGroup;
  133. #if wxUSE_ACCEL
  134. //
  135. // The accelerators for our menu items
  136. //
  137. wxAcceleratorArray m_vAccels;
  138. #endif // wxUSE_ACCEL
  139. DECLARE_DYNAMIC_CLASS(wxMenu)
  140. }; // end of wxMenu
  141. // ----------------------------------------------------------------------------
  142. // Menu Bar (a la Windows)
  143. // ----------------------------------------------------------------------------
  144. class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
  145. {
  146. public:
  147. //
  148. // Ctors & dtor
  149. //
  150. //
  151. // Default constructor
  152. //
  153. wxMenuBar();
  154. //
  155. // Unused under OS2
  156. wxMenuBar(long lStyle);
  157. //
  158. // Menubar takes ownership of the menus arrays but copies the titles
  159. //
  160. wxMenuBar( int n
  161. ,wxMenu* vMenus[]
  162. ,const wxString sTitles[]
  163. ,long lStyle = 0
  164. );
  165. virtual ~wxMenuBar();
  166. //
  167. // Menubar construction
  168. //
  169. virtual bool Append( wxMenu* pMenu
  170. ,const wxString& rTitle
  171. );
  172. virtual bool Insert( size_t nPos
  173. ,wxMenu* pMenu
  174. ,const wxString& rTitle
  175. );
  176. virtual wxMenu* Replace( size_t nPos
  177. ,wxMenu* pMenu
  178. ,const wxString& rTitle
  179. );
  180. virtual wxMenu* Remove(size_t nPos);
  181. virtual int FindMenuItem( const wxString& rMenuString
  182. ,const wxString& rItemString
  183. ) const;
  184. virtual wxMenuItem* FindItem( int nId
  185. ,wxMenu** ppMenu = NULL
  186. ) const;
  187. virtual wxMenuItem* FindItem( int nId
  188. ,ULONG hItem
  189. ,wxMenu** ppMenu = NULL
  190. ) const;
  191. virtual void EnableTop( size_t nPos
  192. ,bool bFlag
  193. );
  194. virtual void SetMenuLabel( size_t nPos
  195. ,const wxString& rLabel
  196. );
  197. virtual wxString GetMenuLabel(size_t nPos) const;
  198. //
  199. // Implementation from now on
  200. //
  201. WXHMENU Create(void);
  202. virtual void Detach(void);
  203. virtual void Attach(wxFrame* pFrame);
  204. #if wxUSE_ACCEL
  205. //
  206. // Get the accel table for all the menus
  207. //
  208. const wxAcceleratorTable& GetAccelTable(void) const { return m_vAccelTable; }
  209. //
  210. // Update the accel table (must be called after adding/deleting a menu)
  211. //
  212. void RebuildAccelTable(void);
  213. #endif // wxUSE_ACCEL
  214. //
  215. // Get the menu handle
  216. WXHMENU GetHMenu(void) const { return m_hMenu; }
  217. //
  218. // If the menubar is modified, the display is not updated automatically,
  219. // call this function to update it (m_menuBarFrame should be !NULL)
  220. //
  221. void Refresh(void);
  222. protected:
  223. //
  224. // Common part of all ctors
  225. //
  226. void Init(void);
  227. wxArrayString m_titles;
  228. WXHMENU m_hMenu;
  229. #if wxUSE_ACCEL
  230. //
  231. // The accelerator table for all accelerators in all our menus
  232. //
  233. wxAcceleratorTable m_vAccelTable;
  234. #endif // wxUSE_ACCEL
  235. private:
  236. //
  237. // Virtual function hiding suppression
  238. //
  239. void Refresh( bool bErase
  240. ,const wxRect* pRect
  241. )
  242. { wxWindow::Refresh(bErase, pRect); }
  243. DECLARE_DYNAMIC_CLASS(wxMenuBar)
  244. };
  245. #endif // _WX_MENU_H_