X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/092f753690cec1f4ee3a7ad2df53afc70caaa2f3..229653c99e1d679aab15772a4a25909ca52c4d94:/src/gtk1/menu.cpp diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index e6789d180b..d74c9b2ca6 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -117,14 +117,25 @@ static wxString wxReplaceUnderscore( const wxString& title ) { if (*pc == wxT('&')) { -#if GTK_CHECK_VERSION(1, 2, 1) +#if GTK_CHECK_VERSION(1, 2, 0) str << wxT('_'); +#endif + } +#if GTK_CHECK_VERSION(2, 0, 0) + else if (*pc == wxT('/')) + { + str << wxT("\\/"); + } + else if (*pc == wxT('\\')) + { + str << wxT("\\\\"); } +#elif GTK_CHECK_VERSION(1, 2, 0) else if (*pc == wxT('/')) { str << wxT('\\'); -#endif } +#endif else { #if __WXGTK12__ @@ -621,21 +632,25 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) if (item->IsCheckable()) { - bool isReallyChecked = item->IsChecked(); - if ( item->wxMenuItemBase::IsChecked() == isReallyChecked ) + bool isReallyChecked = item->IsChecked(), + isInternallyChecked = item->wxMenuItemBase::IsChecked(); + + // ensure that the internal state is always consistent with what is + // shown on the screen + item->wxMenuItemBase::Check(isReallyChecked); + + // we must not report the events for the radio button going up nor the + // events resulting from the calls to wxMenuItem::Check() + if ( (item->GetKind() == wxITEM_RADIO && !isReallyChecked) || + (isInternallyChecked == isReallyChecked) ) { - /* the menu item has been checked by calling wxMenuItem->Check() */ return; } - else - { - /* the user pressed on the menu item -> report and make consistent - * again */ - item->wxMenuItemBase::Check(isReallyChecked); - } + + // the user pressed on the menu item: report the event below } - menu->SendEvent(item->GetId(), item->IsCheckable() ? item->IsChecked() : -1); + menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1); } //----------------------------------------------------------------------------- @@ -771,6 +786,14 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) void wxMenuItem::SetText( const wxString& str ) { + // Some optimization to avoid flicker + wxString oldLabel = m_text; + oldLabel = wxStripMenuCodes(oldLabel.BeforeFirst('\t')); + oldLabel.Replace(wxT("_"), wxT("")); + wxString label1 = wxStripMenuCodes(str.BeforeFirst('\t')); + if (oldLabel == label1) + return; + DoSetText(str); if (m_menuItem) @@ -798,20 +821,35 @@ void wxMenuItem::DoSetText( const wxString& str ) const wxChar *pc = str; for (; (*pc != wxT('\0')) && (*pc != wxT('\t')); pc++ ) { +#if GTK_CHECK_VERSION(1, 2, 0) if (*pc == wxT('&')) { -#if GTK_CHECK_VERSION(1, 2, 0) m_text << wxT('_'); } else if ( *pc == wxT('_') ) // escape underscores { m_text << wxT("__"); } +#else // GTK+ < 1.2.0 + if (*pc == wxT('&')) + { + } +#endif +#if GTK_CHECK_VERSION(2, 0, 0) + else if (*pc == wxT('/')) // we have to escape slashes + { + m_text << wxT("\\/"); + } + else if (*pc == wxT('\\')) // we have to double backslashes + { + m_text << wxT("\\\\"); + } +#elif GTK_CHECK_VERSION(1, 2, 0) else if (*pc == wxT('/')) /* we have to filter out slashes ... */ { m_text << wxT('\\'); /* ... and replace them with back slashes */ -#endif // GTK+ 1.2.0+ } +#endif else m_text << *pc; } @@ -851,17 +889,20 @@ void wxMenuItem::Check( bool check ) { wxCHECK_RET( m_menuItem, wxT("invalid menu item") ); - wxCHECK_RET( IsCheckable(), wxT("Can't check uncheckable item!") ) - if (check == m_isChecked) return; wxMenuItemBase::Check( check ); - // GTK+ does it itself for the radio item - if ( GetKind() == wxITEM_CHECK ) + switch ( GetKind() ) { - gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check ); + case wxITEM_CHECK: + case wxITEM_RADIO: + gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check ); + break; + + default: + wxFAIL_MSG( _T("can't check this item") ); } } @@ -964,8 +1005,8 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) #endif #if GTK_CHECK_VERSION(1, 2, 0) - // is this a radio item? - bool isRadio = FALSE; + // does this item terminate the current radio group? + bool endOfRadioGroup = TRUE; #endif // GTK+ >= 1.2 if ( mitem->IsSeparator() ) @@ -982,6 +1023,9 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) /* this will be wrong for more than one separator. do we care? */ menuItem = gtk_item_factory_get_widget( m_factory, "
/sep" ); + + // we might have a separator inside a radio group + endOfRadioGroup = FALSE; #else // GTK+ 1.0 menuItem = gtk_menu_item_new(); #endif // GTK 1.2/1.0 @@ -1097,9 +1141,8 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) item_type = pathRadio; } - // remember that this one was a radio item to avoid resetting - // m_pathLastRadio below - isRadio = TRUE; + // continue the existing radio group, if any + endOfRadioGroup = FALSE; break; default: @@ -1162,7 +1205,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) mitem->SetMenuItem(menuItem); #if GTK_CHECK_VERSION(1, 2, 0) - if ( !isRadio ) + if ( endOfRadioGroup ) { m_pathLastRadio.clear(); }