Playing with wxgrid, adding optionnally native columns labels

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50861 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-12-20 15:05:03 +00:00
parent ac209a0f70
commit 71cf399ff0
4 changed files with 99 additions and 75 deletions

View File

@@ -1312,6 +1312,7 @@ public:
int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; } int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; }
void SetUseNativeColLabels( bool native = true );
void SetRowLabelSize( int width ); void SetRowLabelSize( int width );
void SetColLabelSize( int height ); void SetColLabelSize( int height );
void SetLabelBackgroundColour( const wxColour& ); void SetLabelBackgroundColour( const wxColour& );
@@ -1834,6 +1835,8 @@ protected:
int m_minAcceptableColWidth; int m_minAcceptableColWidth;
wxArrayInt m_colWidths; wxArrayInt m_colWidths;
wxArrayInt m_colRights; wxArrayInt m_colRights;
bool m_nativeColumnLabels;
// get the col/row coords // get the col/row coords
int GetColWidth(int col) const; int GetColWidth(int col) const;

View File

@@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_VTABLE, GridFrame::OnVTable) EVT_MENU( ID_VTABLE, GridFrame::OnVTable)
EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable) EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable)
EVT_MENU( ID_SMALL_GRID, GridFrame::OnSmallGrid) EVT_MENU( ID_SMALL_GRID, GridFrame::OnSmallGrid)
EVT_MENU( ID_TABULAR_GRID, GridFrame::OnTabularGrid)
EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell) EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell)
EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol) EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol)
@@ -146,6 +147,7 @@ GridFrame::GridFrame()
fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V")); fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V"));
fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B")); fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B"));
fileMenu->Append( ID_SMALL_GRID, _T("&Small Grid test\tCtrl-S")); fileMenu->Append( ID_SMALL_GRID, _T("&Small Grid test\tCtrl-S"));
fileMenu->Append( ID_TABULAR_GRID, _T("&Tabular Grid test\tCtrl-T"));
fileMenu->AppendSeparator(); fileMenu->AppendSeparator();
fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") ); fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") );
@@ -1117,6 +1119,65 @@ void GridFrame::OnSmallGrid(wxCommandEvent& )
frame->Show(true); frame->Show(true);
} }
// ----------------------------------------------------------------------------
// MyGridCellAttrProvider
// ----------------------------------------------------------------------------
MyGridCellAttrProvider::MyGridCellAttrProvider()
{
m_attrForOddRows = new wxGridCellAttr;
m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
}
MyGridCellAttrProvider::~MyGridCellAttrProvider()
{
m_attrForOddRows->DecRef();
}
wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
{
wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
if ( row % 2 )
{
if ( !attr )
{
attr = m_attrForOddRows;
attr->IncRef();
}
else
{
if ( !attr->HasBackgroundColour() )
{
wxGridCellAttr *attrNew = attr->Clone();
attr->DecRef();
attr = attrNew;
attr->SetBackgroundColour(*wxLIGHT_GREY);
}
}
}
return attr;
}
// ----------------------------------------------------------------------------
void GridFrame::OnTabularGrid(wxCommandEvent& )
{
wxFrame* frame = new wxFrame(NULL, wxID_ANY, _T("A small tabular Grid"),
wxDefaultPosition, wxSize(640, 480));
wxGrid* grid = new wxGrid(frame, wxID_ANY, wxPoint(10,10), wxSize(40,40),
wxWANTS_CHARS | wxBORDER_SUNKEN);
grid->SetRowLabelSize( 0 );
grid->DisableDragRowSize();
grid->SetUseNativeColLabels();
grid->CreateGrid(10,10);
grid->SetSelectionMode( wxGrid::wxGridSelectRows );
frame->Show(true);
}
void GridFrame::OnVTable(wxCommandEvent& ) void GridFrame::OnVTable(wxCommandEvent& )
{ {
static long s_sizeGrid = 10000; static long s_sizeGrid = 10000;
@@ -1167,48 +1228,6 @@ void MyGridCellRenderer::Draw(wxGrid& grid,
dc.DrawEllipse(rect); dc.DrawEllipse(rect);
} }
// ----------------------------------------------------------------------------
// MyGridCellAttrProvider
// ----------------------------------------------------------------------------
MyGridCellAttrProvider::MyGridCellAttrProvider()
{
m_attrForOddRows = new wxGridCellAttr;
m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
}
MyGridCellAttrProvider::~MyGridCellAttrProvider()
{
m_attrForOddRows->DecRef();
}
wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
{
wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
if ( row % 2 )
{
if ( !attr )
{
attr = m_attrForOddRows;
attr->IncRef();
}
else
{
if ( !attr->HasBackgroundColour() )
{
wxGridCellAttr *attrNew = attr->Clone();
attr->DecRef();
attr = attrNew;
attr->SetBackgroundColour(*wxLIGHT_GREY);
}
}
}
return attr;
}
// ============================================================================ // ============================================================================
// BigGridFrame and BigGridTable: Sample of a non-standard table // BigGridFrame and BigGridTable: Sample of a non-standard table
// ============================================================================ // ============================================================================

View File

@@ -107,6 +107,7 @@ public:
void OnVTable( wxCommandEvent& ); void OnVTable( wxCommandEvent& );
void OnBugsTable( wxCommandEvent& ); void OnBugsTable( wxCommandEvent& );
void OnSmallGrid( wxCommandEvent& ); void OnSmallGrid( wxCommandEvent& );
void OnTabularGrid( wxCommandEvent& );
enum enum
{ {
@@ -146,6 +147,7 @@ public:
ID_VTABLE, ID_VTABLE,
ID_BUGS_TABLE, ID_BUGS_TABLE,
ID_SMALL_GRID, ID_SMALL_GRID,
ID_TABULAR_GRID,
ID_SELECT_UNSELECT, ID_SELECT_UNSELECT,
ID_SHOW_SELECTION, ID_SHOW_SELECTION,
ID_SELECT_ALL, ID_SELECT_ALL,

View File

@@ -4515,6 +4515,7 @@ void wxGrid::Init()
m_dragRowOrCol = -1; m_dragRowOrCol = -1;
m_isDragging = false; m_isDragging = false;
m_startDragPos = wxDefaultPosition; m_startDragPos = wxDefaultPosition;
m_nativeColumnLabels = false;
m_waitForSlowClick = false; m_waitForSlowClick = false;
@@ -7912,19 +7913,6 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
wxRect rect; wxRect rect;
#if 0
def __WXGTK20__
rect.SetX( 1 );
rect.SetY( GetRowTop(row) + 1 );
rect.SetWidth( m_rowLabelWidth - 2 );
rect.SetHeight( GetRowHeight(row) - 2 );
CalcScrolledPosition( 0, rect.y, NULL, &rect.y );
wxWindowDC *win_dc = (wxWindowDC*) &dc;
wxRendererNative::Get().DrawHeaderButton( win_dc->m_owner, dc, rect, 0 );
#else
int rowTop = GetRowTop(row), int rowTop = GetRowTop(row),
rowBottom = GetRowBottom(row) - 1; rowBottom = GetRowBottom(row) - 1;
@@ -7936,7 +7924,6 @@ def __WXGTK20__
dc.SetPen( *wxWHITE_PEN ); dc.SetPen( *wxWHITE_PEN );
dc.DrawLine( 1, rowTop, 1, rowBottom ); dc.DrawLine( 1, rowTop, 1, rowBottom );
dc.DrawLine( 1, rowTop, m_rowLabelWidth - 1, rowTop ); dc.DrawLine( 1, rowTop, m_rowLabelWidth - 1, rowTop );
#endif
dc.SetBackgroundMode( wxTRANSPARENT ); dc.SetBackgroundMode( wxTRANSPARENT );
dc.SetTextForeground( GetLabelTextColour() ); dc.SetTextForeground( GetLabelTextColour() );
@@ -7952,6 +7939,18 @@ def __WXGTK20__
DrawTextRectangle( dc, GetRowLabelValue( row ), rect, hAlign, vAlign ); DrawTextRectangle( dc, GetRowLabelValue( row ), rect, hAlign, vAlign );
} }
void wxGrid::SetUseNativeColLabels( bool native )
{
m_nativeColumnLabels = native;
if (native)
{
int height = wxRendererNative::Get().GetHeaderButtonHeight( this );
SetColLabelSize( height );
}
m_colLabelWin->Refresh();
}
void wxGrid::DrawColLabels( wxDC& dc,const wxArrayInt& cols ) void wxGrid::DrawColLabels( wxDC& dc,const wxArrayInt& cols )
{ {
if ( !m_numCols ) if ( !m_numCols )
@@ -7975,29 +7974,30 @@ void wxGrid::DrawColLabel( wxDC& dc, int col )
wxRect rect; wxRect rect;
#if 0 if (m_nativeColumnLabels)
def __WXGTK20__ {
rect.SetX( colLeft + 1 ); rect.SetX( colLeft);
rect.SetY( 1 ); rect.SetY( 0 );
rect.SetWidth( GetColWidth(col) - 2 ); rect.SetWidth( GetColWidth(col));
rect.SetHeight( m_colLabelHeight - 2 ); rect.SetHeight( m_colLabelHeight );
wxWindowDC *win_dc = (wxWindowDC*) &dc; wxWindowDC *win_dc = (wxWindowDC*) &dc;
wxRendererNative::Get().DrawHeaderButton( win_dc->GetWindow(), dc, rect, 0 );
}
else
{
int colRight = GetColRight(col) - 1;
wxRendererNative::Get().DrawHeaderButton( win_dc->m_owner, dc, rect, 0 ); dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID) );
#else dc.DrawLine( colRight, 0, colRight, m_colLabelHeight - 1 );
int colRight = GetColRight(col) - 1; dc.DrawLine( colLeft, 0, colRight, 0 );
dc.DrawLine( colLeft, m_colLabelHeight - 1,
dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID) );
dc.DrawLine( colRight, 0, colRight, m_colLabelHeight - 1 );
dc.DrawLine( colLeft, 0, colRight, 0 );
dc.DrawLine( colLeft, m_colLabelHeight - 1,
colRight + 1, m_colLabelHeight - 1 ); colRight + 1, m_colLabelHeight - 1 );
dc.SetPen( *wxWHITE_PEN ); dc.SetPen( *wxWHITE_PEN );
dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight - 1 ); dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight - 1 );
dc.DrawLine( colLeft, 1, colRight, 1 ); dc.DrawLine( colLeft, 1, colRight, 1 );
#endif }
dc.SetBackgroundMode( wxTRANSPARENT ); dc.SetBackgroundMode( wxTRANSPARENT );
dc.SetTextForeground( GetLabelTextColour() ); dc.SetTextForeground( GetLabelTextColour() );