grid autosize fixes/changes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-02-28 16:40:14 +00:00
parent bb338b31a7
commit 266e83674a
3 changed files with 68 additions and 17 deletions

View File

@@ -1078,9 +1078,11 @@ public:
void AutoSizeColumn( int col, bool setAsMin = TRUE );
// auto size all columns (very ineffective for big grids!)
void AutoSizeColumns( bool setAsMin = TRUE );
void AutoSizeColumns( bool setAsMin = TRUE )
{ (void)SetOrCalcColumnSizes(TRUE, setAsMin); }
void AutoSizeRows( bool setAsMin = TRUE );
void AutoSizeRows( bool setAsMin = TRUE )
{ (void)SetOrCalcRowSizes(TRUE, setAsMin); }
// auto size the grid, that is make the columns/rows of the "right" size
// and also set the grid size to just fit its contents
@@ -1222,7 +1224,13 @@ public:
wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
// grid may occupy more space than needed for its rows/columns, this
// function allows to set how big this extra space is
void SetMargins(int extraWidth, int extraHeight)
{
m_extraWidth = extraWidth;
m_extraHeight = extraHeight;
}
// ------ For compatibility with previous wxGrid only...
//
@@ -1384,7 +1392,12 @@ public:
wxGRID_CHOICE,
wxGRID_COMBOBOX };
// overridden wxWindow methods
virtual void Fit();
protected:
virtual wxSize DoGetBestSize() const;
bool m_created;
bool m_displayed;
@@ -1444,6 +1457,10 @@ protected:
int m_rowLabelWidth;
int m_colLabelHeight;
// the size of the margin left to the right and bottom of the cell area
int m_extraWidth,
m_extraHeight;
wxColour m_labelBackgroundColour;
wxColour m_labelTextColour;
wxFont m_labelFont;
@@ -1459,6 +1476,10 @@ protected:
wxColour m_gridLineColour;
bool m_gridLinesEnabled;
// common part of AutoSizeColumn/Row() and GetBestSize()
int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE);
int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = TRUE);
// if a column has a minimal width, it will be the value for it in this
// hash table
wxHashTable m_colMinWidths;

View File

@@ -756,10 +756,20 @@ static const wxChar* severities[] =
static struct BugsGridData
{
int id;
const wxChar *summary;
#ifndef __BORLANDC__
wxString
#else
const wxChar *
#endif
summary;
Severity severity;
int prio;
const wxChar *platform;
#ifndef __BORLANDC__
wxString
#else
const wxChar *
#endif
platform;
bool opened;
} gs_dataBugsGrid [] =
{
@@ -1003,7 +1013,8 @@ BugsGridFrame::BugsGridFrame()
grid->SetColAttr(Col_Priority, attrRangeEditor);
grid->SetColAttr(Col_Severity, attrCombo);
grid->AutoSize();
grid->SetMargins(0, 0);
grid->Fit();
Fit();
}

View File

@@ -2944,6 +2944,9 @@ void wxGrid::Init()
m_inOnKeyDown = FALSE;
m_batchCount = 0;
m_extraWidth =
m_extraHeight = 50;
CalcDimensions();
}
@@ -3031,8 +3034,8 @@ void wxGrid::CalcDimensions()
if ( m_numRows > 0 && m_numCols > 0 )
{
int right = GetColRight( m_numCols-1 ) + 50;
int bottom = GetRowBottom( m_numRows-1 ) + 50;
int right = GetColRight( m_numCols-1 ) + m_extraWidth;
int bottom = GetRowBottom( m_numRows-1 ) + m_extraHeight;
// TODO: restore the scroll position that we had before sizing
//
@@ -6903,39 +6906,55 @@ void wxGrid::AutoSizeColumn( int col, bool setAsMin )
}
}
void wxGrid::AutoSizeColumns( bool setAsMin )
int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
{
int width = m_rowLabelWidth;
for ( int col = 0; col < m_numCols; col++ )
{
if ( !calcOnly )
{
AutoSizeColumn(col, setAsMin);
}
width += GetColWidth(col);
}
// also set the grid size to just fit the columns
SetSize(width, -1);
return width;
}
void wxGrid::AutoSizeRows(bool WXUNUSED(setAsMin))
int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
{
int height = m_colLabelHeight;
for ( int row = 0; row < m_numRows; row++ )
{
// AutoSizeRow(row, setAsMin) -- TODO
// if ( !calcOnly ) AutoSizeRow(row, setAsMin) -- TODO
height += GetRowHeight(row);
}
SetSize(-1, height);
return height;
}
void wxGrid::AutoSize()
{
AutoSizeColumns();
AutoSizeRows();
// set the size too
SetSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE));
}
wxSize wxGrid::DoGetBestSize() const
{
// don't set sizes, only calculate them
wxGrid *self = (wxGrid *)this; // const_cast
return wxSize(self->SetOrCalcColumnSizes(TRUE),
self->SetOrCalcRowSizes(TRUE));
}
void wxGrid::Fit()
{
AutoSize();
}
// ----------------------------------------------------------------------------