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