Added wxGridSizer.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7075 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2000-04-06 19:31:51 +00:00
parent 8bbce21e90
commit 6067cee7fa
2 changed files with 224 additions and 53 deletions

View File

@@ -113,53 +113,90 @@ protected:
class WXDLLEXPORT wxSizer: public wxObject class WXDLLEXPORT wxSizer: public wxObject
{ {
DECLARE_CLASS(wxSizer);
public: public:
wxSizer(); wxSizer();
~wxSizer(); ~wxSizer();
virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); /* These should be called Append() really. */
virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
virtual bool Remove( wxWindow *window ); virtual bool Remove( wxWindow *window );
virtual bool Remove( wxSizer *sizer ); virtual bool Remove( wxSizer *sizer );
virtual bool Remove( int pos ); virtual bool Remove( int pos );
void SetDimension( int x, int y, int width, int height ); void SetDimension( int x, int y, int width, int height );
wxSize GetSize() wxSize GetSize()
{ return m_size; } { return m_size; }
wxPoint GetPosition() wxPoint GetPosition()
{ return m_position; } { return m_position; }
wxSize GetMinSize() wxSize GetMinSize()
{ return CalcMin(); } { return CalcMin(); }
virtual void RecalcSizes() = 0; virtual void RecalcSizes() = 0;
virtual wxSize CalcMin() = 0; virtual wxSize CalcMin() = 0;
virtual void Layout(); virtual void Layout();
void Fit( wxWindow *window ); void Fit( wxWindow *window );
void SetSizeHints( wxWindow *window ); void SetSizeHints( wxWindow *window );
wxList& GetChildren() wxList& GetChildren()
{ return m_children; } { return m_children; }
protected: protected:
wxSize m_size; wxSize m_size;
wxPoint m_position; wxPoint m_position;
wxList m_children; wxList m_children;
wxSize GetMinWindowSize( wxWindow *window ); wxSize GetMinWindowSize( wxWindow *window );
private:
DECLARE_CLASS(wxSizer);
};
//---------------------------------------------------------------------------
// wxGridSizer
//---------------------------------------------------------------------------
class WXDLLEXPORT wxGridSizer: public wxSizer
{
public:
wxGridSizer( int rows, int cols, int vgap, int hgap );
wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
void RecalcSizes();
wxSize CalcMin();
void SetCols( int cols ) { m_cols = cols; }
void SetRows( int rows ) { m_rows = rows; }
void SetVGap( int gap ) { m_vgap = gap; }
void SetHGap( int gap ) { m_hgap = gap; }
int GetCols() { return m_cols; }
int GetRows() { return m_rows; }
int GetVGap() { return m_vgap; }
int GetHGap() { return m_hgap; }
protected:
int m_rows;
int m_cols;
int m_vgap;
int m_hgap;
void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
private:
DECLARE_CLASS(wxGridSizer);
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -168,15 +205,14 @@ protected:
class WXDLLEXPORT wxBoxSizer: public wxSizer class WXDLLEXPORT wxBoxSizer: public wxSizer
{ {
DECLARE_CLASS(wxBoxSizer);
public: public:
wxBoxSizer( int orient ); wxBoxSizer( int orient );
void RecalcSizes(); void RecalcSizes();
wxSize CalcMin(); wxSize CalcMin();
int GetOrientation() int GetOrientation()
{ return m_orient; } { return m_orient; }
protected: protected:
int m_orient; int m_orient;
@@ -185,6 +221,9 @@ protected:
int m_minHeight; int m_minHeight;
int m_fixedWidth; int m_fixedWidth;
int m_fixedHeight; int m_fixedHeight;
private:
DECLARE_CLASS(wxBoxSizer);
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -193,18 +232,20 @@ protected:
class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
{ {
DECLARE_CLASS(wxStaticBoxSizer);
public: public:
wxStaticBoxSizer( wxStaticBox *box, int orient ); wxStaticBoxSizer( wxStaticBox *box, int orient );
void RecalcSizes(); void RecalcSizes();
wxSize CalcMin(); wxSize CalcMin();
wxStaticBox *GetStaticBox() wxStaticBox *GetStaticBox()
{ return m_staticBox; } { return m_staticBox; }
protected: protected:
wxStaticBox *m_staticBox; wxStaticBox *m_staticBox;
private:
DECLARE_CLASS(wxStaticBoxSizer);
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -215,18 +256,20 @@ protected:
class WXDLLEXPORT wxNotebookSizer: public wxSizer class WXDLLEXPORT wxNotebookSizer: public wxSizer
{ {
DECLARE_CLASS(wxNotebookSizer);
public: public:
wxNotebookSizer( wxNotebook *nb ); wxNotebookSizer( wxNotebook *nb );
void RecalcSizes(); void RecalcSizes();
wxSize CalcMin(); wxSize CalcMin();
wxNotebook *GetNotebook() wxNotebook *GetNotebook()
{ return m_notebook; } { return m_notebook; }
protected: protected:
wxNotebook *m_notebook; wxNotebook *m_notebook;
private:
DECLARE_CLASS(wxNotebookSizer);
}; };
#endif #endif

View File

@@ -29,6 +29,7 @@
IMPLEMENT_ABSTRACT_CLASS(wxSizerItem, wxObject); IMPLEMENT_ABSTRACT_CLASS(wxSizerItem, wxObject);
IMPLEMENT_ABSTRACT_CLASS(wxSizer, wxObject); IMPLEMENT_ABSTRACT_CLASS(wxSizer, wxObject);
IMPLEMENT_ABSTRACT_CLASS(wxGridSizer, wxObject);
IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer, wxSizer); IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer, wxSizer);
IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer, wxBoxSizer); IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer, wxBoxSizer);
#if wxUSE_NOTEBOOK #if wxUSE_NOTEBOOK
@@ -368,6 +369,133 @@ void wxSizer::SetDimension( int x, int y, int width, int height )
RecalcSizes(); RecalcSizes();
} }
//---------------------------------------------------------------------------
// wxGridSizer
//---------------------------------------------------------------------------
wxGridSizer::wxGridSizer( int rows, int cols, int vgap, int hgap )
{
m_rows = rows;
m_cols = cols;
m_vgap = vgap;
m_hgap = hgap;
}
wxGridSizer::wxGridSizer( int cols, int vgap, int hgap )
{
m_rows = 0;
m_cols = cols;
m_vgap = vgap;
m_hgap = hgap;
}
void wxGridSizer::RecalcSizes()
{
if (m_children.GetCount() == 0)
return;
int nitems = m_children.GetCount();
int nrows = m_rows;
int ncols = m_cols;
if (ncols > 0)
nrows = (nitems + ncols-1) / ncols;
else
ncols = (nitems + nrows-1) / nrows;
wxSize sz( GetSize() );
wxPoint pt( GetPosition() );
int w = (sz.x - (ncols - 1) * m_hgap) / ncols;
int h = (sz.y - (nrows - 1) * m_vgap) / nrows;
int x = pt.x;
for (int c = 0; c < ncols; c++)
{
int y = pt.y;
for (int r = 0; r < nrows; r++)
{
int i = r * ncols + c;
if (i < nitems)
{
wxNode *node = m_children.Nth( i );
wxASSERT( node );
SetItemBounds( (wxSizerItem*) node->Data(), x, y, w, h);
}
y = y + h + m_vgap;
}
x = x + w + m_hgap;
}
}
wxSize wxGridSizer::CalcMin()
{
if (m_children.GetCount() == 0)
return wxSize(10,10);
int nitems = m_children.GetCount();
int nrows = m_rows;
int ncols = m_cols;
if (ncols > 0)
nrows = (nitems + ncols-1) / ncols;
else
ncols = (nitems + nrows-1) / nrows;
/* Find the max width and height for any component */
int w = 0;
int h = 0;
wxNode *node = m_children.First();
while (node)
{
wxSizerItem *item = (wxSizerItem*)node->Data();
wxSize sz( item->CalcMin() );
w = wxMax( w, sz.x );
h = wxMax( h, sz.y );
node = node->Next();
}
return wxSize(ncols * w + (ncols-1) * m_hgap,
nrows * h + (nrows-1) * m_vgap);
}
void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h )
{
wxPoint pt( x,y );
wxSize sz( item->CalcMin() );
int flag = item->GetFlag();
if ((flag & wxEXPAND) || (flag & wxSHAPED))
{
sz = wxSize(w, h);
}
else
{
if (flag & wxALIGN_CENTER_HORIZONTAL)
{
pt.x = x + (w - sz.x) / 2;
}
else if (flag & wxALIGN_RIGHT)
{
pt.x = x + (w - sz.x);
}
if (flag & wxALIGN_CENTER_VERTICAL)
{
pt.y = y + (h - sz.y) / 2;
}
else if (flag & wxALIGN_BOTTOM)
{
pt.y = y + (h - sz.y);
}
}
item->SetDimension(pt, sz);
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxBoxSizer // wxBoxSizer
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------