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}
@@ -812,9 +819,11 @@ method:\par
\constfunc{const wxSizer *}{GetSizer}{\void} \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}. \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}}}
@@ -1927,8 +1936,8 @@ Sets the accelerator table for this window. See \helpref{wxAcceleratorTable}{wxa
\func{void}{SetAutoLayout}{\param{bool}{ autoLayout}} \func{void}{SetAutoLayout}{\param{bool}{ autoLayout}}
Determines whether the \helpref{wxWindow::Layout}{wxwindowlayout} function will Determines whether the \helpref{wxWindow::Layout}{wxwindowlayout} function will
be called automatically when the window is resized. Use in connection with be called automatically when the window is resized. Use in connection with
\helpref{wxWindow::SetSizer}{wxwindowsetsizer} and \helpref{wxWindow::SetSizer}{wxwindowsetsizer} and
\helpref{wxWindow::SetConstraints}{wxwindowsetconstraints} for laying out \helpref{wxWindow::SetConstraints}{wxwindowsetconstraints} for laying out
subwindows. subwindows.
@@ -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}}
@@ -2107,7 +2124,7 @@ window if it has this style flag set.}
events are propagared upwards to the window parent recursively until a handler 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 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 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}.} \helpref{event processing overview}{eventprocessing}.}
\twocolitem{\windowstyle{wxWS\_EX\_TRANSIENT}}{This can be used to prevent a \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 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 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. 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 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 {\tt wxDEFAULT\_FRAME\_STYLE & ~(wxMINIMIZE\_BOX | wxMAXIMIZE\_BOX)} for the
frames having this style (the dialogs don't have minimize nor maximize box by frames having this style (the dialogs don't have minimize nor maximize box by
default)} default)}
@@ -2550,7 +2567,7 @@ See \helpref{Window styles}{windowstyles} for more information about flags.
\func{virtual bool}{Show}{\param{bool}{ show = {\tt TRUE}}} \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 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. 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} \func{virtual void}{Thaw}{\void}
Reenables window updating after a previous call to Reenables window updating after a previous call to
\helpref{Freeze}{wxwindowfreeze}. \helpref{Freeze}{wxwindowfreeze}.
\membersection{wxWindow::TransferDataFromWindow}\label{wxwindowtransferdatafromwindow} \membersection{wxWindow::TransferDataFromWindow}\label{wxwindowtransferdatafromwindow}

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;
@@ -923,7 +928,7 @@ protected:
// capture/release the mouse, used by Capture/ReleaseMouse() // capture/release the mouse, used by Capture/ReleaseMouse()
virtual void DoCaptureMouse() = 0; virtual void DoCaptureMouse() = 0;
virtual void DoReleaseMouse() = 0; virtual void DoReleaseMouse() = 0;
// retrieve the position/size of the window // retrieve the position/size of the window
virtual void DoGetPosition( int *x, int *y ) const = 0; virtual void DoGetPosition( int *x, int *y ) const = 0;
virtual void DoGetSize( int *width, int *height ) const = 0; virtual void DoGetSize( int *width, int *height ) const = 0;

View File

@@ -236,7 +236,7 @@ void wxSizerItem::DeleteWindows()
{ {
if (m_window) if (m_window)
m_window->Destroy(); m_window->Destroy();
if (m_sizer) if (m_sizer)
m_sizer->DeleteWindows(); m_sizer->DeleteWindows();
} }
@@ -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);