From be90c029fd255fba3eb7379aabef5780df210ad8 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 14 Feb 2002 23:34:46 +0000 Subject: [PATCH] As per the wx-dev discussion in early Jan, replaced wxWindow::m_parentSizer with m_containingSizer which is used to track which sizer this window is a member of. Windows will now remove themselves from a sizer when destroyed. Also added accessors so window classes can find out if they are in a sizer and do things like reset their min size, etc. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14221 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/window.tex | 31 +++++++++++++---- include/wx/window.h | 15 +++++--- src/common/sizer.cpp | 21 +++++++++-- src/common/wincmn.cpp | 4 +++ wxPython/src/msw/windows.cpp | 67 ++++++++++++++++++++++++++++++++++++ wxPython/src/msw/windows.py | 6 ++++ wxPython/src/windows.i | 4 +++ 7 files changed, 134 insertions(+), 14 deletions(-) diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 01e98faf26..2eefeb2c3c 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -564,6 +564,13 @@ implements the following methods:\par Returns a pointer to the window's layout constraints, or NULL if there are none. +\membersection{wxWindow::GetContainingSizer}\label{wxwindowgetcontainingsizer} + +\constfunc{const wxSizer *}{GetContainingSizer}{\void} + +Return the sizer that this window is a member of, if any, otherwise +{\tt NULL}. + \membersection{wxWindow::GetDropTarget}\label{wxwindowgetdroptarget} \constfunc{wxDropTarget*}{GetDropTarget}{\void} @@ -812,9 +819,11 @@ method:\par \constfunc{const wxSizer *}{GetSizer}{\void} -Return the sizer associated with the window by a previous call to +Return the sizer associated with the window by a previous call to \helpref{SetSizer()}{wxwindowsetsizer} or {\tt NULL}. +\membersection{wxWindow::GetTextExtent}\label{wxwindowgettextextent} + \constfunc{virtual void}{GetTextExtent}{\param{const wxString\& }{string}, \param{int* }{x}, \param{int* }{y}, \param{int* }{descent = NULL}, \param{int* }{externalLeading = NULL}, \param{const wxFont* }{font = NULL}, \param{bool}{ use16 = {\tt FALSE}}} @@ -1927,8 +1936,8 @@ Sets the accelerator table for this window. See \helpref{wxAcceleratorTable}{wxa \func{void}{SetAutoLayout}{\param{bool}{ autoLayout}} Determines whether the \helpref{wxWindow::Layout}{wxwindowlayout} function will -be called automatically when the window is resized. Use in connection with -\helpref{wxWindow::SetSizer}{wxwindowsetsizer} and +be called automatically when the window is resized. Use in connection with +\helpref{wxWindow::SetSizer}{wxwindowsetsizer} and \helpref{wxWindow::SetConstraints}{wxwindowsetconstraints} for laying out subwindows. @@ -2007,6 +2016,14 @@ implements the following methods:\par \end{twocollist}} } +\membersection{wxWindow::SetContainingSizer}\label{wxwindowsetcontainingsizer} + +\func{void}{SetContainingSizer}{\param{wxSizer* }{sizer}} + +This normally does not need to be called by user code. It is called +when a window is added to a sizer, and is used so the window can +remove itself from the sizer when it is destroyed. + \membersection{wxWindow::SetCursor}\label{wxwindowsetcursor} \func{virtual void}{SetCursor}{\param{const wxCursor\&}{cursor}} @@ -2107,7 +2124,7 @@ window if it has this style flag set.} events are propagared upwards to the window parent recursively until a handler for them is found. Using this style allows to prevent them from being propagated beyond this window. Notice that wxDialog has this style on by -default for the reasons explained in the +default for the reasons explained in the \helpref{event processing overview}{eventprocessing}.} \twocolitem{\windowstyle{wxWS\_EX\_TRANSIENT}}{This can be used to prevent a window from being used as an implicit parent for the dialogs which were @@ -2117,7 +2134,7 @@ any moment as creating childs of such windows results in fatal problems.} caption. When pressed, Windows will go into a context-sensitive help mode and wxWindows will send a wxEVT\_HELP event if the user clicked on an application window. This style cannot be used together with wxMAXIMIZE\_BOX or wxMINIMIZE\_BOX, so -you should use the style of +you should use the style of {\tt wxDEFAULT\_FRAME\_STYLE & ~(wxMINIMIZE\_BOX | wxMAXIMIZE\_BOX)} for the frames having this style (the dialogs don't have minimize nor maximize box by default)} @@ -2550,7 +2567,7 @@ See \helpref{Window styles}{windowstyles} for more information about flags. \func{virtual bool}{Show}{\param{bool}{ show = {\tt TRUE}}} -Shows or hides the window. You may need to call \helpref{Raise}{wxwindowraise} +Shows or hides the window. You may need to call \helpref{Raise}{wxwindowraise} for a top level window if you want to bring it to top, although this is not needed if Show() is called immediately after the frame creation. @@ -2571,7 +2588,7 @@ done because it already was in the requested state. \func{virtual void}{Thaw}{\void} -Reenables window updating after a previous call to +Reenables window updating after a previous call to \helpref{Freeze}{wxwindowfreeze}. \membersection{wxWindow::TransferDataFromWindow}\label{wxwindowtransferdatafromwindow} diff --git a/include/wx/window.h b/include/wx/window.h index c7cbaa4611..fcb1ec05df 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -734,9 +734,13 @@ public: virtual void GetPositionConstraint(int *x, int *y) const ; // sizers - // TODO: what are they and how do they work?? void SetSizer( wxSizer *sizer ); wxSizer *GetSizer() const { return m_windowSizer; } + + // Track if this window is a member of a sizer + void SetContainingSizer(wxSizer* sizer) { m_containingSizer = sizer; } + wxSizer *GetContainingSizer() const { return m_containingSizer; } + #endif // wxUSE_CONSTRAINTS // backward compatibility @@ -840,10 +844,11 @@ protected: // constraints this window is involved in wxWindowList *m_constraintsInvolvedIn; - // top level and the parent sizers - // TODO what's this and how does it work?) + // this window's sizer wxSizer *m_windowSizer; - wxWindowBase *m_sizerParent; + + // The sizer this window is a member of, if any + wxSizer *m_containingSizer; // Layout() window automatically when its size changes? bool m_autoLayout:1; @@ -923,7 +928,7 @@ protected: // capture/release the mouse, used by Capture/ReleaseMouse() virtual void DoCaptureMouse() = 0; virtual void DoReleaseMouse() = 0; - + // retrieve the position/size of the window virtual void DoGetPosition( int *x, int *y ) const = 0; virtual void DoGetSize( int *width, int *height ) const = 0; diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index d11c537e32..f3a5d5a04f 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -236,7 +236,7 @@ void wxSizerItem::DeleteWindows() { if (m_window) m_window->Destroy(); - + if (m_sizer) m_sizer->DeleteWindows(); } @@ -269,11 +269,13 @@ wxSizer::wxSizer() wxSizer::~wxSizer() { + Clear(); } void wxSizer::Add( wxWindow *window, int option, int flag, int border, wxObject* userData ) { m_children.Append( new wxSizerItem( window, option, flag, border, userData ) ); + window->SetContainingSizer(this); } void wxSizer::Add( wxSizer *sizer, int option, int flag, int border, wxObject* userData ) @@ -289,6 +291,7 @@ void wxSizer::Add( int width, int height, int option, int flag, int border, wxOb void wxSizer::Prepend( wxWindow *window, int option, int flag, int border, wxObject* userData ) { m_children.Insert( new wxSizerItem( window, option, flag, border, userData ) ); + window->SetContainingSizer(this); } void wxSizer::Prepend( wxSizer *sizer, int option, int flag, int border, wxObject* userData ) @@ -304,6 +307,7 @@ void wxSizer::Prepend( int width, int height, int option, int flag, int border, void wxSizer::Insert( int before, wxWindow *window, int option, int flag, int border, wxObject* userData ) { m_children.Insert( before, new wxSizerItem( window, option, flag, border, userData ) ); + window->SetContainingSizer(this); } void wxSizer::Insert( int before, wxSizer *sizer, int option, int flag, int border, wxObject* userData ) @@ -326,6 +330,7 @@ bool wxSizer::Remove( wxWindow *window ) wxSizerItem *item = (wxSizerItem*)node->Data(); if (item->GetWindow() == window) { + item->GetWindow()->SetContainingSizer(NULL); m_children.DeleteNode( node ); return TRUE; } @@ -366,9 +371,21 @@ bool wxSizer::Remove( int pos ) void wxSizer::Clear( bool delete_windows ) { + // First clear the ContainingSizer pointers + wxNode *node = m_children.First(); + while (node) + { + wxSizerItem *item = (wxSizerItem*)node->Data(); + if (item->IsWindow()) + item->GetWindow()->SetContainingSizer(NULL); + node = node->Next(); + } + + // Destroy the windows if needed if (delete_windows) DeleteWindows(); - + + // Now empty the list m_children.Clear(); } diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 7780dbd2a7..6ffcaea012 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -152,6 +152,7 @@ void wxWindowBase::InitBase() m_constraints = (wxLayoutConstraints *) NULL; m_constraintsInvolvedIn = (wxWindowList *) NULL; m_windowSizer = (wxSizer *) NULL; + m_containingSizer = (wxSizer *) NULL; m_autoLayout = FALSE; #endif // wxUSE_CONSTRAINTS @@ -257,6 +258,9 @@ wxWindowBase::~wxWindowBase() m_constraints = NULL; } + if ( m_containingSizer ) + m_containingSizer->Remove((wxWindow*)this); + if ( m_windowSizer ) delete m_windowSizer; diff --git a/wxPython/src/msw/windows.cpp b/wxPython/src/msw/windows.cpp index e6b6f18e44..007e8a95dd 100644 --- a/wxPython/src/msw/windows.cpp +++ b/wxPython/src/msw/windows.cpp @@ -5282,6 +5282,71 @@ static PyObject *_wrap_wxWindow_GetSizer(PyObject *self, PyObject *args, PyObjec return _resultobj; } +#define wxWindow_SetContainingSizer(_swigobj,_swigarg0) (_swigobj->SetContainingSizer(_swigarg0)) +static PyObject *_wrap_wxWindow_SetContainingSizer(PyObject *self, PyObject *args, PyObject *kwargs) { + PyObject * _resultobj; + wxWindow * _arg0; + wxSizer * _arg1; + PyObject * _argo0 = 0; + PyObject * _argo1 = 0; + char *_kwnames[] = { "self","sizer", NULL }; + + self = self; + if(!PyArg_ParseTupleAndKeywords(args,kwargs,"OO:wxWindow_SetContainingSizer",_kwnames,&_argo0,&_argo1)) + return NULL; + if (_argo0) { + if (_argo0 == Py_None) { _arg0 = NULL; } + else if (SWIG_GetPtrObj(_argo0,(void **) &_arg0,"_wxWindow_p")) { + PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxWindow_SetContainingSizer. Expected _wxWindow_p."); + return NULL; + } + } + if (_argo1) { + if (_argo1 == Py_None) { _arg1 = NULL; } + else if (SWIG_GetPtrObj(_argo1,(void **) &_arg1,"_wxSizer_p")) { + PyErr_SetString(PyExc_TypeError,"Type error in argument 2 of wxWindow_SetContainingSizer. Expected _wxSizer_p."); + return NULL; + } + } +{ + PyThreadState* __tstate = wxPyBeginAllowThreads(); + wxWindow_SetContainingSizer(_arg0,_arg1); + + wxPyEndAllowThreads(__tstate); + if (PyErr_Occurred()) return NULL; +} Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + +#define wxWindow_GetContainingSizer(_swigobj) (_swigobj->GetContainingSizer()) +static PyObject *_wrap_wxWindow_GetContainingSizer(PyObject *self, PyObject *args, PyObject *kwargs) { + PyObject * _resultobj; + wxSizer * _result; + wxWindow * _arg0; + PyObject * _argo0 = 0; + char *_kwnames[] = { "self", NULL }; + + self = self; + if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O:wxWindow_GetContainingSizer",_kwnames,&_argo0)) + return NULL; + if (_argo0) { + if (_argo0 == Py_None) { _arg0 = NULL; } + else if (SWIG_GetPtrObj(_argo0,(void **) &_arg0,"_wxWindow_p")) { + PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxWindow_GetContainingSizer. Expected _wxWindow_p."); + return NULL; + } + } +{ + PyThreadState* __tstate = wxPyBeginAllowThreads(); + _result = (wxSizer *)wxWindow_GetContainingSizer(_arg0); + + wxPyEndAllowThreads(__tstate); + if (PyErr_Occurred()) return NULL; +}{ _resultobj = wxPyMake_wxSizer(_result); } + return _resultobj; +} + #define wxWindow_GetValidator(_swigobj) (_swigobj->GetValidator()) static PyObject *_wrap_wxWindow_GetValidator(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; @@ -10896,6 +10961,8 @@ static PyMethodDef windowscMethods[] = { { "wxWindow_SetDropTarget", (PyCFunction) _wrap_wxWindow_SetDropTarget, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_SetValidator", (PyCFunction) _wrap_wxWindow_SetValidator, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_GetValidator", (PyCFunction) _wrap_wxWindow_GetValidator, METH_VARARGS | METH_KEYWORDS }, + { "wxWindow_GetContainingSizer", (PyCFunction) _wrap_wxWindow_GetContainingSizer, METH_VARARGS | METH_KEYWORDS }, + { "wxWindow_SetContainingSizer", (PyCFunction) _wrap_wxWindow_SetContainingSizer, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_GetSizer", (PyCFunction) _wrap_wxWindow_GetSizer, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_SetSizer", (PyCFunction) _wrap_wxWindow_SetSizer, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_GetToolTip", (PyCFunction) _wrap_wxWindow_GetToolTip, METH_VARARGS | METH_KEYWORDS }, diff --git a/wxPython/src/msw/windows.py b/wxPython/src/msw/windows.py index f8587f4dcd..2c3579fede 100644 --- a/wxPython/src/msw/windows.py +++ b/wxPython/src/msw/windows.py @@ -514,6 +514,12 @@ class wxWindowPtr(wxEvtHandlerPtr): def GetSizer(self, *_args, **_kwargs): val = apply(windowsc.wxWindow_GetSizer,(self,) + _args, _kwargs) return val + def SetContainingSizer(self, *_args, **_kwargs): + val = apply(windowsc.wxWindow_SetContainingSizer,(self,) + _args, _kwargs) + return val + def GetContainingSizer(self, *_args, **_kwargs): + val = apply(windowsc.wxWindow_GetContainingSizer,(self,) + _args, _kwargs) + return val def GetValidator(self, *_args, **_kwargs): val = apply(windowsc.wxWindow_GetValidator,(self,) + _args, _kwargs) return val diff --git a/wxPython/src/windows.i b/wxPython/src/windows.i index d2f44fd990..a72fb75ab5 100644 --- a/wxPython/src/windows.i +++ b/wxPython/src/windows.i @@ -374,6 +374,10 @@ public: void SetSizer(wxSizer* sizer); wxSizer* GetSizer(); + // Track if this window is a member of a sizer + void SetContainingSizer(wxSizer* sizer) { m_containingSizer = sizer; } + wxSizer *GetContainingSizer() const { return m_containingSizer; } + wxValidator* GetValidator(); void SetValidator(const wxValidator& validator); -- 2.45.2