no message
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6366 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -43,34 +43,38 @@ class WXDLLEXPORT wxMenuItem: public wxMenuItemBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor & dtor
|
// ctor & dtor
|
||||||
wxMenuItem(wxMenu *pParentMenu = NULL, int id = ID_SEPARATOR,
|
wxMenuItem( wxMenu* pParentMenu = NULL
|
||||||
const wxString& strName = "", const wxString& wxHelp = "",
|
,int nId = ID_SEPARATOR
|
||||||
bool bCheckable = FALSE, wxMenu *pSubMenu = NULL);
|
,const wxString& rStrName = ""
|
||||||
|
,const wxString& rWxHelp = ""
|
||||||
|
,bool bCheckable = FALSE
|
||||||
|
,wxMenu* pSubMenu = NULL
|
||||||
|
);
|
||||||
virtual ~wxMenuItem();
|
virtual ~wxMenuItem();
|
||||||
|
|
||||||
// override base class virtuals
|
// override base class virtuals
|
||||||
virtual void SetText(const wxString& strName);
|
virtual void SetText(const wxString& rStrName);
|
||||||
virtual void SetCheckable(bool checkable);
|
virtual void SetCheckable(bool bCheckable);
|
||||||
|
|
||||||
virtual void Enable(bool bDoEnable = TRUE);
|
virtual void Enable(bool bDoEnable = TRUE);
|
||||||
virtual void Check(bool bDoCheck = TRUE);
|
virtual void Check(bool bDoCheck = TRUE);
|
||||||
virtual bool IsChecked() const;
|
virtual bool IsChecked(void) const;
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
virtual wxAcceleratorEntry *GetAccel() const;
|
virtual wxAcceleratorEntry* GetAccel(void) const;
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
// unfortunately needed to resolve ambiguity between
|
// unfortunately needed to resolve ambiguity between
|
||||||
// wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
|
// wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable()
|
||||||
bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); }
|
bool IsCheckable(void) const { return wxMenuItemBase::IsCheckable(); }
|
||||||
|
|
||||||
// the id for a popup menu is really its menu handle (as required by
|
// the id for a popup menu is really its menu handle (as required by
|
||||||
// ::AppendMenu() API), so this function will return either the id or the
|
// ::AppendMenu() API), so this function will return either the id or the
|
||||||
// menu handle depending on what we're
|
// menu handle depending on what we're
|
||||||
int GetRealId() const;
|
int GetRealId(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxMenuItem)
|
DECLARE_DYNAMIC_CLASS(wxMenuItem)
|
||||||
};
|
}; // end of CLASS wxMenuItem
|
||||||
|
|
||||||
#endif //_MENUITEM_H
|
#endif //_MENUITEM_H
|
||||||
|
@@ -518,42 +518,23 @@ bool wxICOResourceHandler::LoadIcon(
|
|||||||
, const wxString& rName
|
, const wxString& rName
|
||||||
, HPS hPs
|
, HPS hPs
|
||||||
, long lFlags
|
, long lFlags
|
||||||
, int nDesiredWidth
|
, int WXUNUSED(nDesiredWidth)
|
||||||
, int nDesiredHeight
|
, int WXUNUSED(nDesiredHeight)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// TODO: load icon from a file
|
HPOINTER hIcon;
|
||||||
/*
|
|
||||||
HICON hicon;
|
|
||||||
|
|
||||||
#if defined(__WIN32__) && !defined(__SC__)
|
hIcon = ::WinLoadFileIcon( (PSZ)rName.c_str()
|
||||||
if ( desiredWidth != -1 && desiredHeight != -1 )
|
,TRUE // load for private use
|
||||||
{
|
);
|
||||||
hicon = (HICON)::LoadImage(wxGetInstance(), name, IMAGE_ICON,
|
|
||||||
desiredWidth, desiredHeight,
|
|
||||||
LR_DEFAULTCOLOR);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif // Win32
|
|
||||||
{
|
|
||||||
hicon = ::LoadIcon(wxGetInstance(), name);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxSize size = GetHiconSize(hicon);
|
pIcon->SetSize(32, 32); // all OS/2 icons are 32 x 32
|
||||||
icon->SetSize(size.x, size.y);
|
|
||||||
|
|
||||||
// Override the found values with desired values
|
|
||||||
if ( desiredWidth > -1 && desiredHeight > -1 )
|
|
||||||
{
|
|
||||||
icon->SetSize(desiredWidth, desiredHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
icon->SetHICON((WXHICON)hicon);
|
pIcon->SetHICON((WXHICON)hIcon);
|
||||||
|
|
||||||
return icon->Ok();
|
return pIcon->Ok();
|
||||||
*/
|
} // end of wxICOResourceHandler::LoadIcon
|
||||||
return(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// private functions
|
// private functions
|
||||||
|
@@ -75,26 +75,35 @@
|
|||||||
// ctor & dtor
|
// ctor & dtor
|
||||||
// -----------
|
// -----------
|
||||||
|
|
||||||
wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
|
wxMenuItem::wxMenuItem(
|
||||||
int id,
|
wxMenu* pParentMenu
|
||||||
const wxString& text,
|
, int nId
|
||||||
const wxString& strHelp,
|
, const wxString& rText
|
||||||
bool bCheckable,
|
, const wxString& rStrHelp
|
||||||
wxMenu *pSubMenu)
|
, bool bCheckable
|
||||||
|
, wxMenu* pSubMenu
|
||||||
|
)
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
: wxOwnerDrawn(text, bCheckable)
|
: wxOwnerDrawn( rText
|
||||||
|
,bCheckable
|
||||||
|
)
|
||||||
#endif // owner drawn
|
#endif // owner drawn
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
|
wxASSERT_MSG(pParentMenu != NULL, wxT("a menu item should have a parent"));
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
// set default menu colors
|
|
||||||
|
//
|
||||||
|
// Set default menu colors
|
||||||
|
//
|
||||||
#define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
|
#define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
|
||||||
|
|
||||||
SetTextColour(SYS_COLOR(MENUTEXT));
|
SetTextColour(SYS_COLOR(MENUTEXT));
|
||||||
SetBackgroundColour(SYS_COLOR(MENU));
|
SetBackgroundColour(SYS_COLOR(MENU));
|
||||||
|
|
||||||
// we don't want normal items be owner-drawn
|
//
|
||||||
|
// We don't want normal items be owner-drawn
|
||||||
|
//
|
||||||
ResetOwnerDrawn();
|
ResetOwnerDrawn();
|
||||||
|
|
||||||
#undef SYS_COLOR
|
#undef SYS_COLOR
|
||||||
@@ -104,42 +113,47 @@ wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
|
|||||||
m_subMenu = pSubMenu;
|
m_subMenu = pSubMenu;
|
||||||
m_isEnabled = TRUE;
|
m_isEnabled = TRUE;
|
||||||
m_isChecked = FALSE;
|
m_isChecked = FALSE;
|
||||||
m_id = id;
|
m_id = nId;
|
||||||
m_text = text;
|
m_text = rText;
|
||||||
m_isCheckable = bCheckable;
|
m_isCheckable = bCheckable;
|
||||||
m_help = strHelp;
|
m_help = rStrHelp;
|
||||||
}
|
} // end of wxMenuItem::wxMenuItem
|
||||||
|
|
||||||
wxMenuItem::~wxMenuItem()
|
wxMenuItem::~wxMenuItem()
|
||||||
{
|
{
|
||||||
}
|
} // end of wxMenuItem::~wxMenuItem
|
||||||
|
|
||||||
// misc
|
//
|
||||||
|
// Misc
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
// return the id for calling Win32 API functions
|
//
|
||||||
|
// Return the id for calling Win32 API functions
|
||||||
|
//
|
||||||
int wxMenuItem::GetRealId() const
|
int wxMenuItem::GetRealId() const
|
||||||
{
|
{
|
||||||
return m_subMenu ? (int)m_subMenu->GetHMenu() : GetId();
|
return m_subMenu ? (int)m_subMenu->GetHMenu() : GetId();
|
||||||
}
|
} // end of wxMenuItem::GetRealId
|
||||||
|
|
||||||
// get item state
|
//
|
||||||
|
// Get item state
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
bool wxMenuItem::IsChecked() const
|
bool wxMenuItem::IsChecked() const
|
||||||
{
|
{
|
||||||
/*
|
USHORT uFlag = SHORT1FROMMR(::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetId(), MF_BYCOMMAND);
|
,MM_QUERYITEMATTR
|
||||||
|
,MPFROM2SHORT(GetId(), TRUE)
|
||||||
|
,MPFROMSHORT(MIA_CHECKED)
|
||||||
|
));
|
||||||
|
|
||||||
// don't "and" with MF_ENABLED because its value is 0
|
return (uFlag & MIA_CHECKED);
|
||||||
return (flag & MF_DISABLED) == 0;
|
} // end of wxMenuItem::IsChecked
|
||||||
*/
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
wxString wxMenuItemBase::GetLabelFromText(
|
||||||
|
const wxString& rText
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return wxStripMenuCodes(text);
|
return wxStripMenuCodes(rText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// accelerators
|
// accelerators
|
||||||
@@ -157,114 +171,170 @@ wxAcceleratorEntry *wxMenuItem::GetAccel() const
|
|||||||
// change item state
|
// change item state
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
void wxMenuItem::Enable(bool enable)
|
void wxMenuItem::Enable(
|
||||||
|
bool bEnable
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if ( m_isEnabled == enable )
|
bool bOk;
|
||||||
return;
|
|
||||||
/*
|
|
||||||
long rc = EnableMenuItem(GetHMenuOf(m_parentMenu),
|
|
||||||
GetRealId(),
|
|
||||||
MF_BYCOMMAND |
|
|
||||||
(enable ? MF_ENABLED : MF_GRAYED));
|
|
||||||
|
|
||||||
if ( rc == -1 ) {
|
if (m_isEnabled == bEnable)
|
||||||
|
return;
|
||||||
|
if (bEnable)
|
||||||
|
bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
|
,MM_SETITEMATTR
|
||||||
|
,MPFROM2SHORT(GetRealId(), TRUE)
|
||||||
|
,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
|
||||||
|
);
|
||||||
|
else
|
||||||
|
bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
|
,MM_SETITEMATTR
|
||||||
|
,MPFROM2SHORT(GetRealId(), TRUE)
|
||||||
|
,MPFROM2SHORT(MIA_DISABLED, FALSE)
|
||||||
|
);
|
||||||
|
if (!bOk)
|
||||||
|
{
|
||||||
wxLogLastError("EnableMenuItem");
|
wxLogLastError("EnableMenuItem");
|
||||||
}
|
}
|
||||||
*/
|
wxMenuItemBase::Enable(bEnable);
|
||||||
wxMenuItemBase::Enable(enable);
|
} // end of wxMenuItem::Enable
|
||||||
}
|
|
||||||
|
|
||||||
void wxMenuItem::Check(bool check)
|
void wxMenuItem::Check(
|
||||||
|
bool bCheck
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
bool bOk;
|
||||||
|
|
||||||
wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
|
wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
|
||||||
|
if (m_isChecked == bCheck)
|
||||||
if ( m_isChecked == check )
|
|
||||||
return;
|
return;
|
||||||
/*
|
if (bCheck)
|
||||||
long rc = CheckMenuItem(GetHMenuOf(m_parentMenu),
|
bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
GetRealId(),
|
,MM_SETITEMATTR
|
||||||
MF_BYCOMMAND |
|
,MPFROM2SHORT(GetRealId(), TRUE)
|
||||||
(check ? MF_CHECKED : MF_UNCHECKED));
|
,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
|
||||||
|
);
|
||||||
if ( rc == -1 ) {
|
else
|
||||||
wxLogLastError("CheckMenuItem");
|
bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
|
,MM_SETITEMATTR
|
||||||
|
,MPFROM2SHORT(GetRealId(), TRUE)
|
||||||
|
,MPFROM2SHORT(MIA_CHECKED, FALSE)
|
||||||
|
);
|
||||||
|
if (!bOk)
|
||||||
|
{
|
||||||
|
wxLogLastError("EnableMenuItem");
|
||||||
}
|
}
|
||||||
*/
|
wxMenuItemBase::Check(bCheck);
|
||||||
wxMenuItemBase::Check(check);
|
} // end of wxMenuItem::Check
|
||||||
}
|
|
||||||
|
|
||||||
void wxMenuItem::SetText(const wxString& text)
|
void wxMenuItem::SetText(
|
||||||
|
const wxString& rText
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// don't do anything if label didn't change
|
//
|
||||||
if ( m_text == text )
|
// Don't do anything if label didn't change
|
||||||
|
//
|
||||||
|
if (m_text == rText)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxMenuItemBase::SetText(text);
|
wxMenuItemBase::SetText(rText);
|
||||||
OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
|
OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(rText));
|
||||||
/*
|
|
||||||
HMENU hMenu = GetHMenuOf(m_parentMenu);
|
HWND hMenu = GetHMenuOf(m_parentMenu);
|
||||||
wxCHECK_RET( hMenu, wxT("menuitem without menu") );
|
|
||||||
|
wxCHECK_RET(hMenu, wxT("menuitem without menu"));
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
m_parentMenu->UpdateAccel(this);
|
m_parentMenu->UpdateAccel(this);
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
UINT id = GetRealId();
|
USHORT uId = GetRealId();
|
||||||
UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
|
MENUITEM vItem;
|
||||||
if ( flagsOld == 0xFFFFFFFF )
|
USHORT uFlagsOld;
|
||||||
|
|
||||||
|
if (!::WinSendMsg( hMenu
|
||||||
|
,MM_QUERYITEM
|
||||||
|
,MPFROM2SHORT(uId, TRUE)
|
||||||
|
,(MPARAM)&vItem
|
||||||
|
))
|
||||||
{
|
{
|
||||||
wxLogLastError("GetMenuState");
|
wxLogLastError("GetMenuState");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( IsSubMenu() )
|
uFlagsOld = vItem.afStyle;
|
||||||
|
if (IsSubMenu())
|
||||||
{
|
{
|
||||||
// high byte contains the number of items in a submenu for submenus
|
uFlagsOld |= MIS_SUBMENU;
|
||||||
flagsOld &= 0xFF;
|
|
||||||
flagsOld |= MF_POPUP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LPCTSTR data;
|
BYTE* pData;
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
if ( IsOwnerDrawn() )
|
if (IsOwnerDrawn())
|
||||||
{
|
{
|
||||||
flagsOld |= MF_OWNERDRAW;
|
uFlagsOld |= MIS_OWNERDRAW;
|
||||||
data = (LPCTSTR)this;
|
pData = (BYTE*)this;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif //owner drawn
|
#endif //owner drawn
|
||||||
{
|
{
|
||||||
flagsOld |= MF_STRING;
|
uFlagsOld |= MIS_TEXT;
|
||||||
data = (char*) text.c_str();
|
pData = (BYTE*)rText.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ::ModifyMenu(hMenu, id,
|
//
|
||||||
MF_BYCOMMAND | flagsOld,
|
// Set the style
|
||||||
id, data) == (int)0xFFFFFFFF )
|
//
|
||||||
|
if (!::WinSendMsg( hMenu
|
||||||
|
,MM_SETITEM
|
||||||
|
,MPFROM2SHORT(uId, TRUE)
|
||||||
|
,(MPARAM)&vItem
|
||||||
|
))
|
||||||
|
{
|
||||||
|
wxLogLastError(wxT("ModifyMenu"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set the text
|
||||||
|
//
|
||||||
|
if (::WinSendMsg( hMenu
|
||||||
|
,MM_SETITEMTEXT
|
||||||
|
,MPFROMSHORT(uId)
|
||||||
|
,(MPARAM)pData
|
||||||
|
))
|
||||||
{
|
{
|
||||||
wxLogLastError(wxT("ModifyMenu"));
|
wxLogLastError(wxT("ModifyMenu"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
} // end of wxMenuItem::SetText
|
||||||
}
|
|
||||||
|
|
||||||
void wxMenuItem::SetCheckable(bool checkable)
|
void wxMenuItem::SetCheckable(
|
||||||
|
bool bCheckable
|
||||||
|
)
|
||||||
{
|
{
|
||||||
wxMenuItemBase::SetCheckable(checkable);
|
wxMenuItemBase::SetCheckable(bCheckable);
|
||||||
OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
|
OWNER_DRAWN_ONLY(wxOwnerDrawn::SetCheckable(bCheckable));
|
||||||
}
|
} // end of wxMenuItem::SetCheckable
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxMenuItemBase
|
// wxMenuItemBase
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
|
wxMenuItem* wxMenuItemBase::New(
|
||||||
int id,
|
wxMenu* pParentMenu
|
||||||
const wxString& name,
|
, int nId
|
||||||
const wxString& help,
|
, const wxString& rName
|
||||||
bool isCheckable,
|
, const wxString& rHelp
|
||||||
wxMenu *subMenu)
|
, bool bIsCheckable
|
||||||
|
, wxMenu* pSubMenu
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
|
return new wxMenuItem( pParentMenu
|
||||||
}
|
,nId
|
||||||
|
,rName
|
||||||
|
,rHelp
|
||||||
|
,bIsCheckable
|
||||||
|
,pSubMenu
|
||||||
|
);
|
||||||
|
} // end of wxMenuItemBase::New
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user