From 301d7a0da67f917447e4f594a85a218eea4e003b Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 12 Feb 2008 15:49:22 +0000 Subject: [PATCH] added wxWindow::ClientToWindowSize and WindowToClientSize helpers git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51737 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/window.tex | 33 +++++++++++++ include/wx/window.h | 4 ++ src/common/wincmn.cpp | 16 +++++++ tests/Makefile.in | 4 ++ tests/controls/clientsize.cpp | 85 ++++++++++++++++++++++++++++++++++ tests/makefile.bcc | 4 ++ tests/makefile.gcc | 4 ++ tests/makefile.vc | 4 ++ tests/makefile.wat | 4 ++ tests/test.bkl | 1 + tests/test_test_gui.dsp | 4 ++ tests/test_vc7_test_gui.vcproj | 2 + tests/test_vc8_test_gui.vcproj | 3 ++ 13 files changed, 168 insertions(+) create mode 100644 tests/controls/clientsize.cpp diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 28f53c5607..5e3731fe2b 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -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} diff --git a/include/wx/window.h b/include/wx/window.h index 013426c8f8..4451f8f50d 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -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) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index fd92806261..0c2f15dc96 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -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 ) diff --git a/tests/Makefile.in b/tests/Makefile.in index 56205bab41..14b4866478 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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 index 0000000000..8f87ed9b8b --- /dev/null +++ b/tests/controls/clientsize.cpp @@ -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 +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// 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())); +} diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 1c630af6ff..3f6fe75329 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -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 diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 9de958824d..ab7646b5b9 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -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) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 395b6c4ac6..3dc3d715ff 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -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 diff --git a/tests/makefile.wat b/tests/makefile.wat index 60d133b8cb..1cdce99cc9 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -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) $< diff --git a/tests/test.bkl b/tests/test.bkl index bfdcbbd93c..8d682b7998 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -92,6 +92,7 @@ geometry/size.cpp geometry/point.cpp config/config.cpp + controls/clientsize.cpp controls/textctrltest.cpp core diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index 635bbcfea2..e64be615d8 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -235,6 +235,10 @@ LINK32=link.exe # PROP Default_Filter "" # Begin Source File +SOURCE=.\controls\clientsize.cpp +# End Source File +# Begin Source File + SOURCE=.\config\config.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index e8e8ebaa51..73c760d662 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -649,6 +649,8 @@ Name="Source Files" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"> + + -- 2.45.2