]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/grid.h
define {first,second}_type in the struct declared by _WX_DECLARE_PAIR too for compati...
[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.
1854 */
328f5751 1855 wxArrayInt GetSelectedCols() const;
23324ae1
FM
1856
1857 /**
1858 Returns an array of selected rows.
1859 */
328f5751 1860 wxArrayInt GetSelectedRows() const;
23324ae1
FM
1861
1862 /**
1863 Access or update the selection fore/back colours
1864 */
328f5751 1865 wxColour GetSelectionBackground() const;
23324ae1
FM
1866
1867 /**
1868 Returns an array of the bottom right corners of blocks of selected cells,
1869 see GetSelectionBlockTopLeft().
1870 */
328f5751 1871 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
23324ae1
FM
1872
1873 /**
1874 Returns an array of the top left corners of blocks of selected cells,
1875 see GetSelectionBlockBottomRight().
1876 */
328f5751 1877 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
23324ae1
FM
1878
1879 /**
3c4f71cc 1880
23324ae1 1881 */
328f5751 1882 wxColour GetSelectionForeground() const;
23324ae1
FM
1883
1884 /**
1885 Returns the current selection mode, see SetSelectionMode().
1886 */
328f5751 1887 wxGrid::wxGridSelectionModes GetSelectionMode() const;
23324ae1
FM
1888
1889 /**
1890 Returns a base pointer to the current table object.
1891 */
328f5751 1892 wxGridTableBase* GetTable() const;
23324ae1
FM
1893
1894 /**
1895 Returned number of whole cols visible.
1896 */
328f5751 1897 int GetViewWidth() const;
23324ae1
FM
1898
1899 /**
1900 EnableGridLines()
3c4f71cc 1901
23324ae1 1902 GridLinesEnabled()
3c4f71cc 1903
23324ae1 1904 SetGridLineColour()
3c4f71cc 1905
23324ae1 1906 GetGridLineColour()
3c4f71cc 1907
23324ae1 1908 GetDefaultGridLinePen()
3c4f71cc 1909
23324ae1 1910 GetRowGridLinePen()
3c4f71cc 1911
23324ae1
FM
1912 GetColGridLinePen()
1913 */
1914
1915
1916 /**
1917 Returns @true if drawing of grid lines is turned on, @false otherwise.
1918 */
328f5751 1919 bool GridLinesEnabled() const;
23324ae1
FM
1920
1921 /**
1922 Hides the in-place cell edit control.
1923 */
1924 void HideCellEditControl();
1925
1926 /**
1927 Hides the column labels by calling SetColLabelSize()
1928 with a size of 0. Show labels again by calling that method with
1929 a width greater than 0.
1930 */
1931 void HideColLabels();
1932
1933 /**
1934 Hides the row labels by calling SetRowLabelSize()
1935 with a size of 0. Show labels again by calling that method with
1936 a width greater than 0.
1937 */
1938 void HideRowLabels();
1939
1940 /**
1941 Init the m_colWidths/Rights arrays
1942 */
1943 void InitColWidths();
1944
1945 /**
1add55ae 1946 @note @e never access m_row/col arrays directly because they are created
23324ae1 1947 on demand, @e always use accessor functions instead!
23324ae1
FM
1948 Init the m_rowHeights/Bottoms arrays with default values.
1949 */
1950 void InitRowHeights();
1951
1952 /**
1953 Inserts one or more new columns into a grid with the first new column at the
1954 specified position and returns @true if successful. The updateLabels argument is
1955 not
1956 used at present.
23324ae1
FM
1957 The sequence of actions begins with the grid object requesting the underlying
1958 grid
1959 table to insert new columns. If this is successful the table notifies the grid
1960 and the
1961 grid updates the display. For a default grid (one where you have called
1962 wxGrid::CreateGrid) this process is automatic. If you are
1963 using a custom grid table (specified with wxGrid::SetTable)
1964 then you must override
1965 wxGridTableBase::InsertCols in your derived
1966 table class.
1967 */
1968 bool InsertCols(int pos = 0, int numCols = 1,
4cc4bfaf 1969 bool updateLabels = true);
23324ae1
FM
1970
1971 /**
1972 Inserts one or more new rows into a grid with the first new row at the specified
1973 position and returns @true if successful. The updateLabels argument is not used
1974 at
1975 present.
23324ae1
FM
1976 The sequence of actions begins with the grid object requesting the underlying
1977 grid
1978 table to insert new rows. If this is successful the table notifies the grid and
1979 the
1980 grid updates the display. For a default grid (one where you have called
1981 wxGrid::CreateGrid) this process is automatic. If you are
1982 using a custom grid table (specified with wxGrid::SetTable)
1983 then you must override
1984 wxGridTableBase::InsertRows in your derived
1985 table class.
1986 */
1987 bool InsertRows(int pos = 0, int numRows = 1,
4cc4bfaf 1988 bool updateLabels = true);
23324ae1
FM
1989
1990 /**
1991 Returns @true if the in-place edit control is currently enabled.
1992 */
328f5751 1993 bool IsCellEditControlEnabled() const;
23324ae1
FM
1994
1995 /**
1996 Returns @true if the current cell has been set to read-only
1997 (see wxGrid::SetReadOnly).
1998 */
328f5751 1999 bool IsCurrentCellReadOnly() const;
23324ae1
FM
2000
2001 /**
2002 Returns @false if the whole grid has been set as read-only or @true otherwise.
2003 See EnableEditing() for more information about
2004 controlling the editing status of grid cells.
2005 */
328f5751 2006 bool IsEditable() const;
23324ae1
FM
2007
2008 //@{
2009 /**
2010 Is this cell currently selected.
2011 */
328f5751
FM
2012 bool IsInSelection(int row, int col) const;
2013 const bool IsInSelection(const wxGridCellCoords& coords) const;
23324ae1
FM
2014 //@}
2015
2016 /**
2017 Returns @true if the cell at the specified location can't be edited.
2018 See also IsReadOnly().
2019 */
328f5751 2020 bool IsReadOnly(int row, int col) const;
23324ae1
FM
2021
2022 /**
2023 Returns @true if there are currently rows, columns or blocks of cells selected.
2024 */
328f5751 2025 bool IsSelection() const;
23324ae1
FM
2026
2027 //@{
2028 /**
2029 Returns @true if a cell is either wholly visible (the default) or at least
2030 partially
2031 visible in the grid window.
2032 */
328f5751
FM
2033 bool IsVisible(int row, int col, bool wholeCellVisible = true) const;
2034 const bool IsVisible(const wxGridCellCoords& coords,
2035 bool wholeCellVisible = true) const;
23324ae1
FM
2036 //@}
2037
2038 //@{
2039 /**
2040 Brings the specified cell into the visible grid cell area with minimal
2041 scrolling. Does
2042 nothing if the cell is already visible.
2043 */
2044 void MakeCellVisible(int row, int col);
7c913512 2045 void MakeCellVisible(const wxGridCellCoords& coords);
23324ae1
FM
2046 //@}
2047
2048 /**
2049 Moves the grid cursor down by one row. If a block of cells was previously
2050 selected it
2051 will expand if the argument is @true or be cleared if the argument is @false.
2052 */
2053 bool MoveCursorDown(bool expandSelection);
2054
2055 /**
2056 Moves the grid cursor down in the current column such that it skips to the
2057 beginning or
2058 end of a block of non-empty cells. If a block of cells was previously selected
2059 it
2060 will expand if the argument is @true or be cleared if the argument is @false.
2061 */
2062 bool MoveCursorDownBlock(bool expandSelection);
2063
2064 /**
2065 Moves the grid cursor left by one column. If a block of cells was previously
2066 selected it
2067 will expand if the argument is @true or be cleared if the argument is @false.
2068 */
2069 bool MoveCursorLeft(bool expandSelection);
2070
2071 /**
2072 Moves the grid cursor left in the current row such that it skips to the
2073 beginning or
2074 end of a block of non-empty cells. If a block of cells was previously selected
2075 it
2076 will expand if the argument is @true or be cleared if the argument is @false.
2077 */
2078 bool MoveCursorLeftBlock(bool expandSelection);
2079
2080 /**
2081 Moves the grid cursor right by one column. If a block of cells was previously
2082 selected it
2083 will expand if the argument is @true or be cleared if the argument is @false.
2084 */
2085 bool MoveCursorRight(bool expandSelection);
2086
2087 /**
2088 Moves the grid cursor right in the current row such that it skips to the
2089 beginning or
2090 end of a block of non-empty cells. If a block of cells was previously selected
2091 it
2092 will expand if the argument is @true or be cleared if the argument is @false.
2093 */
2094 bool MoveCursorRightBlock(bool expandSelection);
2095
2096 /**
2097 Moves the grid cursor up by one row. If a block of cells was previously
2098 selected it
2099 will expand if the argument is @true or be cleared if the argument is @false.
2100 */
2101 bool MoveCursorUp(bool expandSelection);
2102
2103 /**
2104 Moves the grid cursor up in the current column such that it skips to the
2105 beginning or
2106 end of a block of non-empty cells. If a block of cells was previously selected
2107 it
2108 will expand if the argument is @true or be cleared if the argument is @false.
2109 */
2110 bool MoveCursorUpBlock(bool expandSelection);
2111
2112 /**
2113 Moves the grid cursor down by some number of rows so that the previous bottom
2114 visible row
2115 becomes the top visible row.
2116 */
2117 bool MovePageDown();
2118
2119 /**
2120 Moves the grid cursor up by some number of rows so that the previous top
2121 visible row
2122 becomes the bottom visible row.
2123 */
2124 bool MovePageUp();
2125
2126 /**
2127 Methods for a registry for mapping data types to Renderers/Editors
2128 */
2129 void RegisterDataType(const wxString& typeName,
2130 wxGridCellRenderer* renderer,
2131 wxGridCellEditor* editor);
2132
2133 /**
2134 SetRowLabelValue()
3c4f71cc 2135
23324ae1 2136 SetColLabelValue()
3c4f71cc 2137
23324ae1 2138 GetRowLabelValue()
3c4f71cc 2139
23324ae1 2140 GetColLabelValue()
3c4f71cc 2141
23324ae1 2142 SetUseNativeColLabels()
3c4f71cc 2143
23324ae1 2144 HideColLabels()
3c4f71cc 2145
23324ae1 2146 HideRowLabels()
3c4f71cc 2147
23324ae1 2148 SetRowLabelSize()
3c4f71cc 2149
23324ae1 2150 SetColLabelSize()
3c4f71cc 2151
23324ae1 2152 GetRowLabelSize()
3c4f71cc 2153
23324ae1 2154 GetColLabelSize()
3c4f71cc 2155
23324ae1 2156 AutoSizeRowLabelSize()
3c4f71cc 2157
23324ae1 2158 AutoSizeColLabelSize()
3c4f71cc 2159
23324ae1 2160 GetDefaultRowLabelSize()
3c4f71cc 2161
23324ae1 2162 GetDefaultColLabelSize()
3c4f71cc 2163
23324ae1 2164 SetRowLabelAlignment()
3c4f71cc 2165
23324ae1 2166 SetColLabelAlignment()
3c4f71cc 2167
23324ae1 2168 GetRowLabelAlignment()
3c4f71cc 2169
23324ae1 2170 GetColLabelAlignment()
3c4f71cc 2171
23324ae1 2172 SetLabelFont()
3c4f71cc 2173
23324ae1 2174 SetLabelTextColour()
3c4f71cc 2175
23324ae1 2176 SetLabelBackgroundColour()
3c4f71cc 2177
23324ae1 2178 GetLabelFont()
3c4f71cc 2179
23324ae1 2180 GetLabelBackgroundColour()
3c4f71cc 2181
23324ae1 2182 GetLabelTextColour()
3c4f71cc 2183
23324ae1 2184 SetColLabelTextOrientation()
3c4f71cc 2185
23324ae1
FM
2186 GetColLabelTextOrientation()
2187 */
2188
2189
2190 /**
2191 Sets the value of the current grid cell to the current in-place edit control
2192 value.
2193 This is called automatically when the grid cursor moves from the current cell
2194 to a
2195 new cell. It is also a good idea to call this function when closing a grid since
2196 any edits to the final cell location will not be saved otherwise.
2197 */
2198 void SaveEditControlValue();
2199
2200 /**
2201 Selects all cells in the grid.
2202 */
2203 void SelectAll();
2204
2205 //@{
2206 /**
2207 Selects a rectangular block of cells. If addToSelected is @false then any
2208 existing selection will be
2209 deselected; if @true the column will be added to the existing selection.
2210 */
2211 void SelectBlock(int topRow, int leftCol, int bottomRow,
2212 int rightCol,
4cc4bfaf 2213 bool addToSelected = false);
7c913512
FM
2214 void SelectBlock(const wxGridCellCoords& topLeft,
2215 const wxGridCellCoords& bottomRight,
4cc4bfaf 2216 bool addToSelected = false);
23324ae1
FM
2217 //@}
2218
2219 /**
2220 Selects the specified column. If addToSelected is @false then any existing
2221 selection will be
2222 deselected; if @true the column will be added to the existing selection.
2223 */
4cc4bfaf 2224 void SelectCol(int col, bool addToSelected = false);
23324ae1
FM
2225
2226 /**
2227 Selects the specified row. If addToSelected is @false then any existing
2228 selection will be
2229 deselected; if @true the row will be added to the existing selection.
2230 */
4cc4bfaf 2231 void SelectRow(int row, bool addToSelected = false);
23324ae1
FM
2232
2233 /**
2234 ClearSelection()
3c4f71cc 2235
23324ae1 2236 IsSelection()
3c4f71cc 2237
23324ae1 2238 SelectAll()
3c4f71cc 2239
23324ae1 2240 SelectBlock()
3c4f71cc 2241
23324ae1 2242 SelectCol()
3c4f71cc 2243
23324ae1
FM
2244 SelectRow()
2245 */
2246
2247
2248 /**
2249 This function returns the rectangle that encloses the selected cells
2250 in device coords and clipped to the client size of the grid window.
2251 */
328f5751 2252 wxRect SelectionToDeviceRect() const;
23324ae1
FM
2253
2254 //@{
2255 /**
2256 Sets the horizontal and vertical alignment for grid cell text at the specified
2257 location.
23324ae1 2258 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
7c913512 2259 wxALIGN_RIGHT.
3c4f71cc 2260
23324ae1
FM
2261 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2262 wxALIGN_BOTTOM.
2263 */
2264 void SetCellAlignment(int row, int col, int horiz, int vert);
7c913512 2265 void SetCellAlignment(int align, int row, int col);
23324ae1
FM
2266 //@}
2267
2268 /**
3c4f71cc 2269
23324ae1
FM
2270 */
2271 void SetCellBackgroundColour(int row, int col,
2272 const wxColour& colour);
2273
2274 /**
2275 Sets the editor for the grid cell at the specified location.
2276 The grid will take ownership of the pointer.
23324ae1
FM
2277 See wxGridCellEditor and
2278 the @ref overview_gridoverview "wxGrid overview" for more information about
2279 cell editors and renderers.
2280 */
2281 void SetCellEditor(int row, int col, wxGridCellEditor* editor);
2282
2283 /**
2284 Sets the font for text in the grid cell at the specified location.
2285 */
2286 void SetCellFont(int row, int col, const wxFont& font);
2287
2288 /**
2289 Sets the renderer for the grid cell at the specified location.
2290 The grid will take ownership of the pointer.
23324ae1
FM
2291 See wxGridCellRenderer and
2292 the @ref overview_gridoverview "wxGrid overview" for more information about
2293 cell editors and renderers.
2294 */
2295 void SetCellRenderer(int row, int col,
2296 wxGridCellRenderer* renderer);
2297
2298 //@{
2299 /**
2300 Sets the text colour for the grid cell at the specified location.
2301 */
2302 void SetCellTextColour(int row, int col, const wxColour& colour);
7c913512
FM
2303 void SetCellTextColour(const wxColour& val, int row, int col);
2304 void SetCellTextColour(const wxColour& colour);
23324ae1
FM
2305 //@}
2306
2307 //@{
2308 /**
2309 Sets the string value for the cell at the specified location. For simple
2310 applications where a
2311 grid object automatically uses a default grid table of string values you use
2312 this function together
2313 with GetCellValue() to access cell values.
23324ae1
FM
2314 For more complex applications where you have derived your own grid table class
2315 that contains
2316 various data types (e.g. numeric, boolean or user-defined custom types) then
2317 you only use this
2318 function for those cells that contain string values.
23324ae1 2319 The last form is for backward compatibility only.
23324ae1
FM
2320 See wxGridTableBase::CanSetValueAs
2321 and the @ref overview_gridoverview "wxGrid overview" for more information.
2322 */
2323 void SetCellValue(int row, int col, const wxString& s);
7c913512
FM
2324 void SetCellValue(const wxGridCellCoords& coords,
2325 const wxString& s);
2326 void SetCellValue(const wxString& val, int row, int col);
23324ae1
FM
2327 //@}
2328
2329 /**
2330 Sets the cell attributes for all cells in the specified column.
23324ae1
FM
2331 For more information about controlling grid cell attributes see the
2332 wxGridCellAttr cell attribute class and the
4cc4bfaf 2333 @ref overview_gridoverview.
23324ae1
FM
2334 */
2335 void SetColAttr(int col, wxGridCellAttr* attr);
2336
2337 /**
2338 Sets the specified column to display boolean values. wxGrid displays boolean
2339 values with a checkbox.
2340 */
2341 void SetColFormatBool(int col);
2342
2343 /**
2344 Sets the specified column to display data in a custom format.
2345 See the @ref overview_gridoverview "wxGrid overview" for more information on
2346 working
2347 with custom data types.
2348 */
2349 void SetColFormatCustom(int col, const wxString& typeName);
2350
2351 /**
2352 Sets the specified column to display floating point values with the given width
2353 and precision.
2354 */
2355 void SetColFormatFloat(int col, int width = -1,
2356 int precision = -1);
2357
2358 /**
2359 Sets the specified column to display integer values.
2360 */
2361 void SetColFormatNumber(int col);
2362
2363 /**
2364 Sets the horizontal and vertical alignment of column label text.
23324ae1
FM
2365 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
2366 wxALIGN_RIGHT.
23324ae1
FM
2367 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2368 wxALIGN_BOTTOM.
2369 */
2370 void SetColLabelAlignment(int horiz, int vert);
2371
2372 /**
2373 Sets the height of the column labels.
4cc4bfaf 2374 If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
23324ae1
FM
2375 automatically
2376 so that no label is truncated. Note that this could be slow for a large table.
2377 */
2378 void SetColLabelSize(int height);
2379
2380 /**
2381 Set the value for the given column label. If you are using a derived grid table
2382 you must
2383 override wxGridTableBase::SetColLabelValue
2384 for this to have any effect.
2385 */
2386 void SetColLabelValue(int col, const wxString& value);
2387
2388 /**
2389 This modifies the minimum column width that can be handled correctly.
2390 Specifying a low value here
2391 allows smaller grid cells to be dealt with correctly. Specifying a value here
2392 which is much smaller
2393 than the actual minimum size will incur a performance penalty in the functions
2394 which perform
2395 grid cell index lookup on the basis of screen coordinates.
2396 This should normally be called when creating the grid because it will not
2397 resize existing columns
2398 with sizes smaller than the value specified here.
2399 */
2400 void SetColMinimalAcceptableWidth(int width);
2401
2402 /**
2403 Sets the minimal width for the specified column. This should normally be called
2404 when creating the grid
2405 because it will not resize a column that is already narrower than the minimal
2406 width.
2407 The width argument must be higher than the minimimal acceptable column width,
2408 see
2409 GetColMinimalAcceptableWidth().
2410 */
2411 void SetColMinimalWidth(int col, int width);
2412
2413 /**
2414 Sets the position of the specified column.
2415 */
2416 void SetColPos(int colID, int newPos);
2417
2418 /**
2419 Sets the width of the specified column.
23324ae1
FM
2420 This function does not refresh the grid. If you are calling it outside of a
2421 BeginBatch / EndBatch
2422 block you can use ForceRefresh() to see the changes.
23324ae1
FM
2423 Automatically sizes the column to fit its contents. If setAsMin is @true the
2424 calculated width will
2425 also be set as the minimal width for the column.
2426 */
2427 void SetColSize(int col, int width);
2428
2429 /**
2430 Sets the default horizontal and vertical alignment for grid cell text.
23324ae1
FM
2431 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
2432 wxALIGN_RIGHT.
23324ae1
FM
2433 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2434 wxALIGN_BOTTOM.
2435 */
2436 void SetDefaultCellAlignment(int horiz, int vert);
2437
2438 /**
2439 Sets the default background colour for grid cells.
2440 */
2441 void SetDefaultCellBackgroundColour(const wxColour& colour);
2442
2443 /**
2444 Sets the default font to be used for grid cell text.
2445 */
2446 void SetDefaultCellFont(const wxFont& font);
2447
2448 /**
2449 Sets the current default colour for grid cell text.
2450 */
2451 void SetDefaultCellTextColour(const wxColour& colour);
2452
2453 /**
2454 Sets the default width for columns in the grid. This will only affect columns
2455 subsequently added to
2456 the grid unless resizeExistingCols is @true.
2457 */
2458 void SetDefaultColSize(int width,
4cc4bfaf 2459 bool resizeExistingCols = false);
23324ae1
FM
2460
2461 /**
2462 Sets the default editor for grid cells. The grid will take ownership of the
2463 pointer.
23324ae1
FM
2464 See wxGridCellEditor and
2465 the @ref overview_gridoverview "wxGrid overview" for more information about
2466 cell editors and renderers.
2467 */
2468 void SetDefaultEditor(wxGridCellEditor* editor);
2469
2470 /**
2471 Sets the default renderer for grid cells. The grid will take ownership of the
2472 pointer.
23324ae1
FM
2473 See wxGridCellRenderer and
2474 the @ref overview_gridoverview "wxGrid overview" for more information about
2475 cell editors and renderers.
2476 */
2477 void SetDefaultRenderer(wxGridCellRenderer* renderer);
2478
2479 /**
2480 Sets the default height for rows in the grid. This will only affect rows
2481 subsequently added
2482 to the grid unless resizeExistingRows is @true.
2483 */
2484 void SetDefaultRowSize(int height,
4cc4bfaf 2485 bool resizeExistingRows = false);
23324ae1
FM
2486
2487 /**
2488 Set the grid cursor to the specified cell.
2489 This function calls MakeCellVisible().
2490 */
2491 void SetGridCursor(int row, int col);
2492
2493 /**
2494 Sets the colour used to draw grid lines.
2495 */
2496 void SetGridLineColour(const wxColour& colour);
2497
2498 /**
2499 Sets the background colour for row and column labels.
2500 */
2501 void SetLabelBackgroundColour(const wxColour& colour);
2502
2503 /**
2504 Sets the font for row and column labels.
2505 */
2506 void SetLabelFont(const wxFont& font);
2507
2508 /**
2509 Sets the colour for row and column label text.
2510 */
2511 void SetLabelTextColour(const wxColour& colour);
2512
2513 /**
2514 A grid may occupy more space than needed for its rows/columns. This
2515 function allows to set how big this extra space is
2516 */
2517 void SetMargins(int extraWidth, int extraHeight);
2518
2519 /**
2520 Common part of AutoSizeColumn/Row() and GetBestSize()
2521 */
4cc4bfaf 2522 int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true);
23324ae1
FM
2523
2524 /**
3c4f71cc 2525
23324ae1 2526 */
4cc4bfaf 2527 int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true);
23324ae1
FM
2528
2529 /**
2530 Makes the cell at the specified location read-only or editable.
2531 See also IsReadOnly().
2532 */
4cc4bfaf 2533 void SetReadOnly(int row, int col, bool isReadOnly = true);
23324ae1
FM
2534
2535 /**
2536 Sets the cell attributes for all cells in the specified row.
2537 See the wxGridCellAttr class for more information
2538 about controlling cell attributes.
2539 */
2540 void SetRowAttr(int row, wxGridCellAttr* attr);
2541
2542 /**
2543 Sets the horizontal and vertical alignment of row label text.
23324ae1
FM
2544 Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or
2545 wxALIGN_RIGHT.
23324ae1
FM
2546 Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or
2547 wxALIGN_BOTTOM.
2548 */
2549 void SetRowLabelAlignment(int horiz, int vert);
2550
2551 /**
2552 Sets the width of the row labels.
4cc4bfaf 2553 If @a width equals @c wxGRID_AUTOSIZE then width is calculated automatically
23324ae1
FM
2554 so that no label is truncated. Note that this could be slow for a large table.
2555 */
2556 void SetRowLabelSize(int width);
2557
2558 /**
2559 Set the value for the given row label. If you are using a derived grid table
2560 you must
2561 override wxGridTableBase::SetRowLabelValue
2562 for this to have any effect.
2563 */
2564 void SetRowLabelValue(int row, const wxString& value);
2565
2566 /**
2567 This modifies the minimum row width that can be handled correctly. Specifying a
2568 low value here
2569 allows smaller grid cells to be dealt with correctly. Specifying a value here
2570 which is much smaller
2571 than the actual minimum size will incur a performance penalty in the functions
2572 which perform
2573 grid cell index lookup on the basis of screen coordinates.
2574 This should normally be called when creating the grid because it will not
2575 resize existing rows
2576 with sizes smaller than the value specified here.
2577 */
2578 void SetRowMinimalAcceptableHeight(int height);
2579
2580 /**
2581 Sets the minimal height for the specified row. This should normally be called
2582 when creating the grid
2583 because it will not resize a row that is already shorter than the minimal
2584 height.
2585 The height argument must be higher than the minimimal acceptable row height, see
2586 GetRowMinimalAcceptableHeight().
2587 */
2588 void SetRowMinimalHeight(int row, int height);
2589
2590 /**
2591 Sets the height of the specified row.
23324ae1
FM
2592 This function does not refresh the grid. If you are calling it outside of a
2593 BeginBatch / EndBatch
2594 block you can use ForceRefresh() to see the changes.
23324ae1
FM
2595 Automatically sizes the column to fit its contents. If setAsMin is @true the
2596 calculated width will
2597 also be set as the minimal width for the column.
2598 */
2599 void SetRowSize(int row, int height);
2600
2601 /**
2602 Sets the number of pixels per horizontal scroll increment. The default is 15.
2603 Sometimes wxGrid has trouble setting the scrollbars correctly due to rounding
2604 errors: setting this to 1 can help.
3c4f71cc 2605
4cc4bfaf 2606 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
23324ae1
FM
2607 */
2608 void SetScrollLineX(int x);
2609
2610 /**
2611 Sets the number of pixels per vertical scroll increment. The default is 15.
2612 Sometimes wxGrid has trouble setting the scrollbars correctly due to rounding
2613 errors: setting this to 1 can help.
3c4f71cc 2614
4cc4bfaf 2615 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
23324ae1
FM
2616 */
2617 void SetScrollLineY(int y);
2618
2619 /**
3c4f71cc 2620
23324ae1
FM
2621 */
2622 void SetSelectionBackground(const wxColour& c);
2623
2624 /**
3c4f71cc 2625
23324ae1
FM
2626 */
2627 void SetSelectionForeground(const wxColour& c);
2628
2629 /**
2630 Set the selection behaviour of the grid.
3c4f71cc 2631
7c913512 2632 @param wxGridSelectCells()
4cc4bfaf 2633 The default mode where individual cells are selected.
7c913512 2634 @param wxGridSelectRows()
4cc4bfaf 2635 Selections will consist of whole rows.
7c913512 2636 @param wxGridSelectColumns()
4cc4bfaf 2637 Selections will consist of whole columns.
23324ae1
FM
2638 */
2639 void SetSelectionMode(wxGrid::wxGridSelectionModes selmode);
2640
2641 /**
2642 Passes a pointer to a custom grid table to be used by the grid. This should be
2643 called
2644 after the grid constructor and before using the grid object. If takeOwnership
2645 is set to
2646 @true then the table will be deleted by the wxGrid destructor.
23324ae1
FM
2647 Use this function instead of CreateGrid() when your
2648 application involves complex or non-string data or data sets that are too large
2649 to fit
2650 wholly in memory.
2651 */
4cc4bfaf 2652 bool SetTable(wxGridTableBase* table, bool takeOwnership = false,
23324ae1
FM
2653 wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);
2654
2655 /**
2656 Call this in order to make the column labels use a native look by using
2657 wxRenderer::DrawHeaderButton
2658 internally. There is no equivalent method for drawing row columns as
2659 there is not native look for that. This option is useful when using
2660 wxGrid for displaying tables and not as a spread-sheet.
2661 */
4cc4bfaf 2662 void SetUseNativeColLabels(bool native = true);
23324ae1
FM
2663
2664 /**
2665 Displays the in-place cell edit control for the current cell.
2666 */
2667 void ShowCellEditControl();
2668
2669 /**
7c913512 2670 @param x
4cc4bfaf 2671 The x position to evaluate.
7c913512 2672 @param clipToMinMax
4cc4bfaf
FM
2673 If @true, rather than returning wxNOT_FOUND, it returns either the first or
2674 last column depending on whether x is too far to the left or right respectively.
23324ae1 2675 */
328f5751 2676 int XToCol(int x, bool clipToMinMax = false) const;
23324ae1
FM
2677
2678 /**
2679 Returns the column whose right hand edge is close to the given logical x
2680 position.
2681 If no column edge is near to this position @c wxNOT_FOUND is returned.
2682 */
328f5751 2683 int XToEdgeOfCol(int x) const;
23324ae1
FM
2684
2685 /**
2686 Returns the row whose bottom edge is close to the given logical y position.
2687 If no row edge is near to this position @c wxNOT_FOUND is returned.
2688 */
328f5751 2689 int YToEdgeOfRow(int y) const;
23324ae1
FM
2690
2691 /**
2692 Returns the grid row that corresponds to the logical y coordinate. Returns
2693 @c wxNOT_FOUND if there is no row at the y position.
2694 */
328f5751 2695 int YToRow(int y) const;
23324ae1
FM
2696};
2697
2698
e54c96f1 2699
23324ae1
FM
2700/**
2701 @class wxGridCellBoolEditor
7c913512 2702
23324ae1 2703 The editor for boolean data.
7c913512 2704
23324ae1
FM
2705 @library{wxadv}
2706 @category{FIXME}
7c913512 2707
e54c96f1 2708 @see wxGridCellEditor, wxGridCellFloatEditor, wxGridCellNumberEditor,
23324ae1
FM
2709 wxGridCellTextEditor, wxGridCellChoiceEditor
2710*/
2711class wxGridCellBoolEditor : public wxGridCellEditor
2712{
2713public:
2714 /**
2715 Default constructor.
2716 */
2717 wxGridCellBoolEditor();
2718
2719 /**
4cc4bfaf 2720 Returns @true if the given @a value is equal to the string representation of
7c913512 2721 the truth value we currently use (see
23324ae1
FM
2722 wxGridCellBoolEditor::UseStringValues).
2723 */
2724 static bool IsTrueValue(const wxString& value);
2725
2726 /**
328f5751 2727 , wxString&@e valueFalse = _T(""))
23324ae1
FM
2728 This method allows to customize the values returned by GetValue() method for
2729 the cell using this editor. By default, the default values of the arguments are
2730 used, i.e. @c "1" is returned if the cell is checked and an empty string
2731 otherwise, using this method allows to change this.
2732 */
328f5751 2733 static void UseStringValues() const;
23324ae1
FM
2734};
2735
2736
e54c96f1 2737
23324ae1
FM
2738/**
2739 @class wxGridUpdateLocker
7c913512 2740
23324ae1
FM
2741 This small class can be used to prevent wxGrid from redrawing
2742 during its lifetime by calling wxGrid::BeginBatch
2743 in its constructor and wxGrid::EndBatch in its
2744 destructor. It is typically used in a function performing several operations
2745 with a grid which would otherwise result in flicker. For example:
7c913512 2746
23324ae1
FM
2747 @code
2748 void MyFrame::Foo()
2749 {
2750 m_grid = new wxGrid(this, ...);
7c913512 2751
23324ae1
FM
2752 wxGridUpdateLocker noUpdates(m_grid);
2753 m_grid-AppendColumn();
2754 ... many other operations with m_grid...
2755 m_grid-AppendRow();
7c913512 2756
23324ae1
FM
2757 // destructor called, grid refreshed
2758 }
2759 @endcode
7c913512
FM
2760
2761 Using this class is easier and safer than calling
23324ae1
FM
2762 wxGrid::BeginBatch and wxGrid::EndBatch
2763 because you don't risk not to call the latter (due to an exception for example).
7c913512 2764
23324ae1
FM
2765 @library{wxadv}
2766 @category{FIXME}
2767*/
7c913512 2768class wxGridUpdateLocker
23324ae1
FM
2769{
2770public:
2771 /**
2772 Creates an object preventing the updates of the specified @e grid. The
4cc4bfaf 2773 parameter could be @NULL in which case nothing is done. If @a grid is
23324ae1
FM
2774 non-@NULL then the grid must exist for longer than wxGridUpdateLocker object
2775 itself.
7c913512 2776 The default constructor could be followed by a call to
23324ae1
FM
2777 Create() to set the
2778 grid object later.
2779 */
4cc4bfaf 2780 wxGridUpdateLocker(wxGrid* grid = NULL);
23324ae1
FM
2781
2782 /**
2783 Destructor reenables updates for the grid this object is associated with.
2784 */
2785 ~wxGridUpdateLocker();
2786
2787 /**
2788 This method can be called if the object had been constructed using the default
2789 constructor. It must not be called more than once.
2790 */
2791 void Create(wxGrid* grid);
2792};
e54c96f1 2793