#include "wx/wxprec.h"
#include "wx/menu.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
-#include "wx/app.h"
-#include "wx/bitmap.h"
-
#if wxUSE_ACCEL
#include "wx/accel.h"
#endif // wxUSE_ACCEL
wxMenu *subMenu)
: wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{
- Init(text);
+ Init();
}
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()
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);
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')) )
{
{
// "&" 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
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
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" );
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" );
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;
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 )