From a0a0e2b8d83959148615c080b0e3317da7cbb950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 5 Mar 2008 14:19:38 +0000 Subject: [PATCH] backported ClientToWindowSize(), WindowToClientSize() to 2.8 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@52330 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/window.tex | 37 +++++++++++++++++++++++++++++++++++++ include/wx/window.h | 6 ++++++ src/common/wincmn.cpp | 16 ++++++++++++++++ version-script.in | 2 ++ 5 files changed, 62 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index e960409bdf..4a9e3d9b9d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -120,6 +120,7 @@ All (GUI): - Remove associated help text from wxHelpProvider when a window is destroyed. - Added wxSizerFlags::ReserveSpaceEvenIfHidden() and wxRESERVE_SPACE_EVEN_IF_HIDDEN sizer flag. +- Added wxWindow::ClientToWindowSize() and WindowToClientSize() helpers. All (Unix): diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 7a4b1e4b5b..1023537565 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -343,6 +343,25 @@ implements the following methods:\par \end{twocollist}} } +\membersection{wxWindow::ClientToWindowSize}\label{wxwindowclienttowindowsize} + +\func{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. + +\since{2.8.8} + +\wxheading{See also} + +\helpref{wxWindow::WindowToClientSize}{wxwindowwindowtoclientsize} + \membersection{wxWindow::Close}\label{wxwindowclose} @@ -3731,3 +3750,21 @@ 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. + +\since{2.8.8} + +\wxheading{See also} + +\helpref{wxWindow::ClientToWindowSize}{wxwindowclienttowindowsize} diff --git a/include/wx/window.h b/include/wx/window.h index 3477511474..aeae05a689 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -326,6 +326,12 @@ public: return wxRect(GetClientAreaOrigin(), GetClientSize()); } +#if wxABI_VERSION >= 20808 + // client<->window size conversion + wxSize ClientToWindowSize(const wxSize& size) const; + wxSize WindowToClientSize(const wxSize& size) const; +#endif + // 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 4525d893da..7183689ea0 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -755,6 +755,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/version-script.in b/version-script.in index 90e4d2d0c4..6a250aa781 100644 --- a/version-script.in +++ b/version-script.in @@ -39,7 +39,9 @@ *wxScrollHelper*HandleOnChildFocus*; *wxSizerFlags*ReserveSpaceEvenIfHidden*; *wxSizerItem*ShouldAccountFor*; + *wxWindowBase*ClientToWindowSize*; *wxWindowBase*Get*Sibling*; + *wxWindowBase*WindowToClientSize*; }; # public symbols added in 2.8.7 (please keep in alphabetical order):