]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/sizer.h
destroy m_impl even if an exception is thrown from the main loop
[wxWidgets.git] / include / wx / sizer.h
index e815822be2962693813d8b4983f575525ab534c0..5cceec9ca86e062b65a0d966459a6b277eaeac31 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        sizer.h
+// Name:        wx/sizer.h
 // Purpose:     provide wxSizer class for layout
 // Author:      Robert Roebling and Robin Dunn
 // Modified by: Ron Lee, Vadim Zeitlin (wxSizerFlags)
 
 #include "wx/defs.h"
 
-#include "wx/button.h"
 #include "wx/window.h"
-#include "wx/frame.h"
-#include "wx/dialog.h"
 
 //---------------------------------------------------------------------------
 // classes
 //---------------------------------------------------------------------------
 
+class WXDLLEXPORT wxButton;
+class WXDLLEXPORT wxBoxSizer;
 class WXDLLEXPORT wxSizerItem;
 class WXDLLEXPORT wxSizer;
-class WXDLLEXPORT wxBoxSizer;
 
+#ifndef wxUSE_BORDER_BY_DEFAULT
+    #ifdef __SMARTPHONE__
+        // no borders by default on limited size screen
+        #define wxUSE_BORDER_BY_DEFAULT 0
+    #else
+        #define wxUSE_BORDER_BY_DEFAULT 1
+    #endif
+#endif
 
 // ----------------------------------------------------------------------------
 // wxSizerFlags: flags used for an item in the sizer
@@ -69,8 +75,22 @@ public:
     // some shortcuts for Align()
     wxSizerFlags& Centre() { return Align(wxCENTRE); }
     wxSizerFlags& Center() { return Centre(); }
+    wxSizerFlags& Top() { return Align(wxALIGN_TOP); }
     wxSizerFlags& Left() { return Align(wxALIGN_LEFT); }
     wxSizerFlags& Right() { return Align(wxALIGN_RIGHT); }
+    wxSizerFlags& Bottom() { return Align(wxALIGN_BOTTOM); }
+
+    // default border size used by Border() below
+    static int GetDefaultBorder()
+    {
+#if wxUSE_BORDER_BY_DEFAULT
+        // FIXME: default border size shouldn't be hardcoded and at the very
+        //        least they should depend on the current font size
+        return 5;
+#else
+        return 0;
+#endif
+    }
 
 
     wxSizerFlags& Border(int direction, int borderInPixels)
@@ -85,17 +105,70 @@ public:
 
     wxSizerFlags& Border(int direction = wxALL)
     {
-        // FIXME: default border size shouldn't be hardcoded
-#ifdef __SMARTPHONE__
+#if wxUSE_BORDER_BY_DEFAULT
+        return Border(direction, GetDefaultBorder());
+#else
         // no borders by default on limited size screen
         wxUnusedVar(direction);
 
         return *this;
+#endif
+    }
+
+    wxSizerFlags& DoubleBorder(int direction = wxALL)
+    {
+#if wxUSE_BORDER_BY_DEFAULT
+        return Border(direction, 2*GetDefaultBorder());
 #else
-        return Border(direction, 5);
+        wxUnusedVar(direction);
+
+        return *this;
 #endif
     }
 
+    wxSizerFlags& TripleBorder(int direction = wxALL)
+    {
+#if wxUSE_BORDER_BY_DEFAULT
+        return Border(direction, 3*GetDefaultBorder());
+#else
+        wxUnusedVar(direction);
+
+        return *this;
+#endif
+    }
+
+    wxSizerFlags& HorzBorder()
+    {
+#if wxUSE_BORDER_BY_DEFAULT
+        return Border(wxLEFT | wxRIGHT, GetDefaultBorder());
+#else
+        return *this;
+#endif
+    }
+
+    wxSizerFlags& DoubleHorzBorder()
+    {
+#if wxUSE_BORDER_BY_DEFAULT
+        return Border(wxLEFT | wxRIGHT, 2*GetDefaultBorder());
+#else
+        return *this;
+#endif
+    }
+
+    // setters for the others flags
+    wxSizerFlags& Shaped()
+    {
+        m_flags |= wxSHAPED;
+
+        return *this;
+    }
+
+    wxSizerFlags& FixedMinSize()
+    {
+        m_flags |= wxFIXED_MINSIZE;
+
+        return *this;
+    }
 
     // accessors for wxSizer only
     int GetProportion() const { return m_proportion; }
@@ -329,87 +402,91 @@ WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
 class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
 {
 public:
-    wxSizer() { }
-    ~wxSizer();
+    wxSizer() { m_containingWindow = NULL; }
+    virtual ~wxSizer();
 
     // methods for adding elements to the sizer: there are Add/Insert/Prepend
     // overloads for each of window/sizer/spacer/wxSizerItem
-    inline wxSizerItem* Add( wxWindow *window,
-                             int proportion = 0,
-                             int flag = 0,
-                             int border = 0,
-                             wxObject* userData = NULL );
-    inline wxSizerItem* Add( wxSizer *sizer,
-                             int proportion = 0,
-                             int flag = 0,
-                             int border = 0,
-                             wxObject* userData = NULL );
-    inline wxSizerItem* Add( int width,
-                             int height,
-                             int proportion = 0,
-                             int flag = 0,
-                             int border = 0,
-                             wxObject* userData = NULL );
-    inline wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags );
-    inline wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags );
-    inline wxSizerItem* Add( wxSizerItem *item );
-
-    inline wxSizerItem* AddSpacer(int size);
-    inline wxSizerItem* AddStretchSpacer(int prop = 1);
-
-    inline wxSizerItem* Insert( size_t index,
-                                wxWindow *window,
-                                int proportion = 0,
-                                int flag = 0,
-                                int border = 0,
-                                wxObject* userData = NULL );
-    inline wxSizerItem* Insert( size_t index,
-                                wxSizer *sizer,
-                                int proportion = 0,
-                                int flag = 0,
-                                int border = 0,
-                                wxObject* userData = NULL );
-    inline wxSizerItem* Insert( size_t index,
-                                int width,
-                                int height,
-                                int proportion = 0,
-                                int flag = 0,
-                                int border = 0,
-                                wxObject* userData = NULL );
-    inline wxSizerItem* Insert( size_t index,
-                                wxWindow *window,
-                                const wxSizerFlags& flags );
-    inline wxSizerItem* Insert( size_t index,
-                                wxSizer *sizer,
-                                const wxSizerFlags& flags );
-    virtual wxSizerItem* Insert( size_t index, wxSizerItem *item );
-
-    inline wxSizerItem* InsertSpacer(size_t index, int size);
-    inline wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
-
-    inline wxSizerItem* Prepend( wxWindow *window,
-                                 int proportion = 0,
-                                 int flag = 0,
-                                 int border = 0,
-                                 wxObject* userData = NULL );
-    inline wxSizerItem* Prepend( wxSizer *sizer,
-                                 int proportion = 0,
-                                 int flag = 0,
-                                 int border = 0,
-                                 wxObject* userData = NULL );
-    inline wxSizerItem* Prepend( int width,
-                                 int height,
-                                 int proportion = 0,
-                                 int flag = 0,
-                                 int border = 0,
-                                 wxObject* userData = NULL );
-    inline wxSizerItem* Prepend( wxWindow *window, const wxSizerFlags& flags );
-    inline wxSizerItem* Prepend( wxSizer *sizer, const wxSizerFlags& flags );
-    inline wxSizerItem* Prepend( wxSizerItem *item );
-
-    inline wxSizerItem* PrependSpacer(int size);
-    inline wxSizerItem* PrependStretchSpacer(int prop = 1);
-
+    wxSizerItem* Add(wxWindow *window,
+                     int proportion = 0,
+                     int flag = 0,
+                     int border = 0,
+                     wxObject* userData = NULL);
+    wxSizerItem* Add(wxSizer *sizer,
+                     int proportion = 0,
+                     int flag = 0,
+                     int border = 0,
+                     wxObject* userData = NULL);
+    wxSizerItem* Add(int width,
+                     int height,
+                     int proportion = 0,
+                     int flag = 0,
+                     int border = 0,
+                     wxObject* userData = NULL);
+    wxSizerItem* Add( wxWindow *window, const wxSizerFlags& flags);
+    wxSizerItem* Add( wxSizer *sizer, const wxSizerFlags& flags);
+    wxSizerItem* Add( wxSizerItem *item);
+
+    wxSizerItem* AddSpacer(int size);
+    wxSizerItem* AddStretchSpacer(int prop = 1);
+
+    wxSizerItem* Insert(size_t index,
+                        wxWindow *window,
+                        int proportion = 0,
+                        int flag = 0,
+                        int border = 0,
+                        wxObject* userData = NULL);
+    wxSizerItem* Insert(size_t index,
+                        wxSizer *sizer,
+                        int proportion = 0,
+                        int flag = 0,
+                        int border = 0,
+                        wxObject* userData = NULL);
+    wxSizerItem* Insert(size_t index,
+                        int width,
+                        int height,
+                        int proportion = 0,
+                        int flag = 0,
+                        int border = 0,
+                        wxObject* userData = NULL);
+    wxSizerItem* Insert(size_t index,
+                        wxWindow *window,
+                        const wxSizerFlags& flags);
+    wxSizerItem* Insert(size_t index,
+                        wxSizer *sizer,
+                        const wxSizerFlags& flags);
+    virtual wxSizerItem* Insert( size_t index, wxSizerItem *item);
+
+    wxSizerItem* InsertSpacer(size_t index, int size);
+    wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
+
+    wxSizerItem* Prepend(wxWindow *window,
+                         int proportion = 0,
+                         int flag = 0,
+                         int border = 0,
+                         wxObject* userData = NULL);
+    wxSizerItem* Prepend(wxSizer *sizer,
+                         int proportion = 0,
+                         int flag = 0,
+                         int border = 0,
+                         wxObject* userData = NULL);
+    wxSizerItem* Prepend(int width,
+                         int height,
+                         int proportion = 0,
+                         int flag = 0,
+                         int border = 0,
+                         wxObject* userData = NULL);
+    wxSizerItem* Prepend(wxWindow *window, const wxSizerFlags& flags);
+    wxSizerItem* Prepend(wxSizer *sizer, const wxSizerFlags& flags);
+    wxSizerItem* Prepend(wxSizerItem *item);
+
+    wxSizerItem* PrependSpacer(int size);
+    wxSizerItem* PrependStretchSpacer(int prop = 1);
+
+    // set (or possibly unset if window is NULL) or get the window this sizer
+    // is used in
+    void SetContainingWindow(wxWindow *window);
+    wxWindow *GetContainingWindow() const { return m_containingWindow; }
 
 #if WXWIN_COMPATIBILITY_2_6
     // Deprecated in 2.6 since historically it does not delete the window,
@@ -424,6 +501,10 @@ public:
     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();
 
@@ -469,6 +550,8 @@ public:
 
     wxSizerItemList& GetChildren()
         { return m_children; }
+    const wxSizerItemList& GetChildren() const
+        { return m_children; }
 
     void SetDimension( int x, int y, int width, int height );
 
@@ -504,11 +587,13 @@ protected:
     wxPoint             m_position;
     wxSizerItemList     m_children;
 
+    // the window this sizer is used in, can be NULL
+    wxWindow *m_containingWindow;
+
     wxSize GetMaxWindowSize( wxWindow *window ) const;
     wxSize GetMinWindowSize( wxWindow *window );
     wxSize GetMaxClientSize( wxWindow *window ) const;
     wxSize GetMinClientSize( wxWindow *window );
-    wxSize FitSize( wxWindow *window );
     wxSize VirtualFitSize( wxWindow *window );
 
     virtual void DoSetMinSize( int width, int height );
@@ -695,7 +780,10 @@ public:
 
     // override to hide/show the static box as well
     virtual void ShowItems (bool show);
+
     virtual bool Detach( wxWindow *window );
+    virtual bool Detach( wxSizer *sizer ) { return wxBoxSizer::Detach(sizer); }
+    virtual bool Detach( int index ) { return wxBoxSizer::Detach(index); }
 
 protected:
     wxStaticBox   *m_staticBox;
@@ -755,74 +843,16 @@ private:
 
 #endif // wxUSE_BUTTON
 
-#if WXWIN_COMPATIBILITY_2_4
-// NB: wxBookCtrlSizer and wxNotebookSizer are deprecated, they
-//     don't do anything. wxBookCtrlBase::DoGetBestSize does the job now.
 
 // ----------------------------------------------------------------------------
-// wxBookCtrlSizer
+// inline functions implementation
 // ----------------------------------------------------------------------------
 
-#if wxUSE_BOOKCTRL
-
-// this sizer works with wxNotebook/wxListbook/... and sizes the control to
-// fit its pages
-class WXDLLEXPORT wxBookCtrlBase;
-
-class WXDLLEXPORT wxBookCtrlSizer : public wxSizer
-{
-public:
-#if WXWIN_COMPATIBILITY_2_6
-    wxDEPRECATED( wxBookCtrlSizer(wxBookCtrlBase *bookctrl) );
-#endif // WXWIN_COMPATIBILITY_2_6
-
-    wxBookCtrlBase *GetControl() const { return m_bookctrl; }
-
-    virtual void RecalcSizes();
-    virtual wxSize CalcMin();
-
-protected:
-    // this protected ctor lets us mark the real one above as deprecated
-    // and still have warning-free build of the library itself:
-    wxBookCtrlSizer() {}
-
-    wxBookCtrlBase *m_bookctrl;
-
-private:
-    DECLARE_CLASS(wxBookCtrlSizer)
-    DECLARE_NO_COPY_CLASS(wxBookCtrlSizer)
-};
-
-
-#if wxUSE_NOTEBOOK
-
-// before wxBookCtrlBase we only had wxNotebookSizer, keep it for backwards
-// compatibility
-class WXDLLEXPORT wxNotebook;
-
-class WXDLLEXPORT wxNotebookSizer : public wxBookCtrlSizer
+inline wxSizerItem*
+wxSizer::Add( wxSizerItem *item )
 {
-public:
-#if WXWIN_COMPATIBILITY_2_6
-    wxDEPRECATED( wxNotebookSizer(wxNotebook *nb) );
-#endif // WXWIN_COMPATIBILITY_2_6
-
-    wxNotebook *GetNotebook() const { return (wxNotebook *)m_bookctrl; }
-
-private:
-    DECLARE_CLASS(wxNotebookSizer)
-    DECLARE_NO_COPY_CLASS(wxNotebookSizer)
-};
-
-#endif // wxUSE_NOTEBOOK
-
-#endif // wxUSE_BOOKCTRL
-
-#endif // WXWIN_COMPATIBILITY_2_4
-
-// ----------------------------------------------------------------------------
-// inline functions implementation
-// ----------------------------------------------------------------------------
+    return Insert( m_children.GetCount(), item );
+}
 
 inline wxSizerItem*
 wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
@@ -854,12 +884,6 @@ wxSizer::Add( wxSizer *sizer, const wxSizerFlags& flags )
     return Add( new wxSizerItem(sizer, flags) );
 }
 
-inline wxSizerItem*
-wxSizer::Add( wxSizerItem *item )
-{
-    return Insert( m_children.GetCount(), item );
-}
-
 inline wxSizerItem*
 wxSizer::AddSpacer(int size)
 {
@@ -872,6 +896,12 @@ wxSizer::AddStretchSpacer(int prop)
     return Add(0, 0, prop);
 }
 
+inline wxSizerItem*
+wxSizer::Prepend( wxSizerItem *item )
+{
+    return Insert( 0, item );
+}
+
 inline wxSizerItem*
 wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
 {
@@ -890,12 +920,6 @@ wxSizer::Prepend( int width, int height, int proportion, int flag, int border, w
     return Prepend( new wxSizerItem( width, height, proportion, flag, border, userData ) );
 }
 
-inline wxSizerItem*
-wxSizer::Prepend( wxSizerItem *item )
-{
-    return Insert( 0, item );
-}
-
 inline wxSizerItem*
 wxSizer::PrependSpacer(int size)
 {
@@ -980,4 +1004,3 @@ wxSizer::InsertStretchSpacer(size_t index, int prop)
 
 
 #endif // __WXSIZER_H__
-