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