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