Applied patch [ 1039456 ] [wxOS2]Popup menu problems

By Dave Parsons
Fixes problems including:

titles do not display,
title id is already allocated to the menu separator,
menus show in totally the wrong position,
possible to call DoPopupMenu with out of range parameters,
showing a menu enters an infinite loop with 100% cpu usage,
ProcessEvent is called destroying the return value from
HandleMouseEvent.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2004-10-07 18:35:50 +00:00
parent 004a805d3d
commit c82be69b51
2 changed files with 59 additions and 27 deletions

View File

@@ -47,7 +47,7 @@ extern wxMenu* wxCurrentPopupMenu;
// //
// The (popup) menu title has this special id // The (popup) menu title has this special id
// //
static const int idMenuTitle = -2; static const int idMenuTitle = -3;
// //
// The unique ID for Menus // The unique ID for Menus
@@ -280,7 +280,7 @@ bool wxMenu::DoInsertOrAppend(
rItem.id = pItem->GetId(); rItem.id = pItem->GetId();
} }
BYTE* pData; BYTE* pData=NULL;
#if wxUSE_OWNER_DRAWN #if wxUSE_OWNER_DRAWN
if (pItem->IsOwnerDrawn()) if (pItem->IsOwnerDrawn())
@@ -303,11 +303,19 @@ bool wxMenu::DoInsertOrAppend(
rItem.afStyle = MIS_SEPARATOR; rItem.afStyle = MIS_SEPARATOR;
} }
else else
{
if (pItem->GetId() == idMenuTitle)
{
// Item is an unselectable title to be passed via pData
rItem.afStyle = MIS_STATIC;
}
else
{ {
// //
// Menu is just a normal string (passed in data parameter) // Menu is just a normal string (passed in data parameter)
// //
rItem.afStyle |= MIS_TEXT; rItem.afStyle |= MIS_TEXT;
}
pData = (char*)pItem->GetText().c_str(); pData = (char*)pItem->GetText().c_str();
} }

View File

@@ -1951,6 +1951,11 @@ bool wxWindowOS2::DoPopupMenu(
HWND hWndParent = GetHwnd(); HWND hWndParent = GetHwnd();
HWND hMenu = GetHmenuOf(pMenu); HWND hMenu = GetHmenuOf(pMenu);
bool bIsWaiting = TRUE; bool bIsWaiting = TRUE;
int nHeight;
// Protect against recursion
if (wxCurrentPopupMenu)
return false;
pMenu->SetInvokingWindow(this); pMenu->SetInvokingWindow(this);
pMenu->UpdateUI(); pMenu->UpdateUI();
@@ -1965,6 +1970,8 @@ bool wxWindowOS2::DoPopupMenu(
DoClientToScreen( &nX DoClientToScreen( &nX
,&nY ,&nY
); );
DoGetSize(0,&nHeight);
nY = nHeight - nY;
} }
wxCurrentPopupMenu = pMenu; wxCurrentPopupMenu = pMenu;
@@ -1981,13 +1988,12 @@ bool wxWindowOS2::DoPopupMenu(
{ {
QMSG vMsg; QMSG vMsg;
if (vMsg.msg == WM_MENUEND || vMsg.msg == WM_COMMAND) ::WinGetMsg(vHabmain,&vMsg, (HWND)0, 0, 0);
{ if (vMsg.msg == WM_COMMAND)
bIsWaiting = FALSE; bIsWaiting = FALSE;
}
::WinDispatchMsg(vHabmain, (PQMSG)&vMsg); ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
} }
wxCurrentPopupMenu = NULL; wxCurrentPopupMenu = NULL;
pMenu->SetInvokingWindow(NULL); pMenu->SetInvokingWindow(NULL);
return TRUE; return TRUE;
@@ -2958,6 +2964,20 @@ MRESULT wxWindowOS2::OS2WindowProc(
mResult = (MRESULT)TRUE; mResult = (MRESULT)TRUE;
} }
break; break;
#if wxUSE_MENUS_NATIVE
case WM_MENUEND:
if (wxCurrentPopupMenu)
{
if (GetHmenuOf(wxCurrentPopupMenu) == (HWND)lParam)
{
// Break out of msg loop in DoPopupMenu
::WinPostMsg((HWND)lParam,WM_COMMAND,wParam,0);
}
}
break;
#endif // wxUSE_MENUS_NATIVE
} }
if (!bProcessed) if (!bProcessed)
{ {
@@ -4047,7 +4067,7 @@ bool wxWindowOS2::HandleMouseEvent(
// //
// The mouse events take consecutive IDs from WM_MOUSEFIRST to // The mouse events take consecutive IDs from WM_MOUSEFIRST to
// WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
// from the message id and take the value in the table to get wxWin event // from the message id and take the value in the table to get wxWin event
// id // id
// //
@@ -4065,6 +4085,9 @@ bool wxWindowOS2::HandleMouseEvent(
wxEVT_MIDDLE_DCLICK wxEVT_MIDDLE_DCLICK
}; };
// Bounds check
if ((uMsg >= WM_MOUSEMOVE) && (uMsg <= WM_BUTTON3DBLCLK))
{
wxMouseEvent vEvent(eventsMouse[uMsg - WM_MOUSEMOVE]); wxMouseEvent vEvent(eventsMouse[uMsg - WM_MOUSEMOVE]);
InitMouseEvent( vEvent InitMouseEvent( vEvent
@@ -4084,7 +4107,8 @@ bool wxWindowOS2::HandleMouseEvent(
bProcessed = TRUE; bProcessed = TRUE;
} }
} }
return GetEventHandler()->ProcessEvent(vEvent); }
return bProcessed;
} // end of wxWindowOS2::HandleMouseEvent } // end of wxWindowOS2::HandleMouseEvent
bool wxWindowOS2::HandleMouseMove( bool wxWindowOS2::HandleMouseMove(