1 ///////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/gridctrl.h
3 // Purpose: wxGrid controls
4 // Author: Paul Gammans, Roger Gammans
8 // Copyright: (c) The Computer Surgery (paul@compsurg.co.uk)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRIDCTRL_H_
13 #define _WX_GENERIC_GRIDCTRL_H_
19 #define wxGRID_VALUE_CHOICEINT wxT("choiceint")
20 #define wxGRID_VALUE_DATETIME wxT("datetime")
23 // the default renderer for the cells containing string data
24 class WXDLLIMPEXP_ADV wxGridCellStringRenderer
: public wxGridCellRenderer
28 virtual void Draw(wxGrid
& grid
,
35 // return the string extent
36 virtual wxSize
GetBestSize(wxGrid
& grid
,
41 virtual wxGridCellRenderer
*Clone() const
42 { return new wxGridCellStringRenderer
; }
45 // set the text colours before drawing
46 void SetTextColoursAndFont(const wxGrid
& grid
,
47 const wxGridCellAttr
& attr
,
51 // calc the string extent for given string/font
52 wxSize
DoGetBestSize(const wxGridCellAttr
& attr
,
54 const wxString
& text
);
57 // the default renderer for the cells containing numeric (long) data
58 class WXDLLIMPEXP_ADV wxGridCellNumberRenderer
: public wxGridCellStringRenderer
61 // draw the string right aligned
62 virtual void Draw(wxGrid
& grid
,
69 virtual wxSize
GetBestSize(wxGrid
& grid
,
74 virtual wxGridCellRenderer
*Clone() const
75 { return new wxGridCellNumberRenderer
; }
78 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
81 class WXDLLIMPEXP_ADV wxGridCellFloatRenderer
: public wxGridCellStringRenderer
84 wxGridCellFloatRenderer(int width
= -1,
86 int format
= wxGRID_FLOAT_FORMAT_DEFAULT
);
88 // get/change formatting parameters
89 int GetWidth() const { return m_width
; }
90 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
91 int GetPrecision() const { return m_precision
; }
92 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
93 int GetFormat() const { return m_style
; }
94 void SetFormat(int format
) { m_style
= format
; m_format
.clear(); }
96 // draw the string right aligned with given width/precision
97 virtual void Draw(wxGrid
& grid
,
104 virtual wxSize
GetBestSize(wxGrid
& grid
,
105 wxGridCellAttr
& attr
,
109 // parameters string format is "width[,precision[,format]]"
110 // with format being one of f|e|g|E|F|G
111 virtual void SetParameters(const wxString
& params
);
113 virtual wxGridCellRenderer
*Clone() const;
116 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
119 // formatting parameters
127 // renderer for boolean fields
128 class WXDLLIMPEXP_ADV wxGridCellBoolRenderer
: public wxGridCellRenderer
131 // draw a check mark or nothing
132 virtual void Draw(wxGrid
& grid
,
133 wxGridCellAttr
& attr
,
139 // return the checkmark size
140 virtual wxSize
GetBestSize(wxGrid
& grid
,
141 wxGridCellAttr
& attr
,
145 virtual wxGridCellRenderer
*Clone() const
146 { return new wxGridCellBoolRenderer
; }
149 static wxSize ms_sizeCheckMark
;
155 #include "wx/datetime.h"
157 // the default renderer for the cells containing times and dates
158 class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer
: public wxGridCellStringRenderer
161 wxGridCellDateTimeRenderer(const wxString
& outformat
= wxDefaultDateTimeFormat
,
162 const wxString
& informat
= wxDefaultDateTimeFormat
);
164 // draw the string right aligned
165 virtual void Draw(wxGrid
& grid
,
166 wxGridCellAttr
& attr
,
172 virtual wxSize
GetBestSize(wxGrid
& grid
,
173 wxGridCellAttr
& attr
,
177 virtual wxGridCellRenderer
*Clone() const;
179 // output strptime()-like format string
180 virtual void SetParameters(const wxString
& params
);
183 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
187 wxDateTime m_dateDef
;
188 wxDateTime::TimeZone m_tz
;
191 #endif // wxUSE_DATETIME
193 // renders a number using the corresponding text string
194 class WXDLLIMPEXP_ADV wxGridCellEnumRenderer
: public wxGridCellStringRenderer
197 wxGridCellEnumRenderer( const wxString
& choices
= wxEmptyString
);
199 // draw the string right aligned
200 virtual void Draw(wxGrid
& grid
,
201 wxGridCellAttr
& attr
,
207 virtual wxSize
GetBestSize(wxGrid
& grid
,
208 wxGridCellAttr
& attr
,
212 virtual wxGridCellRenderer
*Clone() const;
214 // parameters string format is "item1[,item2[...,itemN]]" where itemN will
215 // be used if the cell value is N-1
216 virtual void SetParameters(const wxString
& params
);
219 wxString
GetString(const wxGrid
& grid
, int row
, int col
);
221 wxArrayString m_choices
;
225 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringRenderer
: public wxGridCellStringRenderer
228 wxGridCellAutoWrapStringRenderer() : wxGridCellStringRenderer() { }
230 virtual void Draw(wxGrid
& grid
,
231 wxGridCellAttr
& attr
,
237 virtual wxSize
GetBestSize(wxGrid
& grid
,
238 wxGridCellAttr
& attr
,
242 virtual wxGridCellRenderer
*Clone() const
243 { return new wxGridCellAutoWrapStringRenderer
; }
246 wxArrayString
GetTextLines( wxGrid
& grid
,
248 const wxGridCellAttr
& attr
,
252 // Helper methods of GetTextLines()
254 // Break a single logical line of text into several physical lines, all of
255 // which are added to the lines array. The lines are broken at maxWidth and
256 // the dc is used for measuring text extent only.
257 void BreakLine(wxDC
& dc
,
258 const wxString
& logicalLine
,
260 wxArrayString
& lines
);
262 // Break a word, which is supposed to be wider than maxWidth, into several
263 // lines, which are added to lines array and the last, incomplete, of which
264 // is returned in line output parameter.
266 // Returns the width of the last line.
267 wxCoord
BreakWord(wxDC
& dc
,
268 const wxString
& word
,
270 wxArrayString
& lines
,
277 #endif // _WX_GENERIC_GRIDCTRL_H_