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:
@@ -9,7 +9,6 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
|
|
||||||
#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
|
#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
|
||||||
@@ -146,6 +145,10 @@ public:
|
|||||||
// colours/fonts for it
|
// colours/fonts for it
|
||||||
virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
|
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
|
// Fetch the value from the table and prepare the edit control
|
||||||
// to begin editing. Set the focus to the edit control.
|
// to begin editing. Set the focus to the edit control.
|
||||||
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
|
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
|
||||||
@@ -193,6 +196,8 @@ public:
|
|||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
wxEvtHandler* evtHandler);
|
wxEvtHandler* evtHandler);
|
||||||
|
|
||||||
|
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
|
||||||
|
|
||||||
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
||||||
virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
|
virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
|
||||||
|
|
||||||
@@ -229,8 +234,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_startValue;
|
bool m_startValue;
|
||||||
|
|
||||||
wxRect m_rectCell; // the total size of the cell
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -295,10 +295,23 @@ void wxGridCellEditor::Create(wxWindow* WXUNUSED(parent),
|
|||||||
wxWindowID WXUNUSED(id),
|
wxWindowID WXUNUSED(id),
|
||||||
wxEvtHandler* evtHandler)
|
wxEvtHandler* evtHandler)
|
||||||
{
|
{
|
||||||
if (evtHandler)
|
if ( evtHandler )
|
||||||
m_control->PushEventHandler(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()
|
void wxGridCellEditor::Destroy()
|
||||||
{
|
{
|
||||||
if (m_control)
|
if (m_control)
|
||||||
@@ -408,6 +421,12 @@ void wxGridCellTextEditor::Create(wxWindow* parent,
|
|||||||
wxGridCellEditor::Create(parent, id, evtHandler);
|
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)
|
void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||||
{
|
{
|
||||||
@@ -508,7 +527,6 @@ void wxGridCellBoolEditor::Create(wxWindow* parent,
|
|||||||
|
|
||||||
void wxGridCellBoolEditor::SetSize(const wxRect& r)
|
void wxGridCellBoolEditor::SetSize(const wxRect& r)
|
||||||
{
|
{
|
||||||
m_rectCell = r;
|
|
||||||
// position it in the centre of the rectangle (TODO: support alignment?)
|
// position it in the centre of the rectangle (TODO: support alignment?)
|
||||||
wxCoord w, h;
|
wxCoord w, h;
|
||||||
m_control->GetSize(&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,
|
// the checkbox without label still has some space to the right in wxGTK,
|
||||||
// so shift it to the right
|
// so shift it to the right
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
w += 8;
|
w -= 8;
|
||||||
#endif // GTK
|
#endif // GTK
|
||||||
|
|
||||||
m_control->Move(r.x + r.width/2 - w/2, r.y + r.height/2 - h/2);
|
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)
|
void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
|
||||||
{
|
{
|
||||||
wxGridCellEditor::Show(show, attr);
|
wxGridCellEditor::Show(show, attr);
|
||||||
if ( !show )
|
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 )
|
|
||||||
{
|
{
|
||||||
wxClientDC dc(m_control->GetParent());
|
// VZ: normally base class already does it, but it doesn't work (FIXME)
|
||||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
|
||||||
dc.SetBrush(wxBrush(colBg, wxSOLID));
|
CBox()->SetBackgroundColour(colBg);
|
||||||
dc.DrawRectangle(m_rectCell);
|
|
||||||
|
|
||||||
m_rectCell.width = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CBox()->SetBackgroundColour(colBg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
|
void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||||
@@ -4047,23 +4053,32 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
|
|||||||
DrawCellBorder( dc, coords );
|
DrawCellBorder( dc, coords );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// don't draw the cell over the active edit control!
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
if ( (coords == m_currentCellCoords) && IsCellEditControlEnabled() )
|
|
||||||
return;
|
bool isCurrent = coords == m_currentCellCoords;
|
||||||
|
|
||||||
// but all the rest is drawn by the cell renderer and hence may be
|
|
||||||
// customized
|
|
||||||
wxRect rect;
|
wxRect rect;
|
||||||
rect.x = m_colRights[col] - m_colWidths[col];
|
rect.x = m_colRights[col] - m_colWidths[col];
|
||||||
rect.y = m_rowBottoms[row] - m_rowHeights[row];
|
rect.y = m_rowBottoms[row] - m_rowHeights[row];
|
||||||
rect.width = m_colWidths[col]-1;
|
rect.width = m_colWidths[col] - 1;
|
||||||
rect.height = m_rowHeights[row]-1;
|
rect.height = m_rowHeights[row] - 1;
|
||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
// if the editor is shown, we should use it and not the renderer
|
||||||
attr->GetRenderer()->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
|
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)
|
if ( isCurrent )
|
||||||
DrawCellHighlight(dc, attr);
|
{
|
||||||
|
DrawCellHighlight(dc, attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
attr->DecRef();
|
attr->DecRef();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user