From d2520c85b013473a5861426aa639ad6ba8c83510 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 9 May 2001 22:31:17 +0000 Subject: [PATCH] Added accessors for the sub-windows in the wxGrid. Added methods to get/set the pen width used for the current cell highlight, bot normal and read-only. Fixed (I think) the problem of the cell highlight leaving extra lines behind when the grid lines are turned off git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10092 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/grid.h | 19 ++++++++++-- samples/newgrid/griddemo.cpp | 34 +++++++++++++++++++++ samples/newgrid/griddemo.h | 6 ++++ src/generic/grid.cpp | 57 ++++++++++++++++++++++++++++++++++-- 4 files changed, 111 insertions(+), 5 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index e4be782cb9..8a32fe9f70 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1078,7 +1078,7 @@ public: // handler to reduce screen flicker. // void ForceRefresh(); - + // ------ edit control functions // @@ -1160,6 +1160,8 @@ public: wxString GetColLabelValue( int col ); wxColour GetGridLineColour() { return m_gridLineColour; } wxColour GetCellHighlightColour() { return m_cellHighlightColour; } + int GetCellHighlightPenWidth() { return m_cellHighlightPenWidth; } + int GetCellHighlightROPenWidth() { return m_cellHighlightROPenWidth; } void SetRowLabelSize( int width ); void SetColLabelSize( int height ); @@ -1172,6 +1174,8 @@ public: void SetColLabelValue( int col, const wxString& ); void SetGridLineColour( const wxColour& ); void SetCellHighlightColour( const wxColour& ); + void SetCellHighlightPenWidth(int width); + void SetCellHighlightROPenWidth(int width); void EnableDragRowSize( bool enable = TRUE ); void DisableDragRowSize() { EnableDragRowSize( FALSE ); } @@ -1364,6 +1368,14 @@ public: m_extraHeight = extraHeight; } + // Accessors for component windows + wxWindow* GetGridWindow() { return (wxWindow*)m_gridWin; } + wxWindow* GetGridRowLabelWindow() { return (wxWindow*)m_rowLabelWin; } + wxWindow* GetGridColLabelWindow() { return (wxWindow*)m_colLabelWin; } + wxWindow* GetGridCornerLabelWindow() { return (wxWindow*)m_cornerLabelWin; } + + + // ------ For compatibility with previous wxGrid only... // // ************************************************ @@ -1605,6 +1617,9 @@ protected: wxColour m_gridLineColour; bool m_gridLinesEnabled; wxColour m_cellHighlightColour; + int m_cellHighlightPenWidth; + int m_cellHighlightROPenWidth; + // common part of AutoSizeColumn/Row() and GetBestSize() int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE); @@ -1741,7 +1756,7 @@ protected: void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol ); void HighlightBlock( const wxGridCellCoords& topLeft, - const wxGridCellCoords& bottomRight ) + const wxGridCellCoords& bottomRight ) { HighlightBlock( topLeft.GetRow(), topLeft.GetCol(), bottomRight.GetRow(), bottomRight.GetCol() ); } diff --git a/samples/newgrid/griddemo.cpp b/samples/newgrid/griddemo.cpp index cfc2de54a5..f8b14785a4 100644 --- a/samples/newgrid/griddemo.cpp +++ b/samples/newgrid/griddemo.cpp @@ -107,6 +107,9 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll) EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle) + EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth) + EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth) + EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick ) EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick ) EVT_GRID_ROW_SIZE( GridFrame::OnRowSize ) @@ -142,6 +145,8 @@ GridFrame::GridFrame() viewMenu->Append( ID_TOGGLECOLSIZING, "C&ol drag-resize", "", TRUE ); viewMenu->Append( ID_TOGGLEGRIDSIZING, "&Grid drag-resize", "", TRUE ); viewMenu->Append( ID_TOGGLEGRIDLINES, "&Grid Lines", "", TRUE ); + viewMenu->Append( ID_SET_HIGHLIGHT_WIDTH, "&Set Cell Highlight Width...", "" ); + viewMenu->Append( ID_SET_RO_HIGHLIGHT_WIDTH, "&Set Cell RO Highlight Width...", "" ); viewMenu->Append( ID_AUTOSIZECOLS, "&Auto-size cols" ); wxMenu *rowLabelMenu = new wxMenu; @@ -380,6 +385,35 @@ void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) ) GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES ) ); } +void GridFrame::OnSetHighlightWidth( wxCommandEvent& WXUNUSED(ev) ) +{ + wxString choices[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; + + wxSingleChoiceDialog dlg(this, "Choose the thickness of the highlight pen:", + "Pen Width", 11, choices); + + int current = grid->GetCellHighlightPenWidth(); + dlg.SetSelection(current); + if (dlg.ShowModal() == wxID_OK) { + grid->SetCellHighlightPenWidth(dlg.GetSelection()); + } +} + +void GridFrame::OnSetROHighlightWidth( wxCommandEvent& WXUNUSED(ev) ) +{ + wxString choices[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; + + wxSingleChoiceDialog dlg(this, "Choose the thickness of the highlight pen:", + "Pen Width", 11, choices); + + int current = grid->GetCellHighlightROPenWidth(); + dlg.SetSelection(current); + if (dlg.ShowModal() == wxID_OK) { + grid->SetCellHighlightROPenWidth(dlg.GetSelection()); + } +} + + void GridFrame::AutoSizeCols( wxCommandEvent& WXUNUSED(ev) ) { diff --git a/samples/newgrid/griddemo.h b/samples/newgrid/griddemo.h index 235ea69b58..b35d9cfc59 100644 --- a/samples/newgrid/griddemo.h +++ b/samples/newgrid/griddemo.h @@ -83,6 +83,9 @@ class GridFrame : public wxFrame void OnEditorShown(wxGridEvent&); void OnEditorHidden(wxGridEvent&); + void OnSetHighlightWidth(wxCommandEvent&); + void OnSetROHighlightWidth(wxCommandEvent&); + public: GridFrame(); ~GridFrame(); @@ -135,6 +138,9 @@ public: ID_DESELECT_COL, ID_DESELECT_CELL, + ID_SET_HIGHLIGHT_WIDTH, + ID_SET_RO_HIGHLIGHT_WIDTH, + ID_TESTFUNC }; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index d4d8541251..d6664efc0e 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3598,6 +3598,8 @@ void wxGrid::Init() m_gridLineColour = wxColour( 128, 128, 255 ); m_gridLinesEnabled = TRUE; m_cellHighlightColour = m_gridLineColour; + m_cellHighlightPenWidth = 3; + m_cellHighlightROPenWidth = 1; m_cursorMode = WXGRID_CURSOR_SELECT_CELL; m_winCapture = (wxWindow *)NULL; @@ -5991,10 +5993,27 @@ void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ) // hmmm... what could we do here to show that the cell is disabled? // for now, I just draw a thinner border than for the other ones, but // it doesn't look really good - dc.SetPen(wxPen(m_cellHighlightColour, attr->IsReadOnly() ? 1 : 3, wxSOLID)); - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRectangle(rect); + int penWidth = attr->IsReadOnly() ? m_cellHighlightROPenWidth : m_cellHighlightPenWidth; + + if (penWidth > 0) { + + // The center of th drawn line is where the position/width/height of + // the rectangle is actually at, (on wxMSW atr least,) so we will + // reduce the size of the rectangle to compensate for the thickness of + // the line. If this is too strange on non wxMSW platforms then + // please #ifdef this appropriately. + rect.x += penWidth/2; + rect.y += penWidth/2; + rect.width -= penWidth-1; + rect.height -= penWidth-1; + + + // Now draw the rectangle + dc.SetPen(wxPen(m_cellHighlightColour, penWidth, wxSOLID)); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(rect); + } #if 0 // VZ: my experiments with 3d borders... @@ -7547,6 +7566,38 @@ void wxGrid::SetCellHighlightColour( const wxColour& colour ) } } +void wxGrid::SetCellHighlightPenWidth(int width) +{ + if (m_cellHighlightPenWidth != width) { + m_cellHighlightPenWidth = width; + + // Just redrawing the cell highlight is not enough since that won't + // make any visible change if the the thickness is getting smaller. + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) + return; + wxRect rect = CellToRect(row, col); + m_gridWin->Refresh(TRUE, &rect); + } +} + +void wxGrid::SetCellHighlightROPenWidth(int width) +{ + if (m_cellHighlightROPenWidth != width) { + m_cellHighlightROPenWidth = width; + + // Just redrawing the cell highlight is not enough since that won't + // make any visible change if the the thickness is getting smaller. + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) + return; + wxRect rect = CellToRect(row, col); + m_gridWin->Refresh(TRUE, &rect); + } +} + void wxGrid::EnableGridLines( bool enable ) { if ( enable != m_gridLinesEnabled ) -- 2.45.2