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