]> git.saurik.com Git - wxWidgets.git/commitdiff
Added accessors for the sub-windows in the wxGrid.
authorRobin Dunn <robin@alldunn.com>
Wed, 9 May 2001 22:31:17 +0000 (22:31 +0000)
committerRobin Dunn <robin@alldunn.com>
Wed, 9 May 2001 22:31:17 +0000 (22:31 +0000)
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
samples/newgrid/griddemo.cpp
samples/newgrid/griddemo.h
src/generic/grid.cpp

index e4be782cb96a9149648d8e1e3d680a9b6b75939b..8a32fe9f7041835d6faeb6f1b19628045948886b 100644 (file)
@@ -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() ); }
 
index cfc2de54a5dd13e37ca4ea7fec93028e328a24ce..f8b14785a43c8eef549d6dd9439683521f0392d5 100644 (file)
@@ -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) )
 {
index 235ea69b58ecc9e78f09f13022fee74df4be26e7..b35d9cfc5922d5354f216da046a3636612a652e9 100644 (file)
@@ -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
     };
 
index d4d8541251349c28d06b65ee7a3b1a32b41bce6c..d6664efc0e8a052308af8edfd6d7cb42b29e1dd6 100644 (file)
@@ -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 )