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