Returns true if the child item was found and removed, false otherwise.
+\membersection{wxSizer::Replace}\label{wxsizerreplace}
+
+\func{bool}{Replace}{\param{wxWindow* }{oldwin}, \param{wxWindow* }{newwin}, \param{bool }{recursive = false}}
+
+\func{bool}{Replace}{\param{wxSizer* }{oldsz}, \param{wxSizer* }{newsz}, \param{bool }{recursive = false}}
+
+\func{bool}{Remove}{\param{size\_t }{oldindex}, \param{wxSizerItem* }{newitem}}
+
+Detaches the given \arg{oldwin}, \arg{oldsz} child from the sizer and
+replaces it with the given window, sizer, or wxSizerItem.
+
+The detached child is removed {\bf only} if it is a sizer or a spacer
+(because windows are owned by their parent window, not the sizer).
+
+Use parameter \arg{recursive} to search the given element recursively in subsizers.
+
+
+This method does not cause any layout or resizing to take place, call
+\helpref{wxSizer::Layout}{wxsizerlayout} to update the layout "on screen" after replacing a
+child from the sizer.
+
+Returns true if the child item was found and removed, false otherwise.
+
+
\membersection{wxSizer::SetDimension}\label{wxsizersetdimension}
\func{void}{SetDimension}{\param{int }{x}, \param{int }{y}, \param{int }{width}, \param{int }{height}}
virtual bool Detach( wxSizer *sizer );
virtual bool Detach( int index );
+ virtual bool Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false );
+ virtual bool Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false );
+ virtual bool Replace( size_t index, wxSizerItem *newitem );
+
virtual void Clear( bool delete_windows = false );
virtual void DeleteWindows();
return true;
}
+bool wxSizer::Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive )
+{
+ wxASSERT_MSG( oldwin, _T("Replacing NULL window") );
+ wxASSERT_MSG( newwin, _T("Replacing with NULL window") );
+
+ wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
+ while (node)
+ {
+ wxSizerItem *item = node->GetData();
+
+ if (item->GetWindow() == oldwin)
+ {
+ item->GetWindow()->SetContainingSizer( NULL );
+ item->SetWindow(newwin);
+ newwin->SetContainingSizer( this );
+ return true;
+ }
+ else if (recursive && item->IsSizer())
+ {
+ if (item->GetSizer()->Replace( oldwin, newwin, true ))
+ return true;
+ }
+
+ node = node->GetNext();
+ }
+
+ return false;
+}
+
+bool wxSizer::Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive )
+{
+ wxASSERT_MSG( oldsz, _T("Replacing NULL sizer") );
+ wxASSERT_MSG( newsz, _T("Replacing with NULL sizer") );
+
+ wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
+ while (node)
+ {
+ wxSizerItem *item = node->GetData();
+
+ if (item->GetSizer() == oldsz)
+ {
+ wxSizer *old = item->GetSizer();
+ item->SetSizer(newsz);
+ delete old;
+ return true;
+ }
+ else if (recursive && item->IsSizer())
+ {
+ if (item->GetSizer()->Replace( oldsz, newsz, true ))
+ return true;
+ }
+
+ node = node->GetNext();
+ }
+
+ return false;
+}
+
+bool wxSizer::Replace( size_t old, wxSizerItem *newitem )
+{
+ wxCHECK_MSG( old < m_children.GetCount(), false, _T("Replace index is out of range") );
+ wxASSERT_MSG( newitem, _T("Replacing with NULL item") );
+
+ wxSizerItemList::compatibility_iterator node = m_children.Item( old );
+
+ wxCHECK_MSG( node, false, _T("Failed to find child node") );
+
+ wxSizerItem *item = node->GetData();
+ node->SetData(newitem);
+ delete item;
+
+ return true;
+}
+
void wxSizer::Clear( bool delete_windows )
{
// First clear the ContainingSizer pointers