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