From 9f13661f8bce6d5b3dd402d8688de7592957d11e Mon Sep 17 00:00:00 2001
From: =?utf8?q?W=C5=82odzimierz=20Skiba?= <abx@abx.art.pl>
Date: Fri, 15 Oct 2004 18:58:52 +0000
Subject: [PATCH] Parts of wxSizer::Show() extracted into wxSizer::GetItem()
 (together with documentation).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29884 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt        |  1 +
 docs/latex/wx/sizer.tex | 15 ++++++++
 include/wx/sizer.h      |  4 +++
 src/common/sizer.cpp    | 77 ++++++++++++++++++++++++++++++-----------
 4 files changed, 76 insertions(+), 21 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index ce649bcfff..42f9ce5eb2 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -205,6 +205,7 @@ OTHER CHANGES
 All:
 
 - Norvegian (Bokmål) translation added (Hans F. Nordhaug)
+- recursive wxSizer::GetItem returns item of given window, sizer or nth index
 
 Unix:
 
diff --git a/docs/latex/wx/sizer.tex b/docs/latex/wx/sizer.tex
index cc834ce3bc..4c13b8ebcb 100644
--- a/docs/latex/wx/sizer.tex
+++ b/docs/latex/wx/sizer.tex
@@ -214,6 +214,21 @@ windows which manage it.
 \helpref{wxSizer::SetVirtualSizeHints}{wxsizersetvirtualsizehints}
 
 
+\membersection{wxSizer::GetItem}\label{wxsizergetitem}
+
+\func{wxSizerItem *}{GetItem}{\param{wxWindow* }{window}, \param{bool }{recursive = false}}
+
+\func{wxSizerItem *}{GetItem}{\param{wxSizer* }{sizer}, \param{bool }{recursive = false}}
+
+\func{wxSizerItem *}{GetItem}{\param{size\_t }{index}}
+
+Finds item of the sizer which holds given {\it window}, {\it sizer} or is located
+in sizer at position {\it index}.
+Use parameter {\it recursive} to search in subsizers too.
+
+Returns pointer to item or NULL.
+
+
 \membersection{wxSizer::GetSize}\label{wxsizergetsize}
 
 \func{wxSize}{GetSize}{\void}
diff --git a/include/wx/sizer.h b/include/wx/sizer.h
index 4023dfa87f..374b1559dc 100644
--- a/include/wx/sizer.h
+++ b/include/wx/sizer.h
@@ -408,6 +408,10 @@ public:
 
     void SetDimension( int x, int y, int width, int height );
 
+    wxSizerItem* GetItem( wxWindow *window, bool recursive = false );
+    wxSizerItem* GetItem( wxSizer *sizer, bool recursive = false );
+    wxSizerItem* GetItem( size_t index );
+
     // Manage whether individual scene items are considered
     // in the layout calculations or not.
     bool Show( wxWindow *window, bool show = true, bool recursive = false );
diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp
index 9f73688a00..b5d44e452a 100644
--- a/src/common/sizer.cpp
+++ b/src/common/sizer.cpp
@@ -760,9 +760,9 @@ bool wxSizer::DoSetItemMinSize( size_t index, int width, int height )
     return true;
 }
 
-bool wxSizer::Show( wxWindow *window, bool show, bool recursive )
+wxSizerItem* wxSizer::GetItem( wxWindow *window, bool recursive )
 {
-    wxASSERT_MSG( window, _T("Show for NULL window") );
+    wxASSERT_MSG( window, _T("GetItem for NULL window") );
 
     wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
     while (node)
@@ -771,58 +771,93 @@ bool wxSizer::Show( wxWindow *window, bool show, bool recursive )
 
         if (item->GetWindow() == window)
         {
-            item->Show( show );
-
-            return true;
+            return item;
         }
         else if (recursive && item->IsSizer())
         {
-            if (item->GetSizer()->Show(window, show, recursive))
-                return true;
+            wxSizerItem *subitem = item->GetSizer()->GetItem( window, true );
+            if (subitem)
+                return subitem;
         }
 
         node = node->GetNext();
     }
 
-    return false;
+    return NULL;
 }
 
-bool wxSizer::Show( wxSizer *sizer, bool show, bool recursive )
+wxSizerItem* wxSizer::GetItem( wxSizer *sizer, bool recursive )
 {
-    wxASSERT_MSG( sizer, _T("Show for NULL sizer") );
+    wxASSERT_MSG( sizer, _T("GetItem for NULL sizer") );
 
     wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
     while (node)
     {
-        wxSizerItem     *item = node->GetData();
+        wxSizerItem *item = node->GetData();
 
         if (item->GetSizer() == sizer)
         {
-            item->Show( show );
-
-            return true;
+            return item;
         }
         else if (recursive && item->IsSizer())
         {
-            if (item->GetSizer()->Show(sizer, show, recursive))
-                return true;
+            wxSizerItem *subitem = item->GetSizer()->GetItem( sizer, true );
+            if (subitem)
+                return subitem;
         }
 
         node = node->GetNext();
     }
 
+    return NULL;
+}
+
+wxSizerItem* wxSizer::GetItem( size_t index )
+{
+    wxCHECK_MSG( index < m_children.GetCount(),
+                 NULL,
+                 _T("GetItem index is out of range") );
+
+    return m_children.Item( index )->GetData();
+}
+
+bool wxSizer::Show( wxWindow *window, bool show, bool recursive )
+{
+    wxSizerItem *item = GetItem( window, recursive );
+
+    if ( item )
+    {
+         item->Show( show );
+         return true;
+    }
+
+    return false;
+}
+
+bool wxSizer::Show( wxSizer *sizer, bool show, bool recursive )
+{
+    wxSizerItem *item = GetItem( sizer, recursive );
+
+    if ( item )
+    {
+         item->Show( show );
+         return true;
+    }
+
     return false;
 }
 
 bool wxSizer::Show( size_t index, bool show)
 {
-    wxCHECK_MSG( index < m_children.GetCount(),
-                 false,
-                 _T("Show index is out of range") );
+    wxSizerItem *item = GetItem( index );
 
-    m_children.Item( index )->GetData()->Show( show );
+    if ( item )
+    {
+         item->Show( show );
+         return true;
+    }
 
-    return true;
+    return false;
 }
 
 void wxSizer::ShowItems( bool show )
-- 
2.50.0

