]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxWindow::ClientToWindowSize and WindowToClientSize helpers
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 12 Feb 2008 15:49:22 +0000 (15:49 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 12 Feb 2008 15:49:22 +0000 (15:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51737 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
docs/latex/wx/window.tex
include/wx/window.h
src/common/wincmn.cpp
tests/Makefile.in
tests/controls/clientsize.cpp [new file with mode: 0644]
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test_gui.dsp
tests/test_vc7_test_gui.vcproj
tests/test_vc8_test_gui.vcproj

index 28f53c56074e642339971d572479a9d8c2e14a58..5e3731fe2b540047c24261440ba525caef43444a 100644 (file)
@@ -380,6 +380,23 @@ implements the following methods:\par
 \end{twocollist}}
 }
 
+\membersection{wxWindow::ClientToWindowSize}\label{wxwindowclienttowindowsize}
+
+\func{virtual wxSize}{ClientToWindowSize}{\param{const wxSize\&}{ size}}
+
+Converts client area size \arg{size} to corresponding window size. In other
+words, the returned value is what would \helpref{GetSize}{wxwindowgetsize}
+return if this window had client area of given size.
+Components with $wxDefaultCoord$ value are left unchanged.
+
+Note that the conversion is not always exact, it assumes that non-client area
+doesn't change and so doesn't take into account things like menu bar
+(un)wrapping or (dis)appearance of the scrollbars.
+
+\wxheading{See also}
+
+\helpref{wxWindow::WindowToClientSize}{wxwindowwindowtoclientsize}
+
 
 \membersection{wxWindow::Close}\label{wxwindowclose}
 
@@ -4033,3 +4050,19 @@ Interface Guidelines forbid moving the mouse cursor programmatically.
 
 \docparam{y}{The new y position for the cursor.}
 
+\membersection{wxWindow::WindowToClientSize}\label{wxwindowwindowtoclientsize}
+
+\func{virtual wxSize}{WindowToClientSize}{\param{const wxSize\&}{ size}}
+
+Converts window size \arg{size} to corresponding client area size. In other
+words, the returned value is what would
+\helpref{GetClientSize}{wxwindowgetclientsize} return if this window had
+given window size. Components with $wxDefaultCoord$ value are left unchanged. 
+
+Note that the conversion is not always exact, it assumes that non-client area
+doesn't change and so doesn't take into account things like menu bar
+(un)wrapping or (dis)appearance of the scrollbars.
+
+\wxheading{See also}
+
+\helpref{wxWindow::ClientToWindowSize}{wxwindowclienttowindowsize}
index 013426c8f80e1877375d33536654f199091830d7..4451f8f50d44dd74273417c10a974d9bf7e6c1e9 100644 (file)
@@ -355,6 +355,10 @@ public:
         return wxRect(GetClientAreaOrigin(), GetClientSize());
     }
 
+    // client<->window size conversion
+    virtual wxSize ClientToWindowSize(const wxSize& size) const;
+    virtual wxSize WindowToClientSize(const wxSize& size) const;
+
         // get the size best suited for the window (in fact, minimal
         // acceptable size using which it will still look "nice" in
         // most situations)
index fd92806261b8434bb85f0c2759bfc0ad05738918..0c2f15dc96f56319a12de22eb4475865b2375ec6 100644 (file)
@@ -713,6 +713,22 @@ wxPoint wxWindowBase::GetClientAreaOrigin() const
     return wxPoint(0,0);
 }
 
+wxSize wxWindowBase::ClientToWindowSize(const wxSize& size) const
+{
+    const wxSize diff(GetSize() - GetClientSize());
+
+    return wxSize(size.x == -1 ? -1 : size.x + diff.x,
+                  size.y == -1 ? -1 : size.y + diff.y);
+}
+
+wxSize wxWindowBase::WindowToClientSize(const wxSize& size) const
+{
+    const wxSize diff(GetSize() - GetClientSize());
+
+    return wxSize(size.x == -1 ? -1 : size.x - diff.x,
+                  size.y == -1 ? -1 : size.y - diff.y);
+}
+
 void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
 {
     if ( m_windowVariant != variant )
index 56205bab41b2b78b2f18c93a1a545a9e7143105a..14b486647827c9b948f3890c22e305e313e21114 100644 (file)
@@ -113,6 +113,7 @@ TEST_GUI_OBJECTS =  \
        test_gui_size.o \
        test_gui_point.o \
        test_gui_config.o \
+       test_gui_clientsize.o \
        test_gui_textctrltest.o
 TEST_GUI_ODEP =  $(___pch_testprec_test_gui_testprec_h_gch___depname)
 PRINTFBENCH_CXXFLAGS = $(__printfbench_PCH_INC) -D__WX$(TOOLKIT)__ \
@@ -487,6 +488,9 @@ test_gui_point.o: $(srcdir)/geometry/point.cpp $(TEST_GUI_ODEP)
 test_gui_config.o: $(srcdir)/config/config.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/config/config.cpp
 
+test_gui_clientsize.o: $(srcdir)/controls/clientsize.cpp $(TEST_GUI_ODEP)
+       $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/clientsize.cpp
+
 test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textctrltest.cpp
 
diff --git a/tests/controls/clientsize.cpp b/tests/controls/clientsize.cpp
new file mode 100644 (file)
index 0000000..8f87ed9
--- /dev/null
@@ -0,0 +1,85 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/controls/clientsize.cpp
+// Purpose:     Client vs. window size handling unit test
+// Author:      Vaclav Slavik
+// Created:     2008-02-12
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+    #include "wx/window.h"
+#endif // WX_PRECOMP
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class ClientSizeTestCase : public CppUnit::TestCase
+{
+public:
+    ClientSizeTestCase() { }
+
+    virtual void setUp();
+    virtual void tearDown();
+
+private:
+    CPPUNIT_TEST_SUITE( ClientSizeTestCase );
+        CPPUNIT_TEST( ClientToWindow );
+        CPPUNIT_TEST( WindowToClient );
+    CPPUNIT_TEST_SUITE_END();
+
+    void ClientToWindow();
+    void WindowToClient();
+
+    wxWindow *m_win;
+
+    DECLARE_NO_COPY_CLASS(ClientSizeTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( ClientSizeTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ClientSizeTestCase, "ClientSizeTestCase" );
+
+// ----------------------------------------------------------------------------
+// test initialization
+// ----------------------------------------------------------------------------
+
+void ClientSizeTestCase::setUp()
+{
+    m_win = wxTheApp->GetTopWindow();
+}
+
+void ClientSizeTestCase::tearDown()
+{
+    m_win = NULL;
+}
+
+// ----------------------------------------------------------------------------
+// tests themselves
+// ----------------------------------------------------------------------------
+
+void ClientSizeTestCase::ClientToWindow()
+{
+    CPPUNIT_ASSERT(m_win->GetSize() ==
+                   m_win->ClientToWindowSize(m_win->GetClientSize()));
+}
+
+void ClientSizeTestCase::WindowToClient()
+{
+    CPPUNIT_ASSERT(m_win->GetClientSize() ==
+                   m_win->WindowToClientSize(m_win->GetSize()));
+}
index 1c630af6ffd62be35a2857cbf6f53179961f9038..3f6fe75329294a1e9c62bdedf962ce0c73ee8393 100644 (file)
@@ -101,6 +101,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_size.obj \
        $(OBJS)\test_gui_point.obj \
        $(OBJS)\test_gui_config.obj \
+       $(OBJS)\test_gui_clientsize.obj \
        $(OBJS)\test_gui_textctrltest.obj
 PRINTFBENCH_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
        $(__OPTIMIZEFLAG) $(__THREADSFLAG_1) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
@@ -522,6 +523,9 @@ $(OBJS)\test_gui_point.obj: .\geometry\point.cpp
 $(OBJS)\test_gui_config.obj: .\config\config.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp
 
+$(OBJS)\test_gui_clientsize.obj: .\controls\clientsize.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\clientsize.cpp
+
 $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp
 
index 9de958824d374edc50f1a55db68088f387a633ec..ab7646b5b935a60028ef68c6a35ec951cb4805c4 100644 (file)
@@ -94,6 +94,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_size.o \
        $(OBJS)\test_gui_point.o \
        $(OBJS)\test_gui_config.o \
+       $(OBJS)\test_gui_clientsize.o \
        $(OBJS)\test_gui_textctrltest.o
 PRINTFBENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) \
        $(GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
@@ -500,6 +501,9 @@ $(OBJS)\test_gui_point.o: ./geometry/point.cpp
 $(OBJS)\test_gui_config.o: ./config/config.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\test_gui_clientsize.o: ./controls/clientsize.cpp
+       $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
index 395b6c4ac6388ee6a027203039ab573cd696f2fa..3dc3d715ff5aea1200e1419d664cc6ae3e304e25 100644 (file)
@@ -97,6 +97,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_size.obj \
        $(OBJS)\test_gui_point.obj \
        $(OBJS)\test_gui_config.obj \
+       $(OBJS)\test_gui_clientsize.obj \
        $(OBJS)\test_gui_textctrltest.obj
 PRINTFBENCH_CXXFLAGS = /M$(__RUNTIME_LIBS_38)$(__DEBUGRUNTIME) /DWIN32 \
        $(__DEBUGINFO) /Fd$(OBJS)\printfbench.pdb $(____DEBUGRUNTIME) \
@@ -607,6 +608,9 @@ $(OBJS)\test_gui_point.obj: .\geometry\point.cpp
 $(OBJS)\test_gui_config.obj: .\config\config.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp
 
+$(OBJS)\test_gui_clientsize.obj: .\controls\clientsize.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\clientsize.cpp
+
 $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp
 
index 60d133b8cbd67fadb76c44c38057ca80c8e10b57..1cdce99cc9fc775f9bca46a0dfab11b644733a74 100644 (file)
@@ -301,6 +301,7 @@ TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_size.obj &
        $(OBJS)\test_gui_point.obj &
        $(OBJS)\test_gui_config.obj &
+       $(OBJS)\test_gui_clientsize.obj &
        $(OBJS)\test_gui_textctrltest.obj
 PRINTFBENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
        $(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
@@ -552,6 +553,9 @@ $(OBJS)\test_gui_point.obj :  .AUTODEPEND .\geometry\point.cpp
 $(OBJS)\test_gui_config.obj :  .AUTODEPEND .\config\config.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
+$(OBJS)\test_gui_clientsize.obj :  .AUTODEPEND .\controls\clientsize.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
 $(OBJS)\test_gui_textctrltest.obj :  .AUTODEPEND .\controls\textctrltest.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
index bfdcbbd93c27900a0c4681b4bf328599f78f9cbc..8d682b799807400ebcba58ae65717e3ffe3cf30e 100644 (file)
@@ -92,6 +92,7 @@
             geometry/size.cpp
             geometry/point.cpp
             config/config.cpp
+            controls/clientsize.cpp
             controls/textctrltest.cpp
         </sources>
         <wx-lib>core</wx-lib>
index 635bbcfea20c872f9c9c91148080bb5c04b65177..e64be615d8d2acef5f8fb20257c77de323b2c45f 100644 (file)
@@ -235,6 +235,10 @@ LINK32=link.exe
 # PROP Default_Filter ""\r
 # Begin Source File\r
 \r
+SOURCE=.\controls\clientsize.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\config\config.cpp\r
 # End Source File\r
 # Begin Source File\r
index e8e8ebaa51e3928a6b67da8583265c1ed05577a5..73c760d662d8371a3a53e84733d8a49716b7fe0b 100644 (file)
                        Name="Source Files"\r
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
                        Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx">\r
+                       <File\r
+                               RelativePath=".\controls\clientsize.cpp"/>\r
                        <File\r
                                RelativePath=".\config\config.cpp"/>\r
                        <File\r
index e6ee8c2b194377d0d621cbbc1dc94fbc9fc2d328..3501c978c652cb5aab41bd0539f40f3cf47d5035 100644 (file)
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
                        Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
                        >\r
+                       <File\r
+                               RelativePath=".\controls\clientsize.cpp"\r
+                       />\r
                        <File\r
                                RelativePath=".\config\config.cpp"\r
                        />\r