1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar, wxMenuItem
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "menu.h"
14 #pragma implementation "menuitem.h"
17 // ============================================================================
18 // headers & declarations
19 // ============================================================================
26 #include "wx/menuitem.h"
27 #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
= -3;
45 static MenuItemIndex firstUserHelpMenuItem
= 0 ;
47 const short kwxMacMenuBarResource
= 1 ;
48 const short kwxMacAppleMenuId
= 1 ;
51 // Find an item given the Macintosh Menu Reference
53 wxList
wxWinMacMenuList(wxKEY_INTEGER
);
54 wxMenu
*wxFindMenuFromMacMenu(MenuRef inMenuRef
)
56 wxNode
*node
= wxWinMacMenuList
.Find((long)inMenuRef
);
59 return (wxMenu
*)node
->GetData();
62 void wxAssociateMenuWithMacMenu(MenuRef inMenuRef
, wxMenu
*menu
) ;
63 void wxAssociateMenuWithMacMenu(MenuRef inMenuRef
, wxMenu
*menu
)
65 // adding NULL MenuRef is (first) surely a result of an error and
66 // (secondly) breaks menu command processing
67 wxCHECK_RET( inMenuRef
!= (MenuRef
) NULL
, wxT("attempt to add a NULL MenuRef to menu list") );
69 if ( !wxWinMacMenuList
.Find((long)inMenuRef
) )
70 wxWinMacMenuList
.Append((long)inMenuRef
, menu
);
73 void wxRemoveMacMenuAssociation(wxMenu
*menu
) ;
74 void wxRemoveMacMenuAssociation(wxMenu
*menu
)
76 wxWinMacMenuList
.DeleteObject(menu
);
80 // ============================================================================
82 // ============================================================================
83 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
) ;
84 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
);
88 // Construct a menu with optional title (then use append)
91 short wxMenu::s_macNextMenuId
= 3 ;
93 short wxMenu::s_macNextMenuId
= 2 ;
99 m_startRadioGroup
= -1;
102 m_macMenuId
= s_macNextMenuId
++;
103 m_hMenu
= UMANewMenu(m_macMenuId
, m_title
, wxFont::GetDefaultEncoding() );
107 wxLogLastError(wxT("UMANewMenu failed"));
110 wxAssociateMenuWithMacMenu( (MenuRef
)m_hMenu
, this ) ;
112 // if we have a title, insert it in the beginning of the menu
115 Append(idMenuTitle
, m_title
) ;
122 wxRemoveMacMenuAssociation( this ) ;
123 if (MAC_WXHMENU(m_hMenu
))
124 ::DisposeMenu(MAC_WXHMENU(m_hMenu
));
129 // not available on the mac platform
132 void wxMenu::Attach(wxMenuBarBase
*menubar
)
134 wxMenuBase::Attach(menubar
);
139 // function appends a new item or submenu to the menu
140 // append a new item or submenu to the menu
141 bool wxMenu::DoInsertOrAppend(wxMenuItem
*pItem
, size_t pos
)
143 wxASSERT_MSG( pItem
!= NULL
, wxT("can't append NULL item to the menu") );
145 if ( pItem
->IsSeparator() )
147 if ( pos
== (size_t)-1 )
148 MacAppendMenu(MAC_WXHMENU(m_hMenu
), "\p-");
150 MacInsertMenuItem(MAC_WXHMENU(m_hMenu
), "\p-" , pos
);
154 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
155 if ( pSubMenu
!= NULL
)
157 wxASSERT_MSG( pSubMenu
->m_hMenu
!= NULL
, wxT("invalid submenu added"));
158 pSubMenu
->m_menuParent
= this ;
160 if (wxMenuBar::MacGetInstalledMenuBar() == GetMenuBar())
162 pSubMenu
->MacBeforeDisplay( true ) ;
165 if ( pos
== (size_t)-1 )
166 UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu
), pItem
->GetText(), wxFont::GetDefaultEncoding() , pSubMenu
->m_macMenuId
);
168 UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu
), pItem
->GetText(), wxFont::GetDefaultEncoding() , pos
, pSubMenu
->m_macMenuId
);
169 pItem
->UpdateItemBitmap() ;
170 pItem
->UpdateItemStatus() ;
174 if ( pos
== (size_t)-1 )
176 UMAAppendMenuItem(MAC_WXHMENU(m_hMenu
), wxT("a") , wxFont::GetDefaultEncoding() );
177 pos
= CountMenuItems(MAC_WXHMENU(m_hMenu
)) ;
181 // MacOS counts menu items from 1 and inserts after, therefore having the
182 // same effect as wx 0 based and inserting before, we must correct pos
183 // after however for updates to be correct
184 UMAInsertMenuItem(MAC_WXHMENU(m_hMenu
), wxT("a"), wxFont::GetDefaultEncoding(), pos
);
188 SetMenuItemCommandID( MAC_WXHMENU(m_hMenu
) , pos
, pItem
->GetId() ) ;
189 SetMenuItemRefCon( MAC_WXHMENU(m_hMenu
) , pos
, (UInt32
) pItem
) ;
190 pItem
->UpdateItemText() ;
191 pItem
->UpdateItemBitmap() ;
192 pItem
->UpdateItemStatus() ;
194 if ( pItem
->GetId() == idMenuTitle
)
196 UMAEnableMenuItem(MAC_WXHMENU(m_hMenu
) , pos
, false ) ;
200 // if we're already attached to the menubar, we must update it
203 GetMenuBar()->Refresh();
208 void wxMenu::EndRadioGroup()
210 // we're not inside a radio group any longer
211 m_startRadioGroup
= -1;
214 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*item
)
216 wxCHECK_MSG( item
, NULL
, _T("NULL item in wxMenu::DoAppend") );
220 if ( item
->GetKind() == wxITEM_RADIO
)
222 int count
= GetMenuItemCount();
224 if ( m_startRadioGroup
== -1 )
226 // start a new radio group
227 m_startRadioGroup
= count
;
229 // for now it has just one element
230 item
->SetAsRadioGroupStart();
231 item
->SetRadioGroupEnd(m_startRadioGroup
);
233 // ensure that we have a checked item in the radio group
236 else // extend the current radio group
238 // we need to update its end item
239 item
->SetRadioGroupStart(m_startRadioGroup
);
240 wxMenuItemList::Node
*node
= GetMenuItems().Item(m_startRadioGroup
);
244 node
->GetData()->SetRadioGroupEnd(count
);
248 wxFAIL_MSG( _T("where is the radio group start item?") );
252 else // not a radio item
257 if ( !wxMenuBase::DoAppend(item
) || !DoInsertOrAppend(item
) )
264 // check the item initially
271 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
273 if (wxMenuBase::DoInsert(pos
, item
) && DoInsertOrAppend(item
, pos
))
279 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
281 // we need to find the items position in the child list
283 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
284 for ( pos
= 0; node
; pos
++ )
286 if ( node
->GetData() == item
)
289 node
= node
->GetNext();
292 // DoRemove() (unlike Remove) can only be called for existing item!
293 wxCHECK_MSG( node
, NULL
, wxT("bug in wxMenu::Remove logic") );
295 ::DeleteMenuItem(MAC_WXHMENU(m_hMenu
) , pos
+ 1);
299 // otherwise, the change won't be visible
300 GetMenuBar()->Refresh();
303 // and from internal data structures
304 return wxMenuBase::DoRemove(item
);
307 void wxMenu::SetTitle(const wxString
& label
)
310 UMASetMenuTitle(MAC_WXHMENU(m_hMenu
) , label
, wxFont::GetDefaultEncoding() ) ;
312 bool wxMenu::ProcessCommand(wxCommandEvent
& event
)
314 bool processed
= FALSE
;
316 // Try the menu's event handler
317 if ( !processed
&& GetEventHandler())
319 processed
= GetEventHandler()->ProcessEvent(event
);
322 // Try the window the menu was popped up from (and up through the
324 wxWindow
*win
= GetInvokingWindow();
325 if ( !processed
&& win
)
326 processed
= win
->GetEventHandler()->ProcessEvent(event
);
332 // ---------------------------------------------------------------------------
334 // ---------------------------------------------------------------------------
336 wxWindow
*wxMenu::GetWindow() const
338 if ( m_invokingWindow
!= NULL
)
339 return m_invokingWindow
;
340 else if ( GetMenuBar() != NULL
)
341 return (wxWindow
*) GetMenuBar()->GetFrame();
346 // helper functions returning the mac menu position for a certain item, note that this is
347 // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
349 int wxMenu::MacGetIndexFromId( int id
)
352 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
353 for ( pos
= 0; node
; pos
++ )
355 if ( node
->GetData()->GetId() == id
)
358 node
= node
->GetNext();
367 int wxMenu::MacGetIndexFromItem( wxMenuItem
*pItem
)
370 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
371 for ( pos
= 0; node
; pos
++ )
373 if ( node
->GetData() == pItem
)
376 node
= node
->GetNext();
385 void wxMenu::MacEnableMenu( bool bDoEnable
)
387 UMAEnableMenuItem(MAC_WXHMENU(m_hMenu
) , 0 , bDoEnable
) ;
392 // MacOS needs to know about submenus somewhere within this menu
393 // before it can be displayed , also hide special menu items like preferences
394 // that are handled by the OS
395 void wxMenu::MacBeforeDisplay( bool isSubMenu
)
397 wxMenuItem
* previousItem
= NULL
;
399 wxMenuItemList::Node
*node
;
401 for (pos
= 0, node
= GetMenuItems().GetFirst(); node
; node
= node
->GetNext(), pos
++)
403 item
= (wxMenuItem
*)node
->GetData();
404 wxMenu
* subMenu
= item
->GetSubMenu() ;
407 subMenu
->MacBeforeDisplay( true ) ;
412 if ( UMAGetSystemVersion() >= 0x1000 )
414 if ( item
->GetId() == wxApp::s_macPreferencesMenuItemId
|| item
->GetId() == wxApp::s_macExitMenuItemId
)
416 ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ) , pos
+ 1, kMenuItemAttrHidden
, 0 );
417 if ( GetMenuItems().GetCount() == pos
+ 1 &&
418 previousItem
!= NULL
&&
419 previousItem
->IsSeparator() )
421 ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ) , pos
, kMenuItemAttrHidden
, 0 );
427 previousItem
= item
;
431 ::InsertMenu(MAC_WXHMENU( GetHMenu()), -1);
434 // undo all changes from the MacBeforeDisplay call
435 void wxMenu::MacAfterDisplay( bool isSubMenu
)
438 ::DeleteMenu(MacGetMenuId());
440 wxMenuItem
* previousItem
= NULL
;
442 wxMenuItemList::Node
*node
;
444 for (pos
= 0, node
= GetMenuItems().GetFirst(); node
; node
= node
->GetNext(), pos
++)
446 item
= (wxMenuItem
*)node
->GetData();
447 wxMenu
* subMenu
= item
->GetSubMenu() ;
450 subMenu
->MacAfterDisplay( true ) ;
454 // no need to undo hidings
456 previousItem
= item
;
464 Mac Implementation note :
466 The Mac has only one global menubar, so we attempt to install the currently
467 active menubar from a frame, we currently don't take into account mdi-frames
468 which would ask for menu-merging
470 Secondly there is no mac api for changing a menubar that is not the current
471 menubar, so we have to wait for preparing the actual menubar until the
472 wxMenubar is to be used
474 We can in subsequent versions use MacInstallMenuBar to provide some sort of
475 auto-merge for MDI in case this will be necessary
479 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
480 wxMenuBar
* wxMenuBar::s_macCommonMenuBar
= NULL
;
482 void wxMenuBar::Init()
484 m_eventHandler
= this;
485 m_menuBarFrame
= NULL
;
486 m_invokingWindow
= (wxWindow
*) NULL
;
489 wxMenuBar::wxMenuBar()
494 wxMenuBar::wxMenuBar( long WXUNUSED(style
) )
500 wxMenuBar::wxMenuBar(int count
, wxMenu
*menus
[], const wxString titles
[])
504 m_titles
.Alloc(count
);
506 for ( int i
= 0; i
< count
; i
++ )
508 m_menus
.Append(menus
[i
]);
509 m_titles
.Add(titles
[i
]);
511 menus
[i
]->Attach(this);
515 wxMenuBar::~wxMenuBar()
517 if (s_macCommonMenuBar
== this)
518 s_macCommonMenuBar
= NULL
;
519 if (s_macInstalledMenuBar
== this)
522 s_macInstalledMenuBar
= NULL
;
527 void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground
), const wxRect
*WXUNUSED(rect
))
529 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
534 void wxMenuBar::MacInstallMenuBar()
536 if ( s_macInstalledMenuBar
== this )
539 MenuBarHandle menubar
= NULL
;
540 #if TARGET_API_MAC_OSX
541 menubar
= NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ;
543 menubar
= NewHandleClear( 12 ) ;
544 (*menubar
)[3] = 0x0a ;
546 ::SetMenuBar( menubar
) ;
547 DisposeMenuBar( menubar
) ;
548 MenuHandle appleMenu
= NULL
;
549 char appleMenuTitle
[3] = { 01 , kMenuAppleLogoFilledGlyph
, 0 } ;
551 verify_noerr( CreateNewMenu( kwxMacAppleMenuId
, 0 , &appleMenu
) ) ;
552 verify_noerr( SetMenuTitle( appleMenu
, (ConstStr255Param
) appleMenuTitle
) );
554 //under 10.3 it is a standard to include a seperator between About and Preferences
555 #if ( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 )
556 MacInsertMenuItem( appleMenu
, "\p-" , 0 ) ;
559 MacInsertMenuItem( appleMenu
, "\pAbout..." , 0 ) ;
560 MacInsertMenu( appleMenu
, 0 ) ;
562 // clean-up the help menu before adding new items
563 MenuHandle mh
= NULL
;
564 if ( UMAGetHelpMenu( &mh
, &firstUserHelpMenuItem
) == noErr
)
566 for ( int i
= CountMenuItems( mh
) ; i
>= firstUserHelpMenuItem
; --i
)
568 DeleteMenuItem( mh
, i
) ;
576 if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId
)
578 wxMenuItem
*item
= FindItem( wxApp::s_macPreferencesMenuItemId
, NULL
) ;
579 if ( item
== NULL
|| !(item
->IsEnabled()) )
580 DisableMenuCommand( NULL
, kHICommandPreferences
) ;
582 EnableMenuCommand( NULL
, kHICommandPreferences
) ;
585 for (size_t i
= 0; i
< m_menus
.GetCount(); i
++)
587 wxMenuItemList::Node
*node
;
590 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
592 if( m_titles
[i
] == wxT("?") || m_titles
[i
] == wxT("&?") || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
599 for (pos
= 0 , node
= menu
->GetMenuItems().GetFirst(); node
; node
= node
->GetNext(), pos
++)
601 item
= (wxMenuItem
*)node
->GetData();
602 subMenu
= item
->GetSubMenu() ;
605 // we don't support hierarchical menus in the help menu yet
609 if ( item
->IsSeparator() )
612 MacAppendMenu(mh
, "\p-" );
616 wxAcceleratorEntry
* entry
= wxGetAccelFromString( item
->GetText() ) ;
618 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
620 UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , item
->GetText() , wxFont::GetDefaultEncoding() );
621 UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 , true );
622 SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId
) , 1 , item
->GetId() ) ;
623 SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId
) , 1 , (UInt32
)item
) ;
624 UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId
) , 1 , entry
) ;
630 UMAAppendMenuItem(mh
, item
->GetText() , wxFont::GetDefaultEncoding(), entry
);
631 SetMenuItemCommandID( mh
, CountMenuItems(mh
) , item
->GetId() ) ;
632 SetMenuItemRefCon( mh
, CountMenuItems(mh
) , (UInt32
)item
) ;
643 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , m_titles
[i
], m_font
.GetEncoding() ) ;
644 m_menus
[i
]->MacBeforeDisplay(false) ;
645 ::InsertMenu(MAC_WXHMENU(m_menus
[i
]->GetHMenu()), 0);
649 s_macInstalledMenuBar
= this;
652 void wxMenuBar::EnableTop(size_t pos
, bool enable
)
654 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
655 m_menus
[pos
]->MacEnableMenu( enable
) ;
659 bool wxMenuBar::Enable( bool enable
)
661 wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") );
663 for (i
= 0; i
< GetMenuCount(); i
++)
665 EnableTop(i
, enable
);
670 void wxMenuBar::SetLabelTop(size_t pos
, const wxString
& label
)
672 wxCHECK_RET( pos
< GetMenuCount(), wxT("invalid menu index") );
674 m_titles
[pos
] = label
;
681 m_menus
[pos
]->SetTitle( label
) ;
682 if (wxMenuBar::s_macInstalledMenuBar
== this) // are we currently installed ?
684 ::SetMenuBar( GetMenuBar() ) ;
689 wxString
wxMenuBar::GetLabelTop(size_t pos
) const
691 wxCHECK_MSG( pos
< GetMenuCount(), wxEmptyString
,
692 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
694 return m_titles
[pos
];
697 int wxMenuBar::FindMenu(const wxString
& title
)
699 wxString menuTitle
= wxStripMenuCodes(title
);
701 size_t count
= GetMenuCount();
702 for ( size_t i
= 0; i
< count
; i
++ )
704 wxString title
= wxStripMenuCodes(m_titles
[i
]);
705 if ( menuTitle
== title
)
714 // ---------------------------------------------------------------------------
715 // wxMenuBar construction
716 // ---------------------------------------------------------------------------
718 // ---------------------------------------------------------------------------
719 // wxMenuBar construction
720 // ---------------------------------------------------------------------------
722 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
724 wxMenu
*menuOld
= wxMenuBarBase::Replace(pos
, menu
, title
);
727 m_titles
[pos
] = title
;
731 if (s_macInstalledMenuBar
== this)
733 menuOld
->MacAfterDisplay( false ) ;
734 ::DeleteMenu( menuOld
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
736 menu
->MacBeforeDisplay( false ) ;
737 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , title
, m_font
.GetEncoding() ) ;
738 if ( pos
== m_menus
.GetCount() - 1)
740 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
744 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
755 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
757 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
760 m_titles
.Insert(title
, pos
);
762 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , title
, m_font
.GetEncoding() ) ;
764 if ( IsAttached() && s_macInstalledMenuBar
== this )
766 if (s_macInstalledMenuBar
== this)
768 menu
->MacBeforeDisplay( false ) ;
769 if ( pos
== (size_t) -1 || pos
+ 1 == m_menus
.GetCount() )
771 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
775 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
784 wxMenu
*wxMenuBar::Remove(size_t pos
)
786 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
792 if (s_macInstalledMenuBar
== this)
794 ::DeleteMenu( menu
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
800 m_titles
.RemoveAt(pos
);
805 bool wxMenuBar::Append(wxMenu
*menu
, const wxString
& title
)
807 WXHMENU submenu
= menu
? menu
->GetHMenu() : 0;
808 wxCHECK_MSG( submenu
, FALSE
, wxT("can't append invalid menu to menubar") );
810 if ( !wxMenuBarBase::Append(menu
, title
) )
815 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , title
, m_font
.GetEncoding() ) ;
819 if (s_macInstalledMenuBar
== this)
821 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
827 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
828 // adding menu later on.
829 if (m_invokingWindow
)
830 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
835 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
)
837 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
839 wxMenuItemList::Node
*node
= menu
->GetMenuItems().GetFirst();
842 wxMenuItem
*menuitem
= node
->GetData();
843 if (menuitem
->IsSubMenu())
844 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu() );
845 node
= node
->GetNext();
849 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
851 menu
->SetInvokingWindow( win
);
853 wxMenuItemList::Node
*node
= menu
->GetMenuItems().GetFirst();
856 wxMenuItem
*menuitem
= node
->GetData();
857 if (menuitem
->IsSubMenu())
858 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu() , win
);
859 node
= node
->GetNext();
863 void wxMenuBar::UnsetInvokingWindow()
865 m_invokingWindow
= (wxWindow
*) NULL
;
866 wxMenuList::Node
*node
= m_menus
.GetFirst();
869 wxMenu
*menu
= node
->GetData();
870 wxMenubarUnsetInvokingWindow( menu
);
871 node
= node
->GetNext();
875 void wxMenuBar::SetInvokingWindow(wxFrame
*frame
)
877 m_invokingWindow
= frame
;
878 wxMenuList::Node
*node
= m_menus
.GetFirst();
881 wxMenu
*menu
= node
->GetData();
882 wxMenubarSetInvokingWindow( menu
, frame
);
883 node
= node
->GetNext();
887 void wxMenuBar::Detach()
889 wxMenuBarBase::Detach() ;
892 void wxMenuBar::Attach(wxFrame
*frame
)
894 wxMenuBarBase::Attach( frame
) ;
896 // ---------------------------------------------------------------------------
897 // wxMenuBar searching for menu items
898 // ---------------------------------------------------------------------------
900 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
901 int wxMenuBar::FindMenuItem(const wxString
& menuString
,
902 const wxString
& itemString
) const
904 wxString menuLabel
= wxStripMenuCodes(menuString
);
905 size_t count
= GetMenuCount();
906 for ( size_t i
= 0; i
< count
; i
++ )
908 wxString title
= wxStripMenuCodes(m_titles
[i
]);
909 if ( menuLabel
== title
)
910 return m_menus
[i
]->FindItem(itemString
);
916 wxMenuItem
*wxMenuBar::FindItem(int id
, wxMenu
**itemMenu
) const
921 wxMenuItem
*item
= NULL
;
922 size_t count
= GetMenuCount();
923 for ( size_t i
= 0; !item
&& (i
< count
); i
++ )
925 item
= m_menus
[i
]->FindItem(id
, itemMenu
);