Centre() supports wxCENTER_FRAME flag now
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3138 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -137,7 +137,9 @@ Centres the window.
|
|||||||
\wxheading{Parameters}
|
\wxheading{Parameters}
|
||||||
|
|
||||||
\docparam{direction}{Specifies the direction for the centering. May be {\tt wxHORIZONTAL}, {\tt wxVERTICAL}\rtfsp
|
\docparam{direction}{Specifies the direction for the centering. May be {\tt wxHORIZONTAL}, {\tt wxVERTICAL}\rtfsp
|
||||||
or {\tt wxBOTH}.}
|
or {\tt wxBOTH}. It may also include {\tt wxCENTER\_FRAME} flag if you want to center the window
|
||||||
|
on its parent and not on the screen (actually, this flag is added automatically for all controls
|
||||||
|
because it makes no sense to center them on the screen)}
|
||||||
|
|
||||||
\wxheading{Remarks}
|
\wxheading{Remarks}
|
||||||
|
|
||||||
|
@@ -257,10 +257,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// centre with respect to the the parent window
|
// centre with respect to the the parent window
|
||||||
void Centre( int direction = wxHORIZONTAL );
|
void Centre( int direction = wxBOTH );
|
||||||
void Center( int direction = wxHORIZONTAL ) { Centre(direction); }
|
void Center( int direction = wxBOTH ) { Centre(direction); }
|
||||||
void CentreOnParent(int direction = wxHORIZONTAL );
|
void CentreOnParent( int dir = wxBOTH ) { Centre(dir | wxCENTER_FRAME); }
|
||||||
void CenterOnParent(int direction = wxHORIZONTAL ) { CentreOnParent(direction); }
|
void CenterOnParent( int dir = wxBOTH ) { Centre(dir | wxCENTER_FRAME); }
|
||||||
|
|
||||||
// set window size to wrap around its children
|
// set window size to wrap around its children
|
||||||
virtual void Fit();
|
virtual void Fit();
|
||||||
|
@@ -314,44 +314,27 @@ void wxWindowBase::Centre(int direction)
|
|||||||
int width, height;
|
int width, height;
|
||||||
GetSize(&width, &height);
|
GetSize(&width, &height);
|
||||||
|
|
||||||
int new_x = -1,
|
int xNew = -1,
|
||||||
new_y = -1;
|
yNew = -1;
|
||||||
|
|
||||||
if ( direction & wxHORIZONTAL )
|
if ( direction & wxHORIZONTAL )
|
||||||
new_x = (widthParent - width)/2;
|
xNew = (widthParent - width)/2;
|
||||||
|
|
||||||
if ( direction & wxVERTICAL )
|
if ( direction & wxVERTICAL )
|
||||||
new_y = (heightParent - height)/2;
|
yNew = (heightParent - height)/2;
|
||||||
|
|
||||||
Move(new_x, new_y);
|
// controls are always centered on their parent because it doesn't make
|
||||||
}
|
// sense to centre them on the screen
|
||||||
|
if ( (direction & wxCENTER_FRAME) || wxDynamicCast(this, wxControl) )
|
||||||
|
{
|
||||||
|
// adjust to the parents client area origin
|
||||||
|
wxPoint posParent = parent->ClientToScreen(wxPoint(0, 0));
|
||||||
|
|
||||||
// Center TopLevel windows over thier parent instead of the whole screen
|
xNew += posParent.x;
|
||||||
void wxWindowBase::CentreOnParent(int direction)
|
yNew += posParent.y;
|
||||||
{
|
|
||||||
wxPoint ppos;
|
|
||||||
wxSize psze;
|
|
||||||
wxSize wsze;
|
|
||||||
wxWindow* parent = GetParent();
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
if (!parent || !IsTopLevel()) {
|
|
||||||
Centre(direction);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psze = parent->GetSize();
|
Move(xNew, yNew);
|
||||||
ppos = parent->ClientToScreen(wxPoint(0,0));
|
|
||||||
wsze = GetSize();
|
|
||||||
|
|
||||||
x = y = -1;
|
|
||||||
|
|
||||||
if (direction == wxBOTH || direction == wxHORIZONTAL)
|
|
||||||
x = ppos.x + (psze.x - wsze.x)/2;
|
|
||||||
if (direction == wxBOTH || direction == wxVERTICAL)
|
|
||||||
y = ppos.y + (psze.y - wsze.y)/2;
|
|
||||||
|
|
||||||
Move(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fits the window around the children
|
// fits the window around the children
|
||||||
|
Reference in New Issue
Block a user