]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
fixed memory leaks when parsing
[wxWidgets.git] / src / msw / window.cpp
index c41ea10850bd1ed83ad9e760d70ce62a23bce4bb..e9acd3dc698f923ccd1c3f9ade57f4cfb618cb57 100644 (file)
@@ -156,8 +156,25 @@ static void TranslateKbdEventToMouse(wxWindowMSW *win,
 // get the text metrics for the current font
 static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
 
-// check if the mouse is in the window or its child
-//static bool IsMouseInWindow(HWND hwnd);
+// wrapper around BringWindowToTop() API
+static inline void wxBringWindowToTop(HWND hwnd)
+{
+#ifdef __WXMICROWIN__
+    // It seems that MicroWindows brings the _parent_ of the window to the top,
+    // which can be the wrong one.
+
+    // activate (set focus to) specified window
+    ::SetFocus(hwnd);
+
+    // raise top level parent to top of z order
+    ::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+#else // !__WXMICROWIN__
+    if ( !::BringWindowToTop(hwnd) )
+    {
+        wxLogLastError(_T("BringWindowToTop"));
+    }
+#endif // __WXMICROWIN__/!__WXMICROWIN__
+}
 
 // ---------------------------------------------------------------------------
 // event tables
@@ -503,19 +520,7 @@ bool wxWindowMSW::Show(bool show)
 
     if ( show )
     {
-#ifdef __WXMICROWIN__
-        // It seems that MicroWindows brings the _parent_ of the
-        // window to the top, which can be the wrong one.
-
-        // activate (set focus to) specified window
-        ::SetFocus(hWnd);
-
-        // raise top level parent to top of z order
-        ::SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0,
-                SWP_NOMOVE|SWP_NOSIZE);
-#else
-        BringWindowToTop(hWnd);
-#endif
+        wxBringWindowToTop(hWnd);
     }
 
     return TRUE;
@@ -524,22 +529,7 @@ bool wxWindowMSW::Show(bool show)
 // Raise the window to the top of the Z order
 void wxWindowMSW::Raise()
 {
-#ifdef __WIN16__
-    ::BringWindowToTop(GetHwnd());
-#else // Win32
-#ifdef __WXMICROWIN__
-    // It seems that MicroWindows brings the _parent_ of the
-    // window to the top, which can be the wrong one.
-
-    // activate (set focus to) specified window
-    ::SetFocus(GetHwnd());
-
-    // raise top level parent to top of z order
-    ::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
-#else
-    ::SetForegroundWindow(GetHwnd());
-#endif
-#endif
+    wxBringWindowToTop(GetHwnd());
 }
 
 // Lower the window to the bottom of the Z order
@@ -1845,9 +1835,9 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                         }
                         // FIXME: this should be handled by
                         //        wxNavigationKeyEvent handler and not here!!
-#if wxUSE_BUTTON
                         else
                         {
+#if wxUSE_BUTTON
                             wxButton *btn = wxDynamicCast(GetDefaultItem(),
                                                           wxButton);
                             if ( btn && btn->IsEnabled() )
@@ -1857,11 +1847,15 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
 
                                 return TRUE;
                             }
-                            // else: but if it does not it makes sense to make
-                            //       it work like a TAB - and that's what we do.
-                            //       Note that Ctrl-Enter always works this way.
-                        }
+                            else // no default button
 #endif // wxUSE_BUTTON
+                            {
+                                // no special function for enter and don't even
+                                // let IsDialogMessage() have it: it seems to
+                                // do something really strange with it
+                                return FALSE;
+                            }
+                        }
                     }
                     break;
 
@@ -1882,7 +1876,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                 }
             }
         }
-#else
+#else // 0
         // let ::IsDialogMessage() do almost everything and handle just the
         // things it doesn't here: Ctrl-TAB for switching notebook pages
         if ( msg->message == WM_KEYDOWN )
@@ -1910,7 +1904,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                 }
             }
         }
-#endif // 0
+#endif // 1/0
 
         if ( ::IsDialogMessage(GetHwnd(), msg) )
         {
@@ -2128,7 +2122,11 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             break;
 
         case WM_DESTROY:
-            processed = HandleDestroy();
+            // never set processed to TRUE and *always* pass WM_DESTROY to
+            // DefWindowProc() as Windows may do some internal cleanup when
+            // processing it and failing to pass the message along may cause
+            // memory and resource leaks!
+            (void)HandleDestroy();
             break;
 
         case WM_MOVE:
@@ -3023,15 +3021,16 @@ bool wxWindowMSW::HandleEndSession(bool endSession, long logOff)
     if ( !endSession )
         return FALSE;
 
+    // only send once
+    if ( (this != wxTheApp->GetTopWindow()) )
+        return FALSE;
+
     wxCloseEvent event(wxEVT_END_SESSION, -1);
     event.SetEventObject(wxTheApp);
     event.SetCanVeto(FALSE);
     event.SetLoggingOff( (logOff == (long)ENDSESSION_LOGOFF) );
-    if ( (this == wxTheApp->GetTopWindow()) && // Only send once
-        wxTheApp->ProcessEvent(event))
-    {
-    }
-    return TRUE;
+
+    return wxTheApp->ProcessEvent(event);
 }
 
 // ---------------------------------------------------------------------------
@@ -3194,7 +3193,8 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
 
     wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
     event.m_eventObject = this;
-    event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y;
+    event.m_pos.x = dropPoint.x;
+    event.m_pos.y = dropPoint.y;
 
     bool rc = GetEventHandler()->ProcessEvent(event);