From c944775f72435d2c0493113e05445898ab8baf1b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 20 Nov 2007 15:57:51 +0000 Subject: [PATCH] added wxWindow::GetPrev/NextSibling() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 8 ++++++++ docs/latex/wx/window.tex | 28 ++++++++++++++++++++++++++++ include/wx/window.h | 23 ++++++++++++++++------- src/common/wincmn.cpp | 27 ++++++++++++++++++++++++--- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index eaac74c1cf..fe6bb73f8d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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 ----- diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 619125987a..e100561a9d 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -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} diff --git a/include/wx/window.h b/include/wx/window.h index 4ef1695d14..39cea13986 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -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); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index c26cfb27c3..8d16cbcdfd 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -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); } -- 2.45.2