]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: grid.h | |
afe0e400 | 3 | // Purpose: interface of wxGrid and related classes |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
8b9ef005 BP |
9 | /** |
10 | @class wxGridCellRenderer | |
11 | ||
12 | This class is responsible for actually drawing the cell in the grid. You | |
13 | may pass it to the wxGridCellAttr (below) to change the format of one given | |
14 | cell or to wxGrid::SetDefaultRenderer() to change the view of all cells. | |
15 | This is an abstract class, and you will normally use one of the predefined | |
16 | derived classes or derive your own class from it. | |
17 | ||
18 | @library{wxadv} | |
19 | @category{grid} | |
20 | ||
db890987 VZ |
21 | @see wxGridCellAutoWrapStringRenderer, wxGridCellBoolRenderer, |
22 | wxGridCellDateTimeRenderer, wxGridCellEnumRenderer, | |
23 | wxGridCellFloatRenderer, wxGridCellNumberRenderer, | |
24 | wxGridCellStringRenderer | |
8b9ef005 BP |
25 | */ |
26 | class wxGridCellRenderer | |
27 | { | |
28 | public: | |
29 | /** | |
30 | This function must be implemented in derived classes to return a copy | |
31 | of itself. | |
32 | */ | |
33 | virtual wxGridCellRenderer* Clone() const = 0; | |
34 | ||
35 | /** | |
36 | Draw the given cell on the provided DC inside the given rectangle using | |
37 | the style specified by the attribute and the default or selected state | |
38 | corresponding to the isSelected value. | |
39 | ||
40 | This pure virtual function has a default implementation which will | |
41 | prepare the DC using the given attribute: it will draw the rectangle | |
42 | with the background colour from attr and set the text colour and font. | |
43 | */ | |
44 | virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, | |
45 | const wxRect& rect, int row, int col, | |
46 | bool isSelected) = 0; | |
47 | ||
48 | /** | |
49 | Get the preferred size of the cell for its contents. | |
50 | */ | |
51 | virtual wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, | |
52 | int row, int col) = 0; | |
53 | }; | |
54 | ||
db890987 VZ |
55 | /** |
56 | @class wxGridCellAutoWrapStringRenderer | |
57 | ||
58 | This class may be used to format string data in a cell. The too | |
59 | long lines are wrapped to be shown entirely at word boundaries. | |
60 | ||
61 | @library{wxadv} | |
62 | @category{grid} | |
63 | ||
64 | @see wxGridCellRenderer, wxGridCellBoolRenderer, | |
65 | wxGridCellDateTimeRenderer, wxGridCellEnumRenderer, | |
66 | wxGridCellFloatRenderer, wxGridCellNumberRenderer, | |
67 | wxGridCellStringRenderer | |
68 | */ | |
69 | ||
70 | class wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer | |
71 | { | |
72 | public: | |
73 | /** | |
74 | Default constructor. | |
75 | */ | |
76 | wxGridCellAutoWrapStringRenderer(); | |
77 | }; | |
78 | ||
79 | ||
8b9ef005 BP |
80 | /** |
81 | @class wxGridCellBoolRenderer | |
82 | ||
83 | This class may be used to format boolean data in a cell. | |
84 | ||
85 | @library{wxadv} | |
86 | @category{grid} | |
87 | ||
db890987 VZ |
88 | @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer, |
89 | wxGridCellDateTimeRenderer, wxGridCellEnumRenderer, | |
90 | wxGridCellFloatRenderer, wxGridCellNumberRenderer, | |
8b9ef005 BP |
91 | wxGridCellStringRenderer |
92 | */ | |
93 | class wxGridCellBoolRenderer : public wxGridCellRenderer | |
94 | { | |
95 | public: | |
96 | /** | |
97 | Default constructor. | |
98 | */ | |
99 | wxGridCellBoolRenderer(); | |
100 | }; | |
101 | ||
db890987 VZ |
102 | /** |
103 | @class wxGridCellDateTimeRenderer | |
104 | ||
105 | This class may be used to format a date/time data in a cell. | |
106 | The class wxDateTime is used internally to display the local date/time | |
107 | or to parse the string date entered in the cell thanks to the defined format. | |
108 | ||
109 | @library{wxadv} | |
110 | @category{grid} | |
111 | ||
112 | @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer, | |
113 | wxGridCellBoolRenderer, wxGridCellEnumRenderer, | |
114 | wxGridCellFloatRenderer, wxGridCellNumberRenderer, | |
115 | wxGridCellStringRenderer | |
116 | */ | |
117 | class wxGridCellDateTimeRenderer : public wxGridCellStringRenderer | |
118 | { | |
119 | public: | |
120 | /** | |
121 | Date/time renderer constructor. | |
122 | ||
123 | @param outformat | |
124 | strptime()-like format string used the parse the output date/time. | |
125 | @param informat | |
126 | strptime()-like format string used to parse the string entered in the cell. | |
127 | */ | |
128 | wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat, | |
129 | const wxString& informat = wxDefaultDateTimeFormat); | |
130 | ||
131 | ||
132 | /** | |
133 | Sets the strptime()-like format string which will be used to parse | |
134 | the date/time. | |
135 | ||
136 | @param params | |
137 | strptime()-like format string used to parse the date/time. | |
138 | */ | |
139 | virtual void SetParameters(const wxString& params); | |
140 | }; | |
141 | ||
142 | /** | |
143 | @class wxGridCellEnumRenderer | |
144 | ||
145 | This class may be used to render in a cell a number as a textual | |
146 | equivalent. | |
147 | ||
148 | The corresponding text strings are specified as comma-separated items in | |
149 | the string passed to this renderer ctor or SetParameters() method. For | |
150 | example, if this string is @c "John,Fred,Bob" the cell will be rendered as | |
151 | "John", "Fred" or "Bob" if its contents is 0, 1 or 2 respectively. | |
152 | ||
153 | @library{wxadv} | |
154 | @category{grid} | |
155 | ||
156 | @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer, | |
157 | wxGridCellBoolRenderer, wxGridCellDateTimeRenderer, | |
158 | wxGridCellFloatRenderer, wxGridCellNumberRenderer, | |
159 | wxGridCellStringRenderer | |
160 | */ | |
161 | class wxGridCellEnumRenderer : public wxGridCellStringRenderer | |
162 | { | |
163 | public: | |
164 | /** | |
165 | Enum renderer ctor. | |
166 | ||
167 | @param choices | |
168 | Comma separated string parameters "item1[,item2[...,itemN]]". | |
169 | */ | |
170 | wxGridCellEnumRenderer( const wxString& choices = wxEmptyString ); | |
171 | ||
172 | /** | |
173 | Sets the comma separated string content of the enum. | |
174 | ||
175 | @param params | |
176 | Comma separated string parameters "item1[,item2[...,itemN]]". | |
177 | */ | |
178 | virtual void SetParameters(const wxString& params); | |
179 | }; | |
180 | ||
1d8d3cc5 VZ |
181 | /** |
182 | Specifier used to format the data to string for the numbers handled by | |
183 | wxGridCellFloatRenderer and wxGridCellFloatEditor. | |
184 | ||
185 | @since 2.9.3 | |
186 | */ | |
187 | enum wxGridCellFloatFormat | |
188 | { | |
189 | /// Decimal floating point (%f). | |
190 | wxGRID_FLOAT_FORMAT_FIXED = 0x0010, | |
191 | ||
192 | /// Scientific notation (mantise/exponent) using e character (%e). | |
193 | wxGRID_FLOAT_FORMAT_SCIENTIFIC = 0x0020, | |
194 | ||
195 | /// Use the shorter of %e or %f (%g). | |
196 | wxGRID_FLOAT_FORMAT_COMPACT = 0x0040, | |
197 | ||
198 | /// To use in combination with one of the above formats for the upper | |
199 | /// case version (%F/%E/%G) | |
200 | wxGRID_FLOAT_FORMAT_UPPER = 0x0080, | |
201 | ||
202 | /// The format used by default (wxGRID_FLOAT_FORMAT_FIXED). | |
203 | wxGRID_FLOAT_FORMAT_DEFAULT = wxGRID_FLOAT_FORMAT_FIXED | |
204 | }; | |
205 | ||
23324ae1 FM |
206 | /** |
207 | @class wxGridCellFloatRenderer | |
7c913512 | 208 | |
23324ae1 | 209 | This class may be used to format floating point data in a cell. |
7c913512 | 210 | |
23324ae1 | 211 | @library{wxadv} |
42b5841f | 212 | @category{grid} |
7c913512 | 213 | |
db890987 VZ |
214 | @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer, |
215 | wxGridCellBoolRenderer, wxGridCellDateTimeRenderer, | |
216 | wxGridCellEnumRenderer, wxGridCellNumberRenderer, | |
afe0e400 | 217 | wxGridCellStringRenderer |
23324ae1 FM |
218 | */ |
219 | class wxGridCellFloatRenderer : public wxGridCellStringRenderer | |
220 | { | |
221 | public: | |
222 | /** | |
db890987 VZ |
223 | Float cell renderer ctor. |
224 | ||
7c913512 | 225 | @param width |
4cc4bfaf | 226 | Minimum number of characters to be shown. |
7c913512 | 227 | @param precision |
4cc4bfaf | 228 | Number of digits after the decimal dot. |
1d8d3cc5 VZ |
229 | @param format |
230 | The format used to display the string, must be a combination of | |
7920b94b | 231 | ::wxGridCellFloatFormat enum elements. This parameter is only |
1d8d3cc5 | 232 | available since wxWidgets 2.9.3. |
23324ae1 | 233 | */ |
1d8d3cc5 VZ |
234 | wxGridCellFloatRenderer(int width = -1, int precision = -1, |
235 | int format = wxGRID_FLOAT_FORMAT_DEFAULT); | |
236 | ||
237 | /** | |
238 | Returns the specifier used to format the data to string. | |
239 | ||
7920b94b | 240 | The returned value is a combination of ::wxGridCellFloatFormat elements. |
1d8d3cc5 VZ |
241 | |
242 | @since 2.9.3 | |
243 | */ | |
244 | int GetFormat() const; | |
23324ae1 FM |
245 | |
246 | /** | |
42b5841f | 247 | Returns the precision. |
23324ae1 | 248 | */ |
328f5751 | 249 | int GetPrecision() const; |
23324ae1 FM |
250 | |
251 | /** | |
42b5841f | 252 | Returns the width. |
23324ae1 | 253 | */ |
328f5751 | 254 | int GetWidth() const; |
23324ae1 FM |
255 | |
256 | /** | |
1d8d3cc5 VZ |
257 | Set the format to use for display the number. |
258 | ||
259 | @param format | |
7920b94b | 260 | Must be a combination of ::wxGridCellFloatFormat enum elements. |
1d8d3cc5 VZ |
261 | |
262 | @since 2.9.3 | |
263 | */ | |
264 | void SetFormat(int format); | |
265 | ||
266 | /** | |
267 | The parameters string format is "width[,precision[,format]]" where | |
8cddee2d | 268 | @c format should be chosen between f|e|g|E|G (f is used by default) |
23324ae1 | 269 | */ |
adaaa686 | 270 | virtual void SetParameters(const wxString& params); |
23324ae1 FM |
271 | |
272 | /** | |
42b5841f | 273 | Sets the precision. |
23324ae1 FM |
274 | */ |
275 | void SetPrecision(int precision); | |
276 | ||
277 | /** | |
42b5841f | 278 | Sets the width. |
23324ae1 FM |
279 | */ |
280 | void SetWidth(int width); | |
281 | }; | |
282 | ||
23324ae1 | 283 | /** |
8b9ef005 | 284 | @class wxGridCellNumberRenderer |
7c913512 | 285 | |
8b9ef005 | 286 | This class may be used to format integer data in a cell. |
5039f140 | 287 | |
8b9ef005 BP |
288 | @library{wxadv} |
289 | @category{grid} | |
5039f140 | 290 | |
db890987 VZ |
291 | @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer, |
292 | wxGridCellBoolRenderer, wxGridCellDateTimeRenderer, | |
293 | wxGridCellEnumRenderer, wxGridCellFloatRenderer, | |
8b9ef005 BP |
294 | wxGridCellStringRenderer |
295 | */ | |
296 | class wxGridCellNumberRenderer : public wxGridCellStringRenderer | |
297 | { | |
298 | public: | |
299 | /** | |
300 | Default constructor. | |
301 | */ | |
302 | wxGridCellNumberRenderer(); | |
303 | }; | |
5039f140 | 304 | |
8b9ef005 BP |
305 | /** |
306 | @class wxGridCellStringRenderer | |
307 | ||
308 | This class may be used to format string data in a cell; it is the default | |
309 | for string cells. | |
7c913512 | 310 | |
23324ae1 | 311 | @library{wxadv} |
42b5841f | 312 | @category{grid} |
8b9ef005 | 313 | |
db890987 VZ |
314 | @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer, |
315 | wxGridCellBoolRenderer, wxGridCellDateTimeRenderer, | |
316 | wxGridCellEnumRenderer, wxGridCellFloatRenderer, | |
8b9ef005 | 317 | wxGridCellNumberRenderer |
23324ae1 | 318 | */ |
8b9ef005 | 319 | class wxGridCellStringRenderer : public wxGridCellRenderer |
23324ae1 FM |
320 | { |
321 | public: | |
afe0e400 BP |
322 | /** |
323 | Default constructor. | |
8b9ef005 BP |
324 | */ |
325 | wxGridCellStringRenderer(); | |
326 | }; | |
23324ae1 | 327 | |
3c4f71cc | 328 | |
8b9ef005 BP |
329 | /** |
330 | @class wxGridCellEditor | |
23324ae1 | 331 | |
8b9ef005 BP |
332 | This class is responsible for providing and manipulating the in-place edit |
333 | controls for the grid. Instances of wxGridCellEditor (actually, instances | |
334 | of derived classes since it is an abstract class) can be associated with | |
335 | the cell attributes for individual cells, rows, columns, or even for the | |
336 | entire grid. | |
77d2c45c | 337 | |
8b9ef005 BP |
338 | @library{wxadv} |
339 | @category{grid} | |
3c4f71cc | 340 | |
db890987 VZ |
341 | @see wxGridCellAutoWrapStringEditor, wxGridCellBoolEditor, |
342 | wxGridCellChoiceEditor, wxGridCellEnumEditor, | |
343 | wxGridCellFloatEditor, wxGridCellNumberEditor, | |
344 | wxGridCellTextEditor | |
8b9ef005 BP |
345 | */ |
346 | class wxGridCellEditor | |
347 | { | |
348 | public: | |
77d2c45c | 349 | /** |
8b9ef005 BP |
350 | Default constructor. |
351 | */ | |
352 | wxGridCellEditor(); | |
77d2c45c VZ |
353 | |
354 | /** | |
8b9ef005 | 355 | Fetch the value from the table and prepare the edit control to begin |
763163a8 VZ |
356 | editing. |
357 | ||
358 | This function should save the original value of the grid cell at the | |
359 | given @a row and @a col and show the control allowing the user to | |
360 | change it. | |
361 | ||
362 | @see EndEdit() | |
8b9ef005 BP |
363 | */ |
364 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; | |
77d2c45c | 365 | |
8b9ef005 BP |
366 | /** |
367 | Create a new object which is the copy of this one. | |
368 | */ | |
369 | virtual wxGridCellEditor* Clone() const = 0; | |
23324ae1 FM |
370 | |
371 | /** | |
8b9ef005 BP |
372 | Creates the actual edit control. |
373 | */ | |
374 | virtual void Create(wxWindow* parent, wxWindowID id, | |
375 | wxEvtHandler* evtHandler) = 0; | |
3c4f71cc | 376 | |
afe0e400 | 377 | /** |
8b9ef005 BP |
378 | Final cleanup. |
379 | */ | |
380 | virtual void Destroy(); | |
23324ae1 | 381 | |
10a4531d | 382 | /** |
763163a8 | 383 | End editing the cell. |
10a4531d | 384 | |
763163a8 VZ |
385 | This function must check if the current value of the editing control is |
386 | valid and different from the original value (available as @a oldval in | |
387 | its string form and possibly saved internally using its real type by | |
78e78812 VZ |
388 | BeginEdit()). If it isn't, it just returns @false, otherwise it must do |
389 | the following: | |
390 | # Save the new value internally so that ApplyEdit() could apply it. | |
391 | # Fill @a newval (which is never @NULL) with the string | |
392 | representation of the new value. | |
393 | # Return @true | |
394 | ||
395 | Notice that it must @em not modify the grid as the change could still | |
396 | be vetoed. | |
763163a8 VZ |
397 | |
398 | If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto | |
399 | this change, ApplyEdit() will be called next. | |
8b9ef005 | 400 | */ |
78e78812 VZ |
401 | virtual bool EndEdit(int row, int col, const wxGrid* grid, |
402 | const wxString& oldval, wxString* newval) = 0; | |
10a4531d | 403 | |
763163a8 VZ |
404 | /** |
405 | Effectively save the changes in the grid. | |
406 | ||
407 | This function should save the value of the control in the grid. It is | |
408 | called only after EndEdit() returns @true. | |
409 | */ | |
410 | virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0; | |
411 | ||
afe0e400 | 412 | /** |
8b9ef005 BP |
413 | Some types of controls on some platforms may need some help with the |
414 | Return key. | |
415 | */ | |
416 | virtual void HandleReturn(wxKeyEvent& event); | |
3c4f71cc | 417 | |
afe0e400 | 418 | /** |
8b9ef005 BP |
419 | Returns @true if the edit control has been created. |
420 | */ | |
421 | bool IsCreated(); | |
23324ae1 FM |
422 | |
423 | /** | |
8b9ef005 BP |
424 | Draws the part of the cell not occupied by the control: the base class |
425 | version just fills it with background colour from the attribute. | |
426 | */ | |
427 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr* attr); | |
23324ae1 FM |
428 | |
429 | /** | |
8b9ef005 BP |
430 | Reset the value in the control back to its starting value. |
431 | */ | |
432 | virtual void Reset() = 0; | |
3c4f71cc | 433 | |
8b9ef005 BP |
434 | /** |
435 | Size and position the edit control. | |
436 | */ | |
437 | virtual void SetSize(const wxRect& rect); | |
23324ae1 FM |
438 | |
439 | /** | |
8b9ef005 BP |
440 | Show or hide the edit control, use the specified attributes to set |
441 | colours/fonts for it. | |
442 | */ | |
443 | virtual void Show(bool show, wxGridCellAttr* attr = NULL); | |
3c4f71cc | 444 | |
8b9ef005 BP |
445 | /** |
446 | If the editor is enabled by clicking on the cell, this method will be | |
447 | called. | |
448 | */ | |
449 | virtual void StartingClick(); | |
23324ae1 FM |
450 | |
451 | /** | |
8b9ef005 BP |
452 | If the editor is enabled by pressing keys on the grid, this will be |
453 | called to let the editor do something about that first key if desired. | |
454 | */ | |
455 | virtual void StartingKey(wxKeyEvent& event); | |
3c4f71cc | 456 | |
8b9ef005 | 457 | protected: |
23324ae1 FM |
458 | |
459 | /** | |
8b9ef005 BP |
460 | The destructor is private because only DecRef() can delete us. |
461 | */ | |
462 | virtual ~wxGridCellEditor(); | |
463 | }; | |
3c4f71cc | 464 | |
db890987 VZ |
465 | /** |
466 | @class wxGridCellAutoWrapStringEditor | |
467 | ||
468 | Grid cell editor for wrappable string/text data. | |
469 | ||
470 | @library{wxadv} | |
471 | @category{grid} | |
472 | ||
473 | @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor, | |
474 | wxGridCellEnumEditor, wxGridCellFloatEditor, | |
475 | wxGridCellNumberEditor, wxGridCellTextEditor | |
476 | */ | |
477 | class wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor | |
478 | { | |
479 | public: | |
480 | wxGridCellAutoWrapStringEditor(); | |
481 | }; | |
482 | ||
8b9ef005 BP |
483 | /** |
484 | @class wxGridCellBoolEditor | |
23324ae1 | 485 | |
8b9ef005 | 486 | Grid cell editor for boolean data. |
23324ae1 | 487 | |
8b9ef005 BP |
488 | @library{wxadv} |
489 | @category{grid} | |
23324ae1 | 490 | |
db890987 VZ |
491 | @see wxGridCellEditor, wxGridCellAutoWrapStringEditor, |
492 | wxGridCellChoiceEditor, wxGridCellEnumEditor, | |
493 | wxGridCellFloatEditor, wxGridCellNumberEditor, | |
494 | wxGridCellTextEditor | |
8b9ef005 BP |
495 | */ |
496 | class wxGridCellBoolEditor : public wxGridCellEditor | |
497 | { | |
498 | public: | |
23324ae1 | 499 | /** |
8b9ef005 BP |
500 | Default constructor. |
501 | */ | |
502 | wxGridCellBoolEditor(); | |
5039f140 | 503 | |
8b9ef005 BP |
504 | /** |
505 | Returns @true if the given @a value is equal to the string | |
506 | representation of the truth value we currently use (see | |
507 | UseStringValues()). | |
508 | */ | |
509 | static bool IsTrueValue(const wxString& value); | |
3c4f71cc | 510 | |
23324ae1 | 511 | /** |
8b9ef005 BP |
512 | This method allows you to customize the values returned by GetValue() |
513 | for the cell using this editor. By default, the default values of the | |
514 | arguments are used, i.e. @c "1" is returned if the cell is checked and | |
515 | an empty string otherwise. | |
516 | */ | |
517 | static void UseStringValues(const wxString& valueTrue = "1", | |
57bf907d | 518 | const wxString& valueFalse = wxEmptyString); |
8b9ef005 | 519 | }; |
3c4f71cc | 520 | |
8b9ef005 BP |
521 | /** |
522 | @class wxGridCellChoiceEditor | |
23324ae1 | 523 | |
8b9ef005 BP |
524 | Grid cell editor for string data providing the user a choice from a list of |
525 | strings. | |
5039f140 | 526 | |
8b9ef005 BP |
527 | @library{wxadv} |
528 | @category{grid} | |
23324ae1 | 529 | |
db890987 VZ |
530 | @see wxGridCellEditor, wxGridCellAutoWrapStringEditor, |
531 | wxGridCellBoolEditor, wxGridCellEnumEditor, | |
532 | wxGridCellFloatEditor, wxGridCellNumberEditor, | |
533 | wxGridCellTextEditor | |
8b9ef005 BP |
534 | */ |
535 | class wxGridCellChoiceEditor : public wxGridCellEditor | |
536 | { | |
537 | public: | |
23324ae1 | 538 | /** |
db890987 VZ |
539 | Choice cell renderer ctor. |
540 | ||
8b9ef005 BP |
541 | @param count |
542 | Number of strings from which the user can choose. | |
543 | @param choices | |
544 | An array of strings from which the user can choose. | |
545 | @param allowOthers | |
546 | If allowOthers is @true, the user can type a string not in choices | |
547 | array. | |
548 | */ | |
549 | wxGridCellChoiceEditor(size_t count = 0, | |
550 | const wxString choices[] = NULL, | |
551 | bool allowOthers = false); | |
001f1f56 FM |
552 | |
553 | /** | |
554 | Choice cell renderer ctor. | |
555 | ||
556 | @param choices | |
557 | An array of strings from which the user can choose. | |
558 | @param allowOthers | |
559 | If allowOthers is @true, the user can type a string not in choices | |
560 | array. | |
561 | */ | |
8b9ef005 BP |
562 | wxGridCellChoiceEditor(const wxArrayString& choices, |
563 | bool allowOthers = false); | |
23324ae1 FM |
564 | |
565 | /** | |
8b9ef005 BP |
566 | Parameters string format is "item1[,item2[...,itemN]]" |
567 | */ | |
568 | virtual void SetParameters(const wxString& params); | |
569 | }; | |
23324ae1 | 570 | |
db890987 VZ |
571 | /** |
572 | @class wxGridCellEnumEditor | |
573 | ||
574 | Grid cell editor which displays an enum number as a textual equivalent | |
575 | (eg. data in cell is 0,1,2 ... n the cell could be displayed as | |
576 | "John","Fred"..."Bob" in the combo choice box). | |
577 | ||
578 | @library{wxadv} | |
579 | @category{grid} | |
580 | ||
581 | @see wxGridCellEditor, wxGridCellAutoWrapStringEditor, | |
582 | wxGridCellBoolEditor, wxGridCellChoiceEditor, | |
583 | wxGridCellTextEditor, wxGridCellFloatEditor, | |
584 | wxGridCellNumberEditor | |
585 | */ | |
586 | class wxGridCellEnumEditor : public wxGridCellChoiceEditor | |
587 | { | |
588 | public: | |
589 | /** | |
590 | Enum cell editor ctor. | |
591 | ||
592 | @param choices | |
593 | Comma separated choice parameters "item1[,item2[...,itemN]]". | |
594 | */ | |
595 | wxGridCellEnumEditor( const wxString& choices = wxEmptyString ); | |
596 | }; | |
597 | ||
8b9ef005 BP |
598 | /** |
599 | @class wxGridCellTextEditor | |
3c4f71cc | 600 | |
8b9ef005 | 601 | Grid cell editor for string/text data. |
23324ae1 | 602 | |
8b9ef005 BP |
603 | @library{wxadv} |
604 | @category{grid} | |
afe0e400 | 605 | |
db890987 VZ |
606 | @see wxGridCellEditor, wxGridCellAutoWrapStringEditor, |
607 | wxGridCellBoolEditor, wxGridCellChoiceEditor, | |
608 | wxGridCellEnumEditor, wxGridCellFloatEditor, | |
609 | wxGridCellNumberEditor | |
8b9ef005 BP |
610 | */ |
611 | class wxGridCellTextEditor : public wxGridCellEditor | |
612 | { | |
613 | public: | |
23324ae1 | 614 | /** |
8b9ef005 BP |
615 | Default constructor. |
616 | */ | |
617 | wxGridCellTextEditor(); | |
23324ae1 FM |
618 | |
619 | /** | |
8b9ef005 BP |
620 | The parameters string format is "n" where n is a number representing |
621 | the maximum width. | |
622 | */ | |
623 | virtual void SetParameters(const wxString& params); | |
624 | }; | |
5039f140 | 625 | |
8b9ef005 BP |
626 | /** |
627 | @class wxGridCellFloatEditor | |
23324ae1 | 628 | |
8b9ef005 | 629 | The editor for floating point numbers data. |
3c4f71cc | 630 | |
8b9ef005 BP |
631 | @library{wxadv} |
632 | @category{grid} | |
23324ae1 | 633 | |
db890987 VZ |
634 | @see wxGridCellEditor, wxGridCellAutoWrapStringEditor, |
635 | wxGridCellBoolEditor, wxGridCellChoiceEditor, | |
636 | wxGridCellEnumEditor, wxGridCellNumberEditor, | |
637 | wxGridCellTextEditor | |
8b9ef005 BP |
638 | */ |
639 | class wxGridCellFloatEditor : public wxGridCellTextEditor | |
640 | { | |
641 | public: | |
23324ae1 | 642 | /** |
db890987 VZ |
643 | Float cell editor ctor. |
644 | ||
8b9ef005 BP |
645 | @param width |
646 | Minimum number of characters to be shown. | |
647 | @param precision | |
648 | Number of digits after the decimal dot. | |
1d8d3cc5 VZ |
649 | @param format |
650 | The format to use for displaying the number, a combination of | |
7920b94b | 651 | ::wxGridCellFloatFormat enum elements. This parameter is only |
1d8d3cc5 | 652 | available since wxWidgets 2.9.3. |
8b9ef005 | 653 | */ |
1d8d3cc5 VZ |
654 | wxGridCellFloatEditor(int width = -1, int precision = -1, |
655 | int format = wxGRID_FLOAT_FORMAT_DEFAULT); | |
23324ae1 FM |
656 | |
657 | /** | |
1d8d3cc5 | 658 | The parameters string format is "width[,precision[,format]]" where |
8cddee2d | 659 | @c format should be chosen between f|e|g|E|G (f is used by default) |
8b9ef005 BP |
660 | */ |
661 | virtual void SetParameters(const wxString& params); | |
662 | }; | |
23324ae1 | 663 | |
8b9ef005 BP |
664 | /** |
665 | @class wxGridCellNumberEditor | |
3c4f71cc | 666 | |
8b9ef005 | 667 | Grid cell editor for numeric integer data. |
5039f140 | 668 | |
8b9ef005 BP |
669 | @library{wxadv} |
670 | @category{grid} | |
23324ae1 | 671 | |
db890987 VZ |
672 | @see wxGridCellEditor, wxGridCellAutoWrapStringEditor, |
673 | wxGridCellBoolEditor, wxGridCellChoiceEditor, | |
674 | wxGridCellEnumEditor, wxGridCellFloatEditor, | |
675 | wxGridCellTextEditor | |
8b9ef005 BP |
676 | */ |
677 | class wxGridCellNumberEditor : public wxGridCellTextEditor | |
678 | { | |
679 | public: | |
23324ae1 | 680 | /** |
8b9ef005 BP |
681 | Allows you to specify the range for acceptable data. Values equal to |
682 | -1 for both @a min and @a max indicate that no range checking should be | |
683 | done. | |
684 | */ | |
685 | wxGridCellNumberEditor(int min = -1, int max = -1); | |
3c4f71cc | 686 | |
23324ae1 | 687 | |
afe0e400 | 688 | /** |
8b9ef005 BP |
689 | Parameters string format is "min,max". |
690 | */ | |
691 | virtual void SetParameters(const wxString& params); | |
692 | ||
693 | protected: | |
3c4f71cc | 694 | |
afe0e400 | 695 | /** |
8b9ef005 BP |
696 | If the return value is @true, the editor uses a wxSpinCtrl to get user |
697 | input, otherwise it uses a wxTextCtrl. | |
698 | */ | |
699 | bool HasRange() const; | |
23324ae1 | 700 | |
afe0e400 | 701 | /** |
8b9ef005 BP |
702 | String representation of the value. |
703 | */ | |
704 | wxString GetString() const; | |
705 | }; | |
23324ae1 | 706 | |
23324ae1 | 707 | |
3c4f71cc | 708 | |
8b9ef005 BP |
709 | /** |
710 | @class wxGridCellAttr | |
23324ae1 | 711 | |
8b9ef005 BP |
712 | This class can be used to alter the cells' appearance in the grid by |
713 | changing their attributes from the defaults. An object of this class may be | |
714 | returned by wxGridTableBase::GetAttr(). | |
5039f140 | 715 | |
8b9ef005 BP |
716 | @library{wxadv} |
717 | @category{grid} | |
718 | */ | |
719 | class wxGridCellAttr | |
720 | { | |
721 | public: | |
62960a2c VZ |
722 | /** |
723 | Kind of the attribute to retrieve. | |
724 | ||
725 | @see wxGridCellAttrProvider::GetAttr(), wxGridTableBase::GetAttr() | |
726 | */ | |
727 | enum wxAttrKind | |
728 | { | |
729 | /// Return the combined effective attribute for the cell. | |
730 | Any, | |
731 | ||
732 | /// Return the attribute explicitly set for this cell. | |
733 | Cell, | |
734 | ||
735 | /// Return the attribute set for this cells row. | |
736 | Row, | |
737 | ||
738 | /// Return the attribute set for this cells column. | |
739 | Col | |
740 | }; | |
741 | ||
afe0e400 | 742 | /** |
8b9ef005 BP |
743 | Default constructor. |
744 | */ | |
ccf39540 | 745 | wxGridCellAttr(wxGridCellAttr* attrDefault = NULL); |
23324ae1 | 746 | /** |
8b9ef005 BP |
747 | Constructor specifying some of the often used attributes. |
748 | */ | |
749 | wxGridCellAttr(const wxColour& colText, const wxColour& colBack, | |
750 | const wxFont& font, int hAlign, int vAlign); | |
5039f140 | 751 | |
afe0e400 | 752 | /** |
8b9ef005 BP |
753 | Creates a new copy of this object. |
754 | */ | |
755 | wxGridCellAttr* Clone() const; | |
23324ae1 FM |
756 | |
757 | /** | |
8b9ef005 BP |
758 | This class is reference counted: it is created with ref count of 1, so |
759 | calling DecRef() once will delete it. Calling IncRef() allows to lock | |
760 | it until the matching DecRef() is called. | |
761 | */ | |
762 | void DecRef(); | |
23324ae1 FM |
763 | |
764 | /** | |
cfbc15ee VZ |
765 | Get the alignment to use for the cell with the given attribute. |
766 | ||
767 | If this attribute doesn't specify any alignment, the default attribute | |
768 | alignment is used (which can be changed using | |
769 | wxGrid::SetDefaultCellAlignment() but is left and top by default). | |
770 | ||
771 | Notice that @a hAlign and @a vAlign values are always overwritten by | |
772 | this function, use GetNonDefaultAlignment() if this is not desirable. | |
773 | ||
774 | @param hAlign | |
775 | Horizontal alignment is returned here if this argument is non-@NULL. | |
776 | It is one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT. | |
777 | @param vAlign | |
778 | Vertical alignment is returned here if this argument is non-@NULL. | |
779 | It is one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM. | |
8b9ef005 BP |
780 | */ |
781 | void GetAlignment(int* hAlign, int* vAlign) const; | |
23324ae1 FM |
782 | |
783 | /** | |
8b9ef005 BP |
784 | Returns the background colour. |
785 | */ | |
786 | const wxColour& GetBackgroundColour() const; | |
23324ae1 | 787 | |
23324ae1 | 788 | /** |
8b9ef005 BP |
789 | Returns the cell editor. |
790 | */ | |
791 | wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const; | |
23324ae1 FM |
792 | |
793 | /** | |
8b9ef005 BP |
794 | Returns the font. |
795 | */ | |
796 | const wxFont& GetFont() const; | |
23324ae1 | 797 | |
cfbc15ee VZ |
798 | /** |
799 | Get the alignment defined by this attribute. | |
800 | ||
801 | Unlike GetAlignment() this function only modifies @a hAlign and @a | |
802 | vAlign if this attribute does define a non-default alignment. This | |
803 | means that they must be initialized before calling this function and | |
804 | that their values will be preserved unchanged if they are different | |
805 | from wxALIGN_INVALID. | |
806 | ||
807 | For example, the following fragment can be used to use the cell | |
808 | alignment if one is defined but right-align its contents by default | |
809 | (instead of left-aligning it by default) while still using the default | |
810 | vertical alignment: | |
811 | @code | |
812 | int hAlign = wxALIGN_RIGHT, | |
813 | vAlign = wxALIGN_INVALID; | |
814 | attr.GetNonDefaultAlignment(&hAlign, &vAlign); | |
815 | @endcode | |
816 | ||
817 | @since 2.9.1 | |
818 | */ | |
819 | void GetNonDefaultAlignment(int *hAlign, int *vAlign) const; | |
820 | ||
23324ae1 | 821 | /** |
8b9ef005 BP |
822 | Returns the cell renderer. |
823 | */ | |
824 | wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const; | |
23324ae1 FM |
825 | |
826 | /** | |
8b9ef005 BP |
827 | Returns the text colour. |
828 | */ | |
829 | const wxColour& GetTextColour() const; | |
5e6e278d FM |
830 | |
831 | /** | |
8b9ef005 BP |
832 | Returns @true if this attribute has a valid alignment set. |
833 | */ | |
834 | bool HasAlignment() const; | |
7c913512 | 835 | |
23324ae1 | 836 | /** |
8b9ef005 | 837 | Returns @true if this attribute has a valid background colour set. |
23324ae1 | 838 | */ |
8b9ef005 | 839 | bool HasBackgroundColour() const; |
23324ae1 | 840 | |
23324ae1 | 841 | /** |
8b9ef005 | 842 | Returns @true if this attribute has a valid cell editor set. |
23324ae1 | 843 | */ |
8b9ef005 | 844 | bool HasEditor() const; |
23324ae1 FM |
845 | |
846 | /** | |
8b9ef005 | 847 | Returns @true if this attribute has a valid font set. |
23324ae1 | 848 | */ |
8b9ef005 | 849 | bool HasFont() const; |
23324ae1 FM |
850 | |
851 | /** | |
8b9ef005 | 852 | Returns @true if this attribute has a valid cell renderer set. |
23324ae1 | 853 | */ |
8b9ef005 | 854 | bool HasRenderer() const; |
23324ae1 FM |
855 | |
856 | /** | |
8b9ef005 | 857 | Returns @true if this attribute has a valid text colour set. |
23324ae1 | 858 | */ |
8b9ef005 | 859 | bool HasTextColour() const; |
23324ae1 FM |
860 | |
861 | /** | |
8b9ef005 BP |
862 | This class is reference counted: it is created with ref count of 1, so |
863 | calling DecRef() once will delete it. Calling IncRef() allows to lock | |
864 | it until the matching DecRef() is called. | |
23324ae1 | 865 | */ |
8b9ef005 | 866 | void IncRef(); |
23324ae1 FM |
867 | |
868 | /** | |
8b9ef005 | 869 | Returns @true if this cell is set as read-only. |
23324ae1 | 870 | */ |
8b9ef005 | 871 | bool IsReadOnly() const; |
23324ae1 FM |
872 | |
873 | /** | |
8b9ef005 BP |
874 | Sets the alignment. @a hAlign can be one of @c wxALIGN_LEFT, |
875 | @c wxALIGN_CENTRE or @c wxALIGN_RIGHT and @a vAlign can be one of | |
876 | @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. | |
23324ae1 | 877 | */ |
8b9ef005 | 878 | void SetAlignment(int hAlign, int vAlign); |
23324ae1 FM |
879 | |
880 | /** | |
8b9ef005 | 881 | Sets the background colour. |
23324ae1 | 882 | */ |
8b9ef005 | 883 | void SetBackgroundColour(const wxColour& colBack); |
23324ae1 FM |
884 | |
885 | /** | |
8b9ef005 | 886 | @todo Needs documentation. |
23324ae1 | 887 | */ |
8b9ef005 | 888 | void SetDefAttr(wxGridCellAttr* defAttr); |
23324ae1 FM |
889 | |
890 | /** | |
8b9ef005 | 891 | Sets the editor to be used with the cells with this attribute. |
23324ae1 | 892 | */ |
8b9ef005 | 893 | void SetEditor(wxGridCellEditor* editor); |
23324ae1 FM |
894 | |
895 | /** | |
8b9ef005 | 896 | Sets the font. |
23324ae1 | 897 | */ |
8b9ef005 | 898 | void SetFont(const wxFont& font); |
23324ae1 FM |
899 | |
900 | /** | |
8b9ef005 | 901 | Sets the cell as read-only. |
23324ae1 | 902 | */ |
8b9ef005 | 903 | void SetReadOnly(bool isReadOnly = true); |
23324ae1 FM |
904 | |
905 | /** | |
8b9ef005 BP |
906 | Sets the renderer to be used for cells with this attribute. Takes |
907 | ownership of the pointer. | |
23324ae1 | 908 | */ |
8b9ef005 | 909 | void SetRenderer(wxGridCellRenderer* renderer); |
5e6e278d FM |
910 | |
911 | /** | |
8b9ef005 | 912 | Sets the text colour. |
5e6e278d | 913 | */ |
8b9ef005 | 914 | void SetTextColour(const wxColour& colText); |
23324ae1 FM |
915 | }; |
916 | ||
ba9574c3 VZ |
917 | /** |
918 | Base class for corner window renderer. | |
919 | ||
920 | This is the simplest of all header renderers and only has a single | |
921 | function. | |
922 | ||
923 | @see wxGridCellAttrProvider::GetCornerRenderer() | |
924 | ||
925 | @since 2.9.1 | |
926 | */ | |
927 | class wxGridCornerHeaderRenderer | |
928 | { | |
929 | public: | |
930 | /** | |
931 | Called by the grid to draw the corner window border. | |
932 | ||
933 | This method is responsible for drawing the border inside the given @a | |
934 | rect and adjusting the rectangle size to correspond to the area inside | |
935 | the border, i.e. usually call wxRect::Deflate() to account for the | |
936 | border width. | |
937 | ||
938 | @param grid | |
939 | The grid whose corner window is being drawn. | |
940 | @param dc | |
941 | The device context to use for drawing. | |
942 | @param rect | |
943 | Input/output parameter which contains the border rectangle on input | |
944 | and should be updated to contain the area inside the border on | |
945 | function return. | |
946 | */ | |
947 | virtual void DrawBorder(const wxGrid& grid, | |
948 | wxDC& dc, | |
949 | wxRect& rect) const = 0; | |
950 | }; | |
951 | /** | |
952 | Common base class for row and column headers renderers. | |
953 | ||
954 | @see wxGridColumnHeaderRenderer, wxGridRowHeaderRenderer | |
955 | ||
956 | @since 2.9.1 | |
957 | */ | |
958 | class wxGridHeaderLabelsRenderer : public wxGridCornerHeaderRenderer | |
959 | { | |
960 | public: | |
961 | /** | |
962 | Called by the grid to draw the specified label. | |
963 | ||
964 | Notice that the base class DrawBorder() method is called before this | |
965 | one. | |
966 | ||
967 | The default implementation uses wxGrid::GetLabelTextColour() and | |
968 | wxGrid::GetLabelFont() to draw the label. | |
969 | */ | |
970 | virtual void DrawLabel(const wxGrid& grid, | |
971 | wxDC& dc, | |
972 | const wxString& value, | |
973 | const wxRect& rect, | |
974 | int horizAlign, | |
975 | int vertAlign, | |
976 | int textOrientation) const; | |
977 | }; | |
978 | ||
979 | /** | |
980 | Base class for row headers renderer. | |
981 | ||
982 | This is the same as wxGridHeaderLabelsRenderer currently but we still use a | |
983 | separate class for it to distinguish it from wxGridColumnHeaderRenderer. | |
984 | ||
985 | @see wxGridRowHeaderRendererDefault | |
986 | ||
987 | @see wxGridCellAttrProvider::GetRowHeaderRenderer() | |
988 | ||
989 | @since 2.9.1 | |
990 | */ | |
991 | class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer | |
992 | { | |
993 | }; | |
994 | ||
995 | /** | |
996 | Base class for column headers renderer. | |
997 | ||
998 | This is the same as wxGridHeaderLabelsRenderer currently but we still use a | |
999 | separate class for it to distinguish it from wxGridRowHeaderRenderer. | |
1000 | ||
1001 | @see wxGridColumnHeaderRendererDefault | |
1002 | ||
1003 | @see wxGridCellAttrProvider::GetColumnHeaderRenderer() | |
1004 | ||
1005 | @since 2.9.1 | |
1006 | */ | |
1007 | class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer | |
1008 | { | |
1009 | }; | |
1010 | ||
1011 | /** | |
1012 | Default row header renderer. | |
1013 | ||
1014 | You may derive from this class if you need to only override one of its | |
1015 | methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the | |
1016 | default implementation for the other one. | |
1017 | ||
1018 | @see wxGridColumnHeaderRendererDefault | |
1019 | ||
1020 | @since 2.9.1 | |
1021 | */ | |
163bd4f7 | 1022 | class wxGridRowHeaderRendererDefault : public wxGridRowHeaderRenderer |
ba9574c3 VZ |
1023 | { |
1024 | public: | |
1025 | /// Implement border drawing for the row labels. | |
1026 | virtual void DrawBorder(const wxGrid& grid, | |
1027 | wxDC& dc, | |
1028 | wxRect& rect) const; | |
1029 | }; | |
1030 | ||
1031 | /** | |
1032 | Default column header renderer. | |
1033 | ||
1034 | @see wxGridRowHeaderRendererDefault | |
1035 | ||
1036 | @since 2.9.1 | |
1037 | */ | |
1038 | class wxGridColumnHeaderRendererDefault : public wxGridColumnHeaderRenderer | |
1039 | { | |
1040 | public: | |
1041 | /// Implement border drawing for the column labels. | |
1042 | virtual void DrawBorder(const wxGrid& grid, | |
1043 | wxDC& dc, | |
1044 | wxRect& rect) const; | |
1045 | }; | |
1046 | ||
1047 | /** | |
1048 | Default corner window renderer. | |
1049 | ||
1050 | @see wxGridColumnHeaderRendererDefault, wxGridRowHeaderRendererDefault | |
1051 | ||
1052 | @since 2.9.1 | |
1053 | */ | |
1054 | class wxGridCornerHeaderRendererDefault : public wxGridCornerHeaderRenderer | |
1055 | { | |
1056 | public: | |
1057 | /// Implement border drawing for the corner window. | |
1058 | virtual void DrawBorder(const wxGrid& grid, | |
1059 | wxDC& dc, | |
1060 | wxRect& rect) const; | |
1061 | }; | |
1062 | ||
62960a2c VZ |
1063 | /** |
1064 | Class providing attributes to be used for the grid cells. | |
1065 | ||
1066 | This class both defines an interface which grid cell attributes providers | |
1067 | should implement -- and which can be implemented differently in derived | |
1068 | classes -- and a default implementation of this interface which is often | |
1069 | good enough to be used without modification, especially with not very large | |
1070 | grids for which the efficiency of attributes storage hardly matters (see | |
1071 | the discussion below). | |
1072 | ||
1073 | An object of this class can be associated with a wxGrid using | |
1074 | wxGridTableBase::SetAttrProvider() but it's not necessary to call it if you | |
1075 | intend to use the default provider as it is used by wxGridTableBase by | |
1076 | default anyhow. | |
1077 | ||
1078 | Notice that while attributes provided by this class can be set for | |
1079 | individual cells using SetAttr() or the entire rows or columns using | |
1080 | SetRowAttr() and SetColAttr() they are always retrieved using GetAttr() | |
1081 | function. | |
1082 | ||
1083 | ||
1084 | The default implementation of this class stores the attributes passed to | |
1085 | its SetAttr(), SetRowAttr() and SetColAttr() in a straightforward way. A | |
1086 | derived class may use its knowledge about how the attributes are used in | |
1087 | your program to implement it much more efficiently: for example, using a | |
1088 | special background colour for all even-numbered rows can be implemented by | |
1089 | simply returning the same attribute from GetAttr() if the row number is | |
1090 | even instead of having to store N/2 row attributes where N is the total | |
1091 | number of rows in the grid. | |
1092 | ||
1093 | Notice that objects of this class can't be copied. | |
1094 | */ | |
1095 | class wxGridCellAttrProvider : public wxClientDataContainer | |
1096 | { | |
1097 | public: | |
1098 | /// Trivial default constructor. | |
1099 | wxGridCellAttrProvider(); | |
1100 | ||
1101 | /// Destructor releases any attributes held by this class. | |
1102 | virtual ~wxGridCellAttrProvider(); | |
1103 | ||
1104 | /** | |
1105 | Get the attribute to use for the specified cell. | |
1106 | ||
1107 | If wxGridCellAttr::Any is used as @a kind value, this function combines | |
1108 | the attributes set for this cell using SetAttr() and those for its row | |
1109 | or column (set with SetRowAttr() or SetColAttr() respectively), with | |
1110 | the cell attribute having the highest precedence. | |
1111 | ||
1112 | Notice that the caller must call DecRef() on the returned pointer if it | |
1113 | is non-@NULL. | |
1114 | ||
1115 | @param row | |
1116 | The row of the cell. | |
1117 | @param col | |
1118 | The column of the cell. | |
1119 | @param kind | |
1120 | The kind of the attribute to return. | |
1121 | @return | |
1122 | The attribute to use which should be DecRef()'d by caller or @NULL | |
1123 | if no attributes are defined for this cell. | |
1124 | */ | |
1125 | virtual wxGridCellAttr *GetAttr(int row, int col, | |
1126 | wxGridCellAttr::wxAttrKind kind) const; | |
1127 | ||
1128 | /** | |
1129 | Setting attributes. | |
1130 | ||
1131 | All these functions take ownership of the attribute passed to them, | |
1132 | i.e. will call DecRef() on it themselves later and so it should not be | |
1133 | destroyed by the caller. And the attribute can be @NULL to reset a | |
1134 | previously set value. | |
1135 | */ | |
1136 | //@{ | |
1137 | ||
1138 | /// Set attribute for the specified cell. | |
1139 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); | |
1140 | ||
1141 | /// Set attribute for the specified row. | |
1142 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
1143 | ||
1144 | /// Set attribute for the specified column. | |
1145 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
1146 | ||
1147 | //@} | |
ba9574c3 VZ |
1148 | |
1149 | /** | |
1150 | Getting header renderers. | |
1151 | ||
1152 | These functions return the renderers for the given row or column header | |
1153 | label and the corner window. Unlike cell attributes, these objects are | |
1154 | not reference counted and are never @NULL so they are returned by | |
1155 | reference and not pointer and DecRef() shouldn't (and can't) be called | |
1156 | for them. | |
1157 | ||
1158 | All these functions were added in wxWidgets 2.9.1. | |
1159 | */ | |
1160 | //@{ | |
1161 | ||
1162 | /** | |
1163 | Return the renderer used for drawing column headers. | |
1164 | ||
1165 | By default wxGridColumnHeaderRendererDefault is returned. | |
1166 | ||
1167 | @see wxGrid::SetUseNativeColLabels(), wxGrid::UseNativeColHeader() | |
1168 | ||
1169 | @since 2.9.1 | |
1170 | */ | |
1171 | virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col); | |
1172 | ||
1173 | /** | |
1174 | Return the renderer used for drawing row headers. | |
1175 | ||
1176 | By default wxGridRowHeaderRendererDefault is returned. | |
1177 | ||
1178 | @since 2.9.1 | |
1179 | */ | |
1180 | virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row); | |
1181 | ||
1182 | /** | |
1183 | Return the renderer used for drawing the corner window. | |
1184 | ||
1185 | By default wxGridCornerHeaderRendererDefault is returned. | |
1186 | ||
1187 | @since 2.9.1 | |
1188 | */ | |
1189 | virtual const wxGridCornerHeaderRenderer& GetCornerRenderer(); | |
1190 | ||
1191 | //@} | |
62960a2c | 1192 | }; |
23324ae1 | 1193 | |
daf1cbe4 VZ |
1194 | /** |
1195 | Represents coordinates of a grid cell. | |
1196 | ||
1197 | An object of this class is simply a (row, column) pair. | |
1198 | */ | |
1199 | class wxGridCellCoords | |
1200 | { | |
1201 | public: | |
1202 | /** | |
1203 | Default constructor initializes the object to invalid state. | |
1204 | ||
1205 | Initially the row and column are both invalid (-1) and so operator!() | |
1206 | for an uninitialized wxGridCellCoords returns false. | |
1207 | */ | |
1208 | wxGridCellCoords(); | |
1209 | ||
1210 | /** | |
1211 | Constructor taking a row and a column. | |
1212 | */ | |
1213 | wxGridCellCoords(int row, int col); | |
1214 | ||
1215 | /** | |
1216 | Return the row of the coordinate. | |
1217 | */ | |
1218 | int GetRow() const; | |
1219 | ||
1220 | /** | |
1221 | Set the row of the coordinate. | |
1222 | */ | |
1223 | void SetRow(int n); | |
1224 | ||
1225 | /** | |
1226 | Return the column of the coordinate. | |
1227 | */ | |
1228 | int GetCol() const; | |
1229 | ||
1230 | /** | |
1231 | Set the column of the coordinate. | |
1232 | */ | |
1233 | void SetCol(int n); | |
1234 | ||
1235 | /** | |
1236 | Set the row and column of the coordinate. | |
1237 | */ | |
1238 | void Set(int row, int col); | |
1239 | ||
1240 | /** | |
1241 | Assignment operator for coordinate types. | |
1242 | */ | |
1243 | wxGridCellCoords& operator=(const wxGridCellCoords& other); | |
1244 | ||
1245 | /** | |
1246 | Equality operator. | |
1247 | */ | |
1248 | bool operator==(const wxGridCellCoords& other) const; | |
1249 | ||
1250 | /** | |
1251 | Inequality operator. | |
1252 | */ | |
1253 | bool operator!=(const wxGridCellCoords& other) const; | |
1254 | ||
1255 | /** | |
1256 | Checks whether the coordinates are invalid. | |
1257 | ||
1258 | Returns false only if both row and column are -1. Notice that if either | |
1259 | row or column (but not both) are -1, this method returns true even if | |
1260 | the object is invalid. This is done because objects in such state | |
1261 | should actually never exist, i.e. either both coordinates should be -1 | |
1262 | or none of them should be -1. | |
1263 | */ | |
1264 | bool operator!() const; | |
1265 | }; | |
e54c96f1 | 1266 | |
23324ae1 | 1267 | /** |
8b9ef005 | 1268 | @class wxGridTableBase |
7c913512 | 1269 | |
8b9ef005 BP |
1270 | The almost abstract base class for grid tables. |
1271 | ||
1272 | A grid table is responsible for storing the grid data and, indirectly, grid | |
1273 | cell attributes. The data can be stored in the way most convenient for the | |
1274 | application but has to be provided in string form to wxGrid. It is also | |
1275 | possible to provide cells values in other formats if appropriate, e.g. as | |
1276 | numbers. | |
1277 | ||
1278 | This base class is not quite abstract as it implements a trivial strategy | |
1279 | for storing the attributes by forwarding it to wxGridCellAttrProvider and | |
1280 | also provides stubs for some other functions. However it does have a number | |
1281 | of pure virtual methods which must be implemented in the derived classes. | |
1282 | ||
1283 | @see wxGridStringTable | |
7c913512 | 1284 | |
23324ae1 | 1285 | @library{wxadv} |
42b5841f | 1286 | @category{grid} |
23324ae1 | 1287 | */ |
8b9ef005 | 1288 | class wxGridTableBase : public wxObject |
23324ae1 FM |
1289 | { |
1290 | public: | |
1291 | /** | |
1292 | Default constructor. | |
8b9ef005 BP |
1293 | */ |
1294 | wxGridTableBase(); | |
23324ae1 FM |
1295 | |
1296 | /** | |
8b9ef005 BP |
1297 | Destructor frees the attribute provider if it was created. |
1298 | */ | |
1299 | virtual ~wxGridTableBase(); | |
23324ae1 | 1300 | |
8b9ef005 BP |
1301 | /** |
1302 | Must be overridden to return the number of rows in the table. | |
e54c96f1 | 1303 | |
8b9ef005 BP |
1304 | For backwards compatibility reasons, this method is not const. |
1305 | Use GetRowsCount() instead of it in const methods of derived table | |
1306 | classes. | |
1307 | */ | |
1308 | virtual int GetNumberRows() = 0; | |
7c913512 | 1309 | |
8b9ef005 BP |
1310 | /** |
1311 | Must be overridden to return the number of columns in the table. | |
7c913512 | 1312 | |
8b9ef005 BP |
1313 | For backwards compatibility reasons, this method is not const. |
1314 | Use GetColsCount() instead of it in const methods of derived table | |
1315 | classes, | |
1316 | */ | |
1317 | virtual int GetNumberCols() = 0; | |
7c913512 | 1318 | |
23324ae1 | 1319 | /** |
8b9ef005 | 1320 | Return the number of rows in the table. |
23324ae1 | 1321 | |
8b9ef005 BP |
1322 | This method is not virtual and is only provided as a convenience for |
1323 | the derived classes which can't call GetNumberRows() without a | |
1324 | @c const_cast from their const methods. | |
1325 | */ | |
1326 | int GetRowsCount() const; | |
23324ae1 | 1327 | |
8b9ef005 BP |
1328 | /** |
1329 | Return the number of columns in the table. | |
e54c96f1 | 1330 | |
8b9ef005 BP |
1331 | This method is not virtual and is only provided as a convenience for |
1332 | the derived classes which can't call GetNumberCols() without a | |
1333 | @c const_cast from their const methods. | |
1334 | */ | |
1335 | int GetColsCount() const; | |
7c913512 | 1336 | |
7c913512 | 1337 | |
23324ae1 | 1338 | /** |
8b9ef005 BP |
1339 | @name Table Cell Accessors |
1340 | */ | |
1341 | //@{ | |
23324ae1 FM |
1342 | |
1343 | /** | |
8acad210 VZ |
1344 | May be overridden to implement testing for empty cells. |
1345 | ||
1346 | This method is used by the grid to test if the given cell is not used | |
1347 | and so whether a neighbouring cell may overflow into it. By default it | |
1348 | only returns true if the value of the given cell, as returned by | |
1349 | GetValue(), is empty. | |
8b9ef005 | 1350 | */ |
8acad210 | 1351 | virtual bool IsEmptyCell(int row, int col); |
e54c96f1 | 1352 | |
8b9ef005 BP |
1353 | /** |
1354 | Same as IsEmptyCell() but taking wxGridCellCoords. | |
7c913512 | 1355 | |
8b9ef005 BP |
1356 | Notice that this method is not virtual, only IsEmptyCell() should be |
1357 | overridden. | |
1358 | */ | |
1359 | bool IsEmpty(const wxGridCellCoords& coords); | |
7c913512 | 1360 | |
afe0e400 | 1361 | /** |
8b9ef005 BP |
1362 | Must be overridden to implement accessing the table values as text. |
1363 | */ | |
1364 | virtual wxString GetValue(int row, int col) = 0; | |
23324ae1 FM |
1365 | |
1366 | /** | |
8b9ef005 BP |
1367 | Must be overridden to implement setting the table values as text. |
1368 | */ | |
1369 | virtual void SetValue(int row, int col, const wxString& value) = 0; | |
23324ae1 FM |
1370 | |
1371 | /** | |
8b9ef005 | 1372 | Returns the type of the value in the given cell. |
23324ae1 | 1373 | |
8b9ef005 BP |
1374 | By default all cells are strings and this method returns |
1375 | @c wxGRID_VALUE_STRING. | |
1376 | */ | |
1377 | virtual wxString GetTypeName(int row, int col); | |
23324ae1 FM |
1378 | |
1379 | /** | |
8b9ef005 BP |
1380 | Returns true if the value of the given cell can be accessed as if it |
1381 | were of the specified type. | |
23324ae1 | 1382 | |
8b9ef005 BP |
1383 | By default the cells can only be accessed as strings. Note that a cell |
1384 | could be accessible in different ways, e.g. a numeric cell may return | |
1385 | @true for @c wxGRID_VALUE_NUMBER but also for @c wxGRID_VALUE_STRING | |
1386 | indicating that the value can be coerced to a string form. | |
1387 | */ | |
1388 | virtual bool CanGetValueAs(int row, int col, const wxString& typeName); | |
23324ae1 FM |
1389 | |
1390 | /** | |
8b9ef005 BP |
1391 | Returns true if the value of the given cell can be set as if it were of |
1392 | the specified type. | |
23324ae1 | 1393 | |
8b9ef005 BP |
1394 | @see CanGetValueAs() |
1395 | */ | |
1396 | virtual bool CanSetValueAs(int row, int col, const wxString& typeName); | |
e54c96f1 | 1397 | |
8b9ef005 BP |
1398 | /** |
1399 | Returns the value of the given cell as a long. | |
7c913512 | 1400 | |
8b9ef005 BP |
1401 | This should only be called if CanGetValueAs() returns @true when called |
1402 | with @c wxGRID_VALUE_NUMBER argument. Default implementation always | |
1403 | return 0. | |
1404 | */ | |
1405 | virtual long GetValueAsLong(int row, int col); | |
7c913512 | 1406 | |
afe0e400 | 1407 | /** |
8b9ef005 | 1408 | Returns the value of the given cell as a double. |
23324ae1 | 1409 | |
8b9ef005 BP |
1410 | This should only be called if CanGetValueAs() returns @true when called |
1411 | with @c wxGRID_VALUE_FLOAT argument. Default implementation always | |
1412 | return 0.0. | |
1413 | */ | |
1414 | virtual double GetValueAsDouble(int row, int col); | |
23324ae1 FM |
1415 | |
1416 | /** | |
8b9ef005 | 1417 | Returns the value of the given cell as a boolean. |
23324ae1 | 1418 | |
8b9ef005 BP |
1419 | This should only be called if CanGetValueAs() returns @true when called |
1420 | with @c wxGRID_VALUE_BOOL argument. Default implementation always | |
1421 | return false. | |
1422 | */ | |
1423 | virtual bool GetValueAsBool(int row, int col); | |
23324ae1 FM |
1424 | |
1425 | /** | |
8b9ef005 BP |
1426 | Returns the value of the given cell as a user-defined type. |
1427 | ||
1428 | This should only be called if CanGetValueAs() returns @true when called | |
1429 | with @a typeName. Default implementation always return @NULL. | |
1430 | */ | |
1431 | virtual void *GetValueAsCustom(int row, int col, const wxString& typeName); | |
23324ae1 FM |
1432 | |
1433 | /** | |
8b9ef005 BP |
1434 | Sets the value of the given cell as a long. |
1435 | ||
1436 | This should only be called if CanSetValueAs() returns @true when called | |
1437 | with @c wxGRID_VALUE_NUMBER argument. Default implementation doesn't do | |
1438 | anything. | |
1439 | */ | |
1440 | virtual void SetValueAsLong(int row, int col, long value); | |
23324ae1 FM |
1441 | |
1442 | /** | |
8b9ef005 BP |
1443 | Sets the value of the given cell as a double. |
1444 | ||
1445 | This should only be called if CanSetValueAs() returns @true when called | |
1446 | with @c wxGRID_VALUE_FLOAT argument. Default implementation doesn't do | |
1447 | anything. | |
1448 | */ | |
1449 | virtual void SetValueAsDouble(int row, int col, double value); | |
23324ae1 FM |
1450 | |
1451 | /** | |
8b9ef005 BP |
1452 | Sets the value of the given cell as a boolean. |
1453 | ||
1454 | This should only be called if CanSetValueAs() returns @true when called | |
1455 | with @c wxGRID_VALUE_BOOL argument. Default implementation doesn't do | |
1456 | anything. | |
1457 | */ | |
1458 | virtual void SetValueAsBool( int row, int col, bool value ); | |
23324ae1 FM |
1459 | |
1460 | /** | |
8b9ef005 BP |
1461 | Sets the value of the given cell as a user-defined type. |
1462 | ||
1463 | This should only be called if CanSetValueAs() returns @true when called | |
1464 | with @a typeName. Default implementation doesn't do anything. | |
1465 | */ | |
1466 | virtual void SetValueAsCustom(int row, int col, const wxString& typeName, | |
1467 | void *value); | |
1468 | ||
1469 | //@} | |
1470 | ||
23324ae1 FM |
1471 | |
1472 | /** | |
8b9ef005 BP |
1473 | Called by the grid when the table is associated with it. |
1474 | ||
1475 | The default implementation stores the pointer and returns it from its | |
1476 | GetView() and so only makes sense if the table cannot be associated | |
1477 | with more than one grid at a time. | |
1478 | */ | |
1479 | virtual void SetView(wxGrid *grid); | |
23324ae1 FM |
1480 | |
1481 | /** | |
8b9ef005 BP |
1482 | Returns the last grid passed to SetView(). |
1483 | */ | |
1484 | virtual wxGrid *GetView() const; | |
1485 | ||
23324ae1 FM |
1486 | |
1487 | /** | |
8b9ef005 | 1488 | @name Table Structure Modifiers |
23324ae1 | 1489 | |
8b9ef005 BP |
1490 | Notice that none of these functions are pure virtual as they don't have |
1491 | to be implemented if the table structure is never modified after | |
1492 | creation, i.e. neither rows nor columns are never added or deleted but | |
1493 | that you do need to implement them if they are called, i.e. if your | |
1494 | code either calls them directly or uses the matching wxGrid methods, as | |
1495 | by default they simply do nothing which is definitely inappropriate. | |
1496 | */ | |
1497 | //@{ | |
23324ae1 | 1498 | |
8b9ef005 BP |
1499 | /** |
1500 | Clear the table contents. | |
e54c96f1 | 1501 | |
8b9ef005 BP |
1502 | This method is used by wxGrid::ClearGrid(). |
1503 | */ | |
1504 | virtual void Clear(); | |
7c913512 | 1505 | |
8b9ef005 BP |
1506 | /** |
1507 | Insert additional rows into the table. | |
7c913512 | 1508 | |
8b9ef005 BP |
1509 | @param pos |
1510 | The position of the first new row. | |
1511 | @param numRows | |
1512 | The number of rows to insert. | |
1513 | */ | |
1514 | virtual bool InsertRows(size_t pos = 0, size_t numRows = 1); | |
7c913512 | 1515 | |
23324ae1 | 1516 | /** |
8b9ef005 BP |
1517 | Append additional rows at the end of the table. |
1518 | ||
1519 | This method is provided in addition to InsertRows() as some data models | |
1520 | may only support appending rows to them but not inserting them at | |
1521 | arbitrary locations. In such case you may implement this method only | |
1522 | and leave InsertRows() unimplemented. | |
1523 | ||
1524 | @param numRows | |
1525 | The number of rows to add. | |
1526 | */ | |
1527 | virtual bool AppendRows(size_t numRows = 1); | |
23324ae1 FM |
1528 | |
1529 | /** | |
8b9ef005 | 1530 | Delete rows from the table. |
afe0e400 | 1531 | |
4d8e8355 VZ |
1532 | Notice that currently deleting a row intersecting a multi-cell (see |
1533 | SetCellSize()) is not supported and will result in a crash. | |
1534 | ||
8b9ef005 BP |
1535 | @param pos |
1536 | The first row to delete. | |
1537 | @param numRows | |
1538 | The number of rows to delete. | |
1539 | */ | |
1540 | virtual bool DeleteRows(size_t pos = 0, size_t numRows = 1); | |
1541 | ||
1542 | /** | |
1543 | Exactly the same as InsertRows() but for columns. | |
1544 | */ | |
1545 | virtual bool InsertCols(size_t pos = 0, size_t numCols = 1); | |
23324ae1 FM |
1546 | |
1547 | /** | |
8b9ef005 BP |
1548 | Exactly the same as AppendRows() but for columns. |
1549 | */ | |
1550 | virtual bool AppendCols(size_t numCols = 1); | |
23324ae1 | 1551 | |
8b9ef005 BP |
1552 | /** |
1553 | Exactly the same as DeleteRows() but for columns. | |
1554 | */ | |
1555 | virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1); | |
e54c96f1 | 1556 | |
8b9ef005 | 1557 | //@} |
7c913512 | 1558 | |
8b9ef005 BP |
1559 | /** |
1560 | @name Table Row and Column Labels | |
7c913512 | 1561 | |
8b9ef005 BP |
1562 | By default the numbers are used for labeling rows and Latin letters for |
1563 | labeling columns. If the table has more than 26 columns, the pairs of | |
1564 | letters are used starting from the 27-th one and so on, i.e. the | |
1565 | sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ, | |
1566 | AAA, ... | |
1567 | */ | |
1568 | //@{ | |
7c913512 | 1569 | |
23324ae1 | 1570 | /** |
8b9ef005 BP |
1571 | Return the label of the specified row. |
1572 | */ | |
1573 | virtual wxString GetRowLabelValue(int row); | |
23324ae1 | 1574 | |
8b9ef005 BP |
1575 | /** |
1576 | Return the label of the specified column. | |
1577 | */ | |
1578 | virtual wxString GetColLabelValue(int col); | |
5e6e278d | 1579 | |
23324ae1 | 1580 | /** |
8b9ef005 | 1581 | Set the given label for the specified row. |
5e6e278d | 1582 | |
8b9ef005 BP |
1583 | The default version does nothing, i.e. the label is not stored. You |
1584 | must override this method in your derived class if you wish | |
1585 | wxGrid::SetRowLabelValue() to work. | |
1586 | */ | |
1587 | virtual void SetRowLabelValue(int row, const wxString& label); | |
23324ae1 FM |
1588 | |
1589 | /** | |
8b9ef005 BP |
1590 | Exactly the same as SetRowLabelValue() but for columns. |
1591 | */ | |
1592 | virtual void SetColLabelValue(int col, const wxString& label); | |
23324ae1 | 1593 | |
8b9ef005 | 1594 | //@} |
23324ae1 FM |
1595 | |
1596 | ||
8b9ef005 BP |
1597 | /** |
1598 | @name Attributes Management | |
e54c96f1 | 1599 | |
8b9ef005 BP |
1600 | By default the attributes management is delegated to |
1601 | wxGridCellAttrProvider class. You may override the methods in this | |
1602 | section to handle the attributes directly if, for example, they can be | |
1603 | computed from the cell values. | |
1604 | */ | |
1605 | //@{ | |
7c913512 | 1606 | |
8b9ef005 BP |
1607 | /** |
1608 | Associate this attributes provider with the table. | |
7c913512 | 1609 | |
8b9ef005 BP |
1610 | The table takes ownership of @a attrProvider pointer and will delete it |
1611 | when it doesn't need it any more. The pointer can be @NULL, however | |
1612 | this won't disable attributes management in the table but will just | |
1613 | result in a default attributes being recreated the next time any of the | |
1614 | other functions in this section is called. To completely disable the | |
1615 | attributes support, should this be needed, you need to override | |
1616 | CanHaveAttributes() to return @false. | |
1617 | */ | |
1618 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
afe0e400 | 1619 | |
23324ae1 | 1620 | /** |
8b9ef005 | 1621 | Returns the attribute provider currently being used. |
23324ae1 | 1622 | |
8b9ef005 BP |
1623 | This function may return @NULL if the attribute provider hasn't been |
1624 | neither associated with this table by SetAttrProvider() nor created on | |
1625 | demand by any other methods. | |
1626 | */ | |
1627 | wxGridCellAttrProvider *GetAttrProvider() const; | |
23324ae1 FM |
1628 | |
1629 | /** | |
8b9ef005 | 1630 | Return the attribute for the given cell. |
23324ae1 | 1631 | |
8b9ef005 BP |
1632 | By default this function is simply forwarded to |
1633 | wxGridCellAttrProvider::GetAttr() but it may be overridden to handle | |
1634 | attributes directly in the table. | |
1635 | */ | |
1636 | virtual wxGridCellAttr *GetAttr(int row, int col, | |
1637 | wxGridCellAttr::wxAttrKind kind); | |
23324ae1 FM |
1638 | |
1639 | /** | |
8b9ef005 | 1640 | Set attribute of the specified cell. |
23324ae1 | 1641 | |
8b9ef005 BP |
1642 | By default this function is simply forwarded to |
1643 | wxGridCellAttrProvider::SetAttr(). | |
1644 | ||
1645 | The table takes ownership of @a attr, i.e. will call DecRef() on it. | |
1646 | */ | |
1647 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); | |
23324ae1 FM |
1648 | |
1649 | /** | |
8b9ef005 | 1650 | Set attribute of the specified row. |
23324ae1 | 1651 | |
8b9ef005 BP |
1652 | By default this function is simply forwarded to |
1653 | wxGridCellAttrProvider::SetRowAttr(). | |
23324ae1 | 1654 | |
8b9ef005 BP |
1655 | The table takes ownership of @a attr, i.e. will call DecRef() on it. |
1656 | */ | |
1657 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
e54c96f1 | 1658 | |
8b9ef005 BP |
1659 | /** |
1660 | Set attribute of the specified column. | |
7c913512 | 1661 | |
8b9ef005 BP |
1662 | By default this function is simply forwarded to |
1663 | wxGridCellAttrProvider::SetColAttr(). | |
7c913512 | 1664 | |
8b9ef005 BP |
1665 | The table takes ownership of @a attr, i.e. will call DecRef() on it. |
1666 | */ | |
1667 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
1668 | ||
1669 | //@} | |
7c913512 | 1670 | |
23324ae1 | 1671 | /** |
8b9ef005 BP |
1672 | Returns true if this table supports attributes or false otherwise. |
1673 | ||
1674 | By default, the table automatically creates a wxGridCellAttrProvider | |
1675 | when this function is called if it had no attribute provider before and | |
1676 | returns @true. | |
1677 | */ | |
1678 | virtual bool CanHaveAttributes(); | |
23324ae1 FM |
1679 | }; |
1680 | ||
574e1c5a VZ |
1681 | /** |
1682 | @class wxGridSizesInfo | |
1683 | ||
1684 | wxGridSizesInfo stores information about sizes of all wxGrid rows or | |
d455444a | 1685 | columns. |
574e1c5a VZ |
1686 | |
1687 | It assumes that most of the rows or columns (which are both called elements | |
1688 | here as the difference between them doesn't matter at this class level) | |
1689 | have the default size and so stores it separately. And it uses a wxHashMap | |
1690 | to store the sizes of all elements which have the non-default size. | |
1691 | ||
1692 | This structure is particularly useful for serializing the sizes of all | |
1693 | wxGrid elements at once. | |
1694 | ||
1695 | @library{wxadv} | |
1696 | @category{grid} | |
1697 | */ | |
1698 | struct wxGridSizesInfo | |
1699 | { | |
1700 | /** | |
1701 | Default constructor. | |
1702 | ||
1703 | m_sizeDefault and m_customSizes must be initialized later. | |
1704 | */ | |
1705 | wxGridSizesInfo(); | |
1706 | ||
1707 | /** | |
1708 | Constructor. | |
1709 | ||
1710 | This constructor is used by wxGrid::GetRowSizes() and GetColSizes() | |
1711 | methods. User code will usually use the default constructor instead. | |
1712 | ||
1713 | @param defSize | |
1714 | The default element size. | |
d455444a | 1715 | @param allSizes |
574e1c5a VZ |
1716 | Array containing the sizes of @em all elements, including those |
1717 | which have the default size. | |
1718 | */ | |
1719 | wxGridSizesInfo(int defSize, const wxArrayInt& allSizes); | |
1720 | ||
1721 | /** | |
1722 | Get the element size. | |
1723 | ||
1724 | @param pos | |
1725 | The index of the element. | |
1726 | @return | |
1727 | The size for this element, using m_customSizes if @a pos is in it | |
1728 | or m_sizeDefault otherwise. | |
1729 | */ | |
1730 | int GetSize(unsigned pos) const; | |
1731 | ||
1732 | ||
1733 | /// Default size | |
1734 | int m_sizeDefault; | |
1735 | ||
1736 | /** | |
1737 | Map with element indices as keys and their sizes as values. | |
1738 | ||
1739 | This map only contains the elements with non-default size. | |
1740 | */ | |
1741 | wxUnsignedToIntHashMap m_customSizes; | |
1742 | }; | |
23324ae1 | 1743 | |
e54c96f1 | 1744 | |
23324ae1 | 1745 | /** |
8b9ef005 | 1746 | @class wxGrid |
7c913512 | 1747 | |
8b9ef005 | 1748 | wxGrid and its related classes are used for displaying and editing tabular |
caac7804 BP |
1749 | data. They provide a rich set of features for display, editing, and |
1750 | interacting with a variety of data sources. For simple applications, and to | |
1751 | help you get started, wxGrid is the only class you need to refer to | |
1752 | directly. It will set up default instances of the other classes and manage | |
1753 | them for you. For more complex applications you can derive your own classes | |
1754 | for custom grid views, grid data tables, cell editors and renderers. The | |
1755 | @ref overview_grid has examples of simple and more complex applications, | |
8b9ef005 BP |
1756 | explains the relationship between the various grid classes and has a |
1757 | summary of the keyboard shortcuts and mouse functions provided by wxGrid. | |
7c913512 | 1758 | |
8b9ef005 BP |
1759 | A wxGridTableBase class holds the actual data to be displayed by a wxGrid |
1760 | class. One or more wxGrid classes may act as a view for one table class. | |
1761 | The default table class is called wxGridStringTable and holds an array of | |
caac7804 | 1762 | strings. An instance of such a class is created by CreateGrid(). |
23324ae1 | 1763 | |
d13b34d3 | 1764 | wxGridCellRenderer is the abstract base class for rendering contents in a |
8b9ef005 | 1765 | cell. The following renderers are predefined: |
caac7804 BP |
1766 | |
1767 | - wxGridCellBoolRenderer | |
1768 | - wxGridCellFloatRenderer | |
1769 | - wxGridCellNumberRenderer | |
1770 | - wxGridCellStringRenderer | |
1771 | ||
8b9ef005 | 1772 | The look of a cell can be further defined using wxGridCellAttr. An object |
caac7804 | 1773 | of this type may be returned by wxGridTableBase::GetAttr(). |
3c4f71cc | 1774 | |
8b9ef005 BP |
1775 | wxGridCellEditor is the abstract base class for editing the value of a |
1776 | cell. The following editors are predefined: | |
caac7804 BP |
1777 | |
1778 | - wxGridCellBoolEditor | |
1779 | - wxGridCellChoiceEditor | |
1780 | - wxGridCellFloatEditor | |
1781 | - wxGridCellNumberEditor | |
1782 | - wxGridCellTextEditor | |
f8f31de6 | 1783 | |
caac7804 BP |
1784 | Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and |
1785 | wxGridEditorCreatedEvent for the documentation of all event types you can | |
1786 | use with wxGrid. | |
8b9ef005 BP |
1787 | |
1788 | @library{wxadv} | |
1789 | @category{grid} | |
23324ae1 | 1790 | |
caac7804 | 1791 | @see @ref overview_grid, wxGridUpdateLocker |
8b9ef005 BP |
1792 | */ |
1793 | class wxGrid : public wxScrolledWindow | |
1794 | { | |
1795 | public: | |
caac7804 | 1796 | |
23324ae1 | 1797 | /** |
8b9ef005 BP |
1798 | Different selection modes supported by the grid. |
1799 | */ | |
1800 | enum wxGridSelectionModes | |
1801 | { | |
1802 | /** | |
1803 | The default selection mode allowing selection of the individual | |
1804 | cells as well as of the entire rows and columns. | |
1805 | */ | |
1806 | wxGridSelectCells, | |
23324ae1 | 1807 | |
8b9ef005 BP |
1808 | /** |
1809 | The selection mode allowing the selection of the entire rows only. | |
3c4f71cc | 1810 | |
8b9ef005 BP |
1811 | The user won't be able to select any cells or columns in this mode. |
1812 | */ | |
1813 | wxGridSelectRows, | |
23324ae1 | 1814 | |
8b9ef005 BP |
1815 | /** |
1816 | The selection mode allowing the selection of the entire columns only. | |
3c4f71cc | 1817 | |
8b9ef005 BP |
1818 | The user won't be able to select any cells or rows in this mode. |
1819 | */ | |
b08cf4f4 VZ |
1820 | wxGridSelectColumns, |
1821 | ||
1822 | /** | |
1823 | The selection mode allowing the user to select either the entire | |
1824 | columns or the entire rows but not individual cells nor blocks. | |
1825 | ||
1826 | Notice that while this constant is defined as @code | |
1827 | wxGridSelectColumns | wxGridSelectRows @endcode this doesn't mean | |
1828 | that all the other combinations are valid -- at least currently | |
1829 | they are not. | |
1830 | ||
1831 | @since 2.9.1 | |
1832 | */ | |
1833 | wxGridSelectRowsOrColumns | |
8b9ef005 | 1834 | }; |
23324ae1 | 1835 | |
ea99e8e3 VZ |
1836 | /** |
1837 | Return values for GetCellSize(). | |
1838 | ||
1839 | @since 2.9.1 | |
1840 | */ | |
1841 | enum CellSpan | |
1842 | { | |
1843 | /// This cell is inside a span covered by another cell. | |
1844 | CellSpan_Inside = -1, | |
1845 | ||
1846 | /// This is a normal, non-spanning cell. | |
1847 | CellSpan_None = 0, | |
1848 | ||
1849 | /// This cell spans several physical wxGrid cells. | |
1850 | CellSpan_Main | |
1851 | }; | |
caac7804 BP |
1852 | |
1853 | /** | |
1854 | @name Constructors and Initialization | |
1855 | */ | |
1856 | //@{ | |
1857 | ||
23324ae1 | 1858 | /** |
8b9ef005 | 1859 | Default constructor. |
3c4f71cc | 1860 | |
8b9ef005 BP |
1861 | You must call Create() to really create the grid window and also call |
1862 | CreateGrid() or SetTable() to initialize the grid contents. | |
1863 | */ | |
1864 | wxGrid(); | |
23324ae1 | 1865 | /** |
8b9ef005 | 1866 | Constructor creating the grid window. |
3c4f71cc | 1867 | |
8b9ef005 BP |
1868 | You must call either CreateGrid() or SetTable() to initialize the grid |
1869 | contents before using it. | |
23324ae1 | 1870 | */ |
caac7804 | 1871 | wxGrid(wxWindow* parent, wxWindowID id, |
8b9ef005 BP |
1872 | const wxPoint& pos = wxDefaultPosition, |
1873 | const wxSize& size = wxDefaultSize, | |
1874 | long style = wxWANTS_CHARS, | |
1875 | const wxString& name = wxGridNameStr); | |
23324ae1 | 1876 | |
caac7804 BP |
1877 | /** |
1878 | Destructor. | |
1879 | ||
1880 | This will also destroy the associated grid table unless you passed a | |
1881 | table object to the grid and specified that the grid should not take | |
1882 | ownership of the table (see SetTable()). | |
1883 | */ | |
1884 | virtual ~wxGrid(); | |
1885 | ||
23324ae1 | 1886 | /** |
8b9ef005 BP |
1887 | Creates the grid window for an object initialized using the default |
1888 | constructor. | |
3c4f71cc | 1889 | |
8b9ef005 BP |
1890 | You must call either CreateGrid() or SetTable() to initialize the grid |
1891 | contents before using it. | |
1892 | */ | |
caac7804 | 1893 | bool Create(wxWindow* parent, wxWindowID id, |
8b9ef005 BP |
1894 | const wxPoint& pos = wxDefaultPosition, |
1895 | const wxSize& size = wxDefaultSize, | |
1896 | long style = wxWANTS_CHARS, | |
1897 | const wxString& name = wxGridNameStr); | |
23324ae1 FM |
1898 | |
1899 | /** | |
caac7804 | 1900 | Creates a grid with the specified initial number of rows and columns. |
3c4f71cc | 1901 | |
caac7804 BP |
1902 | Call this directly after the grid constructor. When you use this |
1903 | function wxGrid will create and manage a simple table of string values | |
1904 | for you. All of the grid data will be stored in memory. | |
1905 | ||
1906 | For applications with more complex data types or relationships, or for | |
1907 | dealing with very large datasets, you should derive your own grid table | |
1908 | class and pass a table object to the grid with SetTable(). | |
23324ae1 | 1909 | */ |
caac7804 BP |
1910 | bool CreateGrid(int numRows, int numCols, |
1911 | wxGridSelectionModes selmode = wxGridSelectCells); | |
23324ae1 FM |
1912 | |
1913 | /** | |
caac7804 | 1914 | Passes a pointer to a custom grid table to be used by the grid. |
3c4f71cc | 1915 | |
caac7804 BP |
1916 | This should be called after the grid constructor and before using the |
1917 | grid object. If @a takeOwnership is set to @true then the table will be | |
1918 | deleted by the wxGrid destructor. | |
3c4f71cc | 1919 | |
caac7804 BP |
1920 | Use this function instead of CreateGrid() when your application |
1921 | involves complex or non-string data or data sets that are too large to | |
1922 | fit wholly in memory. | |
23324ae1 | 1923 | */ |
caac7804 BP |
1924 | bool SetTable(wxGridTableBase* table, bool takeOwnership = false, |
1925 | wxGridSelectionModes selmode = wxGridSelectCells); | |
23324ae1 | 1926 | |
caac7804 | 1927 | //@} |
8b9ef005 | 1928 | |
3c4f71cc | 1929 | |
caac7804 BP |
1930 | /** |
1931 | @name Grid Line Formatting | |
1932 | */ | |
1933 | //@{ | |
1934 | ||
1935 | /** | |
1936 | Turns the drawing of grid lines on or off. | |
23324ae1 | 1937 | */ |
caac7804 | 1938 | void EnableGridLines(bool enable = true); |
23324ae1 FM |
1939 | |
1940 | /** | |
caac7804 | 1941 | Returns the pen used for vertical grid lines. |
3c4f71cc | 1942 | |
caac7804 BP |
1943 | This virtual function may be overridden in derived classes in order to |
1944 | change the appearance of individual grid lines for the given column | |
1945 | @a col. | |
23324ae1 | 1946 | |
caac7804 BP |
1947 | See GetRowGridLinePen() for an example. |
1948 | */ | |
1949 | virtual wxPen GetColGridLinePen(int col); | |
23324ae1 FM |
1950 | |
1951 | /** | |
caac7804 | 1952 | Returns the pen used for grid lines. |
23324ae1 | 1953 | |
caac7804 BP |
1954 | This virtual function may be overridden in derived classes in order to |
1955 | change the appearance of grid lines. Note that currently the pen width | |
1956 | must be 1. | |
3c4f71cc | 1957 | |
caac7804 BP |
1958 | @see GetColGridLinePen(), GetRowGridLinePen() |
1959 | */ | |
1960 | virtual wxPen GetDefaultGridLinePen(); | |
23324ae1 FM |
1961 | |
1962 | /** | |
caac7804 BP |
1963 | Returns the colour used for grid lines. |
1964 | ||
1965 | @see GetDefaultGridLinePen() | |
23324ae1 | 1966 | */ |
caac7804 | 1967 | wxColour GetGridLineColour() const; |
23324ae1 FM |
1968 | |
1969 | /** | |
caac7804 BP |
1970 | Returns the pen used for horizontal grid lines. |
1971 | ||
1972 | This virtual function may be overridden in derived classes in order to | |
1973 | change the appearance of individual grid line for the given @a row. | |
1974 | ||
1975 | Example: | |
1976 | @code | |
1977 | // in a grid displaying music notation, use a solid black pen between | |
1978 | // octaves (C0=row 127, C1=row 115 etc.) | |
1979 | wxPen MidiGrid::GetRowGridLinePen(int row) | |
1980 | { | |
1981 | if ( row % 12 == 7 ) | |
1982 | return wxPen(*wxBLACK, 1, wxSOLID); | |
1983 | else | |
1984 | return GetDefaultGridLinePen(); | |
1985 | } | |
1986 | @endcode | |
23324ae1 | 1987 | */ |
caac7804 | 1988 | virtual wxPen GetRowGridLinePen(int row); |
23324ae1 FM |
1989 | |
1990 | /** | |
caac7804 | 1991 | Returns @true if drawing of grid lines is turned on, @false otherwise. |
23324ae1 | 1992 | */ |
caac7804 | 1993 | bool GridLinesEnabled() const; |
23324ae1 FM |
1994 | |
1995 | /** | |
caac7804 | 1996 | Sets the colour used to draw grid lines. |
23324ae1 | 1997 | */ |
caac7804 BP |
1998 | void SetGridLineColour(const wxColour& colour); |
1999 | ||
2000 | //@} | |
2001 | ||
23324ae1 FM |
2002 | |
2003 | /** | |
caac7804 BP |
2004 | @name Label Values and Formatting |
2005 | */ | |
2006 | //@{ | |
23324ae1 FM |
2007 | |
2008 | /** | |
caac7804 BP |
2009 | Sets the arguments to the current column label alignment values. |
2010 | ||
2011 | Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE | |
2012 | or @c wxALIGN_RIGHT. | |
2013 | ||
2014 | Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or | |
2015 | @c wxALIGN_BOTTOM. | |
23324ae1 | 2016 | */ |
caac7804 | 2017 | void GetColLabelAlignment(int* horiz, int* vert) const; |
23324ae1 FM |
2018 | |
2019 | /** | |
caac7804 BP |
2020 | Returns the orientation of the column labels (either @c wxHORIZONTAL or |
2021 | @c wxVERTICAL). | |
23324ae1 | 2022 | */ |
caac7804 | 2023 | int GetColLabelTextOrientation() const; |
23324ae1 FM |
2024 | |
2025 | /** | |
caac7804 | 2026 | Returns the specified column label. |
7c913512 | 2027 | |
caac7804 BP |
2028 | The default grid table class provides column labels of the form |
2029 | A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can | |
2030 | override wxGridTableBase::GetColLabelValue() to provide your own | |
2031 | labels. | |
23324ae1 | 2032 | */ |
caac7804 | 2033 | wxString GetColLabelValue(int col) const; |
23324ae1 | 2034 | |
8b9ef005 | 2035 | /** |
caac7804 BP |
2036 | Returns the colour used for the background of row and column labels. |
2037 | */ | |
2038 | wxColour GetLabelBackgroundColour() const; | |
e54c96f1 | 2039 | |
caac7804 BP |
2040 | /** |
2041 | Returns the font used for row and column labels. | |
2042 | */ | |
2043 | wxFont GetLabelFont() const; | |
7c913512 | 2044 | |
caac7804 BP |
2045 | /** |
2046 | Returns the colour used for row and column label text. | |
8b9ef005 | 2047 | */ |
caac7804 | 2048 | wxColour GetLabelTextColour() const; |
7c913512 | 2049 | |
23324ae1 | 2050 | /** |
caac7804 | 2051 | Returns the alignment used for row labels. |
3c4f71cc | 2052 | |
caac7804 BP |
2053 | Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE |
2054 | or @c wxALIGN_RIGHT. | |
2055 | ||
2056 | Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or | |
2057 | @c wxALIGN_BOTTOM. | |
23324ae1 | 2058 | */ |
caac7804 | 2059 | void GetRowLabelAlignment(int* horiz, int* vert) const; |
23324ae1 FM |
2060 | |
2061 | /** | |
caac7804 | 2062 | Returns the specified row label. |
23324ae1 | 2063 | |
caac7804 BP |
2064 | The default grid table class provides numeric row labels. If you are |
2065 | using a custom grid table you can override | |
2066 | wxGridTableBase::GetRowLabelValue() to provide your own labels. | |
23324ae1 | 2067 | */ |
caac7804 | 2068 | wxString GetRowLabelValue(int row) const; |
23324ae1 FM |
2069 | |
2070 | /** | |
caac7804 BP |
2071 | Hides the column labels by calling SetColLabelSize() with a size of 0. |
2072 | Show labels again by calling that method with a width greater than 0. | |
23324ae1 | 2073 | */ |
caac7804 | 2074 | void HideColLabels(); |
23324ae1 FM |
2075 | |
2076 | /** | |
caac7804 | 2077 | Hides the row labels by calling SetRowLabelSize() with a size of 0. |
23324ae1 | 2078 | |
caac7804 BP |
2079 | The labels can be shown again by calling SetRowLabelSize() with a width |
2080 | greater than 0. | |
23324ae1 | 2081 | */ |
caac7804 | 2082 | void HideRowLabels(); |
23324ae1 FM |
2083 | |
2084 | /** | |
caac7804 | 2085 | Sets the horizontal and vertical alignment of column label text. |
23324ae1 | 2086 | |
caac7804 BP |
2087 | Horizontal alignment should be one of @c wxALIGN_LEFT, |
2088 | @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one | |
2089 | of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. | |
23324ae1 | 2090 | */ |
caac7804 | 2091 | void SetColLabelAlignment(int horiz, int vert); |
23324ae1 FM |
2092 | |
2093 | /** | |
caac7804 BP |
2094 | Sets the orientation of the column labels (either @c wxHORIZONTAL or |
2095 | @c wxVERTICAL). | |
8b9ef005 | 2096 | */ |
caac7804 | 2097 | void SetColLabelTextOrientation(int textOrientation); |
7c913512 | 2098 | |
23324ae1 | 2099 | /** |
caac7804 | 2100 | Set the value for the given column label. |
8b9ef005 | 2101 | |
caac7804 BP |
2102 | If you are using a custom grid table you must override |
2103 | wxGridTableBase::SetColLabelValue() for this to have any effect. | |
23324ae1 | 2104 | */ |
caac7804 | 2105 | void SetColLabelValue(int col, const wxString& value); |
23324ae1 FM |
2106 | |
2107 | /** | |
caac7804 | 2108 | Sets the background colour for row and column labels. |
23324ae1 | 2109 | */ |
caac7804 | 2110 | void SetLabelBackgroundColour(const wxColour& colour); |
23324ae1 | 2111 | |
8b9ef005 | 2112 | /** |
caac7804 BP |
2113 | Sets the font for row and column labels. |
2114 | */ | |
2115 | void SetLabelFont(const wxFont& font); | |
55f0bf1f | 2116 | |
8b9ef005 | 2117 | /** |
caac7804 BP |
2118 | Sets the colour for row and column label text. |
2119 | */ | |
2120 | void SetLabelTextColour(const wxColour& colour); | |
55f0bf1f | 2121 | |
8b9ef005 | 2122 | /** |
caac7804 | 2123 | Sets the horizontal and vertical alignment of row label text. |
7c913512 | 2124 | |
caac7804 BP |
2125 | Horizontal alignment should be one of @c wxALIGN_LEFT, |
2126 | @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one | |
2127 | of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. | |
8b9ef005 | 2128 | */ |
caac7804 | 2129 | void SetRowLabelAlignment(int horiz, int vert); |
7c913512 | 2130 | |
23324ae1 | 2131 | /** |
caac7804 | 2132 | Sets the value for the given row label. |
55f0bf1f | 2133 | |
caac7804 BP |
2134 | If you are using a derived grid table you must override |
2135 | wxGridTableBase::SetRowLabelValue() for this to have any effect. | |
8b9ef005 | 2136 | */ |
caac7804 | 2137 | void SetRowLabelValue(int row, const wxString& value); |
55f0bf1f | 2138 | |
8b9ef005 | 2139 | /** |
caac7804 | 2140 | Call this in order to make the column labels use a native look by using |
03faec76 | 2141 | wxRendererNative::DrawHeaderButton() internally. |
55f0bf1f | 2142 | |
caac7804 BP |
2143 | There is no equivalent method for drawing row columns as there is not |
2144 | native look for that. This option is useful when using wxGrid for | |
2145 | displaying tables and not as a spread-sheet. | |
ad805b9e | 2146 | |
03faec76 | 2147 | @see UseNativeColHeader() |
8b9ef005 | 2148 | */ |
caac7804 | 2149 | void SetUseNativeColLabels(bool native = true); |
55f0bf1f | 2150 | |
ad805b9e VZ |
2151 | /** |
2152 | Enable the use of native header window for column labels. | |
2153 | ||
2154 | If this function is called with @true argument, a wxHeaderCtrl is used | |
2155 | instead to display the column labels instead of drawing them in wxGrid | |
2156 | code itself. This has the advantage of making the grid look and feel | |
2157 | perfectly the same as native applications (using SetUseNativeColLabels() | |
2158 | the grid can be made to look more natively but it still doesn't feel | |
2159 | natively, notably the column resizing and dragging still works slightly | |
2160 | differently as it is implemented in wxWidgets itself) but results in | |
2161 | different behaviour for column and row headers, for which there is no | |
2162 | equivalent function, and, most importantly, is unsuitable for grids | |
2163 | with huge numbers of columns as wxHeaderCtrl doesn't support virtual | |
2164 | mode. Because of this, by default the grid does not use the native | |
2165 | header control but you should call this function to enable it if you | |
2166 | are using the grid to display tabular data and don't have thousands of | |
2167 | columns in it. | |
2168 | ||
4a07d706 VZ |
2169 | Another difference between the default behaviour and the native header |
2170 | behaviour is that the latter provides the user with a context menu | |
2171 | (which appears on right clicking the header) allowing to rearrange the | |
2172 | grid columns if CanDragColMove() returns @true. If you want to prevent | |
2173 | this from happening for some reason, you need to define a handler for | |
2174 | @c wxEVT_GRID_LABEL_RIGHT_CLICK event which simply does nothing (in | |
2175 | particular doesn't skip the event) as this will prevent the default | |
2176 | right click handling from working. | |
2177 | ||
2178 | Also note that currently @c wxEVT_GRID_LABEL_RIGHT_DCLICK event is not | |
2179 | generated for the column labels if the native columns header is used | |
2180 | (but this limitation could possibly be lifted in the future). | |
ad805b9e VZ |
2181 | */ |
2182 | void UseNativeColHeader(bool native = true); | |
2183 | ||
caac7804 | 2184 | //@} |
55f0bf1f | 2185 | |
55f0bf1f VZ |
2186 | |
2187 | /** | |
caac7804 | 2188 | @name Cell Formatting |
55f0bf1f | 2189 | |
caac7804 BP |
2190 | Note that wxGridCellAttr can be used alternatively to most of these |
2191 | methods. See the "Attributes Management" of wxGridTableBase. | |
2192 | */ | |
2193 | //@{ | |
23324ae1 FM |
2194 | |
2195 | /** | |
caac7804 BP |
2196 | Sets the arguments to the horizontal and vertical text alignment values |
2197 | for the grid cell at the specified location. | |
55f0bf1f | 2198 | |
caac7804 BP |
2199 | Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE |
2200 | or @c wxALIGN_RIGHT. | |
2201 | ||
2202 | Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or | |
2203 | @c wxALIGN_BOTTOM. | |
8b9ef005 | 2204 | */ |
caac7804 | 2205 | void GetCellAlignment(int row, int col, int* horiz, int* vert) const; |
55f0bf1f VZ |
2206 | |
2207 | /** | |
caac7804 | 2208 | Returns the background colour of the cell at the specified location. |
23324ae1 | 2209 | */ |
caac7804 | 2210 | wxColour GetCellBackgroundColour(int row, int col) const; |
23324ae1 FM |
2211 | |
2212 | /** | |
caac7804 BP |
2213 | Returns the font for text in the grid cell at the specified location. |
2214 | */ | |
2215 | wxFont GetCellFont(int row, int col) const; | |
55f0bf1f | 2216 | |
caac7804 BP |
2217 | /** |
2218 | Returns the text colour for the grid cell at the specified location. | |
23324ae1 | 2219 | */ |
caac7804 | 2220 | wxColour GetCellTextColour(int row, int col) const; |
23324ae1 FM |
2221 | |
2222 | /** | |
caac7804 BP |
2223 | Returns the default cell alignment. |
2224 | ||
2225 | Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE | |
2226 | or @c wxALIGN_RIGHT. | |
55f0bf1f | 2227 | |
caac7804 BP |
2228 | Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or |
2229 | @c wxALIGN_BOTTOM. | |
2230 | ||
2231 | @see SetDefaultCellAlignment() | |
8b9ef005 | 2232 | */ |
caac7804 | 2233 | void GetDefaultCellAlignment(int* horiz, int* vert) const; |
55f0bf1f | 2234 | |
8b9ef005 | 2235 | /** |
caac7804 | 2236 | Returns the current default background colour for grid cells. |
23324ae1 | 2237 | */ |
caac7804 | 2238 | wxColour GetDefaultCellBackgroundColour() const; |
23324ae1 | 2239 | |
9f7aee01 | 2240 | /** |
caac7804 | 2241 | Returns the current default font for grid cell text. |
8b9ef005 | 2242 | */ |
caac7804 | 2243 | wxFont GetDefaultCellFont() const; |
9f7aee01 | 2244 | |
8b9ef005 | 2245 | /** |
caac7804 | 2246 | Returns the current default colour for grid cell text. |
8b9ef005 | 2247 | */ |
caac7804 | 2248 | wxColour GetDefaultCellTextColour() const; |
9f7aee01 | 2249 | |
8b9ef005 | 2250 | /** |
caac7804 BP |
2251 | Sets the horizontal and vertical alignment for grid cell text at the |
2252 | specified location. | |
9f7aee01 | 2253 | |
caac7804 BP |
2254 | Horizontal alignment should be one of @c wxALIGN_LEFT, |
2255 | @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. | |
2256 | ||
2257 | Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE | |
2258 | or @c wxALIGN_BOTTOM. | |
2259 | */ | |
2260 | void SetCellAlignment(int row, int col, int horiz, int vert); | |
9f7aee01 | 2261 | /** |
caac7804 BP |
2262 | Sets the horizontal and vertical alignment for grid cell text at the |
2263 | specified location. | |
9f7aee01 | 2264 | |
caac7804 BP |
2265 | Horizontal alignment should be one of @c wxALIGN_LEFT, |
2266 | @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. | |
9f7aee01 | 2267 | |
caac7804 BP |
2268 | Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE |
2269 | or @c wxALIGN_BOTTOM. | |
8b9ef005 | 2270 | */ |
caac7804 | 2271 | void SetCellAlignment(int align, int row, int col); |
9f7aee01 | 2272 | |
23324ae1 | 2273 | /** |
caac7804 | 2274 | Set the background colour for the given cell or all cells by default. |
23324ae1 | 2275 | */ |
caac7804 | 2276 | void SetCellBackgroundColour(int row, int col, const wxColour& colour); |
23324ae1 FM |
2277 | |
2278 | /** | |
caac7804 BP |
2279 | Sets the font for text in the grid cell at the specified location. |
2280 | */ | |
2281 | void SetCellFont(int row, int col, const wxFont& font); | |
8b9ef005 | 2282 | |
caac7804 BP |
2283 | /** |
2284 | Sets the text colour for the given cell. | |
2285 | */ | |
2286 | void SetCellTextColour(int row, int col, const wxColour& colour); | |
2287 | /** | |
2288 | Sets the text colour for the given cell. | |
2289 | */ | |
2290 | void SetCellTextColour(const wxColour& val, int row, int col); | |
2291 | /** | |
2292 | Sets the text colour for all cells by default. | |
2293 | */ | |
2294 | void SetCellTextColour(const wxColour& colour); | |
8b9ef005 | 2295 | |
caac7804 BP |
2296 | /** |
2297 | Sets the default horizontal and vertical alignment for grid cell text. | |
2298 | ||
2299 | Horizontal alignment should be one of @c wxALIGN_LEFT, | |
2300 | @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one | |
2301 | of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. | |
23324ae1 | 2302 | */ |
caac7804 | 2303 | void SetDefaultCellAlignment(int horiz, int vert); |
23324ae1 FM |
2304 | |
2305 | /** | |
caac7804 | 2306 | Sets the default background colour for grid cells. |
23324ae1 | 2307 | */ |
caac7804 | 2308 | void SetDefaultCellBackgroundColour(const wxColour& colour); |
23324ae1 FM |
2309 | |
2310 | /** | |
caac7804 BP |
2311 | Sets the default font to be used for grid cell text. |
2312 | */ | |
2313 | void SetDefaultCellFont(const wxFont& font); | |
8b9ef005 | 2314 | |
caac7804 BP |
2315 | /** |
2316 | Sets the current default colour for grid cell text. | |
23324ae1 | 2317 | */ |
caac7804 BP |
2318 | void SetDefaultCellTextColour(const wxColour& colour); |
2319 | ||
2320 | //@} | |
2321 | ||
2322 | ||
2323 | /** | |
2324 | @name Cell Values, Editors, and Renderers | |
2325 | ||
2326 | Note that wxGridCellAttr can be used alternatively to most of these | |
2327 | methods. See the "Attributes Management" of wxGridTableBase. | |
2328 | */ | |
2329 | //@{ | |
23324ae1 FM |
2330 | |
2331 | /** | |
caac7804 BP |
2332 | Returns @true if the in-place edit control for the current grid cell |
2333 | can be used and @false otherwise. | |
2334 | ||
2335 | This function always returns @false for the read-only cells. | |
23324ae1 | 2336 | */ |
caac7804 | 2337 | bool CanEnableCellControl() const; |
23324ae1 FM |
2338 | |
2339 | /** | |
caac7804 | 2340 | Disables in-place editing of grid cells. |
8b9ef005 | 2341 | |
caac7804 BP |
2342 | Equivalent to calling EnableCellEditControl(@false). |
2343 | */ | |
2344 | void DisableCellEditControl(); | |
8b9ef005 | 2345 | |
caac7804 BP |
2346 | /** |
2347 | Enables or disables in-place editing of grid cell data. | |
2348 | ||
2349 | The grid will issue either a @c wxEVT_GRID_EDITOR_SHOWN or | |
2350 | @c wxEVT_GRID_EDITOR_HIDDEN event. | |
23324ae1 | 2351 | */ |
caac7804 | 2352 | void EnableCellEditControl(bool enable = true); |
23324ae1 FM |
2353 | |
2354 | /** | |
caac7804 BP |
2355 | Makes the grid globally editable or read-only. |
2356 | ||
2357 | If the edit argument is @false this function sets the whole grid as | |
2358 | read-only. If the argument is @true the grid is set to the default | |
2359 | state where cells may be editable. In the default state you can set | |
2360 | single grid cells and whole rows and columns to be editable or | |
2361 | read-only via wxGridCellAttr::SetReadOnly(). For single cells you | |
2362 | can also use the shortcut function SetReadOnly(). | |
2363 | ||
2364 | For more information about controlling grid cell attributes see the | |
2365 | wxGridCellAttr class and the @ref overview_grid. | |
23324ae1 | 2366 | */ |
caac7804 | 2367 | void EnableEditing(bool edit); |
23324ae1 FM |
2368 | |
2369 | /** | |
8b9ef005 | 2370 | Returns a pointer to the editor for the cell at the specified location. |
3c4f71cc | 2371 | |
caac7804 BP |
2372 | See wxGridCellEditor and the @ref overview_grid for more information |
2373 | about cell editors and renderers. | |
3c4f71cc | 2374 | |
8b9ef005 | 2375 | The caller must call DecRef() on the returned pointer. |
23324ae1 | 2376 | */ |
8b9ef005 | 2377 | wxGridCellEditor* GetCellEditor(int row, int col) const; |
23324ae1 | 2378 | |
8b9ef005 BP |
2379 | /** |
2380 | Returns a pointer to the renderer for the grid cell at the specified | |
2381 | location. | |
08dd9b5a | 2382 | |
caac7804 BP |
2383 | See wxGridCellRenderer and the @ref overview_grid for more information |
2384 | about cell editors and renderers. | |
8b9ef005 BP |
2385 | |
2386 | The caller must call DecRef() on the returned pointer. | |
23324ae1 | 2387 | */ |
8b9ef005 | 2388 | wxGridCellRenderer* GetCellRenderer(int row, int col) const; |
23324ae1 FM |
2389 | |
2390 | /** | |
caac7804 | 2391 | Returns the string contained in the cell at the specified location. |
23324ae1 | 2392 | |
caac7804 BP |
2393 | For simple applications where a grid object automatically uses a |
2394 | default grid table of string values you use this function together with | |
2395 | SetCellValue() to access cell values. For more complex applications | |
2396 | where you have derived your own grid table class that contains various | |
2397 | data types (e.g. numeric, boolean or user-defined custom types) then | |
2398 | you only use this function for those cells that contain string values. | |
2399 | ||
2400 | See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for | |
2401 | more information. | |
2402 | */ | |
2403 | wxString GetCellValue(int row, int col) const; | |
23324ae1 | 2404 | /** |
8b9ef005 | 2405 | Returns the string contained in the cell at the specified location. |
08dd9b5a | 2406 | |
8b9ef005 BP |
2407 | For simple applications where a grid object automatically uses a |
2408 | default grid table of string values you use this function together with | |
2409 | SetCellValue() to access cell values. For more complex applications | |
2410 | where you have derived your own grid table class that contains various | |
2411 | data types (e.g. numeric, boolean or user-defined custom types) then | |
2412 | you only use this function for those cells that contain string values. | |
2413 | ||
caac7804 BP |
2414 | See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for |
2415 | more information. | |
23324ae1 | 2416 | */ |
882678eb | 2417 | wxString GetCellValue(const wxGridCellCoords& coords) const; |
23324ae1 FM |
2418 | |
2419 | /** | |
caac7804 BP |
2420 | Returns a pointer to the current default grid cell editor. |
2421 | ||
2422 | See wxGridCellEditor and the @ref overview_grid for more information | |
2423 | about cell editors and renderers. | |
23324ae1 | 2424 | */ |
caac7804 | 2425 | wxGridCellEditor* GetDefaultEditor() const; |
23324ae1 FM |
2426 | |
2427 | /** | |
caac7804 | 2428 | Returns the default editor for the specified cell. |
08dd9b5a | 2429 | |
caac7804 BP |
2430 | The base class version returns the editor appropriate for the current |
2431 | cell type but this method may be overridden in the derived classes to | |
2432 | use custom editors for some cells by default. | |
8b9ef005 | 2433 | |
caac7804 BP |
2434 | Notice that the same may be achieved in a usually simpler way by |
2435 | associating a custom editor with the given cell or cells. | |
23324ae1 | 2436 | |
caac7804 BP |
2437 | The caller must call DecRef() on the returned pointer. |
2438 | */ | |
2439 | virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; | |
23324ae1 | 2440 | /** |
caac7804 | 2441 | Returns the default editor for the specified cell. |
08dd9b5a | 2442 | |
caac7804 BP |
2443 | The base class version returns the editor appropriate for the current |
2444 | cell type but this method may be overridden in the derived classes to | |
2445 | use custom editors for some cells by default. | |
8b9ef005 | 2446 | |
caac7804 BP |
2447 | Notice that the same may be achieved in a usually simpler way by |
2448 | associating a custom editor with the given cell or cells. | |
23324ae1 | 2449 | |
caac7804 | 2450 | The caller must call DecRef() on the returned pointer. |
23324ae1 | 2451 | */ |
caac7804 | 2452 | wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const; |
23324ae1 FM |
2453 | |
2454 | /** | |
caac7804 BP |
2455 | Returns the default editor for the cells containing values of the given |
2456 | type. | |
55f0bf1f | 2457 | |
caac7804 BP |
2458 | The base class version returns the editor which was associated with the |
2459 | specified @a typeName when it was registered RegisterDataType() but | |
2460 | this function may be overridden to return something different. This | |
2461 | allows to override an editor used for one of the standard types. | |
2462 | ||
2463 | The caller must call DecRef() on the returned pointer. | |
23324ae1 | 2464 | */ |
caac7804 | 2465 | virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; |
23324ae1 FM |
2466 | |
2467 | /** | |
caac7804 | 2468 | Returns a pointer to the current default grid cell renderer. |
8b9ef005 | 2469 | |
caac7804 BP |
2470 | See wxGridCellRenderer and the @ref overview_grid for more information |
2471 | about cell editors and renderers. | |
2472 | ||
2473 | The caller must call DecRef() on the returned pointer. | |
23324ae1 | 2474 | */ |
caac7804 | 2475 | wxGridCellRenderer* GetDefaultRenderer() const; |
23324ae1 | 2476 | |
9f7aee01 | 2477 | /** |
caac7804 BP |
2478 | Returns the default renderer for the given cell. |
2479 | ||
2480 | The base class version returns the renderer appropriate for the current | |
2481 | cell type but this method may be overridden in the derived classes to | |
2482 | use custom renderers for some cells by default. | |
2483 | ||
2484 | The caller must call DecRef() on the returned pointer. | |
8b9ef005 | 2485 | */ |
caac7804 | 2486 | virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; |
9f7aee01 | 2487 | |
8b9ef005 | 2488 | /** |
caac7804 BP |
2489 | Returns the default renderer for the cell containing values of the |
2490 | given type. | |
9f7aee01 | 2491 | |
caac7804 | 2492 | @see GetDefaultEditorForType() |
8b9ef005 | 2493 | */ |
caac7804 | 2494 | virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; |
08dd9b5a | 2495 | |
8b9ef005 | 2496 | /** |
caac7804 | 2497 | Hides the in-place cell edit control. |
23324ae1 | 2498 | */ |
caac7804 | 2499 | void HideCellEditControl(); |
23324ae1 FM |
2500 | |
2501 | /** | |
caac7804 | 2502 | Returns @true if the in-place edit control is currently enabled. |
8b9ef005 | 2503 | */ |
caac7804 | 2504 | bool IsCellEditControlEnabled() const; |
3c4f71cc | 2505 | |
8b9ef005 | 2506 | /** |
caac7804 | 2507 | Returns @true if the current cell is read-only. |
3c4f71cc | 2508 | |
caac7804 | 2509 | @see SetReadOnly(), IsReadOnly() |
23324ae1 | 2510 | */ |
caac7804 | 2511 | bool IsCurrentCellReadOnly() const; |
23324ae1 FM |
2512 | |
2513 | /** | |
caac7804 BP |
2514 | Returns @false if the whole grid has been set as read-only or @true |
2515 | otherwise. | |
2516 | ||
2517 | See EnableEditing() for more information about controlling the editing | |
2518 | status of grid cells. | |
8b9ef005 | 2519 | */ |
caac7804 | 2520 | bool IsEditable() const; |
23324ae1 | 2521 | |
8b9ef005 | 2522 | /** |
caac7804 | 2523 | Returns @true if the cell at the specified location can't be edited. |
55f0bf1f | 2524 | |
caac7804 | 2525 | @see SetReadOnly(), IsCurrentCellReadOnly() |
23324ae1 | 2526 | */ |
caac7804 | 2527 | bool IsReadOnly(int row, int col) const; |
23324ae1 FM |
2528 | |
2529 | /** | |
caac7804 | 2530 | Register a new data type. |
08dd9b5a | 2531 | |
caac7804 BP |
2532 | The data types allow to naturally associate specific renderers and |
2533 | editors to the cells containing values of the given type. For example, | |
2534 | the grid automatically registers a data type with the name | |
2535 | @c wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and | |
2536 | wxGridCellTextEditor as its renderer and editor respectively -- this is | |
2537 | the data type used by all the cells of the default wxGridStringTable, | |
2538 | so this renderer and editor are used by default for all grid cells. | |
8b9ef005 | 2539 | |
caac7804 BP |
2540 | However if a custom table returns @c wxGRID_VALUE_BOOL from its |
2541 | wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and | |
2542 | wxGridCellBoolEditor are used for it because the grid also registers a | |
2543 | boolean data type with this name. | |
8b9ef005 | 2544 | |
caac7804 BP |
2545 | And as this mechanism is completely generic, you may register your own |
2546 | data types using your own custom renderers and editors. Just remember | |
2547 | that the table must identify a cell as being of the given type for them | |
2548 | to be used for this cell. | |
2549 | ||
2550 | @param typeName | |
2551 | Name of the new type. May be any string, but if the type name is | |
2552 | the same as the name of an already registered type, including one | |
2553 | of the standard ones (which are @c wxGRID_VALUE_STRING, @c | |
2554 | wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT | |
2555 | and @c wxGRID_VALUE_CHOICE), then the new registration information | |
2556 | replaces the previously used renderer and editor. | |
2557 | @param renderer | |
2558 | The renderer to use for the cells of this type. Its ownership is | |
2559 | taken by the grid, i.e. it will call DecRef() on this pointer when | |
2560 | it doesn't need it any longer. | |
2561 | @param editor | |
2562 | The editor to use for the cells of this type. Its ownership is also | |
2563 | taken by the grid. | |
23324ae1 | 2564 | */ |
caac7804 BP |
2565 | void RegisterDataType(const wxString& typeName, |
2566 | wxGridCellRenderer* renderer, | |
2567 | wxGridCellEditor* editor); | |
23324ae1 FM |
2568 | |
2569 | /** | |
caac7804 BP |
2570 | Sets the value of the current grid cell to the current in-place edit |
2571 | control value. | |
55f0bf1f | 2572 | |
caac7804 BP |
2573 | This is called automatically when the grid cursor moves from the |
2574 | current cell to a new cell. It is also a good idea to call this | |
2575 | function when closing a grid since any edits to the final cell location | |
2576 | will not be saved otherwise. | |
23324ae1 | 2577 | */ |
caac7804 | 2578 | void SaveEditControlValue(); |
23324ae1 FM |
2579 | |
2580 | /** | |
caac7804 | 2581 | Sets the editor for the grid cell at the specified location. |
55f0bf1f | 2582 | |
caac7804 | 2583 | The grid will take ownership of the pointer. |
8b9ef005 | 2584 | |
caac7804 BP |
2585 | See wxGridCellEditor and the @ref overview_grid for more information |
2586 | about cell editors and renderers. | |
23324ae1 | 2587 | */ |
caac7804 | 2588 | void SetCellEditor(int row, int col, wxGridCellEditor* editor); |
23324ae1 FM |
2589 | |
2590 | /** | |
caac7804 | 2591 | Sets the renderer for the grid cell at the specified location. |
55f0bf1f | 2592 | |
caac7804 | 2593 | The grid will take ownership of the pointer. |
8b9ef005 | 2594 | |
caac7804 BP |
2595 | See wxGridCellRenderer and the @ref overview_grid for more information |
2596 | about cell editors and renderers. | |
23324ae1 | 2597 | */ |
caac7804 | 2598 | void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer); |
23324ae1 FM |
2599 | |
2600 | /** | |
caac7804 | 2601 | Sets the string value for the cell at the specified location. |
55f0bf1f | 2602 | |
caac7804 BP |
2603 | For simple applications where a grid object automatically uses a |
2604 | default grid table of string values you use this function together with | |
2605 | GetCellValue() to access cell values. For more complex applications | |
2606 | where you have derived your own grid table class that contains various | |
2607 | data types (e.g. numeric, boolean or user-defined custom types) then | |
2608 | you only use this function for those cells that contain string values. | |
8b9ef005 | 2609 | |
caac7804 BP |
2610 | See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for |
2611 | more information. | |
23324ae1 | 2612 | */ |
caac7804 | 2613 | void SetCellValue(int row, int col, const wxString& s); |
23324ae1 | 2614 | /** |
caac7804 | 2615 | Sets the string value for the cell at the specified location. |
55f0bf1f | 2616 | |
caac7804 BP |
2617 | For simple applications where a grid object automatically uses a |
2618 | default grid table of string values you use this function together with | |
2619 | GetCellValue() to access cell values. For more complex applications | |
2620 | where you have derived your own grid table class that contains various | |
2621 | data types (e.g. numeric, boolean or user-defined custom types) then | |
2622 | you only use this function for those cells that contain string values. | |
23324ae1 | 2623 | |
caac7804 BP |
2624 | See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for |
2625 | more information. | |
23324ae1 | 2626 | */ |
caac7804 | 2627 | void SetCellValue(const wxGridCellCoords& coords, const wxString& s); |
23324ae1 | 2628 | /** |
caac7804 BP |
2629 | @deprecated Please use SetCellValue(int,int,const wxString&) or |
2630 | SetCellValue(const wxGridCellCoords&,const wxString&) | |
2631 | instead. | |
23324ae1 | 2632 | |
caac7804 | 2633 | Sets the string value for the cell at the specified location. |
23324ae1 | 2634 | |
caac7804 BP |
2635 | For simple applications where a grid object automatically uses a |
2636 | default grid table of string values you use this function together with | |
2637 | GetCellValue() to access cell values. For more complex applications | |
2638 | where you have derived your own grid table class that contains various | |
2639 | data types (e.g. numeric, boolean or user-defined custom types) then | |
2640 | you only use this function for those cells that contain string values. | |
2641 | ||
2642 | See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for | |
2643 | more information. | |
23324ae1 | 2644 | */ |
caac7804 | 2645 | void SetCellValue(const wxString& val, int row, int col); |
23324ae1 FM |
2646 | |
2647 | /** | |
caac7804 | 2648 | Sets the specified column to display boolean values. |
55f0bf1f | 2649 | |
caac7804 | 2650 | @see SetColFormatCustom() |
23324ae1 | 2651 | */ |
caac7804 | 2652 | void SetColFormatBool(int col); |
23324ae1 FM |
2653 | |
2654 | /** | |
caac7804 | 2655 | Sets the specified column to display data in a custom format. |
23324ae1 | 2656 | |
caac7804 BP |
2657 | This method provides an alternative to defining a custom grid table |
2658 | which would return @a typeName from its GetTypeName() method for the | |
2659 | cells in this column: while it doesn't really change the type of the | |
2660 | cells in this column, it does associate the renderer and editor used | |
2661 | for the cells of the specified type with them. | |
23324ae1 | 2662 | |
caac7804 BP |
2663 | See the @ref overview_grid for more information on working with custom |
2664 | data types. | |
23324ae1 | 2665 | */ |
caac7804 | 2666 | void SetColFormatCustom(int col, const wxString& typeName); |
23324ae1 FM |
2667 | |
2668 | /** | |
caac7804 BP |
2669 | Sets the specified column to display floating point values with the |
2670 | given width and precision. | |
55f0bf1f | 2671 | |
caac7804 | 2672 | @see SetColFormatCustom() |
23324ae1 | 2673 | */ |
caac7804 | 2674 | void SetColFormatFloat(int col, int width = -1, int precision = -1); |
23324ae1 FM |
2675 | |
2676 | /** | |
caac7804 | 2677 | Sets the specified column to display integer values. |
8b9ef005 | 2678 | |
caac7804 | 2679 | @see SetColFormatCustom() |
23324ae1 | 2680 | */ |
caac7804 | 2681 | void SetColFormatNumber(int col); |
23324ae1 FM |
2682 | |
2683 | /** | |
caac7804 | 2684 | Sets the default editor for grid cells. |
3c4f71cc | 2685 | |
caac7804 | 2686 | The grid will take ownership of the pointer. |
55f0bf1f | 2687 | |
caac7804 BP |
2688 | See wxGridCellEditor and the @ref overview_grid for more information |
2689 | about cell editors and renderers. | |
23324ae1 | 2690 | */ |
caac7804 | 2691 | void SetDefaultEditor(wxGridCellEditor* editor); |
23324ae1 FM |
2692 | |
2693 | /** | |
caac7804 | 2694 | Sets the default renderer for grid cells. |
8b9ef005 | 2695 | |
caac7804 | 2696 | The grid will take ownership of the pointer. |
8b9ef005 | 2697 | |
caac7804 BP |
2698 | See wxGridCellRenderer and the @ref overview_grid for more information |
2699 | about cell editors and renderers. | |
23324ae1 | 2700 | */ |
caac7804 | 2701 | void SetDefaultRenderer(wxGridCellRenderer* renderer); |
23324ae1 FM |
2702 | |
2703 | /** | |
caac7804 | 2704 | Makes the cell at the specified location read-only or editable. |
08dd9b5a | 2705 | |
caac7804 | 2706 | @see IsReadOnly() |
23324ae1 | 2707 | */ |
caac7804 | 2708 | void SetReadOnly(int row, int col, bool isReadOnly = true); |
23324ae1 FM |
2709 | |
2710 | /** | |
caac7804 | 2711 | Displays the in-place cell edit control for the current cell. |
23324ae1 | 2712 | */ |
caac7804 | 2713 | void ShowCellEditControl(); |
23324ae1 | 2714 | |
caac7804 | 2715 | //@} |
23324ae1 | 2716 | |
23324ae1 | 2717 | |
23324ae1 | 2718 | /** |
caac7804 | 2719 | @name Column and Row Sizes |
82edfbe7 | 2720 | |
32bcf974 | 2721 | @see @ref overview_grid_resizing |
caac7804 BP |
2722 | */ |
2723 | //@{ | |
08dd9b5a | 2724 | |
caac7804 BP |
2725 | /** |
2726 | Automatically sets the height and width of all rows and columns to fit | |
2727 | their contents. | |
23324ae1 | 2728 | */ |
caac7804 | 2729 | void AutoSize(); |
23324ae1 FM |
2730 | |
2731 | /** | |
caac7804 | 2732 | Automatically adjusts width of the column to fit its label. |
23324ae1 | 2733 | */ |
caac7804 | 2734 | void AutoSizeColLabelSize(int col); |
23324ae1 FM |
2735 | |
2736 | /** | |
caac7804 BP |
2737 | Automatically sizes the column to fit its contents. If @a setAsMin is |
2738 | @true the calculated width will also be set as the minimal width for | |
2739 | the column. | |
2740 | */ | |
2741 | void AutoSizeColumn(int col, bool setAsMin = true); | |
23324ae1 FM |
2742 | |
2743 | /** | |
caac7804 BP |
2744 | Automatically sizes all columns to fit their contents. If @a setAsMin |
2745 | is @true the calculated widths will also be set as the minimal widths | |
2746 | for the columns. | |
23324ae1 | 2747 | */ |
caac7804 | 2748 | void AutoSizeColumns(bool setAsMin = true); |
23324ae1 FM |
2749 | |
2750 | /** | |
caac7804 BP |
2751 | Automatically sizes the row to fit its contents. If @a setAsMin is |
2752 | @true the calculated height will also be set as the minimal height for | |
2753 | the row. | |
23324ae1 | 2754 | */ |
caac7804 | 2755 | void AutoSizeRow(int row, bool setAsMin = true); |
23324ae1 | 2756 | |
23324ae1 | 2757 | /** |
caac7804 | 2758 | Automatically adjusts height of the row to fit its label. |
23324ae1 | 2759 | */ |
caac7804 | 2760 | void AutoSizeRowLabelSize(int col); |
23324ae1 | 2761 | |
23324ae1 | 2762 | /** |
caac7804 BP |
2763 | Automatically sizes all rows to fit their contents. If @a setAsMin is |
2764 | @true the calculated heights will also be set as the minimal heights | |
2765 | for the rows. | |
23324ae1 | 2766 | */ |
caac7804 | 2767 | void AutoSizeRows(bool setAsMin = true); |
23324ae1 | 2768 | |
23324ae1 | 2769 | /** |
caac7804 | 2770 | Returns the current height of the column labels. |
23324ae1 | 2771 | */ |
caac7804 | 2772 | int GetColLabelSize() const; |
23324ae1 FM |
2773 | |
2774 | /** | |
caac7804 | 2775 | Returns the minimal width to which a column may be resized. |
08dd9b5a | 2776 | |
caac7804 BP |
2777 | Use SetColMinimalAcceptableWidth() to change this value globally or |
2778 | SetColMinimalWidth() to do it for individual columns. | |
08dd9b5a | 2779 | |
caac7804 | 2780 | @see GetRowMinimalAcceptableHeight() |
23324ae1 | 2781 | */ |
caac7804 | 2782 | int GetColMinimalAcceptableWidth() const; |
23324ae1 FM |
2783 | |
2784 | /** | |
caac7804 | 2785 | Returns the width of the specified column. |
23324ae1 | 2786 | */ |
caac7804 | 2787 | int GetColSize(int col) const; |
23324ae1 | 2788 | |
fe79f76b VZ |
2789 | /** |
2790 | Returns @true if the specified column is not currently hidden. | |
2791 | */ | |
2792 | bool IsColShown(int col) const; | |
2793 | ||
23324ae1 | 2794 | /** |
caac7804 | 2795 | Returns the default height for column labels. |
23324ae1 | 2796 | */ |
caac7804 | 2797 | int GetDefaultColLabelSize() const; |
23324ae1 FM |
2798 | |
2799 | /** | |
caac7804 | 2800 | Returns the current default width for grid columns. |
23324ae1 | 2801 | */ |
caac7804 | 2802 | int GetDefaultColSize() const; |
23324ae1 FM |
2803 | |
2804 | /** | |
caac7804 BP |
2805 | Returns the default width for the row labels. |
2806 | */ | |
2807 | int GetDefaultRowLabelSize() const; | |
08dd9b5a | 2808 | |
caac7804 BP |
2809 | /** |
2810 | Returns the current default height for grid rows. | |
23324ae1 | 2811 | */ |
caac7804 | 2812 | int GetDefaultRowSize() const; |
23324ae1 | 2813 | |
23324ae1 | 2814 | /** |
caac7804 | 2815 | Returns the minimal size to which rows can be resized. |
08dd9b5a | 2816 | |
caac7804 BP |
2817 | Use SetRowMinimalAcceptableHeight() to change this value globally or |
2818 | SetRowMinimalHeight() to do it for individual cells. | |
23324ae1 | 2819 | |
caac7804 | 2820 | @see GetColMinimalAcceptableWidth() |
23324ae1 | 2821 | */ |
caac7804 | 2822 | int GetRowMinimalAcceptableHeight() const; |
23324ae1 FM |
2823 | |
2824 | /** | |
caac7804 | 2825 | Returns the current width of the row labels. |
23324ae1 | 2826 | */ |
caac7804 | 2827 | int GetRowLabelSize() const; |
23324ae1 FM |
2828 | |
2829 | /** | |
caac7804 | 2830 | Returns the height of the specified row. |
8b9ef005 | 2831 | */ |
caac7804 | 2832 | int GetRowSize(int row) const; |
08dd9b5a | 2833 | |
fe79f76b VZ |
2834 | /** |
2835 | Returns @true if the specified row is not currently hidden. | |
2836 | */ | |
2837 | bool IsRowShown(int row) const; | |
2838 | ||
8b9ef005 | 2839 | /** |
caac7804 | 2840 | Sets the height of the column labels. |
08dd9b5a | 2841 | |
caac7804 BP |
2842 | If @a height equals to @c wxGRID_AUTOSIZE then height is calculated |
2843 | automatically so that no label is truncated. Note that this could be | |
2844 | slow for a large table. | |
23324ae1 | 2845 | */ |
caac7804 | 2846 | void SetColLabelSize(int height); |
23324ae1 FM |
2847 | |
2848 | /** | |
caac7804 | 2849 | Sets the minimal @a width to which the user can resize columns. |
08dd9b5a | 2850 | |
caac7804 | 2851 | @see GetColMinimalAcceptableWidth() |
23324ae1 | 2852 | */ |
caac7804 | 2853 | void SetColMinimalAcceptableWidth(int width); |
23324ae1 FM |
2854 | |
2855 | /** | |
caac7804 | 2856 | Sets the minimal @a width for the specified column @a col. |
3c4f71cc | 2857 | |
caac7804 BP |
2858 | It is usually best to call this method during grid creation as calling |
2859 | it later will not resize the column to the given minimal width even if | |
2860 | it is currently narrower than it. | |
23324ae1 | 2861 | |
caac7804 BP |
2862 | @a width must be greater than the minimal acceptable column width as |
2863 | returned by GetColMinimalAcceptableWidth(). | |
23324ae1 | 2864 | */ |
caac7804 | 2865 | void SetColMinimalWidth(int col, int width); |
23324ae1 FM |
2866 | |
2867 | /** | |
caac7804 BP |
2868 | Sets the width of the specified column. |
2869 | ||
caac7804 BP |
2870 | @param col |
2871 | The column index. | |
2872 | @param width | |
009c7216 VZ |
2873 | The new column width in pixels, 0 to hide the column or -1 to fit |
2874 | the column width to its label width. | |
23324ae1 | 2875 | */ |
caac7804 | 2876 | void SetColSize(int col, int width); |
23324ae1 | 2877 | |
009c7216 VZ |
2878 | /** |
2879 | Hides the specified column. | |
2880 | ||
2881 | To show the column later you need to call SetColSize() with non-0 | |
2882 | width or ShowCol(). | |
2883 | ||
2884 | @param col | |
2885 | The column index. | |
2886 | */ | |
2887 | void HideCol(int col); | |
2888 | ||
2889 | /** | |
2890 | Shows the previously hidden column by resizing it to non-0 size. | |
2891 | ||
2892 | @see HideCol(), SetColSize() | |
2893 | */ | |
2894 | void ShowCol(int col); | |
2895 | ||
2896 | ||
23324ae1 | 2897 | /** |
caac7804 | 2898 | Sets the default width for columns in the grid. |
23324ae1 | 2899 | |
caac7804 BP |
2900 | This will only affect columns subsequently added to the grid unless |
2901 | @a resizeExistingCols is @true. | |
2902 | ||
2903 | If @a width is less than GetColMinimalAcceptableWidth(), then the | |
2904 | minimal acceptable width is used instead of it. | |
23324ae1 | 2905 | */ |
caac7804 | 2906 | void SetDefaultColSize(int width, bool resizeExistingCols = false); |
23324ae1 FM |
2907 | |
2908 | /** | |
caac7804 | 2909 | Sets the default height for rows in the grid. |
3c4f71cc | 2910 | |
caac7804 BP |
2911 | This will only affect rows subsequently added to the grid unless |
2912 | @a resizeExistingRows is @true. | |
2913 | ||
2914 | If @a height is less than GetRowMinimalAcceptableHeight(), then the | |
d13b34d3 | 2915 | minimal acceptable height is used instead of it. |
23324ae1 | 2916 | */ |
caac7804 | 2917 | void SetDefaultRowSize(int height, bool resizeExistingRows = false); |
23324ae1 FM |
2918 | |
2919 | /** | |
caac7804 BP |
2920 | Sets the width of the row labels. |
2921 | ||
2922 | If @a width equals @c wxGRID_AUTOSIZE then width is calculated | |
2923 | automatically so that no label is truncated. Note that this could be | |
2924 | slow for a large table. | |
23324ae1 | 2925 | */ |
caac7804 | 2926 | void SetRowLabelSize(int width); |
23324ae1 FM |
2927 | |
2928 | /** | |
caac7804 | 2929 | Sets the minimal row @a height used by default. |
8b9ef005 | 2930 | |
caac7804 | 2931 | See SetColMinimalAcceptableWidth() for more information. |
23324ae1 | 2932 | */ |
caac7804 | 2933 | void SetRowMinimalAcceptableHeight(int height); |
23324ae1 FM |
2934 | |
2935 | /** | |
caac7804 BP |
2936 | Sets the minimal @a height for the specified @a row. |
2937 | ||
2938 | See SetColMinimalWidth() for more information. | |
23324ae1 | 2939 | */ |
caac7804 | 2940 | void SetRowMinimalHeight(int row, int height); |
23324ae1 FM |
2941 | |
2942 | /** | |
caac7804 | 2943 | Sets the height of the specified row. |
08dd9b5a | 2944 | |
caac7804 | 2945 | See SetColSize() for more information. |
23324ae1 | 2946 | */ |
caac7804 BP |
2947 | void SetRowSize(int row, int height); |
2948 | ||
009c7216 VZ |
2949 | /** |
2950 | Hides the specified row. | |
2951 | ||
2952 | To show the row later you need to call SetRowSize() with non-0 | |
2953 | width or ShowRow(). | |
2954 | ||
2955 | @param col | |
2956 | The row index. | |
2957 | */ | |
2958 | void HideRow(int col); | |
2959 | ||
2960 | /** | |
2961 | Shows the previously hidden row by resizing it to non-0 size. | |
2962 | ||
2963 | @see HideRow(), SetRowSize() | |
2964 | */ | |
2965 | void ShowRow(int col); | |
2966 | ||
574e1c5a VZ |
2967 | /** |
2968 | Get size information for all columns at once. | |
2969 | ||
2970 | This method is useful when the information about all column widths | |
2971 | needs to be saved. The widths can be later restored using | |
2972 | SetColSizes(). | |
2973 | ||
2974 | @sa wxGridSizesInfo, GetRowSizes() | |
2975 | */ | |
2976 | wxGridSizesInfo GetColSizes() const; | |
2977 | ||
2978 | /** | |
2979 | Get size information for all row at once. | |
2980 | ||
2981 | @sa wxGridSizesInfo, GetColSizes() | |
2982 | */ | |
2983 | wxGridSizesInfo GetRowSizes() const; | |
2984 | ||
2985 | /** | |
2986 | Restore all columns sizes. | |
2987 | ||
2988 | This is usually called with wxGridSizesInfo object previously returned | |
2989 | by GetColSizes(). | |
2990 | ||
2991 | @sa SetRowSizes() | |
2992 | */ | |
2993 | void SetColSizes(const wxGridSizesInfo& sizeInfo); | |
2994 | ||
2995 | /** | |
2996 | Restore all rows sizes. | |
2997 | ||
2998 | @sa SetColSizes() | |
2999 | */ | |
3000 | void SetRowSizes(const wxGridSizesInfo& sizeInfo); | |
3001 | ||
ea99e8e3 VZ |
3002 | /** |
3003 | Set the size of the cell. | |
3004 | ||
3005 | Specifying a value of more than 1 in @a num_rows or @a num_cols will | |
3006 | make the cell at (@a row, @a col) span the block of the specified size, | |
3007 | covering the other cells which would be normally shown in it. Passing 1 | |
3008 | for both arguments resets the cell to normal appearance. | |
3009 | ||
3010 | @see GetCellSize() | |
3011 | ||
3012 | @param row | |
3013 | The row of the cell. | |
3014 | @param col | |
3015 | The column of the cell. | |
3016 | @param num_rows | |
3017 | Number of rows to be occupied by this cell, must be >= 1. | |
3018 | @param num_cols | |
3019 | Number of columns to be occupied by this cell, must be >= 1. | |
3020 | */ | |
3021 | void SetCellSize(int row, int col, int num_rows, int num_cols); | |
3022 | ||
3023 | /** | |
3024 | Get the size of the cell in number of cells covered by it. | |
3025 | ||
3026 | For normal cells, the function fills both @a num_rows and @a num_cols | |
3027 | with 1 and returns CellSpan_None. For cells which span multiple cells, i.e. | |
3028 | for which SetCellSize() had been called, the returned values are the | |
3029 | same ones as were passed to SetCellSize() call and the function return | |
3030 | value is CellSpan_Main. | |
3031 | ||
3032 | More unexpectedly, perhaps, the returned values may be @em negative for | |
3033 | the cells which are inside a span covered by a cell occupying multiple | |
3034 | rows or columns. They correspond to the offset of the main cell of the | |
3035 | span from the cell passed to this functions and the function returns | |
3036 | CellSpan_Inside value to indicate this. | |
3037 | ||
3038 | As an example, consider a 3*3 grid with the cell (1, 1) (the one in the | |
3039 | middle) having a span of 2 rows and 2 columns, i.e. the grid looks like | |
3040 | @code | |
3041 | +----+----+----+ | |
3042 | | | | | | |
3043 | +----+----+----+ | |
3044 | | | | | |
3045 | +----+ | | |
3046 | | | | | |
3047 | +----+----+----+ | |
3048 | @endcode | |
3049 | Then the function returns 2 and 2 in @a num_rows and @a num_cols for | |
3050 | the cell (1, 1) itself and -1 and -1 for the cell (2, 2) as well as -1 | |
3051 | and 0 for the cell (2, 1). | |
3052 | ||
3053 | @param row | |
3054 | The row of the cell. | |
3055 | @param col | |
3056 | The column of the cell. | |
3057 | @param num_rows | |
3058 | Pointer to variable receiving the number of rows, must not be @NULL. | |
3059 | @param num_cols | |
3060 | Pointer to variable receiving the number of columns, must not be | |
3061 | @NULL. | |
3062 | @return | |
3063 | The kind of this cell span (the return value is new in wxWidgets | |
3064 | 2.9.1, this function was void in previous wxWidgets versions). | |
3065 | */ | |
3066 | CellSpan GetCellSize( int row, int col, int *num_rows, int *num_cols ) const; | |
3067 | ||
3068 | /** | |
3069 | Get the number of rows and columns allocated for this cell. | |
3070 | ||
3071 | This overload doesn't return a CellSpan value but the values returned | |
3072 | may still be negative, see GetCellSize(int, int, int *, int *) for | |
3073 | details. | |
3074 | */ | |
3075 | wxSize GetCellSize(const wxGridCellCoords& coords); | |
3076 | ||
8b9ef005 | 3077 | //@} |
23324ae1 | 3078 | |
caac7804 | 3079 | |
23324ae1 | 3080 | /** |
caac7804 | 3081 | @name User-Resizing and Dragging |
82edfbe7 VZ |
3082 | |
3083 | Functions controlling various interactive mouse operations. | |
3084 | ||
3085 | By default, columns and rows can be resized by dragging the edges of | |
3086 | their labels (this can be disabled using DisableDragColSize() and | |
3087 | DisableDragRowSize() methods). And if grid line dragging is enabled with | |
3088 | EnableDragGridSize() they can also be resized by dragging the right or | |
3089 | bottom edge of the grid cells. | |
3090 | ||
3091 | Columns can also be moved to interactively change their order but this | |
3092 | needs to be explicitly enabled with EnableDragColMove(). | |
caac7804 BP |
3093 | */ |
3094 | //@{ | |
08dd9b5a | 3095 | |
caac7804 BP |
3096 | /** |
3097 | Return @true if the dragging of cells is enabled or @false otherwise. | |
23324ae1 | 3098 | */ |
caac7804 | 3099 | bool CanDragCell() const; |
23324ae1 FM |
3100 | |
3101 | /** | |
caac7804 | 3102 | Returns @true if columns can be moved by dragging with the mouse. |
08dd9b5a | 3103 | |
caac7804 | 3104 | Columns can be moved by dragging on their labels. |
23324ae1 | 3105 | */ |
caac7804 | 3106 | bool CanDragColMove() const; |
23324ae1 FM |
3107 | |
3108 | /** | |
82edfbe7 VZ |
3109 | Returns @true if the given column can be resized by dragging with the |
3110 | mouse. | |
8b9ef005 | 3111 | |
82edfbe7 VZ |
3112 | This function returns @true if resizing the columns interactively is |
3113 | globally enabled, i.e. if DisableDragColSize() hadn't been called, and | |
3114 | if this column wasn't explicitly marked as non-resizable with | |
3115 | DisableColResize(). | |
23324ae1 | 3116 | */ |
82edfbe7 | 3117 | bool CanDragColSize(int col) const; |
23324ae1 FM |
3118 | |
3119 | /** | |
caac7804 BP |
3120 | Return @true if the dragging of grid lines to resize rows and columns |
3121 | is enabled or @false otherwise. | |
3122 | */ | |
3123 | bool CanDragGridSize() const; | |
3124 | ||
3125 | /** | |
82edfbe7 VZ |
3126 | Returns @true if the given row can be resized by dragging with the |
3127 | mouse. | |
caac7804 | 3128 | |
82edfbe7 | 3129 | This is the same as CanDragColSize() but for rows. |
caac7804 | 3130 | */ |
82edfbe7 VZ |
3131 | bool CanDragRowSize(int row) const; |
3132 | ||
3133 | /** | |
3134 | Disable interactive resizing of the specified column. | |
3135 | ||
3136 | This method allows to disable resizing of an individual column in a | |
3137 | grid where the columns are otherwise resizable (which is the case by | |
3138 | default). | |
3139 | ||
3140 | Notice that currently there is no way to make some columns resizable in | |
3141 | a grid where columns can't be resized by default as there doesn't seem | |
3142 | to be any need for this in practice. There is also no way to make the | |
d13b34d3 | 3143 | column marked as fixed using this method resizable again because it is |
82edfbe7 VZ |
3144 | supposed that fixed columns are used for static parts of the grid and |
3145 | so should remain fixed during the entire grid lifetime. | |
3146 | ||
3147 | Also notice that disabling interactive column resizing will not prevent | |
3148 | the program from changing the column size. | |
3149 | ||
3150 | @see EnableDragColSize() | |
3151 | */ | |
3152 | void DisableColResize(int col); | |
3153 | ||
3154 | /** | |
3155 | Disable interactive resizing of the specified row. | |
3156 | ||
3157 | This is the same as DisableColResize() but for rows. | |
3158 | ||
3159 | @see EnableDragRowSize() | |
3160 | */ | |
3161 | void DisableRowResize(int row); | |
caac7804 BP |
3162 | |
3163 | /** | |
3164 | Disables column moving by dragging with the mouse. | |
3165 | ||
3166 | Equivalent to passing @false to EnableDragColMove(). | |
3167 | */ | |
3168 | void DisableDragColMove(); | |
3169 | ||
3170 | /** | |
3171 | Disables column sizing by dragging with the mouse. | |
3172 | ||
3173 | Equivalent to passing @false to EnableDragColSize(). | |
3174 | */ | |
3175 | void DisableDragColSize(); | |
3176 | ||
3177 | /** | |
3178 | Disable mouse dragging of grid lines to resize rows and columns. | |
3179 | ||
3180 | Equivalent to passing @false to EnableDragGridSize() | |
3181 | */ | |
3182 | void DisableDragGridSize(); | |
3183 | ||
3184 | /** | |
3185 | Disables row sizing by dragging with the mouse. | |
3186 | ||
3187 | Equivalent to passing @false to EnableDragRowSize(). | |
3188 | */ | |
3189 | void DisableDragRowSize(); | |
3190 | ||
3191 | /** | |
3192 | Enables or disables cell dragging with the mouse. | |
3193 | */ | |
3194 | void EnableDragCell(bool enable = true); | |
3195 | ||
3196 | /** | |
3197 | Enables or disables column moving by dragging with the mouse. | |
3198 | */ | |
3199 | void EnableDragColMove(bool enable = true); | |
3200 | ||
3201 | /** | |
3202 | Enables or disables column sizing by dragging with the mouse. | |
82edfbe7 VZ |
3203 | |
3204 | @see DisableColResize() | |
caac7804 BP |
3205 | */ |
3206 | void EnableDragColSize(bool enable = true); | |
3207 | ||
3208 | /** | |
3209 | Enables or disables row and column resizing by dragging gridlines with | |
3210 | the mouse. | |
3211 | */ | |
3212 | void EnableDragGridSize(bool enable = true); | |
3213 | ||
3214 | /** | |
3215 | Enables or disables row sizing by dragging with the mouse. | |
82edfbe7 VZ |
3216 | |
3217 | @see DisableRowResize() | |
caac7804 BP |
3218 | */ |
3219 | void EnableDragRowSize(bool enable = true); | |
3220 | ||
3221 | /** | |
3222 | Returns the column ID of the specified column position. | |
3223 | */ | |
3224 | int GetColAt(int colPos) const; | |
3225 | ||
3226 | /** | |
3227 | Returns the position of the specified column. | |
3228 | */ | |
3229 | int GetColPos(int colID) const; | |
3230 | ||
3231 | /** | |
3232 | Sets the position of the specified column. | |
3233 | */ | |
3234 | void SetColPos(int colID, int newPos); | |
3235 | ||
31ec8b4e VZ |
3236 | /** |
3237 | Sets the positions of all columns at once. | |
3238 | ||
3239 | This method takes an array containing the indices of the columns in | |
3240 | their display order, i.e. uses the same convention as | |
3241 | wxHeaderCtrl::SetColumnsOrder(). | |
f8f31de6 | 3242 | */ |
31ec8b4e VZ |
3243 | void SetColumnsOrder(const wxArrayInt& order); |
3244 | ||
009c7216 VZ |
3245 | /** |
3246 | Resets the position of the columns to the default. | |
f8f31de6 | 3247 | */ |
009c7216 VZ |
3248 | void ResetColPos(); |
3249 | ||
caac7804 BP |
3250 | //@} |
3251 | ||
3252 | ||
3253 | /** | |
3254 | @name Cursor Movement | |
f8f31de6 | 3255 | */ |
caac7804 BP |
3256 | //@{ |
3257 | ||
3258 | /** | |
3259 | Returns the current grid cell column position. | |
3260 | */ | |
3261 | int GetGridCursorCol() const; | |
3262 | ||
3263 | /** | |
3264 | Returns the current grid cell row position. | |
3265 | */ | |
3266 | int GetGridCursorRow() const; | |
3267 | ||
3268 | /** | |
3269 | Make the given cell current and ensure it is visible. | |
3270 | ||
3271 | This method is equivalent to calling MakeCellVisible() and | |
3272 | SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL | |
3273 | event is generated by it and the selected cell doesn't change if the | |
3274 | event is vetoed. | |
3275 | */ | |
3276 | void GoToCell(int row, int col); | |
3277 | /** | |
3278 | Make the given cell current and ensure it is visible. | |
3279 | ||
3280 | This method is equivalent to calling MakeCellVisible() and | |
3281 | SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL | |
3282 | event is generated by it and the selected cell doesn't change if the | |
3283 | event is vetoed. | |
3284 | */ | |
3285 | void GoToCell(const wxGridCellCoords& coords); | |
3286 | ||
3287 | /** | |
3288 | Moves the grid cursor down by one row. | |
3289 | ||
3290 | If a block of cells was previously selected it will expand if the | |
3291 | argument is @true or be cleared if the argument is @false. | |
3292 | */ | |
3293 | bool MoveCursorDown(bool expandSelection); | |
3294 | ||
3295 | /** | |
3296 | Moves the grid cursor down in the current column such that it skips to | |
3297 | the beginning or end of a block of non-empty cells. | |
3298 | ||
3299 | If a block of cells was previously selected it will expand if the | |
3300 | argument is @true or be cleared if the argument is @false. | |
3301 | */ | |
3302 | bool MoveCursorDownBlock(bool expandSelection); | |
3303 | ||
3304 | /** | |
3305 | Moves the grid cursor left by one column. | |
08dd9b5a | 3306 | |
8b9ef005 BP |
3307 | If a block of cells was previously selected it will expand if the |
3308 | argument is @true or be cleared if the argument is @false. | |
23324ae1 | 3309 | */ |
8b9ef005 | 3310 | bool MoveCursorLeft(bool expandSelection); |
23324ae1 FM |
3311 | |
3312 | /** | |
8b9ef005 BP |
3313 | Moves the grid cursor left in the current row such that it skips to the |
3314 | beginning or end of a block of non-empty cells. | |
3315 | ||
3316 | If a block of cells was previously selected it will expand if the | |
3317 | argument is @true or be cleared if the argument is @false. | |
23324ae1 | 3318 | */ |
8b9ef005 | 3319 | bool MoveCursorLeftBlock(bool expandSelection); |
23324ae1 FM |
3320 | |
3321 | /** | |
8b9ef005 | 3322 | Moves the grid cursor right by one column. |
08dd9b5a | 3323 | |
8b9ef005 BP |
3324 | If a block of cells was previously selected it will expand if the |
3325 | argument is @true or be cleared if the argument is @false. | |
23324ae1 | 3326 | */ |
8b9ef005 | 3327 | bool MoveCursorRight(bool expandSelection); |
23324ae1 FM |
3328 | |
3329 | /** | |
8b9ef005 BP |
3330 | Moves the grid cursor right in the current row such that it skips to |
3331 | the beginning or end of a block of non-empty cells. | |
08dd9b5a | 3332 | |
8b9ef005 BP |
3333 | If a block of cells was previously selected it will expand if the |
3334 | argument is @true or be cleared if the argument is @false. | |
23324ae1 | 3335 | */ |
8b9ef005 | 3336 | bool MoveCursorRightBlock(bool expandSelection); |
23324ae1 | 3337 | |
23324ae1 | 3338 | /** |
8b9ef005 BP |
3339 | Moves the grid cursor up by one row. |
3340 | ||
3341 | If a block of cells was previously selected it will expand if the | |
3342 | argument is @true or be cleared if the argument is @false. | |
23324ae1 | 3343 | */ |
8b9ef005 | 3344 | bool MoveCursorUp(bool expandSelection); |
23324ae1 FM |
3345 | |
3346 | /** | |
8b9ef005 BP |
3347 | Moves the grid cursor up in the current column such that it skips to |
3348 | the beginning or end of a block of non-empty cells. | |
3c4f71cc | 3349 | |
8b9ef005 BP |
3350 | If a block of cells was previously selected it will expand if the |
3351 | argument is @true or be cleared if the argument is @false. | |
23324ae1 | 3352 | */ |
8b9ef005 | 3353 | bool MoveCursorUpBlock(bool expandSelection); |
23324ae1 FM |
3354 | |
3355 | /** | |
8b9ef005 BP |
3356 | Moves the grid cursor down by some number of rows so that the previous |
3357 | bottom visible row becomes the top visible row. | |
3358 | */ | |
3359 | bool MovePageDown(); | |
3c4f71cc | 3360 | |
8b9ef005 BP |
3361 | /** |
3362 | Moves the grid cursor up by some number of rows so that the previous | |
3363 | top visible row becomes the bottom visible row. | |
23324ae1 | 3364 | */ |
8b9ef005 | 3365 | bool MovePageUp(); |
23324ae1 FM |
3366 | |
3367 | /** | |
caac7804 | 3368 | Set the grid cursor to the specified cell. |
08dd9b5a | 3369 | |
caac7804 BP |
3370 | The grid cursor indicates the current cell and can be moved by the user |
3371 | using the arrow keys or the mouse. | |
8b9ef005 | 3372 | |
caac7804 BP |
3373 | Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and |
3374 | if the event handler vetoes this event, the cursor is not moved. | |
8b9ef005 | 3375 | |
caac7804 BP |
3376 | This function doesn't make the target call visible, use GoToCell() to |
3377 | do this. | |
23324ae1 | 3378 | */ |
caac7804 | 3379 | void SetGridCursor(int row, int col); |
23324ae1 | 3380 | /** |
caac7804 | 3381 | Set the grid cursor to the specified cell. |
23324ae1 | 3382 | |
caac7804 BP |
3383 | The grid cursor indicates the current cell and can be moved by the user |
3384 | using the arrow keys or the mouse. | |
bb778cae | 3385 | |
caac7804 BP |
3386 | Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and |
3387 | if the event handler vetoes this event, the cursor is not moved. | |
8b9ef005 | 3388 | |
caac7804 BP |
3389 | This function doesn't make the target call visible, use GoToCell() to |
3390 | do this. | |
23324ae1 | 3391 | */ |
caac7804 BP |
3392 | void SetGridCursor(const wxGridCellCoords& coords); |
3393 | ||
8b9ef005 | 3394 | //@} |
23324ae1 | 3395 | |
8b9ef005 | 3396 | |
caac7804 BP |
3397 | /** |
3398 | @name User Selection | |
3399 | */ | |
3400 | //@{ | |
8b9ef005 | 3401 | |
caac7804 BP |
3402 | /** |
3403 | Deselects all cells that are currently selected. | |
23324ae1 | 3404 | */ |
caac7804 | 3405 | void ClearSelection(); |
23324ae1 FM |
3406 | |
3407 | /** | |
caac7804 | 3408 | Returns an array of individually selected cells. |
08dd9b5a | 3409 | |
caac7804 BP |
3410 | Notice that this array does @em not contain all the selected cells in |
3411 | general as it doesn't include the cells selected as part of column, row | |
3412 | or block selection. You must use this method, GetSelectedCols(), | |
3413 | GetSelectedRows() and GetSelectionBlockTopLeft() and | |
3414 | GetSelectionBlockBottomRight() methods to obtain the entire selection | |
3415 | in general. | |
08dd9b5a | 3416 | |
caac7804 BP |
3417 | Please notice this behaviour is by design and is needed in order to |
3418 | support grids of arbitrary size (when an entire column is selected in | |
3419 | a grid with a million of columns, we don't want to create an array with | |
3420 | a million of entries in this function, instead it returns an empty | |
3421 | array and GetSelectedCols() returns an array containing one element). | |
23324ae1 | 3422 | */ |
caac7804 | 3423 | wxGridCellCoordsArray GetSelectedCells() const; |
23324ae1 FM |
3424 | |
3425 | /** | |
caac7804 | 3426 | Returns an array of selected columns. |
08dd9b5a | 3427 | |
caac7804 BP |
3428 | Please notice that this method alone is not sufficient to find all the |
3429 | selected columns as it contains only the columns which were | |
3430 | individually selected but not those being part of the block selection | |
3431 | or being selected in virtue of all of their cells being selected | |
3432 | individually, please see GetSelectedCells() for more details. | |
23324ae1 | 3433 | */ |
caac7804 | 3434 | wxArrayInt GetSelectedCols() const; |
23324ae1 FM |
3435 | |
3436 | /** | |
caac7804 | 3437 | Returns an array of selected rows. |
23324ae1 | 3438 | |
caac7804 BP |
3439 | Please notice that this method alone is not sufficient to find all the |
3440 | selected rows as it contains only the rows which were individually | |
3441 | selected but not those being part of the block selection or being | |
3442 | selected in virtue of all of their cells being selected individually, | |
3443 | please see GetSelectedCells() for more details. | |
23324ae1 | 3444 | */ |
caac7804 | 3445 | wxArrayInt GetSelectedRows() const; |
23324ae1 FM |
3446 | |
3447 | /** | |
caac7804 | 3448 | Returns the colour used for drawing the selection background. |
23324ae1 | 3449 | */ |
caac7804 | 3450 | wxColour GetSelectionBackground() const; |
23324ae1 | 3451 | |
8a3e536c | 3452 | /** |
caac7804 BP |
3453 | Returns an array of the bottom right corners of blocks of selected |
3454 | cells. | |
8a3e536c | 3455 | |
caac7804 BP |
3456 | Please see GetSelectedCells() for more information about the selection |
3457 | representation in wxGrid. | |
23324ae1 | 3458 | |
caac7804 | 3459 | @see GetSelectionBlockTopLeft() |
23324ae1 | 3460 | */ |
caac7804 | 3461 | wxGridCellCoordsArray GetSelectionBlockBottomRight() const; |
8b9ef005 | 3462 | |
8b9ef005 | 3463 | /** |
caac7804 | 3464 | Returns an array of the top left corners of blocks of selected cells. |
8b9ef005 | 3465 | |
caac7804 BP |
3466 | Please see GetSelectedCells() for more information about the selection |
3467 | representation in wxGrid. | |
23324ae1 | 3468 | |
caac7804 | 3469 | @see GetSelectionBlockBottomRight() |
23324ae1 | 3470 | */ |
caac7804 | 3471 | wxGridCellCoordsArray GetSelectionBlockTopLeft() const; |
23324ae1 FM |
3472 | |
3473 | /** | |
caac7804 | 3474 | Returns the colour used for drawing the selection foreground. |
23324ae1 | 3475 | */ |
caac7804 | 3476 | wxColour GetSelectionForeground() const; |
23324ae1 FM |
3477 | |
3478 | /** | |
caac7804 | 3479 | Returns the current selection mode. |
23324ae1 | 3480 | |
caac7804 | 3481 | @see SetSelectionMode(). |
23324ae1 | 3482 | */ |
caac7804 | 3483 | wxGridSelectionModes GetSelectionMode() const; |
23324ae1 FM |
3484 | |
3485 | /** | |
caac7804 BP |
3486 | Returns @true if the given cell is selected. |
3487 | */ | |
3488 | bool IsInSelection(int row, int col) const; | |
3489 | /** | |
3490 | Returns @true if the given cell is selected. | |
3491 | */ | |
3492 | bool IsInSelection(const wxGridCellCoords& coords) const; | |
08dd9b5a | 3493 | |
caac7804 BP |
3494 | /** |
3495 | Returns @true if there are currently any selected cells, rows, columns | |
3496 | or blocks. | |
3497 | */ | |
3498 | bool IsSelection() const; | |
08dd9b5a | 3499 | |
caac7804 BP |
3500 | /** |
3501 | Selects all cells in the grid. | |
23324ae1 | 3502 | */ |
caac7804 | 3503 | void SelectAll(); |
23324ae1 FM |
3504 | |
3505 | /** | |
caac7804 | 3506 | Selects a rectangular block of cells. |
8b9ef005 | 3507 | |
caac7804 BP |
3508 | If @a addToSelected is @false then any existing selection will be |
3509 | deselected; if @true the column will be added to the existing | |
3510 | selection. | |
23324ae1 | 3511 | */ |
caac7804 BP |
3512 | void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol, |
3513 | bool addToSelected = false); | |
23324ae1 | 3514 | /** |
caac7804 | 3515 | Selects a rectangular block of cells. |
08dd9b5a | 3516 | |
caac7804 BP |
3517 | If @a addToSelected is @false then any existing selection will be |
3518 | deselected; if @true the column will be added to the existing | |
3519 | selection. | |
23324ae1 | 3520 | */ |
caac7804 BP |
3521 | void SelectBlock(const wxGridCellCoords& topLeft, |
3522 | const wxGridCellCoords& bottomRight, | |
3523 | bool addToSelected = false); | |
23324ae1 FM |
3524 | |
3525 | /** | |
caac7804 | 3526 | Selects the specified column. |
08dd9b5a | 3527 | |
caac7804 BP |
3528 | If @a addToSelected is @false then any existing selection will be |
3529 | deselected; if @true the column will be added to the existing | |
3530 | selection. | |
3531 | ||
3532 | This method won't select anything if the current selection mode is | |
3533 | wxGridSelectRows. | |
23324ae1 | 3534 | */ |
caac7804 | 3535 | void SelectCol(int col, bool addToSelected = false); |
23324ae1 | 3536 | |
23324ae1 | 3537 | /** |
caac7804 | 3538 | Selects the specified row. |
8b9ef005 | 3539 | |
caac7804 BP |
3540 | If @a addToSelected is @false then any existing selection will be |
3541 | deselected; if @true the row will be added to the existing selection. | |
3542 | ||
3543 | This method won't select anything if the current selection mode is | |
3544 | wxGridSelectColumns. | |
23324ae1 | 3545 | */ |
caac7804 | 3546 | void SelectRow(int row, bool addToSelected = false); |
23324ae1 FM |
3547 | |
3548 | /** | |
caac7804 BP |
3549 | Set the colour to be used for drawing the selection background. |
3550 | */ | |
3551 | void SetSelectionBackground(const wxColour& c); | |
08dd9b5a | 3552 | |
caac7804 BP |
3553 | /** |
3554 | Set the colour to be used for drawing the selection foreground. | |
23324ae1 | 3555 | */ |
caac7804 | 3556 | void SetSelectionForeground(const wxColour& c); |
23324ae1 FM |
3557 | |
3558 | /** | |
caac7804 | 3559 | Set the selection behaviour of the grid. |
8b9ef005 | 3560 | |
caac7804 BP |
3561 | The existing selection is converted to conform to the new mode if |
3562 | possible and discarded otherwise (e.g. any individual selected cells | |
3563 | are deselected if the new mode allows only the selection of the entire | |
3564 | rows or columns). | |
23324ae1 | 3565 | */ |
caac7804 | 3566 | void SetSelectionMode(wxGridSelectionModes selmode); |
23324ae1 | 3567 | |
caac7804 | 3568 | //@} |
08dd9b5a | 3569 | |
8b9ef005 | 3570 | |
caac7804 BP |
3571 | /** |
3572 | @name Scrolling | |
3573 | */ | |
3574 | //@{ | |
23324ae1 | 3575 | |
23324ae1 | 3576 | /** |
caac7804 BP |
3577 | Returns the number of pixels per horizontal scroll increment. |
3578 | ||
3579 | The default is 15. | |
3580 | ||
3581 | @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY() | |
23324ae1 | 3582 | */ |
caac7804 | 3583 | int GetScrollLineX() const; |
23324ae1 FM |
3584 | |
3585 | /** | |
caac7804 | 3586 | Returns the number of pixels per vertical scroll increment. |
08dd9b5a | 3587 | |
caac7804 | 3588 | The default is 15. |
8b9ef005 | 3589 | |
caac7804 | 3590 | @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY() |
23324ae1 | 3591 | */ |
caac7804 | 3592 | int GetScrollLineY() const; |
23324ae1 FM |
3593 | |
3594 | /** | |
caac7804 BP |
3595 | Returns @true if a cell is either entirely or at least partially |
3596 | visible in the grid window. | |
08dd9b5a | 3597 | |
caac7804 BP |
3598 | By default, the cell must be entirely visible for this function to |
3599 | return @true but if @a wholeCellVisible is @false, the function returns | |
3600 | @true even if the cell is only partially visible. | |
23324ae1 | 3601 | */ |
caac7804 | 3602 | bool IsVisible(int row, int col, bool wholeCellVisible = true) const; |
23324ae1 | 3603 | /** |
caac7804 BP |
3604 | Returns @true if a cell is either entirely or at least partially |
3605 | visible in the grid window. | |
3606 | ||
3607 | By default, the cell must be entirely visible for this function to | |
3608 | return @true but if @a wholeCellVisible is @false, the function returns | |
3609 | @true even if the cell is only partially visible. | |
23324ae1 | 3610 | */ |
caac7804 BP |
3611 | bool IsVisible(const wxGridCellCoords& coords, |
3612 | bool wholeCellVisible = true) const; | |
23324ae1 FM |
3613 | |
3614 | /** | |
caac7804 BP |
3615 | Brings the specified cell into the visible grid cell area with minimal |
3616 | scrolling. | |
23324ae1 | 3617 | |
caac7804 BP |
3618 | Does nothing if the cell is already visible. |
3619 | */ | |
3620 | void MakeCellVisible(int row, int col); | |
23324ae1 | 3621 | /** |
caac7804 BP |
3622 | Brings the specified cell into the visible grid cell area with minimal |
3623 | scrolling. | |
3624 | ||
3625 | Does nothing if the cell is already visible. | |
23324ae1 | 3626 | */ |
caac7804 | 3627 | void MakeCellVisible(const wxGridCellCoords& coords); |
23324ae1 FM |
3628 | |
3629 | /** | |
caac7804 | 3630 | Sets the number of pixels per horizontal scroll increment. |
08dd9b5a | 3631 | |
caac7804 | 3632 | The default is 15. |
8b9ef005 | 3633 | |
caac7804 | 3634 | @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY() |
23324ae1 | 3635 | */ |
caac7804 | 3636 | void SetScrollLineX(int x); |
23324ae1 FM |
3637 | |
3638 | /** | |
caac7804 | 3639 | Sets the number of pixels per vertical scroll increment. |
08dd9b5a | 3640 | |
caac7804 | 3641 | The default is 15. |
8b9ef005 | 3642 | |
caac7804 | 3643 | @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX() |
23324ae1 | 3644 | */ |
caac7804 | 3645 | void SetScrollLineY(int y); |
23324ae1 | 3646 | |
caac7804 | 3647 | //@} |
08dd9b5a | 3648 | |
23324ae1 | 3649 | |
caac7804 BP |
3650 | /** |
3651 | @name Cell and Device Coordinate Translation | |
3652 | */ | |
3653 | //@{ | |
23324ae1 FM |
3654 | |
3655 | /** | |
caac7804 | 3656 | Convert grid cell coordinates to grid window pixel coordinates. |
8b9ef005 | 3657 | |
caac7804 BP |
3658 | This function returns the rectangle that encloses the block of cells |
3659 | limited by @a topLeft and @a bottomRight cell in device coords and | |
3660 | clipped to the client size of the grid window. | |
8b9ef005 | 3661 | |
caac7804 | 3662 | @see CellToRect() |
23324ae1 | 3663 | */ |
caac7804 BP |
3664 | wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft, |
3665 | const wxGridCellCoords& bottomRight) const; | |
23324ae1 FM |
3666 | |
3667 | /** | |
caac7804 BP |
3668 | Return the rectangle corresponding to the grid cell's size and position |
3669 | in logical coordinates. | |
08dd9b5a | 3670 | |
caac7804 BP |
3671 | @see BlockToDeviceRect() |
3672 | */ | |
3673 | wxRect CellToRect(int row, int col) const; | |
3674 | /** | |
3675 | Return the rectangle corresponding to the grid cell's size and position | |
3676 | in logical coordinates. | |
08dd9b5a | 3677 | |
caac7804 | 3678 | @see BlockToDeviceRect() |
23324ae1 | 3679 | */ |
882678eb | 3680 | wxRect CellToRect(const wxGridCellCoords& coords) const; |
23324ae1 | 3681 | |
23324ae1 | 3682 | /** |
caac7804 BP |
3683 | Returns the column at the given pixel position. |
3684 | ||
3685 | @param x | |
3686 | The x position to evaluate. | |
3687 | @param clipToMinMax | |
3688 | If @true, rather than returning @c wxNOT_FOUND, it returns either | |
3689 | the first or last column depending on whether @a x is too far to | |
3690 | the left or right respectively. | |
3691 | @return | |
3692 | The column index or @c wxNOT_FOUND. | |
23324ae1 | 3693 | */ |
caac7804 | 3694 | int XToCol(int x, bool clipToMinMax = false) const; |
23324ae1 FM |
3695 | |
3696 | /** | |
caac7804 BP |
3697 | Returns the column whose right hand edge is close to the given logical |
3698 | @a x position. | |
3699 | ||
3700 | If no column edge is near to this position @c wxNOT_FOUND is returned. | |
23324ae1 | 3701 | */ |
caac7804 | 3702 | int XToEdgeOfCol(int x) const; |
23324ae1 | 3703 | |
23324ae1 | 3704 | /** |
caac7804 BP |
3705 | Translates logical pixel coordinates to the grid cell coordinates. |
3706 | ||
3707 | Notice that this function expects logical coordinates on input so if | |
3708 | you use this function in a mouse event handler you need to translate | |
3709 | the mouse position, which is expressed in device coordinates, to | |
3710 | logical ones. | |
3711 | ||
3712 | @see XToCol(), YToRow() | |
3713 | */ | |
3714 | wxGridCellCoords XYToCell(int x, int y) const; | |
3715 | /** | |
3716 | Translates logical pixel coordinates to the grid cell coordinates. | |
3717 | ||
3718 | Notice that this function expects logical coordinates on input so if | |
3719 | you use this function in a mouse event handler you need to translate | |
3720 | the mouse position, which is expressed in device coordinates, to | |
3721 | logical ones. | |
3722 | ||
3723 | @see XToCol(), YToRow() | |
3724 | */ | |
3725 | wxGridCellCoords XYToCell(const wxPoint& pos) const; | |
3726 | // XYToCell(int, int, wxGridCellCoords&) overload is intentionally | |
3727 | // undocumented, using it is ugly and non-const reference parameters are | |
3728 | // not used in wxWidgets API | |
08dd9b5a | 3729 | |
8b9ef005 | 3730 | /** |
caac7804 BP |
3731 | Returns the row whose bottom edge is close to the given logical @a y |
3732 | position. | |
3733 | ||
3734 | If no row edge is near to this position @c wxNOT_FOUND is returned. | |
23324ae1 | 3735 | */ |
caac7804 | 3736 | int YToEdgeOfRow(int y) const; |
23324ae1 FM |
3737 | |
3738 | /** | |
caac7804 | 3739 | Returns the grid row that corresponds to the logical @a y coordinate. |
08dd9b5a | 3740 | |
caac7804 | 3741 | Returns @c wxNOT_FOUND if there is no row at the @a y position. |
8b9ef005 | 3742 | */ |
caac7804 BP |
3743 | int YToRow(int y, bool clipToMinMax = false) const; |
3744 | ||
3745 | //@} | |
3746 | ||
08dd9b5a | 3747 | |
8b9ef005 | 3748 | /** |
caac7804 BP |
3749 | @name Miscellaneous Functions |
3750 | */ | |
3751 | //@{ | |
8b9ef005 | 3752 | |
caac7804 BP |
3753 | /** |
3754 | Appends one or more new columns to the right of the grid. | |
3755 | ||
3756 | The @a updateLabels argument is not used at present. If you are using a | |
3757 | derived grid table class you will need to override | |
3758 | wxGridTableBase::AppendCols(). See InsertCols() for further | |
3759 | information. | |
3760 | ||
3761 | @return @true on success or @false if appending columns failed. | |
23324ae1 | 3762 | */ |
caac7804 | 3763 | bool AppendCols(int numCols = 1, bool updateLabels = true); |
23324ae1 FM |
3764 | |
3765 | /** | |
caac7804 | 3766 | Appends one or more new rows to the bottom of the grid. |
08dd9b5a | 3767 | |
caac7804 BP |
3768 | The @a updateLabels argument is not used at present. If you are using a |
3769 | derived grid table class you will need to override | |
3770 | wxGridTableBase::AppendRows(). See InsertRows() for further | |
3771 | information. | |
23324ae1 | 3772 | |
caac7804 | 3773 | @return @true on success or @false if appending rows failed. |
23324ae1 | 3774 | */ |
caac7804 | 3775 | bool AppendRows(int numRows = 1, bool updateLabels = true); |
23324ae1 | 3776 | |
23324ae1 | 3777 | /** |
caac7804 BP |
3778 | Return @true if the horizontal grid lines stop at the last column |
3779 | boundary or @false if they continue to the end of the window. | |
3c4f71cc | 3780 | |
caac7804 BP |
3781 | The default is to clip grid lines. |
3782 | ||
3783 | @see ClipHorzGridLines(), AreVertGridLinesClipped() | |
3784 | */ | |
3785 | bool AreHorzGridLinesClipped() const; | |
23324ae1 FM |
3786 | |
3787 | /** | |
caac7804 BP |
3788 | Return @true if the vertical grid lines stop at the last row |
3789 | boundary or @false if they continue to the end of the window. | |
8b9ef005 | 3790 | |
caac7804 BP |
3791 | The default is to clip grid lines. |
3792 | ||
3793 | @see ClipVertGridLines(), AreHorzGridLinesClipped() | |
3794 | */ | |
3795 | bool AreVertGridLinesClipped() const; | |
23324ae1 FM |
3796 | |
3797 | /** | |
caac7804 | 3798 | Increments the grid's batch count. |
08dd9b5a | 3799 | |
caac7804 BP |
3800 | When the count is greater than zero repainting of the grid is |
3801 | suppressed. Each call to BeginBatch must be matched by a later call to | |
3802 | EndBatch(). Code that does a lot of grid modification can be enclosed | |
3803 | between BeginBatch() and EndBatch() calls to avoid screen flicker. The | |
3804 | final EndBatch() call will cause the grid to be repainted. | |
3805 | ||
3806 | Notice that you should use wxGridUpdateLocker which ensures that there | |
3807 | is always a matching EndBatch() call for this BeginBatch() if possible | |
3808 | instead of calling this method directly. | |
8b9ef005 | 3809 | */ |
caac7804 | 3810 | void BeginBatch(); |
08dd9b5a | 3811 | |
8b9ef005 | 3812 | /** |
caac7804 | 3813 | Clears all data in the underlying grid table and repaints the grid. |
8b9ef005 | 3814 | |
caac7804 BP |
3815 | The table is not deleted by this function. If you are using a derived |
3816 | table class then you need to override wxGridTableBase::Clear() for this | |
3817 | function to have any effect. | |
23324ae1 | 3818 | */ |
caac7804 | 3819 | void ClearGrid(); |
23324ae1 FM |
3820 | |
3821 | /** | |
caac7804 BP |
3822 | Change whether the horizontal grid lines are clipped by the end of the |
3823 | last column. | |
8b9ef005 | 3824 | |
caac7804 BP |
3825 | By default the grid lines are not drawn beyond the end of the last |
3826 | column but after calling this function with @a clip set to @false they | |
3827 | will be drawn across the entire grid window. | |
3828 | ||
3829 | @see AreHorzGridLinesClipped(), ClipVertGridLines() | |
3830 | */ | |
3831 | void ClipHorzGridLines(bool clip); | |
23324ae1 FM |
3832 | |
3833 | /** | |
caac7804 BP |
3834 | Change whether the vertical grid lines are clipped by the end of the |
3835 | last row. | |
08dd9b5a | 3836 | |
caac7804 BP |
3837 | By default the grid lines are not drawn beyond the end of the last |
3838 | row but after calling this function with @a clip set to @false they | |
3839 | will be drawn across the entire grid window. | |
3840 | ||
3841 | @see AreVertGridLinesClipped(), ClipHorzGridLines() | |
3842 | */ | |
3843 | void ClipVertGridLines(bool clip); | |
08dd9b5a | 3844 | |
8b9ef005 | 3845 | /** |
caac7804 BP |
3846 | Deletes one or more columns from a grid starting at the specified |
3847 | position. | |
8b9ef005 | 3848 | |
caac7804 BP |
3849 | The @a updateLabels argument is not used at present. If you are using a |
3850 | derived grid table class you will need to override | |
3851 | wxGridTableBase::DeleteCols(). See InsertCols() for further | |
3852 | information. | |
8b9ef005 | 3853 | |
caac7804 | 3854 | @return @true on success or @false if deleting columns failed. |
23324ae1 | 3855 | */ |
caac7804 | 3856 | bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true); |
23324ae1 | 3857 | |
23324ae1 | 3858 | /** |
caac7804 BP |
3859 | Deletes one or more rows from a grid starting at the specified |
3860 | position. | |
8b9ef005 | 3861 | |
caac7804 BP |
3862 | The @a updateLabels argument is not used at present. If you are using a |
3863 | derived grid table class you will need to override | |
3864 | wxGridTableBase::DeleteRows(). See InsertRows() for further | |
3865 | information. | |
8b9ef005 | 3866 | |
caac7804 | 3867 | @return @true on success or @false if appending rows failed. |
23324ae1 | 3868 | */ |
caac7804 | 3869 | bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true); |
23324ae1 | 3870 | |
23324ae1 | 3871 | /** |
caac7804 BP |
3872 | Decrements the grid's batch count. |
3873 | ||
3874 | When the count is greater than zero repainting of the grid is | |
3875 | suppressed. Each previous call to BeginBatch() must be matched by a | |
3876 | later call to EndBatch(). Code that does a lot of grid modification can | |
3877 | be enclosed between BeginBatch() and EndBatch() calls to avoid screen | |
3878 | flicker. The final EndBatch() will cause the grid to be repainted. | |
3879 | ||
3880 | @see wxGridUpdateLocker | |
8b9ef005 | 3881 | */ |
caac7804 | 3882 | void EndBatch(); |
08dd9b5a | 3883 | |
8b9ef005 | 3884 | /** |
caac7804 | 3885 | Overridden wxWindow method. |
8b9ef005 | 3886 | */ |
caac7804 | 3887 | virtual void Fit(); |
08dd9b5a | 3888 | |
8b9ef005 | 3889 | /** |
caac7804 | 3890 | Causes immediate repainting of the grid. |
8b9ef005 | 3891 | |
caac7804 | 3892 | Use this instead of the usual wxWindow::Refresh(). |
23324ae1 | 3893 | */ |
caac7804 | 3894 | void ForceRefresh(); |
23324ae1 FM |
3895 | |
3896 | /** | |
caac7804 BP |
3897 | Returns the number of times that BeginBatch() has been called without |
3898 | (yet) matching calls to EndBatch(). While the grid's batch count is | |
3899 | greater than zero the display will not be updated. | |
3900 | */ | |
3901 | int GetBatchCount(); | |
08dd9b5a | 3902 | |
caac7804 BP |
3903 | /** |
3904 | Returns the total number of grid columns. | |
8b9ef005 | 3905 | |
caac7804 | 3906 | This is the same as the number of columns in the underlying grid table. |
23324ae1 | 3907 | */ |
caac7804 | 3908 | int GetNumberCols() const; |
23324ae1 FM |
3909 | |
3910 | /** | |
caac7804 | 3911 | Returns the total number of grid rows. |
08dd9b5a | 3912 | |
caac7804 | 3913 | This is the same as the number of rows in the underlying grid table. |
23324ae1 | 3914 | */ |
caac7804 | 3915 | int GetNumberRows() const; |
23324ae1 FM |
3916 | |
3917 | /** | |
caac7804 BP |
3918 | Returns the attribute for the given cell creating one if necessary. |
3919 | ||
3920 | If the cell already has an attribute, it is returned. Otherwise a new | |
3921 | attribute is created, associated with the cell and returned. In any | |
3922 | case the caller must call DecRef() on the returned pointer. | |
3923 | ||
3924 | This function may only be called if CanHaveAttributes() returns @true. | |
8b9ef005 | 3925 | */ |
caac7804 | 3926 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; |
08dd9b5a | 3927 | |
8b9ef005 | 3928 | /** |
caac7804 | 3929 | Returns a base pointer to the current table object. |
08dd9b5a | 3930 | |
caac7804 | 3931 | The returned pointer is still owned by the grid. |
23324ae1 | 3932 | */ |
caac7804 | 3933 | wxGridTableBase *GetTable() const; |
23324ae1 FM |
3934 | |
3935 | /** | |
caac7804 BP |
3936 | Inserts one or more new columns into a grid with the first new column |
3937 | at the specified position. | |
08dd9b5a | 3938 | |
caac7804 BP |
3939 | Notice that inserting the columns in the grid requires grid table |
3940 | cooperation: when this method is called, grid object begins by | |
3941 | requesting the underlying grid table to insert new columns. If this is | |
3942 | successful the table notifies the grid and the grid updates the | |
3943 | display. For a default grid (one where you have called CreateGrid()) | |
3944 | this process is automatic. If you are using a custom grid table | |
3945 | (specified with SetTable()) then you must override | |
3946 | wxGridTableBase::InsertCols() in your derived table class. | |
3947 | ||
3948 | @param pos | |
3949 | The position which the first newly inserted column will have. | |
3950 | @param numCols | |
3951 | The number of columns to insert. | |
3952 | @param updateLabels | |
3953 | Currently not used. | |
3954 | @return | |
3955 | @true if the columns were successfully inserted, @false if an error | |
3956 | occurred (most likely the table couldn't be updated). | |
23324ae1 | 3957 | */ |
caac7804 | 3958 | bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true); |
23324ae1 FM |
3959 | |
3960 | /** | |
caac7804 BP |
3961 | Inserts one or more new rows into a grid with the first new row at the |
3962 | specified position. | |
8b9ef005 | 3963 | |
caac7804 BP |
3964 | Notice that you must implement wxGridTableBase::InsertRows() if you use |
3965 | a grid with a custom table, please see InsertCols() for more | |
3966 | information. | |
8b9ef005 | 3967 | |
caac7804 BP |
3968 | @param pos |
3969 | The position which the first newly inserted row will have. | |
3970 | @param numRows | |
3971 | The number of rows to insert. | |
3972 | @param updateLabels | |
3973 | Currently not used. | |
3974 | @return | |
3975 | @true if the rows were successfully inserted, @false if an error | |
3976 | occurred (most likely the table couldn't be updated). | |
3977 | */ | |
3978 | bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true); | |
8b9ef005 | 3979 | |
b99450ee VZ |
3980 | /** |
3981 | Invalidates the cached attribute for the given cell. | |
3982 | ||
3983 | For efficiency reasons, wxGrid may cache the recently used attributes | |
3984 | (currently it caches only the single most recently used one, in fact) | |
3985 | which can result in the cell appearance not being refreshed even when | |
3986 | the attribute returned by your custom wxGridCellAttrProvider-derived | |
3987 | class has changed. To force the grid to refresh the cell attribute, | |
3988 | this function may be used. Notice that calling it will not result in | |
3989 | actually redrawing the cell, you still need to call | |
3990 | wxWindow::RefreshRect() to invalidate the area occupied by the cell in | |
3991 | the window to do this. Also note that you don't need to call this | |
3992 | function if you store the attributes in wxGrid itself, i.e. use its | |
3993 | SetAttr() and similar methods, it is only useful when using a separate | |
3994 | custom attributes provider. | |
3995 | ||
3996 | @param row | |
3997 | The row of the cell whose attribute needs to be queried again. | |
3998 | @param col | |
3999 | The column of the cell whose attribute needs to be queried again. | |
4000 | ||
4001 | @since 2.9.2 | |
4002 | */ | |
4003 | void RefreshAttr(int row, int col); | |
4004 | ||
caac7804 BP |
4005 | /** |
4006 | Sets the cell attributes for all cells in the specified column. | |
08dd9b5a | 4007 | |
caac7804 BP |
4008 | For more information about controlling grid cell attributes see the |
4009 | wxGridCellAttr cell attribute class and the @ref overview_grid. | |
4010 | */ | |
4011 | void SetColAttr(int col, wxGridCellAttr* attr); | |
23324ae1 FM |
4012 | |
4013 | /** | |
caac7804 | 4014 | Sets the extra margins used around the grid area. |
08dd9b5a | 4015 | |
caac7804 BP |
4016 | A grid may occupy more space than needed for its data display and |
4017 | this function allows to set how big this extra space is | |
23324ae1 | 4018 | */ |
caac7804 | 4019 | void SetMargins(int extraWidth, int extraHeight); |
23324ae1 FM |
4020 | |
4021 | /** | |
caac7804 | 4022 | Sets the cell attributes for all cells in the specified row. |
08dd9b5a | 4023 | |
caac7804 BP |
4024 | The grid takes ownership of the attribute pointer. |
4025 | ||
4026 | See the wxGridCellAttr class for more information about controlling | |
4027 | cell attributes. | |
23324ae1 | 4028 | */ |
caac7804 BP |
4029 | void SetRowAttr(int row, wxGridCellAttr* attr); |
4030 | ||
4031 | //@} | |
23324ae1 | 4032 | |
11393d29 VZ |
4033 | |
4034 | /** | |
4035 | @name Sorting support. | |
4036 | ||
4037 | wxGrid doesn't provide any support for sorting the data but it does | |
4038 | generate events allowing the user code to sort it and supports | |
4039 | displaying the sort indicator in the column used for sorting. | |
4040 | ||
4041 | To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT | |
4042 | event (and not veto it) and resort the data displayed in the grid. The | |
4043 | grid will automatically update the sorting indicator on the column | |
4044 | which was clicked. | |
4045 | ||
4046 | You can also call the functions in this section directly to update the | |
4047 | sorting indicator. Once again, they don't do anything with the grid | |
4048 | data, it remains your responsibility to actually sort it appropriately. | |
4049 | */ | |
4050 | //@{ | |
4051 | ||
4052 | /** | |
4053 | Return the column in which the sorting indicator is currently | |
4054 | displayed. | |
4055 | ||
4056 | Returns @c wxNOT_FOUND if sorting indicator is not currently displayed | |
4057 | at all. | |
4058 | ||
4059 | @see SetSortingColumn() | |
4060 | */ | |
4061 | int GetSortingColumn() const; | |
4062 | ||
4063 | /** | |
4064 | Return @true if this column is currently used for sorting. | |
4065 | ||
4066 | @see GetSortingColumn() | |
4067 | */ | |
4068 | bool IsSortingBy(int col) const; | |
4069 | ||
4070 | /** | |
4071 | Return @true if the current sorting order is ascending or @false if it | |
4072 | is descending. | |
4073 | ||
4074 | It only makes sense to call this function if GetSortingColumn() returns | |
4075 | a valid column index and not @c wxNOT_FOUND. | |
4076 | ||
4077 | @see SetSortingColumn() | |
4078 | */ | |
4079 | bool IsSortOrderAscending() const; | |
4080 | ||
4081 | /** | |
4082 | Set the column to display the sorting indicator in and its direction. | |
4083 | ||
4084 | @param col | |
4085 | The column to display the sorting indicator in or @c wxNOT_FOUND to | |
4086 | remove any currently displayed sorting indicator. | |
4087 | @param ascending | |
4088 | If @true, display the ascending sort indicator, otherwise display | |
4089 | the descending sort indicator. | |
4090 | ||
4091 | @see GetSortingColumn(), IsSortOrderAscending() | |
4092 | */ | |
4093 | void SetSortingColumn(int col, bool ascending = true); | |
4094 | ||
4095 | /** | |
4096 | Remove any currently shown sorting indicator. | |
4097 | ||
4098 | This is equivalent to calling SetSortingColumn() with @c wxNOT_FOUND | |
4099 | first argument. | |
4100 | */ | |
4101 | void UnsetSortingColumn(); | |
4102 | //@} | |
3039ade9 | 4103 | |
882678eb | 4104 | |
3039ade9 VZ |
4105 | /** |
4106 | @name Accessors for component windows. | |
4107 | ||
4108 | Return the various child windows of wxGrid. | |
4109 | ||
4110 | wxGrid is an empty parent window for 4 children representing the column | |
4111 | labels window (top), the row labels window (left), the corner window | |
4112 | (top left) and the main grid window. It may be necessary to use these | |
4113 | individual windows and not the wxGrid window itself if you need to | |
4114 | handle events for them (this can be done using wxEvtHandler::Connect() | |
4115 | or wxWindow::PushEventHandler()) or do something else requiring the use | |
4116 | of the correct window pointer. Notice that you should not, however, | |
4117 | change these windows (e.g. reposition them or draw over them) because | |
4118 | they are managed by wxGrid itself. | |
4119 | */ | |
4120 | //@{ | |
4121 | ||
4122 | /** | |
4123 | Return the main grid window containing the grid cells. | |
4124 | ||
4125 | This window is always shown. | |
4126 | */ | |
4127 | wxWindow *GetGridWindow() const; | |
4128 | ||
4129 | /** | |
4130 | Return the row labels window. | |
4131 | ||
4132 | This window is not shown if the row labels were hidden using | |
4133 | HideRowLabels(). | |
4134 | */ | |
4135 | wxWindow *GetGridRowLabelWindow() const; | |
4136 | ||
4137 | /** | |
4138 | Return the column labels window. | |
4139 | ||
4140 | This window is not shown if the columns labels were hidden using | |
4141 | HideColLabels(). | |
4142 | ||
4143 | Depending on whether UseNativeColHeader() was called or not this can be | |
4144 | either a wxHeaderCtrl or a plain wxWindow. This function returns a valid | |
4145 | window pointer in either case but in the former case you can also use | |
4146 | GetGridColHeader() to access it if you need wxHeaderCtrl-specific | |
4147 | functionality. | |
4148 | */ | |
600e986a | 4149 | wxWindow *GetGridColLabelWindow() const; |
3039ade9 VZ |
4150 | |
4151 | /** | |
4152 | Return the window in the top left grid corner. | |
4153 | ||
4154 | This window is shown only of both columns and row labels are shown and | |
4155 | normally doesn't contain anything. Clicking on it is handled by wxGrid | |
4156 | however and can be used to select the entire grid. | |
4157 | */ | |
4158 | wxWindow *GetGridCornerLabelWindow() const; | |
4159 | ||
4160 | /** | |
4161 | Return the header control used for column labels display. | |
4162 | ||
4163 | This function can only be called if UseNativeColHeader() had been | |
4164 | called. | |
4165 | */ | |
4166 | wxHeaderCtrl *GetGridColHeader() const; | |
4167 | ||
4168 | //@} | |
882678eb FM |
4169 | |
4170 | protected: | |
4171 | /** | |
4172 | Returns @true if this grid has support for cell attributes. | |
4173 | ||
4174 | The grid supports attributes if it has the associated table which, in | |
4175 | turn, has attributes support, i.e. wxGridTableBase::CanHaveAttributes() | |
4176 | returns @true. | |
4177 | */ | |
4178 | bool CanHaveAttributes() const; | |
4179 | ||
4180 | /** | |
4181 | Get the minimal width of the given column/row. | |
4182 | ||
4183 | The value returned by this function may be different than that returned | |
4184 | by GetColMinimalAcceptableWidth() if SetColMinimalWidth() had been | |
4185 | called for this column. | |
4186 | */ | |
4187 | int GetColMinimalWidth(int col) const; | |
4188 | ||
4189 | /** | |
4190 | Returns the coordinate of the right border specified column. | |
4191 | */ | |
4192 | int GetColRight(int col) const; | |
4193 | ||
4194 | /** | |
4195 | Returns the coordinate of the left border specified column. | |
4196 | */ | |
4197 | int GetColLeft(int col) const; | |
4198 | ||
4199 | /** | |
4200 | Returns the minimal size for the given column. | |
4201 | ||
4202 | The value returned by this function may be different than that returned | |
4203 | by GetRowMinimalAcceptableHeight() if SetRowMinimalHeight() had been | |
4204 | called for this row. | |
4205 | */ | |
4206 | int GetRowMinimalHeight(int col) const; | |
8b9ef005 | 4207 | }; |
23324ae1 | 4208 | |
08dd9b5a | 4209 | |
23324ae1 | 4210 | |
8b9ef005 BP |
4211 | /** |
4212 | @class wxGridUpdateLocker | |
23324ae1 | 4213 | |
8b9ef005 BP |
4214 | This small class can be used to prevent wxGrid from redrawing during its |
4215 | lifetime by calling wxGrid::BeginBatch() in its constructor and | |
4216 | wxGrid::EndBatch() in its destructor. It is typically used in a function | |
4217 | performing several operations with a grid which would otherwise result in | |
4218 | flicker. For example: | |
23324ae1 | 4219 | |
8b9ef005 BP |
4220 | @code |
4221 | void MyFrame::Foo() | |
4222 | { | |
4223 | m_grid = new wxGrid(this, ...); | |
23324ae1 | 4224 | |
8b9ef005 BP |
4225 | wxGridUpdateLocker noUpdates(m_grid); |
4226 | m_grid-AppendColumn(); | |
4227 | // ... many other operations with m_grid ... | |
4228 | m_grid-AppendRow(); | |
08dd9b5a | 4229 | |
8b9ef005 BP |
4230 | // destructor called, grid refreshed |
4231 | } | |
4232 | @endcode | |
08dd9b5a | 4233 | |
8b9ef005 BP |
4234 | Using this class is easier and safer than calling wxGrid::BeginBatch() and |
4235 | wxGrid::EndBatch() because you don't risk missing the call the latter (due | |
4236 | to an exception for example). | |
23324ae1 | 4237 | |
8b9ef005 BP |
4238 | @library{wxadv} |
4239 | @category{grid} | |
4240 | */ | |
4241 | class wxGridUpdateLocker | |
4242 | { | |
4243 | public: | |
23324ae1 | 4244 | /** |
8b9ef005 BP |
4245 | Creates an object preventing the updates of the specified @a grid. The |
4246 | parameter could be @NULL in which case nothing is done. If @a grid is | |
4247 | non-@NULL then the grid must exist for longer than this | |
4248 | wxGridUpdateLocker object itself. | |
08dd9b5a | 4249 | |
8b9ef005 BP |
4250 | The default constructor could be followed by a call to Create() to set |
4251 | the grid object later. | |
23324ae1 | 4252 | */ |
8b9ef005 | 4253 | wxGridUpdateLocker(wxGrid* grid = NULL); |
23324ae1 FM |
4254 | |
4255 | /** | |
8b9ef005 BP |
4256 | Destructor reenables updates for the grid this object is associated |
4257 | with. | |
23324ae1 | 4258 | */ |
8b9ef005 | 4259 | ~wxGridUpdateLocker(); |
23324ae1 FM |
4260 | |
4261 | /** | |
8b9ef005 BP |
4262 | This method can be called if the object had been constructed using the |
4263 | default constructor. It must not be called more than once. | |
4264 | */ | |
4265 | void Create(wxGrid* grid); | |
4266 | }; | |
08dd9b5a | 4267 | |
08dd9b5a | 4268 | |
23324ae1 | 4269 | |
8b9ef005 BP |
4270 | /** |
4271 | @class wxGridEvent | |
08dd9b5a | 4272 | |
8b9ef005 | 4273 | This event class contains information about various grid events. |
8a3e536c | 4274 | |
2b1f9fa0 VZ |
4275 | Notice that all grid event table macros are available in two versions: |
4276 | @c EVT_GRID_XXX and @c EVT_GRID_CMD_XXX. The only difference between the | |
4277 | two is that the former doesn't allow to specify the grid window identifier | |
4278 | and so takes a single parameter, the event handler, but is not suitable if | |
4279 | there is more than one grid control in the window where the event table is | |
4280 | used (as it would catch the events from all the grids). The version with @c | |
4281 | CMD takes the id as first argument and the event handler as the second one | |
4282 | and so can be used with multiple grids as well. Otherwise there are no | |
4283 | difference between the two and only the versions without the id are | |
4284 | documented below for brevity. | |
4285 | ||
8b9ef005 | 4286 | @beginEventTable{wxGridEvent} |
763163a8 VZ |
4287 | @event{EVT_GRID_CELL_CHANGING(func)} |
4288 | The user is about to change the data in a cell. The new cell value as | |
4289 | string is available from GetString() event object method. This event | |
f8f31de6 FM |
4290 | can be vetoed if the change is not allowed. |
4291 | Processes a @c wxEVT_GRID_CELL_CHANGING event type. | |
763163a8 VZ |
4292 | @event{EVT_GRID_CELL_CHANGED(func)} |
4293 | The user changed the data in a cell. The old cell value as string is | |
4294 | available from GetString() event object method. Notice that vetoing | |
4295 | this event still works for backwards compatibility reasons but any new | |
4296 | code should only veto EVT_GRID_CELL_CHANGING event and not this one. | |
4297 | Processes a @c wxEVT_GRID_CELL_CHANGED event type. | |
8b9ef005 BP |
4298 | @event{EVT_GRID_CELL_LEFT_CLICK(func)} |
4299 | The user clicked a cell with the left mouse button. Processes a | |
4300 | @c wxEVT_GRID_CELL_LEFT_CLICK event type. | |
4301 | @event{EVT_GRID_CELL_LEFT_DCLICK(func)} | |
4302 | The user double-clicked a cell with the left mouse button. Processes a | |
4303 | @c wxEVT_GRID_CELL_LEFT_DCLICK event type. | |
4304 | @event{EVT_GRID_CELL_RIGHT_CLICK(func)} | |
4305 | The user clicked a cell with the right mouse button. Processes a | |
4306 | @c wxEVT_GRID_CELL_RIGHT_CLICK event type. | |
4307 | @event{EVT_GRID_CELL_RIGHT_DCLICK(func)} | |
4308 | The user double-clicked a cell with the right mouse button. Processes a | |
4309 | @c wxEVT_GRID_CELL_RIGHT_DCLICK event type. | |
4310 | @event{EVT_GRID_EDITOR_HIDDEN(func)} | |
4311 | The editor for a cell was hidden. Processes a | |
4312 | @c wxEVT_GRID_EDITOR_HIDDEN event type. | |
4313 | @event{EVT_GRID_EDITOR_SHOWN(func)} | |
4314 | The editor for a cell was shown. Processes a | |
4315 | @c wxEVT_GRID_EDITOR_SHOWN event type. | |
4316 | @event{EVT_GRID_LABEL_LEFT_CLICK(func)} | |
4317 | The user clicked a label with the left mouse button. Processes a | |
4318 | @c wxEVT_GRID_LABEL_LEFT_CLICK event type. | |
4319 | @event{EVT_GRID_LABEL_LEFT_DCLICK(func)} | |
4320 | The user double-clicked a label with the left mouse button. Processes a | |
4321 | @c wxEVT_GRID_LABEL_LEFT_DCLICK event type. | |
4322 | @event{EVT_GRID_LABEL_RIGHT_CLICK(func)} | |
4323 | The user clicked a label with the right mouse button. Processes a | |
4324 | @c wxEVT_GRID_LABEL_RIGHT_CLICK event type. | |
4325 | @event{EVT_GRID_LABEL_RIGHT_DCLICK(func)} | |
4326 | The user double-clicked a label with the right mouse button. Processes | |
4327 | a @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type. | |
4328 | @event{EVT_GRID_SELECT_CELL(func)} | |
c6cc8b15 VZ |
4329 | The given cell was made current, either by user or by the program via a |
4330 | call to SetGridCursor() or GoToCell(). Processes a | |
8b9ef005 | 4331 | @c wxEVT_GRID_SELECT_CELL event type. |
cd68daf5 VZ |
4332 | @event{EVT_GRID_COL_MOVE(func)} |
4333 | The user tries to change the order of the columns in the grid by | |
4334 | dragging the column specified by GetCol(). This event can be vetoed to | |
4335 | either prevent the user from reordering the column change completely | |
4336 | (but notice that if you don't want to allow it at all, you simply | |
4337 | shouldn't call wxGrid::EnableDragColMove() in the first place), vetoed | |
4338 | but handled in some way in the handler, e.g. by really moving the | |
4339 | column to the new position at the associated table level, or allowed to | |
4340 | proceed in which case wxGrid::SetColPos() is used to reorder the | |
4341 | columns display order without affecting the use of the column indices | |
4342 | otherwise. | |
4343 | This event macro corresponds to @c wxEVT_GRID_COL_MOVE event type. | |
11393d29 VZ |
4344 | @event{EVT_GRID_COL_SORT(func)} |
4345 | This event is generated when a column is clicked by the user and its | |
4346 | name is explained by the fact that the custom reaction to a click on a | |
4347 | column is to sort the grid contents by this column. However the grid | |
4348 | itself has no special support for sorting and it's up to the handler of | |
4349 | this event to update the associated table. But if the event is handled | |
4350 | (and not vetoed) the grid supposes that the table was indeed resorted | |
4351 | and updates the column to indicate the new sort order and refreshes | |
4352 | itself. | |
11393d29 | 4353 | This event macro corresponds to @c wxEVT_GRID_COL_SORT event type. |
8b9ef005 | 4354 | @endEventTable |
8a3e536c | 4355 | |
8b9ef005 | 4356 | @library{wxadv} |
87638422 | 4357 | @category{grid,events} |
8b9ef005 BP |
4358 | */ |
4359 | class wxGridEvent : public wxNotifyEvent | |
4360 | { | |
4361 | public: | |
4362 | /** | |
4363 | Default constructor. | |
23324ae1 | 4364 | */ |
8b9ef005 | 4365 | wxGridEvent(); |
23324ae1 | 4366 | /** |
8b9ef005 | 4367 | Constructor for initializing all event attributes. |
23324ae1 | 4368 | */ |
8b9ef005 BP |
4369 | wxGridEvent(int id, wxEventType type, wxObject* obj, |
4370 | int row = -1, int col = -1, int x = -1, int y = -1, | |
ccf39540 | 4371 | bool sel = true, const wxKeyboardState& kbd = wxKeyboardState()); |
23324ae1 FM |
4372 | |
4373 | /** | |
8b9ef005 | 4374 | Returns @true if the Alt key was down at the time of the event. |
23324ae1 | 4375 | */ |
8b9ef005 | 4376 | bool AltDown() const; |
23324ae1 FM |
4377 | |
4378 | /** | |
8b9ef005 | 4379 | Returns @true if the Control key was down at the time of the event. |
23324ae1 | 4380 | */ |
8b9ef005 | 4381 | bool ControlDown() const; |
23324ae1 FM |
4382 | |
4383 | /** | |
8b9ef005 | 4384 | Column at which the event occurred. |
204530b0 VZ |
4385 | |
4386 | Notice that for a @c wxEVT_GRID_SELECT_CELL event this column is the | |
4387 | column of the newly selected cell while the previously selected cell | |
4388 | can be retrieved using wxGrid::GetGridCursorCol(). | |
23324ae1 | 4389 | */ |
8b9ef005 | 4390 | virtual int GetCol(); |
23324ae1 FM |
4391 | |
4392 | /** | |
8b9ef005 | 4393 | Position in pixels at which the event occurred. |
23324ae1 | 4394 | */ |
8b9ef005 | 4395 | wxPoint GetPosition(); |
23324ae1 FM |
4396 | |
4397 | /** | |
8b9ef005 | 4398 | Row at which the event occurred. |
204530b0 VZ |
4399 | |
4400 | Notice that for a @c wxEVT_GRID_SELECT_CELL event this row is the row | |
4401 | of the newly selected cell while the previously selected cell can be | |
4402 | retrieved using wxGrid::GetGridCursorRow(). | |
23324ae1 | 4403 | */ |
8b9ef005 | 4404 | virtual int GetRow(); |
23324ae1 FM |
4405 | |
4406 | /** | |
8b9ef005 | 4407 | Returns @true if the Meta key was down at the time of the event. |
23324ae1 | 4408 | */ |
8b9ef005 | 4409 | bool MetaDown() const; |
23324ae1 FM |
4410 | |
4411 | /** | |
8b9ef005 BP |
4412 | Returns @true if the user is selecting grid cells, or @false if |
4413 | deselecting. | |
23324ae1 | 4414 | */ |
8b9ef005 | 4415 | bool Selecting(); |
23324ae1 FM |
4416 | |
4417 | /** | |
8b9ef005 | 4418 | Returns @true if the Shift key was down at the time of the event. |
23324ae1 | 4419 | */ |
8b9ef005 BP |
4420 | bool ShiftDown() const; |
4421 | }; | |
23324ae1 | 4422 | |
08dd9b5a | 4423 | |
8b9ef005 BP |
4424 | |
4425 | /** | |
4426 | @class wxGridSizeEvent | |
4427 | ||
4428 | This event class contains information about a row/column resize event. | |
4429 | ||
4430 | @beginEventTable{wxGridSizeEvent} | |
8b9ef005 | 4431 | @event{EVT_GRID_CMD_COL_SIZE(id, func)} |
27bb2c8c VZ |
4432 | The user resized a column, corresponds to @c wxEVT_GRID_COL_SIZE event |
4433 | type. | |
8b9ef005 | 4434 | @event{EVT_GRID_CMD_ROW_SIZE(id, func)} |
27bb2c8c VZ |
4435 | The user resized a row, corresponds to @c wxEVT_GRID_ROW_SIZE event |
4436 | type. | |
4437 | @event{EVT_GRID_COL_SIZE(func)} | |
4438 | Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id. | |
4439 | @event{EVT_GRID_ROW_SIZE(func)} | |
4440 | Same as EVT_GRID_CMD_ROW_SIZE() but uses `wxID_ANY` id. | |
8b9ef005 BP |
4441 | @endEventTable |
4442 | ||
4443 | @library{wxadv} | |
87638422 | 4444 | @category{grid,events} |
8b9ef005 BP |
4445 | */ |
4446 | class wxGridSizeEvent : public wxNotifyEvent | |
4447 | { | |
4448 | public: | |
4449 | /** | |
4450 | Default constructor. | |
23324ae1 | 4451 | */ |
8b9ef005 | 4452 | wxGridSizeEvent(); |
23324ae1 | 4453 | /** |
8b9ef005 | 4454 | Constructor for initializing all event attributes. |
23324ae1 | 4455 | */ |
8b9ef005 BP |
4456 | wxGridSizeEvent(int id, wxEventType type, wxObject* obj, |
4457 | int rowOrCol = -1, int x = -1, int y = -1, | |
ccf39540 | 4458 | const wxKeyboardState& kbd = wxKeyboardState()); |
23324ae1 FM |
4459 | |
4460 | /** | |
8b9ef005 | 4461 | Returns @true if the Alt key was down at the time of the event. |
23324ae1 | 4462 | */ |
8b9ef005 | 4463 | bool AltDown() const; |
23324ae1 FM |
4464 | |
4465 | /** | |
8b9ef005 | 4466 | Returns @true if the Control key was down at the time of the event. |
23324ae1 | 4467 | */ |
8b9ef005 | 4468 | bool ControlDown() const; |
23324ae1 FM |
4469 | |
4470 | /** | |
8b9ef005 | 4471 | Position in pixels at which the event occurred. |
23324ae1 | 4472 | */ |
8b9ef005 | 4473 | wxPoint GetPosition(); |
23324ae1 FM |
4474 | |
4475 | /** | |
8b9ef005 | 4476 | Row or column at that was resized. |
23324ae1 | 4477 | */ |
8b9ef005 | 4478 | int GetRowOrCol(); |
23324ae1 FM |
4479 | |
4480 | /** | |
8b9ef005 | 4481 | Returns @true if the Meta key was down at the time of the event. |
23324ae1 | 4482 | */ |
8b9ef005 | 4483 | bool MetaDown() const; |
23324ae1 FM |
4484 | |
4485 | /** | |
8b9ef005 | 4486 | Returns @true if the Shift key was down at the time of the event. |
23324ae1 | 4487 | */ |
8b9ef005 BP |
4488 | bool ShiftDown() const; |
4489 | }; | |
23324ae1 | 4490 | |
3c4f71cc | 4491 | |
23324ae1 | 4492 | |
8b9ef005 BP |
4493 | /** |
4494 | @class wxGridRangeSelectEvent | |
08dd9b5a | 4495 | |
8b9ef005 BP |
4496 | @beginEventTable{wxGridRangeSelectEvent} |
4497 | @event{EVT_GRID_RANGE_SELECT(func)} | |
4498 | The user selected a group of contiguous cells. Processes a | |
4499 | @c wxEVT_GRID_RANGE_SELECT event type. | |
4500 | @event{EVT_GRID_CMD_RANGE_SELECT(id, func)} | |
4501 | The user selected a group of contiguous cells; variant taking a window | |
4502 | identifier. Processes a @c wxEVT_GRID_RANGE_SELECT event type. | |
4503 | @endEventTable | |
08dd9b5a | 4504 | |
8b9ef005 | 4505 | @library{wxadv} |
87638422 | 4506 | @category{grid,events} |
8b9ef005 BP |
4507 | */ |
4508 | class wxGridRangeSelectEvent : public wxNotifyEvent | |
4509 | { | |
4510 | public: | |
4511 | /** | |
4512 | Default constructor. | |
23324ae1 | 4513 | */ |
8b9ef005 | 4514 | wxGridRangeSelectEvent(); |
23324ae1 | 4515 | /** |
8b9ef005 | 4516 | Constructor for initializing all event attributes. |
23324ae1 | 4517 | */ |
8b9ef005 BP |
4518 | wxGridRangeSelectEvent(int id, wxEventType type, |
4519 | wxObject* obj, | |
4520 | const wxGridCellCoords& topLeft, | |
4521 | const wxGridCellCoords& bottomRight, | |
ccf39540 | 4522 | bool sel = true, const wxKeyboardState& kbd = wxKeyboardState()); |
23324ae1 FM |
4523 | |
4524 | /** | |
8b9ef005 | 4525 | Returns @true if the Alt key was down at the time of the event. |
23324ae1 | 4526 | */ |
8b9ef005 | 4527 | bool AltDown() const; |
23324ae1 FM |
4528 | |
4529 | /** | |
8b9ef005 | 4530 | Returns @true if the Control key was down at the time of the event. |
23324ae1 | 4531 | */ |
8b9ef005 | 4532 | bool ControlDown() const; |
23324ae1 FM |
4533 | |
4534 | /** | |
8b9ef005 | 4535 | Top left corner of the rectangular area that was (de)selected. |
23324ae1 | 4536 | */ |
8b9ef005 | 4537 | wxGridCellCoords GetBottomRightCoords(); |
23324ae1 | 4538 | |
8a3e536c | 4539 | /** |
8b9ef005 BP |
4540 | Bottom row of the rectangular area that was (de)selected. |
4541 | */ | |
4542 | int GetBottomRow(); | |
8a3e536c | 4543 | |
23324ae1 | 4544 | /** |
8b9ef005 | 4545 | Left column of the rectangular area that was (de)selected. |
23324ae1 | 4546 | */ |
8b9ef005 | 4547 | int GetLeftCol(); |
23324ae1 FM |
4548 | |
4549 | /** | |
8b9ef005 | 4550 | Right column of the rectangular area that was (de)selected. |
23324ae1 | 4551 | */ |
8b9ef005 | 4552 | int GetRightCol(); |
5e6e278d | 4553 | |
5e6e278d | 4554 | /** |
8b9ef005 | 4555 | Top left corner of the rectangular area that was (de)selected. |
5e6e278d | 4556 | */ |
8b9ef005 | 4557 | wxGridCellCoords GetTopLeftCoords(); |
5e6e278d FM |
4558 | |
4559 | /** | |
8b9ef005 | 4560 | Top row of the rectangular area that was (de)selected. |
5e6e278d | 4561 | */ |
8b9ef005 | 4562 | int GetTopRow(); |
5e6e278d FM |
4563 | |
4564 | /** | |
8b9ef005 | 4565 | Returns @true if the Meta key was down at the time of the event. |
5e6e278d | 4566 | */ |
8b9ef005 | 4567 | bool MetaDown() const; |
5e6e278d FM |
4568 | |
4569 | /** | |
8b9ef005 | 4570 | Returns @true if the area was selected, @false otherwise. |
5e6e278d | 4571 | */ |
8b9ef005 | 4572 | bool Selecting(); |
5e6e278d FM |
4573 | |
4574 | /** | |
8b9ef005 | 4575 | Returns @true if the Shift key was down at the time of the event. |
5e6e278d | 4576 | */ |
8b9ef005 | 4577 | bool ShiftDown() const; |
23324ae1 FM |
4578 | }; |
4579 | ||
4580 | ||
e54c96f1 | 4581 | |
23324ae1 | 4582 | /** |
8b9ef005 | 4583 | @class wxGridEditorCreatedEvent |
7c913512 | 4584 | |
8b9ef005 BP |
4585 | @beginEventTable{wxGridEditorCreatedEvent} |
4586 | @event{EVT_GRID_EDITOR_CREATED(func)} | |
4587 | The editor for a cell was created. Processes a | |
4588 | @c wxEVT_GRID_EDITOR_CREATED event type. | |
4589 | @event{EVT_GRID_CMD_EDITOR_CREATED(id, func)} | |
4590 | The editor for a cell was created; variant taking a window identifier. | |
4591 | Processes a @c wxEVT_GRID_EDITOR_CREATED event type. | |
4592 | @endEventTable | |
7c913512 | 4593 | |
23324ae1 | 4594 | @library{wxadv} |
87638422 | 4595 | @category{grid,events} |
23324ae1 | 4596 | */ |
8b9ef005 | 4597 | class wxGridEditorCreatedEvent : public wxCommandEvent |
23324ae1 FM |
4598 | { |
4599 | public: | |
4600 | /** | |
4601 | Default constructor. | |
4602 | */ | |
8b9ef005 | 4603 | wxGridEditorCreatedEvent(); |
23324ae1 | 4604 | /** |
8b9ef005 | 4605 | Constructor for initializing all event attributes. |
23324ae1 | 4606 | */ |
8b9ef005 BP |
4607 | wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj, |
4608 | int row, int col, wxControl* ctrl); | |
23324ae1 FM |
4609 | |
4610 | /** | |
8b9ef005 | 4611 | Returns the column at which the event occurred. |
23324ae1 | 4612 | */ |
8b9ef005 | 4613 | int GetCol(); |
7c913512 | 4614 | |
8b9ef005 BP |
4615 | /** |
4616 | Returns the edit control. | |
4617 | */ | |
4618 | wxControl* GetControl(); | |
7c913512 | 4619 | |
8b9ef005 BP |
4620 | /** |
4621 | Returns the row at which the event occurred. | |
4622 | */ | |
4623 | int GetRow(); | |
7c913512 | 4624 | |
23324ae1 | 4625 | /** |
8b9ef005 | 4626 | Sets the column at which the event occurred. |
23324ae1 | 4627 | */ |
8b9ef005 | 4628 | void SetCol(int col); |
23324ae1 FM |
4629 | |
4630 | /** | |
8b9ef005 | 4631 | Sets the edit control. |
23324ae1 | 4632 | */ |
8b9ef005 | 4633 | void SetControl(wxControl* ctrl); |
23324ae1 FM |
4634 | |
4635 | /** | |
8b9ef005 | 4636 | Sets the row at which the event occurred. |
23324ae1 | 4637 | */ |
8b9ef005 | 4638 | void SetRow(int row); |
23324ae1 | 4639 | }; |
e54c96f1 | 4640 |