+
+ virtual wxSize GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ int row, int col);
+
+ virtual wxGridCellRenderer *Clone() const
+ { return new wxGridCellNumberRenderer; }
+
+protected:
+ wxString GetString(const wxGrid& grid, int row, int col);
+};
+
+class WXDLLIMPEXP_ADV 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(const wxGrid& grid, int row, int col);
+
+private:
+ // formatting parameters
+ int m_width,
+ m_precision;
+
+ wxString m_format;
+};
+
+// renderer for boolean fields
+class WXDLLIMPEXP_ADV 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 WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker
+{
+public:
+ wxGridCellEditor();
+
+ bool IsCreated() { return m_control != NULL; }
+ wxControl* GetControl() { return m_control; }
+ void SetControl(wxControl* control) { m_control = control; }
+
+ wxGridCellAttr* GetCellAttr() { return m_attr; }
+ void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; }
+
+ // 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;
+
+ // added GetValue so we can get the value which is in the control
+ virtual wxString GetValue() const = 0;
+
+protected:
+ // the dtor is private because only DecRef() can delete us
+ virtual ~wxGridCellEditor();
+
+ // the control we show on screen
+ wxControl* m_control;
+
+ // a temporary pointer to the attribute being edited
+ wxGridCellAttr* m_attr;
+
+ // 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;
+
+ DECLARE_NO_COPY_CLASS(wxGridCellEditor)
+};
+
+#if wxUSE_TEXTCTRL
+
+// the editor for string/text data
+class WXDLLIMPEXP_ADV 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; }
+
+ // added GetValue so we can get the value which is in the control
+ virtual wxString GetValue() const;
+
+protected:
+ wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
+
+ // parts of our virtual functions reused by the derived classes
+ void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
+ long style = 0);
+ void DoBeginEdit(const wxString& startValue);
+ void DoReset(const wxString& startValue);
+
+private:
+ size_t m_maxChars; // max number of chars allowed
+ wxString m_startValue;
+
+ DECLARE_NO_COPY_CLASS(wxGridCellTextEditor)
+};
+
+// the editor for numeric (long) data
+class WXDLLIMPEXP_ADV 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);
+
+ virtual void Reset();
+ virtual void StartingKey(wxKeyEvent& event);
+
+ // parameters string format is "min,max"
+ virtual void SetParameters(const wxString& params);
+
+ virtual wxGridCellEditor *Clone() const
+ { return new wxGridCellNumberEditor(m_min, m_max); }
+
+ // added GetValue so we can get the value which is in the control
+ virtual wxString GetValue() const;
+
+protected:
+#if wxUSE_SPINCTRL
+ wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
+#endif
+
+ // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
+ bool HasRange() const
+ {
+#if wxUSE_SPINCTRL
+ return m_min != m_max;
+#else
+ return false;
+#endif
+ }
+
+ // string representation of m_valueOld
+ wxString GetString() const
+ { return wxString::Format(_T("%ld"), m_valueOld); }
+
+private:
+ int m_min,
+ m_max;
+
+ long m_valueOld;
+
+ DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)