+class WXDLLEXPORT wxGridCellAttr;
+class WXDLLEXPORT wxGridCellAttrProviderData;
+class WXDLLEXPORT wxGridColLabelWindow;
+class WXDLLEXPORT wxGridCornerLabelWindow;
+class WXDLLEXPORT wxGridRowLabelWindow;
+class WXDLLEXPORT wxGridTableBase;
+class WXDLLEXPORT wxGridWindow;
+class WXDLLEXPORT wxGridTypeRegistry;
+class WXDLLEXPORT wxGridSelection;
+
+class WXDLLEXPORT wxCheckBox;
+class WXDLLEXPORT wxComboBox;
+class WXDLLEXPORT wxTextCtrl;
+class WXDLLEXPORT wxSpinCtrl;
+
+// ----------------------------------------------------------------------------
+// macros
+// ----------------------------------------------------------------------------
+
+#define wxSafeIncRef(p) if ( p ) (p)->IncRef()
+#define wxSafeDecRef(p) if ( p ) (p)->DecRef()
+
+// ----------------------------------------------------------------------------
+// wxGridCellWorker: common base class for wxGridCellRenderer and
+// wxGridCellEditor
+//
+// NB: this is more an implementation convenience than a design issue, so this
+// class is not documented and is not public at all
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxGridCellWorker : public wxClientDataContainer
+{
+public:
+ wxGridCellWorker() { m_nRef = 1; }
+
+ // 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
+ // it until the matching DecRef() is called
+ void IncRef() { m_nRef++; }
+ void DecRef() { if ( !--m_nRef ) delete this; }
+
+ // interpret renderer parameters: arbitrary string whose interpretatin is
+ // left to the derived classes
+ virtual void SetParameters(const wxString& params);
+
+protected:
+ // virtual dtor for any base class - private because only DecRef() can
+ // delete us
+ virtual ~wxGridCellWorker();
+
+private:
+ size_t m_nRef;
+
+ // suppress the stupid gcc warning about the class having private dtor and
+ // no friends
+ friend class wxGridCellWorkerDummyFriend;
+};
+
+// ----------------------------------------------------------------------------
+// wxGridCellRenderer: this class is responsible for actually drawing the cell
+// in the grid. You may pass it to the wxGridCellAttr (below) to change the
+// format of one given cell or to wxGrid::SetDefaultRenderer() to change the
+// view of all cells. This is an ABC, you will normally use one of the
+// predefined derived classes or derive your own class from it.
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxGridCellRenderer : public wxGridCellWorker
+{
+public:
+ // draw the given cell on the provided DC inside the given rectangle
+ // using the style specified by the attribute and the default or selected
+ // state corresponding to the isSelected value.
+ //
+ // this pure virtual function has a default implementation which will
+ // prepare the DC using the given attribute: it will draw the rectangle
+ // with the bg colour from attr and set the text colour and font
+ virtual void Draw(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxRect& rect,
+ int row, int col,
+ bool isSelected) = 0;
+
+ // get the preferred size of the cell for its contents
+ virtual wxSize GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ int row, int col) = 0;
+
+ // create a new object which is the copy of this one
+ virtual wxGridCellRenderer *Clone() const = 0;
+};
+
+// the default renderer for the cells containing string data
+class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer
+{
+public:
+ // draw the string
+ virtual void Draw(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxRect& rect,
+ int row, int col,
+ bool isSelected);
+
+ // return the string extent
+ virtual wxSize GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ int row, int col);
+
+ virtual wxGridCellRenderer *Clone() const
+ { return new wxGridCellStringRenderer; }
+
+protected:
+ // set the text colours before drawing
+ void SetTextColoursAndFont(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ bool isSelected);
+
+ // calc the string extent for given string/font
+ wxSize DoGetBestSize(wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxString& text);
+};
+
+// the default renderer for the cells containing numeric (long) data
+class WXDLLEXPORT wxGridCellNumberRenderer : public wxGridCellStringRenderer
+{
+public:
+ // draw the string right aligned
+ virtual void Draw(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxRect& rect,
+ int row, int col,
+ bool isSelected);
+
+ virtual wxSize GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ int row, int col);
+
+ virtual wxGridCellRenderer *Clone() const
+ { return new wxGridCellNumberRenderer; }
+
+protected:
+ wxString GetString(wxGrid& grid, int row, int col);
+};
+
+class WXDLLEXPORT wxGridCellFloatRenderer : public wxGridCellStringRenderer
+{
+public:
+ wxGridCellFloatRenderer(int width = -1, int precision = -1);
+
+ // get/change formatting parameters
+ int GetWidth() const { return m_width; }
+ void SetWidth(int width) { m_width = width; m_format.clear(); }
+ int GetPrecision() const { return m_precision; }
+ void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
+
+ // draw the string right aligned with given width/precision
+ virtual void Draw(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxRect& rect,
+ int row, int col,
+ bool isSelected);
+
+ virtual wxSize GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ int row, int col);
+
+ // parameters string format is "width[,precision]"
+ virtual void SetParameters(const wxString& params);
+
+ virtual wxGridCellRenderer *Clone() const;
+
+protected:
+ wxString GetString(wxGrid& grid, int row, int col);
+
+private:
+ // formatting parameters
+ int m_width,
+ m_precision;
+
+ wxString m_format;
+};
+
+// renderer for boolean fields
+class WXDLLEXPORT wxGridCellBoolRenderer : public wxGridCellRenderer
+{
+public:
+ // draw a check mark or nothing
+ virtual void Draw(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxRect& rect,
+ int row, int col,
+ bool isSelected);
+
+ // return the checkmark size
+ virtual wxSize GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ int row, int col);
+
+ virtual wxGridCellRenderer *Clone() const
+ { return new wxGridCellBoolRenderer; }
+
+private:
+ static wxSize ms_sizeCheckMark;
+};
+
+// ----------------------------------------------------------------------------
+// wxGridCellEditor: This class is responsible for providing and manipulating
+// the in-place edit controls for the grid. Instances of wxGridCellEditor
+// (actually, instances of derived classes since it is an ABC) can be
+// associated with the cell attributes for individual cells, rows, columns, or
+// even for the entire grid.
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxGridCellEditor : public wxGridCellWorker
+{
+public:
+ wxGridCellEditor();
+
+ bool IsCreated() { return m_control != NULL; }
+ wxControl* GetControl() { return m_control; }
+ void SetControl(wxControl* control) { m_control = control; }
+
+ // Creates the actual edit control
+ virtual void Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler) = 0;
+
+ // Size and position the edit control
+ virtual void SetSize(const wxRect& rect);
+
+ // Show or hide the edit control, use the specified attributes to set
+ // 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;
+
+ // Complete the editing of the current cell. Returns true if the value has
+ // changed. If necessary, the control may be destroyed.
+ virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
+
+ // Reset the value in the control back to its starting value
+ virtual void Reset() = 0;
+
+ // return TRUE to allow the given key to start editing: the base class
+ // version only checks that the event has no modifiers. The derived
+ // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
+ // their IsAcceptedKey() implementation, although, of course, it is not a
+ // mandatory requirment.
+ //
+ // NB: if the key is F2 (special), editing will always start and this
+ // method will not be called at all (but StartingKey() will)
+ virtual bool IsAcceptedKey(wxKeyEvent& event);
+
+ // If the editor is enabled by pressing keys on the grid, this will be
+ // called to let the editor do something about that first key if desired
+ virtual void StartingKey(wxKeyEvent& event);
+
+ // if the editor is enabled by clicking on the cell, this method will be
+ // called
+ virtual void StartingClick();
+
+ // Some types of controls on some platforms may need some help
+ // with the Return key.
+ virtual void HandleReturn(wxKeyEvent& event);
+
+ // Final cleanup
+ virtual void Destroy();
+
+ // create a new object which is the copy of this one
+ virtual wxGridCellEditor *Clone() const = 0;
+
+protected:
+ // the dtor is private because only DecRef() can delete us
+ virtual ~wxGridCellEditor();
+
+ // the control we show on screen
+ wxControl* m_control;
+
+ // if we change the colours/font of the control from the default ones, we
+ // must restore the default later and we save them here between calls to
+ // Show(TRUE) and Show(FALSE)
+ wxColour m_colFgOld,
+ m_colBgOld;
+ wxFont m_fontOld;
+
+ // suppress the stupid gcc warning about the class having private dtor and
+ // no friends
+ friend class wxGridCellEditorDummyFriend;
+};
+
+#if wxUSE_TEXTCTRL
+
+// the editor for string/text data
+class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor
+{
+public:
+ wxGridCellTextEditor();
+
+ virtual void Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler);
+ virtual void SetSize(const wxRect& rect);
+
+ virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+
+ virtual bool IsAcceptedKey(wxKeyEvent& event);
+ virtual void BeginEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(int row, int col, wxGrid* grid);
+
+ virtual void Reset();
+ virtual void StartingKey(wxKeyEvent& event);
+ virtual void HandleReturn(wxKeyEvent& event);
+
+ // parameters string format is "max_width"
+ virtual void SetParameters(const wxString& params);
+
+ virtual wxGridCellEditor *Clone() const
+ { return new wxGridCellTextEditor; }
+
+protected:
+ wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
+
+ // parts of our virtual functions reused by the derived classes
+ void DoBeginEdit(const wxString& startValue);
+ void DoReset(const wxString& startValue);
+
+private:
+ size_t m_maxChars; // max number of chars allowed
+ wxString m_startValue;
+};
+
+// the editor for numeric (long) data
+class WXDLLEXPORT wxGridCellNumberEditor : public wxGridCellTextEditor
+{
+public:
+ // allows to specify the range - if min == max == -1, no range checking is
+ // done
+ wxGridCellNumberEditor(int min = -1, int max = -1);
+
+ virtual void Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler);
+
+ virtual bool IsAcceptedKey(wxKeyEvent& event);
+ virtual void BeginEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(int row, int col, wxGrid* grid);