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,
const wxColour& colBack,
const wxFont& font,
m_hAlign = hAlign;
m_vAlign = vAlign;
}
+ void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; }
// takes ownership of the pointer
void SetRenderer(wxGridCellRenderer *renderer)
wxGridCellRenderer *GetRenderer() const;
wxGridCellEditor *GetEditor() const;
+ bool IsReadOnly() const { return m_isReadOnly; }
+
void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
private:
// the common part of all ctors
- void Init() {
+ void Init()
+ {
m_nRef = 1;
+
+ m_isReadOnly = FALSE;
+
m_renderer = NULL;
m_editor = NULL;
}
wxGridCellEditor* m_editor;
wxGridCellAttr* m_defGridAttr;
+ bool m_isReadOnly;
+
// suppress the stupid gcc warning about the class having private dtor and
// no friends
friend class wxGridCellAttrDummyFriend;
void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
void DrawCell( wxDC& dc, const wxGridCellCoords& );
- void DrawCellHighlight( wxDC& dc );
+ void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
void DrawRowLabels( wxDC& dc );
void DrawRowLabel( wxDC& dc, int row );
void EnableCellEditControl( bool enable );
- bool IsCellEditControlEnabled()
- { return m_cellEditCtrlEnabled; }
+ bool IsCellEditControlEnabled();
void ShowCellEditControl();
void HideCellEditControl();
wxGridCellRenderer *GetDefaultRenderer() const;
wxGridCellRenderer* GetCellRenderer(int row, int col);
- // takes ownership of the pointer
+ // takes ownership of the pointer
void SetDefaultEditor(wxGridCellEditor *editor);
void SetCellEditor(int row, int col, wxGridCellEditor *editor);
wxGridCellEditor *GetDefaultEditor() const;
void SetCellValue( const wxGridCellCoords& coords, const wxString& 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
//
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
-
END_EVENT_TABLE()
grid->SetCellValue( 0, 1, "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" );
attr->SetBackgroundColour(*wxBLUE);
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 );
topSizer->Add( grid,
1,
// now we only have to draw the text
dc.SetBackgroundMode( wxTRANSPARENT );
+ // TODO some special colours for attr.IsReadOnly() case?
+
if ( isSelected )
{
dc.SetTextBackground( grid.GetSelectionBackground() );
{
wxClientDC dc(m_gridWin);
PrepareDC(dc);
- DrawCellHighlight(dc);
+
+ wxGridCellAttr* attr = GetCellAttr(coords);
+ DrawCellHighlight(dc, attr);
+ attr->DecRef();
if ( IsSelection() )
{
wxGridCellAttr* attr = GetCellAttr(row, col);
attr->GetRenderer()->Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
- attr->DecRef();
if (m_currentCellCoords == coords)
- DrawCellHighlight(dc);
-}
+ DrawCellHighlight(dc, attr);
+ attr->DecRef();
+}
-void wxGrid::DrawCellHighlight( wxDC& dc )
+void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr )
{
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
rect.width = m_colWidths[col] - 1;
rect.height = m_rowHeights[row] - 1;
- dc.SetPen(wxPen(m_gridLineColour, 3, wxSOLID));
- dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ if ( attr->IsReadOnly() )
+ {
+ // 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 )
}
+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()
{
if ( IsCellEditControlEnabled() )
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, ...
// ----------------------------------------------------------------------------
}
}
+void wxGrid::SetReadOnly(int row, int col, bool isReadOnly)
+{
+ if ( CanHaveAttributes() )
+ {
+ wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
+ attr->SetReadOnly(isReadOnly);
+ attr->DecRef();
+ }
+}
+
// ----------------------------------------------------------------------------
// row/col size
// ----------------------------------------------------------------------------