X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bcf881efa908bc34f014552dce74a171e2a9a920..8ca1a013e4e699724040ff1f514dab3b4a11d3c9:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 7f4d87855d..97d926f92f 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: src/gtk/menu.cpp -// Purpose: +// Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK // Author: Robert Roebling // Id: $Id$ // Copyright: (c) 1998 Robert Roebling @@ -10,6 +10,8 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#if wxUSE_MENUS + #include "wx/menu.h" #ifndef WX_PRECOMP @@ -55,14 +57,12 @@ static wxString GetGtkHotKey( const wxMenuItem& item ); static wxString wxReplaceUnderscore( const wxString& title ) { - const wxChar *pc; - // GTK 1.2 wants to have "_" instead of "&" for accelerators wxString str; - pc = title; - while (*pc != wxT('\0')) + + for ( wxString::const_iterator pc = title.begin(); pc != title.end(); ++pc ) { - if ((*pc == wxT('&')) && (*(pc+1) == wxT('&'))) + if ((*pc == wxT('&')) && (pc+1 != title.end()) && (*(pc+1) == wxT('&'))) { // "&" is doubled to indicate "&" instead of accelerator ++pc; @@ -83,7 +83,6 @@ static wxString wxReplaceUnderscore( const wxString& title ) str << *pc; } - ++pc; } // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() ); @@ -97,9 +96,6 @@ static wxString wxReplaceUnderscore( const wxString& title ) static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event) { - if (g_isIdle) - wxapp_install_idle_handler(); - event.SetEventObject( menu ); wxEvtHandler* handler = menu->GetEventHandler(); @@ -143,13 +139,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style) { - // the parent window is known after wxFrame::SetMenu() - m_needParent = false; m_style = style; - m_invokingWindow = (wxWindow*) NULL; + m_invokingWindow = NULL; - if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || - !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") )) + if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) || + !CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") )) { wxFAIL_MSG( wxT("wxMenuBar creation failed") ); return; @@ -160,12 +154,12 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st if (style & wxMB_DOCKABLE) { m_widget = gtk_handle_box_new(); - gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) ); - gtk_widget_show( GTK_WIDGET(m_menubar) ); + gtk_container_add(GTK_CONTAINER(m_widget), m_menubar); + gtk_widget_show(m_menubar); } else { - m_widget = GTK_WIDGET(m_menubar); + m_widget = m_menubar; } PostCreation(); @@ -560,9 +554,6 @@ void wxMenuBar::SetLabelTop( size_t pos, const wxString& label ) extern "C" { static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) { - if (g_isIdle) - wxapp_install_idle_handler(); - int id = menu->FindMenuIdByMenuItem(widget); /* should find it for normal (not popup) menu */ @@ -637,8 +628,6 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) extern "C" { static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) { - if (g_isIdle) wxapp_install_idle_handler(); - int id = menu->FindMenuIdByMenuItem(widget); wxASSERT( id != -1 ); // should find it! @@ -665,8 +654,6 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) extern "C" { static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu ) { - if (g_isIdle) wxapp_install_idle_handler(); - int id = menu->FindMenuIdByMenuItem(widget); wxASSERT( id != -1 ); // should find it! @@ -833,7 +820,7 @@ void wxMenuItem::SetText( const wxString& str ) gtk_accelerator_parse( (const char*) oldbuf, &accel_key, &accel_mods); if (accel_key != 0) { - gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem), + gtk_widget_remove_accelerator(m_menuItem, m_parentMenu->m_accel, accel_key, accel_mods ); @@ -843,7 +830,7 @@ void wxMenuItem::SetText( const wxString& str ) { // if the accelerator was taken from a stock ID, just get it back from GTK+ stock if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key)) - gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem), + gtk_widget_remove_accelerator( m_menuItem, m_parentMenu->m_accel, accel_key, accel_mods ); @@ -856,7 +843,7 @@ void wxMenuItem::SetText( const wxString& str ) gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods); if (accel_key != 0) { - gtk_widget_add_accelerator( GTK_WIDGET(m_menuItem), + gtk_widget_add_accelerator( m_menuItem, "activate", m_parentMenu->m_accel, accel_key, @@ -868,7 +855,7 @@ void wxMenuItem::SetText( const wxString& str ) { // if the accelerator was taken from a stock ID, just get it back from GTK+ stock if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key)) - gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem), + gtk_widget_remove_accelerator( m_menuItem, m_parentMenu->m_accel, accel_key, accel_mods ); @@ -883,18 +870,22 @@ wxString wxMenuItem::GTKProcessMenuItemLabel(const wxString& str, wxString *hotK wxString text; // '\t' is the deliminator indicating a hot key - const wxChar *pc = str; - while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) ) + wxString::const_iterator pc = str.begin(); + while ( pc != str.end() && *pc != wxT('\t') ) { - if ((*pc == wxT('&')) && (*(pc+1) == wxT('&'))) - { - // "&" is doubled to indicate "&" instead of accelerator - ++pc; - text << wxT('&'); - } - else if (*pc == wxT('&')) + if (*pc == wxT('&')) { - text << wxT('_'); + wxString::const_iterator next = pc + 1; + if (next != str.end() && *next == wxT('&')) + { + // "&" is doubled to indicate "&" instead of accelerator + ++pc; + text << wxT('&'); + } + else + { + text << wxT('_'); + } } else if ( *pc == wxT('_') ) // escape underscores { @@ -913,7 +904,7 @@ wxString wxMenuItem::GTKProcessMenuItemLabel(const wxString& str, wxString *hotK if(*pc == wxT('\t')) { pc++; - *hotKey = pc; + hotKey->assign(pc, str.end()); } } @@ -1030,6 +1021,8 @@ wxMenu::~wxMenu() { // see wxMenu::Init gtk_widget_unref( m_menu ); + g_object_unref( m_accel ); + // if the menu is inserted in another menu at this time, there was // one more reference to it: if ( m_owner ) @@ -1174,7 +1167,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods); if (accel_key != 0) { - gtk_widget_add_accelerator (GTK_WIDGET(menuItem), + gtk_widget_add_accelerator (menuItem, "activate", m_accel, accel_key, @@ -1186,7 +1179,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) { // if the accelerator was taken from a stock ID, just get it back from GTK+ stock if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key)) - gtk_widget_add_accelerator( GTK_WIDGET(menuItem), + gtk_widget_add_accelerator( menuItem, "activate", m_accel, accel_key, @@ -1362,10 +1355,10 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) hotkey << wxT("Down" ); break; case WXK_PAGEUP: - hotkey << wxT("PgUp" ); + hotkey << wxT("Page_Up" ); break; case WXK_PAGEDOWN: - hotkey << wxT("PgDn" ); + hotkey << wxT("Page_Down" ); break; case WXK_LEFT: hotkey << wxT("Left" ); @@ -1483,10 +1476,10 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) hotkey << wxT("KP_Down" ); break; case WXK_NUMPAD_PAGEUP: - hotkey << wxT("KP_PgUp" ); + hotkey << wxT("KP_Page_Up" ); break; case WXK_NUMPAD_PAGEDOWN: - hotkey << wxT("KP_PgDn" ); + hotkey << wxT("KP_Page_Down" ); break; case WXK_NUMPAD_END: hotkey << wxT("KP_End" ); @@ -1547,8 +1540,9 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) default: if ( code < 127 ) { - wxString name = wxGTK_CONV_BACK( gdk_keyval_name((guint)code) ); - if ( name ) + const wxString + name = wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint)code)); + if ( !name.empty() ) { hotkey << name; break; @@ -1800,3 +1794,5 @@ bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key) } #endif // __WXGTK20__ + +#endif // wxUSE_MENUS