]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxWindowBase::CentreOnParent to allow top level windows to be
authorRobin Dunn <robin@alldunn.com>
Thu, 10 Jun 1999 22:44:50 +0000 (22:44 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 10 Jun 1999 22:44:50 +0000 (22:44 +0000)
centered over their parent (if they have one) instead of the entire
screen.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/window.tex
include/wx/window.h
src/common/wincmn.cpp

index 32d23e45ec807fd213b636a77d9e0bc19eb790e1..46b27b976ba0a12dcccd01fe4b37169f5a22fa8e 100644 (file)
@@ -122,9 +122,15 @@ release the capture.
 
 A synonym for \helpref{Centre}{wxwindowcentre}.
 
+\membersection{wxWindow::CenterOnParent}\label{wxwindowcenteronparent}
+
+\func{void}{CenterOnParent}{\param{int}{ direction}}
+
+A synonym for \helpref{CentreOnParent}{wxwindowcentreonparent}.
+
 \membersection{wxWindow::Centre}\label{wxwindowcentre}
 
-\func{virtual void}{Centre}{\param{int}{ direction = wxHORIZONTAL}}
+\func{void}{Centre}{\param{int}{ direction = wxHORIZONTAL}}
 
 Centres the window.
 
@@ -143,6 +149,28 @@ relative to the panel.
 
 \helpref{wxWindow::Center}{wxwindowcenter}
 
+\membersection{wxWindow::CentreOnParent}\label{wxwindowcentreonparent}
+
+\func{void}{CentreOnParent}{\param{int}{ direction = wxHORIZONTAL}}
+
+Centres the window.
+
+\wxheading{Parameters}
+
+\docparam{direction}{Specifies the direction for the centering. May be {\tt wxHORIZONTAL}, {\tt wxVERTICAL}\rtfsp
+or {\tt wxBOTH}.}
+
+\wxheading{Remarks}
+
+This methods provides for a way to center top level windows over their
+parents instead of the entire screen.  If there is no parent or if the
+window is not a top level window, then behaviour is the same as
+\helpref{wxWindow::Centre}{wxwindowcentre}.
+
+\wxheading{See also}
+
+\helpref{wxWindow::CenterOnParent}{wxwindowcenteronparent}
+
 \membersection{wxWindow::Clear}\label{wxwindowclear}
 
 \func{void}{Clear}{\void}
@@ -717,7 +745,7 @@ Returns a pointer to the current validator for the window, or NULL if there is n
 
 \constfunc{long}{GetWindowStyleFlag}{\void}
 
-Gets the window style that was passed to the consructor or {\bf Create} member. 
+Gets the window style that was passed to the consructor or {\bf Create} member.
 {\bf GetWindowStyle} is synonymous.
 
 \membersection{wxWindow::InitDialog}\label{wxwindowinitdialog}
@@ -769,7 +797,7 @@ window).
 
 \func{void}{Layout}{\void}
 
-Invokes the constraint-based layout algorithm for this window. 
+Invokes the constraint-based layout algorithm for this window.
 
 See \helpref{wxWindow::SetAutoLayout}{wxwindowsetautolayout} on when
 this function gets called automatically using auto layout.
index 3fdcd5acf00e6297a99930c83c15aa1639562c1b..6edbb625246468e17a1c22a0d82ab5171b5c7ed2 100644 (file)
@@ -259,6 +259,8 @@ public:
         // centre with respect to the the parent window
     void Centre( int direction = wxHORIZONTAL );
     void Center( int direction = wxHORIZONTAL ) { Centre(direction); }
+    void CentreOnParent(int direction = wxHORIZONTAL );
+    void CenterOnParent(int direction = wxHORIZONTAL ) { CentreOnParent(direction); }
 
         // set window size to wrap around its children
     virtual void Fit();
index a877e3548649b800ce9ead5b1fb40f6634d0c13e..582ea1e9bb997d6073de67d4a3301fc5938ec36a 100644 (file)
@@ -316,6 +316,34 @@ void wxWindowBase::Centre(int direction)
     Move(new_x, new_y);
 }
 
+// Center TopLevel windows over thier parent instead of the whole screen
+void wxWindowBase::CentreOnParent(int direction)
+{
+    wxPoint     ppos;
+    wxSize      psze;
+    wxSize      wsze;
+    wxWindow*   parent = GetParent();
+    int         x, y;
+
+    if (!parent || !IsTopLevel()) {
+        Centre(direction);
+        return;
+    }
+
+    psze = parent->GetSize();
+    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
 void wxWindowBase::Fit()
 {