]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/grid.h
fix the event type in EVT_GRID_[CMD_]COL_MOVE declaration: this event handler receive...
[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
FM
14 @library{wxadv}
15 @category{FIXME}
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 /**
32 Returns the precision ( see @ref constr() wxGridCellFloatRenderer ).
33 */
328f5751 34 int GetPrecision() const;
23324ae1
FM
35
36 /**
37 Returns the width ( see @ref constr() wxGridCellFloatRenderer ).
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 /**
47 Sets the precision ( see @ref constr() wxGridCellFloatRenderer ).
48 */
49 void SetPrecision(int precision);
50
51 /**
52 Sets the width ( see @ref constr() wxGridCellFloatRenderer )
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
FM
64 @library{wxadv}
65 @category{FIXME}
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
FM
287 @library{wxadv}
288 @category{FIXME}
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
FM
389 @library{wxadv}
390 @category{FIXME}
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
FM
418 @library{wxadv}
419 @category{FIXME}
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
FM
440 @library{wxadv}
441 @category{FIXME}
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
FM
477 @library{wxadv}
478 @category{FIXME}
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
FM
532 @library{wxadv}
533 @category{FIXME}
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
FM
622 @library{wxadv}
623 @category{FIXME}
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
FM
662 @library{wxadv}
663 @category{FIXME}
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
FM
701 @library{wxadv}
702 @category{FIXME}
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
FM
760 @library{wxadv}
761 @category{FIXME}
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
FM
784 @library{wxadv}
785 @category{FIXME}
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
FM
934 @library{wxadv}
935 @category{FIXME}
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
FM
956 @library{wxadv}
957 @category{FIXME}
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
FM
1026 @library{wxadv}
1027 @category{FIXME}
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
FM
1054 wxGrid and its related classes are used for displaying and editing tabular
1055 data. They provide a rich set of features for display, editing, and
1056 interacting with a variety of data sources. For simple applications, and to
1057 help you get started, wxGrid is the only class you need to refer to
1058 directly. It will set up default instances of the other classes and manage
1059 them for you. For more complex applications you can derive your own
1060 classes for custom grid views, grid data tables, cell editors and
4cc4bfaf 1061 renderers. The @ref overview_gridoverview has
23324ae1
FM
1062 examples of simple and more complex applications, explains the
1063 relationship between the various grid classes and has a summary of the
1064 keyboard shortcuts and mouse functions provided by wxGrid.
7c913512 1065
23324ae1
FM
1066 wxGrid has been greatly expanded and redesigned for wxWidgets 2.2
1067 onwards. The new grid classes are reasonably backward-compatible
1068 but there are some exceptions. There are also easier ways of doing many things
1069 compared to
1070 the previous implementation.
7c913512 1071
23324ae1
FM
1072 A wxGridTableBase class holds the actual
1073 data to be displayed by a wxGrid class. One or more wxGrid classes
7c913512 1074 may act as a view for one table class.
23324ae1
FM
1075 The default table class is called wxGridStringTable and
1076 holds an array of strings. An instance of such a class is created
1077 by wxGrid::CreateGrid.
7c913512 1078
23324ae1
FM
1079 wxGridCellRenderer is the abstract base
1080 class for rendereing contents in a cell. The following renderers are
1081 predefined:
1082 wxGridCellStringRenderer,
1083 wxGridCellBoolRenderer,
1084 wxGridCellFloatRenderer,
1085 wxGridCellNumberRenderer. The
1086 look of a cell can be further defined using wxGridCellAttr.
1087 An object of this type may be returned by wxGridTableBase::GetAttr.
7c913512 1088
23324ae1
FM
1089 wxGridCellEditor is the abstract base
1090 class for editing the value of a cell. The following editors are
1091 predefined:
1092 wxGridCellTextEditor
1093 wxGridCellBoolEditor
1094 wxGridCellChoiceEditor
1095 wxGridCellNumberEditor.
7c913512 1096
23324ae1
FM
1097 @library{wxadv}
1098 @category{miscwnd}
7c913512 1099
e54c96f1 1100 @see @ref overview_gridoverview "wxGrid overview"
23324ae1
FM
1101*/
1102class wxGrid : public wxScrolledWindow
1103{
1104public:
1105 //@{
1106 /**
1107 Constructor to create a grid object. Call either CreateGrid() or
1108 SetTable() directly after this to initialize the grid before using
1109 it.
1110 */
1111 wxGrid();
7c913512
FM
1112 wxGrid(wxWindow* parent, wxWindowID id,
1113 const wxPoint& pos = wxDefaultPosition,
1114 const wxSize& size = wxDefaultSize,
1115 long style = wxWANTS_CHARS,
1116 const wxString& name = wxPanelNameStr);
23324ae1
FM
1117 //@}
1118
1119 /**
1120 Destructor. This will also destroy the associated grid table unless you passed
1121 a table
1122 object to the grid and specified that the grid should not take ownership of the
1123 table (see wxGrid::SetTable).
1124 */
1125 ~wxGrid();
1126
1127 /**
1128 Appends one or more new columns to the right of the grid and returns @true if
1129 successful. The updateLabels argument is not used at present.
23324ae1
FM
1130 If you are using a derived grid table class you will need to override
1131 wxGridTableBase::AppendCols. See
1132 InsertCols() for further information.
1133 */
4cc4bfaf 1134 bool AppendCols(int numCols = 1, bool updateLabels = true);
23324ae1
FM
1135
1136 /**
1137 Appends one or more new rows to the bottom of the grid and returns @true if
1138 successful. The updateLabels argument is not used at present.
23324ae1
FM
1139 If you are using a derived grid table class you will need to override
1140 wxGridTableBase::AppendRows. See
1141 InsertRows() for further information.
1142 */
4cc4bfaf 1143 bool AppendRows(int numRows = 1, bool updateLabels = true);
23324ae1
FM
1144
1145 /**
1146 Automatically sets the height and width of all rows and columns to fit their
1147 contents.
1148 */
1149 void AutoSize();
1150
1151 /**
1152 Automatically adjusts width of the column to fit its label.
1153 */
1154 void AutoSizeColLabelSize(int col);
1155
1156 /**
1157 Automatically sizes the column to fit its contents. If setAsMin is @true the
1158 calculated width will
1159 also be set as the minimal width for the column.
1160 */
4cc4bfaf 1161 void AutoSizeColumn(int col, bool setAsMin = true);
23324ae1
FM
1162
1163 /**
1164 Automatically sizes all columns to fit their contents. If setAsMin is @true the
1165 calculated widths will
1166 also be set as the minimal widths for the columns.
1167 */
4cc4bfaf 1168 void AutoSizeColumns(bool setAsMin = true);
23324ae1
FM
1169
1170 /**
1171 Automatically sizes the row to fit its contents. If setAsMin is @true the
1172 calculated height will
1173 also be set as the minimal height for the row.
1174 */
4cc4bfaf 1175 void AutoSizeRow(int row, bool setAsMin = true);
23324ae1
FM
1176
1177 /**
1178 Automatically adjusts height of the row to fit its label.
1179 */
1180 void AutoSizeRowLabelSize(int col);
1181
1182 /**
1183 Automatically sizes all rows to fit their contents. If setAsMin is @true the
1184 calculated heights will
1185 also be set as the minimal heights for the rows.
1186 */
4cc4bfaf 1187 void AutoSizeRows(bool setAsMin = true);
23324ae1
FM
1188
1189 /**
1190 AutoSizeColumn()
3c4f71cc 1191
23324ae1 1192 AutoSizeRow()
3c4f71cc 1193
23324ae1 1194 AutoSizeColumns()
3c4f71cc 1195
23324ae1 1196 AutoSizeRows()
3c4f71cc 1197
23324ae1 1198 AutoSize()
3c4f71cc 1199
23324ae1 1200 SetColMinimalWidth()
3c4f71cc 1201
23324ae1 1202 SetRowMinimalHeight()
3c4f71cc 1203
23324ae1 1204 SetColMinimalAcceptableWidth()
3c4f71cc 1205
23324ae1 1206 SetRowMinimalAcceptableHeight()
3c4f71cc 1207
23324ae1 1208 GetColMinimalAcceptableWidth()
3c4f71cc 1209
23324ae1
FM
1210 GetRowMinimalAcceptableHeight()
1211 */
1212
1213
1214 /**
1215 Increments the grid's batch count. When the count is greater than zero
1216 repainting of
1217 the grid is suppressed. Each call to BeginBatch must be matched by a later call
1218 to
1219 EndBatch(). Code that does a lot of grid
1220 modification can be enclosed between BeginBatch and EndBatch calls to avoid
1221 screen flicker. The final EndBatch will cause the grid to be repainted.
3c4f71cc 1222
4cc4bfaf 1223 @see wxGridUpdateLocker
23324ae1
FM
1224 */
1225 void BeginBatch();
1226
1227 /**
1228 This function returns the rectangle that encloses the block of cells
1229 limited by TopLeft and BottomRight cell in device coords and clipped
1230 to the client size of the grid window.
1231 */
4cc4bfaf 1232 wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft,
328f5751 1233 const wxGridCellCoords& bottomRight) const;
23324ae1
FM
1234
1235 /**
1236 Returns @true if columns can be moved by dragging with the mouse. Columns can be
1237 moved
1238 by dragging on their labels.
1239 */
328f5751 1240 bool CanDragColMove() const;
23324ae1
FM
1241
1242 /**
1243 Returns @true if columns can be resized by dragging with the mouse. Columns can
1244 be resized
1245 by dragging the edges of their labels. If grid line dragging is enabled they
1246 can also be
1247 resized by dragging the right edge of the column in the grid cell area
1248 (see wxGrid::EnableDragGridSize).
1249 */
328f5751 1250 bool CanDragColSize() const;
23324ae1
FM
1251
1252 /**
1253 Return @true if the dragging of grid lines to resize rows and columns is enabled
1254 or @false otherwise.
1255 */
328f5751 1256 bool CanDragGridSize() const;
23324ae1
FM
1257
1258 /**
1259 Returns @true if rows can be resized by dragging with the mouse. Rows can be
1260 resized
1261 by dragging the edges of their labels. If grid line dragging is enabled they
1262 can also be
1263 resized by dragging the lower edge of the row in the grid cell area
1264 (see wxGrid::EnableDragGridSize).
1265 */
328f5751 1266 bool CanDragRowSize() const;
23324ae1
FM
1267
1268 /**
1269 Returns @true if the in-place edit control for the current grid cell can be used
1270 and
1271 @false otherwise (e.g. if the current cell is read-only).
1272 */
328f5751 1273 bool CanEnableCellControl() const;
23324ae1
FM
1274
1275 /**
1276 Do we have some place to store attributes in?
1277 */
328f5751 1278 bool CanHaveAttributes() const;
23324ae1
FM
1279
1280 /**
1281 EnableDragRowSize()
3c4f71cc 1282
23324ae1 1283 EnableDragColSize()
3c4f71cc 1284
23324ae1 1285 CanDragRowSize()
3c4f71cc 1286
23324ae1 1287 CanDragColSize()
3c4f71cc 1288
23324ae1 1289 EnableDragColMove()
3c4f71cc 1290
23324ae1 1291 CanDragColMove()
3c4f71cc 1292
23324ae1 1293 EnableDragGridSize()
3c4f71cc 1294
23324ae1 1295 CanDragGridSize()
3c4f71cc 1296
23324ae1 1297 GetColAt()
3c4f71cc 1298
23324ae1 1299 SetColPos()
3c4f71cc 1300
23324ae1 1301 GetColPos()
3c4f71cc 1302
23324ae1 1303 EnableDragCell()
3c4f71cc 1304
23324ae1
FM
1305 CanDragCell()
1306 */
1307
1308
1309 //@{
1310 /**
1311 Return the rectangle corresponding to the grid cell's size and position in
1312 logical
1313 coordinates.
1314 */
328f5751
FM
1315 wxRect CellToRect(int row, int col) const;
1316 const wxRect CellToRect(const wxGridCellCoords& coords) const;
23324ae1
FM
1317 //@}
1318
1319 /**
1320 Clears all data in the underlying grid table and repaints the grid. The table
1321 is not deleted by
1322 this function. If you are using a derived table class then you need to override
1323 wxGridTableBase::Clear for this function to have any effect.
1324 */
1325 void ClearGrid();
1326
1327 /**
1328 Deselects all cells that are currently selected.
1329 */
1330 void ClearSelection();
1331
1332 /**
1333 @ref ctor() wxGrid
3c4f71cc 1334
23324ae1 1335 @ref dtor() ~wxGrid
3c4f71cc 1336
23324ae1 1337 CreateGrid()
3c4f71cc 1338
23324ae1
FM
1339 SetTable()
1340 */
1341
1342
1343 /**
1344 Creates a grid with the specified initial number of rows and columns.
1345 Call this directly after the grid constructor. When you use this
1346 function wxGrid will create and manage a simple table of string values
1347 for you. All of the grid data will be stored in memory.
23324ae1
FM
1348 For applications with more complex data types or relationships, or for
1349 dealing with very large datasets, you should derive your own grid table
1350 class and pass a table object to the grid with SetTable().
1351 */
1352 bool CreateGrid(int numRows, int numCols,
1353 wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);
1354
1355 /**
1356 MoveCursorUp()
3c4f71cc 1357
23324ae1 1358 MoveCursorDown()
3c4f71cc 1359
23324ae1 1360 MoveCursorLeft()
3c4f71cc 1361
23324ae1 1362 MoveCursorRight()
3c4f71cc 1363
23324ae1 1364 MoveCursorPageUp()
3c4f71cc 1365
23324ae1 1366 MoveCursorPageDown()
3c4f71cc 1367
23324ae1 1368 MoveCursorUpBlock()
3c4f71cc 1369
23324ae1 1370 MoveCursorDownBlock()
3c4f71cc 1371
23324ae1 1372 MoveCursorLeftBlock()
3c4f71cc 1373
23324ae1
FM
1374 MoveCursorRightBlock()
1375 */
1376
1377
1378 /**
1379 Deletes one or more columns from a grid starting at the specified position and
1380 returns
1381 @true if successful. The updateLabels argument is not used at present.
23324ae1
FM
1382 If you are using a derived grid table class you will need to override
1383 wxGridTableBase::DeleteCols. See
1384 InsertCols() for further information.
1385 */
1386 bool DeleteCols(int pos = 0, int numCols = 1,
4cc4bfaf 1387 bool updateLabels = true);
23324ae1
FM
1388
1389 /**
1390 Deletes one or more rows from a grid starting at the specified position and
1391 returns
1392 @true if successful. The updateLabels argument is not used at present.
23324ae1
FM
1393 If you are using a derived grid table class you will need to override
1394 wxGridTableBase::DeleteRows. See
1395 InsertRows() for further information.
1396 */
1397 bool DeleteRows(int pos = 0, int numRows = 1,
4cc4bfaf 1398 bool updateLabels = true);
23324ae1
FM
1399
1400 /**
1401 Disables in-place editing of grid cells.
1402 Equivalent to calling EnableCellEditControl(@false).
1403 */
1404 void DisableCellEditControl();
1405
1406 /**
1407 Disables column moving by dragging with the mouse. Equivalent to passing @false
1408 to
1409 EnableDragColMove().
1410 */
1411 void DisableDragColMove();
1412
1413 /**
1414 Disables column sizing by dragging with the mouse. Equivalent to passing @false
1415 to
1416 EnableDragColSize().
1417 */
1418 void DisableDragColSize();
1419
1420 /**
1421 Disable mouse dragging of grid lines to resize rows and columns. Equivalent to
1422 passing
1423 @false to EnableDragGridSize()
1424 */
1425 void DisableDragGridSize();
1426
1427 /**
1428 Disables row sizing by dragging with the mouse. Equivalent to passing @false to
1429 EnableDragRowSize().
1430 */
1431 void DisableDragRowSize();
1432
1433 /**
1434 Enables or disables in-place editing of grid cell data. The grid will issue
1435 either a
1436 wxEVT_GRID_EDITOR_SHOWN or wxEVT_GRID_EDITOR_HIDDEN event.
1437 */
4cc4bfaf 1438 void EnableCellEditControl(bool enable = true);
23324ae1
FM
1439
1440 /**
1441 Enables or disables column moving by dragging with the mouse.
1442 */
4cc4bfaf 1443 void EnableDragColMove(bool enable = true);
23324ae1
FM
1444
1445 /**
1446 Enables or disables column sizing by dragging with the mouse.
1447 */
4cc4bfaf 1448 void EnableDragColSize(bool enable = true);
23324ae1
FM
1449
1450 /**
1451 Enables or disables row and column resizing by dragging gridlines with the
1452 mouse.
1453 */
4cc4bfaf 1454 void EnableDragGridSize(bool enable = true);
23324ae1
FM
1455
1456 /**
1457 Enables or disables row sizing by dragging with the mouse.
1458 */
4cc4bfaf 1459 void EnableDragRowSize(bool enable = true);
23324ae1
FM
1460
1461 /**
1462 If the edit argument is @false this function sets the whole grid as read-only.
1463 If the
1464 argument is @true the grid is set to the default state where cells may be
1465 editable. In the
1466 default state you can set single grid cells and whole rows and columns to be
1467 editable or
1468 read-only via
1469 wxGridCellAttribute::SetReadOnly. For single
1470 cells you can also use the shortcut function
1471 SetReadOnly().
23324ae1
FM
1472 For more information about controlling grid cell attributes see the
1473 wxGridCellAttr cell attribute class and the
4cc4bfaf 1474 @ref overview_gridoverview.
23324ae1
FM
1475 */
1476 void EnableEditing(bool edit);
1477
1478 /**
1479 Turns the drawing of grid lines on or off.
1480 */
4cc4bfaf 1481 void EnableGridLines(bool enable = true);
23324ae1
FM
1482
1483 /**
1484 Decrements the grid's batch count. When the count is greater than zero
1485 repainting of
1486 the grid is suppressed. Each previous call to
1487 BeginBatch() must be matched by a later call to
1488 EndBatch. Code that does a lot of grid modification can be enclosed between
1489 BeginBatch and EndBatch calls to avoid screen flicker. The final EndBatch will
1490 cause the grid to be repainted.
3c4f71cc 1491
4cc4bfaf 1492 @see wxGridUpdateLocker
23324ae1
FM
1493 */
1494 void EndBatch();
1495
1496 /**
1497 Overridden wxWindow method.
1498 */
4cc4bfaf 1499 void Fit();
23324ae1
FM
1500
1501 /**
1502 Causes immediate repainting of the grid. Use this instead of the usual
1503 wxWindow::Refresh.
1504 */
1505 void ForceRefresh();
1506
1507 /**
1508 Returns the number of times that BeginBatch() has been called
1509 without (yet) matching calls to EndBatch(). While
1510 the grid's batch count is greater than zero the display will not be updated.
1511 */
328f5751 1512 int GetBatchCount() const;
23324ae1
FM
1513
1514 /**
1515 Sets the arguments to the horizontal and vertical text alignment values for the
1516 grid cell at the specified location.
23324ae1 1517 Horizontal alignment will be one of wxALIGN_LEFT, wxALIGN_CENTRE or
7c913512 1518 wxALIGN_RIGHT.
3c4f71cc 1519
23324ae1
FM
1520 Vertical alignment will be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
1521 */
328f5751 1522 void GetCellAlignment(int row, int col, int* horiz, int* vert) const;
23324ae1
FM
1523
1524 /**
1525 Returns the background colour of the cell at the specified location.
1526 */
328f5751 1527 wxColour GetCellBackgroundColour(int row, int col) const;
23324ae1
FM
1528
1529 /**
1530 Returns a pointer to the editor for the cell at the specified location.
23324ae1
FM
1531 See wxGridCellEditor and
1532 the @ref overview_gridoverview "wxGrid overview" for more information about
1533 cell editors and renderers.
1534 */
328f5751 1535 wxGridCellEditor* GetCellEditor(int row, int col) const;
23324ae1
FM
1536
1537 /**
1538 Returns the font for text in the grid cell at the specified location.
1539 */
328f5751 1540 wxFont GetCellFont(int row, int col) const;
23324ae1
FM
1541
1542 /**
1543 Returns a pointer to the renderer for the grid cell at the specified location.
23324ae1
FM
1544 See wxGridCellRenderer and
1545 the @ref overview_gridoverview "wxGrid overview" for more information about
1546 cell editors and renderers.
1547 */
328f5751 1548 wxGridCellRenderer* GetCellRenderer(int row, int col) const;
23324ae1
FM
1549
1550 /**
1551 Returns the text colour for the grid cell at the specified location.
1552 */
328f5751 1553 wxColour GetCellTextColour(int row, int col) const;
23324ae1
FM
1554
1555 //@{
1556 /**
1557 Returns the string contained in the cell at the specified location. For simple
1558 applications where a
1559 grid object automatically uses a default grid table of string values you use
1560 this function together
1561 with SetCellValue() to access cell values.
23324ae1
FM
1562 For more complex applications where you have derived your own grid table class
1563 that contains
1564 various data types (e.g. numeric, boolean or user-defined custom types) then
1565 you only use this
1566 function for those cells that contain string values.
23324ae1
FM
1567 See wxGridTableBase::CanGetValueAs
1568 and the @ref overview_gridoverview "wxGrid overview" for more information.
1569 */
328f5751
FM
1570 wxString GetCellValue(int row, int col) const;
1571 const wxString GetCellValue(const wxGridCellCoords& coords) const;
23324ae1
FM
1572 //@}
1573
1574 /**
1575 Returns the column ID of the specified column position.
1576 */
328f5751 1577 int GetColAt(int colPos) const;
23324ae1
FM
1578
1579 /**
1580 Returns the pen used for vertical grid lines. This virtual function may be
1581 overridden in derived classes in order to change the appearance of individual
1582 grid lines for the given column @e col.
23324ae1
FM
1583 See GetRowGridLinePen() for an example.
1584 */
1585 wxPen GetColGridLinePen(int col);
1586
1587 /**
1588 Sets the arguments to the current column label alignment values.
23324ae1
FM
1589 Horizontal alignment will be one of wxALIGN_LEFT, wxALIGN_CENTRE or
1590 wxALIGN_RIGHT.
3c4f71cc 1591
23324ae1
FM
1592 Vertical alignment will be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
1593 */
328f5751 1594 void GetColLabelAlignment(int* horiz, int* vert) const;
23324ae1
FM
1595
1596 /**
1597 Returns the current height of the column labels.
1598 */
328f5751 1599 int GetColLabelSize() const;
23324ae1
FM
1600
1601 /**
1602 Returns the specified column label. The default grid table class provides
1603 column labels of
1604 the form A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can
1605 override
1606 wxGridTableBase::GetColLabelValue to provide
1607 your own labels.
1608 */
328f5751 1609 wxString GetColLabelValue(int col) const;
23324ae1
FM
1610
1611 /**
3c4f71cc 1612
23324ae1 1613 */
328f5751 1614 int GetColLeft(int col) const;
23324ae1
FM
1615
1616 /**
1617 This returns the value of the lowest column width that can be handled
1618 correctly. See
1619 member SetColMinimalAcceptableWidth() for details.
1620 */
328f5751 1621 int GetColMinimalAcceptableWidth() const;
23324ae1
FM
1622
1623 /**
1624 Get the minimal width of the given column/row.
1625 */
328f5751 1626 int GetColMinimalWidth(int col) const;
23324ae1
FM
1627
1628 /**
1629 Returns the position of the specified column.
1630 */
328f5751 1631 int GetColPos(int colID) const;
23324ae1
FM
1632
1633 /**
3c4f71cc 1634
23324ae1 1635 */
328f5751 1636 int GetColRight(int col) const;
23324ae1
FM
1637
1638 /**
1639 Returns the width of the specified column.
1640 */
328f5751 1641 int GetColSize(int col) const;
23324ae1
FM
1642
1643 /**
1644 Sets the arguments to the current default horizontal and vertical text alignment
1645 values.
23324ae1 1646 Horizontal alignment will be one of wxALIGN_LEFT, wxALIGN_CENTRE or
7c913512 1647 wxALIGN_RIGHT.
3c4f71cc 1648
23324ae1
FM
1649 Vertical alignment will be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
1650 */
328f5751 1651 void GetDefaultCellAlignment(int* horiz, int* vert) const;
23324ae1
FM
1652
1653 /**
1654 Returns the current default background colour for grid cells.
1655 */
328f5751 1656 wxColour GetDefaultCellBackgroundColour() const;
23324ae1
FM
1657
1658 /**
1659 Returns the current default font for grid cell text.
1660 */
328f5751 1661 wxFont GetDefaultCellFont() const;
23324ae1
FM
1662
1663 /**
1664 Returns the current default colour for grid cell text.
1665 */
328f5751 1666 wxColour GetDefaultCellTextColour() const;
23324ae1
FM
1667
1668 /**
1669 Returns the default height for column labels.
1670 */
328f5751 1671 int GetDefaultColLabelSize() const;
23324ae1
FM
1672
1673 /**
1674 Returns the current default width for grid columns.
1675 */
328f5751 1676 int GetDefaultColSize() const;
23324ae1
FM
1677
1678 /**
1679 Returns a pointer to the current default grid cell editor.
23324ae1
FM
1680 See wxGridCellEditor and
1681 the @ref overview_gridoverview "wxGrid overview" for more information about
1682 cell editors and renderers.
1683 */
328f5751 1684 wxGridCellEditor* GetDefaultEditor() const;
23324ae1
FM
1685
1686 //@{
1687 /**
3c4f71cc 1688
23324ae1 1689 */
328f5751
FM
1690 wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
1691 const wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const;
23324ae1
FM
1692 //@}
1693
1694 /**
3c4f71cc 1695
23324ae1 1696 */
328f5751 1697 wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
23324ae1
FM
1698
1699 /**
1700 Returns the pen used for grid lines. This virtual function may be overridden in
1701 derived classes in order to change the appearance of grid lines. Note that
1702 currently the pen width must be 1.
3c4f71cc 1703
4cc4bfaf 1704 @see GetColGridLinePen(), GetRowGridLinePen()
23324ae1
FM
1705 */
1706 wxPen GetDefaultGridLinePen();
1707
1708 /**
1709 Returns a pointer to the current default grid cell renderer.
23324ae1
FM
1710 See wxGridCellRenderer and
1711 the @ref overview_gridoverview "wxGrid overview" for more information about
1712 cell editors and renderers.
1713 */
328f5751 1714 wxGridCellRenderer* GetDefaultRenderer() const;
23324ae1
FM
1715
1716 /**
3c4f71cc 1717
23324ae1 1718 */
328f5751 1719 wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
23324ae1
FM
1720
1721 /**
3c4f71cc 1722
23324ae1 1723 */
328f5751 1724 wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
23324ae1
FM
1725
1726 /**
1727 Returns the default width for the row labels.
1728 */
328f5751 1729 int GetDefaultRowLabelSize() const;
23324ae1
FM
1730
1731 /**
1732 Returns the current default height for grid rows.
1733 */
328f5751 1734 int GetDefaultRowSize() const;
23324ae1
FM
1735
1736 /**
1737 Returns the current grid cell column position.
1738 */
328f5751 1739 int GetGridCursorCol() const;
23324ae1
FM
1740
1741 /**
1742 Returns the current grid cell row position.
1743 */
328f5751 1744 int GetGridCursorRow() const;
23324ae1
FM
1745
1746 /**
1747 Returns the colour used for grid lines.
3c4f71cc 1748
4cc4bfaf 1749 @see GetDefaultGridLinePen()
23324ae1 1750 */
328f5751 1751 wxColour GetGridLineColour() const;
23324ae1
FM
1752
1753 /**
1754 Returns the colour used for the background of row and column labels.
1755 */
328f5751 1756 wxColour GetLabelBackgroundColour() const;
23324ae1
FM
1757
1758 /**
1759 Returns the font used for row and column labels.
1760 */
328f5751 1761 wxFont GetLabelFont() const;
23324ae1
FM
1762
1763 /**
1764 Returns the colour used for row and column label text.
1765 */
328f5751 1766 wxColour GetLabelTextColour() const;
23324ae1
FM
1767
1768 /**
1769 Returns the total number of grid columns (actually the number of columns in the
1770 underlying grid
1771 table).
1772 */
328f5751 1773 int GetNumberCols() const;
23324ae1
FM
1774
1775 /**
1776 Returns the total number of grid rows (actually the number of rows in the
1777 underlying grid table).
1778 */
328f5751 1779 int GetNumberRows() const;
23324ae1
FM
1780
1781 /**
3c4f71cc 1782
23324ae1 1783 */
328f5751 1784 wxGridCellAttr* GetOrCreateCellAttr(int row, int col) const;
23324ae1
FM
1785
1786 /**
1787 Returns the pen used for horizontal grid lines. This virtual function may be
1788 overridden in derived classes in order to change the appearance of individual
1789 grid line for the given row @e row.
23324ae1
FM
1790 Example:
1791 */
1792 wxPen GetRowGridLinePen(int row);
1793
1794 /**
1795 Sets the arguments to the current row label alignment values.
7c913512 1796 Horizontal alignment will be one of wxLEFT, wxCENTRE or wxRIGHT.
3c4f71cc 1797
23324ae1
FM
1798 Vertical alignment will be one of wxTOP, wxCENTRE or wxBOTTOM.
1799 */
328f5751 1800 void GetRowLabelAlignment(int* horiz, int* vert) const;
23324ae1
FM
1801
1802 /**
1803 Returns the current width of the row labels.
1804 */
328f5751 1805 int GetRowLabelSize() const;
23324ae1
FM
1806
1807 /**
1808 Returns the specified row label. The default grid table class provides numeric
1809 row labels.
1810 If you are using a custom grid table you can override
1811 wxGridTableBase::GetRowLabelValue to provide
1812 your own labels.
1813 */
328f5751 1814 wxString GetRowLabelValue(int row) const;
23324ae1
FM
1815
1816 /**
1817 This returns the value of the lowest row width that can be handled correctly.
1818 See
1819 member SetRowMinimalAcceptableHeight() for details.
1820 */
328f5751 1821 int GetRowMinimalAcceptableHeight() const;
23324ae1
FM
1822
1823 /**
3c4f71cc 1824
23324ae1 1825 */
328f5751 1826 int GetRowMinimalHeight(int col) const;
23324ae1
FM
1827
1828 /**
1829 Returns the height of the specified row.
1830 */
328f5751 1831 int GetRowSize(int row) const;
23324ae1
FM
1832
1833 /**
1834 Returns the number of pixels per horizontal scroll increment. The default is 15.
3c4f71cc 1835
4cc4bfaf 1836 @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY()
23324ae1 1837 */
328f5751 1838 int GetScrollLineX() const;
23324ae1
FM
1839
1840 /**
1841 Returns the number of pixels per vertical scroll increment. The default is 15.
3c4f71cc 1842
4cc4bfaf 1843 @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY()
23324ae1 1844 */
328f5751 1845 int GetScrollLineY() const;
23324ae1
FM
1846
1847 /**
1848 Returns an array of singly selected cells.
1849 */
328f5751 1850 wxGridCellCoordsArray GetSelectedCells() const;
23324ae1
FM
1851
1852 /**
1853 Returns an array of selected cols.
bb778cae
VZ
1854
1855 Please notice that this method alone is not sufficient to find all the
1856 selected columns, see the explanation in GetSelectedRows()
1857 documentation for more details.
23324ae1 1858 */
328f5751 1859 wxArrayInt GetSelectedCols() const;
23324ae1
FM
1860
1861 /**
1862 Returns an array of selected rows.
bb778cae
VZ
1863
1864 Note that this array contains only the rows which were individually
1865 selected (using the mouse with the row header or combinations involving
1866 @c Ctrl key for selecting individual rows). In particular if the user
1867 selects many rows at once (e.g. by pressing @c Shift key) this array is
1868 @b not updated because this could mean storing a very large number of
1869 elements in it. So in general to find the current selection you need to
1870 use both this method and GetSelectionBlockTopLeft() and
1871 GetSelectionBlockBottomRight() ones.
23324ae1 1872 */
328f5751 1873 wxArrayInt GetSelectedRows() const;
23324ae1
FM
1874
1875 /**
1876 Access or update the selection fore/back colours
1877 */
328f5751 1878 wxColour GetSelectionBackground() const;
23324ae1
FM
1879
1880 /**
1881 Returns an array of the bottom right corners of blocks of selected cells,
1882 see GetSelectionBlockTopLeft().
1883 */
328f5751 1884 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
23324ae1
FM
1885
1886 /**
1887 Returns an array of the top left corners of blocks of selected cells,
1888 see GetSelectionBlockBottomRight().
1889 */
328f5751 1890 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
23324ae1
FM
1891
1892 /**
3c4f71cc 1893
23324ae1 1894 */
328f5751 1895 wxColour GetSelectionForeground() const;
23324ae1
FM
1896
1897 /**
1898 Returns the current selection mode, see SetSelectionMode().
1899 */
328f5751 1900 wxGrid::wxGridSelectionModes GetSelectionMode() const;
23324ae1
FM
1901
1902 /**
1903 Returns a base pointer to the current table object.
1904 */
328f5751 1905 wxGridTableBase* GetTable() const;
23324ae1
FM
1906
1907 /**
1908 Returned number of whole cols visible.
1909 */
328f5751 1910 int GetViewWidth() const;
23324ae1
FM
1911
1912 /**
1913 EnableGridLines()
3c4f71cc 1914
23324ae1 1915 GridLinesEnabled()
3c4f71cc 1916
23324ae1 1917 SetGridLineColour()
3c4f71cc 1918
23324ae1 1919 GetGridLineColour()
3c4f71cc 1920
23324ae1 1921 GetDefaultGridLinePen()
3c4f71cc 1922
23324ae1 1923 GetRowGridLinePen()
3c4f71cc 1924
23324ae1
FM
1925 GetColGridLinePen()
1926 */
1927
1928
1929 /**
1930 Returns @true if drawing of grid lines is turned on, @false otherwise.
1931 */
328f5751 1932 bool GridLinesEnabled() const;
23324ae1
FM
1933
1934 /**
1935 Hides the in-place cell edit control.
1936 */
1937 void HideCellEditControl();
1938
1939 /**
1940 Hides the column labels by calling SetColLabelSize()
1941 with a size of 0. Show labels again by calling that method with
1942 a width greater than 0.
1943 */
1944 void HideColLabels();
1945
1946 /**
1947 Hides the row labels by calling SetRowLabelSize()
1948 with a size of 0. Show labels again by calling that method with
1949 a width greater than 0.
1950 */
1951 void HideRowLabels();
1952
1953 /**
1954 Init the m_colWidths/Rights arrays
1955 */
1956 void InitColWidths();
1957
1958 /**
1add55ae 1959 @note @e never access m_row/col arrays directly because they are created
23324ae1 1960 on demand, @e always use accessor functions instead!
23324ae1
FM
1961 Init the m_rowHeights/Bottoms arrays with default values.
1962 */
1963 void InitRowHeights();
1964
1965 /**
1966 Inserts one or more new columns into a grid with the first new column at the
1967 specified position and returns @true if successful. The updateLabels argument is
1968 not
1969 used at present.
23324ae1
FM
1970 The sequence of actions begins with the grid object requesting the underlying
1971 grid
1972 table to insert new columns. If this is successful the table notifies the grid
1973 and the
1974 grid updates the display. For a default grid (one where you have called
1975 wxGrid::CreateGrid) this process is automatic. If you are
1976 using a custom grid table (specified with wxGrid::SetTable)
1977 then you must override
1978 wxGridTableBase::InsertCols in your derived
1979 table class.
1980 */
1981 bool InsertCols(int pos = 0, int numCols = 1,
4cc4bfaf 1982 bool updateLabels = true);
23324ae1
FM
1983
1984 /**
1985 Inserts one or more new rows into a grid with the first new row at the specified
1986 position and returns @true if successful. The updateLabels argument is not used
1987 at
1988 present.
23324ae1
FM
1989 The sequence of actions begins with the grid object requesting the underlying
1990 grid
1991 table to insert new rows. If this is successful the table notifies the grid and
1992 the
1993 grid updates the display. For a default grid (one where you have called
1994 wxGrid::CreateGrid) this process is automatic. If you are
1995 using a custom grid table (specified with wxGrid::SetTable)
1996 then you must override
1997 wxGridTableBase::InsertRows in your derived
1998 table class.
1999 */
2000 bool InsertRows(int pos = 0, int numRows = 1,
4cc4bfaf 2001 bool updateLabels = true);
23324ae1
FM
2002
2003 /**
2004 Returns @true if the in-place edit control is currently enabled.
2005 */
328f5751 2006 bool IsCellEditControlEnabled() const;
23324ae1
FM
2007
2008 /**
2009 Returns @true if the current cell has been set to read-only
2010 (see wxGrid::SetReadOnly).
2011 */
328f5751 2012 bool IsCurrentCellReadOnly() const;
23324ae1
FM
2013
2014 /**
2015 Returns @false if the whole grid has been set as read-only or @true otherwise.
2016 See EnableEditing() for more information about
2017 controlling the editing status of grid cells.
2018 */
328f5751 2019 bool IsEditable() const;
23324ae1
FM
2020
2021 //@{
2022 /**
2023 Is this cell currently selected.
2024 */
328f5751
FM
2025 bool IsInSelection(int row, int col) const;
2026 const bool IsInSelection(const wxGridCellCoords& coords) const;
23324ae1
FM
2027 //@}
2028
2029 /**
2030 Returns @true if the cell at the specified location can't be edited.
2031 See also IsReadOnly().
2032 */
328f5751 2033 bool IsReadOnly(int row, int col) const;
23324ae1
FM
2034
2035 /**
2036 Returns @true if there are currently rows, columns or blocks of cells selected.
2037 */
328f5751 2038 bool IsSelection() const;
23324ae1
FM
2039
2040 //@{
2041 /**
2042 Returns @true if a cell is either wholly visible (the default) or at least
2043 partially
2044 visible in the grid window.
2045 */
328f5751
FM
2046 bool IsVisible(int row, int col, bool wholeCellVisible = true) const;
2047 const bool IsVisible(const wxGridCellCoords& coords,
2048 bool wholeCellVisible = true) const;
23324ae1
FM
2049 //@}
2050
2051 //@{
2052 /**
2053 Brings the specified cell into the visible grid cell area with minimal
2054 scrolling. Does
2055 nothing if the cell is already visible.
2056 */
2057 void MakeCellVisible(int row, int col);
7c913512 2058 void MakeCellVisible(const wxGridCellCoords& coords);
23324ae1
FM
2059 //@}
2060
2061 /**
2062 Moves the grid cursor down by one row. If a block of cells was previously
2063 selected it
2064 will expand if the argument is @true or be cleared if the argument is @false.
2065 */
2066 bool MoveCursorDown(bool expandSelection);
2067
2068 /**
2069 Moves the grid cursor down in the current column such that it skips to the
2070 beginning or
2071 end of a block of non-empty cells. If a block of cells was previously selected
2072 it
2073 will expand if the argument is @true or be cleared if the argument is @false.
2074 */
2075 bool MoveCursorDownBlock(bool expandSelection);
2076
2077 /**
2078 Moves the grid cursor left by one column. If a block of cells was previously
2079 selected it
2080 will expand if the argument is @true or be cleared if the argument is @false.
2081 */
2082 bool MoveCursorLeft(bool expandSelection);
2083
2084 /**
2085 Moves the grid cursor left in the current row such that it skips to the
2086 beginning or
2087 end of a block of non-empty cells. If a block of cells was previously selected
2088 it
2089 will expand if the argument is @true or be cleared if the argument is @false.
2090 */
2091 bool MoveCursorLeftBlock(bool expandSelection);
2092
2093 /**
2094 Moves the grid cursor right by one column. If a block of cells was previously
2095 selected it
2096 will expand if the argument is @true or be cleared if the argument is @false.
2097 */
2098 bool MoveCursorRight(bool expandSelection);
2099
2100 /**
2101 Moves the grid cursor right in the current row such that it skips to the
2102 beginning or
2103 end of a block of non-empty cells. If a block of cells was previously selected
2104 it
2105 will expand if the argument is @true or be cleared if the argument is @false.
2106 */
2107 bool MoveCursorRightBlock(bool expandSelection);
2108
2109 /**
2110 Moves the grid cursor up by one row. If a block of cells was previously
2111 selected it
2112 will expand if the argument is @true or be cleared if the argument is @false.
2113 */
2114 bool MoveCursorUp(bool expandSelection);
2115
2116 /**
2117 Moves the grid cursor up in the current column such that it skips to the
2118 beginning or
2119 end of a block of non-empty cells. If a block of cells was previously selected
2120 it
2121 will expand if the argument is @true or be cleared if the argument is @false.
2122 */
2123 bool MoveCursorUpBlock(bool expandSelection);
2124
2125 /**
2126 Moves the grid cursor down by some number of rows so that the previous bottom
2127 visible row
2128 becomes the top visible row.
2129 */
2130 bool MovePageDown();
2131
2132 /**
2133 Moves the grid cursor up by some number of rows so that the previous top
2134 visible row
2135 becomes the bottom visible row.
2136 */
2137 bool MovePageUp();
2138
2139 /**
2140 Methods for a registry for mapping data types to Renderers/Editors
2141 */
2142 void RegisterDataType(const wxString& typeName,
2143 wxGridCellRenderer* renderer,
2144 wxGridCellEditor* editor);
2145
2146 /**
2147 SetRowLabelValue()
3c4f71cc 2148
23324ae1 2149 SetColLabelValue()
3c4f71cc 2150
23324ae1 2151 GetRowLabelValue()
3c4f71cc 2152
23324ae1 2153 GetColLabelValue()
3c4f71cc 2154
23324ae1 2155 SetUseNativeColLabels()
3c4f71cc 2156
23324ae1 2157 HideColLabels()
3c4f71cc 2158
23324ae1 2159 HideRowLabels()
3c4f71cc 2160
23324ae1 2161 SetRowLabelSize()
3c4f71cc 2162
23324ae1 2163 SetColLabelSize()
3c4f71cc 2164
23324ae1 2165 GetRowLabelSize()
3c4f71cc 2166
23324ae1 2167 GetColLabelSize()
3c4f71cc 2168
23324ae1 2169 AutoSizeRowLabelSize()
3c4f71cc 2170
23324ae1 2171 AutoSizeColLabelSize()
3c4f71cc 2172
23324ae1 2173 GetDefaultRowLabelSize()
3c4f71cc 2174
23324ae1 2175 GetDefaultColLabelSize()
3c4f71cc 2176
23324ae1 2177 SetRowLabelAlignment()
3c4f71cc 2178
23324ae1 2179 SetColLabelAlignment()
3c4f71cc 2180
23324ae1 2181 GetRowLabelAlignment()
3c4f71cc 2182
23324ae1 2183 GetColLabelAlignment()
3c4f71cc 2184
23324ae1 2185 SetLabelFont()
3c4f71cc 2186
23324ae1 2187 SetLabelTextColour()
3c4f71cc 2188
23324ae1 2189 SetLabelBackgroundColour()
3c4f71cc 2190
23324ae1 2191 GetLabelFont()
3c4f71cc 2192
23324ae1 2193 GetLabelBackgroundColour()
3c4f71cc 2194
23324ae1 2195 GetLabelTextColour()
3c4f71cc 2196
23324ae1 2197 SetColLabelTextOrientation()
3c4f71cc 2198
23324ae1
FM
2199 GetColLabelTextOrientation()
2200 */
2201
2202
2203 /**
2204 Sets the value of the current grid cell to the current in-place edit control
2205 value.
2206 This is called automatically when the grid cursor moves from the current cell
2207 to a
2208 new cell. It is also a good idea to call this function when closing a grid since
2209 any edits to the final cell location will not be saved otherwise.
2210 */
2211 void SaveEditControlValue();
2212
2213 /**
2214 Selects all cells in the grid.
2215 */
2216 void SelectAll();
2217
2218 //@{
2219 /**
2220 Selects a rectangular block of cells. If addToSelected is @false then any
2221 existing selection will be
2222 deselected; if @true the column will be added to the existing selection.
2223 */
2224 void SelectBlock(int topRow, int leftCol, int bottomRow,
2225 int rightCol,
4cc4bfaf 2226 bool addToSelected = false);
7c913512
FM
2227 void SelectBlock(const wxGridCellCoords& topLeft,
2228 const wxGridCellCoords& bottomRight,
4cc4bfaf 2229 bool addToSelected = false);
23324ae1
FM
2230 //@}
2231
2232 /**
2233 Selects the specified column. If addToSelected is @false then any existing
2234 selection will be
2235 deselected; if @true the column will be added to the existing selection.
2236 */
4cc4bfaf 2237 void SelectCol(int col, bool addToSelected = false);
23324ae1
FM
2238
2239 /**
2240 Selects the specified row. If addToSelected is @false then any existing
2241 selection will be
2242 deselected; if @true the row will be added to the existing selection.
2243 */
4cc4bfaf 2244 void SelectRow(int row, bool addToSelected = false);
23324ae1
FM
2245
2246 /**
2247 ClearSelection()
3c4f71cc 2248
23324ae1 2249 IsSelection()
3c4f71cc 2250
23324ae1 2251 SelectAll()
3c4f71cc 2252
23324ae1 2253 SelectBlock()
3c4f71cc 2254
23324ae1 2255 SelectCol()
3c4f71cc 2256
23324ae1
FM
2257 SelectRow()
2258 */
2259
2260
2261 /**
2262 This function returns the rectangle that encloses the selected cells
2263 in device coords and clipped to the client size of the grid window.
2264 */
328f5751 2265 wxRect SelectionToDeviceRect() const;
23324ae1
FM
2266
2267 //@{
2268 /**
2269 Sets the horizontal and vertical alignment for grid cell text at the specified
2270 location.
23324ae1 2271 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
7c913512 2272 wxALIGN_RIGHT.
3c4f71cc 2273
23324ae1
FM
2274 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2275 wxALIGN_BOTTOM.
2276 */
2277 void SetCellAlignment(int row, int col, int horiz, int vert);
7c913512 2278 void SetCellAlignment(int align, int row, int col);
23324ae1
FM
2279 //@}
2280
2281 /**
3c4f71cc 2282
23324ae1
FM
2283 */
2284 void SetCellBackgroundColour(int row, int col,
2285 const wxColour& colour);
2286
2287 /**
2288 Sets the editor for the grid cell at the specified location.
2289 The grid will take ownership of the pointer.
23324ae1
FM
2290 See wxGridCellEditor and
2291 the @ref overview_gridoverview "wxGrid overview" for more information about
2292 cell editors and renderers.
2293 */
2294 void SetCellEditor(int row, int col, wxGridCellEditor* editor);
2295
2296 /**
2297 Sets the font for text in the grid cell at the specified location.
2298 */
2299 void SetCellFont(int row, int col, const wxFont& font);
2300
2301 /**
2302 Sets the renderer for the grid cell at the specified location.
2303 The grid will take ownership of the pointer.
23324ae1
FM
2304 See wxGridCellRenderer and
2305 the @ref overview_gridoverview "wxGrid overview" for more information about
2306 cell editors and renderers.
2307 */
2308 void SetCellRenderer(int row, int col,
2309 wxGridCellRenderer* renderer);
2310
2311 //@{
2312 /**
2313 Sets the text colour for the grid cell at the specified location.
2314 */
2315 void SetCellTextColour(int row, int col, const wxColour& colour);
7c913512
FM
2316 void SetCellTextColour(const wxColour& val, int row, int col);
2317 void SetCellTextColour(const wxColour& colour);
23324ae1
FM
2318 //@}
2319
2320 //@{
2321 /**
2322 Sets the string value for the cell at the specified location. For simple
2323 applications where a
2324 grid object automatically uses a default grid table of string values you use
2325 this function together
2326 with GetCellValue() to access cell values.
23324ae1
FM
2327 For more complex applications where you have derived your own grid table class
2328 that contains
2329 various data types (e.g. numeric, boolean or user-defined custom types) then
2330 you only use this
2331 function for those cells that contain string values.
23324ae1 2332 The last form is for backward compatibility only.
23324ae1
FM
2333 See wxGridTableBase::CanSetValueAs
2334 and the @ref overview_gridoverview "wxGrid overview" for more information.
2335 */
2336 void SetCellValue(int row, int col, const wxString& s);
7c913512
FM
2337 void SetCellValue(const wxGridCellCoords& coords,
2338 const wxString& s);
2339 void SetCellValue(const wxString& val, int row, int col);
23324ae1
FM
2340 //@}
2341
2342 /**
2343 Sets the cell attributes for all cells in the specified column.
23324ae1
FM
2344 For more information about controlling grid cell attributes see the
2345 wxGridCellAttr cell attribute class and the
4cc4bfaf 2346 @ref overview_gridoverview.
23324ae1
FM
2347 */
2348 void SetColAttr(int col, wxGridCellAttr* attr);
2349
2350 /**
2351 Sets the specified column to display boolean values. wxGrid displays boolean
2352 values with a checkbox.
2353 */
2354 void SetColFormatBool(int col);
2355
2356 /**
2357 Sets the specified column to display data in a custom format.
2358 See the @ref overview_gridoverview "wxGrid overview" for more information on
2359 working
2360 with custom data types.
2361 */
2362 void SetColFormatCustom(int col, const wxString& typeName);
2363
2364 /**
2365 Sets the specified column to display floating point values with the given width
2366 and precision.
2367 */
2368 void SetColFormatFloat(int col, int width = -1,
2369 int precision = -1);
2370
2371 /**
2372 Sets the specified column to display integer values.
2373 */
2374 void SetColFormatNumber(int col);
2375
2376 /**
2377 Sets the horizontal and vertical alignment of column label text.
23324ae1
FM
2378 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
2379 wxALIGN_RIGHT.
23324ae1
FM
2380 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2381 wxALIGN_BOTTOM.
2382 */
2383 void SetColLabelAlignment(int horiz, int vert);
2384
2385 /**
2386 Sets the height of the column labels.
4cc4bfaf 2387 If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
23324ae1
FM
2388 automatically
2389 so that no label is truncated. Note that this could be slow for a large table.
2390 */
2391 void SetColLabelSize(int height);
2392
2393 /**
2394 Set the value for the given column label. If you are using a derived grid table
2395 you must
2396 override wxGridTableBase::SetColLabelValue
2397 for this to have any effect.
2398 */
2399 void SetColLabelValue(int col, const wxString& value);
2400
2401 /**
2402 This modifies the minimum column width that can be handled correctly.
2403 Specifying a low value here
2404 allows smaller grid cells to be dealt with correctly. Specifying a value here
2405 which is much smaller
2406 than the actual minimum size will incur a performance penalty in the functions
2407 which perform
2408 grid cell index lookup on the basis of screen coordinates.
2409 This should normally be called when creating the grid because it will not
2410 resize existing columns
2411 with sizes smaller than the value specified here.
2412 */
2413 void SetColMinimalAcceptableWidth(int width);
2414
2415 /**
2416 Sets the minimal width for the specified column. This should normally be called
2417 when creating the grid
2418 because it will not resize a column that is already narrower than the minimal
2419 width.
2420 The width argument must be higher than the minimimal acceptable column width,
2421 see
2422 GetColMinimalAcceptableWidth().
2423 */
2424 void SetColMinimalWidth(int col, int width);
2425
2426 /**
2427 Sets the position of the specified column.
2428 */
2429 void SetColPos(int colID, int newPos);
2430
2431 /**
2432 Sets the width of the specified column.
23324ae1
FM
2433 This function does not refresh the grid. If you are calling it outside of a
2434 BeginBatch / EndBatch
2435 block you can use ForceRefresh() to see the changes.
23324ae1
FM
2436 Automatically sizes the column to fit its contents. If setAsMin is @true the
2437 calculated width will
2438 also be set as the minimal width for the column.
2439 */
2440 void SetColSize(int col, int width);
2441
2442 /**
2443 Sets the default horizontal and vertical alignment for grid cell text.
23324ae1
FM
2444 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
2445 wxALIGN_RIGHT.
23324ae1
FM
2446 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2447 wxALIGN_BOTTOM.
2448 */
2449 void SetDefaultCellAlignment(int horiz, int vert);
2450
2451 /**
2452 Sets the default background colour for grid cells.
2453 */
2454 void SetDefaultCellBackgroundColour(const wxColour& colour);
2455
2456 /**
2457 Sets the default font to be used for grid cell text.
2458 */
2459 void SetDefaultCellFont(const wxFont& font);
2460
2461 /**
2462 Sets the current default colour for grid cell text.
2463 */
2464 void SetDefaultCellTextColour(const wxColour& colour);
2465
2466 /**
2467 Sets the default width for columns in the grid. This will only affect columns
2468 subsequently added to
2469 the grid unless resizeExistingCols is @true.
2470 */
2471 void SetDefaultColSize(int width,
4cc4bfaf 2472 bool resizeExistingCols = false);
23324ae1
FM
2473
2474 /**
2475 Sets the default editor for grid cells. The grid will take ownership of the
2476 pointer.
23324ae1
FM
2477 See wxGridCellEditor and
2478 the @ref overview_gridoverview "wxGrid overview" for more information about
2479 cell editors and renderers.
2480 */
2481 void SetDefaultEditor(wxGridCellEditor* editor);
2482
2483 /**
2484 Sets the default renderer for grid cells. The grid will take ownership of the
2485 pointer.
23324ae1
FM
2486 See wxGridCellRenderer and
2487 the @ref overview_gridoverview "wxGrid overview" for more information about
2488 cell editors and renderers.
2489 */
2490 void SetDefaultRenderer(wxGridCellRenderer* renderer);
2491
2492 /**
2493 Sets the default height for rows in the grid. This will only affect rows
2494 subsequently added
2495 to the grid unless resizeExistingRows is @true.
2496 */
2497 void SetDefaultRowSize(int height,
4cc4bfaf 2498 bool resizeExistingRows = false);
23324ae1
FM
2499
2500 /**
2501 Set the grid cursor to the specified cell.
2502 This function calls MakeCellVisible().
2503 */
2504 void SetGridCursor(int row, int col);
2505
2506 /**
2507 Sets the colour used to draw grid lines.
2508 */
2509 void SetGridLineColour(const wxColour& colour);
2510
2511 /**
2512 Sets the background colour for row and column labels.
2513 */
2514 void SetLabelBackgroundColour(const wxColour& colour);
2515
2516 /**
2517 Sets the font for row and column labels.
2518 */
2519 void SetLabelFont(const wxFont& font);
2520
2521 /**
2522 Sets the colour for row and column label text.
2523 */
2524 void SetLabelTextColour(const wxColour& colour);
2525
2526 /**
2527 A grid may occupy more space than needed for its rows/columns. This
2528 function allows to set how big this extra space is
2529 */
2530 void SetMargins(int extraWidth, int extraHeight);
2531
2532 /**
2533 Common part of AutoSizeColumn/Row() and GetBestSize()
2534 */
4cc4bfaf 2535 int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true);
23324ae1
FM
2536
2537 /**
3c4f71cc 2538
23324ae1 2539 */
4cc4bfaf 2540 int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true);
23324ae1
FM
2541
2542 /**
2543 Makes the cell at the specified location read-only or editable.
2544 See also IsReadOnly().
2545 */
4cc4bfaf 2546 void SetReadOnly(int row, int col, bool isReadOnly = true);
23324ae1
FM
2547
2548 /**
2549 Sets the cell attributes for all cells in the specified row.
2550 See the wxGridCellAttr class for more information
2551 about controlling cell attributes.
2552 */
2553 void SetRowAttr(int row, wxGridCellAttr* attr);
2554
2555 /**
2556 Sets the horizontal and vertical alignment of row label text.
23324ae1
FM
2557 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
2558 wxALIGN_RIGHT.
23324ae1
FM
2559 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2560 wxALIGN_BOTTOM.
2561 */
2562 void SetRowLabelAlignment(int horiz, int vert);
2563
2564 /**
2565 Sets the width of the row labels.
4cc4bfaf 2566 If @a width equals @c wxGRID_AUTOSIZE then width is calculated automatically
23324ae1
FM
2567 so that no label is truncated. Note that this could be slow for a large table.
2568 */
2569 void SetRowLabelSize(int width);
2570
2571 /**
2572 Set the value for the given row label. If you are using a derived grid table
2573 you must
2574 override wxGridTableBase::SetRowLabelValue
2575 for this to have any effect.
2576 */
2577 void SetRowLabelValue(int row, const wxString& value);
2578
2579 /**
2580 This modifies the minimum row width that can be handled correctly. Specifying a
2581 low value here
2582 allows smaller grid cells to be dealt with correctly. Specifying a value here
2583 which is much smaller
2584 than the actual minimum size will incur a performance penalty in the functions
2585 which perform
2586 grid cell index lookup on the basis of screen coordinates.
2587 This should normally be called when creating the grid because it will not
2588 resize existing rows
2589 with sizes smaller than the value specified here.
2590 */
2591 void SetRowMinimalAcceptableHeight(int height);
2592
2593 /**
2594 Sets the minimal height for the specified row. This should normally be called
2595 when creating the grid
2596 because it will not resize a row that is already shorter than the minimal
2597 height.
2598 The height argument must be higher than the minimimal acceptable row height, see
2599 GetRowMinimalAcceptableHeight().
2600 */
2601 void SetRowMinimalHeight(int row, int height);
2602
2603 /**
2604 Sets the height of the specified row.
23324ae1
FM
2605 This function does not refresh the grid. If you are calling it outside of a
2606 BeginBatch / EndBatch
2607 block you can use ForceRefresh() to see the changes.
23324ae1
FM
2608 Automatically sizes the column to fit its contents. If setAsMin is @true the
2609 calculated width will
2610 also be set as the minimal width for the column.
2611 */
2612 void SetRowSize(int row, int height);
2613
2614 /**
2615 Sets the number of pixels per horizontal scroll increment. The default is 15.
2616 Sometimes wxGrid has trouble setting the scrollbars correctly due to rounding
2617 errors: setting this to 1 can help.
3c4f71cc 2618
4cc4bfaf 2619 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
23324ae1
FM
2620 */
2621 void SetScrollLineX(int x);
2622
2623 /**
2624 Sets the number of pixels per vertical scroll increment. The default is 15.
2625 Sometimes wxGrid has trouble setting the scrollbars correctly due to rounding
2626 errors: setting this to 1 can help.
3c4f71cc 2627
4cc4bfaf 2628 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
23324ae1
FM
2629 */
2630 void SetScrollLineY(int y);
2631
2632 /**
3c4f71cc 2633
23324ae1
FM
2634 */
2635 void SetSelectionBackground(const wxColour& c);
2636
2637 /**
3c4f71cc 2638
23324ae1
FM
2639 */
2640 void SetSelectionForeground(const wxColour& c);
2641
2642 /**
2643 Set the selection behaviour of the grid.
3c4f71cc 2644
7c913512 2645 @param wxGridSelectCells()
4cc4bfaf 2646 The default mode where individual cells are selected.
7c913512 2647 @param wxGridSelectRows()
4cc4bfaf 2648 Selections will consist of whole rows.
7c913512 2649 @param wxGridSelectColumns()
4cc4bfaf 2650 Selections will consist of whole columns.
23324ae1
FM
2651 */
2652 void SetSelectionMode(wxGrid::wxGridSelectionModes selmode);
2653
2654 /**
2655 Passes a pointer to a custom grid table to be used by the grid. This should be
2656 called
2657 after the grid constructor and before using the grid object. If takeOwnership
2658 is set to
2659 @true then the table will be deleted by the wxGrid destructor.
23324ae1
FM
2660 Use this function instead of CreateGrid() when your
2661 application involves complex or non-string data or data sets that are too large
2662 to fit
2663 wholly in memory.
2664 */
4cc4bfaf 2665 bool SetTable(wxGridTableBase* table, bool takeOwnership = false,
23324ae1
FM
2666 wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);
2667
2668 /**
2669 Call this in order to make the column labels use a native look by using
2670 wxRenderer::DrawHeaderButton
2671 internally. There is no equivalent method for drawing row columns as
2672 there is not native look for that. This option is useful when using
2673 wxGrid for displaying tables and not as a spread-sheet.
2674 */
4cc4bfaf 2675 void SetUseNativeColLabels(bool native = true);
23324ae1
FM
2676
2677 /**
2678 Displays the in-place cell edit control for the current cell.
2679 */
2680 void ShowCellEditControl();
2681
2682 /**
7c913512 2683 @param x
4cc4bfaf 2684 The x position to evaluate.
7c913512 2685 @param clipToMinMax
4cc4bfaf
FM
2686 If @true, rather than returning wxNOT_FOUND, it returns either the first or
2687 last column depending on whether x is too far to the left or right respectively.
23324ae1 2688 */
328f5751 2689 int XToCol(int x, bool clipToMinMax = false) const;
23324ae1
FM
2690
2691 /**
2692 Returns the column whose right hand edge is close to the given logical x
2693 position.
2694 If no column edge is near to this position @c wxNOT_FOUND is returned.
2695 */
328f5751 2696 int XToEdgeOfCol(int x) const;
23324ae1
FM
2697
2698 /**
2699 Returns the row whose bottom edge is close to the given logical y position.
2700 If no row edge is near to this position @c wxNOT_FOUND is returned.
2701 */
328f5751 2702 int YToEdgeOfRow(int y) const;
23324ae1
FM
2703
2704 /**
2705 Returns the grid row that corresponds to the logical y coordinate. Returns
2706 @c wxNOT_FOUND if there is no row at the y position.
2707 */
328f5751 2708 int YToRow(int y) const;
23324ae1
FM
2709};
2710
2711
e54c96f1 2712
23324ae1
FM
2713/**
2714 @class wxGridCellBoolEditor
7c913512 2715
23324ae1 2716 The editor for boolean data.
7c913512 2717
23324ae1
FM
2718 @library{wxadv}
2719 @category{FIXME}
7c913512 2720
e54c96f1 2721 @see wxGridCellEditor, wxGridCellFloatEditor, wxGridCellNumberEditor,
23324ae1
FM
2722 wxGridCellTextEditor, wxGridCellChoiceEditor
2723*/
2724class wxGridCellBoolEditor : public wxGridCellEditor
2725{
2726public:
2727 /**
2728 Default constructor.
2729 */
2730 wxGridCellBoolEditor();
2731
2732 /**
4cc4bfaf 2733 Returns @true if the given @a value is equal to the string representation of
7c913512 2734 the truth value we currently use (see
23324ae1
FM
2735 wxGridCellBoolEditor::UseStringValues).
2736 */
2737 static bool IsTrueValue(const wxString& value);
2738
2739 /**
328f5751 2740 , wxString&@e valueFalse = _T(""))
23324ae1
FM
2741 This method allows to customize the values returned by GetValue() method for
2742 the cell using this editor. By default, the default values of the arguments are
2743 used, i.e. @c "1" is returned if the cell is checked and an empty string
2744 otherwise, using this method allows to change this.
2745 */
328f5751 2746 static void UseStringValues() const;
23324ae1
FM
2747};
2748
2749
e54c96f1 2750
23324ae1
FM
2751/**
2752 @class wxGridUpdateLocker
7c913512 2753
23324ae1
FM
2754 This small class can be used to prevent wxGrid from redrawing
2755 during its lifetime by calling wxGrid::BeginBatch
2756 in its constructor and wxGrid::EndBatch in its
2757 destructor. It is typically used in a function performing several operations
2758 with a grid which would otherwise result in flicker. For example:
7c913512 2759
23324ae1
FM
2760 @code
2761 void MyFrame::Foo()
2762 {
2763 m_grid = new wxGrid(this, ...);
7c913512 2764
23324ae1
FM
2765 wxGridUpdateLocker noUpdates(m_grid);
2766 m_grid-AppendColumn();
2767 ... many other operations with m_grid...
2768 m_grid-AppendRow();
7c913512 2769
23324ae1
FM
2770 // destructor called, grid refreshed
2771 }
2772 @endcode
7c913512
FM
2773
2774 Using this class is easier and safer than calling
23324ae1
FM
2775 wxGrid::BeginBatch and wxGrid::EndBatch
2776 because you don't risk not to call the latter (due to an exception for example).
7c913512 2777
23324ae1
FM
2778 @library{wxadv}
2779 @category{FIXME}
2780*/
7c913512 2781class wxGridUpdateLocker
23324ae1
FM
2782{
2783public:
2784 /**
2785 Creates an object preventing the updates of the specified @e grid. The
4cc4bfaf 2786 parameter could be @NULL in which case nothing is done. If @a grid is
23324ae1
FM
2787 non-@NULL then the grid must exist for longer than wxGridUpdateLocker object
2788 itself.
7c913512 2789 The default constructor could be followed by a call to
23324ae1
FM
2790 Create() to set the
2791 grid object later.
2792 */
4cc4bfaf 2793 wxGridUpdateLocker(wxGrid* grid = NULL);
23324ae1
FM
2794
2795 /**
2796 Destructor reenables updates for the grid this object is associated with.
2797 */
2798 ~wxGridUpdateLocker();
2799
2800 /**
2801 This method can be called if the object had been constructed using the default
2802 constructor. It must not be called more than once.
2803 */
2804 void Create(wxGrid* grid);
2805};
e54c96f1 2806