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
This commit is contained in:
Robin Dunn
2002-02-14 23:34:46 +00:00
parent 9990cb50e4
commit be90c029fd
7 changed files with 134 additions and 14 deletions

View File

@@ -564,6 +564,13 @@ implements the following methods:\par
Returns a pointer to the window's layout constraints, or NULL if there are none. 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} \membersection{wxWindow::GetDropTarget}\label{wxwindowgetdroptarget}
\constfunc{wxDropTarget*}{GetDropTarget}{\void} \constfunc{wxDropTarget*}{GetDropTarget}{\void}
@@ -815,6 +822,8 @@ method:\par
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}. \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}, \constfunc{virtual void}{GetTextExtent}{\param{const wxString\& }{string}, \param{int* }{x}, \param{int* }{y},
\param{int* }{descent = NULL}, \param{int* }{externalLeading = NULL}, \param{int* }{descent = NULL}, \param{int* }{externalLeading = NULL},
\param{const wxFont* }{font = NULL}, \param{bool}{ use16 = {\tt FALSE}}} \param{const wxFont* }{font = NULL}, \param{bool}{ use16 = {\tt FALSE}}}
@@ -2007,6 +2016,14 @@ implements the following methods:\par
\end{twocollist}} \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} \membersection{wxWindow::SetCursor}\label{wxwindowsetcursor}
\func{virtual void}{SetCursor}{\param{const wxCursor\&}{cursor}} \func{virtual void}{SetCursor}{\param{const wxCursor\&}{cursor}}

View File

@@ -734,9 +734,13 @@ public:
virtual void GetPositionConstraint(int *x, int *y) const ; virtual void GetPositionConstraint(int *x, int *y) const ;
// sizers // sizers
// TODO: what are they and how do they work??
void SetSizer( wxSizer *sizer ); void SetSizer( wxSizer *sizer );
wxSizer *GetSizer() const { return m_windowSizer; } 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 #endif // wxUSE_CONSTRAINTS
// backward compatibility // backward compatibility
@@ -840,10 +844,11 @@ protected:
// constraints this window is involved in // constraints this window is involved in
wxWindowList *m_constraintsInvolvedIn; wxWindowList *m_constraintsInvolvedIn;
// top level and the parent sizers // this window's sizer
// TODO what's this and how does it work?)
wxSizer *m_windowSizer; 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? // Layout() window automatically when its size changes?
bool m_autoLayout:1; bool m_autoLayout:1;

View File

@@ -269,11 +269,13 @@ wxSizer::wxSizer()
wxSizer::~wxSizer() wxSizer::~wxSizer()
{ {
Clear();
} }
void wxSizer::Add( wxWindow *window, int option, int flag, int border, wxObject* userData ) void wxSizer::Add( wxWindow *window, int option, int flag, int border, wxObject* userData )
{ {
m_children.Append( new wxSizerItem( window, option, flag, border, 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 ) 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 ) void wxSizer::Prepend( wxWindow *window, int option, int flag, int border, wxObject* userData )
{ {
m_children.Insert( new wxSizerItem( window, option, flag, border, 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 ) 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 ) 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 ) ); 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 ) 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(); wxSizerItem *item = (wxSizerItem*)node->Data();
if (item->GetWindow() == window) if (item->GetWindow() == window)
{ {
item->GetWindow()->SetContainingSizer(NULL);
m_children.DeleteNode( node ); m_children.DeleteNode( node );
return TRUE; return TRUE;
} }
@@ -366,9 +371,21 @@ bool wxSizer::Remove( int pos )
void wxSizer::Clear( bool delete_windows ) 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) if (delete_windows)
DeleteWindows(); DeleteWindows();
// Now empty the list
m_children.Clear(); m_children.Clear();
} }

View File

@@ -152,6 +152,7 @@ void wxWindowBase::InitBase()
m_constraints = (wxLayoutConstraints *) NULL; m_constraints = (wxLayoutConstraints *) NULL;
m_constraintsInvolvedIn = (wxWindowList *) NULL; m_constraintsInvolvedIn = (wxWindowList *) NULL;
m_windowSizer = (wxSizer *) NULL; m_windowSizer = (wxSizer *) NULL;
m_containingSizer = (wxSizer *) NULL;
m_autoLayout = FALSE; m_autoLayout = FALSE;
#endif // wxUSE_CONSTRAINTS #endif // wxUSE_CONSTRAINTS
@@ -257,6 +258,9 @@ wxWindowBase::~wxWindowBase()
m_constraints = NULL; m_constraints = NULL;
} }
if ( m_containingSizer )
m_containingSizer->Remove((wxWindow*)this);
if ( m_windowSizer ) if ( m_windowSizer )
delete m_windowSizer; delete m_windowSizer;

View File

@@ -5282,6 +5282,71 @@ static PyObject *_wrap_wxWindow_GetSizer(PyObject *self, PyObject *args, PyObjec
return _resultobj; 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()) #define wxWindow_GetValidator(_swigobj) (_swigobj->GetValidator())
static PyObject *_wrap_wxWindow_GetValidator(PyObject *self, PyObject *args, PyObject *kwargs) { static PyObject *_wrap_wxWindow_GetValidator(PyObject *self, PyObject *args, PyObject *kwargs) {
PyObject * _resultobj; PyObject * _resultobj;
@@ -10896,6 +10961,8 @@ static PyMethodDef windowscMethods[] = {
{ "wxWindow_SetDropTarget", (PyCFunction) _wrap_wxWindow_SetDropTarget, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_SetDropTarget", (PyCFunction) _wrap_wxWindow_SetDropTarget, METH_VARARGS | METH_KEYWORDS },
{ "wxWindow_SetValidator", (PyCFunction) _wrap_wxWindow_SetValidator, 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_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_GetSizer", (PyCFunction) _wrap_wxWindow_GetSizer, METH_VARARGS | METH_KEYWORDS },
{ "wxWindow_SetSizer", (PyCFunction) _wrap_wxWindow_SetSizer, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_SetSizer", (PyCFunction) _wrap_wxWindow_SetSizer, METH_VARARGS | METH_KEYWORDS },
{ "wxWindow_GetToolTip", (PyCFunction) _wrap_wxWindow_GetToolTip, METH_VARARGS | METH_KEYWORDS }, { "wxWindow_GetToolTip", (PyCFunction) _wrap_wxWindow_GetToolTip, METH_VARARGS | METH_KEYWORDS },

View File

@@ -514,6 +514,12 @@ class wxWindowPtr(wxEvtHandlerPtr):
def GetSizer(self, *_args, **_kwargs): def GetSizer(self, *_args, **_kwargs):
val = apply(windowsc.wxWindow_GetSizer,(self,) + _args, _kwargs) val = apply(windowsc.wxWindow_GetSizer,(self,) + _args, _kwargs)
return val 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): def GetValidator(self, *_args, **_kwargs):
val = apply(windowsc.wxWindow_GetValidator,(self,) + _args, _kwargs) val = apply(windowsc.wxWindow_GetValidator,(self,) + _args, _kwargs)
return val return val

View File

@@ -374,6 +374,10 @@ public:
void SetSizer(wxSizer* sizer); void SetSizer(wxSizer* sizer);
wxSizer* GetSizer(); 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(); wxValidator* GetValidator();
void SetValidator(const wxValidator& validator); void SetValidator(const wxValidator& validator);