]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/palmos/menu.h
wxHelpController now wxCHMHelpController on Windows
[wxWidgets.git] / include / wx / palmos / menu.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/palmos/menu.h
3// Purpose: wxMenu, wxMenuBar classes
4// Author: William Osborne - minimal working wxPalmOS port
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
80#if wxUSE_ACCEL
81 // called by wxMenuBar to build its accel table from the accels of all menus
82 bool HasAccels() const { return !m_accels.IsEmpty(); }
83 size_t GetAccelCount() const { return m_accels.GetCount(); }
84 size_t CopyAccels(wxAcceleratorEntry *accels) const;
85
86 // called by wxMenuItem when its accels changes
87 void UpdateAccel(wxMenuItem *item);
88
89 // helper used by wxMenu itself (returns the index in m_accels)
90 int FindAccel(int id) const;
91#endif // wxUSE_ACCEL
92
93private:
94 // common part of all ctors
95 void Init();
96
97 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
98 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
99
100 // terminate the current radio group, if any
101 void EndRadioGroup();
102
103 // if true, insert a break before appending the next item
104 bool m_doBreak;
105
106 // the position of the first item in the current radio group or -1
107 int m_startRadioGroup;
108
109#if wxUSE_ACCEL
110 // the accelerators for our menu items
111 wxAcceleratorArray m_accels;
112#endif // wxUSE_ACCEL
113
114 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
115};
116
117// ----------------------------------------------------------------------------
118// Menu Bar (a la Windows)
119// ----------------------------------------------------------------------------
120
121class WXDLLEXPORT wxMenuInfo : public wxObject
122{
123public :
124 wxMenuInfo() { m_menu = NULL ; }
125 virtual ~wxMenuInfo() { }
126
127 void Create( wxMenu *menu , const wxString &title )
128 { m_menu = menu ; m_title = title ; }
129 wxMenu* GetMenu() const { return m_menu ; }
130 wxString GetTitle() const { return m_title ; }
131private :
132 wxMenu *m_menu ;
133 wxString m_title ;
134
135 DECLARE_DYNAMIC_CLASS(wxMenuInfo) ;
136} ;
137
138WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
139
140class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
141{
142public:
143 // ctors & dtor
144 // default constructor
145 wxMenuBar();
146
147 wxMenuBar(long style);
148 // menubar takes ownership of the menus arrays but copies the titles
149 wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
150 virtual ~wxMenuBar();
151
152 // menubar construction
153 bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ) ; }
154 const wxMenuInfoList& GetMenuInfos() const ;
155
156 virtual bool Append( wxMenu *menu, const wxString &title );
157 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
158 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
159 virtual wxMenu *Remove(size_t pos);
160
161 virtual void EnableTop( size_t pos, bool flag );
162 virtual void SetLabelTop( size_t pos, const wxString& label );
163 virtual wxString GetLabelTop( size_t pos ) const;
164
165 // implementation from now on
166 WXHMENU Create();
167 virtual void Detach();
168 virtual void Attach(wxFrame *frame);
169
170 void LoadMenu();
171 int ProcessCommand(int ItemID);
172
173#if wxUSE_ACCEL
174 // get the accel table for all the menus
175 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
176
177 // update the accel table (must be called after adding/deletign a menu)
178 void RebuildAccelTable();
179#endif // wxUSE_ACCEL
180
181 // if the menubar is modified, the display is not updated automatically,
182 // call this function to update it (m_menuBarFrame should be !NULL)
183 void Refresh();
184
185 // To avoid compile warning
186 void Refresh( bool eraseBackground,
187 const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
188
189protected:
190 // common part of all ctors
191 void Init();
192
193 wxArrayString m_titles ;
194 wxMenuInfoList m_menuInfos;
195
196 // Return the Palm position for a wxMenu which is sometimes different from
197 // the wxWidgets position.
198 int PalmPositionForWxMenu(wxMenu *menu, int wxpos);
199#if wxUSE_ACCEL
200 // the accelerator table for all accelerators in all our menus
201 wxAcceleratorTable m_accelTable;
202#endif // wxUSE_ACCEL
203
204#if defined(__WXWINCE__) && wxUSE_TOOLBAR
205 wxToolBar* m_toolBar;
206#endif
207
208private:
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
210};
211
212#endif // _WX_MENU_H_