X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aee12bfb80fb63b82552f59127d5e66b7f056ff2..2523e9b70044baa92a1c63ffdfe179c28ad53536:/src/gtk1/menu.cpp diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 89b6206f64..ea47b894ec 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -11,10 +11,14 @@ #include "wx/wxprec.h" #include "wx/menu.h" -#include "wx/log.h" -#include "wx/intl.h" -#include "wx/app.h" -#include "wx/bitmap.h" +#include "wx/stockitem.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/app.h" + #include "wx/bitmap.h" +#endif #if wxUSE_ACCEL #include "wx/accel.h" @@ -700,7 +704,7 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, wxMenu *subMenu) : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu) { - Init(text); + Init(); } wxMenuItem::wxMenuItem(wxMenu *parentMenu, @@ -712,15 +716,15 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, : wxMenuItemBase(parentMenu, id, text, help, isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu) { - Init(text); + Init(); } -void wxMenuItem::Init(const wxString& text) +void wxMenuItem::Init() { m_labelWidget = (GtkWidget *) NULL; m_menuItem = (GtkWidget *) NULL; - DoSetText(text); + DoSetText(m_text); } wxMenuItem::~wxMenuItem() @@ -762,8 +766,16 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) return label; } -void wxMenuItem::SetText( const wxString& str ) +void wxMenuItem::SetText( const wxString& string ) { + wxString str = string; + if ( str.empty() && !IsSeparator() ) + { + wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); + str = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR | + wxSTOCK_WITH_MNEMONIC); + } + // Some optimization to avoid flicker wxString oldLabel = m_text; oldLabel = wxStripMenuCodes(oldLabel); @@ -822,7 +834,9 @@ void wxMenuItem::SetText( const wxString& str ) void wxMenuItem::DoSetText( const wxString& str ) { // '\t' is the deliminator indicating a hot key - m_text.Empty(); + wxString text; + text.reserve(str.length()); + const wxChar *pc = str; while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) ) { @@ -830,32 +844,32 @@ void wxMenuItem::DoSetText( const wxString& str ) { // "&" is doubled to indicate "&" instead of accelerator ++pc; - m_text << wxT('&'); + text << wxT('&'); } else if (*pc == wxT('&')) { - m_text << wxT('_'); + text << wxT('_'); } else if ( *pc == wxT('_') ) // escape underscores { - m_text << wxT("__"); + text << wxT("__"); } else { - m_text << *pc; + text << *pc; } ++pc; } m_hotKey = wxEmptyString; - if(*pc == wxT('\t')) + if ( *pc == wxT('\t') ) { pc++; m_hotKey = pc; } - // wxPrintf( wxT("DoSetText(): str %s m_text %s hotkey %s\n"), str.c_str(), m_text.c_str(), m_hotKey.c_str() ); + m_text = text; } #if wxUSE_ACCEL @@ -868,11 +882,12 @@ wxAcceleratorEntry *wxMenuItem::GetAccel() const return (wxAcceleratorEntry *)NULL; } - // as wxGetAccelFromString() looks for TAB, insert a dummy one here + // accelerator parsing code looks for them after a TAB, so insert a dummy + // one here wxString label; label << wxT('\t') << GetHotKey(); - return wxGetAccelFromString(label); + return wxAcceleratorEntry::Create(label); } #endif // wxUSE_ACCEL @@ -984,7 +999,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) text = mitem->GetText(); const wxBitmap *bitmap = &mitem->GetBitmap(); - // TODO + // TODO wxUnusedVar(bitmap); menuItem = gtk_menu_item_new_with_label( wxGTK_CONV( text ) ); label = GTK_LABEL( GTK_BIN(menuItem)->child ); @@ -1233,10 +1248,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" ); @@ -1354,10 +1369,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" ); @@ -1412,14 +1427,14 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1); break; */ - // if there are any other keys wxGetAccelFromString() may + // if there are any other keys wxAcceleratorEntry::Create() may // return, we should process them here default: if ( code < 127 ) { wxString name = wxGTK_CONV_BACK( gdk_keyval_name((guint)code) ); - if ( name ) + if ( !name.empty() ) { hotkey << name; break; @@ -1446,7 +1461,7 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting ) { - *is_waiting = FALSE; + *is_waiting = false; } WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win )