more grid folding: got rid of duplicate version of methods for finding the closest...
[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 Returns @true if drawing of grid lines is turned on, @false otherwise.
2135 */
2136 bool GridLinesEnabled() const;
2137
2138 /**
2139 Hides the in-place cell edit control.
2140 */
2141 void HideCellEditControl();
2142
2143 /**
2144 Hides the column labels by calling SetColLabelSize()
2145 with a size of 0. Show labels again by calling that method with
2146 a width greater than 0.
2147 */
2148 void HideColLabels();
2149
2150 /**
2151 Hides the row labels by calling SetRowLabelSize() with a size of 0.
2152
2153 The labels can be shown again by calling SetRowLabelSize() with a width
2154 greater than 0.
2155 */
2156 void HideRowLabels();
2157
2158 /**
2159 Inserts one or more new columns into a grid with the first new column
2160 at the specified position.
2161
2162 Notice that inserting the columns in the grid requires grid table
2163 cooperation: when this method is called, grid object begins by
2164 requesting the underlying grid table to insert new columns. If this is
2165 successful the table notifies the grid and the grid updates the
2166 display. For a default grid (one where you have called
2167 wxGrid::CreateGrid) this process is automatic. If you are using a
2168 custom grid table (specified with wxGrid::SetTable) then you must
2169 override wxGridTableBase::InsertCols() in your derived table class.
2170
2171 @param pos
2172 The position which the first newly inserted column will have.
2173 @param numCols
2174 The number of columns to insert.
2175 @param updateLabels
2176 Currently not used.
2177 @return
2178 @true if the columns were successfully inserted, @false if an error
2179 occurred (most likely the table couldn't be updated).
2180 */
2181 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true);
2182
2183 /**
2184 Inserts one or more new rows into a grid with the first new row at the
2185 specified position.
2186
2187 Notice that you must implement wxGridTableBase::InsertRows() if you use
2188 a grid with a custom table, please see InsertCols() for more
2189 information.
2190
2191 @param pos
2192 The position which the first newly inserted row will have.
2193 @param numRows
2194 The number of rows to insert.
2195 @param updateLabels
2196 Currently not used.
2197 @return
2198 @true if the rows were successfully inserted, @false if an error
2199 occurred (most likely the table couldn't be updated).
2200 */
2201 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true);
2202
2203 /**
2204 Returns @true if the in-place edit control is currently enabled.
2205 */
2206 bool IsCellEditControlEnabled() const;
2207
2208 /**
2209 Returns @true if the current cell is read-only.
2210
2211 @see SetReadOnly(), IsReadOnly()
2212 */
2213 bool IsCurrentCellReadOnly() const;
2214
2215 /**
2216 Returns @false if the whole grid has been set as read-only or @true
2217 otherwise.
2218
2219 See EnableEditing() for more information about controlling the editing
2220 status of grid cells.
2221 */
2222 bool IsEditable() const;
2223
2224 //@{
2225 /**
2226 Is this cell currently selected?
2227 */
2228 bool IsInSelection(int row, int col) const;
2229 bool IsInSelection(const wxGridCellCoords& coords) const;
2230 //@}
2231
2232 /**
2233 Returns @true if the cell at the specified location can't be edited.
2234
2235 @see SetReadOnly(), IsCurrentCellReadOnly()
2236 */
2237 bool IsReadOnly(int row, int col) const;
2238
2239 /**
2240 Returns @true if there are currently any selected cells, rows, columns
2241 or blocks.
2242 */
2243 bool IsSelection() const;
2244
2245 //@{
2246 /**
2247 Returns @true if a cell is either wholly or at least partially visible
2248 in the grid window.
2249
2250 By default, the cell must be entirely visible for this function to
2251 return true but if @a wholeCellVisible is @false, the function returns
2252 @true even if the cell is only partially visible.
2253 */
2254 bool IsVisible(int row, int col, bool wholeCellVisible = true) const;
2255 const bool IsVisible(const wxGridCellCoords& coords,
2256 bool wholeCellVisible = true) const;
2257 //@}
2258
2259 //@{
2260 /**
2261 Brings the specified cell into the visible grid cell area with minimal
2262 scrolling.
2263
2264 Does nothing if the cell is already visible.
2265 */
2266 void MakeCellVisible(int row, int col);
2267 void MakeCellVisible(const wxGridCellCoords& coords);
2268 //@}
2269
2270 /**
2271 Moves the grid cursor down by one row.
2272
2273 If a block of cells was previously selected it will expand if the
2274 argument is @true or be cleared if the argument is @false.
2275 */
2276 bool MoveCursorDown(bool expandSelection);
2277
2278 /**
2279 Moves the grid cursor down in the current column such that it skips to
2280 the beginning or end of a block of non-empty cells.
2281
2282 If a block of cells was previously selected it will expand if the
2283 argument is @true or be cleared if the argument is @false.
2284 */
2285 bool MoveCursorDownBlock(bool expandSelection);
2286
2287 /**
2288 Moves the grid cursor left by one column.
2289
2290 If a block of cells was previously selected it will expand if the
2291 argument is @true or be cleared if the argument is @false.
2292 */
2293 bool MoveCursorLeft(bool expandSelection);
2294
2295 /**
2296 Moves the grid cursor left in the current row such that it skips to the
2297 beginning or end of a block of non-empty cells.
2298
2299 If a block of cells was previously selected it will expand if the
2300 argument is @true or be cleared if the argument is @false.
2301 */
2302 bool MoveCursorLeftBlock(bool expandSelection);
2303
2304 /**
2305 Moves the grid cursor right by one column.
2306
2307 If a block of cells was previously selected it will expand if the
2308 argument is @true or be cleared if the argument is @false.
2309 */
2310 bool MoveCursorRight(bool expandSelection);
2311
2312 /**
2313 Moves the grid cursor right in the current row such that it skips to
2314 the beginning or end of a block of non-empty cells.
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 MoveCursorRightBlock(bool expandSelection);
2320
2321 /**
2322 Moves the grid cursor up by one row.
2323
2324 If a block of cells was previously selected it will expand if the
2325 argument is @true or be cleared if the argument is @false.
2326 */
2327 bool MoveCursorUp(bool expandSelection);
2328
2329 /**
2330 Moves the grid cursor up in the current column such that it skips to
2331 the beginning or end of a block of non-empty cells.
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 MoveCursorUpBlock(bool expandSelection);
2337
2338 /**
2339 Moves the grid cursor down by some number of rows so that the previous
2340 bottom visible row becomes the top visible row.
2341 */
2342 bool MovePageDown();
2343
2344 /**
2345 Moves the grid cursor up by some number of rows so that the previous
2346 top visible row becomes the bottom visible row.
2347 */
2348 bool MovePageUp();
2349
2350 /**
2351 Register a new data type.
2352
2353 The data types allow to naturally associate specific renderers and
2354 editors to the cells containing values of the given type. For example,
2355 the grid automatically registers a data type with the name @c
2356 wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and
2357 wxGridCellTextEditor as its renderer and editor respectively -- this is
2358 the data type used by all the cells of the default wxGridStringTable,
2359 so this renderer and editor are used by default for all grid cells.
2360
2361 However if a custom table returns @c wxGRID_VALUE_BOOL from its
2362 wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and
2363 wxGridCellBoolEditor are used for it because the grid also registers a
2364 boolean data type with this name.
2365
2366 And as this mechanism is completely generic, you may register your own
2367 data types using your own custom renderers and editors. Just remember
2368 that the table must identify a cell as being of the given type for them
2369 to be used for this cell.
2370
2371 @param typeName
2372 Name of the new type. May be any string, but if the type name is
2373 the same as the name of an already registered type, including one
2374 of the standard ones (which are @c wxGRID_VALUE_STRING, @c
2375 wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT
2376 and @c wxGRID_VALUE_CHOICE), then the new registration information
2377 replaces the previously used renderer and editor.
2378 @param renderer
2379 The renderer to use for the cells of this type. Its ownership is
2380 taken by the grid, i.e. it will call DecRef() on this pointer when
2381 it doesn't need it any longer.
2382 @param editor
2383 The editor to use for the cells of this type. Its ownership is also
2384 taken by the grid.
2385 */
2386 void RegisterDataType(const wxString& typeName,
2387 wxGridCellRenderer* renderer,
2388 wxGridCellEditor* editor);
2389
2390 /**
2391 Sets the value of the current grid cell to the current in-place edit
2392 control value.
2393
2394 This is called automatically when the grid cursor moves from the
2395 current cell to a new cell. It is also a good idea to call this
2396 function when closing a grid since any edits to the final cell location
2397 will not be saved otherwise.
2398 */
2399 void SaveEditControlValue();
2400
2401 /**
2402 Selects all cells in the grid.
2403 */
2404 void SelectAll();
2405
2406 //@{
2407 /**
2408 Selects a rectangular block of cells.
2409
2410 If @a addToSelected is @false then any existing selection will be
2411 deselected; if @true the column will be added to the existing
2412 selection.
2413 */
2414 void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol,
2415 bool addToSelected = false);
2416 void SelectBlock(const wxGridCellCoords& topLeft,
2417 const wxGridCellCoords& bottomRight,
2418 bool addToSelected = false);
2419 //@}
2420
2421 /**
2422 Selects the specified column.
2423
2424 If @a addToSelected is @false then any existing selection will be
2425 deselected; if @true the column will be added to the existing
2426 selection.
2427
2428 This method won't select anything if the current selection mode is
2429 wxGridSelectRows.
2430 */
2431 void SelectCol(int col, bool addToSelected = false);
2432
2433 /**
2434 Selects the specified row.
2435
2436 If @a addToSelected is @false then any existing selection will be
2437 deselected; if @true the row will be added to the existing selection.
2438
2439 This method won't select anything if the current selection mode is
2440 wxGridSelectColumns.
2441 */
2442 void SelectRow(int row, bool addToSelected = false);
2443
2444 //@{
2445 /**
2446 Sets the horizontal and vertical alignment for grid cell text at the
2447 specified location.
2448
2449 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2450 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2451
2452 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2453 or @c wxALIGN_BOTTOM.
2454 */
2455 void SetCellAlignment(int row, int col, int horiz, int vert);
2456 void SetCellAlignment(int align, int row, int col);
2457 //@}
2458
2459 //@{
2460 /**
2461 Set the background colour for the given cell or all cells by default.
2462 */
2463 void SetCellBackgroundColour(int row, int col, const wxColour& colour);
2464 //@}
2465
2466 /**
2467 Sets the editor for the grid cell at the specified location.
2468
2469 The grid will take ownership of the pointer.
2470
2471 See wxGridCellEditor and the @ref overview_gridoverview "wxGrid
2472 overview" for more information about cell editors and renderers.
2473 */
2474 void SetCellEditor(int row, int col, wxGridCellEditor* editor);
2475
2476 /**
2477 Sets the font for text in the grid cell at the specified location.
2478 */
2479 void SetCellFont(int row, int col, const wxFont& font);
2480
2481 /**
2482 Sets the renderer for the grid cell at the specified location.
2483
2484 The grid will take ownership of the pointer.
2485
2486 See wxGridCellRenderer and the @ref overview_gridoverview "wxGrid
2487 overview" for more information about cell editors and renderers.
2488 */
2489 void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer);
2490
2491 //@{
2492 /**
2493 Sets the text colour for the given cell or all cells by default.
2494 */
2495 void SetCellTextColour(int row, int col, const wxColour& colour);
2496 void SetCellTextColour(const wxColour& val, int row, int col);
2497 void SetCellTextColour(const wxColour& colour);
2498 //@}
2499
2500 //@{
2501 /**
2502 Sets the string value for the cell at the specified location.
2503
2504 For simple applications where a grid object automatically uses a
2505 default grid table of string values you use this function together with
2506 GetCellValue() to access cell values. For more complex applications
2507 where you have derived your own grid table class that contains various
2508 data types (e.g. numeric, boolean or user-defined custom types) then
2509 you only use this function for those cells that contain string values.
2510 The last form is for backward compatibility only.
2511
2512 See wxGridTableBase::CanSetValueAs and the @ref overview_gridoverview
2513 "wxGrid overview" for more information.
2514 */
2515 void SetCellValue(int row, int col, const wxString& s);
2516 void SetCellValue(const wxGridCellCoords& coords, const wxString& s);
2517 void SetCellValue(const wxString& val, int row, int col);
2518 //@}
2519
2520 /**
2521 Sets the cell attributes for all cells in the specified column.
2522
2523 For more information about controlling grid cell attributes see the
2524 wxGridCellAttr cell attribute class and the @ref overview_gridoverview.
2525 */
2526 void SetColAttr(int col, wxGridCellAttr* attr);
2527
2528 /**
2529 Sets the specified column to display boolean values.
2530
2531 @see SetColFormatCustom()
2532 */
2533 void SetColFormatBool(int col);
2534
2535 /**
2536 Sets the specified column to display data in a custom format.
2537
2538 This method provides an alternative to defining a custom grid table
2539 which would return @a typeName from its GetTypeName() method for the
2540 cells in this column: while it doesn't really change the type of the
2541 cells in this column, it does associate the renderer and editor used
2542 for the cells of the specified type with them.
2543
2544 See the @ref overview_gridoverview "wxGrid overview" for more
2545 information on working with custom data types.
2546 */
2547 void SetColFormatCustom(int col, const wxString& typeName);
2548
2549 /**
2550 Sets the specified column to display floating point values with the
2551 given width and precision.
2552
2553 @see SetColFormatCustom()
2554 */
2555 void SetColFormatFloat(int col, int width = -1, int precision = -1);
2556
2557 /**
2558 Sets the specified column to display integer values.
2559
2560 @see SetColFormatCustom()
2561 */
2562 void SetColFormatNumber(int col);
2563
2564 /**
2565 Sets the horizontal and vertical alignment of column label text.
2566
2567 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2568 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2569 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2570 or @c wxALIGN_BOTTOM.
2571 */
2572 void SetColLabelAlignment(int horiz, int vert);
2573
2574 /**
2575 Sets the height of the column labels.
2576
2577 If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
2578 automatically so that no label is truncated. Note that this could be
2579 slow for a large table.
2580 */
2581 void SetColLabelSize(int height);
2582
2583 /**
2584 Set the value for the given column label.
2585
2586 If you are using a custom grid table you must override
2587 wxGridTableBase::SetColLabelValue for this to have any effect.
2588 */
2589 void SetColLabelValue(int col, const wxString& value);
2590
2591 /**
2592 Sets the minimal width to which the user can resize columns.
2593
2594 @see GetColMinimalAcceptableWidth()
2595 */
2596 void SetColMinimalAcceptableWidth(int width);
2597
2598 /**
2599 Sets the minimal width for the specified column.
2600
2601 It is usually best to call this method during grid creation as calling
2602 it later will not resize the column to the given minimal width even if
2603 it is currently narrower than it.
2604
2605 @a width must be greater than the minimal acceptable column width as
2606 returned by GetColMinimalAcceptableWidth().
2607 */
2608 void SetColMinimalWidth(int col, int width);
2609
2610 /**
2611 Sets the position of the specified column.
2612 */
2613 void SetColPos(int colID, int newPos);
2614
2615 /**
2616 Sets the width of the specified column.
2617
2618 Notice that this function does not refresh the grid, you need to call
2619 ForceRefresh() to make the changes take effect immediately.
2620
2621 @param col
2622 The column index.
2623 @param width
2624 The new column width in pixels or a negative value to fit the
2625 column width to its label width.
2626 */
2627 void SetColSize(int col, int width);
2628
2629 /**
2630 Sets the default horizontal and vertical alignment for grid cell text.
2631
2632 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2633 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2634 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2635 or @c wxALIGN_BOTTOM.
2636 */
2637 void SetDefaultCellAlignment(int horiz, int vert);
2638
2639 /**
2640 Sets the default background colour for grid cells.
2641 */
2642 void SetDefaultCellBackgroundColour(const wxColour& colour);
2643
2644 /**
2645 Sets the default font to be used for grid cell text.
2646 */
2647 void SetDefaultCellFont(const wxFont& font);
2648
2649 /**
2650 Sets the current default colour for grid cell text.
2651 */
2652 void SetDefaultCellTextColour(const wxColour& colour);
2653
2654 /**
2655 Sets the default width for columns in the grid.
2656
2657 This will only affect columns subsequently added to the grid unless
2658 @a resizeExistingCols is @true.
2659
2660 If @a width is less than GetColMinimalAcceptableWidth(), then the
2661 minimal acceptable width is used instead of it.
2662 */
2663 void SetDefaultColSize(int width, bool resizeExistingCols = false);
2664
2665 /**
2666 Sets the default editor for grid cells.
2667
2668 The grid will take ownership of the pointer.
2669
2670 See wxGridCellEditor and the @ref overview_gridoverview "wxGrid
2671 overview" for more information about cell editors and renderers.
2672 */
2673 void SetDefaultEditor(wxGridCellEditor* editor);
2674
2675 /**
2676 Sets the default renderer for grid cells.
2677
2678 The grid will take ownership of the pointer.
2679
2680 See wxGridCellRenderer and the @ref overview_gridoverview "wxGrid
2681 overview" for more information about cell editors and renderers.
2682 */
2683 void SetDefaultRenderer(wxGridCellRenderer* renderer);
2684
2685 /**
2686 Sets the default height for rows in the grid.
2687
2688 This will only affect rows subsequently added to the grid unless
2689 @a resizeExistingRows is @true.
2690
2691 If @a height is less than GetRowMinimalAcceptableHeight(), then the
2692 minimal acceptable heihgt is used instead of it.
2693 */
2694 void SetDefaultRowSize(int height, bool resizeExistingRows = false);
2695
2696 /**
2697 Set the grid cursor to the specified cell.
2698
2699 This function calls MakeCellVisible().
2700 */
2701 void SetGridCursor(int row, int col);
2702
2703 /**
2704 Sets the colour used to draw grid lines.
2705 */
2706 void SetGridLineColour(const wxColour& colour);
2707
2708 /**
2709 Sets the background colour for row and column labels.
2710 */
2711 void SetLabelBackgroundColour(const wxColour& colour);
2712
2713 /**
2714 Sets the font for row and column labels.
2715 */
2716 void SetLabelFont(const wxFont& font);
2717
2718 /**
2719 Sets the colour for row and column label text.
2720 */
2721 void SetLabelTextColour(const wxColour& colour);
2722
2723 /**
2724 Sets the extra margins used around the grid area.
2725
2726 A grid may occupy more space than needed for its data display and
2727 this function allows to set how big this extra space is
2728 */
2729 void SetMargins(int extraWidth, int extraHeight);
2730
2731 /**
2732 Makes the cell at the specified location read-only or editable.
2733
2734 @see IsReadOnly()
2735 */
2736 void SetReadOnly(int row, int col, bool isReadOnly = true);
2737
2738 /**
2739 Sets the cell attributes for all cells in the specified row.
2740
2741 The grid takes ownership of the attribute pointer.
2742
2743 See the wxGridCellAttr class for more information about controlling
2744 cell attributes.
2745 */
2746 void SetRowAttr(int row, wxGridCellAttr* attr);
2747
2748 /**
2749 Sets the horizontal and vertical alignment of row label text.
2750
2751 Horizontal alignment should be one of @c wxALIGN_LEFT, @c
2752 wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2753 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2754 or @c wxALIGN_BOTTOM.
2755 */
2756 void SetRowLabelAlignment(int horiz, int vert);
2757
2758 /**
2759 Sets the width of the row labels.
2760
2761 If @a width equals @c wxGRID_AUTOSIZE then width is calculated
2762 automatically so that no label is truncated. Note that this could be
2763 slow for a large table.
2764 */
2765 void SetRowLabelSize(int width);
2766
2767 /**
2768 Sets the value for the given row label.
2769
2770 If you are using a derived grid table you must override
2771 wxGridTableBase::SetRowLabelValue for this to have any effect.
2772 */
2773 void SetRowLabelValue(int row, const wxString& value);
2774
2775 /**
2776 Sets the minimal row height used by default.
2777
2778 See SetColMinimalAcceptableWidth() for more information.
2779 */
2780 void SetRowMinimalAcceptableHeight(int height);
2781
2782 /**
2783 Sets the minimal height for the specified row.
2784
2785 See SetColMinimalWidth() for more information.
2786 */
2787 void SetRowMinimalHeight(int row, int height);
2788
2789 /**
2790 Sets the height of the specified row.
2791
2792 See SetColSize() for more information.
2793 */
2794 void SetRowSize(int row, int height);
2795
2796 /**
2797 Sets the number of pixels per horizontal scroll increment.
2798
2799 The default is 15.
2800
2801 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
2802 */
2803 void SetScrollLineX(int x);
2804
2805 /**
2806 Sets the number of pixels per vertical scroll increment.
2807
2808 The default is 15.
2809
2810 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
2811 */
2812 void SetScrollLineY(int y);
2813
2814 /**
2815 Set the colour to be used for drawing the selection background.
2816 */
2817 void SetSelectionBackground(const wxColour& c);
2818
2819 /**
2820 Set the colour to be used for drawing the selection foreground.
2821 */
2822 void SetSelectionForeground(const wxColour& c);
2823
2824 /**
2825 Set the selection behaviour of the grid.
2826
2827 The existing selection is converted to conform to the new mode if
2828 possible and discarded otherwise (e.g. any individual selected cells
2829 are deselected if the new mode allows only the selection of the entire
2830 rows or columns).
2831 */
2832 void SetSelectionMode(wxGridSelectionModes selmode);
2833
2834 /**
2835 Passes a pointer to a custom grid table to be used by the grid.
2836
2837 This should be called after the grid constructor and before using the
2838 grid object. If @a takeOwnership is set to @true then the table will be
2839 deleted by the wxGrid destructor.
2840
2841 Use this function instead of CreateGrid() when your application
2842 involves complex or non-string data or data sets that are too large to
2843 fit wholly in memory.
2844 */
2845 bool SetTable(wxGridTableBase* table,
2846 bool takeOwnership = false,
2847 wxGridSelectionModes selmode = wxGridSelectCells);
2848
2849 /**
2850 Call this in order to make the column labels use a native look by using
2851 wxRenderer::DrawHeaderButton internally.
2852
2853 There is no equivalent method for drawing row columns as there is not
2854 native look for that. This option is useful when using wxGrid for
2855 displaying tables and not as a spread-sheet.
2856 */
2857 void SetUseNativeColLabels(bool native = true);
2858
2859 /**
2860 Displays the in-place cell edit control for the current cell.
2861 */
2862 void ShowCellEditControl();
2863
2864 /**
2865 Returns the column at the given pixel position.
2866
2867 @param x
2868 The x position to evaluate.
2869 @param clipToMinMax
2870 If @true, rather than returning wxNOT_FOUND, it returns either the
2871 first or last column depending on whether x is too far to the left
2872 or right respectively.
2873 @return
2874 The column index or wxNOT_FOUND.
2875 */
2876 int XToCol(int x, bool clipToMinMax = false) const;
2877
2878 /**
2879 Returns the column whose right hand edge is close to the given logical
2880 x position.
2881
2882 If no column edge is near to this position @c wxNOT_FOUND is returned.
2883 */
2884 int XToEdgeOfCol(int x) const;
2885
2886 /**
2887 Returns the row whose bottom edge is close to the given logical y
2888 position.
2889
2890 If no row edge is near to this position @c wxNOT_FOUND is returned.
2891 */
2892 int YToEdgeOfRow(int y) const;
2893
2894 /**
2895 Returns the grid row that corresponds to the logical y coordinate.
2896
2897 Returns @c wxNOT_FOUND if there is no row at the y position.
2898 */
2899 int YToRow(int y) const;
2900 };
2901
2902
2903
2904 /**
2905 @class wxGridCellBoolEditor
2906
2907 The editor for boolean data.
2908
2909 @library{wxadv}
2910 @category{grid}
2911
2912 @see wxGridCellEditor, wxGridCellFloatEditor, wxGridCellNumberEditor,
2913 wxGridCellTextEditor, wxGridCellChoiceEditor
2914 */
2915 class wxGridCellBoolEditor : public wxGridCellEditor
2916 {
2917 public:
2918 /**
2919 Default constructor.
2920 */
2921 wxGridCellBoolEditor();
2922
2923 /**
2924 Returns @true if the given @a value is equal to the string representation of
2925 the truth value we currently use (see
2926 wxGridCellBoolEditor::UseStringValues).
2927 */
2928 static bool IsTrueValue(const wxString& value);
2929
2930 /**
2931 , wxString&@e valueFalse = _T(""))
2932 This method allows to customize the values returned by GetValue() method for
2933 the cell using this editor. By default, the default values of the arguments are
2934 used, i.e. @c "1" is returned if the cell is checked and an empty string
2935 otherwise, using this method allows to change this.
2936 */
2937 static void UseStringValues() const;
2938 };
2939
2940
2941
2942 /**
2943 @class wxGridUpdateLocker
2944
2945 This small class can be used to prevent wxGrid from redrawing
2946 during its lifetime by calling wxGrid::BeginBatch
2947 in its constructor and wxGrid::EndBatch in its
2948 destructor. It is typically used in a function performing several operations
2949 with a grid which would otherwise result in flicker. For example:
2950
2951 @code
2952 void MyFrame::Foo()
2953 {
2954 m_grid = new wxGrid(this, ...);
2955
2956 wxGridUpdateLocker noUpdates(m_grid);
2957 m_grid-AppendColumn();
2958 ... many other operations with m_grid...
2959 m_grid-AppendRow();
2960
2961 // destructor called, grid refreshed
2962 }
2963 @endcode
2964
2965 Using this class is easier and safer than calling
2966 wxGrid::BeginBatch and wxGrid::EndBatch
2967 because you don't risk not to call the latter (due to an exception for example).
2968
2969 @library{wxadv}
2970 @category{grid}
2971 */
2972 class wxGridUpdateLocker
2973 {
2974 public:
2975 /**
2976 Creates an object preventing the updates of the specified @e grid. The
2977 parameter could be @NULL in which case nothing is done. If @a grid is
2978 non-@NULL then the grid must exist for longer than wxGridUpdateLocker object
2979 itself.
2980 The default constructor could be followed by a call to
2981 Create() to set the
2982 grid object later.
2983 */
2984 wxGridUpdateLocker(wxGrid* grid = NULL);
2985
2986 /**
2987 Destructor reenables updates for the grid this object is associated with.
2988 */
2989 ~wxGridUpdateLocker();
2990
2991 /**
2992 This method can be called if the object had been constructed using the default
2993 constructor. It must not be called more than once.
2994 */
2995 void Create(wxGrid* grid);
2996 };
2997