Merge in from trunk r64802 - r68625
[wxWidgets.git] / include / wx / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dataview.h
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by: Bo Yang
6 // Created: 08.01.06
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DATAVIEWCTRL
18
19 #include "wx/textctrl.h"
20 #include "wx/headercol.h"
21 #include "wx/variant.h"
22 #include "wx/dynarray.h"
23 #include "wx/icon.h"
24 #include "wx/weakref.h"
25 #include "wx/vector.h"
26 #include "wx/dataobj.h"
27
28 class WXDLLIMPEXP_FWD_CORE wxImageList;
29
30 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
31 // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
32 #define wxHAS_GENERIC_DATAVIEWCTRL
33 #endif
34
35 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
36 // this symbol doesn't follow the convention for wxUSE_XXX symbols which
37 // are normally always defined as either 0 or 1, so its use is deprecated
38 // and it only exists for backwards compatibility, don't use it any more
39 // and use wxHAS_GENERIC_DATAVIEWCTRL instead
40 #define wxUSE_GENERICDATAVIEWCTRL
41 #endif
42
43 // ----------------------------------------------------------------------------
44 // wxDataViewCtrl globals
45 // ----------------------------------------------------------------------------
46
47 class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
48 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
49 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
50 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
51 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
52 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
53
54 extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[];
55
56 // ----------------------------------------------------------------------------
57 // wxDataViewCtrl flags
58 // ----------------------------------------------------------------------------
59
60 // size of a wxDataViewRenderer without contents:
61 #define wxDVC_DEFAULT_RENDERER_SIZE 20
62
63 // the default width of new (text) columns:
64 #define wxDVC_DEFAULT_WIDTH 80
65
66 // the default width of new toggle columns:
67 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
68
69 // the default minimal width of the columns:
70 #define wxDVC_DEFAULT_MINWIDTH 30
71
72 // The default alignment of wxDataViewRenderers is to take
73 // the alignment from the column it owns.
74 #define wxDVR_DEFAULT_ALIGNMENT -1
75
76
77 // ---------------------------------------------------------
78 // wxDataViewItem
79 // ---------------------------------------------------------
80
81 class WXDLLIMPEXP_ADV wxDataViewItem
82 {
83 public:
84 wxDataViewItem() : m_id(NULL) {}
85 wxDataViewItem(const wxDataViewItem &item) : m_id(item.m_id) {}
86
87 wxEXPLICIT wxDataViewItem(void* id) : m_id(id) {}
88
89 bool IsOk() const { return m_id != NULL; }
90 void* GetID() const { return m_id; }
91 operator const void* () const { return m_id; }
92
93 private:
94 void* m_id;
95 };
96
97 inline
98 bool operator==(const wxDataViewItem& left, const wxDataViewItem& right)
99 {
100 return left.GetID() == right.GetID();
101 }
102
103 inline
104 bool operator!=(const wxDataViewItem& left, const wxDataViewItem& right)
105 {
106 return !(left == right);
107 }
108
109 WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
110
111 // ---------------------------------------------------------
112 // wxDataViewModelNotifier
113 // ---------------------------------------------------------
114
115 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
116 {
117 public:
118 wxDataViewModelNotifier() { m_owner = NULL; }
119 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
120
121 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
122 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
123 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
124 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
125 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
126 virtual bool ItemsChanged( const wxDataViewItemArray &items );
127 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
128 virtual bool Cleared() = 0;
129
130 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
131 virtual bool BeforeReset() { return true; }
132 virtual bool AfterReset() { return Cleared(); }
133
134 virtual void Resort() = 0;
135
136 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
137 wxDataViewModel *GetOwner() const { return m_owner; }
138
139 private:
140 wxDataViewModel *m_owner;
141 };
142
143
144
145 // ----------------------------------------------------------------------------
146 // wxDataViewItemAttr: a structure containing the visual attributes of an item
147 // ----------------------------------------------------------------------------
148
149 // TODO: this should be renamed to wxItemAttr or something general like this
150
151 class WXDLLIMPEXP_ADV wxDataViewItemAttr
152 {
153 public:
154 // ctors
155 wxDataViewItemAttr()
156 {
157 m_bold = false;
158 m_italic = false;
159 }
160
161 // setters
162 void SetColour(const wxColour& colour) { m_colour = colour; }
163 void SetBold( bool set ) { m_bold = set; }
164 void SetItalic( bool set ) { m_italic = set; }
165
166 // accessors
167 bool HasColour() const { return m_colour.IsOk(); }
168 const wxColour& GetColour() const { return m_colour; }
169
170 bool HasFont() const { return m_bold || m_italic; }
171 bool GetBold() const { return m_bold; }
172 bool GetItalic() const { return m_italic; }
173
174 bool IsDefault() const { return !(HasColour() || HasFont()); }
175
176 // Return the font based on the given one with this attribute applied to it.
177 wxFont GetEffectiveFont(const wxFont& font) const;
178
179 private:
180 wxColour m_colour;
181 bool m_bold;
182 bool m_italic;
183 };
184
185
186 // ---------------------------------------------------------
187 // wxDataViewModel
188 // ---------------------------------------------------------
189
190 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
191 class WXDLLIMPEXP_ADV);
192
193 class WXDLLIMPEXP_ADV wxDataViewModel: public wxRefCounter
194 {
195 public:
196 wxDataViewModel();
197
198 virtual unsigned int GetColumnCount() const = 0;
199
200 // return type as reported by wxVariant
201 virtual wxString GetColumnType( unsigned int col ) const = 0;
202
203 // get value into a wxVariant
204 virtual void GetValue( wxVariant &variant,
205 const wxDataViewItem &item, unsigned int col ) const = 0;
206
207 // return true if the given item has a value to display in the given
208 // column: this is always true except for container items which by default
209 // only show their label in the first column (but see HasContainerColumns())
210 bool HasValue(const wxDataViewItem& item, unsigned col) const
211 {
212 return col == 0 || !IsContainer(item) || HasContainerColumns(item);
213 }
214
215 // usually ValueChanged() should be called after changing the value in the
216 // model to update the control, ChangeValue() does it on its own while
217 // SetValue() does not -- so while you will override SetValue(), you should
218 // be usually calling ChangeValue()
219 virtual bool SetValue(const wxVariant &variant,
220 const wxDataViewItem &item,
221 unsigned int col) = 0;
222
223 bool ChangeValue(const wxVariant& variant,
224 const wxDataViewItem& item,
225 unsigned int col)
226 {
227 return SetValue(variant, item, col) && ValueChanged(item, col);
228 }
229
230 // Get text attribute, return false of default attributes should be used
231 virtual bool GetAttr(const wxDataViewItem &WXUNUSED(item),
232 unsigned int WXUNUSED(col),
233 wxDataViewItemAttr &WXUNUSED(attr)) const
234 {
235 return false;
236 }
237
238 // Override this if you want to disable specific items
239 virtual bool IsEnabled(const wxDataViewItem &WXUNUSED(item),
240 unsigned int WXUNUSED(col)) const
241 {
242 return true;
243 }
244
245 // define hierachy
246 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
247 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
248 // Is the container just a header or an item with all columns
249 virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const
250 { return false; }
251 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0;
252
253 // delegated notifiers
254 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
255 bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
256 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
257 bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
258 bool ItemChanged( const wxDataViewItem &item );
259 bool ItemsChanged( const wxDataViewItemArray &items );
260 bool ValueChanged( const wxDataViewItem &item, unsigned int col );
261 bool Cleared();
262
263 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
264 bool BeforeReset();
265 bool AfterReset();
266
267
268 // delegated action
269 virtual void Resort();
270
271 void AddNotifier( wxDataViewModelNotifier *notifier );
272 void RemoveNotifier( wxDataViewModelNotifier *notifier );
273
274 // default compare function
275 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
276 unsigned int column, bool ascending ) const;
277 virtual bool HasDefaultCompare() const { return false; }
278
279 // internal
280 virtual bool IsListModel() const { return false; }
281 virtual bool IsVirtualListModel() const { return false; }
282
283 protected:
284 // the user should not delete this class directly: he should use DecRef() instead!
285 virtual ~wxDataViewModel() { }
286
287 wxDataViewModelNotifiers m_notifiers;
288 };
289
290 // ----------------------------------------------------------------------------
291 // wxDataViewListModel: a model of a list, i.e. flat data structure without any
292 // branches/containers, used as base class by wxDataViewIndexListModel and
293 // wxDataViewVirtualListModel
294 // ----------------------------------------------------------------------------
295
296 class WXDLLIMPEXP_ADV wxDataViewListModel : public wxDataViewModel
297 {
298 public:
299 // derived classes should override these methods instead of
300 // {Get,Set}Value() and GetAttr() inherited from the base class
301
302 virtual void GetValueByRow(wxVariant &variant,
303 unsigned row, unsigned col) const = 0;
304
305 virtual bool SetValueByRow(const wxVariant &variant,
306 unsigned row, unsigned col) = 0;
307
308 virtual bool
309 GetAttrByRow(unsigned WXUNUSED(row), unsigned WXUNUSED(col),
310 wxDataViewItemAttr &WXUNUSED(attr)) const
311 {
312 return false;
313 }
314
315 virtual bool IsEnabledByRow(unsigned int WXUNUSED(row),
316 unsigned int WXUNUSED(col)) const
317 {
318 return true;
319 }
320
321
322 // helper methods provided by list models only
323 virtual unsigned GetRow( const wxDataViewItem &item ) const = 0;
324
325 // returns the number of rows
326 virtual unsigned int GetCount() const = 0;
327
328 // implement some base class pure virtual directly
329 virtual wxDataViewItem
330 GetParent( const wxDataViewItem & WXUNUSED(item) ) const
331 {
332 // items never have valid parent in this model
333 return wxDataViewItem();
334 }
335
336 virtual bool IsContainer( const wxDataViewItem &item ) const
337 {
338 // only the invisible (and invalid) root item has children
339 return !item.IsOk();
340 }
341
342 // and implement some others by forwarding them to our own ones
343 virtual void GetValue( wxVariant &variant,
344 const wxDataViewItem &item, unsigned int col ) const
345 {
346 GetValueByRow(variant, GetRow(item), col);
347 }
348
349 virtual bool SetValue( const wxVariant &variant,
350 const wxDataViewItem &item, unsigned int col )
351 {
352 return SetValueByRow( variant, GetRow(item), col );
353 }
354
355 virtual bool GetAttr(const wxDataViewItem &item, unsigned int col,
356 wxDataViewItemAttr &attr) const
357 {
358 return GetAttrByRow( GetRow(item), col, attr );
359 }
360
361 virtual bool IsEnabled(const wxDataViewItem &item, unsigned int col) const
362 {
363 return IsEnabledByRow( GetRow(item), col );
364 }
365
366
367 virtual bool IsListModel() const { return true; }
368 };
369
370 // ---------------------------------------------------------
371 // wxDataViewIndexListModel
372 // ---------------------------------------------------------
373
374 class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewListModel
375 {
376 public:
377 wxDataViewIndexListModel( unsigned int initial_size = 0 );
378
379 void RowPrepended();
380 void RowInserted( unsigned int before );
381 void RowAppended();
382 void RowDeleted( unsigned int row );
383 void RowsDeleted( const wxArrayInt &rows );
384 void RowChanged( unsigned int row );
385 void RowValueChanged( unsigned int row, unsigned int col );
386 void Reset( unsigned int new_size );
387
388 // convert to/from row/wxDataViewItem
389
390 virtual unsigned GetRow( const wxDataViewItem &item ) const;
391 wxDataViewItem GetItem( unsigned int row ) const;
392
393 // compare based on index
394
395 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
396 unsigned int column, bool ascending ) const;
397 virtual bool HasDefaultCompare() const;
398
399 // implement base methods
400 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
401
402 unsigned int GetCount() const { return m_hash.GetCount(); }
403
404 private:
405 wxDataViewItemArray m_hash;
406 unsigned int m_nextFreeID;
407 bool m_ordered;
408 };
409
410 // ---------------------------------------------------------
411 // wxDataViewVirtualListModel
412 // ---------------------------------------------------------
413
414 #ifdef __WXMAC__
415 // better than nothing
416 typedef wxDataViewIndexListModel wxDataViewVirtualListModel;
417 #else
418
419 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewListModel
420 {
421 public:
422 wxDataViewVirtualListModel( unsigned int initial_size = 0 );
423
424 void RowPrepended();
425 void RowInserted( unsigned int before );
426 void RowAppended();
427 void RowDeleted( unsigned int row );
428 void RowsDeleted( const wxArrayInt &rows );
429 void RowChanged( unsigned int row );
430 void RowValueChanged( unsigned int row, unsigned int col );
431 void Reset( unsigned int new_size );
432
433 // convert to/from row/wxDataViewItem
434
435 virtual unsigned GetRow( const wxDataViewItem &item ) const;
436 wxDataViewItem GetItem( unsigned int row ) const;
437
438 // compare based on index
439
440 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
441 unsigned int column, bool ascending ) const;
442 virtual bool HasDefaultCompare() const;
443
444 // implement base methods
445 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
446
447 unsigned int GetCount() const { return m_size; }
448
449 // internal
450 virtual bool IsVirtualListModel() const { return true; }
451
452 private:
453 unsigned int m_size;
454 bool m_ordered;
455 };
456 #endif
457
458 // ----------------------------------------------------------------------------
459 // wxDataViewRenderer and related classes
460 // ----------------------------------------------------------------------------
461
462 #include "wx/dvrenderers.h"
463
464 // ---------------------------------------------------------
465 // wxDataViewColumnBase
466 // ---------------------------------------------------------
467
468 // for compatibility only, do not use
469 enum wxDataViewColumnFlags
470 {
471 wxDATAVIEW_COL_RESIZABLE = wxCOL_RESIZABLE,
472 wxDATAVIEW_COL_SORTABLE = wxCOL_SORTABLE,
473 wxDATAVIEW_COL_REORDERABLE = wxCOL_REORDERABLE,
474 wxDATAVIEW_COL_HIDDEN = wxCOL_HIDDEN
475 };
476
477 class WXDLLIMPEXP_ADV wxDataViewColumnBase : public wxSettableHeaderColumn
478 {
479 public:
480 // ctor for the text columns: takes ownership of renderer
481 wxDataViewColumnBase(wxDataViewRenderer *renderer,
482 unsigned int model_column)
483 {
484 Init(renderer, model_column);
485 }
486
487 // ctor for the bitmap columns
488 wxDataViewColumnBase(const wxBitmap& bitmap,
489 wxDataViewRenderer *renderer,
490 unsigned int model_column)
491 : m_bitmap(bitmap)
492 {
493 Init(renderer, model_column);
494 }
495
496 virtual ~wxDataViewColumnBase();
497
498 // setters:
499 virtual void SetOwner( wxDataViewCtrl *owner )
500 { m_owner = owner; }
501
502 // getters:
503 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
504 wxDataViewCtrl *GetOwner() const { return m_owner; }
505 wxDataViewRenderer* GetRenderer() const { return m_renderer; }
506
507 // implement some of base class pure virtuals (the rest is port-dependent
508 // and done differently in generic and native versions)
509 virtual void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
510 virtual wxBitmap GetBitmap() const { return m_bitmap; }
511
512 protected:
513 wxDataViewRenderer *m_renderer;
514 int m_model_column;
515 wxBitmap m_bitmap;
516 wxDataViewCtrl *m_owner;
517
518 private:
519 // common part of all ctors
520 void Init(wxDataViewRenderer *renderer, unsigned int model_column);
521 };
522
523 // ---------------------------------------------------------
524 // wxDataViewCtrlBase
525 // ---------------------------------------------------------
526
527 #define wxDV_SINGLE 0x0000 // for convenience
528 #define wxDV_MULTIPLE 0x0001 // can select multiple items
529
530 #define wxDV_NO_HEADER 0x0002 // column titles not visible
531 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
532 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
533
534 #define wxDV_ROW_LINES 0x0010 // alternating colour in rows
535 #define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height
536
537 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
538 {
539 public:
540 wxDataViewCtrlBase();
541 virtual ~wxDataViewCtrlBase();
542
543 // model
544 // -----
545
546 virtual bool AssociateModel( wxDataViewModel *model );
547 wxDataViewModel* GetModel();
548 const wxDataViewModel* GetModel() const;
549
550
551 // column management
552 // -----------------
553
554 wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
555 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
556 wxAlignment align = wxALIGN_NOT,
557 int flags = wxDATAVIEW_COL_RESIZABLE );
558 wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column,
559 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
560 wxAlignment align = wxALIGN_NOT,
561 int flags = wxDATAVIEW_COL_RESIZABLE );
562 wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column,
563 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
564 wxAlignment align = wxALIGN_CENTER,
565 int flags = wxDATAVIEW_COL_RESIZABLE );
566 wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column,
567 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
568 wxAlignment align = wxALIGN_CENTER,
569 int flags = wxDATAVIEW_COL_RESIZABLE );
570 wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column,
571 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
572 wxAlignment align = wxALIGN_NOT,
573 int flags = wxDATAVIEW_COL_RESIZABLE );
574 wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column,
575 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
576 wxAlignment align = wxALIGN_CENTER,
577 int flags = wxDATAVIEW_COL_RESIZABLE );
578 wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column,
579 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
580 wxAlignment align = wxALIGN_NOT,
581 int flags = wxDATAVIEW_COL_RESIZABLE );
582 wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
583 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
584 wxAlignment align = wxALIGN_NOT,
585 int flags = wxDATAVIEW_COL_RESIZABLE );
586 wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
587 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
588 wxAlignment align = wxALIGN_CENTER,
589 int flags = wxDATAVIEW_COL_RESIZABLE );
590 wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
591 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
592 wxAlignment align = wxALIGN_CENTER,
593 int flags = wxDATAVIEW_COL_RESIZABLE );
594 wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column,
595 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
596 wxAlignment align = wxALIGN_NOT,
597 int flags = wxDATAVIEW_COL_RESIZABLE );
598 wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
599 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
600 wxAlignment align = wxALIGN_CENTER,
601 int flags = wxDATAVIEW_COL_RESIZABLE );
602
603 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
604 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
605 wxAlignment align = wxALIGN_NOT,
606 int flags = wxDATAVIEW_COL_RESIZABLE );
607 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
608 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
609 wxAlignment align = wxALIGN_NOT,
610 int flags = wxDATAVIEW_COL_RESIZABLE );
611 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
612 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
613 wxAlignment align = wxALIGN_CENTER,
614 int flags = wxDATAVIEW_COL_RESIZABLE );
615 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
616 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
617 wxAlignment align = wxALIGN_CENTER,
618 int flags = wxDATAVIEW_COL_RESIZABLE );
619 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
620 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
621 wxAlignment align = wxALIGN_NOT,
622 int flags = wxDATAVIEW_COL_RESIZABLE );
623 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
624 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
625 wxAlignment align = wxALIGN_CENTER,
626 int flags = wxDATAVIEW_COL_RESIZABLE );
627 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
628 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
629 wxAlignment align = wxALIGN_NOT,
630 int flags = wxDATAVIEW_COL_RESIZABLE );
631 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
632 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
633 wxAlignment align = wxALIGN_NOT,
634 int flags = wxDATAVIEW_COL_RESIZABLE );
635 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
636 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
637 wxAlignment align = wxALIGN_CENTER,
638 int flags = wxDATAVIEW_COL_RESIZABLE );
639 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
640 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
641 wxAlignment align = wxALIGN_CENTER,
642 int flags = wxDATAVIEW_COL_RESIZABLE );
643 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
644 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
645 wxAlignment align = wxALIGN_NOT,
646 int flags = wxDATAVIEW_COL_RESIZABLE );
647 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
648 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
649 wxAlignment align = wxALIGN_CENTER,
650 int flags = wxDATAVIEW_COL_RESIZABLE );
651
652 virtual bool PrependColumn( wxDataViewColumn *col );
653 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
654 virtual bool AppendColumn( wxDataViewColumn *col );
655
656 virtual unsigned int GetColumnCount() const = 0;
657 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
658 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
659
660 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
661 virtual bool ClearColumns() = 0;
662
663 void SetExpanderColumn( wxDataViewColumn *col )
664 { m_expander_column = col ; DoSetExpanderColumn(); }
665 wxDataViewColumn *GetExpanderColumn() const
666 { return m_expander_column; }
667
668 virtual wxDataViewColumn *GetSortingColumn() const = 0;
669
670
671 // items management
672 // ----------------
673
674 void SetIndent( int indent )
675 { m_indent = indent ; DoSetIndent(); }
676 int GetIndent() const
677 { return m_indent; }
678
679 // Current item is the one used by the keyboard navigation, it is the same
680 // as the (unique) selected item in single selection mode so these
681 // functions are mostly useful for controls with wxDV_MULTIPLE style.
682 wxDataViewItem GetCurrentItem() const;
683 void SetCurrentItem(const wxDataViewItem& item);
684
685 virtual wxDataViewItem GetSelection() const = 0;
686 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
687 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
688 virtual void Select( const wxDataViewItem & item ) = 0;
689 virtual void Unselect( const wxDataViewItem & item ) = 0;
690 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
691
692 virtual void SelectAll() = 0;
693 virtual void UnselectAll() = 0;
694
695 virtual void Expand( const wxDataViewItem & item ) = 0;
696 virtual void ExpandAncestors( const wxDataViewItem & item );
697 virtual void Collapse( const wxDataViewItem & item ) = 0;
698 virtual bool IsExpanded( const wxDataViewItem & item ) const = 0;
699
700 virtual void EnsureVisible( const wxDataViewItem & item,
701 const wxDataViewColumn *column = NULL ) = 0;
702 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
703 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
704
705 virtual bool SetRowHeight( int WXUNUSED(rowHeight) ) { return false; }
706
707 virtual void StartEditor( const wxDataViewItem & WXUNUSED(item),
708 unsigned int WXUNUSED(column) )
709 { }
710
711 #if wxUSE_DRAG_AND_DROP
712 virtual bool EnableDragSource(const wxDataFormat& WXUNUSED(format))
713 { return false; }
714 virtual bool EnableDropTarget(const wxDataFormat& WXUNUSED(format))
715 { return false; }
716 #endif // wxUSE_DRAG_AND_DROP
717
718 // define control visual attributes
719 // --------------------------------
720
721 virtual wxVisualAttributes GetDefaultAttributes() const
722 {
723 return GetClassDefaultAttributes(GetWindowVariant());
724 }
725
726 static wxVisualAttributes
727 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
728 {
729 return wxControl::GetCompositeControlsDefaultAttributes(variant);
730 }
731
732 protected:
733 virtual void DoSetExpanderColumn() = 0 ;
734 virtual void DoSetIndent() = 0;
735
736 private:
737 // Implementation of the public Set/GetCurrentItem() methods which are only
738 // called in multi selection case (for single selection controls their
739 // implementation is trivial and is done in the base class itself).
740 virtual wxDataViewItem DoGetCurrentItem() const = 0;
741 virtual void DoSetCurrentItem(const wxDataViewItem& item) = 0;
742
743 wxDataViewModel *m_model;
744 wxDataViewColumn *m_expander_column;
745 int m_indent ;
746
747 protected:
748 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
749 };
750
751 // ----------------------------------------------------------------------------
752 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
753 // ----------------------------------------------------------------------------
754
755 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
756 {
757 public:
758 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
759 : wxNotifyEvent(commandType, winid),
760 m_item(0),
761 m_col(-1),
762 m_model(NULL),
763 m_value(wxNullVariant),
764 m_column(NULL),
765 m_pos(-1,-1),
766 m_cacheFrom(0),
767 m_cacheTo(0),
768 m_editCancelled(false)
769 #if wxUSE_DRAG_AND_DROP
770 , m_dataObject(NULL),
771 m_dataBuffer(NULL),
772 m_dataSize(0)
773 #endif
774 { }
775
776 wxDataViewEvent(const wxDataViewEvent& event)
777 : wxNotifyEvent(event),
778 m_item(event.m_item),
779 m_col(event.m_col),
780 m_model(event.m_model),
781 m_value(event.m_value),
782 m_column(event.m_column),
783 m_pos(event.m_pos),
784 m_cacheFrom(event.m_cacheFrom),
785 m_cacheTo(event.m_cacheTo),
786 m_editCancelled(event.m_editCancelled)
787 #if wxUSE_DRAG_AND_DROP
788 , m_dataObject(event.m_dataObject),
789 m_dataFormat(event.m_dataFormat),
790 m_dataBuffer(event.m_dataBuffer),
791 m_dataSize(event.m_dataSize)
792 #endif
793 { }
794
795 wxDataViewItem GetItem() const { return m_item; }
796 void SetItem( const wxDataViewItem &item ) { m_item = item; }
797
798 int GetColumn() const { return m_col; }
799 void SetColumn( int col ) { m_col = col; }
800
801 wxDataViewModel* GetModel() const { return m_model; }
802 void SetModel( wxDataViewModel *model ) { m_model = model; }
803
804 const wxVariant &GetValue() const { return m_value; }
805 void SetValue( const wxVariant &value ) { m_value = value; }
806
807 // for wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE only
808 bool IsEditCancelled() const { return m_editCancelled; }
809 void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
810
811 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
812 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
813 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
814
815 // for wxEVT_DATAVIEW_CONTEXT_MENU only
816 wxPoint GetPosition() const { return m_pos; }
817 void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; }
818
819 // For wxEVT_COMMAND_DATAVIEW_CACHE_HINT
820 int GetCacheFrom() const { return m_cacheFrom; }
821 int GetCacheTo() const { return m_cacheTo; }
822 void SetCache(int from, int to) { m_cacheFrom = from; m_cacheTo = to; }
823
824
825 #if wxUSE_DRAG_AND_DROP
826 // For drag operations
827 void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; }
828 wxDataObject *GetDataObject() const { return m_dataObject; }
829
830 // For drop operations
831 void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; }
832 wxDataFormat GetDataFormat() const { return m_dataFormat; }
833 void SetDataSize( size_t size ) { m_dataSize = size; }
834 size_t GetDataSize() const { return m_dataSize; }
835 void SetDataBuffer( void* buf ) { m_dataBuffer = buf;}
836 void *GetDataBuffer() const { return m_dataBuffer; }
837 #endif // wxUSE_DRAG_AND_DROP
838
839 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
840
841 protected:
842 wxDataViewItem m_item;
843 int m_col;
844 wxDataViewModel *m_model;
845 wxVariant m_value;
846 wxDataViewColumn *m_column;
847 wxPoint m_pos;
848 int m_cacheFrom;
849 int m_cacheTo;
850 bool m_editCancelled;
851
852 #if wxUSE_DRAG_AND_DROP
853 wxDataObject *m_dataObject;
854
855 wxDataFormat m_dataFormat;
856 void* m_dataBuffer;
857 size_t m_dataSize;
858 #endif // wxUSE_DRAG_AND_DROP
859
860 private:
861 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
862 };
863
864 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
865
866 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
867 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
868 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
869 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
870 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
871 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
872 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
873 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
874 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
875
876 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
877
878 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
879 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
880 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
881 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
882
883 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent );
884
885 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
886 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
887 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
888
889 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
890
891 #define wxDataViewEventHandler(func) \
892 wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func)
893
894 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
895 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
896
897 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
898
899 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
900 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
901 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
902 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
903 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
904 #define EVT_DATAVIEW_ITEM_START_EDITING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_START_EDITING, id, fn)
905 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
906 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
907 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
908
909 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
910
911 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
912 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
913 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
914 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
915 #define EVT_DATAVIEW_CACHE_HINT(id, fn) wx__DECLARE_DATAVIEWEVT(CACHE_HINT, id, fn)
916
917 #define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn)
918 #define EVT_DATAVIEW_ITEM_DROP_POSSIBLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP_POSSIBLE, id, fn)
919 #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
920
921 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
922 #include "wx/generic/dataview.h"
923 #elif defined(__WXGTK20__)
924 #include "wx/gtk/dataview.h"
925 #elif defined(__WXMAC__)
926 #include "wx/osx/dataview.h"
927 #else
928 #error "unknown native wxDataViewCtrl implementation"
929 #endif
930
931 //-----------------------------------------------------------------------------
932 // wxDataViewListStore
933 //-----------------------------------------------------------------------------
934
935 class WXDLLIMPEXP_ADV wxDataViewListStoreLine
936 {
937 public:
938 wxDataViewListStoreLine( wxClientData *data = NULL )
939 {
940 m_data = data;
941 }
942 virtual ~wxDataViewListStoreLine()
943 {
944 delete m_data;
945 }
946
947 void SetData( wxClientData *data )
948 { if (m_data) delete m_data; m_data = data; }
949 wxClientData *GetData() const
950 { return m_data; }
951
952 wxVector<wxVariant> m_values;
953
954 private:
955 wxClientData *m_data;
956 };
957
958
959 class WXDLLIMPEXP_ADV wxDataViewListStore: public wxDataViewIndexListModel
960 {
961 public:
962 wxDataViewListStore();
963 ~wxDataViewListStore();
964
965 void PrependColumn( const wxString &varianttype );
966 void InsertColumn( unsigned int pos, const wxString &varianttype );
967 void AppendColumn( const wxString &varianttype );
968
969 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
970 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
971 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
972 void DeleteItem( unsigned int pos );
973 void DeleteAllItems();
974
975 // override base virtuals
976
977 virtual unsigned int GetColumnCount() const;
978
979 virtual wxString GetColumnType( unsigned int col ) const;
980
981 virtual void GetValueByRow( wxVariant &value,
982 unsigned int row, unsigned int col ) const;
983
984 virtual bool SetValueByRow( const wxVariant &value,
985 unsigned int row, unsigned int col );
986
987
988 public:
989 wxVector<wxDataViewListStoreLine*> m_data;
990 wxArrayString m_cols;
991 };
992
993 //-----------------------------------------------------------------------------
994
995 class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl
996 {
997 public:
998 wxDataViewListCtrl();
999 wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
1000 const wxPoint& pos = wxDefaultPosition,
1001 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1002 const wxValidator& validator = wxDefaultValidator );
1003 ~wxDataViewListCtrl();
1004
1005 bool Create( wxWindow *parent, wxWindowID id,
1006 const wxPoint& pos = wxDefaultPosition,
1007 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1008 const wxValidator& validator = wxDefaultValidator );
1009
1010 wxDataViewListStore *GetStore()
1011 { return (wxDataViewListStore*) GetModel(); }
1012 const wxDataViewListStore *GetStore() const
1013 { return (const wxDataViewListStore*) GetModel(); }
1014
1015 int ItemToRow(const wxDataViewItem &item) const
1016 { return item.IsOk() ? (int)GetStore()->GetRow(item) : wxNOT_FOUND; }
1017 wxDataViewItem RowToItem(int row) const
1018 { return row == wxNOT_FOUND ? wxDataViewItem() : GetStore()->GetItem(row); }
1019
1020 int GetSelectedRow() const
1021 { return ItemToRow(GetSelection()); }
1022 void SelectRow(unsigned row)
1023 { Select(RowToItem(row)); }
1024 void UnselectRow(unsigned row)
1025 { Unselect(RowToItem(row)); }
1026 bool IsRowSelected(unsigned row) const
1027 { return IsSelected(RowToItem(row)); }
1028
1029 bool AppendColumn( wxDataViewColumn *column, const wxString &varianttype );
1030 bool PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
1031 bool InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
1032
1033 // overridden from base class
1034 virtual bool PrependColumn( wxDataViewColumn *col );
1035 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
1036 virtual bool AppendColumn( wxDataViewColumn *col );
1037
1038 wxDataViewColumn *AppendTextColumn( const wxString &label,
1039 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1040 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1041 wxDataViewColumn *AppendToggleColumn( const wxString &label,
1042 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
1043 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1044 wxDataViewColumn *AppendProgressColumn( const wxString &label,
1045 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1046 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1047 wxDataViewColumn *AppendIconTextColumn( const wxString &label,
1048 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1049 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1050
1051 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1052 { GetStore()->AppendItem( values, data ); }
1053 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1054 { GetStore()->PrependItem( values, data ); }
1055 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL )
1056 { GetStore()->InsertItem( row, values, data ); }
1057 void DeleteItem( unsigned row )
1058 { GetStore()->DeleteItem( row ); }
1059 void DeleteAllItems()
1060 { GetStore()->DeleteAllItems(); }
1061
1062 void SetValue( const wxVariant &value, unsigned int row, unsigned int col )
1063 { GetStore()->SetValueByRow( value, row, col );
1064 GetStore()->RowValueChanged( row, col); }
1065 void GetValue( wxVariant &value, unsigned int row, unsigned int col )
1066 { GetStore()->GetValueByRow( value, row, col ); }
1067
1068 void SetTextValue( const wxString &value, unsigned int row, unsigned int col )
1069 { GetStore()->SetValueByRow( value, row, col );
1070 GetStore()->RowValueChanged( row, col); }
1071 wxString GetTextValue( unsigned int row, unsigned int col ) const
1072 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); }
1073
1074 void SetToggleValue( bool value, unsigned int row, unsigned int col )
1075 { GetStore()->SetValueByRow( value, row, col );
1076 GetStore()->RowValueChanged( row, col); }
1077 bool GetToggleValue( unsigned int row, unsigned int col ) const
1078 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
1079
1080 void OnSize( wxSizeEvent &event );
1081
1082 private:
1083 DECLARE_EVENT_TABLE()
1084 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl)
1085 };
1086
1087 //-----------------------------------------------------------------------------
1088 // wxDataViewTreeStore
1089 //-----------------------------------------------------------------------------
1090
1091 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
1092 {
1093 public:
1094 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
1095 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1096 virtual ~wxDataViewTreeStoreNode();
1097
1098 void SetText( const wxString &text )
1099 { m_text = text; }
1100 wxString GetText() const
1101 { return m_text; }
1102 void SetIcon( const wxIcon &icon )
1103 { m_icon = icon; }
1104 const wxIcon &GetIcon() const
1105 { return m_icon; }
1106 void SetData( wxClientData *data )
1107 { if (m_data) delete m_data; m_data = data; }
1108 wxClientData *GetData() const
1109 { return m_data; }
1110
1111 wxDataViewItem GetItem() const
1112 { return wxDataViewItem( (void*) this ); }
1113
1114 virtual bool IsContainer()
1115 { return false; }
1116
1117 wxDataViewTreeStoreNode *GetParent()
1118 { return m_parent; }
1119
1120 private:
1121 wxDataViewTreeStoreNode *m_parent;
1122 wxString m_text;
1123 wxIcon m_icon;
1124 wxClientData *m_data;
1125 };
1126
1127 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
1128 class WXDLLIMPEXP_ADV);
1129
1130 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
1131 {
1132 public:
1133 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
1134 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1135 wxClientData *data = NULL );
1136 virtual ~wxDataViewTreeStoreContainerNode();
1137
1138 const wxDataViewTreeStoreNodeList &GetChildren() const
1139 { return m_children; }
1140 wxDataViewTreeStoreNodeList &GetChildren()
1141 { return m_children; }
1142
1143 void SetExpandedIcon( const wxIcon &icon )
1144 { m_iconExpanded = icon; }
1145 const wxIcon &GetExpandedIcon() const
1146 { return m_iconExpanded; }
1147
1148 void SetExpanded( bool expanded = true )
1149 { m_isExpanded = expanded; }
1150 bool IsExpanded() const
1151 { return m_isExpanded; }
1152
1153 virtual bool IsContainer()
1154 { return true; }
1155
1156 private:
1157 wxDataViewTreeStoreNodeList m_children;
1158 wxIcon m_iconExpanded;
1159 bool m_isExpanded;
1160 };
1161
1162 //-----------------------------------------------------------------------------
1163
1164 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
1165 {
1166 public:
1167 wxDataViewTreeStore();
1168 ~wxDataViewTreeStore();
1169
1170 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1171 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1172 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1173 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1174 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1175 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1176
1177 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1178 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1179 wxClientData *data = NULL );
1180 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1181 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1182 wxClientData *data = NULL );
1183 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1184 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1185 wxClientData *data = NULL );
1186
1187 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
1188 int GetChildCount( const wxDataViewItem& parent ) const;
1189
1190 void SetItemText( const wxDataViewItem& item, const wxString &text );
1191 wxString GetItemText( const wxDataViewItem& item ) const;
1192 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1193 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
1194 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1195 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
1196 void SetItemData( const wxDataViewItem& item, wxClientData *data );
1197 wxClientData *GetItemData( const wxDataViewItem& item ) const;
1198
1199 void DeleteItem( const wxDataViewItem& item );
1200 void DeleteChildren( const wxDataViewItem& item );
1201 void DeleteAllItems();
1202
1203 // implement base methods
1204
1205 virtual void GetValue( wxVariant &variant,
1206 const wxDataViewItem &item, unsigned int col ) const;
1207 virtual bool SetValue( const wxVariant &variant,
1208 const wxDataViewItem &item, unsigned int col );
1209 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
1210 virtual bool IsContainer( const wxDataViewItem &item ) const;
1211 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
1212
1213 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1214 unsigned int column, bool ascending ) const;
1215
1216 virtual bool HasDefaultCompare() const
1217 { return true; }
1218 virtual unsigned int GetColumnCount() const
1219 { return 1; };
1220 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
1221 { return wxT("wxDataViewIconText"); }
1222
1223 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
1224 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
1225 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
1226
1227 public:
1228 wxDataViewTreeStoreNode *m_root;
1229 };
1230
1231 //-----------------------------------------------------------------------------
1232
1233 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
1234 {
1235 public:
1236 wxDataViewTreeCtrl() { Init(); }
1237 wxDataViewTreeCtrl(wxWindow *parent,
1238 wxWindowID id,
1239 const wxPoint& pos = wxDefaultPosition,
1240 const wxSize& size = wxDefaultSize,
1241 long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1242 const wxValidator& validator = wxDefaultValidator)
1243 {
1244 Init();
1245
1246 Create(parent, id, pos, size, style, validator);
1247 }
1248
1249 virtual ~wxDataViewTreeCtrl();
1250
1251 bool Create(wxWindow *parent,
1252 wxWindowID id,
1253 const wxPoint& pos = wxDefaultPosition,
1254 const wxSize& size = wxDefaultSize,
1255 long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1256 const wxValidator& validator = wxDefaultValidator);
1257
1258 wxDataViewTreeStore *GetStore()
1259 { return (wxDataViewTreeStore*) GetModel(); }
1260 const wxDataViewTreeStore *GetStore() const
1261 { return (const wxDataViewTreeStore*) GetModel(); }
1262
1263 bool IsContainer( const wxDataViewItem& item ) const
1264 { return GetStore()->IsContainer(item); }
1265
1266 void SetImageList( wxImageList *imagelist );
1267 wxImageList* GetImageList() { return m_imageList; }
1268
1269 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1270 const wxString &text, int icon = -1, wxClientData *data = NULL );
1271 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1272 const wxString &text, int icon = -1, wxClientData *data = NULL );
1273 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1274 const wxString &text, int icon = -1, wxClientData *data = NULL );
1275
1276 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1277 const wxString &text, int icon = -1, int expanded = -1,
1278 wxClientData *data = NULL );
1279 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1280 const wxString &text, int icon = -1, int expanded = -1,
1281 wxClientData *data = NULL );
1282 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1283 const wxString &text, int icon = -1, int expanded = -1,
1284 wxClientData *data = NULL );
1285
1286 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1287 { return GetStore()->GetNthChild(parent, pos); }
1288 int GetChildCount( const wxDataViewItem& parent ) const
1289 { return GetStore()->GetChildCount(parent); }
1290
1291 void SetItemText( const wxDataViewItem& item, const wxString &text );
1292 wxString GetItemText( const wxDataViewItem& item ) const
1293 { return GetStore()->GetItemText(item); }
1294 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1295 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const
1296 { return GetStore()->GetItemIcon(item); }
1297 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1298 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const
1299 { return GetStore()->GetItemExpandedIcon(item); }
1300 void SetItemData( const wxDataViewItem& item, wxClientData *data )
1301 { GetStore()->SetItemData(item,data); }
1302 wxClientData *GetItemData( const wxDataViewItem& item ) const
1303 { return GetStore()->GetItemData(item); }
1304
1305 void DeleteItem( const wxDataViewItem& item );
1306 void DeleteChildren( const wxDataViewItem& item );
1307 void DeleteAllItems();
1308
1309 void OnExpanded( wxDataViewEvent &event );
1310 void OnCollapsed( wxDataViewEvent &event );
1311 void OnSize( wxSizeEvent &event );
1312
1313 private:
1314 void Init()
1315 {
1316 m_imageList = NULL;
1317 }
1318
1319 wxImageList *m_imageList;
1320
1321 private:
1322 DECLARE_EVENT_TABLE()
1323 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
1324 };
1325
1326 #endif // wxUSE_DATAVIEWCTRL
1327
1328 #endif
1329 // _WX_DATAVIEW_H_BASE_