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:
@@ -1078,9 +1078,11 @@ public:
|
|||||||
void AutoSizeColumn( int col, bool setAsMin = TRUE );
|
void AutoSizeColumn( int col, bool setAsMin = TRUE );
|
||||||
|
|
||||||
// auto size all columns (very ineffective for big grids!)
|
// 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
|
// 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
|
// and also set the grid size to just fit its contents
|
||||||
@@ -1222,7 +1224,13 @@ public:
|
|||||||
wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
|
wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
|
||||||
wxGridCellRenderer* GetDefaultRendererForType(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...
|
// ------ For compatibility with previous wxGrid only...
|
||||||
//
|
//
|
||||||
@@ -1384,7 +1392,12 @@ public:
|
|||||||
wxGRID_CHOICE,
|
wxGRID_CHOICE,
|
||||||
wxGRID_COMBOBOX };
|
wxGRID_COMBOBOX };
|
||||||
|
|
||||||
|
// overridden wxWindow methods
|
||||||
|
virtual void Fit();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
bool m_created;
|
bool m_created;
|
||||||
bool m_displayed;
|
bool m_displayed;
|
||||||
|
|
||||||
@@ -1444,6 +1457,10 @@ protected:
|
|||||||
int m_rowLabelWidth;
|
int m_rowLabelWidth;
|
||||||
int m_colLabelHeight;
|
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_labelBackgroundColour;
|
||||||
wxColour m_labelTextColour;
|
wxColour m_labelTextColour;
|
||||||
wxFont m_labelFont;
|
wxFont m_labelFont;
|
||||||
@@ -1459,6 +1476,10 @@ protected:
|
|||||||
wxColour m_gridLineColour;
|
wxColour m_gridLineColour;
|
||||||
bool m_gridLinesEnabled;
|
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
|
// if a column has a minimal width, it will be the value for it in this
|
||||||
// hash table
|
// hash table
|
||||||
wxHashTable m_colMinWidths;
|
wxHashTable m_colMinWidths;
|
||||||
|
@@ -756,10 +756,20 @@ static const wxChar* severities[] =
|
|||||||
static struct BugsGridData
|
static struct BugsGridData
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
const wxChar *summary;
|
#ifndef __BORLANDC__
|
||||||
|
wxString
|
||||||
|
#else
|
||||||
|
const wxChar *
|
||||||
|
#endif
|
||||||
|
summary;
|
||||||
Severity severity;
|
Severity severity;
|
||||||
int prio;
|
int prio;
|
||||||
const wxChar *platform;
|
#ifndef __BORLANDC__
|
||||||
|
wxString
|
||||||
|
#else
|
||||||
|
const wxChar *
|
||||||
|
#endif
|
||||||
|
platform;
|
||||||
bool opened;
|
bool opened;
|
||||||
} gs_dataBugsGrid [] =
|
} gs_dataBugsGrid [] =
|
||||||
{
|
{
|
||||||
@@ -1003,7 +1013,8 @@ BugsGridFrame::BugsGridFrame()
|
|||||||
grid->SetColAttr(Col_Priority, attrRangeEditor);
|
grid->SetColAttr(Col_Priority, attrRangeEditor);
|
||||||
grid->SetColAttr(Col_Severity, attrCombo);
|
grid->SetColAttr(Col_Severity, attrCombo);
|
||||||
|
|
||||||
grid->AutoSize();
|
grid->SetMargins(0, 0);
|
||||||
|
|
||||||
|
grid->Fit();
|
||||||
Fit();
|
Fit();
|
||||||
}
|
}
|
||||||
|
@@ -2944,6 +2944,9 @@ void wxGrid::Init()
|
|||||||
m_inOnKeyDown = FALSE;
|
m_inOnKeyDown = FALSE;
|
||||||
m_batchCount = 0;
|
m_batchCount = 0;
|
||||||
|
|
||||||
|
m_extraWidth =
|
||||||
|
m_extraHeight = 50;
|
||||||
|
|
||||||
CalcDimensions();
|
CalcDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3031,8 +3034,8 @@ void wxGrid::CalcDimensions()
|
|||||||
|
|
||||||
if ( m_numRows > 0 && m_numCols > 0 )
|
if ( m_numRows > 0 && m_numCols > 0 )
|
||||||
{
|
{
|
||||||
int right = GetColRight( m_numCols-1 ) + 50;
|
int right = GetColRight( m_numCols-1 ) + m_extraWidth;
|
||||||
int bottom = GetRowBottom( m_numRows-1 ) + 50;
|
int bottom = GetRowBottom( m_numRows-1 ) + m_extraHeight;
|
||||||
|
|
||||||
// TODO: restore the scroll position that we had before sizing
|
// 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;
|
int width = m_rowLabelWidth;
|
||||||
|
|
||||||
for ( int col = 0; col < m_numCols; col++ )
|
for ( int col = 0; col < m_numCols; col++ )
|
||||||
{
|
{
|
||||||
AutoSizeColumn(col, setAsMin);
|
if ( !calcOnly )
|
||||||
|
{
|
||||||
|
AutoSizeColumn(col, setAsMin);
|
||||||
|
}
|
||||||
|
|
||||||
width += GetColWidth(col);
|
width += GetColWidth(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
// also set the grid size to just fit the columns
|
return width;
|
||||||
SetSize(width, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGrid::AutoSizeRows(bool WXUNUSED(setAsMin))
|
int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
|
||||||
{
|
{
|
||||||
int height = m_colLabelHeight;
|
int height = m_colLabelHeight;
|
||||||
|
|
||||||
for ( int row = 0; row < m_numRows; row++ )
|
for ( int row = 0; row < m_numRows; row++ )
|
||||||
{
|
{
|
||||||
// AutoSizeRow(row, setAsMin) -- TODO
|
// if ( !calcOnly ) AutoSizeRow(row, setAsMin) -- TODO
|
||||||
|
|
||||||
height += GetRowHeight(row);
|
height += GetRowHeight(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSize(-1, height);
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGrid::AutoSize()
|
void wxGrid::AutoSize()
|
||||||
{
|
{
|
||||||
AutoSizeColumns();
|
// set the size too
|
||||||
AutoSizeRows();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user