1. implemented radio menu items for wxGTK

2. changed (in most cases blindly) code for all the others
3. added wx/features.h
4. update wxMenu[Item] docs

----------------------------------------------------------------------
Committing in .

Modified Files:
	distrib/msw/tmake/filelist.txt docs/changes.txt
	docs/latex/wx/menu.tex docs/latex/wx/menuitem.tex
	include/wx/defs.h include/wx/menu.h include/wx/menuitem.h
	include/wx/gtk/menu.h include/wx/gtk/menuitem.h
	include/wx/mac/menuitem.h include/wx/motif/menuitem.h
	include/wx/msw/menuitem.h include/wx/os2/MENUITEM.H
	include/wx/univ/menuitem.h samples/menu/menu.cpp
	src/common/menucmn.cpp src/gtk/menu.cpp src/mac/menuitem.cpp
	src/motif/menuitem.cpp src/msw/menuitem.cpp
	src/os2/MENUITEM.CPP src/univ/menu.cpp
Added Files:
	include/wx/features.h
----------------------------------------------------------------------


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14674 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-03-18 19:41:35 +00:00
parent cac344f664
commit d65c269b3f
27 changed files with 551 additions and 171 deletions

View File

@@ -55,6 +55,25 @@ WX_DEFINE_LIST(wxMenuItemList);
// 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;

View File

@@ -699,27 +699,20 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
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;
@@ -948,6 +941,11 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
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)
@@ -1046,16 +1044,52 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
/* 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
@@ -1105,6 +1139,13 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
mitem->SetMenuItem(menuItem);
#if GTK_CHECK_VERSION(1, 2, 0)
if ( !isRadio )
{
m_pathLastRadio.clear();
}
#endif // GTK+ >= 1.2
return TRUE;
}

View File

@@ -699,27 +699,20 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
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;
@@ -948,6 +941,11 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
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)
@@ -1046,16 +1044,52 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
/* 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
@@ -1105,6 +1139,13 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
mitem->SetMenuItem(menuItem);
#if GTK_CHECK_VERSION(1, 2, 0)
if ( !isRadio )
{
m_pathLastRadio.clear();
}
#endif // GTK+ >= 1.2
return TRUE;
}

View File

@@ -175,23 +175,15 @@ int wxMenuItem::MacBuildMenuString(StringPtr outMacItemText, SInt16 *outMacShort
// 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" ;
@@ -348,8 +340,8 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
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);
}

View File

@@ -175,23 +175,15 @@ int wxMenuItem::MacBuildMenuString(StringPtr outMacItemText, SInt16 *outMacShort
// 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" ;
@@ -348,8 +340,8 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
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);
}

View File

@@ -62,7 +62,7 @@ static void wxMenuItemDisarmCallback(Widget w, XtPointer clientData, XtPointer p
// dynamic classes implementation
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
// ----------------------------------------------------------------------------
// wxMenuItem
@@ -71,23 +71,14 @@ static void wxMenuItemDisarmCallback(Widget w, XtPointer clientData, XtPointer p
// 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;
@@ -170,10 +161,10 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
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);
}
// ----------------------------------------------------------------------------

View File

@@ -85,10 +85,11 @@ wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
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") );
@@ -108,15 +109,6 @@ wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
// 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()
@@ -170,7 +162,7 @@ void wxMenuItem::Enable(bool enable)
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;
@@ -256,10 +248,10 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
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

View File

@@ -110,11 +110,12 @@ wxMenuItem::wxMenuItem(
, 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
@@ -139,14 +140,8 @@ wxMenuItem::wxMenuItem(
#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
@@ -236,7 +231,7 @@ void wxMenuItem::Check(
{
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)
@@ -359,7 +354,7 @@ wxMenuItem* wxMenuItemBase::New(
, int nId
, const wxString& rName
, const wxString& rHelp
, bool bIsCheckable
, wxItemKind kind
, wxMenu* pSubMenu
)
{
@@ -367,7 +362,7 @@ wxMenuItem* wxMenuItemBase::New(
,nId
,rName
,rHelp
,bIsCheckable
,kind
,pSubMenu
);
} // end of wxMenuItemBase::New

View File

@@ -1397,20 +1397,10 @@ 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_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;
@@ -1474,7 +1464,7 @@ void wxMenuItem::SetText(const wxString& text)
void wxMenuItem::SetCheckable(bool checkable)
{
if ( checkable != m_isCheckable )
if ( checkable != IsCheckable() )
{
wxMenuItemBase::SetCheckable(checkable);