Finished review of the first 1,000 lines of grid.h interface header.
[wxWidgets.git] / interface / wx / grid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: grid.h
3 // Purpose: interface of wxGrid and related classes
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxGridCellFloatRenderer
11
12 This class may be used to format floating point data in a cell.
13
14 @library{wxadv}
15 @category{grid}
16
17 @see wxGridCellRenderer, wxGridCellBoolRenderer, wxGridCellNumberRenderer,
18 wxGridCellStringRenderer
19 */
20 class wxGridCellFloatRenderer : public wxGridCellStringRenderer
21 {
22 public:
23 /**
24 @param width
25 Minimum number of characters to be shown.
26 @param precision
27 Number of digits after the decimal dot.
28 */
29 wxGridCellFloatRenderer(int width = -1, int precision = -1);
30
31 /**
32 Returns the precision.
33 */
34 int GetPrecision() const;
35
36 /**
37 Returns the width.
38 */
39 int GetWidth() const;
40
41 /**
42 Parameters string format is "width[,precision]".
43 */
44 virtual void SetParameters(const wxString& params);
45
46 /**
47 Sets the precision.
48 */
49 void SetPrecision(int precision);
50
51 /**
52 Sets the width.
53 */
54 void SetWidth(int width);
55 };
56
57
58
59 /**
60 @class wxGridTableBase
61
62 The almost abstract base class for grid tables.
63
64 A grid table is responsible for storing the grid data and, indirectly, grid
65 cell attributes. The data can be stored in the way most convenient for the
66 application but has to be provided in string form to wxGrid. It is also
67 possible to provide cells values in other formats if appropriate, e.g. as
68 numbers.
69
70 This base class is not quite abstract as it implements a trivial strategy
71 for storing the attributes by forwarding it to wxGridCellAttrProvider and
72 also provides stubs for some other functions. However it does have a number
73 of pure virtual methods which must be implemented in the derived classes.
74
75 @see wxGridStringTable
76
77 @library{wxadv}
78 @category{grid}
79 */
80 class wxGridTableBase : public wxObject
81 {
82 public:
83 /**
84 Default constructor.
85 */
86 wxGridTableBase();
87
88 /**
89 Destructor frees the attribute provider if it was created.
90 */
91 virtual ~wxGridTableBase();
92
93 /**
94 Must be overridden to return the number of rows in the table.
95
96 For backwards compatibility reasons, this method is not const.
97 Use GetRowsCount() instead of it in const methods of derived table
98 classes.
99 */
100 virtual int GetNumberRows() = 0;
101
102 /**
103 Must be overridden to return the number of columns in the table.
104
105 For backwards compatibility reasons, this method is not const.
106 Use GetColsCount() instead of it in const methods of derived table
107 classes,
108 */
109 virtual int GetNumberCols() = 0;
110
111 /**
112 Return the number of rows in the table.
113
114 This method is not virtual and is only provided as a convenience for
115 the derived classes which can't call GetNumberRows() without a
116 @c const_cast from their const methods.
117 */
118 int GetRowsCount() const;
119
120 /**
121 Return the number of columns in the table.
122
123 This method is not virtual and is only provided as a convenience for
124 the derived classes which can't call GetNumberCols() without a
125 @c const_cast from their const methods.
126 */
127 int GetColsCount() const;
128
129
130 /**
131 @name Table Cell Accessors
132 */
133 //@{
134
135 /**
136 Must be overridden to implement testing for empty cells.
137 */
138 virtual bool IsEmptyCell(int row, int col) = 0;
139
140 /**
141 Same as IsEmptyCell() but taking wxGridCellCoords.
142
143 Notice that this method is not virtual, only IsEmptyCell() should be
144 overridden.
145 */
146 bool IsEmpty(const wxGridCellCoords& coords);
147
148 /**
149 Must be overridden to implement accessing the table values as text.
150 */
151 virtual wxString GetValue(int row, int col) = 0;
152
153 /**
154 Must be overridden to implement setting the table values as text.
155 */
156 virtual void SetValue(int row, int col, const wxString& value) = 0;
157
158 /**
159 Returns the type of the value in the given cell.
160
161 By default all cells are strings and this method returns
162 @c wxGRID_VALUE_STRING.
163 */
164 virtual wxString GetTypeName(int row, int col);
165
166 /**
167 Returns true if the value of the given cell can be accessed as if it
168 were of the specified type.
169
170 By default the cells can only be accessed as strings. Note that a cell
171 could be accessible in different ways, e.g. a numeric cell may return
172 @true for @c wxGRID_VALUE_NUMBER but also for @c wxGRID_VALUE_STRING
173 indicating that the value can be coerced to a string form.
174 */
175 virtual bool CanGetValueAs(int row, int col, const wxString& typeName);
176
177 /**
178 Returns true if the value of the given cell can be set as if it were of
179 the specified type.
180
181 @see CanGetValueAs()
182 */
183 virtual bool CanSetValueAs(int row, int col, const wxString& typeName);
184
185 /**
186 Returns the value of the given cell as a long.
187
188 This should only be called if CanGetValueAs() returns @true when called
189 with @c wxGRID_VALUE_NUMBER argument. Default implementation always
190 return 0.
191 */
192 virtual long GetValueAsLong(int row, int col);
193
194 /**
195 Returns the value of the given cell as a double.
196
197 This should only be called if CanGetValueAs() returns @true when called
198 with @c wxGRID_VALUE_FLOAT argument. Default implementation always
199 return 0.0.
200 */
201 virtual double GetValueAsDouble(int row, int col);
202
203 /**
204 Returns the value of the given cell as a boolean.
205
206 This should only be called if CanGetValueAs() returns @true when called
207 with @c wxGRID_VALUE_BOOL argument. Default implementation always
208 return false.
209 */
210 virtual bool GetValueAsBool(int row, int col);
211
212 /**
213 Returns the value of the given cell as a user-defined type.
214
215 This should only be called if CanGetValueAs() returns @true when called
216 with @a typeName. Default implementation always return @NULL.
217 */
218 virtual void *GetValueAsCustom(int row, int col, const wxString& typeName);
219
220 /**
221 Sets the value of the given cell as a long.
222
223 This should only be called if CanSetValueAs() returns @true when called
224 with @c wxGRID_VALUE_NUMBER argument. Default implementation doesn't do
225 anything.
226 */
227 virtual void SetValueAsLong(int row, int col, long value);
228
229 /**
230 Sets the value of the given cell as a double.
231
232 This should only be called if CanSetValueAs() returns @true when called
233 with @c wxGRID_VALUE_FLOAT argument. Default implementation doesn't do
234 anything.
235 */
236 virtual void SetValueAsDouble(int row, int col, double value);
237
238 /**
239 Sets the value of the given cell as a boolean.
240
241 This should only be called if CanSetValueAs() returns @true when called
242 with @c wxGRID_VALUE_BOOL argument. Default implementation doesn't do
243 anything.
244 */
245 virtual void SetValueAsBool( int row, int col, bool value );
246
247 /**
248 Sets the value of the given cell as a user-defined type.
249
250 This should only be called if CanSetValueAs() returns @true when called
251 with @a typeName. Default implementation doesn't do anything.
252 */
253 virtual void SetValueAsCustom(int row, int col, const wxString& typeName,
254 void *value);
255
256 //@}
257
258
259 /**
260 Called by the grid when the table is associated with it.
261
262 The default implementation stores the pointer and returns it from its
263 GetView() and so only makes sense if the table cannot be associated
264 with more than one grid at a time.
265 */
266 virtual void SetView(wxGrid *grid);
267
268 /**
269 Returns the last grid passed to SetView().
270 */
271 virtual wxGrid *GetView() const;
272
273
274 /**
275 @name Table Structure Modifiers
276
277 Notice that none of these functions are pure virtual as they don't have
278 to be implemented if the table structure is never modified after
279 creation, i.e. neither rows nor columns are never added or deleted but
280 that you do need to implement them if they are called, i.e. if your
281 code either calls them directly or uses the matching wxGrid methods, as
282 by default they simply do nothing which is definitely inappropriate.
283 */
284 //@{
285
286 /**
287 Clear the table contents.
288
289 This method is used by wxGrid::ClearGrid().
290 */
291 virtual void Clear();
292
293 /**
294 Insert additional rows into the table.
295
296 @param pos
297 The position of the first new row.
298 @param numRows
299 The number of rows to insert.
300 */
301 virtual bool InsertRows(size_t pos = 0, size_t numRows = 1);
302
303 /**
304 Append additional rows at the end of the table.
305
306 This method is provided in addition to InsertRows() as some data models
307 may only support appending rows to them but not inserting them at
308 arbitrary locations. In such case you may implement this method only
309 and leave InsertRows() unimplemented.
310
311 @param numRows
312 The number of rows to add.
313 */
314 virtual bool AppendRows(size_t numRows = 1);
315
316 /**
317 Delete rows from the table.
318
319 @param pos
320 The first row to delete.
321 @param numRows
322 The number of rows to delete.
323 */
324 virtual bool DeleteRows(size_t pos = 0, size_t numRows = 1);
325
326 /**
327 Exactly the same as InsertRows() but for columns.
328 */
329 virtual bool InsertCols(size_t pos = 0, size_t numCols = 1);
330
331 /**
332 Exactly the same as AppendRows() but for columns.
333 */
334 virtual bool AppendCols(size_t numCols = 1);
335
336 /**
337 Exactly the same as DeleteRows() but for columns.
338 */
339 virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1);
340
341 //@}
342
343 /**
344 @name Table Row and Column Labels
345
346 By default the numbers are used for labeling rows and Latin letters for
347 labeling columns. If the table has more than 26 columns, the pairs of
348 letters are used starting from the 27-th one and so on, i.e. the
349 sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ,
350 AAA, ...
351 */
352 //@{
353
354 /**
355 Return the label of the specified row.
356 */
357 virtual wxString GetRowLabelValue(int row);
358
359 /**
360 Return the label of the specified column.
361 */
362 virtual wxString GetColLabelValue(int col);
363
364 /**
365 Set the given label for the specified row.
366
367 The default version does nothing, i.e. the label is not stored. You
368 must override this method in your derived class if you wish
369 wxGrid::SetRowLabelValue() to work.
370 */
371 virtual void SetRowLabelValue(int row, const wxString& label);
372
373 /**
374 Exactly the same as SetRowLabelValue() but for columns.
375 */
376 virtual void SetColLabelValue(int col, const wxString& label);
377
378 //@}
379
380
381 /**
382 @name Attributes Management
383
384 By default the attributes management is delegated to
385 wxGridCellAttrProvider class. You may override the methods in this
386 section to handle the attributes directly if, for example, they can be
387 computed from the cell values.
388 */
389 //@{
390
391 /**
392 Associate this attributes provider with the table.
393
394 The table takes ownership of @a attrProvider pointer and will delete it
395 when it doesn't need it any more. The pointer can be @NULL, however
396 this won't disable attributes management in the table but will just
397 result in a default attributes being recreated the next time any of the
398 other functions in this section is called. To completely disable the
399 attributes support, should this be needed, you need to override
400 CanHaveAttributes() to return @false.
401 */
402 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
403
404 /**
405 Returns the attribute provider currently being used.
406
407 This function may return @NULL if the attribute provider hasn't been
408 neither associated with this table by SetAttrProvider() nor created on
409 demand by any other methods.
410 */
411 wxGridCellAttrProvider *GetAttrProvider() const;
412
413 /**
414 Return the attribute for the given cell.
415
416 By default this function is simply forwarded to
417 wxGridCellAttrProvider::GetAttr() but it may be overridden to handle
418 attributes directly in the table.
419 */
420 virtual wxGridCellAttr *GetAttr(int row, int col,
421 wxGridCellAttr::wxAttrKind kind);
422
423 /**
424 Set attribute of the specified cell.
425
426 By default this function is simply forwarded to
427 wxGridCellAttrProvider::SetAttr().
428
429 The table takes ownership of @a attr, i.e. will call DecRef() on it.
430 */
431 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
432
433 /**
434 Set attribute of the specified row.
435
436 By default this function is simply forwarded to
437 wxGridCellAttrProvider::SetRowAttr().
438
439 The table takes ownership of @a attr, i.e. will call DecRef() on it.
440 */
441 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
442
443 /**
444 Set attribute of the specified column.
445
446 By default this function is simply forwarded to
447 wxGridCellAttrProvider::SetColAttr().
448
449 The table takes ownership of @a attr, i.e. will call DecRef() on it.
450 */
451 virtual void SetColAttr(wxGridCellAttr *attr, int col);
452
453 //@}
454
455 /**
456 Returns true if this table supports attributes or false otherwise.
457
458 By default, the table automatically creates a wxGridCellAttrProvider
459 when this function is called if it had no attribute provider before and
460 returns @true.
461 */
462 virtual bool CanHaveAttributes();
463 };
464
465
466
467 /**
468 @class wxGridCellEditor
469
470 This class is responsible for providing and manipulating the in-place edit
471 controls for the grid. Instances of wxGridCellEditor (actually, instances
472 of derived classes since it is an abstract class) can be associated with
473 the cell attributes for individual cells, rows, columns, or even for the
474 entire grid.
475
476 @library{wxadv}
477 @category{grid}
478
479 @see wxGridCellBoolEditor, wxGridCellChoiceEditor, wxGridCellFloatEditor,
480 wxGridCellNumberEditor, wxGridCellTextEditor
481 */
482 class wxGridCellEditor
483 {
484 public:
485 /**
486 Default constructor.
487 */
488 wxGridCellEditor();
489
490 /**
491 Fetch the value from the table and prepare the edit control to begin
492 editing. Sets the focus to the edit control.
493 */
494 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
495
496 /**
497 Create a new object which is the copy of this one.
498 */
499 virtual wxGridCellEditor* Clone() const = 0;
500
501 /**
502 Creates the actual edit control.
503 */
504 virtual void Create(wxWindow* parent, wxWindowID id,
505 wxEvtHandler* evtHandler) = 0;
506
507 /**
508 Final cleanup.
509 */
510 virtual void Destroy();
511
512 /**
513 Complete the editing of the current cell. If necessary, the control may
514 be destroyed.
515
516 @return @true if the value has changed.
517 */
518 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
519
520 /**
521 Some types of controls on some platforms may need some help with the
522 Return key.
523 */
524 virtual void HandleReturn(wxKeyEvent& event);
525
526 /**
527 Returns @true if the edit control has been created.
528 */
529 bool IsCreated();
530
531 /**
532 Draws the part of the cell not occupied by the control: the base class
533 version just fills it with background colour from the attribute.
534 */
535 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr* attr);
536
537 /**
538 Reset the value in the control back to its starting value.
539 */
540 virtual void Reset() = 0;
541
542 /**
543 Size and position the edit control.
544 */
545 virtual void SetSize(const wxRect& rect);
546
547 /**
548 Show or hide the edit control, use the specified attributes to set
549 colours/fonts for it.
550 */
551 virtual void Show(bool show, wxGridCellAttr* attr = NULL);
552
553 /**
554 If the editor is enabled by clicking on the cell, this method will be
555 called.
556 */
557 virtual void StartingClick();
558
559 /**
560 If the editor is enabled by pressing keys on the grid, this will be
561 called to let the editor do something about that first key if desired.
562 */
563 virtual void StartingKey(wxKeyEvent& event);
564
565 protected:
566
567 /**
568 The destructor is private because only DecRef() can delete us.
569 */
570 virtual ~wxGridCellEditor();
571 };
572
573
574
575 /**
576 @class wxGridCellTextEditor
577
578 Grid cell editor for string/text data.
579
580 @library{wxadv}
581 @category{grid}
582
583 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
584 wxGridCellFloatEditor, wxGridCellNumberEditor
585 */
586 class wxGridCellTextEditor : public wxGridCellEditor
587 {
588 public:
589 /**
590 Default constructor.
591 */
592 wxGridCellTextEditor();
593
594 /**
595 The parameters string format is "n" where n is a number representing
596 the maximum width.
597 */
598 virtual void SetParameters(const wxString& params);
599 };
600
601
602
603 /**
604 @class wxGridCellStringRenderer
605
606 This class may be used to format string data in a cell; it is the default
607 for string cells.
608
609 @library{wxadv}
610 @category{grid}
611
612 @see wxGridCellRenderer, wxGridCellBoolRenderer, wxGridCellFloatRenderer,
613 wxGridCellNumberRenderer
614 */
615 class wxGridCellStringRenderer : public wxGridCellRenderer
616 {
617 public:
618 /**
619 Default constructor.
620 */
621 wxGridCellStringRenderer();
622 };
623
624
625
626 /**
627 @class wxGridCellChoiceEditor
628
629 The editor for string data allowing to choose from a list of strings.
630
631 @library{wxadv}
632 @category{grid}
633
634 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellFloatEditor,
635 wxGridCellNumberEditor, wxGridCellTextEditor
636 */
637 class wxGridCellChoiceEditor : public wxGridCellEditor
638 {
639 public:
640 /**
641 @param count
642 Number of strings from which the user can choose.
643 @param choices
644 An array of strings from which the user can choose.
645 @param allowOthers
646 If allowOthers is @true, the user can type a string not in choices
647 array.
648 */
649 wxGridCellChoiceEditor(size_t count = 0,
650 const wxString choices[] = NULL,
651 bool allowOthers = false);
652 /**
653 @param choices
654 An array of strings from which the user can choose.
655 @param allowOthers
656 If allowOthers is @true, the user can type a string not in choices
657 array.
658 */
659 wxGridCellChoiceEditor(const wxArrayString& choices,
660 bool allowOthers = false);
661
662 /**
663 Parameters string format is "item1[,item2[...,itemN]]"
664 */
665 virtual void SetParameters(const wxString& params);
666 };
667
668
669
670 /**
671 @class wxGridEditorCreatedEvent
672
673 @beginEventTable{wxGridEditorCreatedEvent}
674 @event{EVT_GRID_EDITOR_CREATED(func)}
675 The editor for a cell was created. Processes a
676 @c wxEVT_GRID_EDITOR_CREATED event type.
677 @event{EVT_GRID_CMD_EDITOR_CREATED(id, func)}
678 The editor for a cell was created; variant taking a window identifier.
679 Processes a @c wxEVT_GRID_EDITOR_CREATED event type.
680 @endEventTable
681
682 @library{wxadv}
683 @category{grid}
684 */
685 class wxGridEditorCreatedEvent : public wxCommandEvent
686 {
687 public:
688 /**
689 Default constructor.
690 */
691 wxGridEditorCreatedEvent();
692 /**
693 Constructor for initializing all event attributes.
694 */
695 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
696 int row, int col, wxControl* ctrl);
697
698 /**
699 Returns the column at which the event occurred.
700 */
701 int GetCol();
702
703 /**
704 Returns the edit control.
705 */
706 wxControl* GetControl();
707
708 /**
709 Returns the row at which the event occurred.
710 */
711 int GetRow();
712
713 /**
714 Sets the column at which the event occurred.
715 */
716 void SetCol(int col);
717
718 /**
719 Sets the edit control.
720 */
721 void SetControl(wxControl* ctrl);
722
723 /**
724 Sets the row at which the event occurred.
725 */
726 void SetRow(int row);
727 };
728
729
730
731 /**
732 @class wxGridRangeSelectEvent
733
734 @beginEventTable{wxGridRangeSelectEvent}
735 @event{EVT_GRID_RANGE_SELECT(func)}
736 The user selected a group of contiguous cells. Processes a
737 @c wxEVT_GRID_RANGE_SELECT event type.
738 @event{EVT_GRID_CMD_RANGE_SELECT(id, func)}
739 The user selected a group of contiguous cells; variant taking a window
740 identifier. Processes a @c wxEVT_GRID_RANGE_SELECT event type.
741 @endEventTable
742
743 @library{wxadv}
744 @category{grid}
745 */
746 class wxGridRangeSelectEvent : public wxNotifyEvent
747 {
748 public:
749 /**
750 Default constructor.
751 */
752 wxGridRangeSelectEvent();
753 /**
754 Constructor for initializing all event attributes.
755 */
756 wxGridRangeSelectEvent(int id, wxEventType type,
757 wxObject* obj,
758 const wxGridCellCoords& topLeft,
759 const wxGridCellCoords& bottomRight,
760 bool sel = true, bool control = false,
761 bool shift = false, bool alt = false,
762 bool meta = false);
763
764 /**
765 Returns @true if the Alt key was down at the time of the event.
766 */
767 bool AltDown() const;
768
769 /**
770 Returns @true if the Control key was down at the time of the event.
771 */
772 bool ControlDown() const;
773
774 /**
775 Top left corner of the rectangular area that was (de)selected.
776 */
777 wxGridCellCoords GetBottomRightCoords();
778
779 /**
780 Bottom row of the rectangular area that was (de)selected.
781 */
782 int GetBottomRow();
783
784 /**
785 Left column of the rectangular area that was (de)selected.
786 */
787 int GetLeftCol();
788
789 /**
790 Right column of the rectangular area that was (de)selected.
791 */
792 int GetRightCol();
793
794 /**
795 Top left corner of the rectangular area that was (de)selected.
796 */
797 wxGridCellCoords GetTopLeftCoords();
798
799 /**
800 Top row of the rectangular area that was (de)selected.
801 */
802 int GetTopRow();
803
804 /**
805 Returns @true if the Meta key was down at the time of the event.
806 */
807 bool MetaDown() const;
808
809 /**
810 Returns @true if the area was selected, @false otherwise.
811 */
812 bool Selecting();
813
814 /**
815 Returns @true if the Shift key was down at the time of the event.
816 */
817 bool ShiftDown() const;
818 };
819
820
821
822 /**
823 @class wxGridCellRenderer
824
825 This class is responsible for actually drawing the cell in the grid. You
826 may pass it to the wxGridCellAttr (below) to change the format of one given
827 cell or to wxGrid::SetDefaultRenderer() to change the view of all cells.
828 This is an abstract class, and you will normally use one of the predefined
829 derived classes or derive your own class from it.
830
831 @library{wxadv}
832 @category{grid}
833
834 @see wxGridCellBoolRenderer, wxGridCellFloatRenderer,
835 wxGridCellNumberRenderer, wxGridCellStringRenderer
836 */
837 class wxGridCellRenderer
838 {
839 public:
840 /**
841 This function must be implemented in derived classes to return a copy
842 of itself.
843 */
844 virtual wxGridCellRenderer* Clone() const = 0;
845
846 /**
847 Draw the given cell on the provided DC inside the given rectangle using
848 the style specified by the attribute and the default or selected state
849 corresponding to the isSelected value.
850
851 This pure virtual function has a default implementation which will
852 prepare the DC using the given attribute: it will draw the rectangle
853 with the background colour from attr and set the text colour and font.
854 */
855 virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
856 const wxRect& rect, int row, int col,
857 bool isSelected) = 0;
858
859 /**
860 Get the preferred size of the cell for its contents.
861 */
862 virtual wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
863 int row, int col) = 0;
864 };
865
866
867
868 /**
869 @class wxGridCellNumberEditor
870
871 Grid cell editor for numeric integer data.
872
873 @library{wxadv}
874 @category{grid}
875
876 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
877 wxGridCellFloatEditor, wxGridCellTextEditor
878 */
879 class wxGridCellNumberEditor : public wxGridCellTextEditor
880 {
881 public:
882 /**
883 Allows you to specify the range for acceptable data. Values equal to
884 -1 for both @a min and @a max indicate that no range checking should be
885 done.
886 */
887 wxGridCellNumberEditor(int min = -1, int max = -1);
888
889
890 /**
891 Parameters string format is "min,max".
892 */
893 virtual void SetParameters(const wxString& params);
894
895 protected:
896
897 /**
898 If the return value is @true, the editor uses a wxSpinCtrl to get user
899 input, otherwise it uses a wxTextCtrl.
900 */
901 bool HasRange() const;
902
903 /**
904 String representation of the value.
905 */
906 wxString GetString() const;
907 };
908
909
910
911 /**
912 @class wxGridSizeEvent
913
914 This event class contains information about a row/column resize event.
915
916 @beginEventTable{wxGridSizeEvent}
917 @event{EVT_GRID_COL_SIZE(func)}
918 The user resized a column by dragging it. Processes a
919 @c wxEVT_GRID_COL_SIZE event type.
920 @event{EVT_GRID_ROW_SIZE(func)}
921 The user resized a row by dragging it. Processes a
922 @c wxEVT_GRID_ROW_SIZE event type.
923 @event{EVT_GRID_CMD_COL_SIZE(id, func)}
924 The user resized a column by dragging it; variant taking a window
925 identifier. Processes a @c wxEVT_GRID_COL_SIZE event type.
926 @event{EVT_GRID_CMD_ROW_SIZE(id, func)}
927 The user resized a row by dragging it; variant taking a window
928 identifier. Processes a @c wxEVT_GRID_ROW_SIZE event type.
929 @endEventTable
930
931 @library{wxadv}
932 @category{grid}
933 */
934 class wxGridSizeEvent : public wxNotifyEvent
935 {
936 public:
937 /**
938 Default constructor.
939 */
940 wxGridSizeEvent();
941 /**
942 Constructor for initializing all event attributes.
943 */
944 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
945 int rowOrCol = -1, int x = -1, int y = -1,
946 bool control = false, bool shift = false,
947 bool alt = false, bool meta = false);
948
949 /**
950 Returns @true if the Alt key was down at the time of the event.
951 */
952 bool AltDown() const;
953
954 /**
955 Returns @true if the Control key was down at the time of the event.
956 */
957 bool ControlDown() const;
958
959 /**
960 Position in pixels at which the event occurred.
961 */
962 wxPoint GetPosition();
963
964 /**
965 Row or column at that was resized.
966 */
967 int GetRowOrCol();
968
969 /**
970 Returns @true if the Meta key was down at the time of the event.
971 */
972 bool MetaDown() const;
973
974 /**
975 Returns @true if the Shift key was down at the time of the event.
976 */
977 bool ShiftDown() const;
978 };
979
980
981
982 /**
983 @class wxGridCellNumberRenderer
984
985 This class may be used to format integer data in a cell.
986
987 @library{wxadv}
988 @category{grid}
989
990 @see wxGridCellRenderer, wxGridCellBoolRenderer, wxGridCellFloatRenderer,
991 wxGridCellStringRenderer
992 */
993 class wxGridCellNumberRenderer : public wxGridCellStringRenderer
994 {
995 public:
996 /**
997 Default constructor
998 */
999 wxGridCellNumberRenderer();
1000 };
1001
1002
1003
1004 /**
1005 @class wxGridCellAttr
1006
1007 This class can be used to alter the cells' appearance in
1008 the grid by changing their colour/font/... from default. An object of this
1009 class may be returned by wxGridTableBase::GetAttr.
1010
1011 @library{wxadv}
1012 @category{grid}
1013 */
1014 class wxGridCellAttr
1015 {
1016 public:
1017 //@{
1018 /**
1019 Constructor specifying some of the often used attributes.
1020 */
1021 wxGridCellAttr();
1022 wxGridCellAttr(const wxColour& colText,
1023 const wxColour& colBack,
1024 const wxFont& font,
1025 int hAlign, int vAlign);
1026 //@}
1027
1028 /**
1029 Creates a new copy of this object.
1030 */
1031 wxGridCellAttr* Clone() const;
1032
1033 /**
1034
1035 */
1036 void DecRef();
1037
1038 /**
1039 See SetAlignment() for the returned values.
1040 */
1041 void GetAlignment(int* hAlign, int* vAlign) const;
1042
1043 /**
1044
1045 */
1046 const wxColour& GetBackgroundColour() const;
1047
1048 /**
1049
1050 */
1051 wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const;
1052
1053 /**
1054
1055 */
1056 const wxFont& GetFont() const;
1057
1058 /**
1059
1060 */
1061 wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const;
1062
1063 /**
1064
1065 */
1066 const wxColour& GetTextColour() const;
1067
1068 /**
1069
1070 */
1071 bool HasAlignment() const;
1072
1073 /**
1074
1075 */
1076 bool HasBackgroundColour() const;
1077
1078 /**
1079
1080 */
1081 bool HasEditor() const;
1082
1083 /**
1084
1085 */
1086 bool HasFont() const;
1087
1088 /**
1089
1090 */
1091 bool HasRenderer() const;
1092
1093 /**
1094 accessors
1095 */
1096 bool HasTextColour() const;
1097
1098 /**
1099 This class is ref counted: it is created with ref count of 1, so
1100 calling DecRef() once will delete it. Calling IncRef() allows to lock
1101 it until the matching DecRef() is called
1102 */
1103 void IncRef();
1104
1105 /**
1106
1107 */
1108 bool IsReadOnly() const;
1109
1110 /**
1111 Sets the alignment. @a hAlign can be one of @c wxALIGN_LEFT,
1112 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT and @a vAlign can be one
1113 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
1114 */
1115 void SetAlignment(int hAlign, int vAlign);
1116
1117 /**
1118 Sets the background colour.
1119 */
1120 void SetBackgroundColour(const wxColour& colBack);
1121
1122 /**
1123
1124 */
1125 void SetDefAttr(wxGridCellAttr* defAttr);
1126
1127 /**
1128
1129 */
1130 void SetEditor(wxGridCellEditor* editor);
1131
1132 /**
1133 Sets the font.
1134 */
1135 void SetFont(const wxFont& font);
1136
1137 /**
1138
1139 */
1140 void SetReadOnly(bool isReadOnly = true);
1141
1142 /**
1143 takes ownership of the pointer
1144 */
1145 void SetRenderer(wxGridCellRenderer* renderer);
1146
1147 /**
1148 Sets the text colour.
1149 */
1150 void SetTextColour(const wxColour& colText);
1151 };
1152
1153
1154
1155 /**
1156 @class wxGridCellBoolRenderer
1157
1158 This class may be used to format boolean data in a cell.
1159 for string cells.
1160
1161 @library{wxadv}
1162 @category{grid}
1163
1164 @see wxGridCellRenderer, wxGridCellStringRenderer, wxGridCellFloatRenderer,
1165 wxGridCellNumberRenderer
1166 */
1167 class wxGridCellBoolRenderer : public wxGridCellRenderer
1168 {
1169 public:
1170 /**
1171 Default constructor
1172 */
1173 wxGridCellBoolRenderer();
1174 };
1175
1176
1177
1178 /**
1179 @class wxGridEvent
1180
1181 This event class contains information about various grid events.
1182
1183 @library{wxadv}
1184 @category{grid}
1185 */
1186 class wxGridEvent : public wxNotifyEvent
1187 {
1188 public:
1189 //@{
1190 /**
1191
1192 */
1193 wxGridEvent();
1194 wxGridEvent(int id, wxEventType type, wxObject* obj,
1195 int row = -1, int col = -1,
1196 int x = -1, int y = -1,
1197 bool sel = true,
1198 bool control = false,
1199 bool shift = false,
1200 bool alt = false,
1201 bool meta = false);
1202 //@}
1203
1204 /**
1205 Returns @true if the Alt key was down at the time of the event.
1206 */
1207 bool AltDown() const;
1208
1209 /**
1210 Returns @true if the Control key was down at the time of the event.
1211 */
1212 bool ControlDown() const;
1213
1214 /**
1215 Column at which the event occurred.
1216 */
1217 virtual int GetCol();
1218
1219 /**
1220 Position in pixels at which the event occurred.
1221 */
1222 wxPoint GetPosition();
1223
1224 /**
1225 Row at which the event occurred.
1226 */
1227 virtual int GetRow();
1228
1229 /**
1230 Returns @true if the Meta key was down at the time of the event.
1231 */
1232 bool MetaDown() const;
1233
1234 /**
1235 Returns @true if the user is selecting grid cells, @false -- if
1236 deselecting.
1237 */
1238 bool Selecting();
1239
1240 /**
1241 Returns @true if the Shift key was down at the time of the event.
1242 */
1243 bool ShiftDown() const;
1244 };
1245
1246
1247
1248 /**
1249 @class wxGridCellFloatEditor
1250
1251 The editor for floating point numbers data.
1252
1253 @library{wxadv}
1254 @category{grid}
1255
1256 @see wxGridCellEditor, wxGridCellNumberEditor, wxGridCellBoolEditor,
1257 wxGridCellTextEditor, wxGridCellChoiceEditor
1258 */
1259 class wxGridCellFloatEditor : public wxGridCellTextEditor
1260 {
1261 public:
1262 /**
1263 @param width
1264 Minimum number of characters to be shown.
1265 @param precision
1266 Number of digits after the decimal dot.
1267 */
1268 wxGridCellFloatEditor(int width = -1, int precision = -1);
1269
1270 /**
1271 Parameters string format is "width,precision"
1272 */
1273 virtual void SetParameters(const wxString& params);
1274 };
1275
1276
1277
1278 /**
1279 @class wxGrid
1280
1281 wxGrid and its related classes are used for displaying and editing tabular
1282 data.
1283 They provide a rich set of features for display, editing, and interacting
1284 with a variety of data sources. For simple applications, and to help you
1285 get started, wxGrid is the only class you need to refer to directly. It
1286 will set up default instances of the other classes and manage them for you.
1287 For more complex applications you can derive your own classes for custom
1288 grid views, grid data tables, cell editors and renderers. The @ref
1289 overview_grid "wxGrid overview" has examples of simple and more complex applications,
1290 explains the relationship between the various grid classes and has a
1291 summary of the keyboard shortcuts and mouse functions provided by wxGrid.
1292
1293 wxGrid has been greatly expanded and redesigned for wxWidgets 2.2 onwards.
1294 The new grid classes are reasonably backward-compatible but there are some
1295 exceptions. There are also easier ways of doing many things compared to the
1296 previous implementation.
1297
1298 A wxGridTableBase class holds the actual data to be displayed by a wxGrid
1299 class. One or more wxGrid classes may act as a view for one table class.
1300 The default table class is called wxGridStringTable and holds an array of
1301 strings. An instance of such a class is created by wxGrid::CreateGrid.
1302
1303 wxGridCellRenderer is the abstract base class for rendereing contents in a
1304 cell. The following renderers are predefined:
1305 - wxGridCellStringRenderer,
1306 - wxGridCellBoolRenderer,
1307 - wxGridCellFloatRenderer,
1308 - wxGridCellNumberRenderer.
1309 The look of a cell can be further defined using wxGridCellAttr. An object
1310 of this type may be returned by wxGridTableBase::GetAttr.
1311
1312 wxGridCellEditor is the abstract base class for editing the value of a
1313 cell. The following editors are predefined:
1314 - wxGridCellTextEditor
1315 - wxGridCellBoolEditor
1316 - wxGridCellChoiceEditor
1317 - wxGridCellNumberEditor.
1318
1319 @library{wxadv}
1320 @category{grid}
1321
1322 @see @ref overview_grid "wxGrid overview"
1323 */
1324 class wxGrid : public wxScrolledWindow
1325 {
1326 public:
1327 /**
1328 Different selection modes supported by the grid.
1329 */
1330 enum wxGridSelectionModes
1331 {
1332 /**
1333 The default selection mode allowing selection of the individual
1334 cells as well as of the entire rows and columns.
1335 */
1336 wxGridSelectCells,
1337
1338 /**
1339 The selection mode allowing the selection of the entire rows only.
1340
1341 The user won't be able to select any cells or columns in this mode.
1342 */
1343 wxGridSelectRows,
1344
1345 /**
1346 The selection mode allowing the selection of the entire columns only.
1347
1348 The user won't be able to select any cells or rows in this mode.
1349 */
1350 wxGridSelectColumns
1351 };
1352
1353 /**
1354 Default constructor.
1355
1356 You must call Create() to really create the grid window and also call
1357 CreateGrid() or SetTable() to initialize the grid contents.
1358 */
1359 wxGrid();
1360
1361 /**
1362 Constructor creating the grid window.
1363
1364 You must call either CreateGrid() or SetTable() to initialize the grid
1365 contents before using it.
1366 */
1367 wxGrid(wxWindow* parent,
1368 wxWindowID id,
1369 const wxPoint& pos = wxDefaultPosition,
1370 const wxSize& size = wxDefaultSize,
1371 long style = wxWANTS_CHARS,
1372 const wxString& name = wxGridNameStr);
1373
1374 /**
1375 Creates the grid window for an object initialized using the default
1376 constructor.
1377
1378 You must call either CreateGrid() or SetTable() to initialize the grid
1379 contents before using it.
1380 */
1381 bool Create(wxWindow* parent,
1382 wxWindowID id,
1383 const wxPoint& pos = wxDefaultPosition,
1384 const wxSize& size = wxDefaultSize,
1385 long style = wxWANTS_CHARS,
1386 const wxString& name = wxGridNameStr);
1387
1388 /**
1389 Destructor.
1390
1391 This will also destroy the associated grid table unless you passed a
1392 table object to the grid and specified that the grid should not take
1393 ownership of the table (see wxGrid::SetTable).
1394 */
1395 virtual ~wxGrid();
1396
1397 /**
1398 Appends one or more new columns to the right of the grid.
1399
1400 The @a updateLabels argument is not used at present. If you are using a
1401 derived grid table class you will need to override
1402 wxGridTableBase::AppendCols. See InsertCols() for further information.
1403
1404 @return @true on success or @false if appending columns failed.
1405 */
1406 bool AppendCols(int numCols = 1, bool updateLabels = true);
1407
1408 /**
1409 Appends one or more new rows to the bottom of the grid.
1410
1411 The @a updateLabels argument is not used at present. If you are using a
1412 derived grid table class you will need to override
1413 wxGridTableBase::AppendRows. See InsertRows() for further information.
1414
1415 @return @true on success or @false if appending rows failed.
1416 */
1417 bool AppendRows(int numRows = 1, bool updateLabels = true);
1418
1419 /**
1420 Return @true if the horizontal grid lines stop at the last column
1421 boundary or @false if they continue to the end of the window.
1422
1423 The default is to clip grid lines.
1424
1425 @see ClipHorzGridLines(), AreVertGridLinesClipped()
1426 */
1427 bool AreHorzGridLinesClipped() const;
1428
1429 /**
1430 Return @true if the vertical grid lines stop at the last row
1431 boundary or @false if they continue to the end of the window.
1432
1433 The default is to clip grid lines.
1434
1435 @see ClipVertGridLines(), AreHorzGridLinesClipped()
1436 */
1437 bool AreVertGridLinesClipped() const;
1438
1439 /**
1440 Automatically sets the height and width of all rows and columns to fit their
1441 contents.
1442 */
1443 void AutoSize();
1444
1445 /**
1446 Automatically adjusts width of the column to fit its label.
1447 */
1448 void AutoSizeColLabelSize(int col);
1449
1450 /**
1451 Automatically sizes the column to fit its contents. If setAsMin is @true the
1452 calculated width will
1453 also be set as the minimal width for the column.
1454 */
1455 void AutoSizeColumn(int col, bool setAsMin = true);
1456
1457 /**
1458 Automatically sizes all columns to fit their contents. If setAsMin is @true the
1459 calculated widths will
1460 also be set as the minimal widths for the columns.
1461 */
1462 void AutoSizeColumns(bool setAsMin = true);
1463
1464 /**
1465 Automatically sizes the row to fit its contents. If setAsMin is @true the
1466 calculated height will
1467 also be set as the minimal height for the row.
1468 */
1469 void AutoSizeRow(int row, bool setAsMin = true);
1470
1471 /**
1472 Automatically adjusts height of the row to fit its label.
1473 */
1474 void AutoSizeRowLabelSize(int col);
1475
1476 /**
1477 Automatically sizes all rows to fit their contents. If setAsMin is @true the
1478 calculated heights will
1479 also be set as the minimal heights for the rows.
1480 */
1481 void AutoSizeRows(bool setAsMin = true);
1482
1483 /**
1484 Increments the grid's batch count.
1485
1486 When the count is greater than zero repainting of the grid is
1487 suppressed. Each call to BeginBatch must be matched by a later call to
1488 EndBatch(). Code that does a lot of grid modification can be enclosed
1489 between BeginBatch and EndBatch calls to avoid screen flicker. The
1490 final EndBatch will cause the grid to be repainted.
1491
1492 Notice that you should use wxGridUpdateLocker which ensures that there
1493 is always a matching EndBatch() call for this BeginBatch() if possible
1494 instead of calling this method directly.
1495 */
1496 void BeginBatch();
1497
1498 /**
1499 Convert grid cell coordinates to grid window pixel coordinates.
1500
1501 This function returns the rectangle that encloses the block of cells
1502 limited by @a topLeft and @a bottomRight cell in device coords and
1503 clipped to the client size of the grid window.
1504
1505 @see CellToRect()
1506 */
1507 wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft,
1508 const wxGridCellCoords& bottomRight) const;
1509
1510 /**
1511 Returns @true if columns can be moved by dragging with the mouse.
1512
1513 Columns can be moved by dragging on their labels.
1514 */
1515 bool CanDragColMove() const;
1516
1517 /**
1518 Returns @true if columns can be resized by dragging with the mouse.
1519
1520 Columns can be resized by dragging the edges of their labels. If grid
1521 line dragging is enabled they can also be resized by dragging the right
1522 edge of the column in the grid cell area (see
1523 wxGrid::EnableDragGridSize).
1524 */
1525 bool CanDragColSize() const;
1526
1527 /**
1528 Return @true if the dragging of grid lines to resize rows and columns
1529 is enabled or @false otherwise.
1530 */
1531 bool CanDragGridSize() const;
1532
1533 /**
1534 Returns @true if rows can be resized by dragging with the mouse.
1535
1536 Rows can be resized by dragging the edges of their labels. If grid line
1537 dragging is enabled they can also be resized by dragging the lower edge
1538 of the row in the grid cell area (see wxGrid::EnableDragGridSize).
1539 */
1540 bool CanDragRowSize() const;
1541
1542 /**
1543 Returns @true if the in-place edit control for the current grid cell
1544 can be used and @false otherwise.
1545
1546 This function always returns @false for the read-only cells.
1547 */
1548 bool CanEnableCellControl() const;
1549
1550 //@{
1551 /**
1552 Return the rectangle corresponding to the grid cell's size and position
1553 in logical coordinates.
1554
1555 @see BlockToDeviceRect()
1556 */
1557 wxRect CellToRect(int row, int col) const;
1558 const wxRect CellToRect(const wxGridCellCoords& coords) const;
1559
1560 //@}
1561
1562 /**
1563 Clears all data in the underlying grid table and repaints the grid.
1564
1565 The table is not deleted by this function. If you are using a derived
1566 table class then you need to override wxGridTableBase::Clear() for this
1567 function to have any effect.
1568 */
1569 void ClearGrid();
1570
1571 /**
1572 Deselects all cells that are currently selected.
1573 */
1574 void ClearSelection();
1575
1576 /**
1577 Change whether the horizontal grid lines are clipped by the end of the
1578 last column.
1579
1580 By default the grid lines are not drawn beyond the end of the last
1581 column but after calling this function with @a clip set to @false they
1582 will be drawn across the entire grid window.
1583
1584 @see AreHorzGridLinesClipped(), ClipVertGridLines()
1585 */
1586 void ClipHorzGridLines(bool clip);
1587
1588 /**
1589 Change whether the vertical grid lines are clipped by the end of the
1590 last row.
1591
1592 By default the grid lines are not drawn beyond the end of the last
1593 row but after calling this function with @a clip set to @false they
1594 will be drawn across the entire grid window.
1595
1596 @see AreVertzGridLinesClipped(), ClipHorzGridLines()
1597 */
1598 void ClipVertzGridLines(bool clip);
1599
1600 /**
1601 Creates a grid with the specified initial number of rows and columns.
1602
1603 Call this directly after the grid constructor. When you use this
1604 function wxGrid will create and manage a simple table of string values
1605 for you. All of the grid data will be stored in memory.
1606 For applications with more complex data types or relationships, or for
1607 dealing with very large datasets, you should derive your own grid table
1608 class and pass a table object to the grid with SetTable().
1609 */
1610 bool CreateGrid(int numRows, int numCols,
1611 wxGridSelectionModes selmode = wxGridSelectCells);
1612
1613 /**
1614 Deletes one or more columns from a grid starting at the specified
1615 position.
1616
1617 The @a updateLabels argument is not used at present. If you are using a
1618 derived grid table class you will need to override
1619 wxGridTableBase::DeleteCols. See InsertCols() for further information.
1620
1621 @return @true on success or @false if deleting columns failed.
1622 */
1623 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true);
1624
1625 /**
1626 Deletes one or more rows from a grid starting at the specified position.
1627
1628 The @a updateLabels argument is not used at present. If you are using a
1629 derived grid table class you will need to override
1630 wxGridTableBase::DeleteRows. See InsertRows() for further information.
1631
1632 @return @true on success or @false if appending rows failed.
1633 */
1634 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true);
1635
1636 /**
1637 Disables in-place editing of grid cells.
1638
1639 Equivalent to calling EnableCellEditControl(@false).
1640 */
1641 void DisableCellEditControl();
1642
1643 /**
1644 Disables column moving by dragging with the mouse.
1645
1646 Equivalent to passing @false to EnableDragColMove().
1647 */
1648 void DisableDragColMove();
1649
1650 /**
1651 Disables column sizing by dragging with the mouse.
1652
1653 Equivalent to passing @false to EnableDragColSize().
1654 */
1655 void DisableDragColSize();
1656
1657 /**
1658 Disable mouse dragging of grid lines to resize rows and columns.
1659
1660 Equivalent to passing @false to EnableDragGridSize()
1661 */
1662 void DisableDragGridSize();
1663
1664 /**
1665 Disables row sizing by dragging with the mouse.
1666
1667 Equivalent to passing @false to EnableDragRowSize().
1668 */
1669 void DisableDragRowSize();
1670
1671 /**
1672 Enables or disables in-place editing of grid cell data.
1673
1674 The grid will issue either a wxEVT_GRID_EDITOR_SHOWN or
1675 wxEVT_GRID_EDITOR_HIDDEN event.
1676 */
1677 void EnableCellEditControl(bool enable = true);
1678
1679 /**
1680 Enables or disables column moving by dragging with the mouse.
1681 */
1682 void EnableDragColMove(bool enable = true);
1683
1684 /**
1685 Enables or disables column sizing by dragging with the mouse.
1686 */
1687 void EnableDragColSize(bool enable = true);
1688
1689 /**
1690 Enables or disables row and column resizing by dragging gridlines with the
1691 mouse.
1692 */
1693 void EnableDragGridSize(bool enable = true);
1694
1695 /**
1696 Enables or disables row sizing by dragging with the mouse.
1697 */
1698 void EnableDragRowSize(bool enable = true);
1699
1700 /**
1701 Makes the grid globally editable or read-only.
1702
1703 If the edit argument is @false this function sets the whole grid as
1704 read-only. If the argument is @true the grid is set to the default
1705 state where cells may be editable. In the default state you can set
1706 single grid cells and whole rows and columns to be editable or
1707 read-only via wxGridCellAttribute::SetReadOnly. For single cells you
1708 can also use the shortcut function SetReadOnly().
1709
1710 For more information about controlling grid cell attributes see the
1711 wxGridCellAttr cell attribute class and the
1712 @ref overview_grid "wxGrid overview".
1713 */
1714 void EnableEditing(bool edit);
1715
1716 /**
1717 Turns the drawing of grid lines on or off.
1718 */
1719 void EnableGridLines(bool enable = true);
1720
1721 /**
1722 Decrements the grid's batch count.
1723
1724 When the count is greater than zero repainting of the grid is
1725 suppressed. Each previous call to BeginBatch() must be matched by a
1726 later call to EndBatch. Code that does a lot of grid modification can
1727 be enclosed between BeginBatch and EndBatch calls to avoid screen
1728 flicker. The final EndBatch will cause the grid to be repainted.
1729
1730 @see wxGridUpdateLocker
1731 */
1732 void EndBatch();
1733
1734 /**
1735 Overridden wxWindow method.
1736 */
1737 virtual void Fit();
1738
1739 /**
1740 Causes immediate repainting of the grid.
1741
1742 Use this instead of the usual wxWindow::Refresh.
1743 */
1744 void ForceRefresh();
1745
1746 /**
1747 Returns the number of times that BeginBatch() has been called
1748 without (yet) matching calls to EndBatch(). While
1749 the grid's batch count is greater than zero the display will not be updated.
1750 */
1751 int GetBatchCount();
1752
1753 /**
1754 Sets the arguments to the horizontal and vertical text alignment values
1755 for the grid cell at the specified location.
1756
1757 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1758 or @c wxALIGN_RIGHT.
1759
1760 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1761 @c wxALIGN_BOTTOM.
1762 */
1763 void GetCellAlignment(int row, int col, int* horiz, int* vert) const;
1764
1765 /**
1766 Returns the background colour of the cell at the specified location.
1767 */
1768 wxColour GetCellBackgroundColour(int row, int col) const;
1769
1770 /**
1771 Returns a pointer to the editor for the cell at the specified location.
1772
1773 See wxGridCellEditor and the @ref overview_grid "wxGrid overview"
1774 for more information about cell editors and renderers.
1775
1776 The caller must call DecRef() on the returned pointer.
1777 */
1778 wxGridCellEditor* GetCellEditor(int row, int col) const;
1779
1780 /**
1781 Returns the font for text in the grid cell at the specified location.
1782 */
1783 wxFont GetCellFont(int row, int col) const;
1784
1785 /**
1786 Returns a pointer to the renderer for the grid cell at the specified
1787 location.
1788
1789 See wxGridCellRenderer and the @ref overview_grid "wxGrid overview"
1790 for more information about cell editors and renderers.
1791
1792 The caller must call DecRef() on the returned pointer.
1793 */
1794 wxGridCellRenderer* GetCellRenderer(int row, int col) const;
1795
1796 /**
1797 Returns the text colour for the grid cell at the specified location.
1798 */
1799 wxColour GetCellTextColour(int row, int col) const;
1800
1801 //@{
1802 /**
1803 Returns the string contained in the cell at the specified location.
1804
1805 For simple applications where a grid object automatically uses a
1806 default grid table of string values you use this function together with
1807 SetCellValue() to access cell values. For more complex applications
1808 where you have derived your own grid table class that contains various
1809 data types (e.g. numeric, boolean or user-defined custom types) then
1810 you only use this function for those cells that contain string values.
1811
1812 See wxGridTableBase::CanGetValueAs and the @ref overview_grid "wxGrid overview"
1813 for more information.
1814 */
1815 wxString GetCellValue(int row, int col) const;
1816 const wxString GetCellValue(const wxGridCellCoords& coords) const;
1817 //@}
1818
1819 /**
1820 Returns the column ID of the specified column position.
1821 */
1822 int GetColAt(int colPos) const;
1823
1824 /**
1825 Returns the pen used for vertical grid lines.
1826
1827 This virtual function may be overridden in derived classes in order to
1828 change the appearance of individual grid lines for the given column @e
1829 col.
1830
1831 See GetRowGridLinePen() for an example.
1832 */
1833 virtual wxPen GetColGridLinePen(int col);
1834
1835 /**
1836 Sets the arguments to the current column label alignment values.
1837
1838 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1839 or @c wxALIGN_RIGHT.
1840
1841 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1842 @c wxALIGN_BOTTOM.
1843 */
1844 void GetColLabelAlignment(int* horiz, int* vert) const;
1845
1846 /**
1847 Returns the current height of the column labels.
1848 */
1849 int GetColLabelSize() const;
1850
1851 /**
1852 Returns the specified column label.
1853
1854 The default grid table class provides column labels of the form
1855 A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can
1856 override wxGridTableBase::GetColLabelValue to provide your own labels.
1857 */
1858 wxString GetColLabelValue(int col) const;
1859
1860 /**
1861 Returns the minimal width to which a column may be resized.
1862
1863 Use SetColMinimalAcceptableWidth() to change this value globally or
1864 SetColMinimalWidth() to do it for individual columns.
1865 */
1866 int GetColMinimalAcceptableWidth() const;
1867
1868 /**
1869 Returns the position of the specified column.
1870 */
1871 int GetColPos(int colID) const;
1872
1873 /**
1874 Returns the width of the specified column.
1875 */
1876 int GetColSize(int col) const;
1877
1878 /**
1879 Returns the default cell alignment.
1880
1881 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1882 or @c wxALIGN_RIGHT.
1883
1884 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1885 @c wxALIGN_BOTTOM.
1886
1887 @see SetDefaultCellAlignment()
1888 */
1889 void GetDefaultCellAlignment(int* horiz, int* vert) const;
1890
1891 /**
1892 Returns the current default background colour for grid cells.
1893 */
1894 wxColour GetDefaultCellBackgroundColour() const;
1895
1896 /**
1897 Returns the current default font for grid cell text.
1898 */
1899 wxFont GetDefaultCellFont() const;
1900
1901 /**
1902 Returns the current default colour for grid cell text.
1903 */
1904 wxColour GetDefaultCellTextColour() const;
1905
1906 /**
1907 Returns the default height for column labels.
1908 */
1909 int GetDefaultColLabelSize() const;
1910
1911 /**
1912 Returns the current default width for grid columns.
1913 */
1914 int GetDefaultColSize() const;
1915
1916 /**
1917 Returns a pointer to the current default grid cell editor.
1918
1919 See wxGridCellEditor and the @ref overview_grid "wxGrid overview"
1920 for more information about cell editors and renderers.
1921 */
1922 wxGridCellEditor* GetDefaultEditor() const;
1923
1924 //@{
1925 /**
1926 Returns the default editor for the specified cell.
1927
1928 The base class version returns the editor appropriate for the current
1929 cell type but this method may be overridden in the derived classes to
1930 use custom editors for some cells by default.
1931
1932 Notice that the same may be usually achieved in simpler way by
1933 associating a custom editor with the given cell or cells.
1934
1935 The caller must call DecRef() on the returned pointer.
1936 */
1937 virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1938 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const;
1939 //@}
1940
1941 /**
1942 Returns the default editor for the cells containing values of the given
1943 type.
1944
1945 The base class version returns the editor which was associated with the
1946 specified @a typeName when it was registered RegisterDataType() but
1947 this function may be overridden to return something different. This
1948 allows to override an editor used for one of the standard types.
1949
1950 The caller must call DecRef() on the returned pointer.
1951 */
1952 virtual wxGridCellEditor *
1953 GetDefaultEditorForType(const wxString& typeName) const;
1954
1955 /**
1956 Returns the pen used for grid lines.
1957
1958 This virtual function may be overridden in derived classes in order to
1959 change the appearance of grid lines. Note that currently the pen width
1960 must be 1.
1961
1962 @see GetColGridLinePen(), GetRowGridLinePen()
1963 */
1964 virtual wxPen GetDefaultGridLinePen();
1965
1966 /**
1967 Returns a pointer to the current default grid cell renderer.
1968
1969 See wxGridCellRenderer and the @ref overview_grid "wxGrid overview"
1970 for more information about cell editors and renderers.
1971
1972 The caller must call DecRef() on the returned pointer.
1973 */
1974 wxGridCellRenderer* GetDefaultRenderer() const;
1975
1976 /**
1977 Returns the default renderer for the given cell.
1978
1979 The base class version returns the renderer appropriate for the current
1980 cell type but this method may be overridden in the derived classes to
1981 use custom renderers for some cells by default.
1982
1983 The caller must call DecRef() on the returned pointer.
1984 */
1985 virtual wxGridCellRenderer *GetDefaultRendererForCell(int row, int col) const;
1986
1987 /**
1988 Returns the default renderer for the cell containing values of the
1989 given type.
1990
1991 @see GetDefaultEditorForType()
1992 */
1993 virtual wxGridCellRenderer *
1994 GetDefaultRendererForType(const wxString& typeName) const;
1995
1996 /**
1997 Returns the default width for the row labels.
1998 */
1999 int GetDefaultRowLabelSize() const;
2000
2001 /**
2002 Returns the current default height for grid rows.
2003 */
2004 int GetDefaultRowSize() const;
2005
2006 /**
2007 Returns the current grid cell column position.
2008 */
2009 int GetGridCursorCol() const;
2010
2011 /**
2012 Returns the current grid cell row position.
2013 */
2014 int GetGridCursorRow() const;
2015
2016 /**
2017 Returns the colour used for grid lines.
2018
2019 @see GetDefaultGridLinePen()
2020 */
2021 wxColour GetGridLineColour() const;
2022
2023 /**
2024 Returns the colour used for the background of row and column labels.
2025 */
2026 wxColour GetLabelBackgroundColour() const;
2027
2028 /**
2029 Returns the font used for row and column labels.
2030 */
2031 wxFont GetLabelFont() const;
2032
2033 /**
2034 Returns the colour used for row and column label text.
2035 */
2036 wxColour GetLabelTextColour() const;
2037
2038 /**
2039 Returns the total number of grid columns.
2040
2041 This is the same as the number of columns in the underlying grid
2042 table.
2043 */
2044 int GetNumberCols() const;
2045
2046 /**
2047 Returns the total number of grid rows.
2048
2049 This is the same as the number of rows in the underlying grid table.
2050 */
2051 int GetNumberRows() const;
2052
2053 /**
2054 Returns the attribute for the given cell creating one if necessary.
2055
2056 If the cell already has an attribute, it is returned. Otherwise a new
2057 attribute is created, associated with the cell and returned. In any
2058 case the caller must call DecRef() on the returned pointer.
2059
2060 This function may only be called if CanHaveAttributes() returns @true.
2061 */
2062 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
2063
2064 /**
2065 Returns the pen used for horizontal grid lines.
2066
2067 This virtual function may be overridden in derived classes in order to
2068 change the appearance of individual grid line for the given row @e row.
2069
2070 Example:
2071 @code
2072 // in a grid displaying music notation, use a solid black pen between
2073 // octaves (C0=row 127, C1=row 115 etc.)
2074 wxPen MidiGrid::GetRowGridLinePen(int row)
2075 {
2076 if ( row % 12 == 7 )
2077 return wxPen(*wxBLACK, 1, wxSOLID);
2078 else
2079 return GetDefaultGridLinePen();
2080 }
2081 @endcode
2082 */
2083 virtual wxPen GetRowGridLinePen(int row);
2084
2085 /**
2086 Returns the alignment used for row labels.
2087
2088 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
2089 or @c wxALIGN_RIGHT.
2090
2091 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
2092 @c wxALIGN_BOTTOM.
2093 */
2094 void GetRowLabelAlignment(int* horiz, int* vert) const;
2095
2096 /**
2097 Returns the current width of the row labels.
2098 */
2099 int GetRowLabelSize() const;
2100
2101 /**
2102 Returns the specified row label.
2103
2104 The default grid table class provides numeric row labels. If you are
2105 using a custom grid table you can override
2106 wxGridTableBase::GetRowLabelValue to provide your own labels.
2107 */
2108 wxString GetRowLabelValue(int row) const;
2109
2110 /**
2111 Returns the minimal size to which rows can be resized.
2112
2113 Use SetRowMinimalAcceptableHeight() to change this value globally or
2114 SetRowMinimalHeight() to do it for individual cells.
2115
2116 @see GetColMinimalAcceptableWidth()
2117 */
2118 int GetRowMinimalAcceptableHeight() const;
2119
2120 /**
2121 Returns the height of the specified row.
2122 */
2123 int GetRowSize(int row) const;
2124
2125 /**
2126 Returns the number of pixels per horizontal scroll increment.
2127
2128 The default is 15.
2129
2130 @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY()
2131 */
2132 int GetScrollLineX() const;
2133
2134 /**
2135 Returns the number of pixels per vertical scroll increment.
2136
2137 The default is 15.
2138
2139 @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY()
2140 */
2141 int GetScrollLineY() const;
2142
2143 /**
2144 Returns an array of individually selected cells.
2145
2146 Notice that this array does @em not contain all the selected cells in
2147 general as it doesn't include the cells selected as part of column, row
2148 or block selection. You must use this method, GetSelectedCols(),
2149 GetSelectedRows() and GetSelectionBlockTopLeft() and
2150 GetSelectionBlockBottomRight() methods to obtain the entire selection
2151 in general.
2152
2153 Please notice this behaviour is by design and is needed in order to
2154 support grids of arbitrary size (when an entire column is selected in
2155 a grid with a million of columns, we don't want to create an array with
2156 a million of entries in this function, instead it returns an empty
2157 array and GetSelectedCols() returns an array containing one element).
2158 */
2159 wxGridCellCoordsArray GetSelectedCells() const;
2160
2161 /**
2162 Returns an array of selected columns.
2163
2164 Please notice that this method alone is not sufficient to find all the
2165 selected columns as it contains only the columns which were
2166 individually selected but not those being part of the block selection
2167 or being selected in virtue of all of their cells being selected
2168 individually, please see GetSelectedCells() for more details.
2169 */
2170 wxArrayInt GetSelectedCols() const;
2171
2172 /**
2173 Returns an array of selected rows.
2174
2175 Please notice that this method alone is not sufficient to find all the
2176 selected rows as it contains only the rows which were individually
2177 selected but not those being part of the block selection or being
2178 selected in virtue of all of their cells being selected individually,
2179 please see GetSelectedCells() for more details.
2180 */
2181 wxArrayInt GetSelectedRows() const;
2182
2183 /**
2184 Access or update the selection fore/back colours
2185 */
2186 wxColour GetSelectionBackground() const;
2187
2188 /**
2189 Returns an array of the bottom right corners of blocks of selected
2190 cells.
2191
2192 Please see GetSelectedCells() for more information about the selection
2193 representation in wxGrid.
2194
2195 @see GetSelectionBlockTopLeft()
2196 */
2197 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
2198
2199 /**
2200 Returns an array of the top left corners of blocks of selected cells.
2201
2202 Please see GetSelectedCells() for more information about the selection
2203 representation in wxGrid.
2204
2205 @see GetSelectionBlockBottomRight()
2206 */
2207 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
2208
2209 /**
2210 Returns the colour used for drawing the selection foreground.
2211 */
2212 wxColour GetSelectionForeground() const;
2213
2214 /**
2215 Returns the current selection mode.
2216
2217 @see SetSelectionMode().
2218 */
2219 wxGridSelectionModes GetSelectionMode() const;
2220
2221 /**
2222 Returns a base pointer to the current table object.
2223
2224 The returned pointer is still owned by the grid.
2225 */
2226 wxGridTableBase *GetTable() const;
2227
2228 //@{
2229 /**
2230 Make the given cell current and ensure it is visible.
2231
2232 This method is equivalent to calling MakeCellVisible() and
2233 SetGridCursor() and so, as with the latter, a wxEVT_GRID_SELECT_CELL
2234 event is generated by it and the selected cell doesn't change if the
2235 event is vetoed.
2236 */
2237 void GoToCell(int row, int col);
2238 void GoToCell(const wxGridCellCoords& coords);
2239 //@}
2240
2241 /**
2242 Returns @true if drawing of grid lines is turned on, @false otherwise.
2243 */
2244 bool GridLinesEnabled() const;
2245
2246 /**
2247 Hides the in-place cell edit control.
2248 */
2249 void HideCellEditControl();
2250
2251 /**
2252 Hides the column labels by calling SetColLabelSize()
2253 with a size of 0. Show labels again by calling that method with
2254 a width greater than 0.
2255 */
2256 void HideColLabels();
2257
2258 /**
2259 Hides the row labels by calling SetRowLabelSize() with a size of 0.
2260
2261 The labels can be shown again by calling SetRowLabelSize() with a width
2262 greater than 0.
2263 */
2264 void HideRowLabels();
2265
2266 /**
2267 Inserts one or more new columns into a grid with the first new column
2268 at the specified position.
2269
2270 Notice that inserting the columns in the grid requires grid table
2271 cooperation: when this method is called, grid object begins by
2272 requesting the underlying grid table to insert new columns. If this is
2273 successful the table notifies the grid and the grid updates the
2274 display. For a default grid (one where you have called
2275 wxGrid::CreateGrid) this process is automatic. If you are using a
2276 custom grid table (specified with wxGrid::SetTable) then you must
2277 override wxGridTableBase::InsertCols() in your derived table class.
2278
2279 @param pos
2280 The position which the first newly inserted column will have.
2281 @param numCols
2282 The number of columns to insert.
2283 @param updateLabels
2284 Currently not used.
2285 @return
2286 @true if the columns were successfully inserted, @false if an error
2287 occurred (most likely the table couldn't be updated).
2288 */
2289 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true);
2290
2291 /**
2292 Inserts one or more new rows into a grid with the first new row at the
2293 specified position.
2294
2295 Notice that you must implement wxGridTableBase::InsertRows() if you use
2296 a grid with a custom table, please see InsertCols() for more
2297 information.
2298
2299 @param pos
2300 The position which the first newly inserted row will have.
2301 @param numRows
2302 The number of rows to insert.
2303 @param updateLabels
2304 Currently not used.
2305 @return
2306 @true if the rows were successfully inserted, @false if an error
2307 occurred (most likely the table couldn't be updated).
2308 */
2309 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true);
2310
2311 /**
2312 Returns @true if the in-place edit control is currently enabled.
2313 */
2314 bool IsCellEditControlEnabled() const;
2315
2316 /**
2317 Returns @true if the current cell is read-only.
2318
2319 @see SetReadOnly(), IsReadOnly()
2320 */
2321 bool IsCurrentCellReadOnly() const;
2322
2323 /**
2324 Returns @false if the whole grid has been set as read-only or @true
2325 otherwise.
2326
2327 See EnableEditing() for more information about controlling the editing
2328 status of grid cells.
2329 */
2330 bool IsEditable() const;
2331
2332 //@{
2333 /**
2334 Is this cell currently selected?
2335 */
2336 bool IsInSelection(int row, int col) const;
2337 bool IsInSelection(const wxGridCellCoords& coords) const;
2338 //@}
2339
2340 /**
2341 Returns @true if the cell at the specified location can't be edited.
2342
2343 @see SetReadOnly(), IsCurrentCellReadOnly()
2344 */
2345 bool IsReadOnly(int row, int col) const;
2346
2347 /**
2348 Returns @true if there are currently any selected cells, rows, columns
2349 or blocks.
2350 */
2351 bool IsSelection() const;
2352
2353 //@{
2354 /**
2355 Returns @true if a cell is either wholly or at least partially visible
2356 in the grid window.
2357
2358 By default, the cell must be entirely visible for this function to
2359 return true but if @a wholeCellVisible is @false, the function returns
2360 @true even if the cell is only partially visible.
2361 */
2362 bool IsVisible(int row, int col, bool wholeCellVisible = true) const;
2363 bool IsVisible(const wxGridCellCoords& coords,
2364 bool wholeCellVisible = true) const;
2365 //@}
2366
2367 //@{
2368 /**
2369 Brings the specified cell into the visible grid cell area with minimal
2370 scrolling.
2371
2372 Does nothing if the cell is already visible.
2373 */
2374 void MakeCellVisible(int row, int col);
2375 void MakeCellVisible(const wxGridCellCoords& coords);
2376 //@}
2377
2378 /**
2379 Moves the grid cursor down by one row.
2380
2381 If a block of cells was previously selected it will expand if the
2382 argument is @true or be cleared if the argument is @false.
2383 */
2384 bool MoveCursorDown(bool expandSelection);
2385
2386 /**
2387 Moves the grid cursor down in the current column such that it skips to
2388 the beginning or end of a block of non-empty cells.
2389
2390 If a block of cells was previously selected it will expand if the
2391 argument is @true or be cleared if the argument is @false.
2392 */
2393 bool MoveCursorDownBlock(bool expandSelection);
2394
2395 /**
2396 Moves the grid cursor left by one column.
2397
2398 If a block of cells was previously selected it will expand if the
2399 argument is @true or be cleared if the argument is @false.
2400 */
2401 bool MoveCursorLeft(bool expandSelection);
2402
2403 /**
2404 Moves the grid cursor left in the current row such that it skips to the
2405 beginning or end of a block of non-empty cells.
2406
2407 If a block of cells was previously selected it will expand if the
2408 argument is @true or be cleared if the argument is @false.
2409 */
2410 bool MoveCursorLeftBlock(bool expandSelection);
2411
2412 /**
2413 Moves the grid cursor right by one column.
2414
2415 If a block of cells was previously selected it will expand if the
2416 argument is @true or be cleared if the argument is @false.
2417 */
2418 bool MoveCursorRight(bool expandSelection);
2419
2420 /**
2421 Moves the grid cursor right in the current row such that it skips to
2422 the beginning or end of a block of non-empty cells.
2423
2424 If a block of cells was previously selected it will expand if the
2425 argument is @true or be cleared if the argument is @false.
2426 */
2427 bool MoveCursorRightBlock(bool expandSelection);
2428
2429 /**
2430 Moves the grid cursor up by one row.
2431
2432 If a block of cells was previously selected it will expand if the
2433 argument is @true or be cleared if the argument is @false.
2434 */
2435 bool MoveCursorUp(bool expandSelection);
2436
2437 /**
2438 Moves the grid cursor up in the current column such that it skips to
2439 the beginning or end of a block of non-empty cells.
2440
2441 If a block of cells was previously selected it will expand if the
2442 argument is @true or be cleared if the argument is @false.
2443 */
2444 bool MoveCursorUpBlock(bool expandSelection);
2445
2446 /**
2447 Moves the grid cursor down by some number of rows so that the previous
2448 bottom visible row becomes the top visible row.
2449 */
2450 bool MovePageDown();
2451
2452 /**
2453 Moves the grid cursor up by some number of rows so that the previous
2454 top visible row becomes the bottom visible row.
2455 */
2456 bool MovePageUp();
2457
2458 /**
2459 Register a new data type.
2460
2461 The data types allow to naturally associate specific renderers and
2462 editors to the cells containing values of the given type. For example,
2463 the grid automatically registers a data type with the name @c
2464 wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and
2465 wxGridCellTextEditor as its renderer and editor respectively -- this is
2466 the data type used by all the cells of the default wxGridStringTable,
2467 so this renderer and editor are used by default for all grid cells.
2468
2469 However if a custom table returns @c wxGRID_VALUE_BOOL from its
2470 wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and
2471 wxGridCellBoolEditor are used for it because the grid also registers a
2472 boolean data type with this name.
2473
2474 And as this mechanism is completely generic, you may register your own
2475 data types using your own custom renderers and editors. Just remember
2476 that the table must identify a cell as being of the given type for them
2477 to be used for this cell.
2478
2479 @param typeName
2480 Name of the new type. May be any string, but if the type name is
2481 the same as the name of an already registered type, including one
2482 of the standard ones (which are @c wxGRID_VALUE_STRING, @c
2483 wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT
2484 and @c wxGRID_VALUE_CHOICE), then the new registration information
2485 replaces the previously used renderer and editor.
2486 @param renderer
2487 The renderer to use for the cells of this type. Its ownership is
2488 taken by the grid, i.e. it will call DecRef() on this pointer when
2489 it doesn't need it any longer.
2490 @param editor
2491 The editor to use for the cells of this type. Its ownership is also
2492 taken by the grid.
2493 */
2494 void RegisterDataType(const wxString& typeName,
2495 wxGridCellRenderer* renderer,
2496 wxGridCellEditor* editor);
2497
2498 /**
2499 Sets the value of the current grid cell to the current in-place edit
2500 control value.
2501
2502 This is called automatically when the grid cursor moves from the
2503 current cell to a new cell. It is also a good idea to call this
2504 function when closing a grid since any edits to the final cell location
2505 will not be saved otherwise.
2506 */
2507 void SaveEditControlValue();
2508
2509 /**
2510 Selects all cells in the grid.
2511 */
2512 void SelectAll();
2513
2514 //@{
2515 /**
2516 Selects a rectangular block of cells.
2517
2518 If @a addToSelected is @false then any existing selection will be
2519 deselected; if @true the column will be added to the existing
2520 selection.
2521 */
2522 void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol,
2523 bool addToSelected = false);
2524 void SelectBlock(const wxGridCellCoords& topLeft,
2525 const wxGridCellCoords& bottomRight,
2526 bool addToSelected = false);
2527 //@}
2528
2529 /**
2530 Selects the specified column.
2531
2532 If @a addToSelected is @false then any existing selection will be
2533 deselected; if @true the column will be added to the existing
2534 selection.
2535
2536 This method won't select anything if the current selection mode is
2537 wxGridSelectRows.
2538 */
2539 void SelectCol(int col, bool addToSelected = false);
2540
2541 /**
2542 Selects the specified row.
2543
2544 If @a addToSelected is @false then any existing selection will be
2545 deselected; if @true the row will be added to the existing selection.
2546
2547 This method won't select anything if the current selection mode is
2548 wxGridSelectColumns.
2549 */
2550 void SelectRow(int row, bool addToSelected = false);
2551
2552 //@{
2553 /**
2554 Sets the horizontal and vertical alignment for grid cell text at the
2555 specified location.
2556
2557 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2558 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2559
2560 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2561 or @c wxALIGN_BOTTOM.
2562 */
2563 void SetCellAlignment(int row, int col, int horiz, int vert);
2564 void SetCellAlignment(int align, int row, int col);
2565 //@}
2566
2567 //@{
2568 /**
2569 Set the background colour for the given cell or all cells by default.
2570 */
2571 void SetCellBackgroundColour(int row, int col, const wxColour& colour);
2572 //@}
2573
2574 /**
2575 Sets the editor for the grid cell at the specified location.
2576
2577 The grid will take ownership of the pointer.
2578
2579 See wxGridCellEditor and the @ref overview_grid "wxGrid overview"
2580 for more information about cell editors and renderers.
2581 */
2582 void SetCellEditor(int row, int col, wxGridCellEditor* editor);
2583
2584 /**
2585 Sets the font for text in the grid cell at the specified location.
2586 */
2587 void SetCellFont(int row, int col, const wxFont& font);
2588
2589 /**
2590 Sets the renderer for the grid cell at the specified location.
2591
2592 The grid will take ownership of the pointer.
2593
2594 See wxGridCellRenderer and the @ref overview_grid "wxGrid overview"
2595 for more information about cell editors and renderers.
2596 */
2597 void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer);
2598
2599 //@{
2600 /**
2601 Sets the text colour for the given cell or all cells by default.
2602 */
2603 void SetCellTextColour(int row, int col, const wxColour& colour);
2604 void SetCellTextColour(const wxColour& val, int row, int col);
2605 void SetCellTextColour(const wxColour& colour);
2606 //@}
2607
2608 //@{
2609 /**
2610 Sets the string value for the cell at the specified location.
2611
2612 For simple applications where a grid object automatically uses a
2613 default grid table of string values you use this function together with
2614 GetCellValue() to access cell values. For more complex applications
2615 where you have derived your own grid table class that contains various
2616 data types (e.g. numeric, boolean or user-defined custom types) then
2617 you only use this function for those cells that contain string values.
2618 The last form is for backward compatibility only.
2619
2620 See wxGridTableBase::CanSetValueAs and the @ref overview_grid
2621 "wxGrid overview" for more information.
2622 */
2623 void SetCellValue(int row, int col, const wxString& s);
2624 void SetCellValue(const wxGridCellCoords& coords, const wxString& s);
2625 void SetCellValue(const wxString& val, int row, int col);
2626 //@}
2627
2628 /**
2629 Sets the cell attributes for all cells in the specified column.
2630
2631 For more information about controlling grid cell attributes see the
2632 wxGridCellAttr cell attribute class and the @ref overview_grid "wxGrid overview".
2633 */
2634 void SetColAttr(int col, wxGridCellAttr* attr);
2635
2636 /**
2637 Sets the specified column to display boolean values.
2638
2639 @see SetColFormatCustom()
2640 */
2641 void SetColFormatBool(int col);
2642
2643 /**
2644 Sets the specified column to display data in a custom format.
2645
2646 This method provides an alternative to defining a custom grid table
2647 which would return @a typeName from its GetTypeName() method for the
2648 cells in this column: while it doesn't really change the type of the
2649 cells in this column, it does associate the renderer and editor used
2650 for the cells of the specified type with them.
2651
2652 See the @ref overview_grid "wxGrid overview" for more
2653 information on working with custom data types.
2654 */
2655 void SetColFormatCustom(int col, const wxString& typeName);
2656
2657 /**
2658 Sets the specified column to display floating point values with the
2659 given width and precision.
2660
2661 @see SetColFormatCustom()
2662 */
2663 void SetColFormatFloat(int col, int width = -1, int precision = -1);
2664
2665 /**
2666 Sets the specified column to display integer values.
2667
2668 @see SetColFormatCustom()
2669 */
2670 void SetColFormatNumber(int col);
2671
2672 /**
2673 Sets the horizontal and vertical alignment of column label text.
2674
2675 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2676 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2677 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2678 or @c wxALIGN_BOTTOM.
2679 */
2680 void SetColLabelAlignment(int horiz, int vert);
2681
2682 /**
2683 Sets the height of the column labels.
2684
2685 If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
2686 automatically so that no label is truncated. Note that this could be
2687 slow for a large table.
2688 */
2689 void SetColLabelSize(int height);
2690
2691 /**
2692 Set the value for the given column label.
2693
2694 If you are using a custom grid table you must override
2695 wxGridTableBase::SetColLabelValue for this to have any effect.
2696 */
2697 void SetColLabelValue(int col, const wxString& value);
2698
2699 /**
2700 Sets the minimal width to which the user can resize columns.
2701
2702 @see GetColMinimalAcceptableWidth()
2703 */
2704 void SetColMinimalAcceptableWidth(int width);
2705
2706 /**
2707 Sets the minimal width for the specified column.
2708
2709 It is usually best to call this method during grid creation as calling
2710 it later will not resize the column to the given minimal width even if
2711 it is currently narrower than it.
2712
2713 @a width must be greater than the minimal acceptable column width as
2714 returned by GetColMinimalAcceptableWidth().
2715 */
2716 void SetColMinimalWidth(int col, int width);
2717
2718 /**
2719 Sets the position of the specified column.
2720 */
2721 void SetColPos(int colID, int newPos);
2722
2723 /**
2724 Sets the width of the specified column.
2725
2726 Notice that this function does not refresh the grid, you need to call
2727 ForceRefresh() to make the changes take effect immediately.
2728
2729 @param col
2730 The column index.
2731 @param width
2732 The new column width in pixels or a negative value to fit the
2733 column width to its label width.
2734 */
2735 void SetColSize(int col, int width);
2736
2737 /**
2738 Sets the default horizontal and vertical alignment for grid cell text.
2739
2740 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2741 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2742 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2743 or @c wxALIGN_BOTTOM.
2744 */
2745 void SetDefaultCellAlignment(int horiz, int vert);
2746
2747 /**
2748 Sets the default background colour for grid cells.
2749 */
2750 void SetDefaultCellBackgroundColour(const wxColour& colour);
2751
2752 /**
2753 Sets the default font to be used for grid cell text.
2754 */
2755 void SetDefaultCellFont(const wxFont& font);
2756
2757 /**
2758 Sets the current default colour for grid cell text.
2759 */
2760 void SetDefaultCellTextColour(const wxColour& colour);
2761
2762 /**
2763 Sets the default width for columns in the grid.
2764
2765 This will only affect columns subsequently added to the grid unless
2766 @a resizeExistingCols is @true.
2767
2768 If @a width is less than GetColMinimalAcceptableWidth(), then the
2769 minimal acceptable width is used instead of it.
2770 */
2771 void SetDefaultColSize(int width, bool resizeExistingCols = false);
2772
2773 /**
2774 Sets the default editor for grid cells.
2775
2776 The grid will take ownership of the pointer.
2777
2778 See wxGridCellEditor and the @ref overview_grid "wxGrid overview"
2779 for more information about cell editors and renderers.
2780 */
2781 void SetDefaultEditor(wxGridCellEditor* editor);
2782
2783 /**
2784 Sets the default renderer for grid cells.
2785
2786 The grid will take ownership of the pointer.
2787
2788 See wxGridCellRenderer and the @ref overview_grid "wxGrid overview"
2789 for more information about cell editors and renderers.
2790 */
2791 void SetDefaultRenderer(wxGridCellRenderer* renderer);
2792
2793 /**
2794 Sets the default height for rows in the grid.
2795
2796 This will only affect rows subsequently added to the grid unless
2797 @a resizeExistingRows is @true.
2798
2799 If @a height is less than GetRowMinimalAcceptableHeight(), then the
2800 minimal acceptable heihgt is used instead of it.
2801 */
2802 void SetDefaultRowSize(int height, bool resizeExistingRows = false);
2803
2804 //@{
2805 /**
2806 Set the grid cursor to the specified cell.
2807
2808 The grid cursor indicates the current cell and can be moved by the user
2809 using the arrow keys or the mouse.
2810
2811 Calling this function generates a wxEVT_GRID_SELECT_CELL event and if
2812 the event handler vetoes this event, the cursor is not moved.
2813
2814 This function doesn't make the target call visible, use GoToCell() to
2815 do this.
2816 */
2817 void SetGridCursor(int row, int col);
2818 void SetGridCursor(const wxGridCellCoords& coords);
2819 //@}
2820
2821 /**
2822 Sets the colour used to draw grid lines.
2823 */
2824 void SetGridLineColour(const wxColour& colour);
2825
2826 /**
2827 Sets the background colour for row and column labels.
2828 */
2829 void SetLabelBackgroundColour(const wxColour& colour);
2830
2831 /**
2832 Sets the font for row and column labels.
2833 */
2834 void SetLabelFont(const wxFont& font);
2835
2836 /**
2837 Sets the colour for row and column label text.
2838 */
2839 void SetLabelTextColour(const wxColour& colour);
2840
2841 /**
2842 Sets the extra margins used around the grid area.
2843
2844 A grid may occupy more space than needed for its data display and
2845 this function allows to set how big this extra space is
2846 */
2847 void SetMargins(int extraWidth, int extraHeight);
2848
2849 /**
2850 Makes the cell at the specified location read-only or editable.
2851
2852 @see IsReadOnly()
2853 */
2854 void SetReadOnly(int row, int col, bool isReadOnly = true);
2855
2856 /**
2857 Sets the cell attributes for all cells in the specified row.
2858
2859 The grid takes ownership of the attribute pointer.
2860
2861 See the wxGridCellAttr class for more information about controlling
2862 cell attributes.
2863 */
2864 void SetRowAttr(int row, wxGridCellAttr* attr);
2865
2866 /**
2867 Sets the horizontal and vertical alignment of row label text.
2868
2869 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2870 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2871 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2872 or @c wxALIGN_BOTTOM.
2873 */
2874 void SetRowLabelAlignment(int horiz, int vert);
2875
2876 /**
2877 Sets the width of the row labels.
2878
2879 If @a width equals @c wxGRID_AUTOSIZE then width is calculated
2880 automatically so that no label is truncated. Note that this could be
2881 slow for a large table.
2882 */
2883 void SetRowLabelSize(int width);
2884
2885 /**
2886 Sets the value for the given row label.
2887
2888 If you are using a derived grid table you must override
2889 wxGridTableBase::SetRowLabelValue for this to have any effect.
2890 */
2891 void SetRowLabelValue(int row, const wxString& value);
2892
2893 /**
2894 Sets the minimal row height used by default.
2895
2896 See SetColMinimalAcceptableWidth() for more information.
2897 */
2898 void SetRowMinimalAcceptableHeight(int height);
2899
2900 /**
2901 Sets the minimal height for the specified row.
2902
2903 See SetColMinimalWidth() for more information.
2904 */
2905 void SetRowMinimalHeight(int row, int height);
2906
2907 /**
2908 Sets the height of the specified row.
2909
2910 See SetColSize() for more information.
2911 */
2912 void SetRowSize(int row, int height);
2913
2914 /**
2915 Sets the number of pixels per horizontal scroll increment.
2916
2917 The default is 15.
2918
2919 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
2920 */
2921 void SetScrollLineX(int x);
2922
2923 /**
2924 Sets the number of pixels per vertical scroll increment.
2925
2926 The default is 15.
2927
2928 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
2929 */
2930 void SetScrollLineY(int y);
2931
2932 /**
2933 Set the colour to be used for drawing the selection background.
2934 */
2935 void SetSelectionBackground(const wxColour& c);
2936
2937 /**
2938 Set the colour to be used for drawing the selection foreground.
2939 */
2940 void SetSelectionForeground(const wxColour& c);
2941
2942 /**
2943 Set the selection behaviour of the grid.
2944
2945 The existing selection is converted to conform to the new mode if
2946 possible and discarded otherwise (e.g. any individual selected cells
2947 are deselected if the new mode allows only the selection of the entire
2948 rows or columns).
2949 */
2950 void SetSelectionMode(wxGridSelectionModes selmode);
2951
2952 /**
2953 Passes a pointer to a custom grid table to be used by the grid.
2954
2955 This should be called after the grid constructor and before using the
2956 grid object. If @a takeOwnership is set to @true then the table will be
2957 deleted by the wxGrid destructor.
2958
2959 Use this function instead of CreateGrid() when your application
2960 involves complex or non-string data or data sets that are too large to
2961 fit wholly in memory.
2962 */
2963 bool SetTable(wxGridTableBase* table,
2964 bool takeOwnership = false,
2965 wxGridSelectionModes selmode = wxGridSelectCells);
2966
2967 /**
2968 Call this in order to make the column labels use a native look by using
2969 wxRenderer::DrawHeaderButton internally.
2970
2971 There is no equivalent method for drawing row columns as there is not
2972 native look for that. This option is useful when using wxGrid for
2973 displaying tables and not as a spread-sheet.
2974 */
2975 void SetUseNativeColLabels(bool native = true);
2976
2977 /**
2978 Displays the in-place cell edit control for the current cell.
2979 */
2980 void ShowCellEditControl();
2981
2982 /**
2983 Returns the column at the given pixel position.
2984
2985 @param x
2986 The x position to evaluate.
2987 @param clipToMinMax
2988 If @true, rather than returning wxNOT_FOUND, it returns either the
2989 first or last column depending on whether x is too far to the left
2990 or right respectively.
2991 @return
2992 The column index or wxNOT_FOUND.
2993 */
2994 int XToCol(int x, bool clipToMinMax = false) const;
2995
2996 /**
2997 Returns the column whose right hand edge is close to the given logical
2998 x position.
2999
3000 If no column edge is near to this position @c wxNOT_FOUND is returned.
3001 */
3002 int XToEdgeOfCol(int x) const;
3003
3004 //@{
3005 /**
3006 Translates logical pixel coordinates to the grid cell coordinates.
3007
3008 Notice that this function expects logical coordinates on input so if
3009 you use this function in a mouse event handler you need to translate
3010 the mouse position, which is expressed in device coordinates, to
3011 logical ones.
3012
3013 @see XToCol(), YToRow()
3014 */
3015
3016 // XYToCell(int, int, wxGridCellCoords&) overload is intentionally
3017 // undocumented, using it is ugly and non-const reference parameters are
3018 // not used in wxWidgets API
3019
3020 wxGridCellCoords XYToCell(int x, int y) const;
3021 wxGridCellCoords XYToCell(const wxPoint& pos) const;
3022
3023 //@}
3024
3025 /**
3026 Returns the row whose bottom edge is close to the given logical y
3027 position.
3028
3029 If no row edge is near to this position @c wxNOT_FOUND is returned.
3030 */
3031 int YToEdgeOfRow(int y) const;
3032
3033 /**
3034 Returns the grid row that corresponds to the logical y coordinate.
3035
3036 Returns @c wxNOT_FOUND if there is no row at the y position.
3037 */
3038 int YToRow(int y, bool clipToMinMax = false) const;
3039
3040 protected:
3041 /**
3042 Returns @true if this grid has support for cell attributes.
3043
3044 The grid supports attributes if it has the associated table which, in
3045 turn, has attributes support, i.e. wxGridTableBase::CanHaveAttributes()
3046 returns @true.
3047 */
3048 bool CanHaveAttributes() const;
3049
3050 /**
3051 Get the minimal width of the given column/row.
3052
3053 The value returned by this function may be different than that returned
3054 by GetColMinimalAcceptableWidth() if SetColMinimalWidth() had been
3055 called for this column.
3056 */
3057 int GetColMinimalWidth(int col) const;
3058
3059 /**
3060 Returns the coordinate of the right border specified column.
3061 */
3062 int GetColRight(int col) const;
3063
3064 /**
3065 Returns the coordinate of the left border specified column.
3066 */
3067 int GetColLeft(int col) const;
3068
3069 /**
3070 Returns the minimal size for the given column.
3071
3072 The value returned by this function may be different than that returned
3073 by GetRowMinimalAcceptableHeight() if SetRowMinimalHeight() had been
3074 called for this row.
3075 */
3076 int GetRowMinimalHeight(int col) const;
3077 };
3078
3079
3080
3081 /**
3082 @class wxGridCellBoolEditor
3083
3084 The editor for boolean data.
3085
3086 @library{wxadv}
3087 @category{grid}
3088
3089 @see wxGridCellEditor, wxGridCellFloatEditor, wxGridCellNumberEditor,
3090 wxGridCellTextEditor, wxGridCellChoiceEditor
3091 */
3092 class wxGridCellBoolEditor : public wxGridCellEditor
3093 {
3094 public:
3095 /**
3096 Default constructor.
3097 */
3098 wxGridCellBoolEditor();
3099
3100 /**
3101 Returns @true if the given @a value is equal to the string representation of
3102 the truth value we currently use (see
3103 wxGridCellBoolEditor::UseStringValues).
3104 */
3105 static bool IsTrueValue(const wxString& value);
3106
3107 /**
3108 , wxString&@e valueFalse = _T(""))
3109 This method allows to customize the values returned by GetValue() method for
3110 the cell using this editor. By default, the default values of the arguments are
3111 used, i.e. @c "1" is returned if the cell is checked and an empty string
3112 otherwise, using this method allows to change this.
3113 */
3114 static void UseStringValues() const;
3115 };
3116
3117
3118
3119 /**
3120 @class wxGridUpdateLocker
3121
3122 This small class can be used to prevent wxGrid from redrawing
3123 during its lifetime by calling wxGrid::BeginBatch
3124 in its constructor and wxGrid::EndBatch in its
3125 destructor. It is typically used in a function performing several operations
3126 with a grid which would otherwise result in flicker. For example:
3127
3128 @code
3129 void MyFrame::Foo()
3130 {
3131 m_grid = new wxGrid(this, ...);
3132
3133 wxGridUpdateLocker noUpdates(m_grid);
3134 m_grid-AppendColumn();
3135 ... many other operations with m_grid...
3136 m_grid-AppendRow();
3137
3138 // destructor called, grid refreshed
3139 }
3140 @endcode
3141
3142 Using this class is easier and safer than calling
3143 wxGrid::BeginBatch and wxGrid::EndBatch
3144 because you don't risk not to call the latter (due to an exception for example).
3145
3146 @library{wxadv}
3147 @category{grid}
3148 */
3149 class wxGridUpdateLocker
3150 {
3151 public:
3152 /**
3153 Creates an object preventing the updates of the specified @e grid. The
3154 parameter could be @NULL in which case nothing is done. If @a grid is
3155 non-@NULL then the grid must exist for longer than wxGridUpdateLocker object
3156 itself.
3157 The default constructor could be followed by a call to
3158 Create() to set the
3159 grid object later.
3160 */
3161 wxGridUpdateLocker(wxGrid* grid = NULL);
3162
3163 /**
3164 Destructor reenables updates for the grid this object is associated with.
3165 */
3166 ~wxGridUpdateLocker();
3167
3168 /**
3169 This method can be called if the object had been constructed using the default
3170 constructor. It must not be called more than once.
3171 */
3172 void Create(wxGrid* grid);
3173 };
3174