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