added support for readonly cells and 3d border drawing
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6094 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -206,6 +206,8 @@ public:
|
|||||||
SetAlignment(0, 0);
|
SetAlignment(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VZ: considering the number of members wxGridCellAttr has now, this ctor
|
||||||
|
// seems to be pretty useless... may be we should just remove it?
|
||||||
wxGridCellAttr(const wxColour& colText,
|
wxGridCellAttr(const wxColour& colText,
|
||||||
const wxColour& colBack,
|
const wxColour& colBack,
|
||||||
const wxFont& font,
|
const wxFont& font,
|
||||||
@@ -236,6 +238,7 @@ public:
|
|||||||
m_hAlign = hAlign;
|
m_hAlign = hAlign;
|
||||||
m_vAlign = vAlign;
|
m_vAlign = vAlign;
|
||||||
}
|
}
|
||||||
|
void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; }
|
||||||
|
|
||||||
// takes ownership of the pointer
|
// takes ownership of the pointer
|
||||||
void SetRenderer(wxGridCellRenderer *renderer)
|
void SetRenderer(wxGridCellRenderer *renderer)
|
||||||
@@ -258,12 +261,18 @@ public:
|
|||||||
wxGridCellRenderer *GetRenderer() const;
|
wxGridCellRenderer *GetRenderer() const;
|
||||||
wxGridCellEditor *GetEditor() const;
|
wxGridCellEditor *GetEditor() const;
|
||||||
|
|
||||||
|
bool IsReadOnly() const { return m_isReadOnly; }
|
||||||
|
|
||||||
void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
|
void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// the common part of all ctors
|
// the common part of all ctors
|
||||||
void Init() {
|
void Init()
|
||||||
|
{
|
||||||
m_nRef = 1;
|
m_nRef = 1;
|
||||||
|
|
||||||
|
m_isReadOnly = FALSE;
|
||||||
|
|
||||||
m_renderer = NULL;
|
m_renderer = NULL;
|
||||||
m_editor = NULL;
|
m_editor = NULL;
|
||||||
}
|
}
|
||||||
@@ -284,6 +293,8 @@ private:
|
|||||||
wxGridCellEditor* m_editor;
|
wxGridCellEditor* m_editor;
|
||||||
wxGridCellAttr* m_defGridAttr;
|
wxGridCellAttr* m_defGridAttr;
|
||||||
|
|
||||||
|
bool m_isReadOnly;
|
||||||
|
|
||||||
// suppress the stupid gcc warning about the class having private dtor and
|
// suppress the stupid gcc warning about the class having private dtor and
|
||||||
// no friends
|
// no friends
|
||||||
friend class wxGridCellAttrDummyFriend;
|
friend class wxGridCellAttrDummyFriend;
|
||||||
@@ -624,7 +635,7 @@ public:
|
|||||||
void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
|
void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
|
||||||
void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
|
void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
|
||||||
void DrawCell( wxDC& dc, const wxGridCellCoords& );
|
void DrawCell( wxDC& dc, const wxGridCellCoords& );
|
||||||
void DrawCellHighlight( wxDC& dc );
|
void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
|
||||||
|
|
||||||
void DrawRowLabels( wxDC& dc );
|
void DrawRowLabels( wxDC& dc );
|
||||||
void DrawRowLabel( wxDC& dc, int row );
|
void DrawRowLabel( wxDC& dc, int row );
|
||||||
@@ -666,8 +677,7 @@ public:
|
|||||||
|
|
||||||
void EnableCellEditControl( bool enable );
|
void EnableCellEditControl( bool enable );
|
||||||
|
|
||||||
bool IsCellEditControlEnabled()
|
bool IsCellEditControlEnabled();
|
||||||
{ return m_cellEditCtrlEnabled; }
|
|
||||||
|
|
||||||
void ShowCellEditControl();
|
void ShowCellEditControl();
|
||||||
void HideCellEditControl();
|
void HideCellEditControl();
|
||||||
@@ -791,7 +801,7 @@ public:
|
|||||||
wxGridCellRenderer *GetDefaultRenderer() const;
|
wxGridCellRenderer *GetDefaultRenderer() const;
|
||||||
wxGridCellRenderer* GetCellRenderer(int row, int col);
|
wxGridCellRenderer* GetCellRenderer(int row, int col);
|
||||||
|
|
||||||
// takes ownership of the pointer
|
// takes ownership of the pointer
|
||||||
void SetDefaultEditor(wxGridCellEditor *editor);
|
void SetDefaultEditor(wxGridCellEditor *editor);
|
||||||
void SetCellEditor(int row, int col, wxGridCellEditor *editor);
|
void SetCellEditor(int row, int col, wxGridCellEditor *editor);
|
||||||
wxGridCellEditor *GetDefaultEditor() const;
|
wxGridCellEditor *GetDefaultEditor() const;
|
||||||
@@ -819,7 +829,11 @@ public:
|
|||||||
void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
|
void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
|
||||||
{ SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
|
{ SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
|
||||||
|
|
||||||
|
// returns TRUE if the cell can't be edited
|
||||||
|
bool IsReadOnly(int row, int col) const;
|
||||||
|
|
||||||
|
// make the cell editable/readonly
|
||||||
|
void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
|
||||||
|
|
||||||
// ------ selections of blocks of cells
|
// ------ selections of blocks of cells
|
||||||
//
|
//
|
||||||
|
@@ -95,7 +95,6 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
|
|||||||
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
|
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
|
||||||
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
|
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
|
||||||
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
|
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
|
||||||
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
@@ -187,6 +186,8 @@ GridFrame::GridFrame()
|
|||||||
|
|
||||||
grid->SetCellValue( 0, 1, "Blah" );
|
grid->SetCellValue( 0, 1, "Blah" );
|
||||||
grid->SetCellValue( 0, 2, "Blah" );
|
grid->SetCellValue( 0, 2, "Blah" );
|
||||||
|
grid->SetCellValue( 0, 3, "Read only" );
|
||||||
|
grid->SetReadOnly( 0, 3 );
|
||||||
|
|
||||||
grid->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
|
grid->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
|
||||||
|
|
||||||
@@ -212,6 +213,9 @@ GridFrame::GridFrame()
|
|||||||
attr->SetBackgroundColour(*wxBLUE);
|
attr->SetBackgroundColour(*wxBLUE);
|
||||||
grid->SetRowAttr(5, attr);
|
grid->SetRowAttr(5, attr);
|
||||||
|
|
||||||
|
// VZ: cell borders don't look nice otherwise :-) (for now...)
|
||||||
|
grid->SetDefaultCellBackgroundColour(wxColour(200, 200, 180));
|
||||||
|
|
||||||
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
||||||
topSizer->Add( grid,
|
topSizer->Add( grid,
|
||||||
1,
|
1,
|
||||||
|
@@ -546,6 +546,8 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid,
|
|||||||
// now we only have to draw the text
|
// now we only have to draw the text
|
||||||
dc.SetBackgroundMode( wxTRANSPARENT );
|
dc.SetBackgroundMode( wxTRANSPARENT );
|
||||||
|
|
||||||
|
// TODO some special colours for attr.IsReadOnly() case?
|
||||||
|
|
||||||
if ( isSelected )
|
if ( isSelected )
|
||||||
{
|
{
|
||||||
dc.SetTextBackground( grid.GetSelectionBackground() );
|
dc.SetTextBackground( grid.GetSelectionBackground() );
|
||||||
@@ -3780,7 +3782,10 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
|
|||||||
{
|
{
|
||||||
wxClientDC dc(m_gridWin);
|
wxClientDC dc(m_gridWin);
|
||||||
PrepareDC(dc);
|
PrepareDC(dc);
|
||||||
DrawCellHighlight(dc);
|
|
||||||
|
wxGridCellAttr* attr = GetCellAttr(coords);
|
||||||
|
DrawCellHighlight(dc, attr);
|
||||||
|
attr->DecRef();
|
||||||
|
|
||||||
if ( IsSelection() )
|
if ( IsSelection() )
|
||||||
{
|
{
|
||||||
@@ -3874,14 +3879,14 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
|
|||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
attr->GetRenderer()->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
|
attr->GetRenderer()->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
|
||||||
attr->DecRef();
|
|
||||||
|
|
||||||
if (m_currentCellCoords == coords)
|
if (m_currentCellCoords == coords)
|
||||||
DrawCellHighlight(dc);
|
DrawCellHighlight(dc, attr);
|
||||||
|
|
||||||
|
attr->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr )
|
||||||
void wxGrid::DrawCellHighlight( wxDC& dc )
|
|
||||||
{
|
{
|
||||||
int row = m_currentCellCoords.GetRow();
|
int row = m_currentCellCoords.GetRow();
|
||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
@@ -3895,10 +3900,44 @@ void wxGrid::DrawCellHighlight( wxDC& dc )
|
|||||||
rect.width = m_colWidths[col] - 1;
|
rect.width = m_colWidths[col] - 1;
|
||||||
rect.height = m_rowHeights[row] - 1;
|
rect.height = m_rowHeights[row] - 1;
|
||||||
|
|
||||||
dc.SetPen(wxPen(m_gridLineColour, 3, wxSOLID));
|
if ( attr->IsReadOnly() )
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
{
|
||||||
|
// 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_gridLineColour, 2, wxSOLID));
|
||||||
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
|
|
||||||
dc.DrawRectangle(rect);
|
dc.DrawRectangle(rect);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// VZ: my experiments with 3d borders...
|
||||||
|
#if 0
|
||||||
|
dc.SetPen(wxPen(m_gridLineColour, 3, wxSOLID));
|
||||||
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
|
|
||||||
|
dc.DrawRectangle(rect);
|
||||||
|
#else //1
|
||||||
|
// FIXME we should properly set colours for arbitrary bg
|
||||||
|
wxCoord x1 = rect.x,
|
||||||
|
y1 = rect.y,
|
||||||
|
x2 = rect.x + rect.width,
|
||||||
|
y2 = rect.y + rect.height;
|
||||||
|
|
||||||
|
dc.SetPen(*wxWHITE_PEN);
|
||||||
|
dc.DrawLine(x1, y1, x2 - 1, y1);
|
||||||
|
dc.DrawLine(x1, y1, x1, y2 - 1);
|
||||||
|
|
||||||
|
dc.SetPen(*wxLIGHT_GREY_PEN);
|
||||||
|
dc.DrawLine(x1 + 1, y2 - 1, x2 - 1, y2 - 1);
|
||||||
|
dc.DrawLine(x2 - 1, y1 + 1, x2 - 1, y2 - 1);
|
||||||
|
|
||||||
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
dc.DrawLine(x1, y2, x2, y2);
|
||||||
|
dc.DrawLine(x2, y1, x2, y2);
|
||||||
|
#endif // 0/1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords )
|
void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords )
|
||||||
@@ -4247,6 +4286,24 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxGrid::IsCellEditControlEnabled()
|
||||||
|
{
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
|
if ( m_cellEditCtrlEnabled )
|
||||||
|
{
|
||||||
|
wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
|
||||||
|
enabled = !attr->IsReadOnly();
|
||||||
|
attr->DecRef();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
enabled = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void wxGrid::ShowCellEditControl()
|
void wxGrid::ShowCellEditControl()
|
||||||
{
|
{
|
||||||
if ( IsCellEditControlEnabled() )
|
if ( IsCellEditControlEnabled() )
|
||||||
@@ -5344,6 +5401,14 @@ wxGridCellEditor* wxGrid::GetCellEditor(int row, int col)
|
|||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxGrid::IsReadOnly(int row, int col) const
|
||||||
|
{
|
||||||
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
|
bool isReadOnly = attr->IsReadOnly();
|
||||||
|
attr->DecRef();
|
||||||
|
return isReadOnly;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// attribute support: cache, automatic provider creation, ...
|
// attribute support: cache, automatic provider creation, ...
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -5544,6 +5609,16 @@ void wxGrid::SetCellEditor(int row, int col, wxGridCellEditor* editor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGrid::SetReadOnly(int row, int col, bool isReadOnly)
|
||||||
|
{
|
||||||
|
if ( CanHaveAttributes() )
|
||||||
|
{
|
||||||
|
wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
|
||||||
|
attr->SetReadOnly(isReadOnly);
|
||||||
|
attr->DecRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// row/col size
|
// row/col size
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user