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