1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  11 #pragma implementation "menu.h" 
  12 #pragma implementation "menuitem.h" 
  23 //----------------------------------------------------------------------------- 
  25 //----------------------------------------------------------------------------- 
  27 extern void wxapp_install_idle_handler(); 
  30 //----------------------------------------------------------------------------- 
  32 //----------------------------------------------------------------------------- 
  34 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
) 
  36 wxMenuBar::wxMenuBar( long style 
) 
  38     /* the parent window is known after wxFrame::SetMenu() */ 
  41     PreCreation( (wxWindow 
*) NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, "menu" ); 
  43     m_menus
.DeleteContents( TRUE 
); 
  45     /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ 
  46 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) 
  47     m_accel 
= gtk_accel_group_new(); 
  48     m_factory 
= gtk_item_factory_new( GTK_TYPE_MENU_BAR
, "<main>", m_accel 
); 
  49     m_menubar 
= gtk_item_factory_get_widget( m_factory
, "<main>" ); 
  51     m_menubar 
= gtk_menu_bar_new(); 
  54     if (style 
& wxMB_DOCKABLE
) 
  56         m_widget 
= gtk_handle_box_new(); 
  57         gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_menubar
) ); 
  58         gtk_widget_show( GTK_WIDGET(m_menubar
) ); 
  62         m_widget 
= GTK_WIDGET(m_menubar
); 
  70 wxMenuBar::wxMenuBar() 
  72     /* the parent window is known after wxFrame::SetMenu() */ 
  75     PreCreation( (wxWindow 
*) NULL
, -1, wxDefaultPosition
, wxDefaultSize
, 0, "menu" ); 
  77     m_menus
.DeleteContents( TRUE 
); 
  79     /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ 
  80 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) 
  81     m_accel 
= gtk_accel_group_new(); 
  82     m_factory 
= gtk_item_factory_new( GTK_TYPE_MENU_BAR
, "<main>", m_accel 
); 
  83     m_menubar 
= gtk_item_factory_get_widget( m_factory
, "<main>" ); 
  85     m_menubar 
= gtk_menu_bar_new(); 
  88     m_widget 
= GTK_WIDGET(m_menubar
); 
  95 wxMenuBar::~wxMenuBar() 
  97    // how to destroy a GtkItemFactory ? 
 100 void wxMenuBar::Append( wxMenu 
*menu
, const wxString 
&title 
) 
 102     m_menus
.Append( menu 
); 
 104     /* GTK 1.2 wants to have "_" instead of "&" for accelerators */ 
 106     for ( const wxChar 
*pc 
= title
; *pc 
!= _T('\0'); pc
++ ) 
 110 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) 
 122     /* this doesn't have much effect right now */ 
 123     menu
->SetTitle( str 
); 
 125     /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ 
 126 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) 
 128     /* local buffer in multibyte form */ 
 131     strcat( buf
, str
.mb_str() ); 
 133     GtkItemFactoryEntry entry
; 
 135     entry
.accelerator 
= (gchar
*) NULL
; 
 136     entry
.callback 
= (GtkItemFactoryCallback
) NULL
; 
 137     entry
.callback_action 
= 0; 
 138     entry
.item_type 
= "<Branch>"; 
 140     gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 );  /* what is 2 ? */ 
 142     /* in order to get the pointer to the item we need the item text _without_ underscores */ 
 143     wxString tmp 
= _T("<main>/"); 
 144     for ( const wxChar 
*pc 
= str
; *pc 
!= _T('\0'); pc
++ ) 
 146         if (*pc 
== _T('_')) pc
++; /* skip it */ 
 150     menu
->m_owner 
= gtk_item_factory_get_item( m_factory
, tmp
.mb_str() ); 
 152     gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu 
); 
 156     menu
->m_owner 
= gtk_menu_item_new_with_label( str
.mb_str() ); 
 157     gtk_widget_show( menu
->m_owner 
); 
 158     gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu 
); 
 160     gtk_menu_bar_append( GTK_MENU_BAR(m_menubar
), menu
->m_owner 
); 
 165 static int FindMenuItemRecursive( const wxMenu 
*menu
, const wxString 
&menuString
, const wxString 
&itemString 
) 
 167     if (menu
->GetTitle() == menuString
) 
 169         int res 
= menu
->FindItem( itemString 
); 
 170         if (res 
!= wxNOT_FOUND
) 
 174     wxNode 
*node 
= ((wxMenu 
*)menu
)->GetItems().First();    // const_cast 
 177         wxMenuItem 
*item 
= (wxMenuItem
*)node
->Data(); 
 178         if (item
->IsSubMenu()) 
 179             return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
); 
 187 wxMenuItem 
*wxMenuBar::FindItemForId(int itemId
, wxMenu 
**menuForItem 
) const 
 191         // TODO return the pointer to the menu 
 196     return FindItem(itemId
); 
 199 int wxMenuBar::FindMenuItem( const wxString 
&menuString
, const wxString 
&itemString 
) const 
 201     wxNode 
*node 
= m_menus
.First(); 
 204         wxMenu 
*menu 
= (wxMenu
*)node
->Data(); 
 205         int res 
= FindMenuItemRecursive( menu
, menuString
, itemString
); 
 206         if (res 
!= -1) return res
; 
 212 // Find a wxMenuItem using its id. Recurses down into sub-menus 
 213 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
) 
 215     wxMenuItem
* result 
= menu
->FindItem(id
); 
 217     wxNode 
*node 
= ((wxMenu 
*)menu
)->GetItems().First(); // const_cast 
 218     while ( node 
&& result 
== NULL 
) 
 220         wxMenuItem 
*item 
= (wxMenuItem
*)node
->Data(); 
 221         if (item
->IsSubMenu()) 
 223             result 
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id 
); 
 231 wxMenuItem
* wxMenuBar::FindItem( int id 
) const 
 233     wxMenuItem
* result 
= 0; 
 234     wxNode 
*node 
= m_menus
.First(); 
 235     while (node 
&& result 
== 0) 
 237         wxMenu 
*menu 
= (wxMenu
*)node
->Data(); 
 238         result 
= FindMenuItemByIdRecursive( menu
, id 
); 
 245 void wxMenuBar::Check( int id
, bool check 
) 
 247     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 249     wxCHECK_RET( item
, _T("wxMenuBar::Check: no such item") ); 
 254 bool wxMenuBar::IsChecked( int id 
) const 
 256     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 258     wxCHECK_MSG( item
, FALSE
, _T("wxMenuBar::IsChecked: no such item") ); 
 260     return item
->IsChecked(); 
 263 void wxMenuBar::Enable( int id
, bool enable 
) 
 265     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 267     wxCHECK_RET( item
, _T("wxMenuBar::Enable: no such item") ); 
 269     item
->Enable(enable
); 
 272 bool wxMenuBar::IsEnabled( int id 
) const 
 274     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 276     wxCHECK_MSG( item
, FALSE
, _T("wxMenuBar::IsEnabled: no such item") ); 
 278     return item
->IsEnabled(); 
 281 wxString 
wxMenuBar::GetLabel( int id 
) const 
 283     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 285     wxCHECK_MSG( item
, _T(""), _T("wxMenuBar::GetLabel: no such item") ); 
 287     return item
->GetText(); 
 290 void wxMenuBar::SetLabel( int id
, const wxString 
&label 
) 
 292     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 294     wxCHECK_RET( item
, _T("wxMenuBar::SetLabel: no such item") ); 
 296     item
->SetText( label 
); 
 299 void wxMenuBar::EnableTop( int pos
, bool flag 
) 
 301     wxNode 
*node 
= m_menus
.Nth( pos 
); 
 303     wxCHECK_RET( node
, _T("menu not found") ); 
 305     wxMenu
* menu 
= (wxMenu
*)node
->Data(); 
 308         gtk_widget_set_sensitive( menu
->m_owner
, flag 
); 
 311 wxString 
wxMenuBar::GetLabelTop( int pos 
) const 
 313     wxNode 
*node 
= m_menus
.Nth( pos 
); 
 315     wxCHECK_MSG( node
, _T("invalid"), _T("menu not found") ); 
 317     wxMenu
* menu 
= (wxMenu
*)node
->Data(); 
 319     return menu
->GetTitle(); 
 322 void wxMenuBar::SetLabelTop( int pos
, const wxString
& label 
) 
 324     wxNode 
*node 
= m_menus
.Nth( pos 
); 
 326     wxCHECK_RET( node
, _T("menu not found") ); 
 328     wxMenu
* menu 
= (wxMenu
*)node
->Data(); 
 330     menu
->SetTitle( label 
); 
 333 void wxMenuBar::SetHelpString( int id
, const wxString
& helpString 
) 
 335     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 337     wxCHECK_RET( item
, _T("wxMenuBar::SetHelpString: no such item") ); 
 339     item
->SetHelp( helpString 
); 
 342 wxString 
wxMenuBar::GetHelpString( int id 
) const 
 344     wxMenuItem
* item 
= FindMenuItemById( id 
); 
 346     wxCHECK_MSG( item
, _T(""), _T("wxMenuBar::GetHelpString: no such item") ); 
 348     return item
->GetHelp(); 
 351 //----------------------------------------------------------------------------- 
 353 //----------------------------------------------------------------------------- 
 355 static void gtk_menu_clicked_callback( GtkWidget 
*widget
, wxMenu 
*menu 
) 
 357     if (g_isIdle
) wxapp_install_idle_handler(); 
 359     int id 
= menu
->FindMenuIdByMenuItem(widget
); 
 361     /* should find it for normal (not popup) menu */ 
 362     wxASSERT( (id 
!= -1) || (menu
->GetInvokingWindow() != NULL
) ); 
 364     if (!menu
->IsEnabled(id
)) 
 367     wxMenuItem
* item 
= menu
->FindItem( id 
); 
 368     wxCHECK_RET( item
, _T("error in menu item callback") ); 
 370     if (item
->IsCheckable()) 
 372         if (item
->GetCheckedFlag() == item
->IsChecked()) 
 374             /* the menu item has been checked by calling wxMenuItem->Check() */ 
 379             /* the user pressed on the menu item -> report */ 
 380             item
->SetCheckedFlag(item
->IsChecked());  /* make consistent again */ 
 384     wxCommandEvent 
event( wxEVT_COMMAND_MENU_SELECTED
, id 
); 
 385     event
.SetEventObject( menu 
); 
 388     if (menu
->GetCallback()) 
 390         (void) (*(menu
->GetCallback())) (*menu
, event
); 
 394     if (menu
->GetEventHandler()->ProcessEvent(event
)) 
 397     wxWindow 
*win 
= menu
->GetInvokingWindow(); 
 399         win
->GetEventHandler()->ProcessEvent( event 
); 
 402 //----------------------------------------------------------------------------- 
 404 //----------------------------------------------------------------------------- 
 406 static void gtk_menu_hilight_callback( GtkWidget 
*widget
, wxMenu 
*menu 
) 
 408     if (g_isIdle
) wxapp_install_idle_handler(); 
 410     int id 
= menu
->FindMenuIdByMenuItem(widget
); 
 412     wxASSERT( id 
!= -1 ); // should find it! 
 414     if (!menu
->IsEnabled(id
)) 
 417     wxMenuEvent 
event( wxEVT_MENU_HIGHLIGHT
, id 
); 
 418     event
.SetEventObject( menu 
); 
 420 /*   wxMSW doesn't call callback here either 
 422      if (menu->m_callback) 
 424         (void) (*(menu->m_callback)) (*menu, event); 
 429     if (menu
->GetEventHandler()->ProcessEvent(event
)) 
 432     wxWindow 
*win 
= menu
->GetInvokingWindow(); 
 433     if (win
) win
->GetEventHandler()->ProcessEvent( event 
); 
 436 //----------------------------------------------------------------------------- 
 438 //----------------------------------------------------------------------------- 
 440 static void gtk_menu_nolight_callback( GtkWidget 
*widget
, wxMenu 
*menu 
) 
 442     if (g_isIdle
) wxapp_install_idle_handler(); 
 444     int id 
= menu
->FindMenuIdByMenuItem(widget
); 
 446     wxASSERT( id 
!= -1 ); // should find it! 
 448     if (!menu
->IsEnabled(id
)) 
 451     wxMenuEvent 
event( wxEVT_MENU_HIGHLIGHT
, -1 ); 
 452     event
.SetEventObject( menu 
); 
 454     if (menu
->GetEventHandler()->ProcessEvent(event
)) 
 457     wxWindow 
*win 
= menu
->GetInvokingWindow(); 
 459         win
->GetEventHandler()->ProcessEvent( event 
); 
 462 //----------------------------------------------------------------------------- 
 464 //----------------------------------------------------------------------------- 
 466 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
,wxObject
) 
 468 wxMenuItem::wxMenuItem() 
 471     m_isCheckMenu 
= FALSE
; 
 474     m_subMenu 
= (wxMenu 
*) NULL
; 
 475     m_menuItem 
= (GtkWidget 
*) NULL
; 
 478 // it's valid for this function to be called even if m_menuItem == NULL 
 479 void wxMenuItem::SetName( const wxString
& str 
) 
 481     /* '\t' is the deliminator indicating a hot key */ 
 483     const wxChar 
*pc 
= str
; 
 484     for (; (*pc 
!= _T('\0')) && (*pc 
!= _T('\t')); pc
++ ) 
 488 #if (GTK_MINOR_VERSION > 0) 
 500     /* only GTK 1.2 know about hot keys */ 
 502 #if (GTK_MINOR_VERSION > 0) 
 509         GtkLabel 
*label 
= GTK_LABEL( GTK_BIN(m_menuItem
)->child 
); 
 510         gtk_label_set( label
, m_text
.mb_str()); 
 514 void wxMenuItem::Check( bool check 
) 
 516     wxCHECK_RET( m_menuItem
, _T("invalid menu item") ); 
 518     wxCHECK_RET( IsCheckable(), _T("Can't check uncheckable item!") ) 
 520     if (check 
== m_isChecked
) return; 
 523     gtk_check_menu_item_set_state( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check 
); 
 526 void wxMenuItem::Enable( bool enable 
) 
 528     wxCHECK_RET( m_menuItem
, _T("invalid menu item") ); 
 530     gtk_widget_set_sensitive( m_menuItem
, enable 
); 
 531     m_isEnabled 
= enable
; 
 534 bool wxMenuItem::IsChecked() const 
 536     wxCHECK_MSG( m_menuItem
, FALSE
, _T("invalid menu item") ); 
 538     wxCHECK( IsCheckable(), FALSE 
); // can't get state of uncheckable item! 
 540     bool bIsChecked 
= ((GtkCheckMenuItem
*)m_menuItem
)->active 
!= 0; 
 545 //----------------------------------------------------------------------------- 
 547 //----------------------------------------------------------------------------- 
 549 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
) 
 551 wxMenu::wxMenu( const wxString
& title
, const wxFunction func 
) 
 554     m_items
.DeleteContents( TRUE 
); 
 555     m_invokingWindow 
= (wxWindow 
*) NULL
; 
 557 #if (GTK_MINOR_VERSION > 0) 
 558     m_accel 
= gtk_accel_group_new(); 
 559     m_factory 
= gtk_item_factory_new( GTK_TYPE_MENU
, "<main>", m_accel 
); 
 560     m_menu 
= gtk_item_factory_get_widget( m_factory
, "<main>" ); 
 562     m_menu 
= gtk_menu_new();  // Do not show! 
 566     m_eventHandler 
= this; 
 567     m_clientData 
= (void*) NULL
; 
 569     if (m_title
.IsNull()) m_title 
= _T(""); 
 570     if (m_title 
!= _T("")) 
 576     m_owner 
= (GtkWidget
*) NULL
; 
 581     /* how do we delete an item-factory ? */ 
 584 void wxMenu::SetTitle( const wxString
& title 
) 
 586     // TODO Waiting for something better 
 590 const wxString 
wxMenu::GetTitle() const 
 595 void wxMenu::AppendSeparator() 
 597     wxMenuItem 
*mitem 
= new wxMenuItem(); 
 598     mitem
->SetId(ID_SEPARATOR
); 
 600     GtkWidget 
*menuItem 
= gtk_menu_item_new(); 
 601     gtk_menu_append( GTK_MENU(m_menu
), menuItem 
); 
 602     gtk_widget_show( menuItem 
); 
 604     mitem
->SetMenuItem(menuItem
); 
 605     m_items
.Append( mitem 
); 
 608 void wxMenu::Append( int id
, const wxString 
&item
, const wxString 
&helpStr
, bool checkable 
) 
 610     wxMenuItem 
*mitem 
= new wxMenuItem(); 
 612     mitem
->SetText(item
); 
 613     mitem
->SetHelp(helpStr
); 
 614     mitem
->SetCheckable(checkable
); 
 616 #if (GTK_MINOR_VERSION > 0) 
 617     /* text has "_" instead of "&" after mitem->SetText() */  
 618     wxString 
text( mitem
->GetText() ); 
 620     /* local buffer in multibyte form */ 
 623     strcat( buf
, text
.mb_str() ); 
 625     GtkItemFactoryEntry entry
; 
 627     entry
.callback 
= (GtkItemFactoryCallback
) gtk_menu_clicked_callback
; 
 628     entry
.callback_action 
= 0; 
 630         entry
.item_type 
= "<CheckItem>"; 
 632         entry
.item_type 
= "<Item>"; 
 634     entry
.accelerator 
= (gchar
*) NULL
; 
 636     wxString 
hotkey( mitem
->GetHotKey() ); 
 637     if (!hotkey
.IsEmpty()) 
 641             case _T('a'):   /* Alt */ 
 643             case _T('m'):   /* Meta */ 
 646                strcpy( hotbuf
, "<alt>" ); 
 647                wxString last 
= hotkey
.Right(1); 
 648                strcat( hotbuf
, last
.mb_str() ); 
 649                entry
.accelerator 
= hotbuf
; 
 652             case _T('c'):    /* Ctrl */ 
 654             case _T('s'):    /* Strg, yeah man, I'm German */ 
 657                strcpy( hotbuf
, "<control>" ); 
 658                wxString last 
= hotkey
.Right(1); 
 659                strcat( hotbuf
, last
.mb_str() ); 
 660                entry
.accelerator 
= hotbuf
; 
 669     gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 );  /* what is 2 ? */ 
 671     /* in order to get the pointer to the item we need the item text _without_ underscores */ 
 672     wxString s 
= _T("<main>/"); 
 673     for ( const wxChar 
*pc 
= text
; *pc 
!= _T('\0'); pc
++ ) 
 675         if (*pc 
== _T('_')) pc
++; /* skip it */ 
 679     GtkWidget 
*menuItem 
= gtk_item_factory_get_widget( m_factory
, s
.mb_str() ); 
 683     GtkWidget 
*menuItem 
= checkable 
? gtk_check_menu_item_new_with_label( mitem
->GetText().mb_str() ) 
 684                                     : gtk_menu_item_new_with_label( mitem
->GetText().mb_str() ); 
 686     gtk_signal_connect( GTK_OBJECT(menuItem
), "activate", 
 687                         GTK_SIGNAL_FUNC(gtk_menu_clicked_callback
), 
 690     gtk_menu_append( GTK_MENU(m_menu
), menuItem 
); 
 691     gtk_widget_show( menuItem 
); 
 695     gtk_signal_connect( GTK_OBJECT(menuItem
), "select", 
 696                         GTK_SIGNAL_FUNC(gtk_menu_hilight_callback
), 
 699     gtk_signal_connect( GTK_OBJECT(menuItem
), "deselect", 
 700                         GTK_SIGNAL_FUNC(gtk_menu_nolight_callback
), 
 703     mitem
->SetMenuItem(menuItem
); 
 705     m_items
.Append( mitem 
); 
 708 void wxMenu::Append( int id
, const wxString 
&text
, wxMenu 
*subMenu
, const wxString 
&helpStr 
) 
 710     wxMenuItem 
*mitem 
= new wxMenuItem(); 
 712     mitem
->SetText(text
); 
 713     mitem
->SetHelp(helpStr
); 
 715     GtkWidget 
*menuItem 
= gtk_menu_item_new_with_label(mitem
->GetText().mbc_str()); 
 716     mitem
->SetMenuItem(menuItem
); 
 717     mitem
->SetSubMenu(subMenu
); 
 719     gtk_signal_connect( GTK_OBJECT(menuItem
), "select", 
 720                         GTK_SIGNAL_FUNC(gtk_menu_hilight_callback
), 
 723     gtk_signal_connect( GTK_OBJECT(menuItem
), "deselect", 
 724                         GTK_SIGNAL_FUNC(gtk_menu_nolight_callback
), 
 727     gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), subMenu
->m_menu 
); 
 728     gtk_menu_append( GTK_MENU(m_menu
), menuItem 
); 
 729     gtk_widget_show( menuItem 
); 
 730     m_items
.Append( mitem 
); 
 733 void wxMenu::Append( wxMenuItem 
*item 
) 
 735     m_items
.Append( item 
); 
 737     GtkWidget 
*menuItem 
= (GtkWidget
*) NULL
; 
 739     if (item
->IsSeparator()) 
 740         menuItem 
= gtk_menu_item_new(); 
 741     else if (item
->IsSubMenu()) 
 742         menuItem 
= gtk_menu_item_new_with_label(item
->GetText().mbc_str()); 
 744         menuItem 
= item
->IsCheckable() ? gtk_check_menu_item_new_with_label(item
->GetText().mbc_str()) 
 745                                        : gtk_menu_item_new_with_label(item
->GetText().mbc_str()); 
 747     if (!item
->IsSeparator()) 
 749         gtk_signal_connect( GTK_OBJECT(menuItem
), "select", 
 750                             GTK_SIGNAL_FUNC(gtk_menu_hilight_callback
), 
 753         gtk_signal_connect( GTK_OBJECT(menuItem
), "deselect", 
 754                             GTK_SIGNAL_FUNC(gtk_menu_nolight_callback
), 
 757         if (!item
->IsSubMenu()) 
 759             gtk_signal_connect( GTK_OBJECT(menuItem
), "activate", 
 760                                 GTK_SIGNAL_FUNC(gtk_menu_clicked_callback
), 
 765     gtk_menu_append( GTK_MENU(m_menu
), menuItem 
); 
 766     gtk_widget_show( menuItem 
); 
 767     item
->SetMenuItem(menuItem
); 
 770 int wxMenu::FindItem( const wxString itemString 
) const 
 773     for ( const wxChar 
*pc 
= itemString
; *pc 
!= _T('\0'); pc
++ ) 
 778 #if (GTK_MINOR_VERSION > 0) 
 785     wxNode 
*node 
= m_items
.First(); 
 788         wxMenuItem 
*item 
= (wxMenuItem
*)node
->Data(); 
 789         if (item
->GetText() == s
) 
 791             return item
->GetId(); 
 799 void wxMenu::Enable( int id
, bool enable 
) 
 801     wxMenuItem 
*item 
= FindItem(id
); 
 803     wxCHECK_RET( item
, _T("wxMenu::Enable: no such item") ); 
 805     item
->Enable(enable
); 
 808 bool wxMenu::IsEnabled( int id 
) const 
 810     wxMenuItem 
*item 
= FindItem(id
); 
 812     wxCHECK_MSG( item
, FALSE
, _T("wxMenu::IsEnabled: no such item") ); 
 814     return item
->IsEnabled(); 
 817 void wxMenu::Check( int id
, bool enable 
) 
 819     wxMenuItem 
*item 
= FindItem(id
); 
 821     wxCHECK_RET( item
, _T("wxMenu::Check: no such item") ); 
 826 bool wxMenu::IsChecked( int id 
) const 
 828     wxMenuItem 
*item 
= FindItem(id
); 
 830     wxCHECK_MSG( item
, FALSE
, _T("wxMenu::IsChecked: no such item") ); 
 832     return item
->IsChecked(); 
 835 void wxMenu::SetLabel( int id
, const wxString 
&label 
) 
 837     wxMenuItem 
*item 
= FindItem(id
); 
 839     wxCHECK_RET( item
, _T("wxMenu::SetLabel: no such item") ); 
 841     item
->SetText(label
); 
 844 wxString 
wxMenu::GetLabel( int id 
) const 
 846     wxMenuItem 
*item 
= FindItem(id
); 
 848     wxCHECK_MSG( item
, _T(""), _T("wxMenu::GetLabel: no such item") ); 
 850     return item
->GetText(); 
 853 void wxMenu::SetHelpString( int id
, const wxString
& helpString 
) 
 855     wxMenuItem 
*item 
= FindItem(id
); 
 857     wxCHECK_RET( item
, _T("wxMenu::SetHelpString: no such item") ); 
 859     item
->SetHelp( helpString 
); 
 862 wxString 
wxMenu::GetHelpString( int id 
) const 
 864     wxMenuItem 
*item 
= FindItem(id
); 
 866     wxCHECK_MSG( item
, _T(""), _T("wxMenu::GetHelpString: no such item") ); 
 868     return item
->GetHelp(); 
 871 int wxMenu::FindMenuIdByMenuItem( GtkWidget 
*menuItem 
) const 
 873     wxNode 
*node 
= m_items
.First(); 
 876         wxMenuItem 
*item 
= (wxMenuItem
*)node
->Data(); 
 877         if (item
->GetMenuItem() == menuItem
) 
 878            return item
->GetId(); 
 885 wxMenuItem 
*wxMenu::FindItem(int id
) const 
 887     wxNode 
*node 
= m_items
.First(); 
 890         wxMenuItem 
*item 
= (wxMenuItem
*)node
->Data(); 
 891         if (item
->GetId() == id
) 
 898     /* Not finding anything here can be correct 
 899      * when search the entire menu system for 
 900      * an entry -> no error message. */ 
 902     return (wxMenuItem 
*) NULL
; 
 905 void wxMenu::SetInvokingWindow( wxWindow 
*win 
) 
 907     m_invokingWindow 
= win
; 
 910 wxWindow 
*wxMenu::GetInvokingWindow() 
 912     return m_invokingWindow
; 
 915 // Update a menu and all submenus recursively. source is the object that has 
 916 // the update event handlers defined for it. If NULL, the menu or associated 
 917 // window will be used. 
 918 void wxMenu::UpdateUI(wxEvtHandler
* source
) 
 920   if (!source 
&& GetInvokingWindow()) 
 921     source 
= GetInvokingWindow()->GetEventHandler(); 
 923     source 
= GetEventHandler(); 
 927   wxNode
* node 
= GetItems().First(); 
 930     wxMenuItem
* item 
= (wxMenuItem
*) node
->Data(); 
 931     if ( !item
->IsSeparator() ) 
 933       wxWindowID id 
= item
->GetId(); 
 934       wxUpdateUIEvent 
event(id
); 
 935       event
.SetEventObject( source 
); 
 937       if (source
->ProcessEvent(event
)) 
 939         if (event
.GetSetText()) 
 940           SetLabel(id
, event
.GetText()); 
 941         if (event
.GetSetChecked()) 
 942           Check(id
, event
.GetChecked()); 
 943         if (event
.GetSetEnabled()) 
 944           Enable(id
, event
.GetEnabled()); 
 947       if (item
->GetSubMenu()) 
 948         item
->GetSubMenu()->UpdateUI(source
);