]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
fixed parsing of comments before root node
[wxWidgets.git] / src / msw / window.cpp
index fe4e04543c570606e6114287a7d00887afbf8888..02d6431d796c73d5b037861a39fb4c6dda9d7c1f 100644 (file)
@@ -288,6 +288,18 @@ wxWindow::~wxWindow()
     m_isBeingDeleted = TRUE;
 
     MSWDetachWindowMenu();
+    
+    // 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;
+        }
+    }
 
     if ( m_parent )
         m_parent->RemoveChild(this);
@@ -2201,55 +2213,61 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                 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)
                 {
-                    wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
-                    helpEvent.SetEventObject(this);
-                    eventProcessed = GetEventHandler()->ProcessEvent(helpEvent);
+                    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();
+                    }
 
-                    // Go up the window hierarchy until the event is handled (or not)
-                    subjectOfHelp = subjectOfHelp->GetParent();
+                    processed = eventProcessed;
                 }
-                processed = eventProcessed;
-            }
-            else if (info->iContextType == HELPINFO_MENUITEM)
-            {
-                wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
-                helpEvent.SetEventObject(this);
-                processed = GetEventHandler()->ProcessEvent(helpEvent);
+                else if (info->iContextType == HELPINFO_MENUITEM)
+                {
+                    wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
+                    helpEvent.SetEventObject(this);
+                    processed = GetEventHandler()->ProcessEvent(helpEvent);
 
+                }
+                //else: processed is already FALSE
             }
-            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;
-            
+            {
+                // 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);
+                GetEventHandler()->ProcessEvent(evtCtx);
+
+                // 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 )
@@ -2917,19 +2935,20 @@ bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
 
         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);
@@ -3097,9 +3116,8 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
     if ( ::IsIconic(GetHwnd()) )
         return TRUE;
 
-    wxDC dc;
+    wxDCTemp dc(hdc);
 
-    dc.SetHDC(hdc);
     dc.SetWindow(this);
     dc.BeginDrawing();
 
@@ -3108,8 +3126,9 @@ bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
     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;
 }
@@ -4006,8 +4025,9 @@ void wxSetKeyboardHook(bool doIt)
     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