]> git.saurik.com Git - wxWidgets.git/commitdiff
As per the wx-dev discussion in early Jan, replaced
authorRobin Dunn <robin@alldunn.com>
Thu, 14 Feb 2002 23:34:46 +0000 (23:34 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 14 Feb 2002 23:34:46 +0000 (23:34 +0000)
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
include/wx/window.h
src/common/sizer.cpp
src/common/wincmn.cpp
wxPython/src/msw/windows.cpp
wxPython/src/msw/windows.py
wxPython/src/windows.i

index 01e98faf26fedd323585d6f522ec08e2866f3752..2eefeb2c3c42f38dfc325bfac97b2558b0e78260 100644 (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.
 
+\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}
index c7cbaa4611cfdf6637f27964550d51a44a77b111..fcb1ec05dfebd0d431cbe9a262a4164c408ff861 100644 (file)
@@ -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;
index d11c537e32c22f34e63370c3ab3c55a5d5b0cc28..f3a5d5a04ff344729d3430c084db9bd7f81a3b03 100644 (file)
@@ -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();
 }
 
index 7780dbd2a7b02860d54a21f71bc6b9eabbe89f29..6ffcaea012b9827bec575611f260bcc6d0c7315c 100644 (file)
@@ -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;
 
index e6b6f18e44e99f6493e802122d1aad02d362fd99..007e8a95dd9cb777c5ccc4110d5bf4fed2feb65c 100644 (file)
@@ -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 },
index f8587f4dcdd99678b839e69ce4065f421878a4d1..2c3579fede48fc5f9227de0df85300c48cfb1da2 100644 (file)
@@ -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
index d2f44fd990aaf11f22d11bac128e0314f4f63a06..a72fb75ab5178e4a2ea25831dea10f525687209f 100644 (file)
@@ -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);