Forgot this
[wxWidgets.git] / interface / wx / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dataview.h
3 // Purpose: interface of wxDataView* classes
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9
10 /**
11 @class wxDataViewModel
12
13 wxDataViewModel is the base class for all data model to be displayed by a
14 wxDataViewCtrl.
15
16 All other models derive from it and must implement its pure virtual functions
17 in order to define a complete data model. In detail, you need to override
18 wxDataViewModel::IsContainer, wxDataViewModel::GetParent, wxDataViewModel::GetChildren,
19 wxDataViewModel::GetColumnCount, wxDataViewModel::GetColumnType and
20 wxDataViewModel::GetValue in order to define the data model which acts as an
21 interface between your actual data and the wxDataViewCtrl.
22
23 Since you will usually also allow the wxDataViewCtrl to change your data
24 through its graphical interface, you will also have to override
25 wxDataViewModel::SetValue which the wxDataViewCtrl will call when a change
26 to some data has been commited.
27
28 wxDataViewModel (as indeed the entire wxDataViewCtrl code) is using wxVariant
29 to store data and its type in a generic way. wxVariant can be extended to contain
30 almost any data without changes to the original class.
31
32 The data that is presented through this data model is expected to change at
33 run-time. You need to inform the data model when a change happened.
34 Depending on what happened you need to call one of the following methods:
35 - wxDataViewModel::ValueChanged,
36 - wxDataViewModel::ItemAdded,
37 - wxDataViewModel::ItemDeleted,
38 - wxDataViewModel::ItemChanged,
39 - wxDataViewModel::Cleared.
40
41 There are plural forms for notification of addition, change or removal of
42 several item at once. See:
43 - wxDataViewModel::ItemsAdded,
44 - wxDataViewModel::ItemsDeleted,
45 - wxDataViewModel::ItemsChanged.
46
47 Note that wxDataViewModel does not define the position or index of any item
48 in the control because different controls might display the same data differently.
49 wxDataViewModel does provide a wxDataViewModel::Compare method which the
50 wxDataViewCtrl may use to sort the data either in conjunction with a column
51 header or without (see wxDataViewModel::HasDefaultCompare).
52
53 This class maintains a list of wxDataViewModelNotifier which link this class
54 to the specific implementations on the supported platforms so that e.g. calling
55 wxDataViewModel::ValueChanged on this model will just call
56 wxDataViewModelNotifier::ValueChanged for each notifier that has been added.
57 You can also add your own notifier in order to get informed about any changes
58 to the data in the list model.
59
60 Currently wxWidgets provides the following models apart from the base model:
61 wxDataViewIndexListModel, wxDataViewVirtualListModel, wxDataViewTreeStore,
62 wxDataViewListStore.
63
64 Note that wxDataViewModel is reference counted, derives from wxObjectRefData
65 and cannot be deleted directly as it can be shared by several wxDataViewCtrls.
66 This implies that you need to decrease the reference count after
67 associating the model with a control like this:
68
69 @code
70 wxDataViewCtrl *musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL );
71 wxDataViewModel *musicModel = new MyMusicModel;
72 m_musicCtrl-AssociateModel( musicModel );
73 musicModel-DecRef(); // avoid memory leak !!
74 // add columns now
75 @endcode
76
77
78 @library{wxadv}
79 @category{dvc}
80 */
81 class wxDataViewModel : public wxObjectRefData
82 {
83 public:
84 /**
85 Constructor.
86 */
87 wxDataViewModel();
88
89 /**
90 Adds a wxDataViewModelNotifier to the model.
91 */
92 void AddNotifier(wxDataViewModelNotifier* notifier);
93
94 /**
95 Called to inform the model that all data has been cleared.
96 The control will reread the data from the model again.
97 */
98 virtual bool Cleared();
99
100 /**
101 The compare function to be used by control. The default compare function
102 sorts by container and other items separately and in ascending order.
103 Override this for a different sorting behaviour.
104
105 @see HasDefaultCompare().
106 */
107 virtual int Compare(const wxDataViewItem& item1,
108 const wxDataViewItem& item2,
109 unsigned int column,
110 bool ascending);
111
112 /**
113 Override this to indicate that the item has special font attributes.
114 This only affects the wxDataViewTextRendererText renderer.
115
116 @see wxDataViewItemAttr.
117 */
118 virtual bool GetAttr(const wxDataViewItem& item, unsigned int col,
119 wxDataViewItemAttr& attr);
120
121 /**
122 Override this so the control can query the child items of an item.
123 Returns the number of items.
124 */
125 virtual unsigned int GetChildren(const wxDataViewItem& item,
126 wxDataViewItemArray& children) const = 0;
127
128 /**
129 Override this to indicate the number of columns in the model.
130 */
131 virtual unsigned int GetColumnCount() const = 0;
132
133 /**
134 Override this to indicate what type of data is stored in the
135 column specified by @a col.
136
137 This should return a string indicating the type of data as reported by wxVariant.
138 */
139 virtual wxString GetColumnType(unsigned int col) const = 0;
140
141 /**
142 Override this to indicate which wxDataViewItem representing the parent
143 of @a item or an invalid wxDataViewItem if the the root item is
144 the parent item.
145 */
146 virtual wxDataViewItem GetParent(const wxDataViewItem& item) const = 0;
147
148 /**
149 Override this to indicate the value of @a item.
150 A wxVariant is used to store the data.
151 */
152 virtual void GetValue(wxVariant& variant, const wxDataViewItem& item,
153 unsigned int col) const = 0;
154
155 /**
156 Override this method to indicate if a container item merely acts as a
157 headline (or for categorisation) or if it also acts a normal item with
158 entries for futher columns. By default returns @false.
159 */
160 virtual bool HasContainerColumns(const wxDataViewItem& item) const;
161
162 /**
163 Override this to indicate that the model provides a default compare
164 function that the control should use if no wxDataViewColumn has been
165 chosen for sorting. Usually, the user clicks on a column header for
166 sorting, the data will be sorted alphanumerically.
167
168 If any other order (e.g. by index or order of appearance) is required,
169 then this should be used.
170 See wxDataViewIndexListModel for a model which makes use of this.
171 */
172 virtual bool HasDefaultCompare() const;
173
174 /**
175 Override this to indicate of @a item is a container, i.e. if
176 it can have child items.
177 */
178 virtual bool IsContainer(const wxDataViewItem& item) const = 0;
179
180 /**
181 Call this to inform the model that an item has been added to the data.
182 */
183 virtual bool ItemAdded(const wxDataViewItem& parent,
184 const wxDataViewItem& item);
185
186 /**
187 Call this to inform the model that an item has changed.
188
189 This will eventually emit a wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
190 event (in which the column fields will not be set) to the user.
191 */
192 virtual bool ItemChanged(const wxDataViewItem& item);
193
194 /**
195 Call this to inform the model that an item has been deleted from the data.
196 */
197 virtual bool ItemDeleted(const wxDataViewItem& parent,
198 const wxDataViewItem& item);
199
200 /**
201 Call this to inform the model that several items have been added to the data.
202 */
203 virtual bool ItemsAdded(const wxDataViewItem& parent,
204 const wxDataViewItemArray& items);
205
206 /**
207 Call this to inform the model that several items have changed.
208
209 This will eventually emit wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
210 events (in which the column fields will not be set) to the user.
211 */
212 virtual bool ItemsChanged(const wxDataViewItemArray& items);
213
214 /**
215 Call this to inform the model that several items have been deleted.
216 */
217 virtual bool ItemsDeleted(const wxDataViewItem& parent,
218 const wxDataViewItemArray& items);
219
220 /**
221 Remove the @a notifier from the list of notifiers.
222 */
223 void RemoveNotifier(wxDataViewModelNotifier* notifier);
224
225 /**
226 Call this to initiate a resort after the sort function has been changed.
227 */
228 virtual void Resort();
229
230 /**
231 This gets called in order to set a value in the data model.
232 The most common scenario is that the wxDataViewCtrl calls this method
233 after the user changed some data in the view.
234
235 Afterwards ValueChanged() has to be called!
236 */
237 virtual bool SetValue(const wxVariant& variant, const wxDataViewItem& item,
238 unsigned int col) = 0;
239
240 /**
241 Call this to inform this model that a value in the model has been changed.
242 This is also called from wxDataViewCtrl's internal editing code, e.g. when
243 editing a text field in the control.
244
245 This will eventually emit a wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
246 event to the user.
247 */
248 virtual bool ValueChanged(const wxDataViewItem& item,
249 unsigned int col);
250
251 protected:
252
253 /**
254 Destructor. This should not be called directly. Use DecRef() instead.
255 */
256 virtual ~wxDataViewModel();
257 };
258
259
260
261 /**
262 @class wxDataViewIndexListModel
263
264 wxDataViewIndexListModel is a specialized data model which lets you address
265 an item by its position (row) rather than its wxDataViewItem (which you can
266 obtain from this class).
267 This model also provides its own wxDataViewIndexListModel::Compare
268 method which sorts the model's data by the index.
269
270 This model is not a virtual model since the control stores each wxDataViewItem.
271 Use wxDataViewVirtualListModel if you need to display millions of items or
272 have other reason to use a virtual control.
273
274 @library{wxadv}
275 @category{dvc}
276 */
277 class wxDataViewIndexListModel : public wxDataViewModel
278 {
279 public:
280 /**
281 Constructor.
282 */
283 wxDataViewIndexListModel(unsigned int initial_size = 0);
284
285 /**
286 Destructor.
287 */
288 virtual ~wxDataViewIndexListModel();
289
290 /**
291 Compare method that sorts the items by their index.
292 */
293 int Compare(const wxDataViewItem& item1,
294 const wxDataViewItem& item2,
295 unsigned int column, bool ascending);
296
297 /**
298 Override this to indicate that the row has special font attributes.
299 This only affects the wxDataViewTextRendererText() renderer.
300
301 @see wxDataViewItemAttr.
302 */
303 virtual bool GetAttrByRow(unsigned int row, unsigned int col,
304 wxDataViewItemAttr& attr);
305
306 /**
307 Returns the wxDataViewItem at the given @e row.
308 */
309 wxDataViewItem GetItem(unsigned int row) const;
310
311 /**
312 Returns the position of given @e item.
313 */
314 unsigned int GetRow(const wxDataViewItem& item) const;
315
316 /**
317 Override this to allow getting values from the model.
318 */
319 virtual void GetValueByRow(wxVariant& variant, unsigned int row,
320 unsigned int col) const = 0;
321
322 /**
323 Call this after if the data has to be read again from the model.
324 This is useful after major changes when calling the methods below
325 (possibly thousands of times) doesn't make sense.
326 */
327 void Reset(unsigned int new_size);
328
329 /**
330 Call this after a row has been appended to the model.
331 */
332 void RowAppended();
333
334 /**
335 Call this after a row has been changed.
336 */
337 void RowChanged(unsigned int row);
338
339 /**
340 Call this after a row has been deleted.
341 */
342 void RowDeleted(unsigned int row);
343
344 /**
345 Call this after a row has been inserted at the given position.
346 */
347 void RowInserted(unsigned int before);
348
349 /**
350 Call this after a row has been prepended to the model.
351 */
352 void RowPrepended();
353
354 /**
355 Call this after a value has been changed.
356 */
357 void RowValueChanged(unsigned int row, unsigned int col);
358
359 /**
360 Call this after rows have been deleted.
361 The array will internally get copied and sorted in descending order so
362 that the rows with the highest position will be deleted first.
363 */
364 void RowsDeleted(const wxArrayInt& rows);
365
366 /**
367 Called in order to set a value in the model.
368 */
369 virtual bool SetValueByRow(const wxVariant& variant, unsigned int row,
370 unsigned int col) = 0;
371 };
372
373
374
375 /**
376 @class wxDataViewVirtualListModel
377
378 wxDataViewVirtualListModel is a specialized data model which lets you address
379 an item by its position (row) rather than its wxDataViewItem and as such offers
380 the exact same interface as wxDataViewIndexListModel.
381 The important difference is that under platforms other than OS X, using this
382 model will result in a truly virtual control able to handle millions of items
383 as the control doesn't store any item (a feature not supported by the
384 Carbon API under OS X).
385
386 @see wxDataViewIndexListModel for the API.
387
388 @library{wxadv}
389 @category{dvc}
390 */
391 class wxDataViewVirtualListModel : public wxDataViewModel
392 {
393 public:
394 /**
395 Constructor.
396 */
397 wxDataViewVirtualListModel(unsigned int initial_size = 0);
398 };
399
400
401
402 /**
403 @class wxDataViewItemAttr
404
405 This class is used to indicate to a wxDataViewCtrl that a certain item
406 (see wxDataViewItem) has extra font attributes for its renderer.
407 For this, it is required to override wxDataViewModel::GetAttr.
408
409 Attributes are currently only supported by wxDataViewTextRendererText.
410
411 @library{wxadv}
412 @category{dvc}
413 */
414 class wxDataViewItemAttr
415 {
416 public:
417 /**
418 Constructor.
419 */
420 wxDataViewItemAttr();
421
422 /**
423 Call this to indicate that the item shall be displayed in bold text.
424 */
425 void SetBold(bool set);
426
427 /**
428 Call this to indicate that the item shall be displayed with that colour.
429 */
430 void SetColour(const wxColour& colour);
431
432 /**
433 Call this to indicate that the item shall be displayed in italic text.
434 */
435 void SetItalic(bool set);
436 };
437
438
439
440 /**
441 @class wxDataViewItem
442
443 wxDataViewItem is a small opaque class that represents an item in a wxDataViewCtrl
444 in a persistent way, i.e. indepent of the position of the item in the control
445 or changes to its contents.
446
447 It must hold a unique ID of type @e void* in its only field and can be converted
448 to and from it.
449
450 If the ID is @NULL the wxDataViewItem is invalid and wxDataViewItem::IsOk will
451 return @false which used in many places in the API of wxDataViewCtrl to
452 indicate that e.g. no item was found. An ID of @NULL is also used to indicate
453 the invisible root. Examples for this are wxDataViewModel::GetParent and
454 wxDataViewModel::GetChildren.
455
456 @library{wxadv}
457 @category{dvc}
458 */
459 class wxDataViewItem
460 {
461 public:
462 //@{
463 /**
464 Constructor.
465 */
466 wxDataViewItem(void* id = NULL);
467 wxDataViewItem(const wxDataViewItem& item);
468 //@}
469
470 /**
471 Returns the ID.
472 */
473 void* GetID() const;
474
475 /**
476 Returns @true if the ID is not @NULL.
477 */
478 bool IsOk() const;
479 };
480
481
482
483 /**
484 @class wxDataViewCtrl
485
486 wxDataViewCtrl is a control to display data either in a tree like fashion or
487 in a tabular form or both.
488
489 If you only need to display a simple tree structure with an API more like the
490 older wxTreeCtrl class, then the specialized wxDataViewTreeCtrl can be used.
491 Likewise, if you only want to display simple table structure you can use
492 the specialized wxDataViewListCtrl class. Both wxDataViewTreeCtrl and
493 wxDataViewListCtrl can be used without defining your own wxDataViewModel.
494
495 A wxDataViewItem is used to represent a (visible) item in the control.
496
497 Unlike wxListCtrl, wxDataViewCtrl doesn't get its data from the user through
498 virtual functions or by setting it directly. Instead you need to write your own
499 wxDataViewModel and associate it with this control.
500 Then you need to add a number of wxDataViewColumn to this control to define
501 what each column shall display. Each wxDataViewColumn in turn owns 1 instance
502 of a wxDataViewRenderer to render its cells.
503
504 A number of standard renderers for rendering text, dates, images, toggle,
505 a progress bar etc. are provided. Additionally, the user can write custom
506 renderers deriving from wxDataViewCustomRenderer for displaying anything.
507
508 All data transfer from the control to the model and the user code is done
509 through wxVariant which can be extended to support more data formats as necessary.
510 Accordingly, all type information uses the strings returned from wxVariant::GetType.
511
512 @beginStyleTable
513 @style{wxDV_SINGLE}
514 Single selection mode. This is the default.
515 @style{wxDV_MULTIPLE}
516 Multiple selection mode.
517 @style{wxDV_ROW_LINES}
518 Use alternating colours for rows if supported by platform and theme.
519 @style{wxDV_HORIZ_RULES}
520 Display fine rules between row if supported.
521 @style{wxDV_VERT_RULES}
522 Display fine rules between columns is supported.
523 @style{wxDV_VARIABLE_LINE_HEIGHT}
524 Allow variable line heights.
525 This can be inefficient when displaying large number of items.
526 @endStyleTable
527
528 @beginEventTable{wxDataViewEvent}
529 @event{EVT_DATAVIEW_SELECTION_CHANGED(id, func)}
530 Process a wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED event.
531 @event{EVT_DATAVIEW_ITEM_ACTIVATED(id, func)}
532 Process a wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED event.
533 @event{EVT_DATAVIEW_ITEM_EDITING_STARTED(id, func)}
534 Process a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED event.
535 @event{EVT_DATAVIEW_ITEM_EDITING_DONE(id, func)}
536 Process a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE event.
537 @event{EVT_DATAVIEW_ITEM_COLLAPSING(id, func)}
538 Process a wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING event.
539 @event{EVT_DATAVIEW_ITEM_COLLAPSED(id, func)}
540 Process a wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED event.
541 @event{EVT_DATAVIEW_ITEM_EXPANDING(id, func)}
542 Process a wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING event.
543 @event{EVT_DATAVIEW_ITEM_EXPANDED(id, func)}
544 Process a wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED event.
545 @event{EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, func)}
546 Process a wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED event.
547 @event{EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, func)}
548 Process a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU event.
549 @event{EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, func)}
550 Process a wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICKED event.
551 @event{EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK(id, func)}
552 Process a wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED event.
553 @event{EVT_DATAVIEW_COLUMN_SORTED(id, func)}
554 Process a wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED event.
555 @event{EVT_DATAVIEW_COLUMN_REORDERED(id, func)}
556 Process a wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED event.
557 @event{EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, func)}
558 Process a wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG event.
559 @endEventTable
560
561 @library{wxadv}
562 @category{ctrl,dvc}
563 @appearance{dataviewctrl.png}
564 */
565 class wxDataViewCtrl : public wxControl
566 {
567 public:
568 /**
569 Default Constructor.
570 */
571 wxDataViewCtrl();
572
573 /**
574 Constructor. Calls Create().
575 */
576 wxDataViewCtrl(wxWindow* parent, wxWindowID id,
577 const wxPoint& pos = wxDefaultPosition,
578 const wxSize& size = wxDefaultSize,
579 long style = 0,
580 const wxValidator& validator = wxDefaultValidator);
581
582 /**
583 Destructor.
584 */
585 virtual ~wxDataViewCtrl();
586
587 /**
588 Appends a wxDataViewColumn to the control. Returns @true on success.
589
590 Note that there is a number of short cut methods which implicitly create
591 a wxDataViewColumn and a wxDataViewRenderer for it (see below).
592 */
593 virtual bool AppendColumn(wxDataViewColumn* col);
594
595 /**
596 Prepends a wxDataViewColumn to the control. Returns @true on success.
597
598 Note that there is a number of short cut methods which implicitly create
599 a wxDataViewColumn and a wxDataViewRenderer for it.
600 */
601 virtual bool PrependColumn(wxDataViewColumn* col);
602
603 /**
604 Inserts a wxDataViewColumn to the control. Returns @true on success.
605 */
606 virtual bool InsertColumn(unsigned int pos, wxDataViewColumn* col);
607
608 //@{
609 /**
610 Appends a column for rendering a bitmap. Returns the wxDataViewColumn
611 created in the function or @NULL on failure.
612 */
613 wxDataViewColumn* AppendBitmapColumn(const wxString& label,
614 unsigned int model_column,
615 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
616 int width = -1,
617 wxAlignment align = wxALIGN_CENTER,
618 int flags = wxDATAVIEW_COL_RESIZABLE);
619 wxDataViewColumn* AppendBitmapColumn(const wxBitmap& label,
620 unsigned int model_column,
621 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
622 int width = -1,
623 wxAlignment align = wxALIGN_CENTER,
624 int flags = wxDATAVIEW_COL_RESIZABLE);
625 //@}
626
627 //@{
628 /**
629 Appends a column for rendering a date. Returns the wxDataViewColumn
630 created in the function or @NULL on failure.
631
632 @note The @a align parameter is applied to both the column header and
633 the column renderer.
634 */
635 wxDataViewColumn* AppendDateColumn(const wxString& label,
636 unsigned int model_column,
637 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
638 int width = -1,
639 wxAlignment align = wxALIGN_NOT,
640 int flags = wxDATAVIEW_COL_RESIZABLE);
641 wxDataViewColumn* AppendDateColumn(const wxBitmap& label,
642 unsigned int model_column,
643 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
644 int width = -1,
645 wxAlignment align = wxALIGN_NOT,
646 int flags = wxDATAVIEW_COL_RESIZABLE);
647 //@}
648
649 //@{
650 /**
651 Appends a column for rendering text with an icon. Returns the wxDataViewColumn
652 created in the function or @NULL on failure.
653 This method uses the wxDataViewIconTextRenderer class.
654
655 @note The @a align parameter is applied to both the column header and
656 the column renderer.
657 */
658 wxDataViewColumn* AppendIconTextColumn(const wxString& label,
659 unsigned int model_column,
660 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
661 int width = -1,
662 wxAlignment align = wxALIGN_NOT,
663 int flags = wxDATAVIEW_COL_RESIZABLE);
664 wxDataViewColumn* AppendIconTextColumn(const wxBitmap& label,
665 unsigned int model_column,
666 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
667 int width = -1,
668 wxAlignment align = wxALIGN_NOT,
669 int flags = wxDATAVIEW_COL_RESIZABLE);
670 //@}
671
672 //@{
673 /**
674 Appends a column for rendering a progress indicator. Returns the
675 wxDataViewColumn created in the function or @NULL on failure.
676
677 @note The @a align parameter is applied to both the column header and
678 the column renderer.
679 */
680 wxDataViewColumn* AppendProgressColumn(const wxString& label,
681 unsigned int model_column,
682 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
683 int width = 80,
684 wxAlignment align = wxALIGN_CENTER,
685 int flags = wxDATAVIEW_COL_RESIZABLE);
686 wxDataViewColumn* AppendProgressColumn(const wxBitmap& label,
687 unsigned int model_column,
688 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
689 int width = 80,
690 wxAlignment align = wxALIGN_CENTER,
691 int flags = wxDATAVIEW_COL_RESIZABLE);
692 //@}
693
694 //@{
695 /**
696 Appends a column for rendering text. Returns the wxDataViewColumn
697 created in the function or @NULL on failure.
698
699 @note The @a align parameter is applied to both the column header and
700 the column renderer.
701 */
702 wxDataViewColumn* AppendTextColumn(const wxString& label,
703 unsigned int model_column,
704 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
705 int width = -1,
706 wxAlignment align = wxALIGN_NOT,
707 int flags = wxDATAVIEW_COL_RESIZABLE);
708 wxDataViewColumn* AppendTextColumn(const wxBitmap& label,
709 unsigned int model_column,
710 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
711 int width = -1,
712 wxAlignment align = wxALIGN_NOT,
713 int flags = wxDATAVIEW_COL_RESIZABLE);
714 //@}
715
716 //@{
717 /**
718 Appends a column for rendering a toggle. Returns the wxDataViewColumn
719 created in the function or @NULL on failure.
720
721 @note The @a align parameter is applied to both the column header and
722 the column renderer.
723 */
724 wxDataViewColumn* AppendToggleColumn(const wxString& label,
725 unsigned int model_column,
726 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
727 int width = 30,
728 wxAlignment align = wxALIGN_CENTER,
729 int flags = wxDATAVIEW_COL_RESIZABLE);
730 wxDataViewColumn* AppendToggleColumn(const wxBitmap& label,
731 unsigned int model_column,
732 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
733 int width = 30,
734 wxAlignment align = wxALIGN_CENTER,
735 int flags = wxDATAVIEW_COL_RESIZABLE);
736 //@}
737
738 /**
739 Associates a wxDataViewModel with the control.
740 This increases the reference count of the model by 1.
741 */
742 virtual bool AssociateModel(wxDataViewModel* model);
743
744 /**
745 Removes all columns.
746 */
747 virtual bool ClearColumns();
748
749 /**
750 Collapses the item.
751 */
752 virtual void Collapse(const wxDataViewItem& item);
753
754 /**
755 Create the control. Useful for two step creation.
756 */
757 bool Create(wxWindow* parent, wxWindowID id,
758 const wxPoint& pos = wxDefaultPosition,
759 const wxSize& size = wxDefaultSize,
760 long style = 0,
761 const wxValidator& validator = wxDefaultValidator);
762
763 /**
764 Deletes given column.
765 */
766 virtual bool DeleteColumn(wxDataViewColumn* column);
767
768 /**
769 Call this to ensure that the given item is visible.
770 */
771 virtual void EnsureVisible(const wxDataViewItem& item,
772 const wxDataViewColumn* column = NULL);
773
774 /**
775 Expands the item.
776 */
777 virtual void Expand(const wxDataViewItem& item);
778
779 /**
780 Expands all ancestors of the @a item. This method also
781 ensures that the item itself as well as all ancestor
782 items have been read from the model by the control.
783 */
784 virtual void ExpandAncestors( const wxDataViewItem & item );
785
786 /**
787 Returns pointer to the column. @a pos refers to the position in the
788 control which may change after reordering columns by the user.
789 */
790 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
791
792 /**
793 Returns the number of columns.
794 */
795 virtual unsigned int GetColumnCount() const;
796
797 /**
798 Returns the position of the column or -1 if not found in the control.
799 */
800 virtual int GetColumnPosition(const wxDataViewColumn* column) const;
801
802 /**
803 Returns column containing the expanders.
804 */
805 wxDataViewColumn* GetExpanderColumn() const;
806
807 /**
808 Returns indentation.
809 */
810 int GetIndent() const;
811
812 /**
813 Returns item rect.
814 */
815 virtual wxRect GetItemRect(const wxDataViewItem& item,
816 const wxDataViewColumn* col = NULL) const;
817
818 /**
819 Returns pointer to the data model associated with the control (if any).
820 */
821 wxDataViewModel* GetModel();
822
823 /**
824 Returns first selected item or an invalid item if none is selected.
825 */
826 virtual wxDataViewItem GetSelection() const;
827
828 /**
829 Fills @a sel with currently selected items and returns their number.
830 */
831 virtual int GetSelections(wxDataViewItemArray& sel) const;
832
833 /**
834 Returns the wxDataViewColumn currently responsible for sorting
835 or @NULL if none has been selected.
836 */
837 virtual wxDataViewColumn* GetSortingColumn() const;
838
839 /**
840 Hittest.
841 */
842 virtual void HitTest(const wxPoint& point, wxDataViewItem& item,
843 wxDataViewColumn*& col) const;
844
845 /**
846 Return @true if the item is expanded.
847 */
848 virtual bool IsExpanded(const wxDataViewItem& item) const;
849
850 /**
851 Return @true if the item is selected.
852 */
853 virtual bool IsSelected(const wxDataViewItem& item) const;
854
855 /**
856 Select the given item.
857 */
858 virtual void Select(const wxDataViewItem& item);
859
860 /**
861 Select all items.
862 */
863 virtual void SelectAll();
864
865 /**
866 Set which column shall contain the tree-like expanders.
867 */
868 void SetExpanderColumn(wxDataViewColumn* col);
869
870 /**
871 Sets the indendation.
872 */
873 void SetIndent(int indent);
874
875 /**
876 Sets the selection to the array of wxDataViewItems.
877 */
878 virtual void SetSelections(const wxDataViewItemArray& sel);
879
880 /**
881 Unselect the given item.
882 */
883 virtual void Unselect(const wxDataViewItem& item);
884
885 /**
886 Unselect all item.
887 This method only has effect if multiple selections are allowed.
888 */
889 virtual void UnselectAll();
890 };
891
892
893
894 /**
895 @class wxDataViewModelNotifier
896
897 A wxDataViewModelNotifier instance is owned by a wxDataViewModel and mirrors
898 its notification interface.
899 See the documentation of that class for further information.
900
901 @library{wxadv}
902 @category{dvc}
903 */
904 class wxDataViewModelNotifier
905 {
906 public:
907 /**
908 Constructor.
909 */
910 wxDataViewModelNotifier();
911
912 /**
913 Destructor.
914 */
915 virtual ~wxDataViewModelNotifier();
916
917 /**
918 Called by owning model.
919 */
920 virtual bool Cleared() = 0;
921
922 /**
923 Get owning wxDataViewModel.
924 */
925 wxDataViewModel* GetOwner() const;
926
927 /**
928 Called by owning model.
929 */
930 virtual bool ItemAdded(const wxDataViewItem& parent,
931 const wxDataViewItem& item) = 0;
932
933 /**
934 Called by owning model.
935 */
936 virtual bool ItemChanged(const wxDataViewItem& item) = 0;
937
938 /**
939 Called by owning model.
940 */
941 virtual bool ItemDeleted(const wxDataViewItem& parent,
942 const wxDataViewItem& item) = 0;
943
944 /**
945 Called by owning model.
946 */
947 virtual bool ItemsAdded(const wxDataViewItem& parent,
948 const wxDataViewItemArray& items);
949
950 /**
951 Called by owning model.
952 */
953 virtual bool ItemsChanged(const wxDataViewItemArray& items);
954
955 /**
956 Called by owning model.
957 */
958 virtual bool ItemsDeleted(const wxDataViewItem& parent,
959 const wxDataViewItemArray& items);
960
961 /**
962 Called by owning model.
963 */
964 virtual void Resort() = 0;
965
966 /**
967 Set owner of this notifier. Used internally.
968 */
969 void SetOwner(wxDataViewModel* owner);
970
971 /**
972 Called by owning model.
973 */
974 virtual bool ValueChanged(const wxDataViewItem& item, unsigned int col) = 0;
975 };
976
977
978 /**
979 The mode of a data-view cell; see wxDataViewRenderer for more info.
980 */
981 enum wxDataViewCellMode
982 {
983 wxDATAVIEW_CELL_INERT,
984
985 /**
986 Indicates that the user can double click the cell and something will
987 happen (e.g. a window for editing a date will pop up).
988 */
989 wxDATAVIEW_CELL_ACTIVATABLE,
990
991 /**
992 Indicates that the user can edit the data in-place, i.e. an control
993 will show up after a slow click on the cell. This behaviour is best
994 known from changing the filename in most file managers etc.
995 */
996 wxDATAVIEW_CELL_EDITABLE
997 };
998
999 /**
1000 The values of this enum controls how a wxDataViewRenderer should display
1001 its contents in a cell.
1002 */
1003 enum wxDataViewCellRenderState
1004 {
1005 wxDATAVIEW_CELL_SELECTED = 1,
1006 wxDATAVIEW_CELL_PRELIT = 2,
1007 wxDATAVIEW_CELL_INSENSITIVE = 4,
1008 wxDATAVIEW_CELL_FOCUSED = 8
1009 };
1010
1011 /**
1012 @class wxDataViewRenderer
1013
1014 This class is used by wxDataViewCtrl to render the individual cells.
1015 One instance of a renderer class is owned by a wxDataViewColumn.
1016 There is a number of ready-to-use renderers provided:
1017 - wxDataViewTextRenderer,
1018 - wxDataViewTextRendererAttr,
1019 - wxDataViewIconTextRenderer,
1020 - wxDataViewToggleRenderer,
1021 - wxDataViewProgressRenderer,
1022 - wxDataViewBitmapRenderer,
1023 - wxDataViewDateRenderer,
1024 - wxDataViewSpinRenderer.
1025
1026 Additionally, the user can write own renderers by deriving from
1027 wxDataViewCustomRenderer.
1028
1029 The ::wxDataViewCellMode and ::wxDataViewCellRenderState flags accepted
1030 by the constructors respectively controls what actions the cell data allows
1031 and how the renderer should display its contents in a cell.
1032
1033 @library{wxadv}
1034 @category{dvc}
1035 */
1036 class wxDataViewRenderer : public wxObject
1037 {
1038 public:
1039 /**
1040 Constructor.
1041 */
1042 wxDataViewRenderer(const wxString& varianttype,
1043 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1044 int align = wxDVR_DEFAULT_ALIGNMENT );
1045
1046 /**
1047 Returns the alignment. See SetAlignment()
1048 */
1049 virtual int GetAlignment() const;
1050
1051 /**
1052 Returns the cell mode.
1053 */
1054 virtual wxDataViewCellMode GetMode() const;
1055
1056 /**
1057 Returns pointer to the owning wxDataViewColumn.
1058 */
1059 wxDataViewColumn* GetOwner() const;
1060
1061 /**
1062 This methods retrieves the value from the renderer in order to
1063 transfer the value back to the data model.
1064
1065 Returns @false on failure.
1066 */
1067 virtual bool GetValue(wxVariant& value) const = 0;
1068
1069 /**
1070 Returns a string with the type of the wxVariant supported by this renderer.
1071 */
1072 wxString GetVariantType() const;
1073
1074 /**
1075 Sets the alignment of the renderer's content.
1076 The default value of @c wxDVR_DEFAULT_ALIGMENT indicates that the content
1077 should have the same alignment as the column header.
1078
1079 The method is not implemented under OS X and the renderer always aligns
1080 its contents as the column header on that platform. The other platforms
1081 support both vertical and horizontal alignment.
1082 */
1083 virtual void SetAlignment( int align );
1084 /**
1085 Sets the owning wxDataViewColumn.
1086 This is usually called from within wxDataViewColumn.
1087 */
1088 void SetOwner(wxDataViewColumn* owner);
1089
1090 /**
1091 Set the value of the renderer (and thus its cell) to @a value.
1092 The internal code will then render this cell with this data.
1093 */
1094 virtual bool SetValue(const wxVariant& value) = 0;
1095
1096 /**
1097 Before data is committed to the data model, it is passed to this
1098 method where it can be checked for validity. This can also be
1099 used for checking a valid range or limiting the user input in
1100 a certain aspect (e.g. max number of characters or only alphanumeric
1101 input, ASCII only etc.). Return @false if the value is not valid.
1102
1103 Please note that due to implementation limitations, this validation
1104 is done after the editing control already is destroyed and the
1105 editing process finished.
1106 */
1107 virtual bool Validate(wxVariant& value);
1108 };
1109
1110
1111
1112 /**
1113 @class wxDataViewTextRenderer
1114
1115 wxDataViewTextRenderer is used for rendering text.
1116 It supports in-place editing if desired.
1117
1118 @library{wxadv}
1119 @category{dvc}
1120 */
1121 class wxDataViewTextRenderer : public wxDataViewRenderer
1122 {
1123 public:
1124 /**
1125 The ctor.
1126 */
1127 wxDataViewTextRenderer(const wxString& varianttype = "string",
1128 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1129 int align = wxDVR_DEFAULT_ALIGNMENT );
1130 };
1131
1132
1133
1134 /**
1135 @class wxDataViewIconTextRenderer
1136
1137 The wxDataViewIconTextRenderer class is used to display text with
1138 a small icon next to it as it is typically done in a file manager.
1139
1140 This classes uses the wxDataViewIconText helper class to store its data.
1141 wxDataViewIonText can be converted to and from a wxVariant using the left shift
1142 operator.
1143
1144 @library{wxadv}
1145 @category{dvc}
1146 */
1147 class wxDataViewIconTextRenderer : public wxDataViewRenderer
1148 {
1149 public:
1150 /**
1151 The ctor.
1152 */
1153 wxDataViewIconTextRenderer(const wxString& varianttype = "wxDataViewIconText",
1154 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1155 int align = wxDVR_DEFAULT_ALIGNMENT );
1156 };
1157
1158
1159
1160 /**
1161 @class wxDataViewProgressRenderer
1162
1163 This class is used by wxDataViewCtrl to render progress bars.
1164
1165 @library{wxadv}
1166 @category{dvc}
1167 */
1168 class wxDataViewProgressRenderer : public wxDataViewRenderer
1169 {
1170 public:
1171 /**
1172 The ctor.
1173 */
1174 wxDataViewProgressRenderer(const wxString& label = wxEmptyString,
1175 const wxString& varianttype = "long",
1176 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1177 int align = wxDVR_DEFAULT_ALIGNMENT );
1178 };
1179
1180
1181
1182 /**
1183 @class wxDataViewSpinRenderer
1184
1185 This is a specialized renderer for rendering integer values.
1186 It supports modifying the values in-place by using a wxSpinCtrl.
1187 The renderer only support variants of type @e long.
1188
1189 @library{wxadv}
1190 @category{dvc}
1191 */
1192 class wxDataViewSpinRenderer : public wxDataViewCustomRenderer
1193 {
1194 public:
1195 /**
1196 Constructor.
1197 @a min and @a max indicate the minimum and maximum values for the wxSpinCtrl.
1198 */
1199 wxDataViewSpinRenderer(int min, int max,
1200 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
1201 int align = wxDVR_DEFAULT_ALIGNMENT);
1202 };
1203
1204
1205
1206 /**
1207 @class wxDataViewToggleRenderer
1208
1209 This class is used by wxDataViewCtrl to render toggle controls.
1210
1211 @library{wxadv}
1212 @category{dvc}
1213 */
1214 class wxDataViewToggleRenderer : public wxDataViewRenderer
1215 {
1216 public:
1217 /**
1218 The ctor.
1219 */
1220 wxDataViewToggleRenderer(const wxString& varianttype = "bool",
1221 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1222 int align = wxDVR_DEFAULT_ALIGNMENT);
1223 };
1224
1225
1226
1227 /**
1228 @class wxDataViewDateRenderer
1229
1230 This class is used by wxDataViewCtrl to render calendar controls.
1231
1232 @library{wxadv}
1233 @category{dvc}
1234 */
1235 class wxDataViewDateRenderer : public wxDataViewRenderer
1236 {
1237 public:
1238 /**
1239 The ctor.
1240 */
1241 wxDataViewDateRenderer(const wxString& varianttype = "datetime",
1242 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
1243 int align = wxDVR_DEFAULT_ALIGNMENT);
1244 };
1245
1246
1247
1248 /**
1249 @class wxDataViewTextRendererAttr
1250
1251 The same as wxDataViewTextRenderer but with support for font attributes.
1252 Font attributes are currently only supported under GTK+ and MSW.
1253
1254 @see wxDataViewModel::GetAttr and wxDataViewItemAttr.
1255
1256 @library{wxadv}
1257 @category{dvc}
1258 */
1259 class wxDataViewTextRendererAttr : public wxDataViewTextRenderer
1260 {
1261 public:
1262 /**
1263 The ctor.
1264 */
1265 wxDataViewTextRendererAttr(const wxString& varianttype = "string",
1266 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1267 int align = wxDVR_DEFAULT_ALIGNMENT);
1268 };
1269
1270
1271
1272 /**
1273 @class wxDataViewCustomRenderer
1274
1275 You need to derive a new class from wxDataViewCustomRenderer in
1276 order to write a new renderer.
1277
1278 You need to override at least wxDataViewRenderer::SetValue, wxDataViewRenderer::GetValue,
1279 wxDataViewCustomRenderer::GetSize and wxDataViewCustomRenderer::Render.
1280
1281 If you want your renderer to support in-place editing then you also need to override
1282 wxDataViewCustomRenderer::HasEditorCtrl, wxDataViewCustomRenderer::CreateEditorCtrl
1283 and wxDataViewCustomRenderer::GetValueFromEditorCtrl.
1284
1285 Note that a special event handler will be pushed onto that editor control
1286 which handles @e \<ENTER\> and focus out events in order to end the editing.
1287
1288 @library{wxadv}
1289 @category{dvc}
1290 */
1291 class wxDataViewCustomRenderer : public wxDataViewRenderer
1292 {
1293 public:
1294 /**
1295 Constructor.
1296 */
1297 wxDataViewCustomRenderer(const wxString& varianttype = "string",
1298 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1299 int align = -1, bool no_init = false);
1300
1301 /**
1302 Destructor.
1303 */
1304 virtual ~wxDataViewCustomRenderer();
1305
1306 /**
1307 Override this to react to double clicks or ENTER.
1308 This method will only be called in wxDATAVIEW_CELL_ACTIVATABLE mode.
1309 */
1310 virtual bool Activate( wxRect cell,
1311 wxDataViewModel* model,
1312 const wxDataViewItem & item,
1313 unsigned int col );
1314
1315 /**
1316 Override this to create the actual editor control once editing
1317 is about to start.
1318
1319 @a parent is the parent of the editor control, @a labelRect indicates the
1320 position and size of the editor control and @a value is its initial value:
1321 @code
1322 {
1323 long l = value;
1324 return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
1325 labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l );
1326 }
1327 @endcode
1328 */
1329 virtual wxControl* CreateEditorCtrl(wxWindow* parent,
1330 wxRect labelRect,
1331 const wxVariant& value);
1332
1333 /**
1334 Create DC on request. Internal.
1335 */
1336 virtual wxDC* GetDC();
1337
1338 /**
1339 Return size required to show content.
1340 */
1341 virtual wxSize GetSize() const = 0;
1342
1343 /**
1344 Overrride this so that the renderer can get the value from the editor
1345 control (pointed to by @a editor):
1346 @code
1347 {
1348 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1349 long l = sc->GetValue();
1350 value = l;
1351 return true;
1352 }
1353 @endcode
1354 */
1355 virtual bool GetValueFromEditorCtrl(wxControl* editor,
1356 wxVariant& value);
1357
1358 /**
1359 Override this and make it return @true in order to
1360 indicate that this renderer supports in-place editing.
1361 */
1362 virtual bool HasEditorCtrl();
1363
1364 /**
1365 Overrride this to react to a left click.
1366 This method will only be called in @c wxDATAVIEW_CELL_ACTIVATABLE mode.
1367 */
1368 virtual bool LeftClick( wxPoint cursor,
1369 wxRect cell,
1370 wxDataViewModel * model,
1371 const wxDataViewItem & item,
1372 unsigned int col );
1373
1374 /**
1375 Override this to render the cell.
1376 Before this is called, wxDataViewRenderer::SetValue was called
1377 so that this instance knows what to render.
1378 */
1379 virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
1380
1381 /**
1382 This method should be called from within Render() whenever you need to
1383 render simple text.
1384 This will ensure that the correct colour, font and vertical alignment will
1385 be chosen so the text will look the same as text drawn by native renderers.
1386 */
1387 void RenderText(const wxString& text, int xoffset, wxRect cell,
1388 wxDC* dc, int state);
1389
1390 /**
1391 Overrride this to start a drag operation. Not yet supported.
1392 */
1393 virtual bool StartDrag(wxPoint cursor, wxRect cell,
1394 wxDataViewModel* model,
1395 const wxDataViewItem & item,
1396 unsigned int col);
1397 };
1398
1399
1400
1401 /**
1402 @class wxDataViewBitmapRenderer
1403
1404 This class is used by wxDataViewCtrl to render bitmap controls.
1405
1406 @library{wxadv}
1407 @category{dvc}
1408 */
1409 class wxDataViewBitmapRenderer : public wxDataViewRenderer
1410 {
1411 public:
1412 /**
1413 The ctor.
1414 */
1415 wxDataViewBitmapRenderer(const wxString& varianttype = "wxBitmap",
1416 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1417 int align = wxDVR_DEFAULT_ALIGNMENT);
1418 };
1419
1420
1421 /**
1422 The flags used by wxDataViewColumn.
1423 */
1424 enum wxDataViewColumnFlags
1425 {
1426 wxDATAVIEW_COL_RESIZABLE = 1,
1427 wxDATAVIEW_COL_SORTABLE = 2,
1428 wxDATAVIEW_COL_REORDERABLE = 4,
1429 wxDATAVIEW_COL_HIDDEN = 8
1430 };
1431
1432 /**
1433 @class wxDataViewColumn
1434
1435 This class represents a column in a wxDataViewCtrl.
1436 One wxDataViewColumn is bound to one column in the data model to which the
1437 wxDataViewCtrl has been associated.
1438
1439 An instance of wxDataViewRenderer is used by this class to render its data.
1440
1441 @library{wxadv}
1442 @category{dvc}
1443 */
1444 class wxDataViewColumn : public wxHeaderColumn
1445 {
1446 public:
1447 //@{
1448 /**
1449 Constructors.
1450 */
1451 wxDataViewColumn(const wxString& title,
1452 wxDataViewRenderer* renderer,
1453 unsigned int model_column,
1454 int width = wxDVC_DEFAULT_WIDTH,
1455 wxAlignment align = wxALIGN_CENTER,
1456 int flags = wxDATAVIEW_COL_RESIZABLE);
1457 wxDataViewColumn(const wxBitmap& bitmap,
1458 wxDataViewRenderer* renderer,
1459 unsigned int model_column,
1460 int width = wxDVC_DEFAULT_WIDTH,
1461 wxAlignment align = wxALIGN_CENTER,
1462 int flags = wxDATAVIEW_COL_RESIZABLE);
1463 //@}
1464
1465 /**
1466 Returns the index of the column of the model, which this
1467 wxDataViewColumn is displaying.
1468 */
1469 unsigned int GetModelColumn() const;
1470
1471 /**
1472 Returns the owning wxDataViewCtrl.
1473 */
1474 wxDataViewCtrl* GetOwner() const;
1475
1476 /**
1477 Returns the renderer of this wxDataViewColumn.
1478
1479 @see wxDataViewRenderer.
1480 */
1481 wxDataViewRenderer* GetRenderer() const;
1482 };
1483
1484
1485
1486 /**
1487 @class wxDataViewListCtrl
1488
1489 This class is a wxDataViewCtrl which internally uses a wxDataViewListStore
1490 and forwards most of its API to that class.
1491
1492 The purpose of this class is to offer a simple way to display and
1493 edit a small table of data without having to write your own wxDataViewModel.
1494
1495 @code
1496 wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( parent, -1 );
1497
1498 listctrl->AppendToggleColumn( "Toggle" );
1499 listctrl->AppendTextColumn( "Text" );
1500
1501 wxVector<wxVariant> data;
1502 data.push_back( true );
1503 data.push_back( "row 1" );
1504 listctrl->AppendItem( data );
1505
1506 data.clear();
1507 data.push_back( false );
1508 data.push_back( "row 3" );
1509 listctrl->AppendItem( data );
1510 @endcode
1511
1512
1513 @library{wxadv}
1514 @category{ctrl,dvc}
1515 */
1516 class wxDataViewListCtrl: public wxDataViewCtrl
1517 {
1518 public:
1519 /**
1520 Default ctor.
1521 */
1522 wxDataViewListCtrl();
1523
1524 /**
1525 Constructor. Calls Create().
1526 */
1527 wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
1528 const wxPoint& pos = wxDefaultPosition,
1529 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1530 const wxValidator& validator = wxDefaultValidator );
1531
1532 /**
1533 Destructor. Deletes the image list if any.
1534 */
1535 ~wxDataViewListCtrl();
1536
1537 /**
1538 Creates the control and a wxDataViewListStore as its internal model.
1539 */
1540 bool Create( wxWindow *parent, wxWindowID id,
1541 const wxPoint& pos = wxDefaultPosition,
1542 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1543 const wxValidator& validator = wxDefaultValidator );
1544
1545 //@{
1546 /**
1547 Returns the store.
1548 */
1549 wxDataViewListStore *GetStore();
1550 const wxDataViewListStore *GetStore() const;
1551 //@}
1552
1553 /**
1554 Appends a column to the control and additonally appends a
1555 column to the store with the type @a varianttype.
1556 */
1557 void AppendColumn( wxDataViewColumn *column, const wxString &varianttype );
1558
1559 /**
1560 Prepends a column to the control and additonally prepends a
1561 column to the store with the type @a varianttype.
1562 */
1563 void PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
1564
1565 /**
1566 Inserts a column to the control and additonally inserts a
1567 column to the store with the type @a varianttype.
1568 */
1569 void InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
1570
1571 /**
1572 Overridden from wxDataViewCtrl
1573
1574 Appends a column to the control and additonally appends a
1575 column to the store with the type string.
1576 */
1577 virtual void AppendColumn( wxDataViewColumn *column );
1578
1579 /**
1580 Overridden from wxDataViewCtrl
1581
1582 Prepends a column to the control and additonally prepends a
1583 column to the store with the type string.
1584 */
1585 virtual void PrependColumn( wxDataViewColumn *column );
1586
1587 /**
1588 Overridden from wxDataViewCtrl
1589
1590 Inserts a column to the control and additonally inserts a
1591 column to the store with the type string.
1592 */
1593 virtual void InsertColumn( unsigned int pos, wxDataViewColumn *column );
1594
1595 /**
1596 Inserts a text column to the control and the store.
1597 */
1598 wxDataViewColumn *AppendTextColumn( const wxString &label,
1599 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1600 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1601
1602 /**
1603 Inserts a toggle column to the control and the store.
1604 */
1605 wxDataViewColumn *AppendToggleColumn( const wxString &label,
1606 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
1607 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1608
1609 /**
1610 Inserts a progress column to the control and the store.
1611 */
1612 wxDataViewColumn *AppendProgressColumn( const wxString &label,
1613 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1614 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1615
1616 /**
1617 Inserts a icon and text column to the control and the store.
1618 */
1619 wxDataViewColumn *AppendIconTextColumn( const wxString &label,
1620 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1621 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1622
1623 /**
1624 Appends an item (=row) to the control and store.
1625 */
1626 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
1627
1628 /**
1629 Prepends an item (=row) to the control and store.
1630 */
1631 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
1632
1633 /**
1634 Inserts an item (=row) to the control and store.
1635 */
1636 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
1637
1638 /**
1639 Delete the row at position @a row.
1640 */
1641 void DeleteItem( unsigned row );
1642
1643 /**
1644 Delete all items (= all rows).
1645 */
1646 void DeleteAllItems();
1647
1648 /**
1649 Sets the value in the store and update the control.
1650 */
1651 void SetValue( const wxVariant &value, unsigned int row, unsigned int col );
1652
1653 /**
1654 Returns the value from the store.
1655 */
1656 void GetValue( wxVariant &value, unsigned int row, unsigned int col );
1657
1658 /**
1659 Sets the value in the store and update the control.
1660
1661 This method assumes that the a string is stored in respective
1662 column.
1663 */
1664 void SetTextValue( const wxString &value, unsigned int row, unsigned int col );
1665
1666 /**
1667 Returns the value from the store.
1668
1669 This method assumes that the a string is stored in respective
1670 column.
1671 */
1672 wxString GetTextValue( unsigned int row, unsigned int col ) const;
1673
1674 /**
1675 Sets the value in the store and update the control.
1676
1677 This method assumes that the a boolean value is stored in
1678 respective column.
1679 */
1680 void SetToggleValue( bool value, unsigned int row, unsigned int col );
1681
1682 /**
1683 Returns the value from the store.
1684
1685 This method assumes that the a boolean value is stored in
1686 respective column.
1687 */
1688 bool GetToggleValue( unsigned int row, unsigned int col ) const;
1689 };
1690
1691
1692 /**
1693 @class wxDataViewTreeCtrl
1694
1695 This class is a wxDataViewCtrl which internally uses a wxDataViewTreeStore
1696 and forwards most of its API to that class.
1697 Additionally, it uses a wxImageList to store a list of icons.
1698
1699 The main purpose of this class is to look like a wxTreeCtrl to make a transition
1700 from it to the wxDataViewCtrl class simpler.
1701
1702 @library{wxadv}
1703 @category{ctrl,dvc}
1704 @appearance{dataviewtreectrl.png}
1705 */
1706 class wxDataViewTreeCtrl : public wxDataViewCtrl
1707 {
1708 public:
1709 /**
1710 Default ctor.
1711 */
1712 wxDataViewTreeCtrl();
1713
1714 /**
1715 Constructor. Calls Create().
1716 */
1717 wxDataViewTreeCtrl(wxWindow* parent, wxWindowID id,
1718 const wxPoint& pos = wxDefaultPosition,
1719 const wxSize& size = wxDefaultSize,
1720 long style = wxDV_NO_HEADER,
1721 const wxValidator& validator = wxDefaultValidator);
1722
1723 /**
1724 Destructor. Deletes the image list if any.
1725 */
1726 virtual ~wxDataViewTreeCtrl();
1727
1728 /**
1729 Appends a container to the given @a parent.
1730 */
1731 wxDataViewItem AppendContainer(const wxDataViewItem& parent,
1732 const wxString& text,
1733 int icon = -1,
1734 int expanded = -1,
1735 wxClientData* data = NULL);
1736
1737 /**
1738 Appends an item to the given @a parent.
1739 */
1740 wxDataViewItem AppendItem(const wxDataViewItem& parent,
1741 const wxString& text,
1742 int icon = -1,
1743 wxClientData* data = NULL);
1744
1745 /**
1746 Creates the control and a wxDataViewTreeStore as its internal model.
1747 */
1748 bool Create(wxWindow* parent, wxWindowID id,
1749 const wxPoint& pos = wxDefaultPosition,
1750 const wxSize& size = wxDefaultSize,
1751 long style = wxDV_NO_HEADER,
1752 const wxValidator& validator = wxDefaultValidator);
1753
1754 /**
1755 Calls the identical method from wxDataViewTreeStore.
1756 */
1757 void DeleteAllItems();
1758
1759 /**
1760 Calls the identical method from wxDataViewTreeStore.
1761 */
1762 void DeleteChildren(const wxDataViewItem& item);
1763
1764 /**
1765 Calls the identical method from wxDataViewTreeStore.
1766 */
1767 void DeleteItem(const wxDataViewItem& item);
1768
1769 /**
1770 Calls the identical method from wxDataViewTreeStore.
1771 */
1772 int GetChildCount(const wxDataViewItem& parent) const;
1773
1774 /**
1775 Returns the image list.
1776 */
1777 wxImageList* GetImageList();
1778
1779 /**
1780 Calls the identical method from wxDataViewTreeStore.
1781 */
1782 wxClientData* GetItemData(const wxDataViewItem& item) const;
1783
1784 /**
1785 Calls the identical method from wxDataViewTreeStore.
1786 */
1787 const wxIcon& GetItemExpandedIcon(const wxDataViewItem& item) const;
1788
1789 /**
1790 Calls the identical method from wxDataViewTreeStore.
1791 */
1792 const wxIcon& GetItemIcon(const wxDataViewItem& item) const;
1793
1794 /**
1795 Calls the identical method from wxDataViewTreeStore.
1796 */
1797 wxString GetItemText(const wxDataViewItem& item) const;
1798
1799 /**
1800 Calls the identical method from wxDataViewTreeStore.
1801 */
1802 wxDataViewItem GetNthChild(const wxDataViewItem& parent,
1803 unsigned int pos) const;
1804
1805 //@{
1806 /**
1807 Returns the store.
1808 */
1809 wxDataViewTreeStore* GetStore();
1810 const wxDataViewTreeStore* GetStore() const;
1811 //@}
1812
1813 /**
1814 Calls the same method from wxDataViewTreeStore but uses
1815 an index position in the image list instead of a wxIcon.
1816 */
1817 wxDataViewItem InsertContainer(const wxDataViewItem& parent,
1818 const wxDataViewItem& previous,
1819 const wxString& text,
1820 int icon = -1,
1821 int expanded = -1,
1822 wxClientData* data = NULL);
1823
1824 /**
1825 Calls the same method from wxDataViewTreeStore but uses
1826 an index position in the image list instead of a wxIcon.
1827 */
1828 wxDataViewItem InsertItem(const wxDataViewItem& parent,
1829 const wxDataViewItem& previous,
1830 const wxString& text,
1831 int icon = -1,
1832 wxClientData* data = NULL);
1833
1834 /**
1835 Calls the same method from wxDataViewTreeStore but uses
1836 an index position in the image list instead of a wxIcon.
1837 */
1838 wxDataViewItem PrependContainer(const wxDataViewItem& parent,
1839 const wxString& text,
1840 int icon = -1,
1841 int expanded = -1,
1842 wxClientData* data = NULL);
1843
1844 /**
1845 Calls the same method from wxDataViewTreeStore but uses
1846 an index position in the image list instead of a wxIcon.
1847 */
1848 wxDataViewItem PrependItem(const wxDataViewItem& parent,
1849 const wxString& text,
1850 int icon = -1,
1851 wxClientData* data = NULL);
1852
1853 /**
1854 Sets the image list.
1855 */
1856 void SetImageList(wxImageList* imagelist);
1857
1858 /**
1859 Calls the identical method from wxDataViewTreeStore.
1860 */
1861 void SetItemData(const wxDataViewItem& item, wxClientData* data);
1862
1863 /**
1864 Calls the identical method from wxDataViewTreeStore.
1865 */
1866 void SetItemExpandedIcon(const wxDataViewItem& item,
1867 const wxIcon& icon);
1868
1869 /**
1870 Calls the identical method from wxDataViewTreeStore.
1871 */
1872 void SetItemIcon(const wxDataViewItem& item, const wxIcon& icon);
1873
1874 /**
1875 Calls the identical method from wxDataViewTreeStore.
1876 */
1877 void SetItemText(const wxDataViewItem& item,
1878 const wxString& text);
1879 };
1880
1881
1882 /**
1883 @class wxDataViewListStore
1884
1885 wxDataViewListStore is a specialised wxDataViewModel for storing
1886 a simple table of data. Since it derives from wxDataViewIndexListModel
1887 its data is be accessed by row (i.e. by index) instead of only
1888 by wxDataViewItem.
1889
1890 This class actually stores the values (therefore its name)
1891 and implements all virtual methods from the base classes so it can be
1892 used directly without having to derive any class from it, but it is
1893 mostly used from within wxDataViewListCtrl.
1894
1895 @library{wxadv}
1896 @category{dvc}
1897 */
1898
1899 class wxDataViewListStore: public wxDataViewIndexListModel
1900 {
1901 public:
1902 /**
1903 Constructor
1904 */
1905 wxDataViewListStore();
1906
1907 /**
1908 Destructor
1909 */
1910 ~wxDataViewListStore();
1911
1912 /**
1913 Prepends a data column.
1914
1915 @a variantype indicates the type of values store in the column.
1916
1917 This does not automatically fill in any (default) values in
1918 rows which exist in the store already.
1919 */
1920 void PrependColumn( const wxString &varianttype );
1921
1922 /**
1923 Inserts a data column before @a pos.
1924
1925 @a variantype indicates the type of values store in the column.
1926
1927 This does not automatically fill in any (default) values in
1928 rows which exist in the store already.
1929 */
1930 void InsertColumn( unsigned int pos, const wxString &varianttype );
1931
1932 /**
1933 Apppends a data column.
1934
1935 @a variantype indicates the type of values store in the column.
1936
1937 This does not automatically fill in any (default) values in
1938 rows which exist in the store already.
1939 */
1940 void AppendColumn( const wxString &varianttype );
1941
1942 /**
1943 Appends an item (=row) and fills it with @a values.
1944
1945 The values must match the values specifies in the column
1946 in number and type. No (default) values are filled in
1947 automatically.
1948 */
1949 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
1950
1951 /**
1952 Prepends an item (=row) and fills it with @a values.
1953
1954 The values must match the values specifies in the column
1955 in number and type. No (default) values are filled in
1956 automatically.
1957 */
1958 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
1959
1960 /**
1961 Inserts an item (=row) and fills it with @a values.
1962
1963 The values must match the values specifies in the column
1964 in number and type. No (default) values are filled in
1965 automatically.
1966 */
1967 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
1968
1969 /**
1970 Delete the item (=row) at position @a pos.
1971 */
1972 void DeleteItem( unsigned pos );
1973
1974 /**
1975 Delete all item (=all rows) in the store.
1976 */
1977 void DeleteAllItems();
1978
1979 /**
1980 Overriden from wxDataViewModel
1981 */
1982 virtual unsigned int GetColumnCount() const;
1983
1984 /**
1985 Overriden from wxDataViewModel
1986 */
1987 virtual wxString GetColumnType( unsigned int col ) const;
1988
1989 /**
1990 Overriden from wxDataViewIndexListModel
1991 */
1992 virtual void GetValueByRow( wxVariant &value,
1993 unsigned int row, unsigned int col ) const;
1994
1995 /**
1996 Overriden from wxDataViewIndexListModel
1997 */
1998 virtual bool SetValueByRow( const wxVariant &value,
1999 unsigned int row, unsigned int col );
2000 };
2001
2002
2003 /**
2004 @class wxDataViewTreeStore
2005
2006 wxDataViewTreeStore is a specialised wxDataViewModel for stroing simple
2007 trees very much like wxTreeCtrl does and it offers a similar API.
2008
2009 This class actually stores the entire tree and the values (therefore its name)
2010 and implements all virtual methods from the base class so it can be used directly
2011 without having to derive any class from it, but it is mostly used from within
2012 wxDataViewTreeCtrl.
2013
2014 @library{wxadv}
2015 @category{dvc}
2016 */
2017 class wxDataViewTreeStore : public wxDataViewModel
2018 {
2019 public:
2020 /**
2021 Constructor. Creates the invisible root node internally.
2022 */
2023 wxDataViewTreeStore();
2024
2025 /**
2026 Destructor.
2027 */
2028 virtual ~wxDataViewTreeStore();
2029
2030 /**
2031 Append a container.
2032 */
2033 wxDataViewItem AppendContainer(const wxDataViewItem& parent,
2034 const wxString& text,
2035 const wxIcon& icon = wxNullIcon,
2036 const wxIcon& expanded = wxNullIcon,
2037 wxClientData* data = NULL);
2038
2039 /**
2040 Append an item.
2041 */
2042 wxDataViewItem AppendItem(const wxDataViewItem& parent,
2043 const wxString& text,
2044 const wxIcon& icon = wxNullIcon,
2045 wxClientData* data = NULL);
2046
2047 /**
2048 Delete all item in the model.
2049 */
2050 void DeleteAllItems();
2051
2052 /**
2053 Delete all children of the item, but not the item itself.
2054 */
2055 void DeleteChildren(const wxDataViewItem& item);
2056
2057 /**
2058 Delete this item.
2059 */
2060 void DeleteItem(const wxDataViewItem& item);
2061
2062 /**
2063 Return the number of children of item.
2064 */
2065 int GetChildCount(const wxDataViewItem& parent) const;
2066
2067 /**
2068 Returns the client data asoociated with the item.
2069 */
2070 wxClientData* GetItemData(const wxDataViewItem& item) const;
2071
2072 /**
2073 Returns the icon to display in expanded containers.
2074 */
2075 const wxIcon& GetItemExpandedIcon(const wxDataViewItem& item) const;
2076
2077 /**
2078 Returns the icon of the item.
2079 */
2080 const wxIcon& GetItemIcon(const wxDataViewItem& item) const;
2081
2082 /**
2083 Returns the text of the item.
2084 */
2085 wxString GetItemText(const wxDataViewItem& item) const;
2086
2087 /**
2088 Returns the nth child item of item.
2089 */
2090 wxDataViewItem GetNthChild(const wxDataViewItem& parent,
2091 unsigned int pos) const;
2092
2093 /**
2094 Inserts a container after @a previous.
2095 */
2096 wxDataViewItem InsertContainer(const wxDataViewItem& parent,
2097 const wxDataViewItem& previous,
2098 const wxString& text,
2099 const wxIcon& icon = wxNullIcon,
2100 const wxIcon& expanded = wxNullIcon,
2101 wxClientData* data = NULL);
2102
2103 /**
2104 Inserts an item after @a previous.
2105 */
2106 wxDataViewItem InsertItem(const wxDataViewItem& parent,
2107 const wxDataViewItem& previous,
2108 const wxString& text,
2109 const wxIcon& icon = wxNullIcon,
2110 wxClientData* data = NULL);
2111
2112 /**
2113 Inserts a container before the first child item or @a parent.
2114 */
2115 wxDataViewItem PrependContainer(const wxDataViewItem& parent,
2116 const wxString& text,
2117 const wxIcon& icon = wxNullIcon,
2118 const wxIcon& expanded = wxNullIcon,
2119 wxClientData* data = NULL);
2120
2121 /**
2122 Inserts an item before the first child item or @a parent.
2123 */
2124 wxDataViewItem PrependItem(const wxDataViewItem& parent,
2125 const wxString& text,
2126 const wxIcon& icon = wxNullIcon,
2127 wxClientData* data = NULL);
2128
2129 /**
2130 Sets the client data associated with the item.
2131 */
2132 void SetItemData(const wxDataViewItem& item, wxClientData* data);
2133
2134 /**
2135 Sets the expanded icon for the item.
2136 */
2137 void SetItemExpandedIcon(const wxDataViewItem& item,
2138 const wxIcon& icon);
2139
2140 /**
2141 Sets the icon for the item.
2142 */
2143 void SetItemIcon(const wxDataViewItem& item, const wxIcon& icon);
2144 };
2145
2146
2147 /**
2148 @class wxDataViewIconText
2149
2150 wxDataViewIconText is used by wxDataViewIconTextRenderer for data transfer.
2151 This class can be converted to and from a wxVariant.
2152
2153 @library{wxadv}
2154 @category{dvc}
2155 */
2156 class wxDataViewIconText : public wxObject
2157 {
2158 public:
2159 //@{
2160 /**
2161 Constructor.
2162 */
2163 wxDataViewIconText(const wxString& text = wxEmptyString,
2164 const wxIcon& icon = wxNullIcon);
2165 wxDataViewIconText(const wxDataViewIconText& other);
2166 //@}
2167
2168 /**
2169 Gets the icon.
2170 */
2171 const wxIcon& GetIcon() const;
2172
2173 /**
2174 Gets the text.
2175 */
2176 wxString GetText() const;
2177
2178 /**
2179 Set the icon.
2180 */
2181 void SetIcon(const wxIcon& icon);
2182
2183 /**
2184 Set the text.
2185 */
2186 void SetText(const wxString& text);
2187 };
2188
2189
2190
2191 /**
2192 @class wxDataViewEvent
2193
2194 This is the event class for the wxDataViewCtrl notifications.
2195
2196 @library{wxadv}
2197 @category{events,dvc}
2198 */
2199 class wxDataViewEvent : public wxNotifyEvent
2200 {
2201 public:
2202 /**
2203 Constructor. Typically used by wxWidgets internals only.
2204 */
2205 wxDataViewEvent(wxEventType commandType = wxEVT_NULL,
2206 int winid = 0);
2207
2208 /**
2209 Returns the position of the column in the control or -1
2210 if no column field was set by the event emitter.
2211 */
2212 int GetColumn() const;
2213
2214 /**
2215 Returns a pointer to the wxDataViewColumn from which
2216 the event was emitted or @NULL.
2217 */
2218 wxDataViewColumn* GetDataViewColumn() const;
2219
2220 /**
2221 Returns the wxDataViewModel associated with the event.
2222 */
2223 wxDataViewModel* GetModel() const;
2224
2225 /**
2226 Returns a the position of a context menu event in screen coordinates.
2227 */
2228 wxPoint GetPosition() const;
2229
2230 /**
2231 Returns a reference to a value.
2232 */
2233 const wxVariant& GetValue() const;
2234
2235 /**
2236 Sets the column index associated with this event.
2237 */
2238 void SetColumn(int col);
2239
2240 /**
2241 For wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only.
2242 */
2243 void SetDataViewColumn(wxDataViewColumn* col);
2244
2245 /**
2246 Sets the dataview model associated with this event.
2247 */
2248 void SetModel(wxDataViewModel* model);
2249
2250 /**
2251 Sets the value associated with this event.
2252 */
2253 void SetValue(const wxVariant& value);
2254
2255 /**
2256 Set wxDataObject for Drag'n'drop data transfer.
2257 */
2258 void SetDataObject( wxDataObject *obj );
2259
2260 /**
2261 Gets associated wxDataObject for Drag'n'drop data transfer.
2262 */
2263 wxDataObject *GetDataObject();
2264 };
2265