Commited FRM's stockitem patch (empty stock items).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40978 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-09-03 12:23:04 +00:00
parent eae0338fcb
commit ee0a94cfc2
24 changed files with 534 additions and 207 deletions

View File

@@ -127,7 +127,7 @@ and recreation of internal data structures.
\membersection{wxMenu::Append}\label{wxmenuappend} \membersection{wxMenu::Append}\label{wxmenuappend}
\func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp \func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item = ""}, \param{const wxString\& }{helpString = ""},\rtfsp
\param{wxItemKind}{ kind = wxITEM\_NORMAL}} \param{wxItemKind}{ kind = wxITEM\_NORMAL}}
Adds a string item to the end of the menu. Adds a string item to the end of the menu.
@@ -475,7 +475,7 @@ menubar.
\func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}} \func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}}
\func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp \func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp \param{const wxString\& }{ item = ""}, \param{const wxString\& }{helpString = ""},\rtfsp
\param{wxItemKind}{ kind = wxITEM\_NORMAL}} \param{wxItemKind}{ kind = wxITEM\_NORMAL}}
Inserts the given {\it item} before the position {\it pos}. Inserting the item Inserts the given {\it item} before the position {\it pos}. Inserting the item
@@ -569,7 +569,7 @@ true if the menu item is enabled, false otherwise.
\func{wxMenuItem*}{Prepend}{\param{wxMenuItem *}{item}} \func{wxMenuItem*}{Prepend}{\param{wxMenuItem *}{item}}
\func{wxMenuItem*}{Prepend}{\param{int}{ id},\rtfsp \func{wxMenuItem*}{Prepend}{\param{int}{ id},\rtfsp
\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp \param{const wxString\& }{ item = ""}, \param{const wxString\& }{helpString = ""},\rtfsp
\param{wxItemKind}{ kind = wxITEM\_NORMAL}} \param{wxItemKind}{ kind = wxITEM\_NORMAL}}
Inserts the given {\it item} at position $0$, i.e. before all the other Inserts the given {\it item} at position $0$, i.e. before all the other

View File

@@ -42,6 +42,12 @@ only implemented for Windows and GTK+.
Constructs a wxMenuItem object. Constructs a wxMenuItem object.
The preferred way to create standard menu items is to use default value of
\arg{text}. If no text is supplied and \arg{id} is one of standard IDs from
\helpref{this list}{stockitems}, a standard label and a standard accelerator
will be used. In addition to that, the button will be decorated with stock
icons under GTK+ 2.
\wxheading{Parameters} \wxheading{Parameters}
\docparam{parentMenu}{Menu that the menu item belongs to.} \docparam{parentMenu}{Menu that the menu item belongs to.}

View File

@@ -47,7 +47,8 @@ own constants in this range.
wxID_HELP_CONTEXT, wxID_HELP_CONTEXT,
wxID_CLOSE_ALL, wxID_CLOSE_ALL,
wxID_CUT = 5030, wxID_EDIT = 5030,
wxID_CUT,
wxID_COPY, wxID_COPY,
wxID_PASTE, wxID_PASTE,
wxID_CLEAR, wxID_CLEAR,
@@ -68,7 +69,8 @@ own constants in this range.
wxID_VIEW_SORTSIZE, wxID_VIEW_SORTSIZE,
wxID_VIEW_SORTTYPE, wxID_VIEW_SORTTYPE,
wxID_FILE1 = 5050, wxID_FILE = 5050,
wxID_FILE1,
wxID_FILE2, wxID_FILE2,
wxID_FILE3, wxID_FILE3,
wxID_FILE4, wxID_FILE4,

View File

@@ -4,6 +4,7 @@ Window IDs for which stock buttons are created
(see \helpref{wxButton constructor}{wxbuttonctor}): (see \helpref{wxButton constructor}{wxbuttonctor}):
\begin{twocollist}\itemsep=0pt \begin{twocollist}\itemsep=0pt
\twocolitem{wxID\_ABOUT}{"\&About"}
\twocolitem{wxID\_ADD}{"Add"} \twocolitem{wxID\_ADD}{"Add"}
\twocolitem{wxID\_APPLY}{"\&Apply"} \twocolitem{wxID\_APPLY}{"\&Apply"}
\twocolitem{wxID\_BOLD}{"\&Bold"} \twocolitem{wxID\_BOLD}{"\&Bold"}
@@ -13,7 +14,9 @@ Window IDs for which stock buttons are created
\twocolitem{wxID\_COPY}{"\&Copy"} \twocolitem{wxID\_COPY}{"\&Copy"}
\twocolitem{wxID\_CUT}{"Cu\&t"} \twocolitem{wxID\_CUT}{"Cu\&t"}
\twocolitem{wxID\_DELETE}{"\&Delete"} \twocolitem{wxID\_DELETE}{"\&Delete"}
\twocolitem{wxID\_EDIT}{"\&Edit"}
\twocolitem{wxID\_FIND}{"\&Find"} \twocolitem{wxID\_FIND}{"\&Find"}
\twocolitem{wxID\_FILE}{"\&File"}
\twocolitem{wxID\_REPLACE}{"Find and rep\&lace"} \twocolitem{wxID\_REPLACE}{"Find and rep\&lace"}
\twocolitem{wxID\_BACKWARD}{"\&Back"} \twocolitem{wxID\_BACKWARD}{"\&Back"}
\twocolitem{wxID\_DOWN}{"\&Down"} \twocolitem{wxID\_DOWN}{"\&Down"}
@@ -44,6 +47,7 @@ Window IDs for which stock buttons are created
\twocolitem{wxID\_REVERT\_TO\_SAVED}{"Revert to Saved"} \twocolitem{wxID\_REVERT\_TO\_SAVED}{"Revert to Saved"}
\twocolitem{wxID\_SAVE}{"\&Save"} \twocolitem{wxID\_SAVE}{"\&Save"}
\twocolitem{wxID\_SAVEAS}{"Save \&As..."} \twocolitem{wxID\_SAVEAS}{"Save \&As..."}
\twocolitem{wxID\_SELECTALL}{"Select all"}
\twocolitem{wxID\_STOP}{"\&Stop"} \twocolitem{wxID\_STOP}{"\&Stop"}
\twocolitem{wxID\_UNDELETE}{"Undelete"} \twocolitem{wxID\_UNDELETE}{"Undelete"}
\twocolitem{wxID\_UNDERLINE}{"\&Underline"} \twocolitem{wxID\_UNDERLINE}{"\&Underline"}

View File

@@ -100,6 +100,26 @@ public:
bool MatchesEvent(const wxKeyEvent& event) const; bool MatchesEvent(const wxKeyEvent& event) const;
#endif #endif
bool IsOk() const
{
return m_flags != 0 &&
m_keyCode != 0;
}
// string <-> wxAcceleratorEntry conversion
// ----------------------------------------
// returns a wxString for the this accelerator.
// this function formats it using the <flags>-<keycode> format
// where <flags> maybe a hyphen-separed list of "shift|alt|ctrl"
wxString ToString() const;
// returns true if the given string correctly initialized this object
// (i.e. if IsOk() returns true after this call)
bool FromString(const wxString &str);
private: private:
int m_flags; // combination of wxACCEL_XXX constants int m_flags; // combination of wxACCEL_XXX constants
int m_keyCode; // ASCII or virtual keycode int m_keyCode; // ASCII or virtual keycode

View File

@@ -1759,7 +1759,8 @@ enum
wxID_CLOSE_ALL, wxID_CLOSE_ALL,
wxID_PREFERENCES, wxID_PREFERENCES,
wxID_CUT = 5030, wxID_EDIT = 5030,
wxID_CUT,
wxID_COPY, wxID_COPY,
wxID_PASTE, wxID_PASTE,
wxID_CLEAR, wxID_CLEAR,
@@ -1780,7 +1781,8 @@ enum
wxID_VIEW_SORTSIZE, wxID_VIEW_SORTSIZE,
wxID_VIEW_SORTTYPE, wxID_VIEW_SORTTYPE,
wxID_FILE1 = 5050, wxID_FILE = 5050,
wxID_FILE1,
wxID_FILE2, wxID_FILE2,
wxID_FILE3, wxID_FILE3,
wxID_FILE4, wxID_FILE4,

View File

@@ -48,6 +48,10 @@ public:
wxString GetHotKey() const { return m_hotKey; } wxString GetHotKey() const { return m_hotKey; }
// splits given string in the label, doing & => _ translation, which is returned,
// and in the hotkey which is used to set given pointer
static wxString GTKProcessMenuItemLabel(const wxString& str, wxString *hotKey);
// compatibility only, don't use in new code // compatibility only, don't use in new code
wxMenuItem(wxMenu *parentMenu, wxMenuItem(wxMenu *parentMenu,
int id, int id,

View File

@@ -60,7 +60,7 @@ public:
// append any kind of item (normal/check/radio/separator) // append any kind of item (normal/check/radio/separator)
wxMenuItem* Append(int itemid, wxMenuItem* Append(int itemid,
const wxString& text, const wxString& text = wxEmptyString,
const wxString& help = wxEmptyString, const wxString& help = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL) wxItemKind kind = wxITEM_NORMAL)
{ {
@@ -108,7 +108,7 @@ public:
// insert an item before given position // insert an item before given position
wxMenuItem* Insert(size_t pos, wxMenuItem* Insert(size_t pos,
int itemid, int itemid,
const wxString& text, const wxString& text = wxEmptyString,
const wxString& help = wxEmptyString, const wxString& help = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL) wxItemKind kind = wxITEM_NORMAL)
{ {
@@ -158,7 +158,7 @@ public:
// prepend any item to the menu // prepend any item to the menu
wxMenuItem* Prepend(int itemid, wxMenuItem* Prepend(int itemid,
const wxString& text, const wxString& text = wxEmptyString,
const wxString& help = wxEmptyString, const wxString& help = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL) wxItemKind kind = wxITEM_NORMAL)
{ {

View File

@@ -15,6 +15,7 @@
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/wxchar.h" #include "wx/wxchar.h"
#include "wx/string.h" #include "wx/string.h"
#include "wx/accel.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Helper functions for stock items handling: // Helper functions for stock items handling:
@@ -27,15 +28,34 @@ WXDLLEXPORT bool wxIsStockID(wxWindowID id);
// given ID // given ID
WXDLLEXPORT bool wxIsStockLabel(wxWindowID id, const wxString& label); WXDLLEXPORT bool wxIsStockLabel(wxWindowID id, const wxString& label);
enum wxStockLabelQueryFlag
{
wxSTOCK_NOFLAGS = 0,
wxSTOCK_WITH_MNEMONIC = 1,
wxSTOCK_WITH_ACCELERATOR = 2
};
// Returns label that should be used for given stock UI element (e.g. "&OK" // Returns label that should be used for given stock UI element (e.g. "&OK"
// for wxSTOCK_OK): // for wxSTOCK_OK); if wxSTOCK_WITH_MNEMONIC is given, the & character
// is included; if wxSTOCK_WITH_ACCELERATOR is given, the stock accelerator
// for given ID is concatenated to the label using \t as separator
WXDLLEXPORT wxString wxGetStockLabel(wxWindowID id, WXDLLEXPORT wxString wxGetStockLabel(wxWindowID id,
bool withCodes = true, long flags = wxSTOCK_WITH_MNEMONIC);
const wxString& accelerator = wxEmptyString);
// Returns the accelerator that should be used for given stock UI element
// (e.g. "Ctrl+x" for wxSTOCK_EXIT)
WXDLLEXPORT wxAcceleratorEntry wxGetStockAccelerator(wxWindowID id);
#ifdef __WXGTK20__ #ifdef __WXGTK20__
#include <gdk/gdktypes.h>
// Translates stock ID to GTK+'s stock item string indentifier: // Translates stock ID to GTK+'s stock item string indentifier:
WXDLLEXPORT const char *wxGetStockGtkID(wxWindowID id); WXDLLEXPORT const char *wxGetStockGtkID(wxWindowID id);
// Returns stock accelerator modifier and key code for the given ID
WXDLLEXPORT bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key);
#endif #endif
#endif // _WX_STOCKITEM_H_ #endif // _WX_STOCKITEM_H_

View File

@@ -567,7 +567,9 @@ wxDEPRECATED(
#if wxUSE_ACCEL #if wxUSE_ACCEL
class WXDLLEXPORT wxAcceleratorEntry; class WXDLLEXPORT wxAcceleratorEntry;
WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label); wxDEPRECATED(
WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
);
#endif // wxUSE_ACCEL #endif // wxUSE_ACCEL
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -360,6 +360,8 @@ bool MyApp::OnInit()
// MyFrame // MyFrame
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <wx/gtk/private.h>
// Define my frame constructor // Define my frame constructor
MyFrame::MyFrame() MyFrame::MyFrame()
: wxFrame((wxFrame *)NULL, wxID_ANY, _T("wxWidgets menu sample")) : wxFrame((wxFrame *)NULL, wxID_ANY, _T("wxWidgets menu sample"))
@@ -379,56 +381,56 @@ MyFrame::MyFrame()
wxMenu *fileMenu = new wxMenu; wxMenu *fileMenu = new wxMenu;
wxMenu *stockSubMenu = new wxMenu; wxMenu *stockSubMenu = new wxMenu;
stockSubMenu->Append(wxID_ADD, "wxID_ADD"); stockSubMenu->Append(wxID_ADD);
stockSubMenu->Append(wxID_APPLY, "wxID_APPLY"); stockSubMenu->Append(wxID_APPLY);
stockSubMenu->Append(wxID_BOLD, "wxID_BOLD"); stockSubMenu->Append(wxID_BOLD);
stockSubMenu->Append(wxID_CANCEL, "wxID_CANCEL"); stockSubMenu->Append(wxID_CANCEL);
stockSubMenu->Append(wxID_CLEAR, "wxID_CLEAR"); stockSubMenu->Append(wxID_CLEAR);
stockSubMenu->Append(wxID_CLOSE, "wxID_CLOSE"); stockSubMenu->Append(wxID_CLOSE);
stockSubMenu->Append(wxID_COPY, "wxID_COPY"); stockSubMenu->Append(wxID_COPY);
stockSubMenu->Append(wxID_CUT, "wxID_CUT"); stockSubMenu->Append(wxID_CUT);
stockSubMenu->Append(wxID_DELETE, "wxID_DELETE"); stockSubMenu->Append(wxID_DELETE);
stockSubMenu->Append(wxID_FIND, "wxID_FIND"); stockSubMenu->Append(wxID_FIND);
stockSubMenu->Append(wxID_REPLACE, "wxID_REPLACE"); stockSubMenu->Append(wxID_REPLACE);
stockSubMenu->Append(wxID_BACKWARD, "wxID_BACKWARD"); stockSubMenu->Append(wxID_BACKWARD);
stockSubMenu->Append(wxID_DOWN, "wxID_DOWN"); stockSubMenu->Append(wxID_DOWN);
stockSubMenu->Append(wxID_FORWARD, "wxID_FORWARD"); stockSubMenu->Append(wxID_FORWARD);
stockSubMenu->Append(wxID_UP, "wxID_UP"); stockSubMenu->Append(wxID_UP);
stockSubMenu->Append(wxID_HELP, "wxID_HELP"); stockSubMenu->Append(wxID_HELP);
stockSubMenu->Append(wxID_HOME, "wxID_HOME"); stockSubMenu->Append(wxID_HOME);
stockSubMenu->Append(wxID_INDENT, "wxID_INDENT"); stockSubMenu->Append(wxID_INDENT);
stockSubMenu->Append(wxID_INDEX, "wxID_INDEX"); stockSubMenu->Append(wxID_INDEX);
stockSubMenu->Append(wxID_ITALIC, "wxID_ITALIC"); stockSubMenu->Append(wxID_ITALIC);
stockSubMenu->Append(wxID_JUSTIFY_CENTER, "wxID_JUSTIFY_CENTER"); stockSubMenu->Append(wxID_JUSTIFY_CENTER);
stockSubMenu->Append(wxID_JUSTIFY_FILL, "wxID_JUSTIFY_FILL"); stockSubMenu->Append(wxID_JUSTIFY_FILL);
stockSubMenu->Append(wxID_JUSTIFY_LEFT, "wxID_JUSTIFY_LEFT"); stockSubMenu->Append(wxID_JUSTIFY_LEFT);
stockSubMenu->Append(wxID_JUSTIFY_RIGHT, "wxID_JUSTIFY_RIGHT"); stockSubMenu->Append(wxID_JUSTIFY_RIGHT);
stockSubMenu->Append(wxID_NEW, "wxID_NEW"); stockSubMenu->Append(wxID_NEW);
stockSubMenu->Append(wxID_NO, "wxID_NO"); stockSubMenu->Append(wxID_NO);
stockSubMenu->Append(wxID_OK, "wxID_OK"); stockSubMenu->Append(wxID_OK);
stockSubMenu->Append(wxID_OPEN, "wxID_OPEN"); stockSubMenu->Append(wxID_OPEN);
stockSubMenu->Append(wxID_PASTE, "wxID_PASTE"); stockSubMenu->Append(wxID_PASTE);
stockSubMenu->Append(wxID_PREFERENCES, "wxID_PREFERENCES"); stockSubMenu->Append(wxID_PREFERENCES);
stockSubMenu->Append(wxID_PRINT, "wxID_PRINT"); stockSubMenu->Append(wxID_PRINT);
stockSubMenu->Append(wxID_PREVIEW, "wxID_PREVIEW"); stockSubMenu->Append(wxID_PREVIEW);
stockSubMenu->Append(wxID_PROPERTIES, "wxID_PROPERTIES"); stockSubMenu->Append(wxID_PROPERTIES);
stockSubMenu->Append(wxID_EXIT, "wxID_EXIT"); stockSubMenu->Append(wxID_EXIT);
stockSubMenu->Append(wxID_REDO, "wxID_REDO"); stockSubMenu->Append(wxID_REDO);
stockSubMenu->Append(wxID_REFRESH, "wxID_REFRESH"); stockSubMenu->Append(wxID_REFRESH);
stockSubMenu->Append(wxID_REMOVE, "wxID_REMOVE"); stockSubMenu->Append(wxID_REMOVE);
stockSubMenu->Append(wxID_REVERT_TO_SAVED, "wxID_REVERT_TO_SAVED"); stockSubMenu->Append(wxID_REVERT_TO_SAVED);
stockSubMenu->Append(wxID_SAVE, "wxID_SAVE"); stockSubMenu->Append(wxID_SAVE);
stockSubMenu->Append(wxID_SAVEAS, "wxID_SAVEAS"); stockSubMenu->Append(wxID_SAVEAS);
stockSubMenu->Append(wxID_STOP, "wxID_STOP"); stockSubMenu->Append(wxID_STOP);
stockSubMenu->Append(wxID_UNDELETE, "wxID_UNDELETE"); stockSubMenu->Append(wxID_UNDELETE);
stockSubMenu->Append(wxID_UNDERLINE, "wxID_UNDERLINE"); stockSubMenu->Append(wxID_UNDERLINE);
stockSubMenu->Append(wxID_UNDO, "wxID_UNDO"); stockSubMenu->Append(wxID_UNDO);
stockSubMenu->Append(wxID_UNINDENT, "wxID_UNINDENT"); stockSubMenu->Append(wxID_UNINDENT);
stockSubMenu->Append(wxID_YES, "wxID_YES"); stockSubMenu->Append(wxID_YES);
stockSubMenu->Append(wxID_ZOOM_100, "wxID_ZOOM_100"); stockSubMenu->Append(wxID_ZOOM_100);
stockSubMenu->Append(wxID_ZOOM_FIT, "wxID_ZOOM_FIT"); stockSubMenu->Append(wxID_ZOOM_FIT);
stockSubMenu->Append(wxID_ZOOM_IN, "wxID_ZOOM_IN"); stockSubMenu->Append(wxID_ZOOM_IN);
stockSubMenu->Append(wxID_ZOOM_OUT, "wxID_ZOOM_OUT"); stockSubMenu->Append(wxID_ZOOM_OUT);
fileMenu->AppendSubMenu(stockSubMenu, _T("&Standard items demo")); fileMenu->AppendSubMenu(stockSubMenu, _T("&Standard items demo"));
#if USE_LOG_WINDOW #if USE_LOG_WINDOW

View File

@@ -283,7 +283,7 @@ void wxTabMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar)
{ {
if (pMenuBar && m_pWindowMenu) if (pMenuBar && m_pWindowMenu)
{ {
int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,false)); int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,wxSTOCK_NOFLAGS));
if (pos == wxNOT_FOUND) if (pos == wxNOT_FOUND)
pMenuBar->Append(m_pWindowMenu, _("&Window")); pMenuBar->Append(m_pWindowMenu, _("&Window"));
else else

View File

@@ -48,36 +48,9 @@ WX_DEFINE_LIST(wxMenuItemList)
// ============================================================================ // ============================================================================
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxMenuItem // wxAcceleratorEntry
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
int id,
const wxString& text,
const wxString& help,
wxItemKind kind,
wxMenu *subMenu)
: m_text(text),
m_help(help)
{
wxASSERT_MSG( parentMenu != NULL, wxT("menuitem should have a menu") );
m_parentMenu = parentMenu;
m_subMenu = subMenu;
m_isEnabled = true;
m_isChecked = false;
m_id = id;
m_kind = kind;
if (m_id == wxID_ANY)
m_id = wxNewId();
if (m_id == wxID_SEPARATOR)
m_kind = wxITEM_SEPARATOR;
}
wxMenuItemBase::~wxMenuItemBase()
{
delete m_subMenu;
}
#if wxUSE_ACCEL #if wxUSE_ACCEL
@@ -197,13 +170,19 @@ IsNumberedAccelKey(const wxString& str,
return prefixCode + num - first; return prefixCode + num - first;
} }
// return wxAcceleratorEntry for the given menu string or NULL if none bool wxAcceleratorEntry::FromString(const wxString& text)
wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
{ {
// the parser won't like leading/trailing spaces
wxString label = text.Strip(wxString::both);
// set to invalid state:
m_flags = 0;
m_keyCode = 0;
// check for accelerators: they are given after '\t' // check for accelerators: they are given after '\t'
int posTab = label.Find(wxT('\t')); int posTab = label.Find(wxT('\t'));
if ( posTab == wxNOT_FOUND ) if ( posTab == wxNOT_FOUND )
return NULL; return false;
// parse the accelerator string // parse the accelerator string
int accelFlags = wxACCEL_NORMAL; int accelFlags = wxACCEL_NORMAL;
@@ -252,7 +231,7 @@ wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
{ {
case 0: case 0:
wxLogDebug(wxT("No accel key found, accel string ignored.")); wxLogDebug(wxT("No accel key found, accel string ignored."));
return NULL; return false;
case 1: case 1:
// it's just a letter // it's just a letter
@@ -292,29 +271,23 @@ wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
{ {
wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."), wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."),
current.c_str()); current.c_str());
return NULL; return false;
} }
} }
wxASSERT_MSG( keyCode, _T("logic error: should have key code here") ); wxASSERT_MSG( keyCode, _T("logic error: should have key code here") );
return new wxAcceleratorEntry(accelFlags, keyCode); m_flags = accelFlags;
m_keyCode = keyCode;
return true;
} }
wxAcceleratorEntry *wxMenuItemBase::GetAccel() const wxString wxAcceleratorEntry::ToString() const
{ {
return wxGetAccelFromString(GetText()); wxString text;
}
void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel) int flags = GetFlags();
{
wxString text = m_text.BeforeFirst(wxT('\t'));
if ( accel )
{
text += wxT('\t');
int flags = accel->GetFlags();
if ( flags & wxACCEL_ALT ) if ( flags & wxACCEL_ALT )
text += _("Alt-"); text += _("Alt-");
if ( flags & wxACCEL_CTRL ) if ( flags & wxACCEL_CTRL )
@@ -322,7 +295,7 @@ void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
if ( flags & wxACCEL_SHIFT ) if ( flags & wxACCEL_SHIFT )
text += _("Shift-"); text += _("Shift-");
const int code = accel->GetKeyCode(); const int code = GetKeyCode();
if ( wxIsalnum(code) ) if ( wxIsalnum(code) )
text << (wxChar)code; text << (wxChar)code;
@@ -348,6 +321,69 @@ void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
wxASSERT_MSG( n != WXSIZEOF(wxKeyNames), wxASSERT_MSG( n != WXSIZEOF(wxKeyNames),
wxT("unknown keyboard accelerator code") ); wxT("unknown keyboard accelerator code") );
} }
return text;
}
wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
{
wxAcceleratorEntry *ret = new wxAcceleratorEntry();
if (ret->FromString(label))
return ret;
wxDELETE(ret);
return NULL;
}
#endif // wxUSE_ACCEL
// ----------------------------------------------------------------------------
// wxMenuItem
// ----------------------------------------------------------------------------
wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
int id,
const wxString& text,
const wxString& help,
wxItemKind kind,
wxMenu *subMenu)
: m_text(text),
m_help(help)
{
wxASSERT_MSG( parentMenu != NULL, wxT("menuitem should have a menu") );
m_parentMenu = parentMenu;
m_subMenu = subMenu;
m_isEnabled = true;
m_isChecked = false;
m_id = id;
m_kind = kind;
if (m_id == wxID_ANY)
m_id = wxNewId();
if (m_id == wxID_SEPARATOR)
m_kind = wxITEM_SEPARATOR;
}
wxMenuItemBase::~wxMenuItemBase()
{
delete m_subMenu;
}
#if wxUSE_ACCEL
wxAcceleratorEntry *wxMenuItemBase::GetAccel() const
{
return wxGetAccelFromString(GetText());
}
void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
{
wxString text = m_text.BeforeFirst(wxT('\t'));
if ( accel )
{
text += wxT('\t');
text += accel->ToString();
} }
SetText(text); SetText(text);

View File

@@ -35,6 +35,7 @@ bool wxIsStockID(wxWindowID id)
{ {
switch (id) switch (id)
{ {
case wxID_ABOUT:
case wxID_ADD: case wxID_ADD:
case wxID_APPLY: case wxID_APPLY:
case wxID_BOLD: case wxID_BOLD:
@@ -44,7 +45,9 @@ bool wxIsStockID(wxWindowID id)
case wxID_COPY: case wxID_COPY:
case wxID_CUT: case wxID_CUT:
case wxID_DELETE: case wxID_DELETE:
case wxID_EDIT:
case wxID_FIND: case wxID_FIND:
case wxID_FILE:
case wxID_REPLACE: case wxID_REPLACE:
case wxID_BACKWARD: case wxID_BACKWARD:
case wxID_DOWN: case wxID_DOWN:
@@ -75,6 +78,7 @@ bool wxIsStockID(wxWindowID id)
case wxID_REVERT_TO_SAVED: case wxID_REVERT_TO_SAVED:
case wxID_SAVE: case wxID_SAVE:
case wxID_SAVEAS: case wxID_SAVEAS:
case wxID_SELECTALL:
case wxID_STOP: case wxID_STOP:
case wxID_UNDELETE: case wxID_UNDELETE:
case wxID_UNDERLINE: case wxID_UNDERLINE:
@@ -92,7 +96,7 @@ bool wxIsStockID(wxWindowID id)
} }
} }
wxString wxGetStockLabel(wxWindowID id, bool withCodes, const wxString& accelerator) wxString wxGetStockLabel(wxWindowID id, long flags)
{ {
wxString stockLabel; wxString stockLabel;
@@ -103,6 +107,7 @@ wxString wxGetStockLabel(wxWindowID id, bool withCodes, const wxString& accelera
switch (id) switch (id)
{ {
STOCKITEM(wxID_ABOUT, _("&About"))
STOCKITEM(wxID_ADD, _("Add")) STOCKITEM(wxID_ADD, _("Add"))
STOCKITEM(wxID_APPLY, _("&Apply")) STOCKITEM(wxID_APPLY, _("&Apply"))
STOCKITEM(wxID_BOLD, _("&Bold")) STOCKITEM(wxID_BOLD, _("&Bold"))
@@ -112,7 +117,9 @@ wxString wxGetStockLabel(wxWindowID id, bool withCodes, const wxString& accelera
STOCKITEM(wxID_COPY, _("&Copy")) STOCKITEM(wxID_COPY, _("&Copy"))
STOCKITEM(wxID_CUT, _("Cu&t")) STOCKITEM(wxID_CUT, _("Cu&t"))
STOCKITEM(wxID_DELETE, _("&Delete")) STOCKITEM(wxID_DELETE, _("&Delete"))
STOCKITEM(wxID_EDIT, _("&Edit"))
STOCKITEM(wxID_FIND, _("&Find")) STOCKITEM(wxID_FIND, _("&Find"))
STOCKITEM(wxID_FILE, _("&File"))
STOCKITEM(wxID_REPLACE, _("Rep&lace")) STOCKITEM(wxID_REPLACE, _("Rep&lace"))
STOCKITEM(wxID_BACKWARD, _("&Back")) STOCKITEM(wxID_BACKWARD, _("&Back"))
STOCKITEM(wxID_DOWN, _("&Down")) STOCKITEM(wxID_DOWN, _("&Down"))
@@ -143,6 +150,7 @@ wxString wxGetStockLabel(wxWindowID id, bool withCodes, const wxString& accelera
STOCKITEM(wxID_REVERT_TO_SAVED, _("Revert to Saved")) STOCKITEM(wxID_REVERT_TO_SAVED, _("Revert to Saved"))
STOCKITEM(wxID_SAVE, _("&Save")) STOCKITEM(wxID_SAVE, _("&Save"))
STOCKITEM(wxID_SAVEAS, _("Save &As...")) STOCKITEM(wxID_SAVEAS, _("Save &As..."))
STOCKITEM(wxID_SELECTALL, _("Select all"))
STOCKITEM(wxID_STOP, _("&Stop")) STOCKITEM(wxID_STOP, _("&Stop"))
STOCKITEM(wxID_UNDELETE, _("Undelete")) STOCKITEM(wxID_UNDELETE, _("Undelete"))
STOCKITEM(wxID_UNDERLINE, _("&Underline")) STOCKITEM(wxID_UNDERLINE, _("&Underline"))
@@ -161,19 +169,57 @@ wxString wxGetStockLabel(wxWindowID id, bool withCodes, const wxString& accelera
#undef STOCKITEM #undef STOCKITEM
if(!withCodes) if(flags & wxSTOCK_WITH_MNEMONIC)
{ {
stockLabel = wxStripMenuCodes( stockLabel ); stockLabel = wxStripMenuCodes( stockLabel );
} }
else if (!stockLabel.empty() && !accelerator.empty())
if (!stockLabel.empty() && (flags & wxSTOCK_WITH_ACCELERATOR))
{ {
stockLabel += _T("\t"); stockLabel += _T("\t");
stockLabel += accelerator;
wxAcceleratorEntry accel = wxGetStockAccelerator(id);
if (accel.IsOk())
stockLabel += accel.ToString();
} }
return stockLabel; return stockLabel;
} }
wxAcceleratorEntry wxGetStockAccelerator(wxWindowID id)
{
wxAcceleratorEntry ret;
#define STOCKITEM(stockid, flags, keycode) \
case stockid: \
ret.Set(flags, keycode, stockid); \
break;
switch (id)
{
STOCKITEM(wxID_COPY, wxACCEL_CTRL,'C')
STOCKITEM(wxID_CUT, wxACCEL_CTRL,'X')
STOCKITEM(wxID_FIND, wxACCEL_CTRL,'F')
STOCKITEM(wxID_REPLACE, wxACCEL_CTRL,'R')
STOCKITEM(wxID_HELP, wxACCEL_CTRL,'H')
STOCKITEM(wxID_NEW, wxACCEL_CTRL,'N')
STOCKITEM(wxID_OPEN, wxACCEL_CTRL,'O')
STOCKITEM(wxID_PASTE, wxACCEL_CTRL,'V')
STOCKITEM(wxID_SAVE, wxACCEL_CTRL,'S')
default:
// set the wxAcceleratorEntry to return into an invalid state:
// there's no stock accelerator for that.
ret.Set(0, 0, id);
break;
};
#undef STOCKITEM
// always use wxAcceleratorEntry::IsOk on returned value !
return ret;
}
bool wxIsStockLabel(wxWindowID id, const wxString& label) bool wxIsStockLabel(wxWindowID id, const wxString& label)
{ {
if (label.empty()) if (label.empty())
@@ -212,8 +258,22 @@ const char *wxGetStockGtkID(wxWindowID id)
#define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx) #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
#endif #endif
#if GTK_CHECK_VERSION(2,6,0)
#define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
#else
#define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
#endif
#if GTK_CHECK_VERSION(2,10,0)
#define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
#else
#define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
#endif
switch (id) switch (id)
{ {
STOCKITEM_26(wxID_ABOUT, GTK_STOCK_ABOUT)
STOCKITEM(wxID_ADD, GTK_STOCK_ADD) STOCKITEM(wxID_ADD, GTK_STOCK_ADD)
STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY) STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY)
STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD) STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD)
@@ -223,7 +283,9 @@ const char *wxGetStockGtkID(wxWindowID id)
STOCKITEM(wxID_COPY, GTK_STOCK_COPY) STOCKITEM(wxID_COPY, GTK_STOCK_COPY)
STOCKITEM(wxID_CUT, GTK_STOCK_CUT) STOCKITEM(wxID_CUT, GTK_STOCK_CUT)
STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE) STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE)
STOCKITEM_26(wxID_EDIT, GTK_STOCK_EDIT)
STOCKITEM(wxID_FIND, GTK_STOCK_FIND) STOCKITEM(wxID_FIND, GTK_STOCK_FIND)
STOCKITEM_26(wxID_FILE, GTK_STOCK_FILE)
STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE) STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE)
STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK) STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK)
STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN) STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN)
@@ -254,6 +316,7 @@ const char *wxGetStockGtkID(wxWindowID id)
STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED) STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED)
STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE) STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE)
STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS) STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS)
STOCKITEM_210(wxID_SELECTALL, GTK_STOCK_SELECT_ALL)
STOCKITEM(wxID_STOP, GTK_STOCK_STOP) STOCKITEM(wxID_STOP, GTK_STOCK_STOP)
STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE) STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE)
STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE) STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE)
@@ -275,4 +338,21 @@ const char *wxGetStockGtkID(wxWindowID id)
return NULL; return NULL;
} }
bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key)
{
GtkStockItem stock_item;
if (gtk_stock_lookup (id, &stock_item))
{
if (key) *key = stock_item.keyval;
if (mod) *mod = stock_item.modifier;
// some GTK stock items have zero values for the keyval;
// it means that they do not have an accelerator...
if (stock_item.keyval)
return true;
}
return false;
}
#endif // __WXGTK20__ #endif // __WXGTK20__

View File

@@ -733,6 +733,12 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
void wxMenuItem::SetText( const wxString& str ) void wxMenuItem::SetText( const wxString& str )
{ {
// cache some data which must be used later
bool isstock = wxIsStockID(GetId());
const char *stockid = NULL;
if (isstock)
stockid = wxGetStockGtkID(GetId());
// Some optimization to avoid flicker // Some optimization to avoid flicker
wxString oldLabel = m_text; wxString oldLabel = m_text;
oldLabel = wxStripMenuCodes(oldLabel); oldLabel = wxStripMenuCodes(oldLabel);
@@ -755,11 +761,25 @@ void wxMenuItem::SetText( const wxString& str )
else else
label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(m_text) ); // stock menu items can have empty labels:
wxString text = m_text;
if (text.IsEmpty() && !IsSeparator())
{
wxASSERT_MSG(isstock, wxT("A non-stock menu item with an empty label?"));
text = wxGetStockLabel(GetId());
// need & => _ conversion
text = GTKProcessMenuItemLabel(text, NULL);
} }
gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(text) );
}
// remove old accelerator from our parent's accelerator group, if present
guint accel_key; guint accel_key;
GdkModifierType accel_mods; GdkModifierType accel_mods;
if (oldbuf[(size_t)0] != '\0')
{
gtk_accelerator_parse( (const char*) oldbuf, &accel_key, &accel_mods); gtk_accelerator_parse( (const char*) oldbuf, &accel_key, &accel_mods);
if (accel_key != 0) if (accel_key != 0)
{ {
@@ -768,8 +788,21 @@ void wxMenuItem::SetText( const wxString& str )
accel_key, accel_key,
accel_mods ); accel_mods );
} }
}
else if (isstock)
{
// if the accelerator was taken from a stock ID, just get it back from GTK+ stock
if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem),
m_parentMenu->m_accel,
accel_key,
accel_mods );
}
// add new accelerator to our parent's accelerator group
wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) ); wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );
if (buf[(size_t)0] != '\0')
{
gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods); gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
if (accel_key != 0) if (accel_key != 0)
{ {
@@ -781,12 +814,25 @@ void wxMenuItem::SetText( const wxString& str )
GTK_ACCEL_VISIBLE); GTK_ACCEL_VISIBLE);
} }
} }
else if (isstock)
// it's valid for this function to be called even if m_menuItem == NULL
void wxMenuItem::DoSetText( const wxString& str )
{ {
// if the accelerator was taken from a stock ID, just get it back from GTK+ stock
if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem),
m_parentMenu->m_accel,
accel_key,
accel_mods );
}
}
// NOTE: this function is different from the similar functions GTKProcessMnemonics()
// implemented in control.cpp and from wxMenuItemBase::GetLabelFromText...
// so there's no real code duplication
wxString wxMenuItem::GTKProcessMenuItemLabel(const wxString& str, wxString *hotKey)
{
wxString text;
// '\t' is the deliminator indicating a hot key // '\t' is the deliminator indicating a hot key
m_text.Empty();
const wxChar *pc = str; const wxChar *pc = str;
while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) ) while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) )
{ {
@@ -794,31 +840,41 @@ 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 = wxT(""); if (hotKey)
{
hotKey->Empty();
if(*pc == wxT('\t')) if(*pc == wxT('\t'))
{ {
pc++; pc++;
m_hotKey = pc; *hotKey = pc;
}
} }
return text;
}
// it's valid for this function to be called even if m_menuItem == NULL
void wxMenuItem::DoSetText( const wxString& str )
{
m_text.Empty();
m_text = GTKProcessMenuItemLabel(str, &m_hotKey);
// wxPrintf( wxT("DoSetText(): str %s m_text %s hotkey %s\n"), str.c_str(), m_text.c_str(), m_hotKey.c_str() ); // wxPrintf( wxT("DoSetText(): str %s m_text %s hotkey %s\n"), str.c_str(), m_text.c_str(), m_hotKey.c_str() );
} }
@@ -935,17 +991,31 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
{ {
GtkWidget *menuItem; GtkWidget *menuItem;
wxString text; // cache some data used later
wxString text = mitem->GetText();
int id = mitem->GetId();
bool isstock = wxIsStockID(id);
const char *stockid = NULL;
if (isstock)
stockid = wxGetStockGtkID(mitem->GetId());
// stock menu items can have an empty label
if (text.IsEmpty() && !mitem->IsSeparator())
{
wxASSERT_MSG(isstock, wxT("A non-stock menu item with an empty label?"));
text = wxGetStockLabel(id);
// need & => _ conversion
text = wxMenuItem::GTKProcessMenuItemLabel(text, NULL);
}
if ( mitem->IsSeparator() ) if ( mitem->IsSeparator() )
{ {
menuItem = gtk_separator_menu_item_new(); menuItem = gtk_separator_menu_item_new();
} }
else if ( mitem->GetBitmap().Ok() || else if ( mitem->GetBitmap().Ok() ||
(mitem->GetKind() == wxITEM_NORMAL && (mitem->GetKind() == wxITEM_NORMAL && isstock) )
wxIsStockID(mitem->GetId())) )
{ {
text = mitem->GetText();
wxBitmap bitmap(mitem->GetBitmap()); wxBitmap bitmap(mitem->GetBitmap());
menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) ); menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
@@ -955,8 +1025,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
{ {
// use stock bitmap for this item if available on the assumption // use stock bitmap for this item if available on the assumption
// that it never hurts to follow GTK+ conventions more closely // that it never hurts to follow GTK+ conventions more closely
const char *stock = wxGetStockGtkID(mitem->GetId()); image = stockid ? gtk_image_new_from_stock(stockid, GTK_ICON_SIZE_MENU)
image = stock ? gtk_image_new_from_stock(stock, GTK_ICON_SIZE_MENU)
: NULL; : NULL;
} }
else // we have a custom bitmap else // we have a custom bitmap
@@ -989,8 +1058,8 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
} }
else // a normal item else // a normal item
{ {
// text has "_" instead of "&" after mitem->SetText() so don't use it // NB: 'text' variable has "_" instead of "&" after mitem->SetText()
text = mitem->GetText() ; // so don't use it
switch ( mitem->GetKind() ) switch ( mitem->GetKind() )
{ {
@@ -1038,6 +1107,8 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) ); wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) );
// wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() ); // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
if (buf[(size_t)0] != '\0')
{
gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods); gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
if (accel_key != 0) if (accel_key != 0)
{ {
@@ -1048,6 +1119,18 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
accel_mods, accel_mods,
GTK_ACCEL_VISIBLE); GTK_ACCEL_VISIBLE);
} }
}
else if (isstock)
{
// if the accelerator was taken from a stock ID, just get it back from GTK+ stock
if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
gtk_widget_add_accelerator( GTK_WIDGET(menuItem),
"activate",
m_accel,
accel_key,
accel_mods,
GTK_ACCEL_VISIBLE);
}
if (pos == -1) if (pos == -1)
gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);

View File

@@ -11,6 +11,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/intl.h" #include "wx/intl.h"
@@ -765,8 +766,15 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
return label; return label;
} }
void wxMenuItem::SetText( const wxString& str ) void wxMenuItem::SetText( const wxString& string )
{ {
wxString str = string;
if (str.IsEmpty())
{
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 // Some optimization to avoid flicker
wxString oldLabel = m_text; wxString oldLabel = m_text;
oldLabel = wxStripMenuCodes(oldLabel); oldLabel = wxStripMenuCodes(oldLabel);

View File

@@ -12,6 +12,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/menuitem.h" #include "wx/menuitem.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/app.h" #include "wx/app.h"
@@ -136,8 +137,15 @@ void wxMenuItem::UpdateItemText()
if (mhandle == NULL || index == 0) if (mhandle == NULL || index == 0)
return ; return ;
UMASetMenuItemText( mhandle , index , wxStripMenuCodes(m_text) , wxFont::GetDefaultEncoding() ) ; wxString text = m_text;
wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ; if (text.IsEmpty() && !IsSeparator())
{
wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?"));
text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC);
}
UMASetMenuItemText( mhandle , index , wxStripMenuCodes(text) , wxFont::GetDefaultEncoding() ) ;
wxAcceleratorEntry *entry = wxGetAccelFromString( text ) ;
UMASetMenuItemShortcut( mhandle , index , entry ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ;
delete entry ; delete entry ;
} }

View File

@@ -16,6 +16,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/menuitem.h" #include "wx/menuitem.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/app.h" #include "wx/app.h"
@@ -150,8 +151,15 @@ void wxMenuItem::UpdateItemText()
if( mhandle == NULL || index == 0) if( mhandle == NULL || index == 0)
return ; return ;
UMASetMenuItemText( mhandle , index , m_text , wxFont::GetDefaultEncoding() ) ; wxString text = m_text;
wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ; if (text.IsEmpty() && !IsSeparator())
{
wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?"));
text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC);
}
UMASetMenuItemText( mhandle , index , text , wxFont::GetDefaultEncoding() ) ;
wxAcceleratorEntry *entry = wxGetAccelFromString( text ) ;
UMASetMenuItemShortcut( mhandle , index , entry ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ;
delete entry ; delete entry ;
} }

View File

@@ -21,6 +21,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/menuitem.h" #include "wx/menuitem.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/utils.h" #include "wx/utils.h"
@@ -172,9 +173,17 @@ void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar,
(wxStripMenuCodes(m_text), (wxStripMenuCodes(m_text),
xmLabelGadgetClass, (Widget) menu, NULL); xmLabelGadgetClass, (Widget) menu, NULL);
} }
else if (!m_text.empty() && !m_subMenu) else if (!IsSeparator() && !m_subMenu)
{ {
wxString strName = wxStripMenuCodes(m_text); wxString txt = m_text;
if (m_text.IsEmpty())
{
wxASSERT_MSG(wxIsStockId(GetId()), wxT("A non-stock menu item with an empty label?"));
txt = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC);
}
wxString strName = wxStripMenuCodes(txt);
if (IsCheckable()) if (IsCheckable())
{ {
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName, m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
@@ -230,7 +239,7 @@ void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar,
(XtCallbackProc) wxMenuItemDisarmCallback, (XtCallbackProc) wxMenuItemDisarmCallback,
(XtPointer) this); (XtPointer) this);
} }
else if (GetId() == wxID_SEPARATOR) else if (IsSeparator())
{ {
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget ("separator", m_buttonWidget = (WXWidget) XtVaCreateManagedWidget ("separator",
xmSeparatorGadgetClass, (Widget) menu, xmSeparatorGadgetClass, (Widget) menu,

View File

@@ -27,6 +27,7 @@
#if wxUSE_MENUS #if wxUSE_MENUS
#include "wx/menuitem.h" #include "wx/menuitem.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/font.h" #include "wx/font.h"
@@ -153,6 +154,12 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
void wxMenuItem::Init() void wxMenuItem::Init()
{ {
if (m_text.IsEmpty())
{
wxASSERT_MSG(wxIsStockId(GetId()), wxT("A non-stock menu item with an empty label?"));
m_text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC);
}
m_radioGroup.start = -1; m_radioGroup.start = -1;
m_isRadioGroupStart = false; m_isRadioGroupStart = false;
@@ -336,12 +343,20 @@ void wxMenuItem::Check(bool check)
wxMenuItemBase::Check(check); wxMenuItemBase::Check(check);
} }
void wxMenuItem::SetText(const wxString& text) void wxMenuItem::SetText(const wxString& txt)
{ {
wxString text = txt;
// don't do anything if label didn't change // don't do anything if label didn't change
if ( m_text == text ) if ( m_text == txt )
return; return;
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);
}
wxMenuItemBase::SetText(text); wxMenuItemBase::SetText(text);
OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) ); OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
#if wxUSE_OWNER_DRAWN #if wxUSE_OWNER_DRAWN

View File

@@ -78,7 +78,7 @@ void wxTopLevelWindowMSW::ButtonMenu::SetButton(int id, const wxString& label, w
m_assigned = true; m_assigned = true;
m_id = id; m_id = id;
if(label.empty() && wxIsStockID(id)) if(label.empty() && wxIsStockID(id))
m_label = wxGetStockLabel(id, false); m_label = wxGetStockLabel(id, wxSTOCK_NOFLAGS);
else else
m_label = label; m_label = label;
m_menu = subMenu; m_menu = subMenu;

View File

@@ -17,6 +17,7 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/menuitem.h" #include "wx/menuitem.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/font.h" #include "wx/font.h"
@@ -372,9 +373,18 @@ void wxMenuItem::SetText( const wxString& rText )
if (m_text == sText) if (m_text == sText)
return; return;
if (sText.IsEmpty())
{
wxASSERT_MSG(wxIsStockId(GetId()), wxT("A non-stock menu item with an empty label?"));
sText = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC);
}
wxMenuItemBase::SetText(sText); wxMenuItemBase::SetText(sText);
OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(sText)); OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(sText));
#if wxUSE_OWNER_DRAWN #if wxUSE_OWNER_DRAWN
if (rText.IsEmpty())
SetAccelString(sText.AfterFirst(_T('\t')));
else
SetAccelString(rText.AfterFirst(_T('\t'))); SetAccelString(rText.AfterFirst(_T('\t')));
#endif // wxUSE_OWNER_DRAWN #endif // wxUSE_OWNER_DRAWN

View File

@@ -169,7 +169,7 @@ bool wxButton::Create(wxWindow *parent,
// take the stock label // take the stock label
wxString palmLabel = label; wxString palmLabel = label;
if( palmLabel.empty() && wxIsStockID(id) ) if( palmLabel.empty() && wxIsStockID(id) )
palmLabel = wxGetStockLabel(id, false); palmLabel = wxGetStockLabel(id, wxSTOCK_NOFLAGS);
if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name)) if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
return false; return false;

View File

@@ -26,6 +26,7 @@
#if wxUSE_MENUS #if wxUSE_MENUS
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/stockitem.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/dynarray.h" #include "wx/dynarray.h"
@@ -1537,10 +1538,17 @@ void wxMenuItem::UpdateAccelInfo()
m_strAccel = m_text.AfterFirst(_T('\t')); m_strAccel = m_text.AfterFirst(_T('\t'));
} }
void wxMenuItem::SetText(const wxString& text) void wxMenuItem::SetText(const wxString& txt)
{ {
if ( text != m_text ) if ( txt != 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 // first call the base class version to change m_text
wxMenuItemBase::SetText(text); wxMenuItemBase::SetText(text);