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