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