X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ee0a94cfc2f71e8b770eedda5197a1f4bd62b5cb..8f884a0dccd6b642f35c441ac9bfc87a6d5b4d35:/src/univ/menu.cpp diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index c3170fa2d9..ac4d815131 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -67,6 +67,8 @@ public: void SetLabel(const wxString& text) { + m_originalLabel = text; + // remember the accel char (may be -1 if none) m_indexAccel = wxControl::FindAccelIndex(text, &m_label); @@ -79,6 +81,7 @@ public: // accessors const wxString& GetLabel() const { return m_label; } + const wxString& GetOriginalLabel() const { return m_originalLabel; } bool IsEnabled() const { return m_isEnabled; } wxCoord GetWidth(wxMenuBar *menubar) const { @@ -105,6 +108,7 @@ private: } wxString m_label; + wxString m_originalLabel; wxCoord m_width; int m_indexAccel; bool m_isEnabled; @@ -123,7 +127,7 @@ class wxPopupMenuWindow : public wxPopupTransientWindow public: wxPopupMenuWindow(wxWindow *parent, wxMenu *menu); - ~wxPopupMenuWindow(); + virtual ~wxPopupMenuWindow(); // override the base class version to select the first item initially virtual void Popup(wxWindow *focus = NULL); @@ -347,7 +351,7 @@ void wxPopupMenuWindow::SetCurrentItem(wxMenuItemIter node) void wxPopupMenuWindow::ChangeCurrent(wxMenuItemIter node) { - if ( !m_nodeCurrent || (node != m_nodeCurrent) ) + if ( !m_nodeCurrent || !node || (node != m_nodeCurrent) ) { wxMenuItemIter nodeOldCurrent = m_nodeCurrent; @@ -615,7 +619,7 @@ void wxPopupMenuWindow::DoDraw(wxControlRenderer *renderer) dc, y, gi, - item->GetLabel(), + item->GetItemLabelText(), item->GetAccelString(), bmp, flags, @@ -988,7 +992,7 @@ bool wxPopupMenuWindow::ProcessKeyDown(int key) int idxAccel = item->GetAccelIndex(); if ( idxAccel != -1 && - wxTolower(item->GetLabel()[(size_t)idxAccel]) + (wxChar)wxTolower(item->GetItemLabelText()[(size_t)idxAccel]) == chAccel ) { // ok, found an item with this accel @@ -1516,7 +1520,7 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, } /* static */ -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +wxString wxMenuItemBase::GetLabelText(const wxString& text) { return wxStripMenuCodes(text); } @@ -1538,19 +1542,13 @@ void wxMenuItem::UpdateAccelInfo() m_strAccel = m_text.AfterFirst(_T('\t')); } -void wxMenuItem::SetText(const wxString& txt) +void wxMenuItem::SetItemLabel(const wxString& text) { - if ( txt != m_text ) + if ( text != m_text ) { - wxString text = txt; - if (text.IsEmpty()) - { - wxASSERT_MSG(wxIsStockId(GetId()), wxT("A non-stock menu item with an empty label?")); - text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); - } - // first call the base class version to change m_text - wxMenuItemBase::SetText(text); + // (and also check if we don't have a stock menu item) + wxMenuItemBase::SetItemLabel(text); UpdateAccelInfo(); @@ -1826,11 +1824,11 @@ bool wxMenuBar::IsEnabledTop(size_t pos) const return m_menuInfos[pos].IsEnabled(); } -void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) +void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label) { - wxCHECK_RET( pos < GetCount(), _T("invalid index in EnableTop") ); + wxCHECK_RET( pos < GetCount(), _T("invalid index in SetMenuLabel") ); - if ( label != m_menuInfos[pos].GetLabel() ) + if ( label != m_menuInfos[pos].GetOriginalLabel() ) { m_menuInfos[pos].SetLabel(label); @@ -1839,11 +1837,11 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) //else: nothing to do } -wxString wxMenuBar::GetLabelTop(size_t pos) const +wxString wxMenuBar::GetMenuLabel(size_t pos) const { - wxCHECK_MSG( pos < GetCount(), wxEmptyString, _T("invalid index in GetLabelTop") ); + wxCHECK_MSG( pos < GetCount(), wxEmptyString, _T("invalid index in GetMenuLabel") ); - return m_menuInfos[pos].GetLabel(); + return m_menuInfos[pos].GetOriginalLabel(); } // ---------------------------------------------------------------------------- @@ -1966,7 +1964,7 @@ wxSize wxMenuBar::DoGetBestClientSize() const { wxClientDC dc(wxConstCast(this, wxMenuBar)); dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - dc.GetTextExtent(GetLabelTop(0), &size.x, &size.y); + dc.GetTextExtent(GetMenuLabel(0), &size.x, &size.y); // adjust for the renderer we use size = GetRenderer()->GetMenuBarItemSize(size); @@ -2336,8 +2334,7 @@ int wxMenuBar::FindNextItemForAccel(int idxStart, int key, bool *unique) const int idxAccel = info.GetAccelIndex(); if ( idxAccel != -1 && - wxTolower(info.GetLabel()[(size_t)idxAccel]) - == chAccel ) + (wxChar)wxTolower(info.GetLabel()[(size_t)idxAccel]) == chAccel ) { // ok, found an item with this accel if ( idxFound == -1 )