event.h WXH Base
expr.h WXH
fdrepdlg.h WXH
+features.h WXH Base
ffile.h WXH Base
file.h WXH Base
fileconf.h WXH Base
All (GUI):
+- implemented radio menu items
- significantly improved native font support
- wxImage::ComputeHistogram() now uses wxImageHistogram instead of type-unsafe
wxHashTable
\membersection{wxMenu::Append}\label{wxmenuappend}
\func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
-\param{const bool}{ checkable = FALSE}}
+\param{wxItemKind}{ kind = wxItem\_Normal}}
Adds a string item to the end of the menu.
\docparam{menu}{Pull-right submenu.}
-\docparam{checkable}{If TRUE, this item is checkable.}
+\docparam{kind}{May be {\tt wxItem\_Separator}, {\tt wxItem\_Normal},
+{\tt wxItem\_Check} or {\tt wxItem\_Radio}}
\docparam{helpString}{An optional help string associated with the item.
By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays
\wxheading{See also}
\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator},\rtfsp
+\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem},\rtfsp
+\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem},\rtfsp
\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
\helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp
\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem}
\end{twocollist}}
}
+\membersection{wxMenu::AppendCheckItem}\label{wxmenuappendcheckitem}
+
+\func{void}{AppendCheckItem}{\param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
+
+Adds a checkable item to the end of the menu.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
+\helpref{wxMenu::InsertCheckItem}{wxmenuinsertcheckitem}
+
+\membersection{wxMenu::AppendRadioItem}\label{wxmenuappendradioitem}
+
+\func{void}{AppendRadioItem}{\param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
+
+Adds a radio item to the end of the menu. All consequent radio items form a
+group and when an item in the group is checked, all the others are
+automatically unchecked.
+
+{\bf NB:} Currently only implemented under Windows and GTK, use
+{\tt #if wxHAS\_RADIO\_MENU\_ITEMS} to test for availability of this feature.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
+\helpref{wxMenu::InsertRadioItem}{wxmenuinsertradioitem}
+
\membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
\func{void}{AppendSeparator}{\void}
\wxheading{See also}
-\helpref{wxMenu::Append}{wxmenuappend}
+\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
+\helpref{wxMenu::InsertSeparator}{wxmenuinsertseparator}
\membersection{wxMenu::Break}\label{wxmenubreak}
\func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}}
+\func{void}{Insert}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
+\param{wxItemKind}{ kind = wxItem\_Normal}}
+
Inserts the given {\it item} before the position {\it pos}. Inserting the item
at the position \helpref{GetMenuItemCount}{wxmenugetmenuitemcount} is the same
as appending it.
\wxheading{See also}
-\helpref{wxMenu::Append}{wxmenuappend}
+\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
+\helpref{wxMenu::Prepend}{wxmenuprepend}
+
+\membersection{wxMenu::InsertCheckItem}\label{wxmenuinsertcheckitem}
+
+\func{void}{InsertCheckItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
+
+Inserts a checkable item at the given position.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
+\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem}
+
+\membersection{wxMenu::InsertRadioItem}\label{wxmenuinsertradioitem}
+
+\func{void}{InsertRadioItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
+
+Inserts a radio item at the given position.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
+\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem}
+
+\membersection{wxMenu::InsertSeparator}\label{wxmenuinsertseparator}
+
+\func{void}{InsertSeparator}{\param{size\_t }{pos}}
+
+Inserts a separator at the given position.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
+\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}
\membersection{wxMenu::IsChecked}\label{wxmenuischecked}
\helpref{wxMenu::Enable}{wxmenuenable}
+\membersection{wxMenu::Prepend}\label{wxmenuprepend}
+
+\func{bool}{Prepend}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}}
+
+\func{void}{Prepend}{\param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
+\param{wxItemKind}{ kind = wxItem\_Normal}}
+
+Inserts the given {\it item} at the position $0$.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
+\helpref{wxMenu::Inserts}{wxmenuinsert}
+
+\membersection{wxMenu::PrependCheckItem}\label{wxmenuprependcheckitem}
+
+\func{void}{PrependCheckItem}{\param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
+
+Inserts a checkable item at the position $0$.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
+\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem}
+
+\membersection{wxMenu::PrependRadioItem}\label{wxmenuprependradioitem}
+
+\func{void}{PrependRadioItem}{\param{int}{ id},\rtfsp
+\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
+
+Inserts a radio item at the position $0$.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
+\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem}
+
+\membersection{wxMenu::PrependSeparator}\label{wxmenuprependseparator}
+
+\func{void}{PrependSeparator}{\param{size\_t }{pos}}
+
+Inserts a separator at the position $0$.
+
+\wxheading{See also}
+
+\helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
+\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}
+
\membersection{wxMenu::Remove}\label{wxmenuremove}
\func{wxMenuItem *}{Remove}{\param{int }{id}}
\section{\class{wxMenuItem}}\label{wxmenuitem}
-A menu item represents an item in a popup menu. Note that the majority of this
-class is only implemented under Windows so far, but everything except fonts, colours and
-bitmaps can be achieved via wxMenu on all platforms.
+A menu item represents an item in a menu. Note that you usually don't have to
+deal with it directly as \helpref{wxMenu}{wxmenu} methods usually construct an
+object of this class for you.
+
+Also please note that the methods related to fonts and bitmaps are currently
+only implemented for Windows.
\wxheading{Derived from}
\func{}{wxMenuItem}{\param{wxMenu*}{ parentMenu = NULL}, \param{int}{ id = ID\_SEPARATOR},
\param{const wxString\& }{text = ""}, \param{const wxString\& }{helpString = ""},
- \param{bool }{checkable = FALSE}, \param{wxMenu*}{ subMenu = NULL}, }
+ \param{wxItemKind }{kind = wxItem\_Normal}, \param{wxMenu*}{ subMenu = NULL}, }
Constructs a wxMenuItem object.
\docparam{helpString}{Optional help string that will be shown on the status bar.}
-\docparam{checkable}{TRUE if this menu item is checkable.}
+\docparam{kind}{May be {\tt wxItem\_Separator}, {\tt wxItem\_Normal},
+{\tt wxItem\_Check} or {\tt wxItem\_Radio}}
\docparam{subMenu}{If non-NULL, indicates that the menu item is a submenu.}
Returns the menu item identifier.
+\membersection{wxMenuItem::GetKind}\label{wxmenuitemgetkind}
+
+\constfunc{wxItemKind}{GetKind}{\void}
+
+Returns the item kind, one of {\tt wxItem\_Separator}, {\tt wxItem\_Normal},
+{\tt wxItem\_Check} or {\tt wxItem\_Radio}.
+
\membersection{wxMenuItem::GetLabel}\label{wxmenuitemgetlabel}
\constfunc{wxString}{GetLabel}{\void}
#endif // Unix/!Unix
#endif
+// include the feature test macros
+#include "wx/features.h"
+
// suppress some Visual C++ warnings
#ifdef __VISUALC__
# pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
// constants
// ----------------------------------------------------------------------------
+// menu and toolbar item kinds
+enum wxItemKind
+{
+ wxItem_Separator = -1,
+ wxItem_Normal,
+ wxItem_Check,
+ wxItem_Radio,
+ wxItem_Max
+};
+
// hit test results
enum wxHitTest
{
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/features.h
+// Purpose: test macros for the features which might be available in some
+// wxWindows ports but not others
+// Author: Vadim Zeitlin
+// Modified by:
+// Created: 18.03.02
+// RCS-ID: $Id$
+// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_FEATURES_H_
+#define _WX_FEATURES_H_
+
+// radio menu items are currently only implemented in wxGTK
+#if defined(__WXGTK__) // || defined(__WXMSW__)
+ #define wxHAS_RADIO_MENU_ITEMS
+#else
+ #undef wxHAS_RADIO_MENU_ITEMS
+#endif
+
+#endif // _WX_FEATURES_H_
+
// common part of Append and Insert
bool GtkAppend(wxMenuItem *item);
+ // if the last menu item was a radio one, this field contains its path,
+ // otherwise it is empty
+ wxString m_pathLastRadio;
+
DECLARE_DYNAMIC_CLASS(wxMenu)
};
int id = wxID_SEPARATOR,
const wxString& text = wxEmptyString,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
+ wxItemKind kind = wxItem_Normal,
wxMenu *subMenu = (wxMenu *)NULL);
~wxMenuItem();
// common part of Append and Insert
bool GtkAppend(wxMenuItem *item);
+ // if the last menu item was a radio one, this field contains its path,
+ // otherwise it is empty
+ wxString m_pathLastRadio;
+
DECLARE_DYNAMIC_CLASS(wxMenu)
};
int id = wxID_SEPARATOR,
const wxString& text = wxEmptyString,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
+ wxItemKind kind = wxItem_Normal,
wxMenu *subMenu = (wxMenu *)NULL);
~wxMenuItem();
int id = wxID_SEPARATOR,
const wxString& name = wxEmptyString,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
+ wxItemKind kind = wxItem_Normal,
wxMenu *subMenu = (wxMenu *)NULL);
virtual ~wxMenuItem();
// menu construction
// -----------------
- // append a normal item to the menu
+ // append any kind of item (normal/check/radio/separator)
void Append(int id,
const wxString& text,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE)
+ wxItemKind kind = wxItem_Normal)
{
- DoAppend(wxMenuItem::New((wxMenu *)this, id, text, help, isCheckable));
+ DoAppend(wxMenuItem::New((wxMenu *)this, id, text, help, kind));
}
// append a separator to the menu
void AppendSeparator() { Append(wxID_SEPARATOR, wxEmptyString); }
+ // append a check item
+ void AppendCheckItem(int id,
+ const wxString& text,
+ const wxString& help = wxEmptyString)
+ {
+ Append(id, text, help, wxItem_Check);
+ }
+
+ // append a radio item
+ void AppendRadioItem(int id,
+ const wxString& text,
+ const wxString& help = wxEmptyString)
+ {
+ Append(id, text, help, wxItem_Radio);
+ }
+
// append a submenu
void Append(int id,
const wxString& text,
// insert an item before given position
bool Insert(size_t pos, wxMenuItem *item);
+
+ // insert an item before given position
void Insert(size_t pos,
int id,
const wxString& text,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE)
+ wxItemKind kind = wxItem_Normal)
{
- Insert(pos, wxMenuItem::New((wxMenu *)this, id, text, help, isCheckable));
+ Insert(pos, wxMenuItem::New((wxMenu *)this, id, text, help, kind));
}
// insert a separator
Insert(pos, wxMenuItem::New((wxMenu *)this));
}
+ // insert a check item
+ void InsertCheckItem(size_t pos,
+ int id,
+ const wxString& text,
+ const wxString& help = wxEmptyString)
+ {
+ Insert(pos, id, text, help, wxItem_Check);
+ }
+
+ // insert a radio item
+ void InsertRadioItem(size_t pos,
+ int id,
+ const wxString& text,
+ const wxString& help = wxEmptyString)
+ {
+ Insert(pos, id, text, help, wxItem_Radio);
+ }
+
// insert a submenu
void Insert(size_t pos,
int id,
Insert(0u, item);
}
+ // prepend any item to the menu
void Prepend(int id,
const wxString& text,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE)
+ wxItemKind kind = wxItem_Normal)
{
- Insert(0u, id, text, help, isCheckable);
+ Insert(0u, id, text, help, kind);
}
- // insert a separator
+ // prepend a separator
void PrependSeparator()
{
InsertSeparator(0u);
}
- // insert a submenu
+ // prepend a check item
+ void PrependCheckItem(int id,
+ const wxString& text,
+ const wxString& help = wxEmptyString)
+ {
+ InsertCheckItem(0u, id, text, help);
+ }
+
+ // prepend a radio item
+ void PrependRadioItem(int id,
+ const wxString& text,
+ const wxString& help = wxEmptyString)
+ {
+ InsertRadioItem(0u, id, text, help);
+ }
+
+ // prepend a submenu
void Prepend(int id,
const wxString& text,
wxMenu *submenu,
void SetParent(wxMenu *parent) { m_menuParent = parent; }
wxMenu *GetParent() const { return m_menuParent; }
-#if WXWIN_COMPATIBILITY
+ // implementation only from now on
+ // -------------------------------
+
+ // unlike FindItem(), this function doesn't recurse but only looks through
+ // our direct children and also may return the index of the found child if
+ // pos != NULL
+ wxMenuItem *FindChildItem(int id, size_t *pos = NULL) const;
+
+ // called to generate a wxCommandEvent, return TRUE if it was processed,
+ // FALSE otherwise
+ //
+ // the checked parameter may have boolean value or -1 for uncheckable items
+ bool SendEvent(int id, int checked = -1);
+
// compatibility: these functions are deprecated, use the new ones instead
+ // -----------------------------------------------------------------------
+
+ // use the versions taking wxItem_XXX now instead, they're more readable
+ // and allow adding the radio items as well
+ void Append(int id,
+ const wxString& text,
+ const wxString& help,
+ bool isCheckable)
+ {
+ Append(id, text, help, isCheckable ? wxItem_Check : wxItem_Normal);
+ }
+
+ void Insert(size_t pos,
+ int id,
+ const wxString& text,
+ const wxString& help,
+ bool isCheckable)
+ {
+ Insert(pos, id, text, help, isCheckable ? wxItem_Check : wxItem_Normal);
+ }
+
+ void Prepend(int id,
+ const wxString& text,
+ const wxString& help,
+ bool isCheckable)
+ {
+ Insert(0u, id, text, help, isCheckable);
+ }
+
+#if WXWIN_COMPATIBILITY
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
wxFunction m_callback;
#endif // wxUSE_MENU_CALLBACK
- // unlike FindItem(), this function doesn't recurse but only looks through
- // our direct children and also may return the index of the found child if
- // pos != NULL
- wxMenuItem *FindChildItem(int id, size_t *pos = NULL) const;
-
- // called to generate a wxCommandEvent, return TRUE if it was processed,
- // FALSE otherwise
- //
- // the checked parameter may have boolean value or -1 for uncheckable items
- bool SendEvent(int id, int checked = -1);
-
protected:
// virtuals to override in derived classes
// ---------------------------------------
int id = wxID_SEPARATOR,
const wxString& text = wxEmptyString,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
+ wxItemKind kind = wxItem_Normal,
wxMenu *subMenu = (wxMenu *)NULL);
// destruction: wxMenuItem will delete its submenu
static wxString GetLabelFromText(const wxString& text);
// what kind of menu item we are
- virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; }
- bool IsCheckable() const { return m_isCheckable; }
+ wxItemKind GetKind() const { return m_kind; }
+
+ virtual void SetCheckable(bool checkable) { m_kind = wxItem_Check; }
+ bool IsCheckable() const { return m_kind == wxItem_Check; }
bool IsSubMenu() const { return m_subMenu != NULL; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
void SetName(const wxString& str) { SetText(str); }
const wxString& GetName() const { return GetText(); }
+ static wxMenuItem *New(wxMenu *parentMenu,
+ int id,
+ const wxString& text,
+ const wxString& help,
+ bool isCheckable,
+ wxMenu *subMenu = (wxMenu *)NULL)
+ {
+ return New(parentMenu, id, text, help,
+ isCheckable ? wxItem_Check : wxItem_Normal, subMenu);
+ }
+
protected:
int m_id; // numeric id of the item >= 0 or -1
wxMenu *m_parentMenu, // the menu we belong to
*m_subMenu; // our sub menu or NULL
wxString m_text, // label of the item
m_help; // the help string for the item
- bool m_isCheckable; // can be checked?
+ wxItemKind m_kind; // seperator/normal/check/radio item?
bool m_isChecked; // is checked?
bool m_isEnabled; // is enabled?
- // some compilers need a default constructor here, do not remove
- wxMenuItemBase() { }
+ // this ctor is for the derived classes only, we're never created directly
+ wxMenuItemBase(wxMenu *parentMenu = (wxMenu *)NULL,
+ int id = wxID_SEPARATOR,
+ const wxString& text = wxEmptyString,
+ const wxString& help = wxEmptyString,
+ wxItemKind kind = wxItem_Normal,
+ wxMenu *subMenu = (wxMenu *)NULL);
private:
// and, if we have one ctor, compiler won't generate a default copy one, so
public:
// ctor & dtor
wxMenuItem(wxMenu *parentMenu = (wxMenu *)NULL,
- int id = wxID_SEPARATOR,
- const wxString& text = wxEmptyString,
- const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
- wxMenu *subMenu = (wxMenu *)NULL);
+ int id = wxID_SEPARATOR,
+ const wxString& text = wxEmptyString,
+ const wxString& help = wxEmptyString,
+ wxItemKind kind = wxItem_Normal,
+ wxMenu *subMenu = (wxMenu *)NULL);
~wxMenuItem();
// accessors (some more are inherited from wxOwnerDrawn or are below)
int id = wxID_SEPARATOR,
const wxString& name = wxEmptyString,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
+ wxItemKind kind = wxItem_Normal,
wxMenu *subMenu = (wxMenu *)NULL);
virtual ~wxMenuItem();
,int nId = wxID_SEPARATOR
,const wxString& rStrName = ""
,const wxString& rWxHelp = ""
- ,bool bCheckable = FALSE
+ ,wxItemKind kind = wxItem_Normal
,wxMenu* pSubMenu = NULL
);
virtual ~wxMenuItem();
int id = wxID_SEPARATOR,
const wxString& name = wxEmptyString,
const wxString& help = wxEmptyString,
- bool isCheckable = FALSE,
+ wxItemKind kind = wxItem_Normal,
wxMenu *subMenu = (wxMenu *)NULL);
virtual ~wxMenuItem();
void OnGetLabelMenu(wxCommandEvent& event);
void OnSetLabelMenu(wxCommandEvent& event);
+ void OnTestNormal(wxCommandEvent& event);
+ void OnTestCheck(wxCommandEvent& event);
+ void OnTestRadio(wxCommandEvent& event);
+
#ifdef __WXMSW__
void OnContextMenu(wxContextMenuEvent& event)
{ ShowContextMenu(ScreenToClient(event.GetPosition())); }
Menu_Menu_SetLabel,
Menu_Menu_GetInfo,
- Menu_Dummy_First = 400,
+ Menu_Test_Normal = 400,
+ Menu_Test_Check,
+ Menu_Test_Radio1,
+ Menu_Test_Radio2,
+ Menu_Test_Radio3,
+
+ Menu_Dummy_First = 500,
Menu_Dummy_Second,
Menu_Dummy_Third,
Menu_Dummy_Fourth,
EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem)
EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo)
+ EVT_MENU(Menu_Test_Normal, MyFrame::OnTestNormal)
+ EVT_MENU(Menu_Test_Check, MyFrame::OnTestCheck)
+ EVT_MENU(Menu_Test_Radio1, MyFrame::OnTestRadio)
+ EVT_MENU(Menu_Test_Radio2, MyFrame::OnTestRadio)
+ EVT_MENU(Menu_Test_Radio3, MyFrame::OnTestRadio)
+
EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy)
EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
menuMenu->Append(Menu_Menu_GetInfo, "Get menu item in&fo\tAlt-F",
"Show the state of the last menu item");
+ wxMenu *testMenu = new wxMenu;
+ testMenu->Append(Menu_Test_Normal, "&Normal item");
+ testMenu->AppendSeparator();
+ testMenu->AppendCheckItem(Menu_Test_Check, "&Check item");
+ testMenu->AppendSeparator();
+ testMenu->AppendRadioItem(Menu_Test_Radio1, "Radio item &1");
+ testMenu->AppendRadioItem(Menu_Test_Radio2, "Radio item &2");
+ testMenu->AppendRadioItem(Menu_Test_Radio3, "Radio item &3");
+
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(Menu_Help_About, "&About\tF1", "About menu sample");
menuBar->Append(fileMenu, "&File");
menuBar->Append(menubarMenu, "Menu&bar");
menuBar->Append(menuMenu, "&Menu");
+ menuBar->Append(testMenu, "&Test");
menuBar->Append(helpMenu, "&Help");
// these items should be initially checked
#endif // 0
}
+void MyFrame::OnTestNormal(wxCommandEvent& event)
+{
+ wxLogMessage(_T("Normal item selected"));
+}
+
+void MyFrame::OnTestCheck(wxCommandEvent& event)
+{
+ wxLogMessage(_T("Check item %schecked"),
+ event.IsChecked() ? _T("") : _T("un"));
+}
+
+void MyFrame::OnTestRadio(wxCommandEvent& event)
+{
+ wxLogMessage(_T("Radio item %d selected"),
+ event.GetId() - Menu_Test_Radio1 + 1);
+}
+
void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what)
{
wxLogStatus(this, _T("A %smenu has been %s."),
// 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;
+}
+
wxMenuItemBase::~wxMenuItemBase()
{
delete m_subMenu;
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
wxMenuItem::wxMenuItem(wxMenu *parentMenu,
int id,
const wxString& text,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
+ : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{
- m_id = id;
- m_isCheckable = isCheckable;
- m_isChecked = FALSE;
- m_isEnabled = TRUE;
- m_subMenu = subMenu;
- m_parentMenu = parentMenu;
- m_help = help;
-
m_labelWidget = (GtkWidget *) NULL;
m_menuItem = (GtkWidget *) NULL;
bool appended = FALSE;
#endif
+#if GTK_CHECK_VERSION(1, 2, 0)
+ // is this a radio item?
+ bool isRadio = FALSE;
+#endif // GTK+ >= 1.2
+
if ( mitem->IsSeparator() )
{
#if GTK_CHECK_VERSION(1, 2, 0)
/* local buffer in multibyte form */
char buf[200];
strcpy( buf, "/" );
- strcat( buf, text.mb_str() );
+ strncat( buf, text.mb_str(), WXSIZEOF(buf) - 2 );
+ buf[WXSIZEOF(buf) - 1] = '\0';
GtkItemFactoryEntry entry;
entry.path = buf;
entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
entry.callback_action = 0;
- if ( mitem->IsCheckable() )
- entry.item_type = (char *)"<CheckItem>";
- else
- entry.item_type = (char *)"<Item>";
+
+ wxString pathRadio;
+ const char *item_type;
+ switch ( mitem->GetKind() )
+ {
+ case wxItem_Check:
+ item_type = "<CheckItem>";
+ break;
+
+ case wxItem_Radio:
+ if ( m_pathLastRadio.empty() )
+ {
+ // start of a new radio group
+ item_type = "<RadioItem>";
+ m_pathLastRadio = buf + 1;
+ }
+ else // continue the radio group
+ {
+ pathRadio = m_pathLastRadio;
+ pathRadio.Replace("_", "");
+ pathRadio.Prepend("<main>/");
+ item_type = pathRadio;
+ }
+
+ // remember that this one was a radio item to avoid resetting
+ // m_pathLastRadio below
+ isRadio = TRUE;
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unexpected menu item kind") );
+ // fall through
+
+ case wxItem_Normal:
+ item_type = "<Item>";
+ break;
+ }
+
+ entry.item_type = (char *)item_type; // cast needed for GTK+
entry.accelerator = (gchar*) NULL;
#if wxUSE_ACCEL
mitem->SetMenuItem(menuItem);
+#if GTK_CHECK_VERSION(1, 2, 0)
+ if ( !isRadio )
+ {
+ m_pathLastRadio.clear();
+ }
+#endif // GTK+ >= 1.2
+
return TRUE;
}
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
wxMenuItem::wxMenuItem(wxMenu *parentMenu,
int id,
const wxString& text,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
+ : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{
- m_id = id;
- m_isCheckable = isCheckable;
- m_isChecked = FALSE;
- m_isEnabled = TRUE;
- m_subMenu = subMenu;
- m_parentMenu = parentMenu;
- m_help = help;
-
m_labelWidget = (GtkWidget *) NULL;
m_menuItem = (GtkWidget *) NULL;
bool appended = FALSE;
#endif
+#if GTK_CHECK_VERSION(1, 2, 0)
+ // is this a radio item?
+ bool isRadio = FALSE;
+#endif // GTK+ >= 1.2
+
if ( mitem->IsSeparator() )
{
#if GTK_CHECK_VERSION(1, 2, 0)
/* local buffer in multibyte form */
char buf[200];
strcpy( buf, "/" );
- strcat( buf, text.mb_str() );
+ strncat( buf, text.mb_str(), WXSIZEOF(buf) - 2 );
+ buf[WXSIZEOF(buf) - 1] = '\0';
GtkItemFactoryEntry entry;
entry.path = buf;
entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
entry.callback_action = 0;
- if ( mitem->IsCheckable() )
- entry.item_type = (char *)"<CheckItem>";
- else
- entry.item_type = (char *)"<Item>";
+
+ wxString pathRadio;
+ const char *item_type;
+ switch ( mitem->GetKind() )
+ {
+ case wxItem_Check:
+ item_type = "<CheckItem>";
+ break;
+
+ case wxItem_Radio:
+ if ( m_pathLastRadio.empty() )
+ {
+ // start of a new radio group
+ item_type = "<RadioItem>";
+ m_pathLastRadio = buf + 1;
+ }
+ else // continue the radio group
+ {
+ pathRadio = m_pathLastRadio;
+ pathRadio.Replace("_", "");
+ pathRadio.Prepend("<main>/");
+ item_type = pathRadio;
+ }
+
+ // remember that this one was a radio item to avoid resetting
+ // m_pathLastRadio below
+ isRadio = TRUE;
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unexpected menu item kind") );
+ // fall through
+
+ case wxItem_Normal:
+ item_type = "<Item>";
+ break;
+ }
+
+ entry.item_type = (char *)item_type; // cast needed for GTK+
entry.accelerator = (gchar*) NULL;
#if wxUSE_ACCEL
mitem->SetMenuItem(menuItem);
+#if GTK_CHECK_VERSION(1, 2, 0)
+ if ( !isRadio )
+ {
+ m_pathLastRadio.clear();
+ }
+#endif // GTK+ >= 1.2
+
return TRUE;
}
// ctor & dtor
// -----------
-wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
- const wxString& text, const wxString& strHelp,
- bool bCheckable,
+wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
+ int id,
+ const wxString& text,
+ const wxString& strHelp,
+ wxItemKind kind,
wxMenu *pSubMenu)
+ : wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu)
{
- wxASSERT( pParentMenu != NULL );
-
- m_parentMenu = pParentMenu;
- m_subMenu = pSubMenu;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
- m_id = id;
- m_text = text;
- m_isCheckable = bCheckable;
- m_help = strHelp;
-
-
+ // VZ: what about translations?? (FIXME)
if ( m_text == "E&xit" ||m_text == "Exit" ||m_text.Left(5) == "Exit\t" || m_text.Left(6) == "E&xit\t" )
{
m_text = "Quit\tCtrl+Q" ;
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
// ctor & dtor
// -----------
-wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
- const wxString& text, const wxString& strHelp,
- bool bCheckable,
+wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
+ int id,
+ const wxString& text,
+ const wxString& strHelp,
+ wxItemKind kind,
wxMenu *pSubMenu)
+ : wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu)
{
- wxASSERT( pParentMenu != NULL );
-
- m_parentMenu = pParentMenu;
- m_subMenu = pSubMenu;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
- m_id = id;
- m_text = text;
- m_isCheckable = bCheckable;
- m_help = strHelp;
-
-
+ // VZ: what about translations?? (FIXME)
if ( m_text == "E&xit" ||m_text == "Exit" ||m_text.Left(5) == "Exit\t" || m_text.Left(6) == "E&xit\t" )
{
m_text = "Quit\tCtrl+Q" ;
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
// dynamic classes implementation
// ----------------------------------------------------------------------------
- IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
+IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
// ----------------------------------------------------------------------------
// wxMenuItem
// ctor & dtor
// -----------
-wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
- const wxString& strName, const wxString& strHelp,
- bool bCheckable,
+wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
+ int id,
+ const wxString& strName,
+ const wxString& strHelp,
+ wxItemKind kind,
wxMenu *pSubMenu)
+ : wxMenuItemBase(pParentMenu, id, strName, strHelp, kind, pSubMenu)
{
- wxASSERT_MSG( pParentMenu != NULL, wxT("menuitem should have a menu") );
-
- // common init
- m_parentMenu = pParentMenu;
- m_subMenu = pSubMenu;
- m_id = id;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
- m_help = strHelp;
- m_isCheckable = bCheckable;
- m_text = strName;
-
// Motif-specific
m_menuBar = NULL;
m_buttonWidget = (WXWidget) NULL;
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
// ----------------------------------------------------------------------------
int id,
const wxString& text,
const wxString& strHelp,
- bool bCheckable,
+ wxItemKind kind,
wxMenu *pSubMenu)
+ : wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu)
#if wxUSE_OWNER_DRAWN
- : wxOwnerDrawn(GetLabelFromText(text), bCheckable)
+ , wxOwnerDrawn(GetLabelFromText(text), kind == wxItem_Check)
#endif // owner drawn
{
wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
// tell the owner drawing code to to show the accel string as well
SetAccelString(text.AfterFirst(_T('\t')));
#endif // wxUSE_OWNER_DRAWN
-
- m_parentMenu = pParentMenu;
- m_subMenu = pSubMenu;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
- m_id = id;
- m_text = text;
- m_isCheckable = bCheckable;
- m_help = strHelp;
}
wxMenuItem::~wxMenuItem()
void wxMenuItem::Check(bool check)
{
- wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
+ wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
if ( m_isChecked == check )
return;
int id,
const wxString& name,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
{
- return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
}
#endif // wxUSE_MENUS
, int nId
, const wxString& rText
, const wxString& rStrHelp
-, bool bCheckable
+, wxItemKind kind
, wxMenu* pSubMenu
)
+: wxMenuItemBase(pParentMenu, nId, rText, rStrHelp, kind, pSubMenu)
#if wxUSE_OWNER_DRAWN
-: wxOwnerDrawn( TextToLabel(rText)
+, wxOwnerDrawn( TextToLabel(rText)
,bCheckable
)
#endif // owner drawn
#undef SYS_COLOR
#endif // wxUSE_OWNER_DRAWN
- m_parentMenu = pParentMenu;
- m_subMenu = pSubMenu;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
- m_id = nId;
m_text = TextToLabel(rText);
- m_isCheckable = bCheckable;
- m_help = rStrHelp;
+
memset(&m_vMenuData, '\0', sizeof(m_vMenuData));
m_vMenuData.id= nId;
} // end of wxMenuItem::wxMenuItem
{
bool bOk;
- wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
+ wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
if (m_isChecked == bCheck)
return;
if (bCheck)
, int nId
, const wxString& rName
, const wxString& rHelp
-, bool bIsCheckable
+, wxItemKind kind
, wxMenu* pSubMenu
)
{
,nId
,rName
,rHelp
- ,bIsCheckable
+ ,kind
,pSubMenu
);
} // end of wxMenuItemBase::New
int id,
const wxString& text,
const wxString& help,
- bool isCheckable,
+ wxItemKind kind,
wxMenu *subMenu)
+ : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
{
- m_id = id;
- m_parentMenu = parentMenu;
- m_subMenu = subMenu;
-
- m_text = text;
- m_help = help;
-
- m_isCheckable = isCheckable;
- m_isEnabled = TRUE;
- m_isChecked = FALSE;
-
m_posY =
m_height = -1;
void wxMenuItem::SetCheckable(bool checkable)
{
- if ( checkable != m_isCheckable )
+ if ( checkable != IsCheckable() )
{
wxMenuItemBase::SetCheckable(checkable);