#include <string.h>
-#ifndef __GNUWIN32_OLD__
+#if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
#include <shellapi.h>
#include <mmsystem.h>
#endif
#include <windowsx.h>
#endif
-#if !defined(__GNUWIN32_OLD__) && !defined(__TWIN32__)
+#if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__)) || defined(__CYGWIN10__)
#ifdef __WIN95__
#include <commctrl.h>
#endif
MSWDetachWindowMenu();
- if ( m_parent )
- m_parent->RemoveChild(this);
+ // VS: make sure there's no wxFrame with last focus set to us:
+ for (wxWindow *win = GetParent(); win; win = win->GetParent())
+ {
+ wxFrame *frame = wxDynamicCast(win, wxFrame);
+ if ( frame )
+ {
+ if ( frame->GetLastFocus() == this )
+ frame->SetLastFocus((wxWindow*)NULL);
+ break;
+ }
+ }
+ // VS: destroy children first and _then_ detach *this from its parent.
+ // If we'd do it the other way around, children wouldn't be able
+ // find their parent frame (see above).
DestroyChildren();
+ if ( m_parent )
+ m_parent->RemoveChild(this);
+
if ( m_hWnd )
{
// VZ: test temp removed to understand what really happens here
// Raise the window to the top of the Z order
void wxWindow::Raise()
{
+#ifdef __WIN16__
::BringWindowToTop(GetHwnd());
+#else // Win32
+ ::SetForegroundWindow(GetHwnd());
+#endif
}
// Lower the window to the bottom of the Z order
// popup menu
// ---------------------------------------------------------------------------
+// yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
+// immediately, without waiting for the next event loop iteration
+//
+// NB: this function should probably be made public later as it can almost
+// surely replace wxYield() elsewhere as well
+static void wxYieldForCommandsOnly()
+{
+ // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
+ // want to process it here)
+ MSG msg;
+ while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE)
+ && msg.message != WM_QUIT )
+ {
+ wxTheApp->DoMessage((WXMSG *)&msg);
+ }
+}
+
bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
{
menu->SetInvokingWindow(this);
::ClientToScreen(hWnd, &point);
wxCurrentPopupMenu = menu;
::TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL);
- wxYieldIfNeeded();
+
+ // we need to do it righ now as otherwise the events are never going to be
+ // sent to wxCurrentPopupMenu from HandleCommand()
+ //
+ // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
+ // help and we'd still need wxYieldForCommandsOnly() as the menu may be
+ // destroyed as soon as we return (it can be a local variable in the caller
+ // for example) and so we do need to process the event immediately
+ wxYieldForCommandsOnly();
+
wxCurrentPopupMenu = NULL;
menu->SetInvokingWindow(NULL);
rc.result = TRUE;
}
break;
+
#ifdef __WIN32__
case WM_HELP:
- {
- HELPINFO* info = (HELPINFO*) lParam;
- // Don't yet process menu help events, just windows
- if (info->iContextType == HELPINFO_WINDOW)
{
- wxWindow* subjectOfHelp = this;
- bool eventProcessed = FALSE;
- while (subjectOfHelp && !eventProcessed)
+ HELPINFO* info = (HELPINFO*) lParam;
+ // Don't yet process menu help events, just windows
+ if (info->iContextType == HELPINFO_WINDOW)
+ {
+ wxWindow* subjectOfHelp = this;
+ bool eventProcessed = FALSE;
+ while (subjectOfHelp && !eventProcessed)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP,
+ subjectOfHelp->GetId(),
+ wxPoint(info->MousePos.x,
+ info->MousePos.y) );
+ helpEvent.SetEventObject(this);
+ eventProcessed =
+ GetEventHandler()->ProcessEvent(helpEvent);
+
+ // Go up the window hierarchy until the event is
+ // handled (or not)
+ subjectOfHelp = subjectOfHelp->GetParent();
+ }
+
+ processed = eventProcessed;
+ }
+ else if (info->iContextType == HELPINFO_MENUITEM)
{
- wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
+ wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
helpEvent.SetEventObject(this);
- eventProcessed = GetEventHandler()->ProcessEvent(helpEvent);
+ processed = GetEventHandler()->ProcessEvent(helpEvent);
- // Go up the window hierarchy until the event is handled (or not)
- subjectOfHelp = subjectOfHelp->GetParent();
}
- processed = eventProcessed;
+ //else: processed is already FALSE
}
- else if (info->iContextType == HELPINFO_MENUITEM)
+ break;
+
+ case WM_CONTEXTMENU:
{
- wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
- helpEvent.SetEventObject(this);
- processed = GetEventHandler()->ProcessEvent(helpEvent);
+ // we don't convert from screen to client coordinates as
+ // the event may be handled by a parent window
+ wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+ wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
+ processed = GetEventHandler()->ProcessEvent(evtCtx);
}
- else processed = FALSE;
break;
- }
- case WM_CONTEXTMENU:
- {
- HWND hWnd = (HWND) wParam;
-
- // we don't convert from screen to client coordinates as
- // the event may be handled by a parent window
- wxPoint p(LOWORD(lParam), HIWORD(lParam));
-
- wxContextMenuEvent contextEvent(wxEVT_CONTEXT_MENU, GetId(), p);
- GetEventHandler()->ProcessEvent(contextEvent);
-
- // set processed to true even if the event is not handled because if we don't
- // windows will propogate the WM_CONTEXTMENU up the parent window chain, which
- // we have already done ourselves.
- processed = true;
-
- break;
- }
-#endif
+#endif // __WIN32__
}
if ( !processed )
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
- // prepare to call OnDrawItem()
- wxDC dc;
- dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
+ // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
+ // the DC from being released
+ wxDCTemp dc((WXHDC)pDrawStruct->hDC);
wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
return pMenuItem->OnDrawItem
- (
- dc, rect,
- (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
- (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
- );
+ (
+ dc,
+ rect,
+ (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
+ (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
+ );
}
wxWindow *item = FindItem(id);
if ( ::IsIconic(GetHwnd()) )
return TRUE;
- wxDC dc;
+ wxDCTemp dc(hdc);
- dc.SetHDC(hdc);
dc.SetWindow(this);
dc.BeginDrawing();
bool rc = GetEventHandler()->ProcessEvent(event);
dc.EndDrawing();
+
+ // must be called manually as ~wxDC doesn't do anything for wxDCTemp
dc.SelectOldObjects(hdc);
- dc.SetHDC((WXHDC) NULL);
return rc;
}
if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
m_lastMouseEvent == wxEVT_LEFT_DOWN ||
m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
- (m_lastMouseX == event.m_x && m_lastMouseY == event.m_y) )
+ (m_lastMouseX == x && m_lastMouseY == y) )
{
m_lastMouseEvent = wxEVT_MOTION;
return GetEventHandler()->ProcessEvent(event);
#else
+ (void) wParam;
+ (void) lParam;
+
return FALSE;
#endif
}
else
{
UnhookWindowsHookEx(wxTheKeyboardHook);
- // avoids warning about statement with no effect (FreeProcInstance
- // doesn't do anything under Win32)
+
+ // avoids warning about statement with no effect (FreeProcInstance
+ // doesn't do anything under Win32)
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(__NT__) && !defined(__GNUWIN32__)
FreeProcInstance(wxTheKeyboardHookProc);
#endif