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