#pragma hdrstop
#endif
+#if wxUSE_MENUS
+
#ifndef WX_PRECOMP
#include "wx/font.h"
#include "wx/bitmap.h"
// dynamic classes implementation
// ----------------------------------------------------------------------------
- #if wxUSE_OWNER_DRAWN
- IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxMenuItemBase, wxOwnerDrawn)
- #else //!USE_OWNER_DRAWN
- IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxMenuItemBase)
- #endif //USE_OWNER_DRAWN
+IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
// ----------------------------------------------------------------------------
// wxMenuItem
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(text, bCheckable)
+ , wxOwnerDrawn(GetLabelFromText(text), kind == wxItem_Check)
#endif // owner drawn
{
wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
+ m_startRadioGroup =
+ m_endRadioGroup = -1;
+
#if wxUSE_OWNER_DRAWN
// set default menu colors
- #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
+ #define SYS_COLOR(c) (wxSystemSettings::GetColour(wxSYS_COLOUR_##c))
SetTextColour(SYS_COLOR(MENUTEXT));
SetBackgroundColour(SYS_COLOR(MENU));
+ #undef SYS_COLOR
+
// we don't want normal items be owner-drawn
ResetOwnerDrawn();
- #undef SYS_COLOR
+ // 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()
return (flag & MF_CHECKED) != 0;
}
-wxString wxMenuItem::GetLabel() const
-{
- return wxStripMenuCodes(m_text);
-}
-
-// accelerators
-// ------------
-
-#if wxUSE_ACCEL
-
-wxAcceleratorEntry *wxMenuItem::GetAccel() const
+/* static */
+wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{
- return wxGetAccelFromString(GetText());
+ return wxStripMenuCodes(text);
}
-#endif // wxUSE_ACCEL
-
// change item state
// -----------------
(enable ? MF_ENABLED : MF_GRAYED));
if ( rc == -1 ) {
- wxLogLastError("EnableMenuItem");
+ wxLogLastError(wxT("EnableMenuItem"));
}
wxMenuItemBase::Enable(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;
- long rc = CheckMenuItem(GetHMenuOf(m_parentMenu),
- GetRealId(),
- MF_BYCOMMAND |
- (check ? MF_CHECKED : MF_UNCHECKED));
+ int flags = check ? MF_CHECKED : MF_UNCHECKED;
+ HMENU hmenu = GetHMenuOf(m_parentMenu);
- if ( rc == -1 ) {
- wxLogLastError("CheckMenuItem");
+ if ( GetKind() == wxItem_Radio )
+ {
+ // it doesn't make sense to uncheck a radio item - what would this do?
+ if ( !check )
+ return;
+
+ const wxMenuItemList& items = m_parentMenu->GetMenuItems();
+ int pos = items.IndexOf(this);
+ wxCHECK_RET( pos != wxNOT_FOUND,
+ _T("menuitem not found in the menu items list?") );
+
+#ifdef __WIN32__
+ if ( !::CheckMenuRadioItem(hmenu,
+ m_startRadioGroup, // first group item
+ m_endRadioGroup, // last one
+ pos, // the one to check
+ MF_BYPOSITION | flags) )
+ {
+ wxLogLastError(_T("CheckMenuRadioItem"));
+ }
+#endif // __WIN32__
+
+ // also uncheck all the other items in this radio group
+ wxMenuItemList::Node *node = items.Item(m_startRadioGroup);
+ for ( int n = m_startRadioGroup; n <= m_endRadioGroup && node; n++ )
+ {
+ if ( n != pos )
+ {
+ node->GetData()->m_isChecked = FALSE;
+ }
+
+ // we also have to do it in the menu for Win16 (under Win32
+ // CheckMenuRadioItem() does it for us)
+#ifndef __WIN32__
+ ::CheckMenuItem(hmenu, n, n == pos ? MF_CHECKED : MF_UNCHECKED);
+#endif // Win16
+
+ node = node->GetNext();
+ }
+ }
+ else // check item
+ {
+ if ( ::CheckMenuItem(hmenu,
+ GetRealId(),
+ MF_BYCOMMAND | flags) == -1 )
+ {
+ wxLogLastError(wxT("CheckMenuItem"));
+ }
}
wxMenuItemBase::Check(check);
UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
if ( flagsOld == 0xFFFFFFFF )
{
- wxLogLastError("GetMenuState");
+ wxLogLastError(wxT("GetMenuState"));
}
else
{
#endif //owner drawn
{
flagsOld |= MF_STRING;
- data = (char*) text.c_str();
+ data = (wxChar*) text.c_str();
}
if ( ::ModifyMenu(hMenu, id,
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