]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/gridctrl.h
Fix wxOSX warnings about int-to-void* casts.
[wxWidgets.git] / include / wx / generic / gridctrl.h
CommitLineData
d10f4bf9 1///////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/generic/gridctrl.h
d10f4bf9
VZ
3// Purpose: wxGrid controls
4// Author: Paul Gammans, Roger Gammans
5// Modified by:
6// Created: 11/04/2001
d10f4bf9 7// Copyright: (c) The Computer Surgery (paul@compsurg.co.uk)
65571936 8// Licence: wxWindows licence
d10f4bf9
VZ
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_GENERIC_GRIDCTRL_H_
12#define _WX_GENERIC_GRIDCTRL_H_
13
d10f4bf9 14#include "wx/grid.h"
df9fac6d
PC
15
16#if wxUSE_GRID
d10f4bf9 17
9a83f860
VZ
18#define wxGRID_VALUE_CHOICEINT wxT("choiceint")
19#define wxGRID_VALUE_DATETIME wxT("datetime")
d10f4bf9 20
29efc6e4
FM
21
22// the default renderer for the cells containing string data
23class WXDLLIMPEXP_ADV wxGridCellStringRenderer : public wxGridCellRenderer
24{
25public:
26 // draw the string
27 virtual void Draw(wxGrid& grid,
28 wxGridCellAttr& attr,
29 wxDC& dc,
30 const wxRect& rect,
31 int row, int col,
32 bool isSelected);
33
34 // return the string extent
35 virtual wxSize GetBestSize(wxGrid& grid,
36 wxGridCellAttr& attr,
37 wxDC& dc,
38 int row, int col);
39
40 virtual wxGridCellRenderer *Clone() const
41 { return new wxGridCellStringRenderer; }
42
43protected:
44 // set the text colours before drawing
45 void SetTextColoursAndFont(const wxGrid& grid,
46 const wxGridCellAttr& attr,
47 wxDC& dc,
48 bool isSelected);
49
50 // calc the string extent for given string/font
51 wxSize DoGetBestSize(const wxGridCellAttr& attr,
52 wxDC& dc,
53 const wxString& text);
54};
55
56// the default renderer for the cells containing numeric (long) data
57class WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer
58{
59public:
60 // draw the string right aligned
61 virtual void Draw(wxGrid& grid,
62 wxGridCellAttr& attr,
63 wxDC& dc,
64 const wxRect& rect,
65 int row, int col,
66 bool isSelected);
67
68 virtual wxSize GetBestSize(wxGrid& grid,
69 wxGridCellAttr& attr,
70 wxDC& dc,
71 int row, int col);
72
73 virtual wxGridCellRenderer *Clone() const
74 { return new wxGridCellNumberRenderer; }
75
76protected:
77 wxString GetString(const wxGrid& grid, int row, int col);
78};
79
80class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer
81{
82public:
1d8d3cc5
VZ
83 wxGridCellFloatRenderer(int width = -1,
84 int precision = -1,
85 int format = wxGRID_FLOAT_FORMAT_DEFAULT);
29efc6e4
FM
86
87 // get/change formatting parameters
88 int GetWidth() const { return m_width; }
89 void SetWidth(int width) { m_width = width; m_format.clear(); }
90 int GetPrecision() const { return m_precision; }
91 void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
1d8d3cc5
VZ
92 int GetFormat() const { return m_style; }
93 void SetFormat(int format) { m_style = format; m_format.clear(); }
29efc6e4
FM
94
95 // draw the string right aligned with given width/precision
96 virtual void Draw(wxGrid& grid,
97 wxGridCellAttr& attr,
98 wxDC& dc,
99 const wxRect& rect,
100 int row, int col,
101 bool isSelected);
102
103 virtual wxSize GetBestSize(wxGrid& grid,
104 wxGridCellAttr& attr,
105 wxDC& dc,
106 int row, int col);
107
1d8d3cc5
VZ
108 // parameters string format is "width[,precision[,format]]"
109 // with format being one of f|e|g|E|F|G
29efc6e4
FM
110 virtual void SetParameters(const wxString& params);
111
112 virtual wxGridCellRenderer *Clone() const;
113
114protected:
115 wxString GetString(const wxGrid& grid, int row, int col);
116
117private:
118 // formatting parameters
119 int m_width,
120 m_precision;
121
1d8d3cc5 122 int m_style;
29efc6e4
FM
123 wxString m_format;
124};
125
126// renderer for boolean fields
127class WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer
128{
129public:
130 // draw a check mark or nothing
131 virtual void Draw(wxGrid& grid,
132 wxGridCellAttr& attr,
133 wxDC& dc,
134 const wxRect& rect,
135 int row, int col,
136 bool isSelected);
137
138 // return the checkmark size
139 virtual wxSize GetBestSize(wxGrid& grid,
140 wxGridCellAttr& attr,
141 wxDC& dc,
142 int row, int col);
143
144 virtual wxGridCellRenderer *Clone() const
145 { return new wxGridCellBoolRenderer; }
146
147private:
148 static wxSize ms_sizeCheckMark;
149};
150
151
e2b87f38 152#if wxUSE_DATETIME
6d7aee4f
VZ
153
154#include "wx/datetime.h"
e2b87f38 155
db890987 156// the default renderer for the cells containing times and dates
12f190b0 157class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
d10f4bf9
VZ
158{
159public:
fbfb8bcc
VZ
160 wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
161 const wxString& informat = wxDefaultDateTimeFormat);
d10f4bf9
VZ
162
163 // draw the string right aligned
164 virtual void Draw(wxGrid& grid,
165 wxGridCellAttr& attr,
166 wxDC& dc,
167 const wxRect& rect,
168 int row, int col,
169 bool isSelected);
170
171 virtual wxSize GetBestSize(wxGrid& grid,
172 wxGridCellAttr& attr,
173 wxDC& dc,
174 int row, int col);
175
176 virtual wxGridCellRenderer *Clone() const;
177
db890987 178 // output strptime()-like format string
d10f4bf9
VZ
179 virtual void SetParameters(const wxString& params);
180
181protected:
fbfb8bcc 182 wxString GetString(const wxGrid& grid, int row, int col);
d10f4bf9
VZ
183
184 wxString m_iformat;
185 wxString m_oformat;
186 wxDateTime m_dateDef;
187 wxDateTime::TimeZone m_tz;
188};
189
e2b87f38 190#endif // wxUSE_DATETIME
d10f4bf9 191
db890987 192// renders a number using the corresponding text string
12f190b0 193class WXDLLIMPEXP_ADV wxGridCellEnumRenderer : public wxGridCellStringRenderer
d10f4bf9
VZ
194{
195public:
196 wxGridCellEnumRenderer( const wxString& choices = wxEmptyString );
197
198 // draw the string right aligned
199 virtual void Draw(wxGrid& grid,
200 wxGridCellAttr& attr,
201 wxDC& dc,
202 const wxRect& rect,
203 int row, int col,
204 bool isSelected);
205
206 virtual wxSize GetBestSize(wxGrid& grid,
207 wxGridCellAttr& attr,
208 wxDC& dc,
209 int row, int col);
210
211 virtual wxGridCellRenderer *Clone() const;
212
db890987
VZ
213 // parameters string format is "item1[,item2[...,itemN]]" where itemN will
214 // be used if the cell value is N-1
d10f4bf9
VZ
215 virtual void SetParameters(const wxString& params);
216
217protected:
fbfb8bcc 218 wxString GetString(const wxGrid& grid, int row, int col);
d10f4bf9
VZ
219
220 wxArrayString m_choices;
221};
222
d10f4bf9 223
12f190b0 224class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
d10f4bf9
VZ
225{
226public:
227 wxGridCellAutoWrapStringRenderer() : wxGridCellStringRenderer() { }
228
229 virtual void Draw(wxGrid& grid,
230 wxGridCellAttr& attr,
231 wxDC& dc,
232 const wxRect& rect,
233 int row, int col,
234 bool isSelected);
235
236 virtual wxSize GetBestSize(wxGrid& grid,
237 wxGridCellAttr& attr,
238 wxDC& dc,
239 int row, int col);
240
241 virtual wxGridCellRenderer *Clone() const
242 { return new wxGridCellAutoWrapStringRenderer; }
243
244private:
245 wxArrayString GetTextLines( wxGrid& grid,
246 wxDC& dc,
fbfb8bcc 247 const wxGridCellAttr& attr,
d10f4bf9
VZ
248 const wxRect& rect,
249 int row, int col);
250
0ec98fd6
VZ
251 // Helper methods of GetTextLines()
252
253 // Break a single logical line of text into several physical lines, all of
254 // which are added to the lines array. The lines are broken at maxWidth and
255 // the dc is used for measuring text extent only.
256 void BreakLine(wxDC& dc,
257 const wxString& logicalLine,
258 wxCoord maxWidth,
259 wxArrayString& lines);
260
261 // Break a word, which is supposed to be wider than maxWidth, into several
262 // lines, which are added to lines array and the last, incomplete, of which
263 // is returned in line output parameter.
264 //
265 // Returns the width of the last line.
266 wxCoord BreakWord(wxDC& dc,
267 const wxString& word,
268 wxCoord maxWidth,
269 wxArrayString& lines,
270 wxString& line);
271
272
d10f4bf9
VZ
273};
274
df9fac6d
PC
275#endif // wxUSE_GRID
276#endif // _WX_GENERIC_GRIDCTRL_H_