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
This commit is contained in:
Robin Dunn
2001-05-09 22:31:17 +00:00
parent 3b36695de4
commit d2520c85b0
4 changed files with 111 additions and 5 deletions

View File

@@ -1078,7 +1078,7 @@ public:
// handler to reduce screen flicker. // handler to reduce screen flicker.
// //
void ForceRefresh(); void ForceRefresh();
// ------ edit control functions // ------ edit control functions
// //
@@ -1160,6 +1160,8 @@ public:
wxString GetColLabelValue( int col ); wxString GetColLabelValue( int col );
wxColour GetGridLineColour() { return m_gridLineColour; } wxColour GetGridLineColour() { return m_gridLineColour; }
wxColour GetCellHighlightColour() { return m_cellHighlightColour; } wxColour GetCellHighlightColour() { return m_cellHighlightColour; }
int GetCellHighlightPenWidth() { return m_cellHighlightPenWidth; }
int GetCellHighlightROPenWidth() { return m_cellHighlightROPenWidth; }
void SetRowLabelSize( int width ); void SetRowLabelSize( int width );
void SetColLabelSize( int height ); void SetColLabelSize( int height );
@@ -1172,6 +1174,8 @@ public:
void SetColLabelValue( int col, const wxString& ); void SetColLabelValue( int col, const wxString& );
void SetGridLineColour( const wxColour& ); void SetGridLineColour( const wxColour& );
void SetCellHighlightColour( const wxColour& ); void SetCellHighlightColour( const wxColour& );
void SetCellHighlightPenWidth(int width);
void SetCellHighlightROPenWidth(int width);
void EnableDragRowSize( bool enable = TRUE ); void EnableDragRowSize( bool enable = TRUE );
void DisableDragRowSize() { EnableDragRowSize( FALSE ); } void DisableDragRowSize() { EnableDragRowSize( FALSE ); }
@@ -1364,6 +1368,14 @@ public:
m_extraHeight = extraHeight; 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... // ------ For compatibility with previous wxGrid only...
// //
// ************************************************ // ************************************************
@@ -1605,6 +1617,9 @@ protected:
wxColour m_gridLineColour; wxColour m_gridLineColour;
bool m_gridLinesEnabled; bool m_gridLinesEnabled;
wxColour m_cellHighlightColour; wxColour m_cellHighlightColour;
int m_cellHighlightPenWidth;
int m_cellHighlightROPenWidth;
// common part of AutoSizeColumn/Row() and GetBestSize() // common part of AutoSizeColumn/Row() and GetBestSize()
int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE); int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE);
@@ -1741,7 +1756,7 @@ protected:
void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol ); void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol );
void HighlightBlock( const wxGridCellCoords& topLeft, void HighlightBlock( const wxGridCellCoords& topLeft,
const wxGridCellCoords& bottomRight ) const wxGridCellCoords& bottomRight )
{ HighlightBlock( topLeft.GetRow(), topLeft.GetCol(), { HighlightBlock( topLeft.GetRow(), topLeft.GetCol(),
bottomRight.GetRow(), bottomRight.GetCol() ); } bottomRight.GetRow(), bottomRight.GetCol() ); }

View File

@@ -107,6 +107,9 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll) EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll)
EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle) 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_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick )
EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick ) EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick )
EVT_GRID_ROW_SIZE( GridFrame::OnRowSize ) EVT_GRID_ROW_SIZE( GridFrame::OnRowSize )
@@ -142,6 +145,8 @@ GridFrame::GridFrame()
viewMenu->Append( ID_TOGGLECOLSIZING, "C&ol drag-resize", "", TRUE ); viewMenu->Append( ID_TOGGLECOLSIZING, "C&ol drag-resize", "", TRUE );
viewMenu->Append( ID_TOGGLEGRIDSIZING, "&Grid drag-resize", "", TRUE ); viewMenu->Append( ID_TOGGLEGRIDSIZING, "&Grid drag-resize", "", TRUE );
viewMenu->Append( ID_TOGGLEGRIDLINES, "&Grid Lines", "", 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" ); viewMenu->Append( ID_AUTOSIZECOLS, "&Auto-size cols" );
wxMenu *rowLabelMenu = new wxMenu; wxMenu *rowLabelMenu = new wxMenu;
@@ -380,6 +385,35 @@ void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) )
GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES ) ); 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) ) void GridFrame::AutoSizeCols( wxCommandEvent& WXUNUSED(ev) )
{ {

View File

@@ -83,6 +83,9 @@ class GridFrame : public wxFrame
void OnEditorShown(wxGridEvent&); void OnEditorShown(wxGridEvent&);
void OnEditorHidden(wxGridEvent&); void OnEditorHidden(wxGridEvent&);
void OnSetHighlightWidth(wxCommandEvent&);
void OnSetROHighlightWidth(wxCommandEvent&);
public: public:
GridFrame(); GridFrame();
~GridFrame(); ~GridFrame();
@@ -135,6 +138,9 @@ public:
ID_DESELECT_COL, ID_DESELECT_COL,
ID_DESELECT_CELL, ID_DESELECT_CELL,
ID_SET_HIGHLIGHT_WIDTH,
ID_SET_RO_HIGHLIGHT_WIDTH,
ID_TESTFUNC ID_TESTFUNC
}; };

View File

@@ -3598,6 +3598,8 @@ void wxGrid::Init()
m_gridLineColour = wxColour( 128, 128, 255 ); m_gridLineColour = wxColour( 128, 128, 255 );
m_gridLinesEnabled = TRUE; m_gridLinesEnabled = TRUE;
m_cellHighlightColour = m_gridLineColour; m_cellHighlightColour = m_gridLineColour;
m_cellHighlightPenWidth = 3;
m_cellHighlightROPenWidth = 1;
m_cursorMode = WXGRID_CURSOR_SELECT_CELL; m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_winCapture = (wxWindow *)NULL; 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? // 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 // for now, I just draw a thinner border than for the other ones, but
// it doesn't look really good // 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 #if 0
// VZ: my experiments with 3d borders... // 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 ) void wxGrid::EnableGridLines( bool enable )
{ {
if ( enable != m_gridLinesEnabled ) if ( enable != m_gridLinesEnabled )