home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / include / wx / sizer.h < prev    next >
C/C++ Source or Header  |  2002-12-14  |  12KB  |  400 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        sizer.h
  3. // Purpose:     provide wxSizer class for layouting
  4. // Author:      Robert Roebling and Robin Dunn
  5. // Modified by: Ron Lee
  6. // Created:
  7. // RCS-ID:      $Id: sizer.h,v 1.24.2.2 2002/12/14 09:27:40 JS Exp $
  8. // Copyright:   (c) Robin Dunn, Dirk Holtwick and Robert Roebling
  9. // Licence:     wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef __WXSIZER_H__
  13. #define __WXSIZER_H__
  14.  
  15. #if defined(__GNUG__) && !defined(__APPLE__)
  16. #pragma interface "sizer.h"
  17. #endif
  18.  
  19. #include "wx/defs.h"
  20.  
  21. #include "wx/window.h"
  22. #include "wx/frame.h"
  23. #include "wx/dialog.h"
  24.  
  25. //---------------------------------------------------------------------------
  26. // classes
  27. //---------------------------------------------------------------------------
  28.  
  29. class wxSizerItem;
  30. class wxSizer;
  31. class wxBoxSizer;
  32.  
  33. //---------------------------------------------------------------------------
  34. // wxSizerItem
  35. //---------------------------------------------------------------------------
  36.  
  37. class WXDLLEXPORT wxSizerItem: public wxObject
  38. {
  39. public:
  40.     // spacer
  41.     wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
  42.  
  43.     // window
  44.     wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
  45.  
  46.     // subsizer
  47.     wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
  48.  
  49.     ~wxSizerItem();
  50.     
  51.     virtual void DeleteWindows();
  52.  
  53.     virtual wxSize GetSize();
  54.     virtual wxSize CalcMin();
  55.     virtual void SetDimension( wxPoint pos, wxSize size );
  56.  
  57.     wxSize GetMinSize()
  58.         { return m_minSize; }
  59.  
  60.     void SetRatio( int width, int height )
  61.         // if either of dimensions is zero, ratio is assumed to be 1
  62.         // to avoid "divide by zero" errors
  63.         { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
  64.     void SetRatio( wxSize size )
  65.         { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
  66.     void SetRatio( float ratio )
  67.         { m_ratio = ratio; }
  68.     float GetRatio() const
  69.         { return m_ratio; }
  70.  
  71.     bool IsWindow();
  72.     bool IsSizer();
  73.     bool IsSpacer();
  74.  
  75.     void SetInitSize( int x, int y )
  76.         { m_minSize.x = x; m_minSize.y = y; }
  77.     void SetOption( int option )
  78.         { m_option = option; }
  79.     void SetFlag( int flag )
  80.         { m_flag = flag; }
  81.     void SetBorder( int border )
  82.         { m_border = border; }
  83.     void Show ( bool show )
  84.         { m_show = show; }
  85.  
  86.     wxWindow *GetWindow() const
  87.         { return m_window; }
  88.     void SetWindow( wxWindow *window )
  89.         { m_window = window; }
  90.     wxSizer *GetSizer() const
  91.         { return m_sizer; }
  92.     void SetSizer( wxSizer *sizer )
  93.         { m_sizer = sizer; }
  94.     int GetOption() const
  95.         { return m_option; }
  96.     int GetFlag() const
  97.         { return m_flag; }
  98.     int GetBorder() const
  99.         { return m_border; }
  100.     bool IsShown() const
  101.         { return m_show; }
  102.     wxObject* GetUserData()
  103.         { return m_userData; }
  104.     wxPoint GetPosition()
  105.         { return m_pos; }
  106.  
  107. protected:
  108.     wxWindow    *m_window;
  109.     wxSizer     *m_sizer;
  110.     wxSize       m_size;
  111.     wxPoint      m_pos;
  112.     wxSize       m_minSize;
  113.     int          m_option;
  114.     int          m_border;
  115.     int          m_flag;
  116.  
  117.     // If TRUE, then this item is considered in the layout
  118.     // calculation.  Otherwise, it is skipped over. 
  119.     bool         m_show;
  120.     // als: aspect ratio can always be calculated from m_size,
  121.     //      but this would cause precision loss when the window
  122.     //      is shrinked.  it is safer to preserve initial value.
  123.     float        m_ratio;
  124.  
  125.     wxObject    *m_userData;
  126.  
  127. private:
  128.     DECLARE_CLASS(wxSizerItem);
  129. };
  130.  
  131. //---------------------------------------------------------------------------
  132. // wxSizer
  133. //---------------------------------------------------------------------------
  134.  
  135. class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
  136. {
  137. public:
  138.     wxSizer();
  139.     ~wxSizer();
  140.  
  141.     /* These should be called Append() really. */
  142.     virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  143.     virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  144.     virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  145.  
  146.     virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  147.     virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  148.     virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  149.  
  150.     virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  151.     virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  152.     virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
  153.  
  154.     virtual bool Remove( wxWindow *window );
  155.     virtual bool Remove( wxSizer *sizer );
  156.     virtual bool Remove( int pos );
  157.     
  158.     virtual void Clear( bool delete_windows=FALSE );
  159.     virtual void DeleteWindows();
  160.  
  161.     void SetMinSize( int width, int height )
  162.         { DoSetMinSize( width, height ); }
  163.     void SetMinSize( wxSize size )
  164.         { DoSetMinSize( size.x, size.y ); }
  165.  
  166.     /* Searches recursively */
  167.     bool SetItemMinSize( wxWindow *window, int width, int height )
  168.         { return DoSetItemMinSize( window, width, height ); }
  169.     bool SetItemMinSize( wxWindow *window, wxSize size )
  170.         { return DoSetItemMinSize( window, size.x, size.y ); }
  171.  
  172.     /* Searches recursively */
  173.     bool SetItemMinSize( wxSizer *sizer, int width, int height )
  174.         { return DoSetItemMinSize( sizer, width, height ); }
  175.     bool SetItemMinSize( wxSizer *sizer, wxSize size )
  176.         { return DoSetItemMinSize( sizer, size.x, size.y ); }
  177.  
  178.     bool SetItemMinSize( int pos, int width, int height )
  179.         { return DoSetItemMinSize( pos, width, height ); }
  180.     bool SetItemMinSize( int pos, wxSize size )
  181.         { return DoSetItemMinSize( pos, size.x, size.y ); }
  182.  
  183.     wxSize GetSize()
  184.         { return m_size; }
  185.     wxPoint GetPosition()
  186.         { return m_position; }
  187.  
  188.     /* Calculate the minimal size or return m_minSize if bigger. */
  189.     wxSize GetMinSize();
  190.  
  191.     virtual void RecalcSizes() = 0;
  192.     virtual wxSize CalcMin() = 0;
  193.  
  194.     virtual void Layout();
  195.  
  196.     wxSize Fit( wxWindow *window );
  197.     void FitInside( wxWindow *window );
  198.     void SetSizeHints( wxWindow *window );
  199.     void SetVirtualSizeHints( wxWindow *window );
  200.  
  201.     wxList& GetChildren()
  202.         { return m_children; }
  203.  
  204.     void SetDimension( int x, int y, int width, int height );
  205.  
  206.     // Manage whether individual windows or sub-sizers are considered
  207.     // in the layout calculations or not.
  208.     void Show( wxWindow *window, bool show = TRUE );
  209.     void Hide( wxWindow *window )
  210.         { Show (window, FALSE); }
  211.     void Show( wxSizer *sizer, bool show = TRUE );
  212.     void Hide( wxSizer *sizer )
  213.         { Show (sizer, FALSE); }
  214.  
  215.     bool IsShown( wxWindow *window );
  216.     bool IsShown( wxSizer *sizer );
  217.     
  218.     // Recursively call wxWindow::Show () on all sizer items.
  219.     void ShowItems (bool show);
  220.  
  221. protected:
  222.     wxSize  m_size;
  223.     wxSize  m_minSize;
  224.     wxPoint m_position;
  225.     wxList  m_children;
  226.  
  227.     wxSize GetMaxWindowSize( wxWindow *window );
  228.     wxSize GetMinWindowSize( wxWindow *window );
  229.     wxSize GetMaxClientSize( wxWindow *window );
  230.     wxSize GetMinClientSize( wxWindow *window );
  231.     wxSize FitSize( wxWindow *window );
  232.     wxSize VirtualFitSize( wxWindow *window );
  233.  
  234.     virtual void DoSetMinSize( int width, int height );
  235.     virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
  236.     virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
  237.     virtual bool DoSetItemMinSize( int pos, int width, int height );
  238.  
  239. private:
  240.     DECLARE_CLASS(wxSizer);
  241. };
  242.  
  243. //---------------------------------------------------------------------------
  244. // wxGridSizer
  245. //---------------------------------------------------------------------------
  246.  
  247. class WXDLLEXPORT wxGridSizer: public wxSizer
  248. {
  249. public:
  250.     wxGridSizer( int rows, int cols, int vgap, int hgap );
  251.     wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
  252.  
  253.     void RecalcSizes();
  254.     wxSize CalcMin();
  255.  
  256.     void SetCols( int cols )    { m_cols = cols; }
  257.     void SetRows( int rows )    { m_rows = rows; }
  258.     void SetVGap( int gap )     { m_vgap = gap; }
  259.     void SetHGap( int gap )     { m_hgap = gap; }
  260.     int GetCols()               { return m_cols; }
  261.     int GetRows()               { return m_rows; }
  262.     int GetVGap()               { return m_vgap; }
  263.     int GetHGap()               { return m_hgap; }
  264.  
  265. protected:
  266.     int    m_rows;
  267.     int    m_cols;
  268.     int    m_vgap;
  269.     int    m_hgap;
  270.  
  271.     // return the number of total items and the number of columns and rows
  272.     int CalcRowsCols(int& rows, int& cols) const;
  273.  
  274.     void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
  275.  
  276. private:
  277.     DECLARE_CLASS(wxGridSizer);
  278. };
  279.  
  280. //---------------------------------------------------------------------------
  281. // wxFlexGridSizer
  282. //---------------------------------------------------------------------------
  283.  
  284. class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
  285. {
  286. public:
  287.     wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
  288.     wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
  289.     ~wxFlexGridSizer();
  290.  
  291.     void RecalcSizes();
  292.     wxSize CalcMin();
  293.  
  294.     void AddGrowableRow( size_t idx );
  295.     void RemoveGrowableRow( size_t idx );
  296.     void AddGrowableCol( size_t idx );
  297.     void RemoveGrowableCol( size_t idx );
  298.  
  299. protected:
  300.     int         *m_rowHeights;
  301.     int         *m_colWidths;
  302.     wxArrayInt  m_growableRows;
  303.     wxArrayInt  m_growableCols;
  304.  
  305.     void CreateArrays();
  306.  
  307. private:
  308.     DECLARE_CLASS(wxFlexGridSizer);
  309. };
  310.  
  311. //---------------------------------------------------------------------------
  312. // wxBoxSizer
  313. //---------------------------------------------------------------------------
  314.  
  315. class WXDLLEXPORT wxBoxSizer: public wxSizer
  316. {
  317. public:
  318.     wxBoxSizer( int orient );
  319.  
  320.     void RecalcSizes();
  321.     wxSize CalcMin();
  322.  
  323.     int GetOrientation()
  324.         { return m_orient; }
  325.  
  326.     void SetOrientation(int orient)
  327.         { m_orient = orient; }
  328.  
  329. protected:
  330.     int m_orient;
  331.     int m_stretchable;
  332.     int m_minWidth;
  333.     int m_minHeight;
  334.     int m_fixedWidth;
  335.     int m_fixedHeight;
  336.  
  337. private:
  338.     DECLARE_CLASS(wxBoxSizer);
  339. };
  340.  
  341. //---------------------------------------------------------------------------
  342. // wxStaticBoxSizer
  343. //---------------------------------------------------------------------------
  344.  
  345. #if wxUSE_STATBOX
  346.  
  347. class WXDLLEXPORT wxStaticBox;
  348.  
  349. class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
  350. {
  351. public:
  352.     wxStaticBoxSizer( wxStaticBox *box, int orient );
  353.  
  354.     void RecalcSizes();
  355.     wxSize CalcMin();
  356.  
  357.     wxStaticBox *GetStaticBox()
  358.         { return m_staticBox; }
  359.  
  360. protected:
  361.     wxStaticBox   *m_staticBox;
  362.  
  363. private:
  364.     DECLARE_CLASS(wxStaticBoxSizer);
  365. };
  366.  
  367. #endif // wxUSE_STATBOX
  368.  
  369. //---------------------------------------------------------------------------
  370. // wxNotebookSizer
  371. //---------------------------------------------------------------------------
  372.  
  373. #if wxUSE_NOTEBOOK
  374.  
  375. class WXDLLEXPORT wxNotebook;
  376.  
  377. class WXDLLEXPORT wxNotebookSizer: public wxSizer
  378. {
  379. public:
  380.     wxNotebookSizer( wxNotebook *nb );
  381.  
  382.     void RecalcSizes();
  383.     wxSize CalcMin();
  384.  
  385.     wxNotebook *GetNotebook()
  386.         { return m_notebook; }
  387.  
  388. protected:
  389.     wxNotebook   *m_notebook;
  390.  
  391. private:
  392.     DECLARE_CLASS(wxNotebookSizer);
  393. };
  394.  
  395. #endif // wxUSE_NOTEBOOK
  396.  
  397.  
  398. #endif
  399.   // __WXSIZER_H__
  400.