Fixed wxMenuItem::Enable.
Added unique IDs to all menus (using a new static member of wxMenu). Use wxWindow's ID as menu item ID seen by OS/2. Rewrote wxMenu::DoInsertOrAppend which now uses the MENUITEM of the submenu or menu item which already contains most of the needed informations (especially the ID!) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7238 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -154,6 +154,11 @@ private:
|
|||||||
//
|
//
|
||||||
WXHMENU m_hMenu;
|
WXHMENU m_hMenu;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The helper variable for creating unique IDs.
|
||||||
|
//
|
||||||
|
static USHORT m_nextMenuId;
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
//
|
//
|
||||||
// The accelerators for our menu items
|
// The accelerators for our menu items
|
||||||
|
@@ -49,6 +49,10 @@ extern wxMenu* wxCurrentPopupMenu;
|
|||||||
//
|
//
|
||||||
static const int idMenuTitle = -2;
|
static const int idMenuTitle = -2;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The unique ID for Menus
|
||||||
|
//
|
||||||
|
static USHORT wxMenu::m_nextMenuId = 0;
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// macros
|
// macros
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -132,7 +136,7 @@ void wxMenu::Init()
|
|||||||
m_vMenuData.iPosition = 0;
|
m_vMenuData.iPosition = 0;
|
||||||
m_vMenuData.afStyle = MIS_SUBMENU | MIS_TEXT;
|
m_vMenuData.afStyle = MIS_SUBMENU | MIS_TEXT;
|
||||||
m_vMenuData.afAttribute = (USHORT)0;
|
m_vMenuData.afAttribute = (USHORT)0;
|
||||||
m_vMenuData.id = (USHORT)0;
|
m_vMenuData.id = m_nextMenuId++;
|
||||||
m_vMenuData.hwndSubMenu = m_hMenu;
|
m_vMenuData.hwndSubMenu = m_hMenu;
|
||||||
m_vMenuData.hItem = NULLHANDLE;
|
m_vMenuData.hItem = NULLHANDLE;
|
||||||
|
|
||||||
@@ -256,13 +260,24 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
{
|
{
|
||||||
ERRORID vError;
|
ERRORID vError;
|
||||||
wxString sError;
|
wxString sError;
|
||||||
MENUITEM vItem;
|
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
UpdateAccel(pItem);
|
UpdateAccel(pItem);
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
memset(&vItem, '\0', sizeof(vItem));
|
//
|
||||||
|
// rItem is the member MENUITEM for the menu items and the submenu's
|
||||||
|
// MENUITEM for submenus as required by ::MM_INSERTITEM message API
|
||||||
|
//
|
||||||
|
|
||||||
|
wxMenu* pSubmenu = pItem->GetSubMenu();
|
||||||
|
MENUITEM &rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
|
||||||
|
pItem->m_vMenuData;
|
||||||
|
if(pSubmenu != NULL)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
|
||||||
|
pSubmenu->SetParent(this);
|
||||||
|
rItem.afStyle |= MIS_SUBMENU | MIS_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If "Break" has just been called, insert a menu break before this item
|
// If "Break" has just been called, insert a menu break before this item
|
||||||
@@ -270,40 +285,13 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
//
|
//
|
||||||
if (m_bDoBreak)
|
if (m_bDoBreak)
|
||||||
{
|
{
|
||||||
vItem.afStyle |= MIS_BREAK;
|
rItem.afStyle |= MIS_BREAK;
|
||||||
m_bDoBreak = FALSE;
|
m_bDoBreak = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Menu items that are being inserted into a submenu MUST have a
|
|
||||||
// MENUITEM structure separate from the parent menu so we must use
|
|
||||||
// a local vItem not the object's m_vMenuItem as that is the MENUITEM
|
|
||||||
// associated with the parent submenu.
|
|
||||||
//
|
|
||||||
if (pItem->IsSeparator())
|
if (pItem->IsSeparator())
|
||||||
{
|
{
|
||||||
vItem.afStyle |= MIS_SEPARATOR;
|
rItem.afStyle |= MIS_SEPARATOR;
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Id is the numeric id for normal menu items and HMENU for submenus as
|
|
||||||
// required by ::MM_INSERTITEM message API
|
|
||||||
//
|
|
||||||
|
|
||||||
wxMenu* pSubmenu = pItem->GetSubMenu();
|
|
||||||
|
|
||||||
if (pSubmenu != NULL)
|
|
||||||
{
|
|
||||||
wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
|
|
||||||
pSubmenu->SetParent(this);
|
|
||||||
|
|
||||||
vItem.iPosition = 0; // submenus have a 0 position
|
|
||||||
vItem.id = (USHORT)pSubmenu->GetHMenu();
|
|
||||||
vItem.afStyle |= MIS_SUBMENU | MIS_TEXT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vItem.id = pItem->GetId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BYTE* pData;
|
BYTE* pData;
|
||||||
@@ -316,7 +304,7 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
// item draws itself, pass pointer to it in data parameter
|
// item draws itself, pass pointer to it in data parameter
|
||||||
// Will eventually need to set the image handle somewhere into vItem.hItem
|
// Will eventually need to set the image handle somewhere into vItem.hItem
|
||||||
//
|
//
|
||||||
vItem.afStyle |= MIS_OWNERDRAW;
|
rItem.afStyle |= MIS_OWNERDRAW;
|
||||||
pData = (BYTE*)pItem;
|
pData = (BYTE*)pItem;
|
||||||
// vItem.hItem = ????
|
// vItem.hItem = ????
|
||||||
}
|
}
|
||||||
@@ -326,28 +314,23 @@ bool wxMenu::DoInsertOrAppend(
|
|||||||
//
|
//
|
||||||
// Menu is just a normal string (passed in data parameter)
|
// Menu is just a normal string (passed in data parameter)
|
||||||
//
|
//
|
||||||
vItem.afStyle |= MIS_TEXT;
|
rItem.afStyle |= MIS_TEXT;
|
||||||
pData = (char*)pItem->GetText().c_str();
|
pData = (char*)pItem->GetText().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nPos == (size_t)-1)
|
||||||
|
{
|
||||||
|
rItem.iPosition = MIT_END;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rItem.iPosition = nPos;
|
||||||
|
}
|
||||||
|
|
||||||
APIRET rc;
|
APIRET rc;
|
||||||
|
|
||||||
if (pSubmenu == NULL)
|
rc = (APIRET)::WinSendMsg(GetHmenu(), MM_INSERTITEM,
|
||||||
{
|
(MPARAM)&rItem, (MPARAM)pData);
|
||||||
//
|
|
||||||
// -1 means append at end
|
|
||||||
//
|
|
||||||
if (nPos == (size_t)-1)
|
|
||||||
{
|
|
||||||
vItem.iPosition = MIT_END;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vItem.iPosition = nPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = (APIRET)::WinSendMsg(GetHmenu(), MM_INSERTITEM, (MPARAM)&vItem, (MPARAM)pData);
|
|
||||||
if (rc == MIT_MEMERROR || rc == MIT_ERROR)
|
if (rc == MIT_MEMERROR || rc == MIT_ERROR)
|
||||||
{
|
{
|
||||||
vError = ::WinGetLastError(vHabmain);
|
vError = ::WinGetLastError(vHabmain);
|
||||||
@@ -709,7 +692,6 @@ WXHMENU wxMenuBar::Create()
|
|||||||
APIRET rc;
|
APIRET rc;
|
||||||
ERRORID vError;
|
ERRORID vError;
|
||||||
wxString sError;
|
wxString sError;
|
||||||
MENUITEM vItem;
|
|
||||||
HWND hSubMenu;
|
HWND hSubMenu;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -773,7 +755,7 @@ void wxMenuBar::EnableTop(
|
|||||||
wxLogLastError("LogLastError");
|
wxLogLastError("LogLastError");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
::WinSendMsg((HWND)m_hMenu, MM_SETITEMATTR, MPFROM2SHORT(nId, TRUE), MPFROM2SHORT(uFlag, uFlag));
|
::WinSendMsg((HWND)m_hMenu, MM_SETITEMATTR, MPFROM2SHORT(nId, TRUE), MPFROM2SHORT(MIA_DISABLED, uFlag));
|
||||||
Refresh();
|
Refresh();
|
||||||
} // end of wxMenuBar::EnableTop
|
} // end of wxMenuBar::EnableTop
|
||||||
|
|
||||||
|
@@ -155,6 +155,8 @@ wxMenuItem::wxMenuItem(
|
|||||||
m_text = TextToLabel(rText);
|
m_text = TextToLabel(rText);
|
||||||
m_isCheckable = bCheckable;
|
m_isCheckable = bCheckable;
|
||||||
m_help = rStrHelp;
|
m_help = rStrHelp;
|
||||||
|
memset(&m_vMenuData, '\0', sizeof(m_vMenuData));
|
||||||
|
m_vMenuData.id= nId;
|
||||||
} // end of wxMenuItem::wxMenuItem
|
} // end of wxMenuItem::wxMenuItem
|
||||||
|
|
||||||
wxMenuItem::~wxMenuItem()
|
wxMenuItem::~wxMenuItem()
|
||||||
@@ -233,13 +235,13 @@ void wxMenuItem::Enable(
|
|||||||
bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
|
bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
,MM_SETITEMATTR
|
,MM_SETITEMATTR
|
||||||
,MPFROM2SHORT(GetRealId(), TRUE)
|
,MPFROM2SHORT(GetRealId(), TRUE)
|
||||||
,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
|
,MPFROM2SHORT(MIA_DISABLED, FALSE)
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
|
bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
|
||||||
,MM_SETITEMATTR
|
,MM_SETITEMATTR
|
||||||
,MPFROM2SHORT(GetRealId(), TRUE)
|
,MPFROM2SHORT(GetRealId(), TRUE)
|
||||||
,MPFROM2SHORT(MIA_DISABLED, FALSE)
|
,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
|
||||||
);
|
);
|
||||||
if (!bOk)
|
if (!bOk)
|
||||||
{
|
{
|
||||||
@@ -271,7 +273,7 @@ void wxMenuItem::Check(
|
|||||||
);
|
);
|
||||||
if (!bOk)
|
if (!bOk)
|
||||||
{
|
{
|
||||||
wxLogLastError("EnableMenuItem");
|
wxLogLastError("CheckMenuItem");
|
||||||
}
|
}
|
||||||
wxMenuItemBase::Check(bCheck);
|
wxMenuItemBase::Check(bCheck);
|
||||||
} // end of wxMenuItem::Check
|
} // end of wxMenuItem::Check
|
||||||
|
Reference in New Issue
Block a user