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
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...
//
wxGRID_CHOICE,
wxGRID_COMBOBOX };
+ // overridden wxWindow methods
+ virtual void Fit();
+
protected:
+ virtual wxSize DoGetBestSize() const;
+
bool m_created;
bool m_displayed;
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;
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;
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 [] =
{
grid->SetColAttr(Col_Priority, attrRangeEditor);
grid->SetColAttr(Col_Severity, attrCombo);
- grid->AutoSize();
+ grid->SetMargins(0, 0);
+ grid->Fit();
Fit();
}
m_inOnKeyDown = FALSE;
m_batchCount = 0;
+ m_extraWidth =
+ m_extraHeight = 50;
+
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
//
}
}
-void wxGrid::AutoSizeColumns( bool setAsMin )
+int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
{
int width = m_rowLabelWidth;
for ( int col = 0; col < m_numCols; col++ )
{
- AutoSizeColumn(col, setAsMin);
+ 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();
}
// ----------------------------------------------------------------------------