]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.cpp | |
3 | // Purpose: wxMenu, wxMenuBar, wxMenuItem | |
75f11ad7 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
75f11ad7 | 6 | // Created: 10/10/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
75f11ad7 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a4372af6 SN |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "menu.h" | |
14 | #endif | |
15 | ||
75f11ad7 DW |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
0e320a79 | 18 | |
75f11ad7 | 19 | #ifndef WX_PRECOMP |
b59c98dd | 20 | #include "wx/app.h" |
75f11ad7 DW |
21 | #include "wx/frame.h" |
22 | #include "wx/menu.h" | |
23 | #include "wx/utils.h" | |
24 | #include "wx/intl.h" | |
c5fb56c0 | 25 | #include "wx/log.h" |
75f11ad7 | 26 | #endif |
0e320a79 | 27 | |
75f11ad7 DW |
28 | #if wxUSE_OWNER_DRAWN |
29 | #include "wx/ownerdrw.h" | |
0e320a79 DW |
30 | #endif |
31 | ||
75f11ad7 | 32 | #include "wx/os2/private.h" |
0e320a79 DW |
33 | |
34 | // other standard headers | |
0e320a79 DW |
35 | #include <string.h> |
36 | ||
75f11ad7 DW |
37 | // ---------------------------------------------------------------------------- |
38 | // global variables | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
61243a51 | 41 | extern wxMenu* wxCurrentPopupMenu; |
75f11ad7 DW |
42 | |
43 | // ---------------------------------------------------------------------------- | |
44 | // constants | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
61243a51 DW |
47 | // |
48 | // The (popup) menu title has this special id | |
49 | // | |
50 | static const int idMenuTitle = -2; | |
75f11ad7 | 51 | |
f6bcfd97 BP |
52 | // |
53 | // The unique ID for Menus | |
54 | // | |
55 | #ifdef __VISAGECPP__ | |
56 | USHORT wxMenu::m_nextMenuId = 0; | |
57 | #else | |
58 | static USHORT wxMenu::m_nextMenuId = 0; | |
59 | #endif | |
60 | ||
75f11ad7 DW |
61 | // ---------------------------------------------------------------------------- |
62 | // macros | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
75f11ad7 DW |
65 | IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) |
66 | IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) | |
0e320a79 | 67 | |
2b33b728 SN |
68 | // ---------------------------------------------------------------------------- |
69 | // static function for translating menu labels | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | static wxString TextToLabel(const wxString& rTitle) | |
73 | { | |
74 | wxString Title; | |
75 | const wxChar *pc; | |
76 | for (pc = rTitle; *pc != wxT('\0'); pc++ ) | |
77 | { | |
78 | if (*pc == wxT('&') ) | |
79 | { | |
80 | if (*(pc+1) == wxT('&')) | |
81 | { | |
82 | pc++; | |
83 | Title << wxT('&'); | |
84 | } | |
f6bcfd97 | 85 | else |
2b33b728 SN |
86 | Title << wxT('~'); |
87 | } | |
88 | // else if (*pc == wxT('/')) | |
89 | // { | |
90 | // Title << wxT('\\'); | |
91 | // } | |
92 | else | |
93 | { | |
94 | if ( *pc == wxT('~') ) | |
95 | { | |
96 | // tildes must be doubled to prevent them from being | |
97 | // interpreted as accelerator character prefix by PM ??? | |
98 | Title << *pc; | |
99 | } | |
100 | Title << *pc; | |
101 | } | |
102 | } | |
103 | return Title; | |
104 | } | |
105 | ||
0e320a79 DW |
106 | // ============================================================================ |
107 | // implementation | |
108 | // ============================================================================ | |
109 | ||
75f11ad7 DW |
110 | // --------------------------------------------------------------------------- |
111 | // wxMenu construction, adding and removing menu items | |
112 | // --------------------------------------------------------------------------- | |
0e320a79 | 113 | |
61243a51 | 114 | // |
0e320a79 | 115 | // Construct a menu with optional title (then use append) |
61243a51 | 116 | // |
c5fb56c0 | 117 | void wxMenu::Init() |
0e320a79 | 118 | { |
61243a51 DW |
119 | m_bDoBreak = FALSE; |
120 | ||
121 | // | |
f23208ca DW |
122 | // Create the menu (to be used as a submenu or a popup) |
123 | // | |
124 | if ((m_hMenu = ::WinCreateWindow( HWND_DESKTOP | |
f6bcfd97 | 125 | ,WC_MENU |
f23208ca DW |
126 | ,"Menu" |
127 | ,0L | |
128 | ,0L | |
129 | ,0L | |
130 | ,0L | |
131 | ,0L | |
132 | ,NULLHANDLE | |
133 | ,HWND_TOP | |
134 | ,0L | |
135 | ,NULL | |
136 | ,NULL | |
a0606634 | 137 | )) == 0) |
61243a51 DW |
138 | { |
139 | wxLogLastError("WinLoadMenu"); | |
140 | } | |
a0606634 DW |
141 | m_vMenuData.iPosition = 0; |
142 | m_vMenuData.afStyle = MIS_SUBMENU | MIS_TEXT; | |
143 | m_vMenuData.afAttribute = (USHORT)0; | |
f6bcfd97 | 144 | m_vMenuData.id = m_nextMenuId++; |
a0606634 DW |
145 | m_vMenuData.hwndSubMenu = m_hMenu; |
146 | m_vMenuData.hItem = NULLHANDLE; | |
61243a51 DW |
147 | |
148 | // | |
149 | // If we have a title, insert it in the beginning of the menu | |
150 | // | |
f23208ca | 151 | if (!m_title.IsEmpty()) |
61243a51 DW |
152 | { |
153 | Append( idMenuTitle | |
154 | ,m_title | |
155 | ); | |
c5fb56c0 DW |
156 | AppendSeparator(); |
157 | } | |
61243a51 | 158 | } // end of wxMenu::Init |
0e320a79 | 159 | |
61243a51 | 160 | // |
0e320a79 | 161 | // The wxWindow destructor will take care of deleting the submenus. |
61243a51 | 162 | // |
0e320a79 DW |
163 | wxMenu::~wxMenu() |
164 | { | |
61243a51 DW |
165 | // |
166 | // We should free PM resources only if PM doesn't do it for us | |
c5fb56c0 DW |
167 | // which happens if we're attached to a menubar or a submenu of another |
168 | // menu | |
61243a51 | 169 | if (!IsAttached() && !GetParent()) |
75f11ad7 | 170 | { |
61243a51 | 171 | if (!::WinDestroyWindow((HWND)GetHmenu()) ) |
c5fb56c0 | 172 | { |
61243a51 | 173 | wxLogLastError("WinDestroyWindow"); |
c5fb56c0 | 174 | } |
75f11ad7 | 175 | } |
0e320a79 | 176 | |
c5fb56c0 | 177 | #if wxUSE_ACCEL |
61243a51 DW |
178 | // |
179 | // Delete accels | |
180 | // | |
f6bcfd97 | 181 | #if (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 ))) |
61243a51 | 182 | WX_CLEAR_ARRAY(m_vAccels); |
f6bcfd97 | 183 | #endif |
c5fb56c0 | 184 | #endif // wxUSE_ACCEL |
61243a51 | 185 | } // end of wxMenu::~wxMenu |
0e320a79 DW |
186 | |
187 | void wxMenu::Break() | |
188 | { | |
c5fb56c0 | 189 | // this will take effect during the next call to Append() |
61243a51 DW |
190 | m_bDoBreak = TRUE; |
191 | } // end of wxMenu::Break | |
0e320a79 | 192 | |
c5fb56c0 DW |
193 | #if wxUSE_ACCEL |
194 | ||
61243a51 DW |
195 | int wxMenu::FindAccel( |
196 | int nId | |
197 | ) const | |
0e320a79 | 198 | { |
61243a51 DW |
199 | size_t n; |
200 | size_t nCount = m_vAccels.GetCount(); | |
201 | ||
202 | for (n = 0; n < nCount; n++) | |
c5fb56c0 | 203 | { |
61243a51 | 204 | if (m_vAccels[n]->m_command == nId) |
c5fb56c0 DW |
205 | return n; |
206 | } | |
c5fb56c0 | 207 | return wxNOT_FOUND; |
61243a51 | 208 | } // end of wxMenu::FindAccel |
75f11ad7 | 209 | |
61243a51 DW |
210 | void wxMenu::UpdateAccel( |
211 | wxMenuItem* pItem | |
212 | ) | |
c5fb56c0 | 213 | { |
61243a51 DW |
214 | // |
215 | // Find the (new) accel for this item | |
216 | // | |
217 | wxAcceleratorEntry* pAccel = wxGetAccelFromString(pItem->GetText()); | |
75f11ad7 | 218 | |
61243a51 DW |
219 | if (pAccel) |
220 | pAccel->m_command = pItem->GetId(); | |
221 | ||
222 | // | |
223 | // Find the old one | |
224 | // | |
225 | int n = FindAccel(pItem->GetId()); | |
226 | ||
227 | if (n == wxNOT_FOUND) | |
c5fb56c0 | 228 | { |
61243a51 DW |
229 | // |
230 | // No old, add new if any | |
231 | // | |
232 | if (pAccel) | |
233 | m_vAccels.Add(pAccel); | |
c5fb56c0 DW |
234 | else |
235 | return; // skipping RebuildAccelTable() below | |
236 | } | |
237 | else | |
238 | { | |
61243a51 DW |
239 | // |
240 | // Replace old with new or just remove the old one if no new | |
241 | // | |
242 | delete m_vAccels[n]; | |
243 | ||
244 | if (pAccel) | |
245 | m_vAccels[n] = pAccel; | |
c5fb56c0 | 246 | else |
61243a51 | 247 | m_vAccels.Remove(n); |
75f11ad7 | 248 | } |
c5fb56c0 | 249 | |
61243a51 | 250 | if (IsAttached()) |
c5fb56c0 DW |
251 | { |
252 | m_menuBar->RebuildAccelTable(); | |
253 | } | |
61243a51 | 254 | } // wxMenu::UpdateAccel |
c5fb56c0 | 255 | |
75f11ad7 | 256 | #endif // wxUSE_ACCEL |
0e320a79 | 257 | |
61243a51 DW |
258 | // |
259 | // Append a new item or submenu to the menu | |
260 | // | |
261 | bool wxMenu::DoInsertOrAppend( | |
262 | wxMenuItem* pItem | |
263 | , size_t nPos | |
264 | ) | |
c5fb56c0 | 265 | { |
a0606634 DW |
266 | ERRORID vError; |
267 | wxString sError; | |
c5fb56c0 DW |
268 | #if wxUSE_ACCEL |
269 | UpdateAccel(pItem); | |
270 | #endif // wxUSE_ACCEL | |
0e320a79 | 271 | |
f6bcfd97 BP |
272 | // |
273 | // rItem is the member MENUITEM for the menu items and the submenu's | |
274 | // MENUITEM for submenus as required by ::MM_INSERTITEM message API | |
275 | // | |
276 | ||
277 | wxMenu* pSubmenu = pItem->GetSubMenu(); | |
278 | MENUITEM &rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData: | |
279 | pItem->m_vMenuData; | |
280 | if(pSubmenu != NULL) | |
281 | { | |
282 | wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu")); | |
283 | pSubmenu->SetParent(this); | |
284 | rItem.afStyle |= MIS_SUBMENU | MIS_TEXT; | |
285 | } | |
c3cea748 | 286 | |
61243a51 DW |
287 | // |
288 | // If "Break" has just been called, insert a menu break before this item | |
75f11ad7 | 289 | // (and don't forget to reset the flag) |
61243a51 DW |
290 | // |
291 | if (m_bDoBreak) | |
292 | { | |
f6bcfd97 | 293 | rItem.afStyle |= MIS_BREAK; |
61243a51 | 294 | m_bDoBreak = FALSE; |
75f11ad7 | 295 | } |
0e320a79 | 296 | |
61243a51 DW |
297 | if (pItem->IsSeparator()) |
298 | { | |
c3cea748 | 299 | vItem.afStyle |= MIS_SEPARATOR; |
75f11ad7 DW |
300 | } |
301 | ||
61243a51 DW |
302 | // |
303 | // Id is the numeric id for normal menu items and HMENU for submenus as | |
c3cea748 | 304 | // required by ::MM_INSERTITEM message API |
61243a51 | 305 | // |
c5fb56c0 | 306 | |
61243a51 | 307 | wxMenu* pSubmenu = pItem->GetSubMenu(); |
75f11ad7 | 308 | |
f23208ca | 309 | if (pSubmenu != NULL) |
61243a51 DW |
310 | { |
311 | wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu")); | |
312 | pSubmenu->SetParent(this); | |
75f11ad7 | 313 | |
c3cea748 DW |
314 | vItem.iPosition = 0; // submenus have a 0 position |
315 | vItem.id = (USHORT)pSubmenu->GetHMenu(); | |
316 | vItem.afStyle |= MIS_SUBMENU | MIS_TEXT; | |
75f11ad7 | 317 | } |
61243a51 DW |
318 | else |
319 | { | |
c3cea748 | 320 | vItem.id = pItem->GetId(); |
75f11ad7 DW |
321 | } |
322 | ||
61243a51 | 323 | BYTE* pData; |
75f11ad7 DW |
324 | |
325 | #if wxUSE_OWNER_DRAWN | |
61243a51 DW |
326 | if (pItem->IsOwnerDrawn()) |
327 | { | |
328 | // | |
329 | // Want to get {Measure|Draw}Item messages? | |
75f11ad7 | 330 | // item draws itself, pass pointer to it in data parameter |
c3cea748 | 331 | // Will eventually need to set the image handle somewhere into vItem.hItem |
61243a51 | 332 | // |
f6bcfd97 | 333 | rItem.afStyle |= MIS_OWNERDRAW; |
61243a51 | 334 | pData = (BYTE*)pItem; |
c3cea748 | 335 | // vItem.hItem = ???? |
75f11ad7 DW |
336 | } |
337 | else | |
338 | #endif | |
339 | { | |
61243a51 DW |
340 | // |
341 | // Menu is just a normal string (passed in data parameter) | |
342 | // | |
c3cea748 | 343 | vItem.afStyle |= MIS_TEXT; |
c5fb56c0 | 344 | pData = (char*)pItem->GetText().c_str(); |
75f11ad7 | 345 | } |
c5fb56c0 | 346 | |
f6bcfd97 | 347 | if (nPos == (size_t)-1) |
75f11ad7 | 348 | { |
f6bcfd97 BP |
349 | rItem.iPosition = MIT_END; |
350 | } | |
351 | else | |
352 | { | |
353 | rItem.iPosition = nPos; | |
c5fb56c0 DW |
354 | } |
355 | ||
f6bcfd97 BP |
356 | APIRET rc; |
357 | ||
358 | rc = (APIRET)::WinSendMsg( GetHmenu() | |
359 | ,MM_INSERTITEM | |
360 | ,(MPARAM)&rItem | |
361 | ,(MPARAM)pData | |
362 | ); | |
a0606634 | 363 | if (rc == MIT_MEMERROR || rc == MIT_ERROR) |
c5fb56c0 | 364 | { |
a0606634 DW |
365 | vError = ::WinGetLastError(vHabmain); |
366 | sError = wxPMErrorToStr(vError); | |
367 | wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError); | |
c5fb56c0 | 368 | wxLogLastError("Insert or AppendMenu"); |
c5fb56c0 DW |
369 | return FALSE; |
370 | } | |
371 | else | |
372 | { | |
61243a51 DW |
373 | // |
374 | // If we're already attached to the menubar, we must update it | |
375 | // | |
376 | if (IsAttached()) | |
c5fb56c0 DW |
377 | { |
378 | m_menuBar->Refresh(); | |
379 | } | |
c5fb56c0 | 380 | return TRUE; |
75f11ad7 | 381 | } |
c5fb56c0 | 382 | return FALSE; |
61243a51 | 383 | } // end of wxMenu::DoInsertOrAppend |
0e320a79 | 384 | |
61243a51 DW |
385 | bool wxMenu::DoAppend( |
386 | wxMenuItem* pItem | |
387 | ) | |
0e320a79 | 388 | { |
61243a51 | 389 | return wxMenuBase::DoAppend(pItem) && DoInsertOrAppend(pItem); |
0e320a79 DW |
390 | } |
391 | ||
61243a51 DW |
392 | bool wxMenu::DoInsert( |
393 | size_t nPos | |
394 | , wxMenuItem* pItem | |
395 | ) | |
0e320a79 | 396 | { |
61243a51 DW |
397 | return ( wxMenuBase::DoInsert( nPos |
398 | ,pItem) && | |
399 | DoInsertOrAppend( pItem | |
400 | ,nPos | |
401 | )); | |
402 | } // end of wxMenu::DoInsert | |
0e320a79 | 403 | |
61243a51 DW |
404 | wxMenuItem* wxMenu::DoRemove( |
405 | wxMenuItem* pItem | |
406 | ) | |
0e320a79 | 407 | { |
61243a51 DW |
408 | // |
409 | // We need to find the items position in the child list | |
410 | // | |
411 | size_t nPos; | |
412 | wxMenuItemList::Node* pNode = GetMenuItems().GetFirst(); | |
413 | ||
414 | for (nPos = 0; pNode; nPos++) | |
75f11ad7 | 415 | { |
61243a51 | 416 | if (pNode->GetData() == pItem) |
75f11ad7 | 417 | break; |
61243a51 | 418 | pNode = pNode->GetNext(); |
0e320a79 DW |
419 | } |
420 | ||
61243a51 | 421 | // |
c5fb56c0 | 422 | // DoRemove() (unlike Remove) can only be called for existing item! |
61243a51 DW |
423 | // |
424 | wxCHECK_MSG(pNode, NULL, wxT("bug in wxMenu::Remove logic")); | |
75f11ad7 | 425 | |
c5fb56c0 | 426 | #if wxUSE_ACCEL |
61243a51 DW |
427 | // |
428 | // Remove the corresponding accel from the accel table | |
429 | // | |
430 | int n = FindAccel(pItem->GetId()); | |
75f11ad7 | 431 | |
61243a51 | 432 | if (n != wxNOT_FOUND) |
75f11ad7 | 433 | { |
61243a51 DW |
434 | delete m_vAccels[n]; |
435 | m_vAccels.Remove(n); | |
c5fb56c0 | 436 | } |
61243a51 DW |
437 | |
438 | #endif // wxUSE_ACCEL | |
439 | // | |
440 | // Remove the item from the menu | |
441 | // | |
442 | ::WinSendMsg( GetHmenu() | |
443 | ,MM_REMOVEITEM | |
444 | ,MPFROM2SHORT(pItem->GetId(), TRUE) | |
445 | ,(MPARAM)0 | |
446 | ); | |
447 | if (IsAttached()) | |
448 | { | |
449 | // | |
450 | // Otherwise, the chane won't be visible | |
451 | // | |
c5fb56c0 | 452 | m_menuBar->Refresh(); |
75f11ad7 | 453 | } |
0e320a79 | 454 | |
61243a51 DW |
455 | // |
456 | // And from internal data structures | |
457 | // | |
458 | return wxMenuBase::DoRemove(pItem); | |
459 | } // end of wxMenu::DoRemove | |
0e320a79 | 460 | |
75f11ad7 DW |
461 | // --------------------------------------------------------------------------- |
462 | // accelerator helpers | |
463 | // --------------------------------------------------------------------------- | |
464 | ||
c5fb56c0 DW |
465 | #if wxUSE_ACCEL |
466 | ||
61243a51 DW |
467 | // |
468 | // Create the wxAcceleratorEntries for our accels and put them into provided | |
75f11ad7 | 469 | // array - return the number of accels we have |
61243a51 DW |
470 | // |
471 | size_t wxMenu::CopyAccels( | |
472 | wxAcceleratorEntry* pAccels | |
473 | ) const | |
75f11ad7 | 474 | { |
61243a51 DW |
475 | size_t nCount = GetAccelCount(); |
476 | ||
477 | for (size_t n = 0; n < nCount; n++) | |
75f11ad7 | 478 | { |
61243a51 | 479 | *pAccels++ = *m_vAccels[n]; |
75f11ad7 | 480 | } |
61243a51 DW |
481 | return nCount; |
482 | } // end of wxMenu::CopyAccels | |
0e320a79 | 483 | |
75f11ad7 DW |
484 | #endif // wxUSE_ACCEL |
485 | ||
486 | // --------------------------------------------------------------------------- | |
c5fb56c0 | 487 | // set wxMenu title |
75f11ad7 DW |
488 | // --------------------------------------------------------------------------- |
489 | ||
61243a51 DW |
490 | void wxMenu::SetTitle( |
491 | const wxString& rLabel | |
492 | ) | |
0e320a79 | 493 | { |
61243a51 DW |
494 | bool bHasNoTitle = m_title.IsEmpty(); |
495 | HWND hMenu = GetHmenu(); | |
0e320a79 | 496 | |
61243a51 DW |
497 | m_title = rLabel; |
498 | if (bHasNoTitle) | |
0e320a79 | 499 | { |
61243a51 | 500 | if (!rLabel.IsEmpty()) |
75f11ad7 | 501 | { |
61243a51 | 502 | if (!::WinSetWindowText(hMenu, rLabel.c_str())) |
75f11ad7 | 503 | { |
61243a51 | 504 | wxLogLastError("SetMenuTitle"); |
75f11ad7 DW |
505 | } |
506 | } | |
0e320a79 | 507 | } |
75f11ad7 | 508 | else |
0e320a79 | 509 | { |
61243a51 | 510 | if (rLabel.IsEmpty() ) |
0e320a79 | 511 | { |
61243a51 DW |
512 | ::WinSendMsg( GetHmenu() |
513 | ,MM_REMOVEITEM | |
514 | ,MPFROM2SHORT(hMenu, TRUE) | |
515 | ,(MPARAM)0 | |
516 | ); | |
0e320a79 | 517 | } |
75f11ad7 | 518 | else |
0e320a79 | 519 | { |
61243a51 DW |
520 | // |
521 | // Modify the title | |
522 | // | |
523 | if (!::WinSetWindowText(hMenu, rLabel.c_str())) | |
75f11ad7 | 524 | { |
61243a51 | 525 | wxLogLastError("SetMenuTitle"); |
75f11ad7 | 526 | } |
0e320a79 DW |
527 | } |
528 | } | |
61243a51 | 529 | } // end of wxMenu::SetTitle |
0e320a79 | 530 | |
75f11ad7 DW |
531 | // --------------------------------------------------------------------------- |
532 | // event processing | |
533 | // --------------------------------------------------------------------------- | |
534 | ||
61243a51 DW |
535 | bool wxMenu::OS2Command( |
536 | WXUINT WXUNUSED(uParam) | |
537 | , WXWORD vId | |
538 | ) | |
0e320a79 | 539 | { |
61243a51 DW |
540 | // |
541 | // Ignore commands from the menu title | |
542 | // | |
75f11ad7 | 543 | |
61243a51 | 544 | if (vId != (WXWORD)idMenuTitle) |
75f11ad7 | 545 | { |
61243a51 | 546 | wxCommandEvent vEvent(wxEVT_COMMAND_MENU_SELECTED); |
75f11ad7 | 547 | |
61243a51 DW |
548 | vEvent.SetEventObject(this); |
549 | vEvent.SetId(vId); | |
550 | vEvent.SetInt(vId); | |
551 | ProcessCommand(vEvent); | |
552 | } | |
75f11ad7 | 553 | return TRUE; |
61243a51 | 554 | } // end of wxMenu::OS2Command |
0e320a79 | 555 | |
61243a51 DW |
556 | bool wxMenu::ProcessCommand( |
557 | wxCommandEvent& rEvent | |
558 | ) | |
0e320a79 | 559 | { |
61243a51 | 560 | bool bProcessed = FALSE; |
0e320a79 | 561 | |
61243a51 DW |
562 | #if wxUSE_MENU_CALLBACK |
563 | // | |
0e320a79 | 564 | // Try a callback |
61243a51 | 565 | // |
0e320a79 DW |
566 | if (m_callback) |
567 | { | |
61243a51 DW |
568 | (void)(*(m_callback))(*this, rEvent); |
569 | bProcessed = TRUE; | |
0e320a79 | 570 | } |
61243a51 | 571 | #endif // wxUSE_MENU_CALLBACK |
0e320a79 | 572 | |
61243a51 | 573 | // |
0e320a79 | 574 | // Try the menu's event handler |
61243a51 DW |
575 | // |
576 | if (!bProcessed && GetEventHandler()) | |
0e320a79 | 577 | { |
61243a51 | 578 | bProcessed = GetEventHandler()->ProcessEvent(rEvent); |
0e320a79 | 579 | } |
75f11ad7 | 580 | |
61243a51 | 581 | // |
75f11ad7 DW |
582 | // Try the window the menu was popped up from (and up through the |
583 | // hierarchy) | |
61243a51 | 584 | wxWindow* pWin = GetInvokingWindow(); |
75f11ad7 | 585 | |
61243a51 DW |
586 | if (!bProcessed && pWin) |
587 | bProcessed = pWin->GetEventHandler()->ProcessEvent(rEvent); | |
588 | return bProcessed; | |
589 | } // end of wxMenu::ProcessCommand | |
0e320a79 | 590 | |
75f11ad7 DW |
591 | // --------------------------------------------------------------------------- |
592 | // other | |
593 | // --------------------------------------------------------------------------- | |
594 | ||
61243a51 DW |
595 | void wxMenu::Attach( |
596 | wxMenuBar* pMenubar | |
597 | ) | |
0e320a79 | 598 | { |
61243a51 DW |
599 | // |
600 | // Menu can be in at most one menubar because otherwise they would both | |
75f11ad7 | 601 | // delete the menu pointer |
61243a51 DW |
602 | // |
603 | wxASSERT_MSG(!m_menuBar, wxT("menu belongs to 2 menubars, expect a crash")); | |
604 | m_menuBar = pMenubar; | |
605 | } // end of | |
75f11ad7 DW |
606 | |
607 | void wxMenu::Detach() | |
608 | { | |
609 | wxASSERT_MSG( m_menuBar, wxT("can't detach menu if it's not attached") ); | |
c5fb56c0 | 610 | m_menuBar = NULL; |
61243a51 | 611 | } // end of wxMenu::Detach |
c5fb56c0 | 612 | |
61243a51 | 613 | wxWindow* wxMenu::GetWindow() const |
c5fb56c0 | 614 | { |
61243a51 | 615 | if (m_invokingWindow != NULL) |
c5fb56c0 DW |
616 | return m_invokingWindow; |
617 | else if ( m_menuBar != NULL) | |
618 | return m_menuBar->GetFrame(); | |
619 | ||
620 | return NULL; | |
61243a51 | 621 | } // end of wxMenu::GetWindow |
0e320a79 | 622 | |
75f11ad7 | 623 | // --------------------------------------------------------------------------- |
0e320a79 | 624 | // Menu Bar |
75f11ad7 DW |
625 | // --------------------------------------------------------------------------- |
626 | ||
627 | void wxMenuBar::Init() | |
0e320a79 DW |
628 | { |
629 | m_eventHandler = this; | |
61243a51 | 630 | m_pMenuBarFrame = NULL; |
75f11ad7 | 631 | m_hMenu = 0; |
61243a51 | 632 | } // end of wxMenuBar::Init |
0e320a79 | 633 | |
75f11ad7 DW |
634 | wxMenuBar::wxMenuBar() |
635 | { | |
636 | Init(); | |
61243a51 | 637 | } // end of wxMenuBar::wxMenuBar |
0e320a79 | 638 | |
61243a51 DW |
639 | wxMenuBar::wxMenuBar( |
640 | long WXUNUSED(lStyle) | |
641 | ) | |
0e320a79 | 642 | { |
75f11ad7 | 643 | Init(); |
61243a51 | 644 | } // end of wxMenuBar::wxMenuBar |
75f11ad7 | 645 | |
61243a51 DW |
646 | wxMenuBar::wxMenuBar( |
647 | int nCount | |
648 | , wxMenu* vMenus[] | |
649 | , const wxString sTitles[] | |
650 | ) | |
75f11ad7 DW |
651 | { |
652 | Init(); | |
653 | ||
61243a51 DW |
654 | m_titles.Alloc(nCount); |
655 | for ( int i = 0; i < nCount; i++ ) | |
c5fb56c0 | 656 | { |
61243a51 DW |
657 | m_menus.Append(vMenus[i]); |
658 | m_titles.Add(sTitles[i]); | |
659 | vMenus[i]->Attach(this); | |
c5fb56c0 | 660 | } |
61243a51 | 661 | } // end of wxMenuBar::wxMenuBar |
0e320a79 DW |
662 | |
663 | wxMenuBar::~wxMenuBar() | |
664 | { | |
61243a51 | 665 | } // end of wxMenuBar::~wxMenuBar |
0e320a79 | 666 | |
75f11ad7 DW |
667 | // --------------------------------------------------------------------------- |
668 | // wxMenuBar helpers | |
669 | // --------------------------------------------------------------------------- | |
670 | ||
61243a51 | 671 | void wxMenuBar::Refresh() |
75f11ad7 | 672 | { |
c5fb56c0 | 673 | wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") ); |
75f11ad7 | 674 | |
f23208ca DW |
675 | WinSendMsg(GetWinHwnd(m_pMenuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); |
676 | } // end of wxMenuBar::Refresh | |
75f11ad7 DW |
677 | |
678 | WXHMENU wxMenuBar::Create() | |
679 | { | |
61243a51 | 680 | MENUITEM vItem; |
f23208ca | 681 | HWND hFrame; |
61243a51 | 682 | |
75f11ad7 | 683 | if (m_hMenu != 0 ) |
c5fb56c0 | 684 | return m_hMenu; |
75f11ad7 | 685 | |
61243a51 DW |
686 | wxCHECK_MSG(!m_hMenu, TRUE, wxT("menubar already created")); |
687 | ||
f23208ca DW |
688 | // |
689 | // Menubars should be associated with a frame otherwise they are popups | |
690 | // | |
691 | if (m_pMenuBarFrame != NULL) | |
692 | hFrame = GetWinHwnd(m_pMenuBarFrame); | |
693 | else | |
694 | hFrame = HWND_DESKTOP; | |
61243a51 DW |
695 | // |
696 | // Create an empty menu and then fill it with insertions | |
697 | // | |
f6bcfd97 BP |
698 | if ((m_hMenu = ::WinCreateWindow( hFrame |
699 | ,WC_MENU | |
700 | ,(PSZ)NULL | |
701 | ,MS_ACTIONBAR | WS_SYNCPAINT | WS_VISIBLE | |
702 | ,0L | |
703 | ,0L | |
704 | ,0L | |
705 | ,0L | |
706 | ,hFrame | |
707 | ,HWND_TOP | |
708 | ,FID_MENU | |
709 | ,NULL | |
710 | ,NULL | |
711 | )) == 0) | |
75f11ad7 | 712 | { |
f6bcfd97 | 713 | wxLogLastError("WinLoadMenu"); |
75f11ad7 DW |
714 | } |
715 | else | |
716 | { | |
61243a51 DW |
717 | size_t nCount = GetMenuCount(); |
718 | ||
719 | for (size_t i = 0; i < nCount; i++) | |
75f11ad7 | 720 | { |
c0dbf1fb DW |
721 | APIRET rc; |
722 | ERRORID vError; | |
723 | wxString sError; | |
f6bcfd97 | 724 | HWND hSubMenu; |
c3cea748 DW |
725 | |
726 | // | |
727 | // Set the parent and owner of the submenues to be the menubar, not the desktop | |
728 | // | |
f6bcfd97 BP |
729 | hSubMenu = m_menus[i]->m_vMenuData.hwndSubMenu; |
730 | if (!::WinSetParent(m_menus[i]->m_vMenuData.hwndSubMenu, m_hMenu, FALSE)) | |
c3cea748 DW |
731 | { |
732 | vError = ::WinGetLastError(vHabmain); | |
733 | sError = wxPMErrorToStr(vError); | |
734 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
735 | return NULLHANDLE; | |
736 | } | |
737 | ||
f6bcfd97 | 738 | if (!::WinSetOwner(m_menus[i]->m_vMenuData.hwndSubMenu, m_hMenu)) |
c3cea748 DW |
739 | { |
740 | vError = ::WinGetLastError(vHabmain); | |
741 | sError = wxPMErrorToStr(vError); | |
742 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
743 | return NULLHANDLE; | |
744 | } | |
c0dbf1fb | 745 | |
dae16775 DW |
746 | m_menus[i]->m_vMenuData.iPosition = i; |
747 | ||
f6bcfd97 | 748 | rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&m_menus[i]->m_vMenuData, (MPARAM)m_titles[i].c_str()); |
c0dbf1fb DW |
749 | if (rc == MIT_MEMERROR || rc == MIT_ERROR) |
750 | { | |
751 | vError = ::WinGetLastError(vHabmain); | |
752 | sError = wxPMErrorToStr(vError); | |
753 | wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError); | |
754 | return NULLHANDLE; | |
755 | } | |
75f11ad7 DW |
756 | } |
757 | } | |
f6bcfd97 | 758 | return m_hMenu; |
61243a51 | 759 | } // end of wxMenuBar::Create |
0e320a79 | 760 | |
75f11ad7 | 761 | // --------------------------------------------------------------------------- |
c5fb56c0 | 762 | // wxMenuBar functions to work with the top level submenus |
75f11ad7 DW |
763 | // --------------------------------------------------------------------------- |
764 | ||
61243a51 | 765 | // |
c5fb56c0 DW |
766 | // NB: we don't support owner drawn top level items for now, if we do these |
767 | // functions would have to be changed to use wxMenuItem as well | |
61243a51 DW |
768 | // |
769 | void wxMenuBar::EnableTop( | |
770 | size_t nPos | |
771 | , bool bEnable | |
772 | ) | |
0e320a79 | 773 | { |
61243a51 DW |
774 | wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars")); |
775 | USHORT uFlag = 0; | |
776 | SHORT nId; | |
0e320a79 | 777 | |
61243a51 DW |
778 | if(!bEnable) |
779 | uFlag = MIA_DISABLED; | |
75f11ad7 | 780 | |
61243a51 DW |
781 | nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0)); |
782 | if (nId == MIT_ERROR) | |
783 | { | |
784 | wxLogLastError("LogLastError"); | |
785 | return; | |
786 | } | |
f6bcfd97 | 787 | ::WinSendMsg((HWND)m_hMenu, MM_SETITEMATTR, MPFROM2SHORT(nId, TRUE), MPFROM2SHORT(MIA_DISABLED, uFlag)); |
c5fb56c0 | 788 | Refresh(); |
61243a51 | 789 | } // end of wxMenuBar::EnableTop |
75f11ad7 | 790 | |
61243a51 DW |
791 | void wxMenuBar::SetLabelTop( |
792 | size_t nPos | |
793 | , const wxString& rLabel | |
794 | ) | |
75f11ad7 | 795 | { |
61243a51 DW |
796 | SHORT nId; |
797 | MENUITEM vItem; | |
75f11ad7 | 798 | |
61243a51 DW |
799 | wxCHECK_RET(nPos < GetMenuCount(), wxT("invalid menu index")); |
800 | m_titles[nPos] = rLabel; | |
75f11ad7 | 801 | |
61243a51 | 802 | if (!IsAttached()) |
c5fb56c0 DW |
803 | { |
804 | return; | |
805 | } | |
75f11ad7 | 806 | |
61243a51 DW |
807 | nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0)); |
808 | if (nId == MIT_ERROR) | |
75f11ad7 | 809 | { |
61243a51 | 810 | wxLogLastError("LogLastError"); |
75f11ad7 DW |
811 | return; |
812 | } | |
61243a51 DW |
813 | if(!::WinSendMsg( (HWND)m_hMenu |
814 | ,MM_QUERYITEM | |
815 | ,MPFROM2SHORT(nId, TRUE) | |
816 | ,MPARAM(&vItem) | |
817 | )) | |
75f11ad7 | 818 | { |
61243a51 | 819 | wxLogLastError("QueryItem"); |
c5fb56c0 | 820 | } |
61243a51 | 821 | nId = vItem.id; |
c5fb56c0 | 822 | |
61243a51 | 823 | if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT, MPFROMSHORT(nId), (MPARAM)rLabel.c_str())); |
c5fb56c0 DW |
824 | { |
825 | wxLogLastError("ModifyMenu"); | |
75f11ad7 | 826 | } |
c5fb56c0 | 827 | Refresh(); |
61243a51 | 828 | } // end of wxMenuBar::SetLabelTop |
0e320a79 | 829 | |
61243a51 DW |
830 | wxString wxMenuBar::GetLabelTop( |
831 | size_t nPos | |
832 | ) const | |
0e320a79 | 833 | { |
61243a51 | 834 | wxCHECK_MSG( nPos < GetMenuCount(), wxEmptyString, |
c5fb56c0 | 835 | wxT("invalid menu index in wxMenuBar::GetLabelTop") ); |
61243a51 DW |
836 | return m_titles[nPos]; |
837 | } // end of wxMenuBar::GetLabelTop | |
75f11ad7 | 838 | |
c5fb56c0 DW |
839 | // --------------------------------------------------------------------------- |
840 | // wxMenuBar construction | |
841 | // --------------------------------------------------------------------------- | |
75f11ad7 | 842 | |
61243a51 DW |
843 | wxMenu* wxMenuBar::Replace( |
844 | size_t nPos | |
845 | , wxMenu* pMenu | |
846 | , const wxString& rTitle | |
847 | ) | |
75f11ad7 | 848 | { |
61243a51 | 849 | SHORT nId; |
2b33b728 | 850 | wxString Title = TextToLabel(rTitle); |
61243a51 DW |
851 | wxMenu* pMenuOld = wxMenuBarBase::Replace( nPos |
852 | ,pMenu | |
2b33b728 | 853 | ,Title |
61243a51 DW |
854 | ); |
855 | ||
856 | ||
857 | nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0)); | |
858 | if (nId == MIT_ERROR) | |
859 | { | |
860 | wxLogLastError("LogLastError"); | |
861 | return NULL; | |
862 | } | |
863 | if (!pMenuOld) | |
c5fb56c0 | 864 | return FALSE; |
2b33b728 | 865 | m_titles[nPos] = Title; |
61243a51 | 866 | if (IsAttached()) |
75f11ad7 | 867 | { |
f6bcfd97 | 868 | ::WinSendMsg((HWND)m_hMenu, MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0); |
2b33b728 | 869 | ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str()); |
c5fb56c0 DW |
870 | |
871 | #if wxUSE_ACCEL | |
61243a51 | 872 | if (pMenuOld->HasAccels() || pMenu->HasAccels()) |
c5fb56c0 | 873 | { |
61243a51 DW |
874 | // |
875 | // Need to rebuild accell table | |
876 | // | |
c5fb56c0 DW |
877 | RebuildAccelTable(); |
878 | } | |
879 | #endif // wxUSE_ACCEL | |
c5fb56c0 DW |
880 | Refresh(); |
881 | } | |
61243a51 DW |
882 | return pMenuOld; |
883 | } // end of wxMenuBar::Replace | |
75f11ad7 | 884 | |
61243a51 DW |
885 | bool wxMenuBar::Insert( |
886 | size_t nPos | |
887 | , wxMenu* pMenu | |
888 | , const wxString& rTitle | |
889 | ) | |
75f11ad7 | 890 | { |
2b33b728 | 891 | wxString Title = TextToLabel(rTitle); |
61243a51 DW |
892 | if (!wxMenuBarBase::Insert( nPos |
893 | ,pMenu | |
2b33b728 | 894 | ,Title |
61243a51 | 895 | )) |
c5fb56c0 | 896 | return FALSE; |
75f11ad7 | 897 | |
2b33b728 | 898 | m_titles.Insert( Title |
61243a51 DW |
899 | ,nPos |
900 | ); | |
75f11ad7 | 901 | |
61243a51 | 902 | pMenu->Attach(this); |
75f11ad7 | 903 | |
61243a51 DW |
904 | if (IsAttached()) |
905 | { | |
2b33b728 | 906 | ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str()); |
c5fb56c0 | 907 | #if wxUSE_ACCEL |
61243a51 | 908 | if (pMenu->HasAccels()) |
c5fb56c0 DW |
909 | { |
910 | // need to rebuild accell table | |
911 | RebuildAccelTable(); | |
912 | } | |
913 | #endif // wxUSE_ACCEL | |
c5fb56c0 | 914 | Refresh(); |
75f11ad7 | 915 | } |
c5fb56c0 | 916 | return TRUE; |
61243a51 | 917 | } // end of wxMenuBar::Insert |
75f11ad7 | 918 | |
61243a51 DW |
919 | bool wxMenuBar::Append( |
920 | wxMenu* pMenu | |
921 | , const wxString& rTitle | |
922 | ) | |
0e320a79 | 923 | { |
61243a51 DW |
924 | WXHMENU hSubmenu = pMenu ? pMenu->GetHMenu() : 0; |
925 | ||
926 | wxCHECK_MSG(hSubmenu, FALSE, wxT("can't append invalid menu to menubar")); | |
0e320a79 | 927 | |
2b33b728 SN |
928 | wxString Title = TextToLabel(rTitle); |
929 | if (!wxMenuBarBase::Append(pMenu, Title)) | |
c5fb56c0 | 930 | return FALSE; |
0e320a79 | 931 | |
61243a51 | 932 | pMenu->Attach(this); |
2b33b728 | 933 | m_titles.Add(Title); |
c5fb56c0 | 934 | |
c5fb56c0 | 935 | if ( IsAttached() ) |
0e320a79 | 936 | { |
61243a51 | 937 | pMenu->m_vMenuData.iPosition = MIT_END; |
2b33b728 | 938 | ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str()); |
c5fb56c0 | 939 | #if wxUSE_ACCEL |
61243a51 | 940 | if (pMenu->HasAccels()) |
c5fb56c0 | 941 | { |
61243a51 DW |
942 | // |
943 | // Need to rebuild accell table | |
944 | // | |
c5fb56c0 DW |
945 | RebuildAccelTable(); |
946 | } | |
947 | #endif // wxUSE_ACCEL | |
c5fb56c0 DW |
948 | Refresh(); |
949 | } | |
c5fb56c0 | 950 | return TRUE; |
61243a51 | 951 | } // end of wxMenuBar::Append |
0e320a79 | 952 | |
61243a51 DW |
953 | wxMenu* wxMenuBar::Remove( |
954 | size_t nPos | |
955 | ) | |
0e320a79 | 956 | { |
61243a51 DW |
957 | wxMenu* pMenu = wxMenuBarBase::Remove(nPos); |
958 | SHORT nId; | |
959 | ||
960 | if (!pMenu) | |
c5fb56c0 | 961 | return NULL; |
0e320a79 | 962 | |
61243a51 DW |
963 | nId = SHORT1FROMMR(::WinSendMsg((HWND)GetHmenu(), MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0)); |
964 | if (nId == MIT_ERROR) | |
965 | { | |
966 | wxLogLastError("LogLastError"); | |
967 | return NULL; | |
968 | } | |
969 | if (IsAttached()) | |
970 | { | |
f6bcfd97 | 971 | ::WinSendMsg((HWND)GetHmenu(), MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0); |
61243a51 | 972 | pMenu->Detach(); |
0e320a79 | 973 | |
c5fb56c0 | 974 | #if wxUSE_ACCEL |
61243a51 | 975 | if (pMenu->HasAccels()) |
c5fb56c0 | 976 | { |
61243a51 DW |
977 | // |
978 | // Need to rebuild accell table | |
979 | // | |
c5fb56c0 DW |
980 | RebuildAccelTable(); |
981 | } | |
982 | #endif // wxUSE_ACCEL | |
c5fb56c0 | 983 | Refresh(); |
0e320a79 | 984 | } |
61243a51 DW |
985 | m_titles.Remove(nPos); |
986 | return pMenu; | |
987 | } // end of wxMenuBar::Remove | |
75f11ad7 DW |
988 | |
989 | #if wxUSE_ACCEL | |
c5fb56c0 DW |
990 | |
991 | void wxMenuBar::RebuildAccelTable() | |
992 | { | |
61243a51 DW |
993 | // |
994 | // Merge the accelerators of all menus into one accel table | |
995 | // | |
996 | size_t nAccelCount = 0; | |
997 | size_t i; | |
998 | size_t nCount = GetMenuCount(); | |
999 | ||
1000 | for (i = 0; i < nCount; i++) | |
75f11ad7 DW |
1001 | { |
1002 | nAccelCount += m_menus[i]->GetAccelCount(); | |
1003 | } | |
1004 | ||
61243a51 | 1005 | if (nAccelCount) |
0e320a79 | 1006 | { |
61243a51 | 1007 | wxAcceleratorEntry* pAccelEntries = new wxAcceleratorEntry[nAccelCount]; |
75f11ad7 DW |
1008 | |
1009 | nAccelCount = 0; | |
61243a51 | 1010 | for (i = 0; i < nCount; i++) |
75f11ad7 | 1011 | { |
61243a51 | 1012 | nAccelCount += m_menus[i]->CopyAccels(&pAccelEntries[nAccelCount]); |
75f11ad7 | 1013 | } |
61243a51 DW |
1014 | m_vAccelTable = wxAcceleratorTable( nAccelCount |
1015 | ,pAccelEntries | |
1016 | ); | |
1017 | delete [] pAccelEntries; | |
0e320a79 | 1018 | } |
61243a51 | 1019 | } // end of wxMenuBar::RebuildAccelTable |
c5fb56c0 DW |
1020 | |
1021 | #endif // wxUSE_ACCEL | |
1022 | ||
61243a51 DW |
1023 | void wxMenuBar::Attach( |
1024 | wxFrame* pFrame | |
1025 | ) | |
c5fb56c0 DW |
1026 | { |
1027 | wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") ); | |
61243a51 | 1028 | m_pMenuBarFrame = pFrame; |
c5fb56c0 DW |
1029 | |
1030 | #if wxUSE_ACCEL | |
1031 | RebuildAccelTable(); | |
f6bcfd97 BP |
1032 | // |
1033 | // Ensure the accelerator table is set to the frame (not the client!) | |
1034 | // | |
1035 | if (!::WinSetAccelTable( vHabmain | |
1036 | ,(HWND)pFrame->GetFrame() | |
1037 | ,m_vAccelTable.GetHACCEL() | |
1038 | )) | |
1039 | wxLogLastError("WinSetAccelTable"); | |
75f11ad7 | 1040 | #endif // wxUSE_ACCEL |
61243a51 | 1041 | } // end of wxMenuBar::Attach |
0e320a79 | 1042 | |
75f11ad7 | 1043 | void wxMenuBar::Detach() |
0e320a79 | 1044 | { |
61243a51 | 1045 | ::WinDestroyWindow((HWND)m_hMenu); |
c5fb56c0 | 1046 | m_hMenu = (WXHMENU)NULL; |
61243a51 DW |
1047 | m_pMenuBarFrame = NULL; |
1048 | } // end of wxMenuBar::Detach | |
75f11ad7 DW |
1049 | |
1050 | // --------------------------------------------------------------------------- | |
1051 | // wxMenuBar searching for menu items | |
1052 | // --------------------------------------------------------------------------- | |
1053 | ||
61243a51 | 1054 | // |
75f11ad7 | 1055 | // Find the itemString in menuString, and return the item id or wxNOT_FOUND |
61243a51 DW |
1056 | // |
1057 | int wxMenuBar::FindMenuItem( | |
1058 | const wxString& rMenuString | |
1059 | , const wxString& rItemString | |
1060 | ) const | |
75f11ad7 | 1061 | { |
61243a51 DW |
1062 | wxString sMenuLabel = wxStripMenuCodes(rMenuString); |
1063 | size_t nCount = GetMenuCount(); | |
1064 | ||
1065 | for (size_t i = 0; i < nCount; i++) | |
75f11ad7 | 1066 | { |
61243a51 | 1067 | wxString sTitle = wxStripMenuCodes(m_titles[i]); |
75f11ad7 | 1068 | |
61243a51 DW |
1069 | if (rMenuString == sTitle) |
1070 | return m_menus[i]->FindItem(rItemString); | |
1071 | } | |
75f11ad7 | 1072 | return wxNOT_FOUND; |
61243a51 | 1073 | } // end of wxMenuBar::FindMenuItem |
75f11ad7 | 1074 | |
61243a51 DW |
1075 | wxMenuItem* wxMenuBar::FindItem( |
1076 | int nId | |
1077 | , wxMenu** ppItemMenu | |
1078 | ) const | |
75f11ad7 | 1079 | { |
61243a51 DW |
1080 | if (ppItemMenu) |
1081 | *ppItemMenu = NULL; | |
1082 | ||
1083 | wxMenuItem* pItem = NULL; | |
1084 | size_t nCount = GetMenuCount(); | |
0e320a79 | 1085 | |
61243a51 | 1086 | for (size_t i = 0; !pItem && (i < nCount); i++) |
75f11ad7 | 1087 | { |
61243a51 DW |
1088 | pItem = m_menus[i]->FindItem( nId |
1089 | ,ppItemMenu | |
1090 | ); | |
75f11ad7 | 1091 | } |
61243a51 DW |
1092 | return pItem; |
1093 | } // end of wxMenuBar::FindItem | |
75f11ad7 | 1094 | |
dae16775 | 1095 |