1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar, wxMenuItem
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
14 // headers & declarations
15 // ============================================================================
21 #pragma implementation "menu.h"
22 #pragma implementation "menuitem.h"
27 #include "wx/menuitem.h"
28 #include "wx/window.h"
32 #include "wx/mac/uma.h"
34 // other standard headers
35 // ----------------------
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
40 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
43 // the (popup) menu title has this special id
44 static const int idMenuTitle
= -2;
45 static MenuItemIndex firstUserHelpMenuItem
= 0 ;
47 const short kwxMacMenuBarResource
= 1 ;
48 const short kwxMacAppleMenuId
= 1 ;
50 // ============================================================================
52 // ============================================================================
57 // Construct a menu with optional title (then use append)
60 short wxMenu::s_macNextMenuId
= 3 ;
62 short wxMenu::s_macNextMenuId
= 2 ;
71 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, m_title
, false );
72 m_macMenuId
= s_macNextMenuId
++;
73 m_hMenu
= ::NewMenu(m_macMenuId
, label
);
77 wxLogLastError("CreatePopupMenu");
80 // if we have a title, insert it in the beginning of the menu
83 Append(idMenuTitle
, m_title
) ;
90 if (MAC_WXHMENU(m_hMenu
))
91 ::DisposeMenu(MAC_WXHMENU(m_hMenu
));
95 WX_CLEAR_ARRAY(m_accels
);
101 // not available on the mac platform
106 int wxMenu::FindAccel(int id
) const
108 size_t n
, count
= m_accels
.GetCount();
109 for ( n
= 0; n
< count
; n
++ )
111 if ( m_accels
[n
]->m_command
== id
)
118 void wxMenu::UpdateAccel(wxMenuItem
*item
)
120 // find the (new) accel for this item
121 wxAcceleratorEntry
*accel
= wxGetAccelFromString(item
->GetText());
123 accel
->m_command
= item
->GetId();
126 int n
= FindAccel(item
->GetId());
127 if ( n
== wxNOT_FOUND
)
129 // no old, add new if any
133 return; // skipping RebuildAccelTable() below
137 // replace old with new or just remove the old one if no new
142 m_accels
.RemoveAt(n
);
147 m_menuBar
->RebuildAccelTable();
151 #endif // wxUSE_ACCEL
153 // function appends a new item or submenu to the menu
154 // append a new item or submenu to the menu
155 bool wxMenu::DoInsertOrAppend(wxMenuItem
*pItem
, size_t pos
)
157 wxASSERT_MSG( pItem
!= NULL
, "can't append NULL item to the menu" );
160 #endif // wxUSE_ACCEL
162 if ( pItem
->IsSeparator() )
164 if ( pos
== (size_t)-1 )
166 MacAppendMenu(MAC_WXHMENU(m_hMenu
), "\p-");
170 MacInsertMenuItem(MAC_WXHMENU(m_hMenu
), "\p-" , pos
);
175 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
176 if ( pSubMenu
!= NULL
)
179 wxASSERT_MSG( pSubMenu
->m_hMenu
!= NULL
, "invalid submenu added");
180 pSubMenu
->m_menuParent
= this ;
181 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, pItem
->GetText() ,false);
183 if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar
)
185 ::InsertMenu( MAC_WXHMENU( pSubMenu
->m_hMenu
) , -1 ) ;
188 if ( pos
== (size_t)-1 )
190 UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu
), label
, pSubMenu
->m_macMenuId
);
194 UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu
), label
, pos
, pSubMenu
->m_macMenuId
);
202 wxMenuItem::MacBuildMenuString( label
, &key
, &modifiers
, pItem
->GetText(), pItem
->GetId() == wxApp::s_macAboutMenuItemId
);
205 // we cannot add empty menus on mac
209 if ( pos
== (size_t)-1 )
211 UMAAppendMenuItem(MAC_WXHMENU(m_hMenu
), label
,key
,modifiers
);
212 if ( pItem
->GetBitmap().Ok() )
214 ControlButtonContentInfo info
;
215 wxMacCreateBitmapButton( &info
, pItem
->GetBitmap() , true ) ;
216 if ( info
.contentType
!= kControlNoContent
)
218 if ( info
.contentType
== kControlContentCIconHandle
)
219 SetMenuItemIconHandle( MAC_WXHMENU(m_hMenu
) , CountMenuItems(MAC_WXHMENU(m_hMenu
) ) ,
220 kMenuColorIconType
, (Handle
) info
.u
.cIconHandle
) ;
227 UMAInsertMenuItem(MAC_WXHMENU(m_hMenu
), label
, pos
,key
,modifiers
);
228 if ( pItem
->GetBitmap().Ok() )
230 ControlButtonContentInfo info
;
231 wxMacCreateBitmapButton( &info
, pItem
->GetBitmap() , true ) ;
232 if ( info
.contentType
!= kControlNoContent
)
234 if ( info
.contentType
== kControlContentCIconHandle
)
235 SetMenuItemIconHandle( MAC_WXHMENU(m_hMenu
) , pos
,
236 kMenuColorIconType
, (Handle
) info
.u
.cIconHandle
) ;
241 if ( pItem
->GetId() == idMenuTitle
)
243 if ( pos
== (size_t)-1 )
245 UMADisableMenuItem(MAC_WXHMENU(m_hMenu
) , CountMenuItems(MAC_WXHMENU(m_hMenu
) ) ) ;
249 UMADisableMenuItem(MAC_WXHMENU(m_hMenu
) , pos
+ 1 ) ;
254 // if we're already attached to the menubar, we must update it
257 m_menuBar
->Refresh();
262 bool wxMenu::DoAppend(wxMenuItem
*item
)
264 return wxMenuBase::DoAppend(item
) && DoInsertOrAppend(item
);
267 bool wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
269 return wxMenuBase::DoInsert(pos
, item
) && DoInsertOrAppend(item
, pos
);
272 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
274 // we need to find the items position in the child list
276 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
277 for ( pos
= 0; node
; pos
++ )
279 if ( node
->GetData() == item
)
282 node
= node
->GetNext();
285 // DoRemove() (unlike Remove) can only be called for existing item!
286 wxCHECK_MSG( node
, NULL
, wxT("bug in wxMenu::Remove logic") );
289 // remove the corresponding accel from the accel table
290 int n
= FindAccel(item
->GetId());
291 if ( n
!= wxNOT_FOUND
)
295 m_accels
.RemoveAt(n
);
297 //else: this item doesn't have an accel, nothing to do
298 #endif // wxUSE_ACCEL
300 ::DeleteMenuItem(MAC_WXHMENU(m_hMenu
) , pos
+ 1);
304 // otherwise, the chane won't be visible
305 m_menuBar
->Refresh();
308 // and from internal data structures
309 return wxMenuBase::DoRemove(item
);
312 // ---------------------------------------------------------------------------
313 // accelerator helpers
314 // ---------------------------------------------------------------------------
318 // create the wxAcceleratorEntries for our accels and put them into provided
319 // array - return the number of accels we have
320 size_t wxMenu::CopyAccels(wxAcceleratorEntry
*accels
) const
322 size_t count
= GetAccelCount();
323 for ( size_t n
= 0; n
< count
; n
++ )
325 *accels
++ = *m_accels
[n
];
331 #endif // wxUSE_ACCEL
333 void wxMenu::SetTitle(const wxString
& label
)
337 wxMenuItem::MacBuildMenuString( title
, NULL
, NULL
, label
, false );
338 UMASetMenuTitle(MAC_WXHMENU(m_hMenu
) , title
) ;
340 bool wxMenu::ProcessCommand(wxCommandEvent
& event
)
342 bool processed
= FALSE
;
344 #if WXWIN_COMPATIBILITY
348 (void)(*(m_callback
))(*this, event
);
351 #endif WXWIN_COMPATIBILITY
353 // Try the menu's event handler
354 if ( !processed
&& GetEventHandler())
356 processed
= GetEventHandler()->ProcessEvent(event
);
359 // Try the window the menu was popped up from (and up through the
361 wxWindow
*win
= GetInvokingWindow();
362 if ( !processed
&& win
)
363 processed
= win
->GetEventHandler()->ProcessEvent(event
);
369 // ---------------------------------------------------------------------------
371 // ---------------------------------------------------------------------------
373 wxWindow
*wxMenu::GetWindow() const
375 if ( m_invokingWindow
!= NULL
)
376 return m_invokingWindow
;
377 else if ( m_menuBar
!= NULL
)
378 return (wxWindow
*) m_menuBar
->GetFrame();
383 // helper functions returning the mac menu position for a certain item, note that this is
384 // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
386 int wxMenu::MacGetIndexFromId( int id
)
389 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
390 for ( pos
= 0; node
; pos
++ )
392 if ( node
->GetData()->GetId() == id
)
395 node
= node
->GetNext();
404 int wxMenu::MacGetIndexFromItem( wxMenuItem
*pItem
)
407 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
408 for ( pos
= 0; node
; pos
++ )
410 if ( node
->GetData() == pItem
)
413 node
= node
->GetNext();
422 void wxMenu::MacEnableMenu( bool bDoEnable
)
425 UMAEnableMenuItem(MAC_WXHMENU(m_hMenu
) , 0 ) ;
427 UMADisableMenuItem(MAC_WXHMENU(m_hMenu
) , 0 ) ;
432 bool wxMenu::MacMenuSelect( wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
437 if ( m_macMenuId
== macMenuId
)
439 node
= GetMenuItems().Nth(macMenuItemNum
-1);
442 wxMenuItem
*pItem
= (wxMenuItem
*)node
->Data();
444 if (pItem
->IsCheckable())
445 pItem
->Check(! pItem
->IsChecked());
447 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
448 event
.m_timeStamp
= when
;
449 event
.SetEventObject(handler
);
450 event
.SetInt( pItem
->GetId() );
452 bool processed
= false ;
454 #if WXWIN_COMPATIBILITY
458 (void) (*(m_callback
)) (*this, event
);
462 // Try the menu's event handler
463 if ( !processed
&& handler
)
465 processed
= handler
->ProcessEvent(event
);
468 // Try the window the menu was popped up from (and up
469 // through the hierarchy)
470 if ( !processed
&& GetInvokingWindow())
471 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
476 else if ( macMenuId
== kHMHelpMenuID
)
478 int menuItem
= firstUserHelpMenuItem
-1 ;
479 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
481 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
483 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
484 if ( pSubMenu
!= NULL
)
489 if ( pItem
->GetId() != wxApp::s_macAboutMenuItemId
)
492 if ( menuItem
== macMenuItemNum
)
494 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
495 event
.m_timeStamp
= when
;
496 event
.SetEventObject(handler
);
497 event
.SetInt( pItem
->GetId() );
499 bool processed
= false ;
500 #if WXWIN_COMPATIBILITY
504 (void) (*(m_callback
)) (*this, event
);
508 // Try the menu's event handler
509 if ( !processed
&& handler
)
511 processed
= handler
->ProcessEvent(event
);
514 // Try the window the menu was popped up from (and up
515 // through the hierarchy)
516 if ( !processed
&& GetInvokingWindow())
517 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
525 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
527 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
529 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
530 if ( pSubMenu
!= NULL
)
532 if ( pSubMenu
->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
544 Mac Implementation note :
546 The Mac has only one global menubar, so we attempt to install the currently
547 active menubar from a frame, we currently don't take into account mdi-frames
548 which would ask for menu-merging
550 Secondly there is no mac api for changing a menubar that is not the current
551 menubar, so we have to wait for preparing the actual menubar until the
552 wxMenubar is to be used
554 We can in subsequent versions use MacInstallMenuBar to provide some sort of
555 auto-merge for MDI in case this will be necessary
559 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
561 void wxMenuBar::Init()
563 m_eventHandler
= this;
564 m_menuBarFrame
= NULL
;
567 wxMenuBar::wxMenuBar()
572 wxMenuBar::wxMenuBar( long WXUNUSED(style
) )
578 wxMenuBar::wxMenuBar(int count
, wxMenu
*menus
[], const wxString titles
[])
582 m_titles
.Alloc(count
);
584 for ( int i
= 0; i
< count
; i
++ )
586 m_menus
.Append(menus
[i
]);
587 m_titles
.Add(titles
[i
]);
589 menus
[i
]->Attach(this);
593 wxMenuBar::~wxMenuBar()
595 if (s_macInstalledMenuBar
== this)
598 s_macInstalledMenuBar
= NULL
;
603 void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground
), const wxRect
*WXUNUSED(rect
))
605 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
612 void wxMenuBar::RebuildAccelTable()
614 // merge the accelerators of all menus into one accel table
615 size_t nAccelCount
= 0;
616 size_t i
, count
= GetMenuCount();
617 for ( i
= 0; i
< count
; i
++ )
619 nAccelCount
+= m_menus
[i
]->GetAccelCount();
624 wxAcceleratorEntry
*accelEntries
= new wxAcceleratorEntry
[nAccelCount
];
627 for ( i
= 0; i
< count
; i
++ )
629 nAccelCount
+= m_menus
[i
]->CopyAccels(&accelEntries
[nAccelCount
]);
632 m_accelTable
= wxAcceleratorTable(nAccelCount
, accelEntries
);
634 delete [] accelEntries
;
638 #endif // wxUSE_ACCEL
640 void wxMenuBar::MacInstallMenuBar()
642 if ( s_macInstalledMenuBar
== this )
645 wxStAppResource resload
;
647 Handle menubar
= ::GetNewMBar( kwxMacMenuBarResource
) ;
649 wxCHECK_RET( menubar
!= NULL
, "can't read MBAR resource" );
650 ::SetMenuBar( menubar
) ;
651 #if TARGET_API_MAC_CARBON
652 ::DisposeMenuBar( menubar
) ;
654 ::DisposeHandle( menubar
) ;
657 #if TARGET_API_MAC_OS8
658 MenuHandle menu
= ::GetMenuHandle( kwxMacAppleMenuId
) ;
659 if ( CountMenuItems( menu
) == 2 )
661 ::AppendResMenu(menu
, 'DRVR');
665 for (size_t i
= 0; i
< m_menus
.GetCount(); i
++)
671 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
673 if( m_titles
[i
] == "?" || m_titles
[i
] == "&?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
675 MenuHandle mh
= NULL
;
676 if ( UMAGetHelpMenu( &mh
, &firstUserHelpMenuItem
) != noErr
)
681 for ( int i
= CountMenuItems( mh
) ; i
>= firstUserHelpMenuItem
; --i
)
683 DeleteMenuItem( mh
, i
) ;
686 for (pos
= 0 , node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
688 item
= (wxMenuItem
*)node
->Data();
689 subMenu
= item
->GetSubMenu() ;
692 // we don't support hierarchical menus in the help menu yet
696 if ( item
->IsSeparator() )
699 MacAppendMenu(mh
, "\p-" );
706 wxMenuItem::MacBuildMenuString( label
, &key
, &modifiers
, item
->GetText(), item
->GetId() != wxApp::s_macAboutMenuItemId
); // no shortcut in about menu
709 // we cannot add empty menus on mac
713 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
715 ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , label
);
716 UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 );
721 UMAAppendMenuItem(mh
, label
, key
, modifiers
);
729 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, m_titles
[i
] , false );
730 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
731 wxArrayPtrVoid submenus
;
733 for (pos
= 0, node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
735 item
= (wxMenuItem
*)node
->Data();
736 subMenu
= item
->GetSubMenu() ;
739 submenus
.Add(subMenu
) ;
742 ::InsertMenu(MAC_WXHMENU(m_menus
[i
]->GetHMenu()), 0);
743 for ( size_t i
= 0 ; i
< submenus
.GetCount() ; ++i
)
745 wxMenu
* submenu
= (wxMenu
*) submenus
[i
] ;
749 for ( subpos
= 0 , subnode
= submenu
->GetMenuItems().First(); subnode
; subnode
= subnode
->Next(), subpos
++)
751 subitem
= (wxMenuItem
*)subnode
->Data();
752 wxMenu
* itsSubMenu
= subitem
->GetSubMenu() ;
755 submenus
.Add(itsSubMenu
) ;
758 ::InsertMenu( MAC_WXHMENU(submenu
->GetHMenu()) , -1 ) ;
763 s_macInstalledMenuBar
= this;
766 void wxMenuBar::EnableTop(size_t pos
, bool enable
)
768 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
769 m_menus
[pos
]->MacEnableMenu( enable
) ;
773 void wxMenuBar::SetLabelTop(size_t pos
, const wxString
& label
)
775 wxCHECK_RET( pos
< GetMenuCount(), wxT("invalid menu index") );
777 m_titles
[pos
] = label
;
784 m_menus
[pos
]->SetTitle( label
) ;
785 if (wxMenuBar::s_macInstalledMenuBar
== this) // are we currently installed ?
787 ::SetMenuBar( GetMenuBar() ) ;
792 wxString
wxMenuBar::GetLabelTop(size_t pos
) const
794 wxCHECK_MSG( pos
< GetMenuCount(), wxEmptyString
,
795 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
797 return m_titles
[pos
];
800 int wxMenuBar::FindMenu(const wxString
& title
)
802 wxString menuTitle
= wxStripMenuCodes(title
);
804 size_t count
= GetMenuCount();
805 for ( size_t i
= 0; i
< count
; i
++ )
807 wxString title
= wxStripMenuCodes(m_titles
[i
]);
808 if ( menuTitle
== title
)
817 // ---------------------------------------------------------------------------
818 // wxMenuBar construction
819 // ---------------------------------------------------------------------------
821 // ---------------------------------------------------------------------------
822 // wxMenuBar construction
823 // ---------------------------------------------------------------------------
825 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
827 wxMenu
*menuOld
= wxMenuBarBase::Replace(pos
, menu
, title
);
830 m_titles
[pos
] = title
;
834 if (s_macInstalledMenuBar
== this)
836 ::DeleteMenu( menuOld
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
839 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, title
, false );
840 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
841 if ( pos
== m_menus
.GetCount() - 1)
843 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
847 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
854 if ( menuOld
->HasAccels() || menu
->HasAccels() )
856 // need to rebuild accell table
859 #endif // wxUSE_ACCEL
867 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
869 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
872 m_titles
.Insert(title
, pos
);
875 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, title
, false );
876 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
880 if ( pos
== (size_t) -1 || pos
+ 1 == m_menus
.GetCount() )
882 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
886 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
890 if ( menu
->HasAccels() )
892 // need to rebuild accell table
895 #endif // wxUSE_ACCEL
903 void wxMenuBar::MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
905 // first scan fast for direct commands, i.e. menus which have these commands directly in their own list
907 if ( macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
== 1 )
909 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, wxApp::s_macAboutMenuItemId
);
910 event
.m_timeStamp
= when
;
911 event
.SetEventObject(handler
);
912 event
.SetInt( wxApp::s_macAboutMenuItemId
);
913 handler
->ProcessEvent(event
);
917 for (size_t i
= 0; i
< m_menus
.GetCount() ; i
++)
919 if ( m_menus
[i
]->MacGetMenuId() == macMenuId
|| ( macMenuId
== kHMHelpMenuID
&& ( m_titles
[i
] == "?" || m_titles
[i
] == "&?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
) ) )
921 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
925 //TODO flag this as an error since it must contain the item
931 for (size_t i
= 0; i
< m_menus
.GetCount(); i
++)
933 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
941 wxMenu
*wxMenuBar::Remove(size_t pos
)
943 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
949 if (s_macInstalledMenuBar
== this)
951 ::DeleteMenu( menu
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
957 if ( menu
->HasAccels() )
959 // need to rebuild accell table
962 #endif // wxUSE_ACCEL
967 m_titles
.Remove(pos
);
972 bool wxMenuBar::Append(wxMenu
*menu
, const wxString
& title
)
974 WXHMENU submenu
= menu
? menu
->GetHMenu() : 0;
975 wxCHECK_MSG( submenu
, FALSE
, wxT("can't append invalid menu to menubar") );
977 if ( !wxMenuBarBase::Append(menu
, title
) )
983 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, title
, false );
984 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
988 if (s_macInstalledMenuBar
== this)
990 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
994 if ( menu
->HasAccels() )
996 // need to rebuild accell table
999 #endif // wxUSE_ACCEL
1007 void wxMenuBar::Detach()
1009 wxMenuBarBase::Detach() ;
1012 void wxMenuBar::Attach(wxFrame
*frame
)
1014 wxMenuBarBase::Attach( frame
) ;
1017 RebuildAccelTable();
1018 #endif // wxUSE_ACCEL
1020 // ---------------------------------------------------------------------------
1021 // wxMenuBar searching for menu items
1022 // ---------------------------------------------------------------------------
1024 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1025 int wxMenuBar::FindMenuItem(const wxString
& menuString
,
1026 const wxString
& itemString
) const
1028 wxString menuLabel
= wxStripMenuCodes(menuString
);
1029 size_t count
= GetMenuCount();
1030 for ( size_t i
= 0; i
< count
; i
++ )
1032 wxString title
= wxStripMenuCodes(m_titles
[i
]);
1033 if ( menuString
== title
)
1034 return m_menus
[i
]->FindItem(itemString
);
1040 wxMenuItem
*wxMenuBar::FindItem(int id
, wxMenu
**itemMenu
) const
1045 wxMenuItem
*item
= NULL
;
1046 size_t count
= GetMenuCount();
1047 for ( size_t i
= 0; !item
&& (i
< count
); i
++ )
1049 item
= m_menus
[i
]->FindItem(id
, itemMenu
);