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