]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
wxEventType alterations.
[wxWidgets.git] / include / wx / msw / menu.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.h
3// Purpose: wxMenu, wxMenuBar classes
4// Author: Julian Smart
5// Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __MENUH__
13#define __MENUH__
14
15#ifdef __GNUG__
16#pragma interface "menu.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/event.h"
21
22class wxMenuItem;
23class wxMenuBar;
24class wxMenu;
25
26WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
27
28// ----------------------------------------------------------------------------
29// Menu
30// ----------------------------------------------------------------------------
31class WXDLLEXPORT wxMenu: public wxEvtHandler
32{
33 DECLARE_DYNAMIC_CLASS(wxMenu)
34
35public:
36 // ctor & dtor
37 wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL);
38 ~wxMenu();
39
40 // construct menu
41 // append items to the menu
42 // separator line
43 void AppendSeparator();
44 // normal item
45 void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString,
46 bool checkable = FALSE);
47 // a submenu
48 void Append(int id, const wxString& Label, wxMenu *SubMenu,
49 const wxString& helpString = wxEmptyString);
50 // the most generic form (create wxMenuItem first and use it's functions)
51 void Append(wxMenuItem *pItem);
52 // insert a break in the menu
53 void Break();
54 // delete an item
55 void Delete(int id); /* If it's a submenu, menu is not destroyed. VZ: why? */
56
57 // menu item control
58 void Enable(int id, bool Flag);
59 bool Enabled(int id) const;
60 inline bool IsEnabled(int id) const { return Enabled(id); };
61 void Check(int id, bool Flag);
62 bool Checked(int id) const;
63 inline bool IsChecked(int id) const { return IsChecked(id); };
64
65 // item properties
66 // title
67 void SetTitle(const wxString& label);
68 const wxString& GetTitle() const;
69 // label
70 void SetLabel(int id, const wxString& label);
71 wxString GetLabel(int id) const;
72 // help string
73 virtual void SetHelpString(const int id, const wxString& helpString);
74 virtual wxString GetHelpString(const int id) const ;
75
76 // find item
77 // Finds the item id matching the given string, NOT_FOUND if not found.
78 virtual int FindItem(const wxString& itemString) const ;
79 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
80 wxMenuItem *FindItemForId(const int itemId, wxMenu **itemMenu = NULL) const;
81
82 void ProcessCommand(wxCommandEvent& event);
83 inline void Callback(const wxFunction func) { m_callback = func; }
84
85 virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
86 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
87 inline wxEvtHandler *GetEventHandler(void) { return m_eventHandler; }
88
89 // IMPLEMENTATION
90 bool MSWCommand(const WXUINT param, const WXWORD id);
91
92 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
93 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
94
95 // semi-private accessors
96 // get the window which contains this menu
97 wxWindow *GetWindow() const;
98 // get the menu handle
99 WXHMENU GetHMenu() const;
100
101private:
102 bool m_doBreak ;
103
104public:
105 // This is used when m_hMenu is NULL because we don't want to
106 // delete it in ~wxMenu (it's been added to a parent menu).
107 // But we'll still need the handle for other purposes.
108 // Might be better to have a flag saying whether it's deleteable or not.
109 WXHMENU m_savehMenu ; // Used for Enable() on popup
110 WXHMENU m_hMenu;
111 wxFunction m_callback;
112
113 int m_noItems;
114 wxString m_title;
115 wxMenu * m_topLevelMenu;
116 wxMenuBar * m_menuBar;
117 wxList m_menuItems;
118 wxEvtHandler * m_parent;
119 wxEvtHandler * m_eventHandler;
120 wxWindow *m_pInvokingWindow;
121};
122
123// ----------------------------------------------------------------------------
124// Menu Bar (a la Windows)
125// ----------------------------------------------------------------------------
126class wxFrame;
127class WXDLLEXPORT wxMenuBar: public wxEvtHandler
128{
129 DECLARE_DYNAMIC_CLASS(wxMenuBar)
130
131 wxMenuBar(void);
132 wxMenuBar(const int n, wxMenu *menus[], const wxString titles[]);
133 ~wxMenuBar(void);
134
135 void Append(wxMenu *menu, const wxString& title);
136 // Must only be used AFTER menu has been attached to frame,
137 // otherwise use individual menus to enable/disable items
138 void Enable(const int Id, const bool Flag);
139 bool Enabled(const int Id) const ;
140 inline bool IsEnabled(const int Id) const { return Enabled(Id); };
141 void EnableTop(const int pos, const bool Flag);
142 void Check(const int id, const bool Flag);
143 bool Checked(const int id) const ;
144 inline bool IsChecked(const int Id) const { return Checked(Id); };
145 void SetLabel(const int id, const wxString& label) ;
146 wxString GetLabel(const int id) const ;
147 void SetLabelTop(const int pos, const wxString& label) ;
148 wxString GetLabelTop(const int pos) const ;
149 virtual void Delete(wxMenu *menu, const int index = 0); /* Menu not destroyed */
150 virtual bool OnAppend(wxMenu *menu, const char *title);
151 virtual bool OnDelete(wxMenu *menu, const int index);
152
153 virtual void SetHelpString(const int Id, const wxString& helpString);
154 virtual wxString GetHelpString(const int Id) const ;
155
156 virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ;
157
158 // Find wxMenuItem for item ID, and return item's
159 // menu too if itemMenu is non-NULL.
160 wxMenuItem *FindItemForId(const int itemId, wxMenu **menuForItem = NULL) const ;
161
162 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
163 inline wxEvtHandler *GetEventHandler(void) { return m_eventHandler; }
164
165 public:
166 wxEvtHandler * m_eventHandler;
167 int m_menuCount;
168 wxMenu ** m_menus;
169 wxString * m_titles;
170 wxFrame * m_menuBarFrame;
171 WXHMENU m_hMenu;
172};
173
174#endif // __MENUH__