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