1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/dynarray.h"
19 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry
*, wxAcceleratorArray
);
22 class WXDLLEXPORT wxFrame
;
24 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
25 class WXDLLEXPORT wxToolBar
;
28 #include "wx/arrstr.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class WXDLLEXPORT wxMenu
: public wxMenuBase
38 wxMenu(const wxString
& title
, long style
= 0)
39 : wxMenuBase(title
, style
) { Init(); }
41 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
45 // implement base class virtuals
46 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
47 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
48 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
52 virtual void SetTitle(const wxString
& title
);
54 // implementation only from now on
55 // -------------------------------
57 virtual void Attach(wxMenuBarBase
*menubar
);
59 bool PalmCommand(WXUINT param
, WXWORD id
);
61 // semi-private accessors
62 // get the window which contains this menu
63 wxWindow
*GetWindow() const;
66 // called by wxMenuBar to build its accel table from the accels of all menus
67 bool HasAccels() const { return !m_accels
.IsEmpty(); }
68 size_t GetAccelCount() const { return m_accels
.GetCount(); }
69 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
71 // called by wxMenuItem when its accels changes
72 void UpdateAccel(wxMenuItem
*item
);
74 // helper used by wxMenu itself (returns the index in m_accels)
75 int FindAccel(int id
) const;
79 // common part of all ctors
82 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
83 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
85 // terminate the current radio group, if any
88 // if true, insert a break before appending the next item
91 // the position of the first item in the current radio group or -1
92 int m_startRadioGroup
;
95 // the accelerators for our menu items
96 wxAcceleratorArray m_accels
;
99 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu
)
102 // ----------------------------------------------------------------------------
103 // Menu Bar (a la Windows)
104 // ----------------------------------------------------------------------------
106 class WXDLLEXPORT wxMenuInfo
: public wxObject
109 wxMenuInfo() { m_menu
= NULL
; }
110 virtual ~wxMenuInfo() { }
112 void Create( wxMenu
*menu
, const wxString
&title
)
113 { m_menu
= menu
; m_title
= title
; }
114 wxMenu
* GetMenu() const { return m_menu
; }
115 wxString
GetTitle() const { return m_title
; }
120 DECLARE_DYNAMIC_CLASS(wxMenuInfo
) ;
123 WX_DECLARE_EXPORTED_LIST(wxMenuInfo
, wxMenuInfoList
);
125 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
129 // default constructor
132 wxMenuBar(long style
);
133 // menubar takes ownership of the menus arrays but copies the titles
134 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
135 virtual ~wxMenuBar();
137 // menubar construction
138 bool Append( wxMenuInfo
*info
) { return Append( info
->GetMenu() , info
->GetTitle() ) ; }
139 const wxMenuInfoList
& GetMenuInfos() const ;
141 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
142 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
143 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
144 virtual wxMenu
*Remove(size_t pos
);
146 virtual void EnableTop( size_t pos
, bool flag
);
147 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
148 virtual wxString
GetLabelTop( size_t pos
) const;
150 // implementation from now on
152 virtual void Detach();
153 virtual void Attach(wxFrame
*frame
);
156 int ProcessCommand(int ItemID
);
159 // get the accel table for all the menus
160 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
162 // update the accel table (must be called after adding/deleting a menu)
163 void RebuildAccelTable();
164 #endif // wxUSE_ACCEL
166 // if the menubar is modified, the display is not updated automatically,
167 // call this function to update it (m_menuBarFrame should be !NULL)
170 // To avoid compile warning
171 void Refresh( bool eraseBackground
,
172 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
175 // common part of all ctors
178 wxArrayString m_titles
;
179 wxMenuInfoList m_menuInfos
;
181 // Return the Palm position for a wxMenu which is sometimes different from
182 // the wxWidgets position.
183 int PalmPositionForWxMenu(wxMenu
*menu
, int wxpos
);
185 // the accelerator table for all accelerators in all our menus
186 wxAcceleratorTable m_accelTable
;
187 #endif // wxUSE_ACCEL
189 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
190 wxToolBar
* m_toolBar
;
194 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar
)
197 #endif // _WX_MENU_H_