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 // what we do here is to hide the special items which are
415 // shown in the application menu anyhow -- it doesn't make
416 // sense to show them in their normal place as well
417 if ( item
->GetId() == wxApp::s_macPreferencesMenuItemId
||
418 item
->GetId() == wxApp::s_macExitMenuItemId
)
420 ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ),
421 pos
+ 1, kMenuItemAttrHidden
, 0 );
423 // also check for a separator which was used just to
424 // separate this item from the others, so don't leave
425 // separator at the menu start or end nor 2 consecutive
427 wxMenuItemList::Node
*nextNode
= node
->GetNext();
428 wxMenuItem
*next
= nextNode
? nextNode
->GetData() : NULL
;
431 if ( !previousItem
&& next
&& next
->IsSeparator() )
433 // next (i.e. second as we must be first) item is
434 // the separator to hide
435 wxASSERT_MSG( pos
== 0, _T("should be the menu start") );
438 else if ( GetMenuItems().GetCount() == pos
+ 1 &&
439 previousItem
!= NULL
&&
440 previousItem
->IsSeparator() )
442 // prev item is a trailing separator we want to hide
445 else if ( previousItem
&& previousItem
->IsSeparator() &&
446 next
&& next
->IsSeparator() )
448 // two consecutive separators, this is one too many
451 else // no separators to hide
458 // hide the separator as well
459 ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ),
466 #endif // TARGET_CARBON
468 previousItem
= item
;
472 ::InsertMenu(MAC_WXHMENU( GetHMenu()), -1);
475 // undo all changes from the MacBeforeDisplay call
476 void wxMenu::MacAfterDisplay( bool isSubMenu
)
479 ::DeleteMenu(MacGetMenuId());
481 wxMenuItem
* previousItem
= NULL
;
483 wxMenuItemList::Node
*node
;
485 for (pos
= 0, node
= GetMenuItems().GetFirst(); node
; node
= node
->GetNext(), pos
++)
487 item
= (wxMenuItem
*)node
->GetData();
488 wxMenu
* subMenu
= item
->GetSubMenu() ;
491 subMenu
->MacAfterDisplay( true ) ;
495 // no need to undo hidings
497 previousItem
= item
;
505 Mac Implementation note :
507 The Mac has only one global menubar, so we attempt to install the currently
508 active menubar from a frame, we currently don't take into account mdi-frames
509 which would ask for menu-merging
511 Secondly there is no mac api for changing a menubar that is not the current
512 menubar, so we have to wait for preparing the actual menubar until the
513 wxMenubar is to be used
515 We can in subsequent versions use MacInstallMenuBar to provide some sort of
516 auto-merge for MDI in case this will be necessary
520 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
521 wxMenuBar
* wxMenuBar::s_macCommonMenuBar
= NULL
;
523 void wxMenuBar::Init()
525 m_eventHandler
= this;
526 m_menuBarFrame
= NULL
;
527 m_invokingWindow
= (wxWindow
*) NULL
;
530 wxMenuBar::wxMenuBar()
535 wxMenuBar::wxMenuBar( long WXUNUSED(style
) )
541 wxMenuBar::wxMenuBar(int count
, wxMenu
*menus
[], const wxString titles
[])
545 m_titles
.Alloc(count
);
547 for ( int i
= 0; i
< count
; i
++ )
549 m_menus
.Append(menus
[i
]);
550 m_titles
.Add(titles
[i
]);
552 menus
[i
]->Attach(this);
556 wxMenuBar::~wxMenuBar()
558 if (s_macCommonMenuBar
== this)
559 s_macCommonMenuBar
= NULL
;
560 if (s_macInstalledMenuBar
== this)
563 s_macInstalledMenuBar
= NULL
;
568 void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground
), const wxRect
*WXUNUSED(rect
))
570 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
575 void wxMenuBar::MacInstallMenuBar()
577 if ( s_macInstalledMenuBar
== this )
580 MenuBarHandle menubar
= NULL
;
581 #if TARGET_API_MAC_OSX
582 menubar
= NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ;
584 menubar
= NewHandleClear( 12 ) ;
585 (*menubar
)[3] = 0x0a ;
587 ::SetMenuBar( menubar
) ;
588 DisposeMenuBar( menubar
) ;
589 MenuHandle appleMenu
= NULL
;
590 char appleMenuTitle
[3] = { 01 , kMenuAppleLogoFilledGlyph
, 0 } ;
592 verify_noerr( CreateNewMenu( kwxMacAppleMenuId
, 0 , &appleMenu
) ) ;
593 verify_noerr( SetMenuTitle( appleMenu
, (ConstStr255Param
) appleMenuTitle
) );
595 // Add About/Preferences separator only on OS X
596 // KH/RN: Separator is always present on 10.3 but not on 10.2
597 // However, the change from 10.2 to 10.3 suggests it is preferred
598 #if TARGET_API_MAC_OSX
599 MacInsertMenuItem( appleMenu
, "\p-" , 0 ) ;
602 MacInsertMenuItem( appleMenu
, "\pAbout..." , 0 ) ;
603 MacInsertMenu( appleMenu
, 0 ) ;
605 // clean-up the help menu before adding new items
606 MenuHandle mh
= NULL
;
607 if ( UMAGetHelpMenu( &mh
, &firstUserHelpMenuItem
) == noErr
)
609 for ( int i
= CountMenuItems( mh
) ; i
>= firstUserHelpMenuItem
; --i
)
611 DeleteMenuItem( mh
, i
) ;
619 if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId
)
621 wxMenuItem
*item
= FindItem( wxApp::s_macPreferencesMenuItemId
, NULL
) ;
622 if ( item
== NULL
|| !(item
->IsEnabled()) )
623 DisableMenuCommand( NULL
, kHICommandPreferences
) ;
625 EnableMenuCommand( NULL
, kHICommandPreferences
) ;
628 for (size_t i
= 0; i
< m_menus
.GetCount(); i
++)
630 wxMenuItemList::Node
*node
;
633 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
635 if( m_titles
[i
] == wxT("?") || m_titles
[i
] == wxT("&?") || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
642 for (pos
= 0 , node
= menu
->GetMenuItems().GetFirst(); node
; node
= node
->GetNext(), pos
++)
644 item
= (wxMenuItem
*)node
->GetData();
645 subMenu
= item
->GetSubMenu() ;
648 // we don't support hierarchical menus in the help menu yet
652 if ( item
->IsSeparator() )
655 MacAppendMenu(mh
, "\p-" );
659 wxAcceleratorEntry
* entry
= wxGetAccelFromString( item
->GetText() ) ;
661 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
663 UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , item
->GetText() , wxFont::GetDefaultEncoding() );
664 UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 , true );
665 SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId
) , 1 , item
->GetId() ) ;
666 SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId
) , 1 , (UInt32
)item
) ;
667 UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId
) , 1 , entry
) ;
673 UMAAppendMenuItem(mh
, item
->GetText() , wxFont::GetDefaultEncoding(), entry
);
674 SetMenuItemCommandID( mh
, CountMenuItems(mh
) , item
->GetId() ) ;
675 SetMenuItemRefCon( mh
, CountMenuItems(mh
) , (UInt32
)item
) ;
686 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , m_titles
[i
], m_font
.GetEncoding() ) ;
687 m_menus
[i
]->MacBeforeDisplay(false) ;
688 ::InsertMenu(MAC_WXHMENU(m_menus
[i
]->GetHMenu()), 0);
692 s_macInstalledMenuBar
= this;
695 void wxMenuBar::EnableTop(size_t pos
, bool enable
)
697 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
698 m_menus
[pos
]->MacEnableMenu( enable
) ;
702 bool wxMenuBar::Enable( bool enable
)
704 wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") );
706 for (i
= 0; i
< GetMenuCount(); i
++)
708 EnableTop(i
, enable
);
713 void wxMenuBar::SetLabelTop(size_t pos
, const wxString
& label
)
715 wxCHECK_RET( pos
< GetMenuCount(), wxT("invalid menu index") );
717 m_titles
[pos
] = label
;
724 m_menus
[pos
]->SetTitle( label
) ;
725 if (wxMenuBar::s_macInstalledMenuBar
== this) // are we currently installed ?
727 ::SetMenuBar( GetMenuBar() ) ;
732 wxString
wxMenuBar::GetLabelTop(size_t pos
) const
734 wxCHECK_MSG( pos
< GetMenuCount(), wxEmptyString
,
735 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
737 return m_titles
[pos
];
740 int wxMenuBar::FindMenu(const wxString
& title
)
742 wxString menuTitle
= wxStripMenuCodes(title
);
744 size_t count
= GetMenuCount();
745 for ( size_t i
= 0; i
< count
; i
++ )
747 wxString title
= wxStripMenuCodes(m_titles
[i
]);
748 if ( menuTitle
== title
)
757 // ---------------------------------------------------------------------------
758 // wxMenuBar construction
759 // ---------------------------------------------------------------------------
761 // ---------------------------------------------------------------------------
762 // wxMenuBar construction
763 // ---------------------------------------------------------------------------
765 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
767 wxMenu
*menuOld
= wxMenuBarBase::Replace(pos
, menu
, title
);
770 m_titles
[pos
] = title
;
774 if (s_macInstalledMenuBar
== this)
776 menuOld
->MacAfterDisplay( false ) ;
777 ::DeleteMenu( menuOld
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
779 menu
->MacBeforeDisplay( false ) ;
780 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , title
, m_font
.GetEncoding() ) ;
781 if ( pos
== m_menus
.GetCount() - 1)
783 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
787 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
798 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
800 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
803 m_titles
.Insert(title
, pos
);
805 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , title
, m_font
.GetEncoding() ) ;
807 if ( IsAttached() && s_macInstalledMenuBar
== this )
809 if (s_macInstalledMenuBar
== this)
811 menu
->MacBeforeDisplay( false ) ;
812 if ( pos
== (size_t) -1 || pos
+ 1 == m_menus
.GetCount() )
814 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
818 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
827 wxMenu
*wxMenuBar::Remove(size_t pos
)
829 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
835 if (s_macInstalledMenuBar
== this)
837 ::DeleteMenu( menu
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
843 m_titles
.RemoveAt(pos
);
848 bool wxMenuBar::Append(wxMenu
*menu
, const wxString
& title
)
850 WXHMENU submenu
= menu
? menu
->GetHMenu() : 0;
851 wxCHECK_MSG( submenu
, FALSE
, wxT("can't append invalid menu to menubar") );
853 if ( !wxMenuBarBase::Append(menu
, title
) )
858 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , title
, m_font
.GetEncoding() ) ;
862 if (s_macInstalledMenuBar
== this)
864 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
870 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
871 // adding menu later on.
872 if (m_invokingWindow
)
873 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
878 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
)
880 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
882 wxMenuItemList::Node
*node
= menu
->GetMenuItems().GetFirst();
885 wxMenuItem
*menuitem
= node
->GetData();
886 if (menuitem
->IsSubMenu())
887 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu() );
888 node
= node
->GetNext();
892 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
894 menu
->SetInvokingWindow( win
);
896 wxMenuItemList::Node
*node
= menu
->GetMenuItems().GetFirst();
899 wxMenuItem
*menuitem
= node
->GetData();
900 if (menuitem
->IsSubMenu())
901 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu() , win
);
902 node
= node
->GetNext();
906 void wxMenuBar::UnsetInvokingWindow()
908 m_invokingWindow
= (wxWindow
*) NULL
;
909 wxMenuList::Node
*node
= m_menus
.GetFirst();
912 wxMenu
*menu
= node
->GetData();
913 wxMenubarUnsetInvokingWindow( menu
);
914 node
= node
->GetNext();
918 void wxMenuBar::SetInvokingWindow(wxFrame
*frame
)
920 m_invokingWindow
= frame
;
921 wxMenuList::Node
*node
= m_menus
.GetFirst();
924 wxMenu
*menu
= node
->GetData();
925 wxMenubarSetInvokingWindow( menu
, frame
);
926 node
= node
->GetNext();
930 void wxMenuBar::Detach()
932 wxMenuBarBase::Detach() ;
935 void wxMenuBar::Attach(wxFrame
*frame
)
937 wxMenuBarBase::Attach( frame
) ;
939 // ---------------------------------------------------------------------------
940 // wxMenuBar searching for menu items
941 // ---------------------------------------------------------------------------
943 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
944 int wxMenuBar::FindMenuItem(const wxString
& menuString
,
945 const wxString
& itemString
) const
947 wxString menuLabel
= wxStripMenuCodes(menuString
);
948 size_t count
= GetMenuCount();
949 for ( size_t i
= 0; i
< count
; i
++ )
951 wxString title
= wxStripMenuCodes(m_titles
[i
]);
952 if ( menuLabel
== title
)
953 return m_menus
[i
]->FindItem(itemString
);
959 wxMenuItem
*wxMenuBar::FindItem(int id
, wxMenu
**itemMenu
) const
964 wxMenuItem
*item
= NULL
;
965 size_t count
= GetMenuCount();
966 for ( size_t i
= 0; !item
&& (i
< count
); i
++ )
968 item
= m_menus
[i
]->FindItem(id
, itemMenu
);