wxGridCellEditor::PaintBackground() added

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2000-02-17 19:13:48 +00:00
parent f538864d03
commit 189d0213da
2 changed files with 51 additions and 33 deletions

View File

@ -9,7 +9,6 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/defs.h"
#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
@ -146,6 +145,10 @@ public:
// colours/fonts for it
virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
// 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);
// Fetch the value from the table and prepare the edit control
// to begin editing. Set the focus to the edit control.
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
@ -193,6 +196,8 @@ public:
wxWindowID id,
wxEvtHandler* evtHandler);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
@ -229,8 +234,6 @@ protected:
private:
bool m_startValue;
wxRect m_rectCell; // the total size of the cell
};
// ----------------------------------------------------------------------------

View File

@ -295,10 +295,23 @@ void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent),
wxWindowID WXUNUSED(id),
wxEvtHandler* evtHandler)
{
if (evtHandler)
if ( evtHandler )
m_control->PushEventHandler(evtHandler);
}
void wxGridCellEditor::PaintBackground(const wxRect& rectCell,
wxGridCellAttr *attr)
{
// erase the background because we might not fill the cell
wxClientDC dc(m_control->GetParent());
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
dc.DrawRectangle(rectCell);
// redraw the control we just painted over
m_control->Refresh();
}
void wxGridCellEditor::Destroy()
{
if (m_control)
@ -408,6 +421,12 @@ void wxGridCellTextEditor::Create(wxWindow* parent,
wxGridCellEditor::Create(parent, id, evtHandler);
}
void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
wxGridCellAttr * WXUNUSED(attr))
{
// as we fill the entire client area, don't do anything here to minimize
// flicker
}
void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid)
{
@ -508,7 +527,6 @@ void wxGridCellBoolEditor::Create(wxWindow* parent,
void wxGridCellBoolEditor::SetSize(const wxRect& r)
{
m_rectCell = r;
// position it in the centre of the rectangle (TODO: support alignment?)
wxCoord w, h;
m_control->GetSize(&w, &h);
@ -516,7 +534,7 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r)
// the checkbox without label still has some space to the right in wxGTK,
// so shift it to the right
#ifdef __WXGTK__
w += 8;
w -= 8;
#endif // GTK
m_control->Move(r.x + r.width/2 - w/2, r.y + r.height/2 - h/2);
@ -525,24 +543,12 @@ void wxGridCellBoolEditor::SetSize(const wxRect& r)
void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
{
wxGridCellEditor::Show(show, attr);
if ( !show )
return;
// get the bg colour to use
wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
// erase the background because we don't fill the cell
if ( m_rectCell.width > 0 )
if ( show )
{
wxClientDC dc(m_control->GetParent());
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(colBg, wxSOLID));
dc.DrawRectangle(m_rectCell);
m_rectCell.width = 0;
// VZ: normally base class already does it, but it doesn't work (FIXME)
wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
CBox()->SetBackgroundColour(colBg);
}
CBox()->SetBackgroundColour(colBg);
}
void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
@ -4047,23 +4053,32 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
DrawCellBorder( dc, coords );
#endif
// don't draw the cell over the active edit control!
if ( (coords == m_currentCellCoords) && IsCellEditControlEnabled() )
return;
wxGridCellAttr* attr = GetCellAttr(row, col);
bool isCurrent = coords == m_currentCellCoords;
// but all the rest is drawn by the cell renderer and hence may be
// customized
wxRect rect;
rect.x = m_colRights[col] - m_colWidths[col];
rect.y = m_rowBottoms[row] - m_rowHeights[row];
rect.width = m_colWidths[col]-1;
rect.height = m_rowHeights[row]-1;
rect.width = m_colWidths[col] - 1;
rect.height = m_rowHeights[row] - 1;
wxGridCellAttr* attr = GetCellAttr(row, col);
attr->GetRenderer()->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
// if the editor is shown, we should use it and not the renderer
if ( isCurrent && IsCellEditControlEnabled() )
{
attr->GetEditor()->PaintBackground(rect, attr);
}
else
{
// but all the rest is drawn by the cell renderer and hence may be
// customized
attr->GetRenderer()->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
if (m_currentCellCoords == coords)
DrawCellHighlight(dc, attr);
if ( isCurrent )
{
DrawCellHighlight(dc, attr);
}
}
attr->DecRef();
}