]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: menu.h | |
3 | // Purpose: wxMenu, wxMenuBar classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_MOTIF_MENU_H_ | |
13 | #define _WX_MOTIF_MENU_H_ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "menu.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/colour.h" | |
20 | #include "wx/font.h" | |
21 | #include "wx/arrstr.h" | |
22 | ||
23 | class wxFrame; | |
24 | ||
25 | // ---------------------------------------------------------------------------- | |
26 | // Menu | |
27 | // ---------------------------------------------------------------------------- | |
28 | ||
29 | class wxMenu : public wxMenuBase | |
30 | { | |
31 | public: | |
32 | // ctors & dtor | |
33 | wxMenu(const wxString& title, long style = 0) | |
34 | : wxMenuBase(title, style) { Init(); } | |
35 | ||
36 | wxMenu(long style = 0) : wxMenuBase(style) { Init(); } | |
37 | ||
38 | virtual ~wxMenu(); | |
39 | ||
40 | // implement base class virtuals | |
41 | virtual bool DoAppend(wxMenuItem *item); | |
42 | virtual bool DoInsert(size_t pos, wxMenuItem *item); | |
43 | virtual wxMenuItem *DoRemove(wxMenuItem *item); | |
44 | ||
45 | virtual void Break(); | |
46 | ||
47 | virtual void SetTitle(const wxString& title); | |
48 | ||
49 | bool ProcessCommand(wxCommandEvent& event); | |
50 | ||
51 | //// Motif-specific | |
52 | WXWidget GetButtonWidget() const { return m_buttonWidget; } | |
53 | void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } | |
54 | ||
55 | WXWidget GetMainWidget() const { return m_menuWidget; } | |
56 | ||
57 | int GetId() const { return m_menuId; } | |
58 | void SetId(int id) { m_menuId = id; } | |
59 | ||
60 | void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } | |
61 | wxMenuBar* GetMenuBar() const { return m_menuBar; } | |
62 | ||
63 | void CreatePopup(WXWidget logicalParent, int x, int y); | |
64 | void DestroyPopup(); | |
65 | void ShowPopup(int x, int y); | |
66 | void HidePopup(); | |
67 | ||
68 | WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, | |
69 | const wxString& title = wxEmptyString, | |
70 | bool isPulldown = FALSE); | |
71 | ||
72 | // For popups, need to destroy, then recreate menu for a different (or | |
73 | // possibly same) window, since the parent may change. | |
74 | void DestroyMenu(bool full); | |
75 | WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const; | |
76 | ||
77 | const wxColour& GetBackgroundColour() const { return m_backgroundColour; } | |
78 | const wxColour& GetForegroundColour() const { return m_foregroundColour; } | |
79 | const wxFont& GetFont() const { return m_font; } | |
80 | ||
81 | void SetBackgroundColour(const wxColour& colour); | |
82 | void SetForegroundColour(const wxColour& colour); | |
83 | void SetFont(const wxFont& colour); | |
84 | void ChangeFont(bool keepOriginalSize = FALSE); | |
85 | ||
86 | WXWidget GetHandle() const { return m_menuWidget; } | |
87 | ||
88 | bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; } | |
89 | ||
90 | void DestroyWidgetAndDetach(); | |
91 | public: | |
92 | // Motif-specific data | |
93 | int m_numColumns; | |
94 | WXWidget m_menuWidget; | |
95 | WXWidget m_popupShell; // For holding the popup shell widget | |
96 | WXWidget m_buttonWidget; // The actual string, so we can grey it etc. | |
97 | int m_menuId; | |
98 | wxMenu* m_topLevelMenu ; | |
99 | bool m_ownedByMenuBar; | |
100 | wxColour m_foregroundColour; | |
101 | wxColour m_backgroundColour; | |
102 | wxFont m_font; | |
103 | ||
104 | private: | |
105 | // common code for both constructors: | |
106 | void Init(); | |
107 | ||
108 | DECLARE_DYNAMIC_CLASS(wxMenu) | |
109 | }; | |
110 | ||
111 | // ---------------------------------------------------------------------------- | |
112 | // Menu Bar | |
113 | // ---------------------------------------------------------------------------- | |
114 | ||
115 | class wxMenuBar : public wxMenuBarBase | |
116 | { | |
117 | public: | |
118 | wxMenuBar() { Init(); } | |
119 | wxMenuBar(long WXUNUSED(style)) { Init(); } | |
120 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); | |
121 | virtual ~wxMenuBar(); | |
122 | ||
123 | // implement base class (pure) virtuals | |
124 | // ------------------------------------ | |
125 | ||
126 | virtual bool Append( wxMenu *menu, const wxString &title ); | |
127 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
128 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
129 | virtual wxMenu *Remove(size_t pos); | |
130 | ||
131 | virtual int FindMenuItem(const wxString& menuString, | |
132 | const wxString& itemString) const; | |
133 | virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const; | |
134 | ||
135 | virtual void EnableTop( size_t pos, bool flag ); | |
136 | virtual void SetLabelTop( size_t pos, const wxString& label ); | |
137 | virtual wxString GetLabelTop( size_t pos ) const; | |
138 | ||
139 | // implementation only from now on | |
140 | // ------------------------------- | |
141 | ||
142 | wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; } | |
143 | void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; } | |
144 | WXWidget GetMainWidget() const { return m_mainWidget; } | |
145 | void SetMainWidget(WXWidget widget) { m_mainWidget = widget; } | |
146 | ||
147 | // Create menubar | |
148 | bool CreateMenuBar(wxFrame* frame); | |
149 | ||
150 | // Destroy menubar, but keep data structures intact so we can recreate it. | |
151 | bool DestroyMenuBar(); | |
152 | ||
153 | const wxColour& GetBackgroundColour() const { return m_backgroundColour; } | |
154 | const wxColour& GetForegroundColour() const { return m_foregroundColour; } | |
155 | const wxFont& GetFont() const { return m_font; } | |
156 | ||
157 | virtual bool SetBackgroundColour(const wxColour& colour); | |
158 | virtual bool SetForegroundColour(const wxColour& colour); | |
159 | virtual bool SetFont(const wxFont& colour); | |
160 | void ChangeFont(bool keepOriginalSize = FALSE); | |
161 | ||
162 | public: | |
163 | // common part of all ctors | |
164 | void Init(); | |
165 | ||
166 | wxArrayString m_titles; | |
167 | wxFrame *m_menuBarFrame; | |
168 | ||
169 | WXWidget m_mainWidget; | |
170 | ||
171 | wxColour m_foregroundColour; | |
172 | wxColour m_backgroundColour; | |
173 | wxFont m_font; | |
174 | ||
175 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
176 | }; | |
177 | ||
178 | #endif // _WX_MOTIF_MENU_H_ |