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