]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxWindow::GetPrev/NextSibling()
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 20 Nov 2007 15:57:51 +0000 (15:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 20 Nov 2007 15:57:51 +0000 (15:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index eaac74c1cf1c6cc18615fe369a3656303b6b2ecb..fe6bb73f8ddc92b11cc9a9f043682926e8526eec 100644 (file)
@@ -272,6 +272,14 @@ wxX11:
 - Make Enter key activate the default button (David Hart).
 
 
+2.8.8
+-----
+
+All (GUI):
+
+- Added wxWindow::GetNextSibling() and GetPrevSibling()
+
+
 2.8.7
 -----
 
index 619125987af2e6a2ec8a934802e3ee64a081be6c..e100561a9d0982d70573618a48718e8bccea7a6d 100644 (file)
@@ -1197,6 +1197,20 @@ name in the window constructor or via \helpref{wxWindow::SetName}{wxwindowsetnam
 \helpref{wxWindow::SetName}{wxwindowsetname}
 
 
+\membersection{wxWindow::GetNextSibling}\label{wxwindowgetnextsibling}
+
+\constfunc{wxWindow *}{GetNextSibling}{\void}
+
+Returns the next window after this one among the parent children or \NULL if
+this window is the last child.
+
+\newsince{2.8.8}
+
+\wxheading{See also}
+
+\helpref{GetPrevSibling}{wxwindowgetprevsibling}
+
+
 \membersection{wxWindow::GetParent}\label{wxwindowgetparent}
 
 \constfunc{virtual wxWindow*}{GetParent}{\void}
@@ -1270,6 +1284,20 @@ method:\par
 \helpref{GetScreenPosition}{wxwindowgetscreenposition}
 
 
+\membersection{wxWindow::GetPrevSibling}\label{wxwindowgetprevsibling}
+
+\constfunc{wxWindow *}{GetPrevSibling}{\void}
+
+Returns the previous window before this one among the parent children or \NULL if
+this window is the first child.
+
+\newsince{2.8.8}
+
+\wxheading{See also}
+
+\helpref{GetNextSibling}{wxwindowgetnextsibling}
+
+
 \membersection{wxWindow::GetRect}\label{wxwindowgetrect}
 
 \constfunc{virtual wxRect}{GetRect}{\void}
index 4ef1695d1466b4368830e64488ce302c83f52c74..39cea13986142c8852536891d40b0e7f79470729 100644 (file)
@@ -631,9 +631,9 @@ public:
         // move this window just before/after the specified one in tab order
         // (the other window must be our sibling!)
     void MoveBeforeInTabOrder(wxWindow *win)
-        { DoMoveInTabOrder(win, MoveBefore); }
+        { DoMoveInTabOrder(win, OrderBefore); }
     void MoveAfterInTabOrder(wxWindow *win)
-        { DoMoveInTabOrder(win, MoveAfter); }
+        { DoMoveInTabOrder(win, OrderAfter); }
 
 
     // parent/children relations
@@ -646,6 +646,11 @@ public:
     // needed just for extended runtime
     const wxWindowList& GetWindowChildren() const { return GetChildren() ; }
 
+        // get the window before/after this one in the parents children list,
+        // returns NULL if this is the first/last window
+    wxWindow *GetPrevSibling() const { return DoGetSibling(OrderBefore); }
+    wxWindow *GetNextSibling() const { return DoGetSibling(OrderAfter); }
+
         // get the parent or the parent of the parent
     wxWindow *GetParent() const { return m_parent; }
     inline wxWindow *GetGrandParent() const;
@@ -1257,13 +1262,17 @@ protected:
     virtual bool TryValidator(wxEvent& event);
     virtual bool TryParent(wxEvent& event);
 
-    // common part of MoveBefore/AfterInTabOrder()
-    enum MoveKind
+    enum WindowOrder
     {
-        MoveBefore,     // insert before the given window
-        MoveAfter       // insert after the given window
+        OrderBefore,     // insert before the given window
+        OrderAfter       // insert after the given window
     };
-    virtual void DoMoveInTabOrder(wxWindow *win, MoveKind move);
+
+    // common part of GetPrev/NextSibling()
+    wxWindow *DoGetSibling(WindowOrder order) const;
+
+    // common part of MoveBefore/AfterInTabOrder()
+    virtual void DoMoveInTabOrder(wxWindow *win, WindowOrder move);
 
     // implementation of Navigate() and NavigateIn()
     virtual bool DoNavigateIn(int flags);
index c26cfb27c308973f0c35276b5b7caaec2d95aa15..8d16cbcdfdc9f16c7b16f78c463cdcffdc18e548 100644 (file)
@@ -2635,6 +2635,27 @@ bool wxWindowBase::TryParent(wxEvent& event)
     return wxEvtHandler::TryParent(event);
 }
 
+// ----------------------------------------------------------------------------
+// window relationships
+// ----------------------------------------------------------------------------
+
+wxWindow *wxWindowBase::DoGetSibling(WindowOrder order) const
+{
+    wxCHECK_MSG( GetParent(), NULL,
+                    _T("GetPrev/NextSibling() don't work for TLWs!") );
+
+    wxWindowList& siblings = GetParent()->GetChildren();
+    wxWindowList::compatibility_iterator i = siblings.Find(this);
+    wxCHECK_MSG( i, NULL, _T("window not a child of its parent?") );
+
+    if ( order == OrderBefore )
+        i = i->GetPrevious();
+    else // OrderAfter
+        i = i->GetNext();
+
+    return i ? i->GetData() : NULL;
+}
+
 // ----------------------------------------------------------------------------
 // keyboard navigation
 // ----------------------------------------------------------------------------
@@ -2654,7 +2675,7 @@ bool wxWindowBase::DoNavigateIn(int flags)
 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
 }
 
-void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
+void wxWindowBase::DoMoveInTabOrder(wxWindow *win, WindowOrder move)
 {
     // check that we're not a top level window
     wxCHECK_RET( GetParent(),
@@ -2674,7 +2695,7 @@ void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
     // can't just move the node around
     wxWindow *self = (wxWindow *)this;
     siblings.DeleteObject(self);
-    if ( move == MoveAfter )
+    if ( move == OrderAfter )
     {
         i = i->GetNext();
     }
@@ -2683,7 +2704,7 @@ void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
     {
         siblings.Insert(i, self);
     }
-    else // MoveAfter and win was the last sibling
+    else // OrderAfter and win was the last sibling
     {
         siblings.Append(self);
     }