wxArrayString m_choices;
bool m_allowOthers;
};
+
// ----------------------------------------------------------------------------
// wxGridCellAttr: this class can be used to alter the cells appearance in
// the grid by changing their colour/font/... from default. An object of this
SetAlignment(hAlign, vAlign);
}
- // default copy ctor ok
+ // creates a new copy of this object: warning, this is destructive copy
+ // (this is why it's non const), the renderer and editor are "given to"
+ // the new object
+ wxGridCellAttr *Clone();
// this class is ref counted: it is created with ref count of 1, so
// calling DecRef() once will delete it. Calling IncRef() allows to lock
bool m_isReadOnly;
+ // use Clone() instead
+ DECLARE_NO_COPY_CLASS(wxGridCellAttr);
+
// suppress the stupid gcc warning about the class having private dtor and
// no friends
friend class wxGridCellAttrDummyFriend;
dc.DrawEllipse(rect);
}
-
// ----------------------------------------------------------------------------
-// BigGridFrame and BigGridTable: Sample of a non-standard table
+// MyGridCellAttrProvider
// ----------------------------------------------------------------------------
+MyGridCellAttrProvider::MyGridCellAttrProvider()
+{
+ m_attrForOddRows = new wxGridCellAttr;
+ m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
+}
+
+MyGridCellAttrProvider::~MyGridCellAttrProvider()
+{
+ m_attrForOddRows->DecRef();
+}
+
+wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col) const
+{
+ wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col);
+
+ if ( row % 2 )
+ {
+ if ( !attr )
+ {
+ attr = m_attrForOddRows;
+ attr->IncRef();
+ }
+ else
+ {
+ if ( !attr->HasBackgroundColour() )
+ {
+ wxGridCellAttr *attrNew = attr->Clone();
+ attr->DecRef();
+ attr = attrNew;
+ attr->SetBackgroundColour(*wxLIGHT_GREY);
+ }
+ }
+ }
+
+ return attr;
+}
+
+// ============================================================================
+// BigGridFrame and BigGridTable: Sample of a non-standard table
+// ============================================================================
+
BigGridFrame::BigGridFrame(long sizeGrid)
: wxFrame(NULL, -1, "Plugin Virtual Table",
wxDefaultPosition, wxSize(500, 450))
{
m_grid = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize);
m_table = new BigGridTable(sizeGrid);
+
+ // VZ: I don't understand why this slows down the display that much,
+ // must profile it...
+ //m_table->SetAttrProvider(new MyGridCellAttrProvider);
+
m_grid->SetTable(m_table, TRUE);
#if defined __WXMOTIF__
#endif
}
-// ----------------------------------------------------------------------------
+// ============================================================================
// BugsGridFrame: a "realistic" table
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// bugs table data
// ----------------------------------------------------------------------------
enum Columns
_T("Opened?"),
};
+// ----------------------------------------------------------------------------
+// BugsGridTable
+// ----------------------------------------------------------------------------
+
wxString BugsGridTable::GetTypeName(int WXUNUSED(row), int col)
{
switch ( col )
{
}
+// ----------------------------------------------------------------------------
+// BugsGridFrame
+// ----------------------------------------------------------------------------
+
BugsGridFrame::BugsGridFrame()
: wxFrame(NULL, -1, "Bugs table",
wxDefaultPosition, wxSize(500, 300))
{
wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition);
wxGridTableBase *table = new BugsGridTable();
+ table->SetAttrProvider(new MyGridCellAttrProvider);
grid->SetTable(table, TRUE);
wxGridCellAttr *attrRO = new wxGridCellAttr,
BigGridTable* m_table;
};
+// ----------------------------------------------------------------------------
+// an example of custom attr provider: this one makes all odd rows appear grey
+// ----------------------------------------------------------------------------
+
+class MyGridCellAttrProvider : public wxGridCellAttrProvider
+{
+public:
+ MyGridCellAttrProvider();
+ virtual ~MyGridCellAttrProvider();
+
+ virtual wxGridCellAttr *GetAttr(int row, int col) const;
+
+private:
+ wxGridCellAttr *m_attrForOddRows;
+};
+
// ----------------------------------------------------------------------------
// another, more realistic, grid example: shows typed columns and more
// ----------------------------------------------------------------------------
// wxGridCellAttr
// ----------------------------------------------------------------------------
+wxGridCellAttr *wxGridCellAttr::Clone()
+{
+ wxGridCellAttr *attr = new wxGridCellAttr;
+ if ( HasTextColour() )
+ attr->SetTextColour(GetTextColour());
+ if ( HasBackgroundColour() )
+ attr->SetBackgroundColour(GetBackgroundColour());
+ if ( HasFont() )
+ attr->SetFont(GetFont());
+ if ( HasAlignment() )
+ attr->SetAlignment(m_hAlign, m_vAlign);
+
+ if ( m_renderer )
+ {
+ attr->SetRenderer(m_renderer);
+ m_renderer = NULL;
+ }
+ if ( m_editor )
+ {
+ attr->SetEditor(m_editor);
+ m_editor = NULL;
+ }
+
+ if ( IsReadOnly() )
+ attr->SetReadOnly();
+
+ attr->SetDefAttr(m_defGridAttr);
+
+ return attr;
+}
+
const wxColour& wxGridCellAttr::GetTextColour() const
{
if (HasTextColour())