added GetScreenPosition/Rect() which always return the screen coordinates of the window (for child windows and TLWs alike)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38071 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-03-14 15:45:12 +00:00
parent ad332e5bf3
commit 3c81c9aafb
4 changed files with 104 additions and 20 deletions

View File

@ -1111,9 +1111,9 @@ windows.
\wxheading{Parameters}
\docparam{x}{Receives the x position of the window.}
\docparam{x}{Receives the x position of the window if non-\NULL.}
\docparam{y}{Receives the y position of the window.}
\docparam{y}{Receives the y position of the window if non-\NULL.}
\pythonnote{In place of a single overloaded method name, wxPython
implements the following methods:\par
@ -1133,12 +1133,53 @@ method:\par
}}
\wxheading{See also}
\helpref{GetScreenPosition}{wxwindowgetscreenposition}
\membersection{wxWindow::GetRect}\label{wxwindowgetrect}
\constfunc{virtual wxRect}{GetRect}{\void}
Returns the size and position of the window as a \helpref{wxRect}{wxrect} object.
\wxheading{See also}
\helpref{GetScreenRect}{wxwindowgetscreenrect}
\membersection{wxWindow::GetScreenPosition}\label{wxwindowgetscreenposition}
\constfunc{virtual void}{GetScreenPosition}{\param{int* }{x}, \param{int* }{y}}
\constfunc{wxPoint}{GetScreenPosition}{\void}
Returns the window position in screen coordinates, whether the window is a
child window or a top level one.
\wxheading{Parameters}
\docparam{x}{Receives the x position of the window on the screen if non-\NULL.}
\docparam{y}{Receives the y position of the window on the screen if non-\NULL.}
\wxheading{See also}
\helpref{GetPosition}{wxwindowgetposition}
\membersection{wxWindow::GetScreenRect}\label{wxwindowgetscreenrect}
\constfunc{virtual wxRect}{GetScreenRect}{\void}
Returns the size and position of the window on the screen as a
\helpref{wxRect}{wxrect} object.
\wxheading{See also}
\helpref{GetRect}{wxwindowgetrect}
\membersection{wxWindow::GetScrollPos}\label{wxwindowgetscrollpos}

View File

@ -224,6 +224,12 @@ protected:
// add support for wxCENTRE_ON_SCREEN
virtual void DoCentre(int dir);
// no need to do client to screen translation to get our position in screen
// coordinates: this is already the case
virtual void DoGetScreenPosition(int *x, int *y) const
{
return DoGetPosition(x, y);
}
// test whether this window makes part of the frame
// (menubar, toolbar and statusbar are excluded from automatic layout)

View File

@ -222,6 +222,8 @@ public:
void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
{ Move(pt.x, pt.y, flags); }
void SetPosition(const wxPoint& pt) { Move(pt); }
// Z-order
virtual void Raise() = 0;
virtual void Lower() = 0;
@ -236,18 +238,30 @@ public:
void SetClientSize(const wxRect& rect)
{ SetClientSize( rect.width, rect.height ); }
// get the window position and/or size (pointers may be NULL)
// get the window position (pointers may be NULL): notice that it is in
// client coordinates for child windows and screen coordinates for the
// top level ones, use GetScreenPosition() if you need screen
// coordinates for all kinds of windows
void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
wxPoint GetPosition() const
{
int w, h;
DoGetPosition(&w, &h);
int x, y;
DoGetPosition(&x, &y);
return wxPoint(w, h);
return wxPoint(x, y);
}
void SetPosition( const wxPoint& pt ) { Move( pt ) ; }
// get the window position in screen coordinates
void GetScreenPosition(int *x, int *y) const { DoGetScreenPosition(x, y); }
wxPoint GetScreenPosition() const
{
int x, y;
DoGetScreenPosition(&x, &y);
return wxPoint(x, y);
}
// get the window size (pointers may be NULL)
void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
wxSize GetSize() const
{
@ -256,24 +270,34 @@ public:
return wxSize(w, h);
}
wxRect GetRect() const
{
int x, y, w, h;
GetPosition(& x, & y);
GetSize(& w, & h);
return wxRect(x, y, w, h);
}
void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
wxSize GetClientSize() const
{
int w, h;
DoGetClientSize(& w, & h);
DoGetClientSize(&w, &h);
return wxSize(w, h);
}
// get the position and size at once
wxRect GetRect() const
{
int x, y, w, h;
GetPosition(&x, &y);
GetSize(&w, &h);
return wxRect(x, y, w, h);
}
wxRect GetScreenRect() const
{
int x, y, w, h;
GetScreenPosition(&x, &y);
GetSize(&w, &h);
return wxRect(x, y, w, h);
}
// get the origin of the client area of the window relative to the
// window top left corner (the client area may be shifted because of
// the borders, scrollbars, other decorations...)
@ -1258,9 +1282,10 @@ protected:
virtual void DoReleaseMouse() = 0;
// retrieve the position/size of the window
virtual void DoGetPosition( int *x, int *y ) const = 0;
virtual void DoGetSize( int *width, int *height ) const = 0;
virtual void DoGetClientSize( int *width, int *height ) const = 0;
virtual void DoGetPosition(int *x, int *y) const = 0;
virtual void DoGetScreenPosition(int *x, int *y) const;
virtual void DoGetSize(int *width, int *height) const = 0;
virtual void DoGetClientSize(int *width, int *height) const = 0;
// get the size which best suits the window: for a control, it would be
// the minimal size which doesn't truncate the control, for a panel - the

View File

@ -715,6 +715,18 @@ wxSize wxWindowBase::DoGetVirtualSize() const
return size;
}
void wxWindowBase::DoGetScreenPosition(int *x, int *y) const
{
// screen position is the same as (0, 0) in client coords for non TLWs (and
// TLWs override this method)
if ( x )
*x = 0;
if ( y )
*y = 0;
return ClientToScreen(x, y);
}
// ----------------------------------------------------------------------------
// show/hide/enable/disable the window
// ----------------------------------------------------------------------------