#if wxUSE_MENUS
+#include "wx/menu.h"
+#include "wx/stockitem.h"
+
#ifndef WX_PRECOMP
#include "wx/dynarray.h"
#include "wx/control.h" // for FindAccelIndex()
- #include "wx/menu.h"
#include "wx/settings.h"
#include "wx/accel.h"
#include "wx/log.h"
+ #include "wx/frame.h"
+ #include "wx/dcclient.h"
#endif // WX_PRECOMP
#include "wx/popupwin.h"
#include "wx/evtloop.h"
-#include "wx/dcclient.h"
-#include "wx/frame.h"
#include "wx/univ/renderer.h"
void SetLabel(const wxString& text)
{
+ m_originalLabel = text;
+
// remember the accel char (may be -1 if none)
m_indexAccel = wxControl::FindAccelIndex(text, &m_label);
// 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
{
}
wxString m_label;
+ wxString m_originalLabel;
wxCoord m_width;
int m_indexAccel;
bool m_isEnabled;
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);
void wxPopupMenuWindow::ChangeCurrent(wxMenuItemIter node)
{
- if ( node != m_nodeCurrent )
+ if ( !m_nodeCurrent || !node || (node != m_nodeCurrent) )
{
wxMenuItemIter nodeOldCurrent = m_nodeCurrent;
{
// return the last node if there had been no previously selected one
return m_nodeCurrent ? GetPrevNode(m_nodeCurrent)
- : m_menu->GetMenuItems().GetLast();
+ : wxMenuItemIter(m_menu->GetMenuItems().GetLast());
}
wxMenuItemIter
{
// return the first node if there had been no previously selected one
return m_nodeCurrent ? GetNextNode(m_nodeCurrent)
- : m_menu->GetMenuItems().GetFirst();
+ : wxMenuItemIter(m_menu->GetMenuItems().GetFirst());
}
wxMenuItemIter
dc,
y,
gi,
- item->GetLabel(),
+ item->GetItemLabelText(),
item->GetAccelString(),
bmp,
flags,
// the window (see below)
if ( node )
{
- if ( node != m_nodeCurrent )
+ if ( !m_nodeCurrent || (node != m_nodeCurrent) )
{
ChangeCurrent(node);
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
return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
-/* static */
-wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
-{
- return wxStripMenuCodes(text);
-}
-
// ----------------------------------------------------------------------------
// wxMenuItem operations
// ----------------------------------------------------------------------------
m_strAccel = m_text.AfterFirst(_T('\t'));
}
-void wxMenuItem::SetText(const wxString& text)
+void wxMenuItem::SetItemLabel(const wxString& text)
{
if ( text != m_text )
{
// 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();
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);
//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();
}
// ----------------------------------------------------------------------------
{
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);
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 )