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"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 #if (GTK_MINOR_VERSION > 0) && wxUSE_ACCEL
35 static wxString
GetHotKey( const wxMenuItem
& item
);
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
44 wxMenuBar::wxMenuBar( long style
)
46 /* the parent window is known after wxFrame::SetMenu() */
49 m_invokingWindow
= (wxWindow
*) NULL
;
51 if (!PreCreation( (wxWindow
*) NULL
, wxDefaultPosition
, wxDefaultSize
) ||
52 !CreateBase( (wxWindow
*) NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
54 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
58 m_menus
.DeleteContents( TRUE
);
60 /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
61 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
62 m_accel
= gtk_accel_group_new();
63 m_factory
= gtk_item_factory_new( GTK_TYPE_MENU_BAR
, "<main>", m_accel
);
64 m_menubar
= gtk_item_factory_get_widget( m_factory
, "<main>" );
66 m_menubar
= gtk_menu_bar_new();
69 if (style
& wxMB_DOCKABLE
)
71 m_widget
= gtk_handle_box_new();
72 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_menubar
) );
73 gtk_widget_show( GTK_WIDGET(m_menubar
) );
77 m_widget
= GTK_WIDGET(m_menubar
);
83 wxMenuBar::wxMenuBar()
85 /* the parent window is known after wxFrame::SetMenu() */
88 m_invokingWindow
= (wxWindow
*) NULL
;
90 if (!PreCreation( (wxWindow
*) NULL
, wxDefaultPosition
, wxDefaultSize
) ||
91 !CreateBase( (wxWindow
*) NULL
, -1, wxDefaultPosition
, wxDefaultSize
, 0, wxDefaultValidator
, wxT("menubar") ))
93 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
97 m_menus
.DeleteContents( TRUE
);
99 /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
100 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
101 m_accel
= gtk_accel_group_new();
102 m_factory
= gtk_item_factory_new( GTK_TYPE_MENU_BAR
, "<main>", m_accel
);
103 m_menubar
= gtk_item_factory_get_widget( m_factory
, "<main>" );
105 m_menubar
= gtk_menu_bar_new();
108 m_widget
= GTK_WIDGET(m_menubar
);
113 wxMenuBar::~wxMenuBar()
115 // gtk_object_unref( GTK_OBJECT(m_factory) ); why not ?
118 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
120 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
122 #if (GTK_MINOR_VERSION > 0)
123 wxWindow
*top_frame
= win
;
124 while (top_frame
->GetParent() && !(top_frame
->GetParent()->m_isFrame
))
125 top_frame
= top_frame
->GetParent();
127 /* support for native hot keys */
128 gtk_accel_group_detach( menu
->m_accel
, GTK_OBJECT(top_frame
->m_widget
) );
131 wxNode
*node
= menu
->GetItems().First();
134 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
135 if (menuitem
->IsSubMenu())
136 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
141 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
143 menu
->SetInvokingWindow( win
);
145 #if (GTK_MINOR_VERSION > 0)
146 wxWindow
*top_frame
= win
;
147 while (top_frame
->GetParent() && !(top_frame
->GetParent()->m_isFrame
))
148 top_frame
= top_frame
->GetParent();
150 /* support for native hot keys */
151 gtk_accel_group_attach( menu
->m_accel
, GTK_OBJECT(top_frame
->m_widget
) );
154 wxNode
*node
= menu
->GetItems().First();
157 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
158 if (menuitem
->IsSubMenu())
159 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
164 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
166 m_invokingWindow
= win
;
167 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
168 wxWindow
*top_frame
= win
;
169 while (top_frame
->GetParent() && !(top_frame
->GetParent()->m_isFrame
))
170 top_frame
= top_frame
->GetParent();
172 /* support for native key accelerators indicated by underscroes */
173 gtk_accel_group_attach( m_accel
, GTK_OBJECT(top_frame
->m_widget
) );
176 wxNode
*node
= m_menus
.First();
179 wxMenu
*menu
= (wxMenu
*)node
->Data();
180 wxMenubarSetInvokingWindow( menu
, win
);
185 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
187 m_invokingWindow
= (wxWindow
*) NULL
;
188 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
189 wxWindow
*top_frame
= win
;
190 while (top_frame
->GetParent() && !(top_frame
->GetParent()->m_isFrame
))
191 top_frame
= top_frame
->GetParent();
193 /* support for native key accelerators indicated by underscroes */
194 gtk_accel_group_detach( m_accel
, GTK_OBJECT(top_frame
->m_widget
) );
197 wxNode
*node
= m_menus
.First();
200 wxMenu
*menu
= (wxMenu
*)node
->Data();
201 wxMenubarUnsetInvokingWindow( menu
, win
);
206 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
208 m_menus
.Append( menu
);
212 /* GTK 1.2 wants to have "_" instead of "&" for accelerators */
214 for ( pc
= title
; *pc
!= wxT('\0'); pc
++ )
218 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
221 else if (*pc
== wxT('/'))
229 if ( *pc
== wxT('_') )
231 // underscores must be doubled to prevent them from being
232 // interpreted as accelerator character prefix by GTK
241 /* this doesn't have much effect right now */
242 menu
->SetTitle( str
);
244 /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
245 #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
247 /* local buffer in multibyte form */
249 buf
<< wxT('/') << str
.c_str();
251 char *cbuf
= new char[buf
.Length()+1];
252 strcpy(cbuf
, buf
.mbc_str());
254 GtkItemFactoryEntry entry
;
255 entry
.path
= (gchar
*)cbuf
; // const_cast
256 entry
.accelerator
= (gchar
*) NULL
;
257 entry
.callback
= (GtkItemFactoryCallback
) NULL
;
258 entry
.callback_action
= 0;
259 entry
.item_type
= "<Branch>";
261 gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 ); /* what is 2 ? */
262 /* in order to get the pointer to the item we need the item text _without_ underscores */
263 wxString tmp
= wxT("<main>/");
264 for ( pc
= str
; *pc
!= wxT('\0'); pc
++ )
266 // contrary to the common sense, we must throw out _all_ underscores,
267 // (i.e. "Hello__World" => "HelloWorld" and not "Hello_World" as we
268 // might naively think). IMHO it's a bug in GTK+ (VZ)
269 while (*pc
== wxT('_'))
273 menu
->m_owner
= gtk_item_factory_get_item( m_factory
, tmp
.mb_str() );
274 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
278 menu
->m_owner
= gtk_menu_item_new_with_label( str
.mb_str() );
279 gtk_widget_show( menu
->m_owner
);
280 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
282 gtk_menu_bar_append( GTK_MENU_BAR(m_menubar
), menu
->m_owner
);
286 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
287 // adding menu later on.
288 if (m_invokingWindow
)
289 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
294 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
296 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
299 wxFAIL_MSG(wxT("TODO"));
304 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
306 if ( !wxMenuBarBase::Replace(pos
, menu
, title
) )
309 wxFAIL_MSG(wxT("TODO"));
314 wxMenu
*wxMenuBar::Remove(size_t pos
)
316 if ( !wxMenuBarBase::Remove(pos
) )
319 wxFAIL_MSG(wxT("TODO"));
324 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
326 if (menu
->GetTitle() == menuString
)
328 int res
= menu
->FindItem( itemString
);
329 if (res
!= wxNOT_FOUND
)
333 wxNode
*node
= ((wxMenu
*)menu
)->GetItems().First(); // const_cast
336 wxMenuItem
*item
= (wxMenuItem
*)node
->Data();
337 if (item
->IsSubMenu())
338 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
346 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
348 wxNode
*node
= m_menus
.First();
351 wxMenu
*menu
= (wxMenu
*)node
->Data();
352 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
353 if (res
!= -1) return res
;
359 // Find a wxMenuItem using its id. Recurses down into sub-menus
360 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
362 wxMenuItem
* result
= menu
->FindChildItem(id
);
364 wxNode
*node
= ((wxMenu
*)menu
)->GetItems().First(); // const_cast
365 while ( node
&& result
== NULL
)
367 wxMenuItem
*item
= (wxMenuItem
*)node
->Data();
368 if (item
->IsSubMenu())
370 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
378 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
380 wxMenuItem
* result
= 0;
381 wxNode
*node
= m_menus
.First();
382 while (node
&& result
== 0)
384 wxMenu
*menu
= (wxMenu
*)node
->Data();
385 result
= FindMenuItemByIdRecursive( menu
, id
);
391 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
397 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
399 wxMenuList::Node
*node
= m_menus
.Item( pos
);
401 wxCHECK_RET( node
, wxT("menu not found") );
403 wxMenu
* menu
= node
->GetData();
406 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
409 wxString
wxMenuBar::GetLabelTop( size_t pos
) const
411 wxMenuList::Node
*node
= m_menus
.Item( pos
);
413 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
415 wxMenu
* menu
= node
->GetData();
417 return menu
->GetTitle();
420 void wxMenuBar::SetLabelTop( size_t pos
, const wxString
& label
)
422 wxMenuList::Node
*node
= m_menus
.Item( pos
);
424 wxCHECK_RET( node
, wxT("menu not found") );
426 wxMenu
* menu
= node
->GetData();
428 menu
->SetTitle( label
);
431 //-----------------------------------------------------------------------------
433 //-----------------------------------------------------------------------------
435 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
437 if (g_isIdle
) wxapp_install_idle_handler();
439 int id
= menu
->FindMenuIdByMenuItem(widget
);
441 /* should find it for normal (not popup) menu */
442 wxASSERT( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
) );
444 if (!menu
->IsEnabled(id
))
447 wxMenuItem
* item
= menu
->FindChildItem( id
);
448 wxCHECK_RET( item
, wxT("error in menu item callback") );
450 if (item
->IsCheckable())
452 bool isReallyChecked
= item
->IsChecked();
453 if ( item
->wxMenuItemBase::IsChecked() == isReallyChecked
)
455 /* the menu item has been checked by calling wxMenuItem->Check() */
460 /* the user pressed on the menu item -> report and make consistent
462 item
->wxMenuItemBase::Check(isReallyChecked
);
466 wxCommandEvent
event( wxEVT_COMMAND_MENU_SELECTED
, id
);
467 event
.SetEventObject( menu
);
470 if (menu
->GetCallback())
472 (void) (*(menu
->GetCallback())) (*menu
, event
);
476 if (menu
->GetEventHandler()->ProcessEvent(event
))
479 wxWindow
*win
= menu
->GetInvokingWindow();
481 win
->GetEventHandler()->ProcessEvent( event
);
484 //-----------------------------------------------------------------------------
486 //-----------------------------------------------------------------------------
488 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
490 if (g_isIdle
) wxapp_install_idle_handler();
492 int id
= menu
->FindMenuIdByMenuItem(widget
);
494 wxASSERT( id
!= -1 ); // should find it!
496 if (!menu
->IsEnabled(id
))
499 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
500 event
.SetEventObject( menu
);
502 if (menu
->GetEventHandler()->ProcessEvent(event
))
505 wxWindow
*win
= menu
->GetInvokingWindow();
506 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
509 //-----------------------------------------------------------------------------
511 //-----------------------------------------------------------------------------
513 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
515 if (g_isIdle
) wxapp_install_idle_handler();
517 int id
= menu
->FindMenuIdByMenuItem(widget
);
519 wxASSERT( id
!= -1 ); // should find it!
521 if (!menu
->IsEnabled(id
))
524 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
525 event
.SetEventObject( menu
);
527 if (menu
->GetEventHandler()->ProcessEvent(event
))
530 wxWindow
*win
= menu
->GetInvokingWindow();
532 win
->GetEventHandler()->ProcessEvent( event
);
535 //-----------------------------------------------------------------------------
537 //-----------------------------------------------------------------------------
539 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxMenuItemBase
)
541 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
543 const wxString
& name
,
544 const wxString
& help
,
548 return new wxMenuItem(parentMenu
, id
, name
, help
, isCheckable
, subMenu
);
551 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
553 const wxString
& text
,
554 const wxString
& help
,
559 m_isCheckable
= isCheckable
;
563 m_parentMenu
= parentMenu
;
566 m_menuItem
= (GtkWidget
*) NULL
;
571 wxMenuItem::~wxMenuItem()
573 // don't delete menu items, the menus take care of that
576 // return the menu item text without any menu accels
577 wxString
wxMenuItem::GetLabel() const
580 #if (GTK_MINOR_VERSION > 0)
581 for ( const wxChar
*pc
= m_text
.c_str(); *pc
; pc
++ )
583 if ( *pc
== wxT('_') )
585 // this is the escape character for GTK+ - skip it
593 #endif // GTK+ 1.2/1.0
598 void wxMenuItem::SetText( const wxString
& str
)
604 GtkLabel
*label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
607 gtk_label_set( label
, m_text
.mb_str());
609 /* reparse key accel */
610 guint accel_key
= gtk_label_parse_uline (GTK_LABEL(label
), m_text
.mb_str() );
611 gtk_accel_label_refetch( GTK_ACCEL_LABEL(label
) );
615 // it's valid for this function to be called even if m_menuItem == NULL
616 void wxMenuItem::DoSetText( const wxString
& str
)
618 /* '\t' is the deliminator indicating a hot key */
620 const wxChar
*pc
= str
;
621 for (; (*pc
!= wxT('\0')) && (*pc
!= wxT('\t')); pc
++ )
625 #if (GTK_MINOR_VERSION > 0)
628 else if ( *pc
== wxT('_') ) // escape underscores
632 else if (*pc
== wxT('/')) /* we have to filter out slashes ... */
634 m_text
<< wxT('\\'); /* ... and replace them with back slashes */
641 /* only GTK 1.2 knows about hot keys */
643 #if (GTK_MINOR_VERSION > 0)
654 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
656 if ( !item
.GetHotKey() )
659 return (wxAcceleratorEntry
*)NULL
;
662 // as wxGetAccelFromString() looks for TAB, insert a dummy one here
664 label
<< wxT('\t') << item
.GetHotKey();
666 return wxGetAccelFromString(label
);
669 #endif // wxUSE_ACCEL
671 void wxMenuItem::Check( bool check
)
673 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
675 wxCHECK_RET( IsCheckable(), wxT("Can't check uncheckable item!") )
677 if (check
== m_isChecked
)
680 wxMenuItemBase::Check( check
);
681 gtk_check_menu_item_set_state( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
684 void wxMenuItem::Enable( bool enable
)
686 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
688 gtk_widget_set_sensitive( m_menuItem
, enable
);
689 wxMenuItemBase::Enable( enable
);
692 bool wxMenuItem::IsChecked() const
694 wxCHECK_MSG( m_menuItem
, FALSE
, wxT("invalid menu item") );
696 wxCHECK_MSG( IsCheckable(), FALSE
,
697 wxT("can't get state of uncheckable item!") );
699 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
702 wxString
wxMenuItem::GetFactoryPath() const
704 /* in order to get the pointer to the item we need the item text _without_ underscores */
705 wxString
path( wxT("<main>/") );
711 //-----------------------------------------------------------------------------
713 //-----------------------------------------------------------------------------
715 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
719 #if (GTK_MINOR_VERSION > 0)
720 m_accel
= gtk_accel_group_new();
721 m_factory
= gtk_item_factory_new( GTK_TYPE_MENU
, "<main>", m_accel
);
722 m_menu
= gtk_item_factory_get_widget( m_factory
, "<main>" );
724 m_menu
= gtk_menu_new(); // Do not show!
727 m_owner
= (GtkWidget
*) NULL
;
729 #if (GTK_MINOR_VERSION > 0)
730 /* Tearoffs are entries, just like separators. So if we want this
731 menu to be a tear-off one, we just append a tearoff entry
733 if(m_style
& wxMENU_TEAROFF
)
735 GtkItemFactoryEntry entry
;
736 entry
.path
= "/tearoff";
737 entry
.callback
= (GtkItemFactoryCallback
) NULL
;
738 entry
.callback_action
= 0;
739 entry
.item_type
= "<Tearoff>";
740 entry
.accelerator
= (gchar
*) NULL
;
741 gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 ); /* what is 2 ? */
742 //GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, "<main>/tearoff" );
746 // append the title as the very first entry if we have it
756 gtk_widget_destroy( m_menu
);
758 gtk_object_unref( GTK_OBJECT(m_factory
) );
760 // the menu items are deleted by the base class dtor
763 virtual bool wxMenu::DoAppend(wxMenuItem
*mitem
)
767 if ( mitem
->IsSeparator() )
769 #if (GTK_MINOR_VERSION > 0)
770 GtkItemFactoryEntry entry
;
772 entry
.callback
= (GtkItemFactoryCallback
) NULL
;
773 entry
.callback_action
= 0;
774 entry
.item_type
= "<Separator>";
775 entry
.accelerator
= (gchar
*) NULL
;
777 gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 ); /* what is 2 ? */
779 /* this will be wrong for more than one separator. do we care? */
780 menuItem
= gtk_item_factory_get_widget( m_factory
, "<main>/sep" );
782 menuItem
= gtk_menu_item_new();
783 #endif // GTK 1.2/1.0
785 else if ( mitem
->IsSubMenu() )
787 #if (GTK_MINOR_VERSION > 0)
788 /* text has "_" instead of "&" after mitem->SetText() */
789 wxString
text( mitem
->GetText() );
791 /* local buffer in multibyte form */
794 strcat( buf
, text
.mb_str() );
796 GtkItemFactoryEntry entry
;
798 entry
.callback
= (GtkItemFactoryCallback
) 0;
799 entry
.callback_action
= 0;
800 entry
.item_type
= "<Branch>";
802 gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 ); /* what is 2 ? */
804 wxString
path( mitem
->GetFactoryPath() );
805 GtkWidget
*menuItem
= gtk_item_factory_get_item( m_factory
, path
.mb_str() );
807 GtkWidget
*menuItem
= gtk_menu_item_new_with_label(mitem
->GetText().mbc_str());
808 #endif // GTK 1.2/1.0
810 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), subMenu
->m_menu
);
812 else // a normal item
814 #if (GTK_MINOR_VERSION > 0)
815 /* text has "_" instead of "&" after mitem->SetText() */
816 wxString
text( mitem
->GetText() );
818 /* local buffer in multibyte form */
821 strcat( buf
, text
.mb_str() );
823 GtkItemFactoryEntry entry
;
825 entry
.callback
= (GtkItemFactoryCallback
) gtk_menu_clicked_callback
;
826 entry
.callback_action
= 0;
828 entry
.item_type
= "<CheckItem>";
830 entry
.item_type
= "<Item>";
833 // due to an apparent bug in GTK+, we have to use a static buffer here -
834 // otherwise GTK+ 1.2.2 manages to override the memory we pass to it
836 static char s_accel
[32]; // must be big enough for <control><alt><shift>F12
837 strncpy(s_accel
, GetHotKey(*mitem
).mb_str(), WXSIZEOF(s_accel
));
838 entry
.accelerator
= s_accel
;
839 #else // !wxUSE_ACCEL
840 entry
.accelerator
= (char*) NULL
;
841 #endif // wxUSE_ACCEL/!wxUSE_ACCEL
843 gtk_item_factory_create_item( m_factory
, &entry
, (gpointer
) this, 2 ); /* what is 2 ? */
845 wxString
path( mitem
->GetFactoryPath() );
846 GtkWidget
*menuItem
= gtk_item_factory_get_widget( m_factory
, path
.mb_str() );
848 GtkWidget
*menuItem
= checkable
? gtk_check_menu_item_new_with_label( mitem
->GetText().mb_str() )
849 : gtk_menu_item_new_with_label( mitem
->GetText().mb_str() );
851 gtk_signal_connect( GTK_OBJECT(menuItem
), "activate",
852 GTK_SIGNAL_FUNC(gtk_menu_clicked_callback
),
854 #endif // GTK+ 1.2/1.0
857 if ( !mitem
->IsSeparator() )
859 gtk_signal_connect( GTK_OBJECT(menuItem
), "select",
860 GTK_SIGNAL_FUNC(gtk_menu_hilight_callback
),
863 gtk_signal_connect( GTK_OBJECT(menuItem
), "deselect",
864 GTK_SIGNAL_FUNC(gtk_menu_nolight_callback
),
868 #if GTK_MINOR_VERSION == 0
869 gtk_menu_append( GTK_MENU(m_menu
), menuItem
);
870 gtk_widget_show( menuItem
);
873 mitem
->SetMenuItem(menuItem
);
875 return wxMenuBase::DoAppend(mitem
);
878 // VZ: this seems to be GTK+ 1.0 only code, I don't understand why there were
879 // both specialized versions of Append() and this one before my changes,
880 // but it seems that the others are better...
882 void wxMenu::Append( wxMenuItem
*item
)
884 GtkWidget
*menuItem
= (GtkWidget
*) NULL
;
886 if (item
->IsSeparator())
887 menuItem
= gtk_menu_item_new();
888 else if (item
->IsSubMenu())
889 menuItem
= gtk_menu_item_new_with_label(item
->GetText().mbc_str());
891 menuItem
= item
->IsCheckable() ? gtk_check_menu_item_new_with_label(item
->GetText().mbc_str())
892 : gtk_menu_item_new_with_label(item
->GetText().mbc_str());
894 if (!item
->IsSeparator())
896 gtk_signal_connect( GTK_OBJECT(menuItem
), "select",
897 GTK_SIGNAL_FUNC(gtk_menu_hilight_callback
),
900 gtk_signal_connect( GTK_OBJECT(menuItem
), "deselect",
901 GTK_SIGNAL_FUNC(gtk_menu_nolight_callback
),
904 if (!item
->IsSubMenu())
906 gtk_signal_connect( GTK_OBJECT(menuItem
), "activate",
907 GTK_SIGNAL_FUNC(gtk_menu_clicked_callback
),
912 gtk_menu_append( GTK_MENU(m_menu
), menuItem
);
913 gtk_widget_show( menuItem
);
915 item
->SetMenuItem(menuItem
);
919 bool wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
921 if ( !wxMenuBase::DoInsert(pos
, item
) )
924 wxFAIL_MSG(wxT("not implemented"));
929 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
931 if ( !wxMenuBase::DoRemove(item
) )
932 return (wxMenuItem
*)NULL
;
934 // TODO: this code doesn't delete the item factory item and this seems
935 // impossible as of GTK 1.2.6.
936 gtk_widget_destroy( item
->GetMenuItem() );
941 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
943 wxNode
*node
= m_items
.First();
946 wxMenuItem
*item
= (wxMenuItem
*)node
->Data();
947 if (item
->GetMenuItem() == menuItem
)
948 return item
->GetId();
955 // ----------------------------------------------------------------------------
957 // ----------------------------------------------------------------------------
959 #if (GTK_MINOR_VERSION > 0) && wxUSE_ACCEL
960 static wxString
GetHotKey( const wxMenuItem
& item
)
964 wxAcceleratorEntry
*accel
= item
.GetAccel();
967 int flags
= accel
->GetFlags();
968 if ( flags
& wxACCEL_ALT
)
969 hotkey
+= wxT("<alt>");
970 if ( flags
& wxACCEL_CTRL
)
971 hotkey
+= wxT("<control>");
972 if ( flags
& wxACCEL_SHIFT
)
973 hotkey
+= wxT("<shift>");
975 int code
= accel
->GetKeyCode();
990 hotkey
<< wxT('F') << code
- WXK_F1
+ 1;
993 // if there are any other keys wxGetAccelFromString() may return,
994 // we should process them here
997 if ( wxIsalnum(code
) )
999 hotkey
<< (wxChar
)code
;
1004 wxFAIL_MSG( wxT("unknown keyboard accel") );
1012 #endif // wxUSE_ACCEL