split wxGrid implementation in grideditors.cpp (for wxGridCellEditor-derived classes), gridctrl.cpp (for wxGridCellRenderer-derived classes)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58024 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-01-11 15:49:37 +00:00
parent d0bbcd06d2
commit 29efc6e4a4
21 changed files with 3718 additions and 3429 deletions

View File

@@ -90,6 +90,7 @@ class wxGridRowOperations;
class wxGridColumnOperations;
class wxGridDirectionOperations;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
@@ -168,129 +169,6 @@ public:
virtual wxGridCellRenderer *Clone() const = 0;
};
// the default renderer for the cells containing string data
class WXDLLIMPEXP_ADV 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(const wxGrid& grid,
const wxGridCellAttr& attr,
wxDC& dc,
bool isSelected);
// calc the string extent for given string/font
wxSize DoGetBestSize(const wxGridCellAttr& attr,
wxDC& dc,
const wxString& text);
};
// the default renderer for the cells containing numeric (long) data
class WXDLLIMPEXP_ADV 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(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
@@ -406,247 +284,6 @@ protected:
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(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(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_value;
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(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(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 our value
wxString GetString() const
{ return wxString::Format(_T("%ld"), m_value); }
private:
int m_min,
m_max;
long m_value;
DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)
};
// the editor for floating point numbers (double) data
class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
{
public:
wxGridCellFloatEditor(int width = -1, int precision = -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(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellFloatEditor(m_width, m_precision); }
// parameters string format is "width,precision"
virtual void SetParameters(const wxString& params);
protected:
// string representation of our value
wxString GetString() const;
private:
int m_width,
m_precision;
double m_value;
DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor)
};
#endif // wxUSE_TEXTCTRL
#if wxUSE_CHECKBOX
// the editor for boolean data
class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
{
public:
wxGridCellBoolEditor() { }
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler);
virtual void SetSize(const wxRect& rect);
virtual void Show(bool show, wxGridCellAttr *attr = NULL);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingClick();
virtual void StartingKey(wxKeyEvent& event);
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellBoolEditor; }
// added GetValue so we can get the value which is in the control, see
// also UseStringValues()
virtual wxString GetValue() const;
// set the string values returned by GetValue() for the true and false
// states, respectively
static void UseStringValues(const wxString& valueTrue = _T("1"),
const wxString& valueFalse = wxEmptyString);
// return true if the given string is equal to the string representation of
// true value which we currently use
static bool IsTrueValue(const wxString& value);
protected:
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
private:
bool m_value;
static wxString ms_stringValues[2];
DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor)
};
#endif // wxUSE_CHECKBOX
#if wxUSE_COMBOBOX
// the editor for string data allowing to choose from the list of strings
class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
{
public:
// if !allowOthers, user can't type a string not in choices array
wxGridCellChoiceEditor(size_t count = 0,
const wxString choices[] = NULL,
bool allowOthers = false);
wxGridCellChoiceEditor(const wxArrayString& choices,
bool allowOthers = false);
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
// parameters string format is "item1[,item2[...,itemN]]"
virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const;
// added GetValue so we can get the value which is in the control
virtual wxString GetValue() const;
protected:
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
wxString m_value;
wxArrayString m_choices;
bool m_allowOthers;
DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor)
};
#endif // wxUSE_COMBOBOX
// ----------------------------------------------------------------------------
// wxGridCellAttr: this class can be used to alter the cells appearance in