]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: menuitem.cpp | |
3 | // Purpose: wxMenuItem implementation | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // headers & declarations | |
14 | // ============================================================================ | |
15 | ||
16 | #include "wx/menu.h" | |
17 | #include "wx/menuitem.h" | |
18 | ||
519cb848 | 19 | #include <wx/mac/uma.h> |
e9576ca5 SC |
20 | // ============================================================================ |
21 | // implementation | |
22 | // ============================================================================ | |
23 | ||
24 | // ---------------------------------------------------------------------------- | |
25 | // dynamic classes implementation | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
28 | #if !USE_SHARED_LIBRARY | |
29 | IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) | |
30 | #endif //USE_SHARED_LIBRARY | |
31 | ||
51abe921 | 32 | void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; |
e9576ca5 SC |
33 | // ---------------------------------------------------------------------------- |
34 | // wxMenuItem | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | // ctor & dtor | |
38 | // ----------- | |
39 | ||
40 | wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id, | |
e7549107 | 41 | const wxString& text, const wxString& strHelp, |
e9576ca5 | 42 | bool bCheckable, |
e7549107 | 43 | wxMenu *pSubMenu) |
e9576ca5 | 44 | { |
e7549107 | 45 | wxASSERT( pParentMenu != NULL ); |
e9576ca5 | 46 | |
e7549107 SC |
47 | m_parentMenu = pParentMenu; |
48 | m_subMenu = pSubMenu; | |
49 | m_isEnabled = TRUE; | |
50 | m_isChecked = FALSE; | |
51 | m_id = id; | |
52 | m_text = text; | |
53 | m_isCheckable = bCheckable; | |
54 | m_help = strHelp; | |
519cb848 | 55 | |
e7549107 SC |
56 | |
57 | if ( m_text == "E&xit" ||m_text == "Exit" ) | |
58 | { | |
59 | m_text = "Quit\tCtrl+Q" ; | |
60 | } | |
e9576ca5 SC |
61 | } |
62 | ||
63 | wxMenuItem::~wxMenuItem() | |
64 | { | |
65 | } | |
66 | ||
51abe921 SC |
67 | bool wxMenuItem::IsChecked() const |
68 | { | |
69 | return wxMenuItemBase::IsChecked() ; | |
70 | } | |
71 | ||
72 | wxString wxMenuItem::GetLabel() const | |
73 | { | |
74 | return wxStripMenuCodes(m_text); | |
75 | } | |
76 | ||
77 | // accelerators | |
78 | // ------------ | |
79 | ||
80 | #if wxUSE_ACCEL | |
81 | ||
82 | wxAcceleratorEntry *wxMenuItem::GetAccel() const | |
83 | { | |
84 | return wxGetAccelFromString(GetText()); | |
85 | } | |
86 | ||
87 | #endif // wxUSE_ACCEL | |
88 | ||
e9576ca5 SC |
89 | // misc |
90 | // ---- | |
91 | ||
e7549107 SC |
92 | /* |
93 | ||
e9576ca5 SC |
94 | // delete the sub menu |
95 | void wxMenuItem::DeleteSubMenu() | |
96 | { | |
e7549107 | 97 | wxASSERT( m_subMenu != NULL ); |
e9576ca5 | 98 | |
e7549107 SC |
99 | delete m_subMenu; |
100 | m_subMenu = NULL; | |
e9576ca5 SC |
101 | } |
102 | ||
e7549107 SC |
103 | */ |
104 | ||
e9576ca5 SC |
105 | // change item state |
106 | // ----------------- | |
107 | ||
108 | void wxMenuItem::Enable(bool bDoEnable) | |
109 | { | |
e7549107 SC |
110 | if ( m_isEnabled != bDoEnable ) { |
111 | if ( m_subMenu == NULL ) | |
519cb848 SC |
112 | { |
113 | // normal menu item | |
e7549107 | 114 | if ( m_parentMenu->GetHMenu() ) |
519cb848 | 115 | { |
e7549107 | 116 | int index = m_parentMenu->MacGetIndexFromItem( this ) ; |
519cb848 SC |
117 | if ( index >= 1 ) |
118 | { | |
119 | if ( bDoEnable ) | |
e7549107 | 120 | UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ; |
519cb848 | 121 | else |
e7549107 | 122 | UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ; |
519cb848 SC |
123 | } |
124 | } | |
e9576ca5 | 125 | } |
519cb848 | 126 | else |
e9576ca5 | 127 | { |
519cb848 | 128 | // submenu |
e7549107 | 129 | if ( m_parentMenu->GetHMenu() ) |
519cb848 | 130 | { |
e7549107 | 131 | int index = m_parentMenu->MacGetIndexFromItem( this ) ; |
519cb848 SC |
132 | if ( index >= 1 ) |
133 | { | |
134 | if ( bDoEnable ) | |
e7549107 | 135 | UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ; |
519cb848 | 136 | else |
e7549107 | 137 | UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ; |
519cb848 SC |
138 | } |
139 | } | |
e9576ca5 SC |
140 | } |
141 | ||
e7549107 | 142 | m_isEnabled = bDoEnable; |
e9576ca5 SC |
143 | } |
144 | } | |
145 | ||
146 | void wxMenuItem::Check(bool bDoCheck) | |
147 | { | |
148 | wxCHECK_RET( IsCheckable(), "only checkable items may be checked" ); | |
149 | ||
e7549107 | 150 | if ( m_isChecked != bDoCheck ) |
519cb848 | 151 | { |
e7549107 SC |
152 | m_isChecked = bDoCheck; |
153 | if ( m_parentMenu->GetHMenu() ) | |
519cb848 | 154 | { |
e7549107 | 155 | int index = m_parentMenu->MacGetIndexFromItem( this ) ; |
519cb848 SC |
156 | if ( index >= 1 ) |
157 | { | |
158 | if ( bDoCheck ) | |
e7549107 | 159 | ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark |
519cb848 | 160 | else |
e7549107 | 161 | ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark |
519cb848 SC |
162 | } |
163 | } | |
e9576ca5 | 164 | } |
51abe921 SC |
165 | } |
166 | ||
167 | void wxMenuItem::SetText(const wxString& text) | |
168 | { | |
169 | // don't do anything if label didn't change | |
170 | if ( m_text == text ) | |
171 | return; | |
172 | ||
173 | wxMenuItemBase::SetText(text); | |
174 | // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) ); | |
175 | ||
176 | wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") ); | |
177 | if ( m_parentMenu->GetHMenu() ) | |
178 | { | |
179 | int index = m_parentMenu->MacGetIndexFromItem( this ) ; | |
180 | if ( index >= 1 ) | |
181 | { | |
182 | Str255 label; | |
183 | wxMacBuildMenuString( label , NULL , NULL , text ,false); | |
184 | ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark | |
185 | } | |
186 | } | |
187 | ||
188 | #if wxUSE_ACCEL | |
189 | m_parentMenu->UpdateAccel(this); | |
190 | #endif // wxUSE_ACCEL | |
191 | ||
192 | } | |
193 | void wxMenuItem::SetCheckable(bool checkable) | |
194 | { | |
195 | wxMenuItemBase::SetCheckable(checkable); | |
196 | // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) ); | |
197 | } | |
198 | ||
199 | // ---------------------------------------------------------------------------- | |
200 | // wxMenuItemBase | |
201 | // ---------------------------------------------------------------------------- | |
202 | ||
203 | wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, | |
204 | int id, | |
205 | const wxString& name, | |
206 | const wxString& help, | |
207 | bool isCheckable, | |
208 | wxMenu *subMenu) | |
209 | { | |
210 | return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu); | |
211 | } |