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