]> git.saurik.com Git - wxWidgets.git/commitdiff
Ensure that we never return negative client size.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 16 May 2011 14:07:40 +0000 (14:07 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 16 May 2011 14:07:40 +0000 (14:07 +0000)
wxMSW could return negative client size for tiny windows with borders, this
was unexpected and shouldn't happen so explicitly ensure it does not.

Also add a unit test to check that this problem doesn't exist in other ports.

Closes #13184.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/window.cpp
tests/window/clientsize.cpp

index 8a34b50fa98a60d4127b676ab0a9957155690218..246f47ba11d87546f03aefb9747703c564ea22ae 100644 (file)
@@ -1787,6 +1787,15 @@ void wxWindowMSW::DoGetClientSize(int *x, int *y) const
         if ( y )
             *y = rect.bottom;
     }
         if ( y )
             *y = rect.bottom;
     }
+
+    // The size of the client window can't be negative but ::GetClientRect()
+    // can return negative size for an extremely small (1x1) window with
+    // borders so ensure that we correct it here as having negative sizes is
+    // completely unexpected.
+    if ( x && *x < 0 )
+        *x = 0;
+    if ( y && *y < 0 )
+        *y = 0;
 }
 
 void wxWindowMSW::DoGetPosition(int *x, int *y) const
 }
 
 void wxWindowMSW::DoGetPosition(int *x, int *y) const
index 1b075fa1f6b3314c2162f5b60a9b70e0f2cc277a..57089680ef9ac813f3b41cec585f8e48e660352a 100644 (file)
@@ -37,10 +37,12 @@ public:
 private:
     CPPUNIT_TEST_SUITE( ClientSizeTestCase );
         CPPUNIT_TEST( ClientToWindow );
 private:
     CPPUNIT_TEST_SUITE( ClientSizeTestCase );
         CPPUNIT_TEST( ClientToWindow );
+        CPPUNIT_TEST( ClientSizeNotNegative );
         CPPUNIT_TEST( WindowToClient );
     CPPUNIT_TEST_SUITE_END();
 
     void ClientToWindow();
         CPPUNIT_TEST( WindowToClient );
     CPPUNIT_TEST_SUITE_END();
 
     void ClientToWindow();
+    void ClientSizeNotNegative();
     void WindowToClient();
 
     wxWindow *m_win;
     void WindowToClient();
 
     wxWindow *m_win;
@@ -78,6 +80,18 @@ void ClientSizeTestCase::ClientToWindow()
                    m_win->ClientToWindowSize(m_win->GetClientSize()));
 }
 
                    m_win->ClientToWindowSize(m_win->GetClientSize()));
 }
 
+void ClientSizeTestCase::ClientSizeNotNegative()
+{
+    wxWindow* w = new wxWindow(wxTheApp->GetTopWindow(), -1,
+                               wxDefaultPosition, wxDefaultSize,
+                               wxBORDER_THEME);
+    w->SetSize(wxSize(1,1));
+    const wxSize szw = w->GetClientSize();
+    CPPUNIT_ASSERT(szw.GetWidth() >= 0);
+    CPPUNIT_ASSERT(szw.GetHeight() >= 0);
+    w->Destroy();
+}
+
 void ClientSizeTestCase::WindowToClient()
 {
     CPPUNIT_ASSERT(m_win->GetClientSize() ==
 void ClientSizeTestCase::WindowToClient()
 {
     CPPUNIT_ASSERT(m_win->GetClientSize() ==