fix handling of stock menu items (creating a stock item without label left its label empty)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45487 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-04-15 23:08:19 +00:00
parent 498ace9e1f
commit 010eb424bb
2 changed files with 15 additions and 11 deletions

View File

@@ -58,7 +58,7 @@ public:
private: private:
// common part of all ctors // common part of all ctors
void Init(const wxString& text); void Init();
// DoSetText() transforms the accel mnemonics in our label from MSW/wxWin // DoSetText() transforms the accel mnemonics in our label from MSW/wxWin
// style to GTK+ and is called from ctor and SetText() // style to GTK+ and is called from ctor and SetText()

View File

@@ -704,7 +704,7 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
wxMenu *subMenu) wxMenu *subMenu)
: wxMenuItemBase(parentMenu, id, text, help, kind, subMenu) : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{ {
Init(text); Init();
} }
wxMenuItem::wxMenuItem(wxMenu *parentMenu, wxMenuItem::wxMenuItem(wxMenu *parentMenu,
@@ -716,15 +716,15 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
: wxMenuItemBase(parentMenu, id, text, help, : wxMenuItemBase(parentMenu, id, text, help,
isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu) isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu)
{ {
Init(text); Init();
} }
void wxMenuItem::Init(const wxString& text) void wxMenuItem::Init()
{ {
m_labelWidget = (GtkWidget *) NULL; m_labelWidget = (GtkWidget *) NULL;
m_menuItem = (GtkWidget *) NULL; m_menuItem = (GtkWidget *) NULL;
DoSetText(text); DoSetText(m_text);
} }
wxMenuItem::~wxMenuItem() wxMenuItem::~wxMenuItem()
@@ -834,7 +834,9 @@ void wxMenuItem::SetText( const wxString& string )
void wxMenuItem::DoSetText( const wxString& str ) void wxMenuItem::DoSetText( const wxString& str )
{ {
// '\t' is the deliminator indicating a hot key // '\t' is the deliminator indicating a hot key
m_text.Empty(); wxString text;
text.reserve(str.length());
const wxChar *pc = str; const wxChar *pc = str;
while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) ) while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) )
{ {
@@ -842,30 +844,32 @@ void wxMenuItem::DoSetText( const wxString& str )
{ {
// "&" is doubled to indicate "&" instead of accelerator // "&" is doubled to indicate "&" instead of accelerator
++pc; ++pc;
m_text << wxT('&'); text << wxT('&');
} }
else if (*pc == wxT('&')) else if (*pc == wxT('&'))
{ {
m_text << wxT('_'); text << wxT('_');
} }
else if ( *pc == wxT('_') ) // escape underscores else if ( *pc == wxT('_') ) // escape underscores
{ {
m_text << wxT("__"); text << wxT("__");
} }
else else
{ {
m_text << *pc; text << *pc;
} }
++pc; ++pc;
} }
m_hotKey = wxEmptyString; m_hotKey = wxEmptyString;
if(*pc == wxT('\t')) if ( *pc == wxT('\t') )
{ {
pc++; pc++;
m_hotKey = pc; m_hotKey = pc;
} }
m_text = text;
} }
#if wxUSE_ACCEL #if wxUSE_ACCEL