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