From: Robert Roebling Date: Thu, 20 Dec 2007 15:05:03 +0000 (+0000) Subject: Playing with wxgrid, adding optionnally native columns labels X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/71cf399ff0f1ddb966b48e512b0fb4e690f5c440 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 --- diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index c78fe9494d..7e32a046f2 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1312,6 +1312,7 @@ public: int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; } + void SetUseNativeColLabels( bool native = true ); void SetRowLabelSize( int width ); void SetColLabelSize( int height ); void SetLabelBackgroundColour( const wxColour& ); @@ -1834,6 +1835,8 @@ protected: int m_minAcceptableColWidth; wxArrayInt m_colWidths; wxArrayInt m_colRights; + + bool m_nativeColumnLabels; // get the col/row coords int GetColWidth(int col) const; diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index abdcfee872..a3c6b4287c 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_VTABLE, GridFrame::OnVTable) EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable) 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_COL, GridFrame::DeselectCol) @@ -146,6 +147,7 @@ GridFrame::GridFrame() fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V")); 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_TABULAR_GRID, _T("&Tabular Grid test\tCtrl-T")); fileMenu->AppendSeparator(); fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") ); @@ -1117,6 +1119,65 @@ void GridFrame::OnSmallGrid(wxCommandEvent& ) 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& ) { static long s_sizeGrid = 10000; @@ -1167,48 +1228,6 @@ void MyGridCellRenderer::Draw(wxGrid& grid, 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 // ============================================================================ diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index ba0b549477..5d9201af8e 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -107,6 +107,7 @@ public: void OnVTable( wxCommandEvent& ); void OnBugsTable( wxCommandEvent& ); void OnSmallGrid( wxCommandEvent& ); + void OnTabularGrid( wxCommandEvent& ); enum { @@ -146,6 +147,7 @@ public: ID_VTABLE, ID_BUGS_TABLE, ID_SMALL_GRID, + ID_TABULAR_GRID, ID_SELECT_UNSELECT, ID_SHOW_SELECTION, ID_SELECT_ALL, diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index adace08248..0fba2b3829 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4515,6 +4515,7 @@ void wxGrid::Init() m_dragRowOrCol = -1; m_isDragging = false; m_startDragPos = wxDefaultPosition; + m_nativeColumnLabels = false; m_waitForSlowClick = false; @@ -7912,19 +7913,6 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row ) 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), rowBottom = GetRowBottom(row) - 1; @@ -7936,7 +7924,6 @@ def __WXGTK20__ dc.SetPen( *wxWHITE_PEN ); dc.DrawLine( 1, rowTop, 1, rowBottom ); dc.DrawLine( 1, rowTop, m_rowLabelWidth - 1, rowTop ); -#endif dc.SetBackgroundMode( wxTRANSPARENT ); dc.SetTextForeground( GetLabelTextColour() ); @@ -7952,6 +7939,18 @@ def __WXGTK20__ 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 ) { if ( !m_numCols ) @@ -7975,29 +7974,30 @@ void wxGrid::DrawColLabel( wxDC& dc, int col ) wxRect rect; -#if 0 -def __WXGTK20__ - rect.SetX( colLeft + 1 ); - rect.SetY( 1 ); - rect.SetWidth( GetColWidth(col) - 2 ); - rect.SetHeight( m_colLabelHeight - 2 ); - - wxWindowDC *win_dc = (wxWindowDC*) &dc; + if (m_nativeColumnLabels) + { + rect.SetX( colLeft); + rect.SetY( 0 ); + rect.SetWidth( GetColWidth(col)); + rect.SetHeight( m_colLabelHeight ); - wxRendererNative::Get().DrawHeaderButton( win_dc->m_owner, dc, rect, 0 ); -#else - int colRight = GetColRight(col) - 1; + wxWindowDC *win_dc = (wxWindowDC*) &dc; + wxRendererNative::Get().DrawHeaderButton( win_dc->GetWindow(), dc, rect, 0 ); + } + else + { + int colRight = GetColRight(col) - 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, + 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 ); - dc.SetPen( *wxWHITE_PEN ); - dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight - 1 ); - dc.DrawLine( colLeft, 1, colRight, 1 ); -#endif + dc.SetPen( *wxWHITE_PEN ); + dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight - 1 ); + dc.DrawLine( colLeft, 1, colRight, 1 ); + } dc.SetBackgroundMode( wxTRANSPARENT ); dc.SetTextForeground( GetLabelTextColour() );