]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wxGrid editors background painting.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 Oct 2012 16:44:02 +0000 (16:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 Oct 2012 16:44:02 +0000 (16:44 +0000)
There were two fundamental problems: first, we painted on a separately created
wxClientDC instead of using the wxPaintDC already available in wxGrid. Second,
we invalidated the control while painting, resulting in endless repainting, at
least under wxGTK.

Fix the first problem by passing wxDC to wxGridCellEditor::PaintBackground()
and the second one by not refreshing the control from there as it just seems
unnecessary.

Also pass the attribute by reference for consistency with
wxGridCellRenderer::Draw() and because this pointer can never be NULL.

Closes #2628.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72697 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/grid.h
include/wx/generic/grideditors.h
samples/grid/griddemo.cpp
src/generic/grid.cpp
src/generic/grideditors.cpp

index 6ddc69b43a40dea67e56e1331fef45e2810907a9..4fe4b1686b09b1a6d3158c951580dfa2fcbab15a 100644 (file)
@@ -213,7 +213,9 @@ public:
 
     // Draws the part of the cell not occupied by the control: the base class
     // version just fills it with background colour from the attribute
-    virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+    virtual void PaintBackground(wxDC& dc,
+                                 const wxRect& rectCell,
+                                 const wxGridCellAttr& attr);
 
 
     // The methods called by wxGrid when a cell is edited: first BeginEdit() is
index 4a7b9270ddf696a900592cf5253b16d8e41ecee9..aa0fd7af43fe76b50b7a167e5e8ff7f5dd6aed7e 100644 (file)
@@ -59,7 +59,9 @@ public:
                         wxEvtHandler* evtHandler);
     virtual void SetSize(const wxRect& rect);
 
-    virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+    virtual void PaintBackground(wxDC& dc,
+                                 const wxRect& rectCell,
+                                 const wxGridCellAttr& attr);
 
     virtual bool IsAcceptedKey(wxKeyEvent& event);
     virtual void BeginEdit(int row, int col, wxGrid* grid);
@@ -297,7 +299,9 @@ public:
 
     virtual void SetSize(const wxRect& rect);
 
-    virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+    virtual void PaintBackground(wxDC& dc,
+                                 const wxRect& rectCell,
+                                 const wxGridCellAttr& attr);
 
     virtual void BeginEdit(int row, int col, wxGrid* grid);
     virtual bool EndEdit(int row, int col, const wxGrid* grid,
index dc0f993dfa41cfb808f385b66e3ed46d74d6195f..ad85aa111775d95c6b56dd71a7862439d5bdf21b 100644 (file)
@@ -444,6 +444,9 @@ GridFrame::GridFrame()
     grid->SetCellValue( 0, 5, wxT("Press\nCtrl+arrow\nto skip over\ncells") );
 
     grid->SetRowSize( 99, 60 );
+    grid->SetCellValue(98, 98, "Test background colour setting");
+    grid->SetCellBackgroundColour(98, 99, wxColour(255, 127, 127));
+    grid->SetCellBackgroundColour(99, 98, wxColour(255, 127, 127));
     grid->SetCellValue( 99, 99, wxT("Ctrl+End\nwill go to\nthis cell") );
     grid->SetCellValue( 1, 0, wxT("This default cell will overflow into neighboring cells, but not if you turn overflow off."));
 
@@ -465,6 +468,7 @@ GridFrame::GridFrame()
 
     grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
     grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
+    grid->SetCellBackgroundColour(3, 0, wxColour(255, 127, 127));
 
     wxGridCellAttr *attr;
     attr = new wxGridCellAttr;
index ca15ddc2cc325375152514a6aea135c09d2d873e..3a67f6262a482747be4ff56258a6cc2b479401a6 100644 (file)
@@ -5558,7 +5558,7 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
         // implicitly, causing this out-of order render.
 #if !defined(__WXMAC__)
         wxGridCellEditor *editor = attr->GetEditor(this, row, col);
-        editor->PaintBackground(rect, attr);
+        editor->PaintBackground(dc, rect, *attr);
         editor->DecRef();
 #endif
     }
index 36e067e9a631695e75fe1034dbdf83aa4c09cdd8..939552b1803d0e2d4647b9ed28e67ce4122eb3e8 100644 (file)
@@ -246,21 +246,14 @@ void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent),
         m_control->PushEventHandler(evtHandler);
 }
 
-void wxGridCellEditor::PaintBackground(const wxRect& rectCell,
-                                       wxGridCellAttr *attr)
+void wxGridCellEditor::PaintBackground(wxDC& dc,
+                                       const wxRect& rectCell,
+                                       const wxGridCellAttr& attr)
 {
     // erase the background because we might not fill the cell
-    wxClientDC dc(m_control->GetParent());
-    wxGridWindow* gridWindow = wxDynamicCast(m_control->GetParent(), wxGridWindow);
-    if (gridWindow)
-        gridWindow->GetOwner()->PrepareDC(dc);
-
     dc.SetPen(*wxTRANSPARENT_PEN);
-    dc.SetBrush(wxBrush(attr->GetBackgroundColour()));
+    dc.SetBrush(wxBrush(attr.GetBackgroundColour()));
     dc.DrawRectangle(rectCell);
-
-    // redraw the control we just painted over
-    m_control->Refresh();
 }
 
 void wxGridCellEditor::Destroy()
@@ -423,8 +416,9 @@ void wxGridCellTextEditor::DoCreate(wxWindow* parent,
     wxGridCellEditor::Create(parent, id, evtHandler);
 }
 
-void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
-                                           wxGridCellAttr * WXUNUSED(attr))
+void wxGridCellTextEditor::PaintBackground(wxDC& WXUNUSED(dc),
+                                           const wxRect& WXUNUSED(rectCell),
+                                           const wxGridCellAttr& WXUNUSED(attr))
 {
     // as we fill the entire client area,
     // don't do anything here to minimize flicker
@@ -1451,8 +1445,9 @@ void wxGridCellChoiceEditor::SetSize(const wxRect& rect)
     wxGridCellEditor::SetSize(rectTallEnough);
 }
 
-void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
-                                             wxGridCellAttr * attr)
+void wxGridCellChoiceEditor::PaintBackground(wxDC& dc,
+                                             const wxRect& rectCell,
+                                             const wxGridCellAttr& attr)
 {
     // as we fill the entire client area, don't do anything here to minimize
     // flicker
@@ -1460,7 +1455,7 @@ void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
     // TODO: It doesn't actually fill the client area since the height of a
     // combo always defaults to the standard.  Until someone has time to
     // figure out the right rectangle to paint, just do it the normal way.
-    wxGridCellEditor::PaintBackground(rectCell, attr);
+    wxGridCellEditor::PaintBackground(dc, rectCell, attr);
 }
 
 void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)