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