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