]> git.saurik.com Git - wxWidgets.git/blame - include/wx/palmos/menu.h
wxPaletteBase introduction. wxPalette::GetColoursCount() in interface of all platform...
[wxWidgets.git] / include / wx / palmos / menu.h
CommitLineData
ffecfa5a
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/palmos/menu.h
3// Purpose: wxMenu, wxMenuBar classes
4// Author: William Osborne
5// Modified by:
6// Created: 10/13/04
7// RCS-ID: $Id:
8// Copyright: (c) William Osborne
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
14
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "menu.h"
17#endif
18
19#if wxUSE_ACCEL
20 #include "wx/accel.h"
21 #include "wx/dynarray.h"
22
23 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
24#endif // wxUSE_ACCEL
25
26class WXDLLEXPORT wxFrame;
27
28#if defined(__WXWINCE__) && wxUSE_TOOLBAR
29class WXDLLEXPORT wxToolBar;
30#endif
31
32#include "wx/arrstr.h"
33
34// ----------------------------------------------------------------------------
35// Menu
36// ----------------------------------------------------------------------------
37
38class WXDLLEXPORT wxMenu : public wxMenuBase
39{
40public:
41 // ctors & dtor
42 wxMenu(const wxString& title, long style = 0)
43 : wxMenuBase(title, style) { Init(); }
44
45 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
46
47 virtual ~wxMenu();
48
49 // implement base class virtuals
50 virtual wxMenuItem* DoAppend(wxMenuItem *item);
51 virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
52 virtual wxMenuItem* DoRemove(wxMenuItem *item);
53
54 virtual void Break();
55
56 virtual void SetTitle(const wxString& title);
57
58 // deprecated functions
59#if wxUSE_MENU_CALLBACK
60 wxMenu(const wxString& title, const wxFunction func)
61 : wxMenuBase(title)
62 {
63 Init();
64
65 Callback(func);
66 }
67#endif // wxUSE_MENU_CALLBACK
68
69 // implementation only from now on
70 // -------------------------------
71
72 virtual void Attach(wxMenuBarBase *menubar);
73
74 bool PalmCommand(WXUINT param, WXWORD id);
75
76 // semi-private accessors
77 // get the window which contains this menu
78 wxWindow *GetWindow() const;
79 // get the menu handle
80 WXHMENU GetHMenu() const { return m_hMenu; }
81
82#if wxUSE_ACCEL
83 // called by wxMenuBar to build its accel table from the accels of all menus
84 bool HasAccels() const { return !m_accels.IsEmpty(); }
85 size_t GetAccelCount() const { return m_accels.GetCount(); }
86 size_t CopyAccels(wxAcceleratorEntry *accels) const;
87
88 // called by wxMenuItem when its accels changes
89 void UpdateAccel(wxMenuItem *item);
90
91 // helper used by wxMenu itself (returns the index in m_accels)
92 int FindAccel(int id) const;
93#endif // wxUSE_ACCEL
94
95private:
96 // common part of all ctors
97 void Init();
98
99 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
100 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
101
102 // terminate the current radio group, if any
103 void EndRadioGroup();
104
105 // if TRUE, insert a break before appending the next item
106 bool m_doBreak;
107
108 // the position of the first item in the current radio group or -1
109 int m_startRadioGroup;
110
111 // the menu handle of this menu
112 WXHMENU m_hMenu;
113
114#if wxUSE_ACCEL
115 // the accelerators for our menu items
116 wxAcceleratorArray m_accels;
117#endif // wxUSE_ACCEL
118
119 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
120};
121
122// ----------------------------------------------------------------------------
123// Menu Bar (a la Windows)
124// ----------------------------------------------------------------------------
125
126class WXDLLEXPORT wxMenuInfo : public wxObject
127{
128public :
129 wxMenuInfo() { m_menu = NULL ; }
130 virtual ~wxMenuInfo() { }
131
132 void Create( wxMenu *menu , const wxString &title )
133 { m_menu = menu ; m_title = title ; }
134 wxMenu* GetMenu() const { return m_menu ; }
135 wxString GetTitle() const { return m_title ; }
136private :
137 wxMenu *m_menu ;
138 wxString m_title ;
139
140 DECLARE_DYNAMIC_CLASS(wxMenuInfo) ;
141} ;
142
143WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
144
145class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
146{
147public:
148 // ctors & dtor
149 // default constructor
150 wxMenuBar();
151
152 wxMenuBar(long style);
153 // menubar takes ownership of the menus arrays but copies the titles
154 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
155 virtual ~wxMenuBar();
156
157 // menubar construction
158 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ) ; }
159 const wxMenuInfoList& GetMenuInfos() const ;
160
161 virtual bool Append( wxMenu *menu, const wxString &title );
162 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
163 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
164 virtual wxMenu *Remove(size_t pos);
165
166 virtual void EnableTop( size_t pos, bool flag );
167 virtual void SetLabelTop( size_t pos, const wxString& label );
168 virtual wxString GetLabelTop( size_t pos ) const;
169
170 // implementation from now on
171 WXHMENU Create();
172 virtual void Detach();
173 virtual void Attach(wxFrame *frame);
174
175 void LoadMenu();
176 int ProcessCommand(int ItemID);
177
178#if wxUSE_TOOLBAR && defined(__WXWINCE__) && (_WIN32_WCE < 400 || defined(__POCKETPC__) || defined(__SMARTPHONE__))
179 // Under WinCE, a menubar is owned by the frame's toolbar
180 void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
181 wxToolBar* GetToolBar() const { return m_toolBar; }
182#endif
183
184#if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
185 WXHWND GetCommandBar() const { return m_commandBar; }
186 bool AddAdornments(long style);
187#endif
188
189#if wxUSE_ACCEL
190 // get the accel table for all the menus
191 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
192
193 // update the accel table (must be called after adding/deletign a menu)
194 void RebuildAccelTable();
195#endif // wxUSE_ACCEL
196
197 // get the menu handle
198 WXHMENU GetHMenu() const { return m_hMenu; }
199
200 // if the menubar is modified, the display is not updated automatically,
201 // call this function to update it (m_menuBarFrame should be !NULL)
202 void Refresh();
203
204 // To avoid compile warning
205 void Refresh( bool eraseBackground,
206 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
207
208protected:
209 // common part of all ctors
210 void Init();
211
212 wxArrayString m_titles ;
213 wxMenuInfoList m_menuInfos;
214
215 WXHMENU m_hMenu;
216
217 // Return the Palm position for a wxMenu which is sometimes different from
218 // the wxWidgets position.
219 int PalmPositionForWxMenu(wxMenu *menu, int wxpos);
220#if wxUSE_ACCEL
221 // the accelerator table for all accelerators in all our menus
222 wxAcceleratorTable m_accelTable;
223#endif // wxUSE_ACCEL
224
225#if defined(__WXWINCE__) && wxUSE_TOOLBAR
226 wxToolBar* m_toolBar;
227#endif
228 // Not using a combined wxToolBar/wxMenuBar? then use
229 // a commandbar in WinCE .NET to implement the
230 // menubar, since there is no ::SetMenu function.
231#if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
232 WXHWND m_commandBar;
233 bool m_adornmentsAdded;
234#endif
235
236private:
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
238};
239
240#endif // _WX_MENU_H_