]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
4a59a5b39e002fa3d5c7e3130b17272bd930a11b
[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/control.h"
20 #include "wx/textctrl.h"
21 #include "wx/bitmap.h"
22 #include "wx/variant.h"
23 #include "wx/dynarray.h"
24 #include "wx/icon.h"
25 #include "wx/imaglist.h"
26
27 class WXDLLIMPEXP_FWD_CORE wxDataFormat;
28
29 #if defined(__WXGTK20__)
30 // for testing
31 // #define wxUSE_GENERICDATAVIEWCTRL 1
32 #elif defined(__WXMAC__)
33 #else
34 #define wxUSE_GENERICDATAVIEWCTRL 1
35 #endif
36
37 // ----------------------------------------------------------------------------
38 // wxDataViewCtrl flags
39 // ----------------------------------------------------------------------------
40
41 // ----------------------------------------------------------------------------
42 // wxDataViewCtrl globals
43 // ----------------------------------------------------------------------------
44
45 class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
48 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
49 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
50 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
51
52 extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
53
54 // the default width of new (text) columns:
55 #define wxDVC_DEFAULT_WIDTH 80
56
57 // the default width of new toggle columns:
58 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
59
60 // the default minimal width of the columns:
61 #define wxDVC_DEFAULT_MINWIDTH 30
62
63 // the default alignment of wxDataViewRenderers:
64 #define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL)
65
66
67 // ---------------------------------------------------------
68 // wxDataViewItem
69 // ---------------------------------------------------------
70
71 class WXDLLIMPEXP_ADV wxDataViewItem
72 {
73 public:
74 wxDataViewItem( void* id = NULL )
75 { m_id = id; }
76 wxDataViewItem( const wxDataViewItem &item )
77 { m_id = item.m_id; }
78 bool IsOk() const { return m_id != NULL; }
79 void* GetID() const { return m_id; }
80 operator const void* () const { return m_id; }
81
82 #ifdef __WXDEBUG__
83 void Print( const wxString &text ) const;
84 #endif
85
86 private:
87 void* m_id;
88 };
89
90 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right);
91
92 WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
93
94 // ---------------------------------------------------------
95 // wxDataViewModelNotifier
96 // ---------------------------------------------------------
97
98 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
99 {
100 public:
101 wxDataViewModelNotifier() { m_owner = NULL; }
102 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
103
104 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
105 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
106 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
107 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
108 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
109 virtual bool ItemsChanged( const wxDataViewItemArray &items );
110 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
111 virtual bool Cleared() = 0;
112
113 virtual void Resort() = 0;
114
115 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
116 wxDataViewModel *GetOwner() { return m_owner; }
117
118 private:
119 wxDataViewModel *m_owner;
120 };
121
122
123
124 // ----------------------------------------------------------------------------
125 // wxDataViewItemAttr: a structure containing the visual attributes of an item
126 // ----------------------------------------------------------------------------
127
128 // TODO: this should be renamed to wxItemAttr or something general like this
129
130 class WXDLLIMPEXP_ADV wxDataViewItemAttr
131 {
132 public:
133 // ctors
134 wxDataViewItemAttr()
135 {
136 m_bold = false;
137 m_italic = false;
138 }
139
140 // setters
141 void SetColour(const wxColour& colour) { m_colour = colour; }
142 void SetBold( bool set ) { m_bold = set; }
143 void SetItalic( bool set ) { m_italic = set; }
144
145 // accessors
146 bool HasColour() const { return m_colour.Ok(); }
147 const wxColour& GetColour() const { return m_colour; }
148
149 bool GetBold() const { return m_bold; }
150 bool GetItalic() const { return m_italic; }
151
152 private:
153 wxColour m_colour;
154 bool m_bold;
155 bool m_italic;
156 };
157
158
159 // ---------------------------------------------------------
160 // wxDataViewModel
161 // ---------------------------------------------------------
162
163 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
164 class WXDLLIMPEXP_ADV);
165
166 class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
167 {
168 public:
169 wxDataViewModel();
170
171 virtual unsigned int GetColumnCount() const = 0;
172
173 // return type as reported by wxVariant
174 virtual wxString GetColumnType( unsigned int col ) const = 0;
175
176 // get value into a wxVariant
177 virtual void GetValue( wxVariant &variant,
178 const wxDataViewItem &item, unsigned int col ) const = 0;
179
180 // set value, call ValueChanged() afterwards!
181 virtual bool SetValue( const wxVariant &variant,
182 const wxDataViewItem &item, unsigned int col ) = 0;
183
184 // Get text attribute, return false of default attributes should be used
185 virtual bool GetAttr( const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
186 { return false; }
187
188 // define hierachy
189 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
190 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
191 // Is the container just a header or an item with all columns
192 virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const
193 { return false; }
194 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0;
195
196 // define DnD capabilities
197 virtual bool IsDraggable( const wxDataViewItem &WXUNUSED(item) )
198 { return false; }
199 virtual size_t GetDragDataSize( const wxDataViewItem &WXUNUSED(item), const wxDataFormat &WXUNUSED(format) )
200 { return 0; }
201 virtual bool GetDragData( const wxDataViewItem &WXUNUSED(item), const wxDataFormat &WXUNUSED(format),
202 void* WXUNUSED(data), size_t WXUNUSED(size) )
203 { return FALSE; }
204
205 // delegated notifiers
206 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
207 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
208 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
209 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
210 virtual bool ItemChanged( const wxDataViewItem &item );
211 virtual bool ItemsChanged( const wxDataViewItemArray &items );
212 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
213 virtual bool Cleared();
214
215 // delegatd action
216 virtual void Resort();
217
218 void AddNotifier( wxDataViewModelNotifier *notifier );
219 void RemoveNotifier( wxDataViewModelNotifier *notifier );
220
221 // default compare function
222 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
223 unsigned int column, bool ascending );
224 virtual bool HasDefaultCompare() const { return false; }
225
226 // internal
227 virtual bool IsVirtualListModel() const { return false; }
228
229 protected:
230 // the user should not delete this class directly: he should use DecRef() instead!
231 virtual ~wxDataViewModel() { }
232
233 wxDataViewModelNotifiers m_notifiers;
234 };
235
236 // ---------------------------------------------------------
237 // wxDataViewIndexListModel
238 // ---------------------------------------------------------
239
240 class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewModel
241 {
242 public:
243 wxDataViewIndexListModel( unsigned int initial_size = 0 );
244 ~wxDataViewIndexListModel();
245
246 virtual void GetValue( wxVariant &variant,
247 unsigned int row, unsigned int col ) const = 0;
248
249 virtual bool SetValue( const wxVariant &variant,
250 unsigned int row, unsigned int col ) = 0;
251
252 virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
253 { return false; }
254
255 void RowPrepended();
256 void RowInserted( unsigned int before );
257 void RowAppended();
258 void RowDeleted( unsigned int row );
259 void RowsDeleted( const wxArrayInt &rows );
260 void RowChanged( unsigned int row );
261 void RowValueChanged( unsigned int row, unsigned int col );
262 void Reset( unsigned int new_size );
263
264 // convert to/from row/wxDataViewItem
265
266 unsigned int GetRow( const wxDataViewItem &item ) const;
267 wxDataViewItem GetItem( unsigned int row ) const;
268
269 // compare based on index
270
271 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
272 unsigned int column, bool ascending );
273 virtual bool HasDefaultCompare() const;
274
275 // implement base methods
276
277 virtual void GetValue( wxVariant &variant,
278 const wxDataViewItem &item, unsigned int col ) const;
279 virtual bool SetValue( const wxVariant &variant,
280 const wxDataViewItem &item, unsigned int col );
281 virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr );
282 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
283 virtual bool IsContainer( const wxDataViewItem &item ) const;
284 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
285
286 // internal
287 virtual bool IsVirtualListModel() const { return false; }
288 unsigned int GetLastIndex() const { return m_lastIndex; }
289
290 private:
291 wxDataViewItemArray m_hash;
292 unsigned int m_lastIndex;
293 bool m_ordered;
294 bool m_useHash;
295 };
296
297 // ---------------------------------------------------------
298 // wxDataViewVirtualListModel
299 // ---------------------------------------------------------
300
301 #ifdef __WXMAC__
302 // better than nothing
303 typedef wxDataViewIndexListModel wxDataViewVirtualListModel;
304 #else
305
306 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewModel
307 {
308 public:
309 wxDataViewVirtualListModel( unsigned int initial_size = 0 );
310 ~wxDataViewVirtualListModel();
311
312 virtual void GetValue( wxVariant &variant,
313 unsigned int row, unsigned int col ) const = 0;
314
315 virtual bool SetValue( const wxVariant &variant,
316 unsigned int row, unsigned int col ) = 0;
317
318 virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
319 { return false; }
320
321 void RowPrepended();
322 void RowInserted( unsigned int before );
323 void RowAppended();
324 void RowDeleted( unsigned int row );
325 void RowsDeleted( const wxArrayInt &rows );
326 void RowChanged( unsigned int row );
327 void RowValueChanged( unsigned int row, unsigned int col );
328 void Reset( unsigned int new_size );
329
330 // convert to/from row/wxDataViewItem
331
332 unsigned int GetRow( const wxDataViewItem &item ) const;
333 wxDataViewItem GetItem( unsigned int row ) const;
334
335 // compare based on index
336
337 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
338 unsigned int column, bool ascending );
339 virtual bool HasDefaultCompare() const;
340
341 // implement base methods
342
343 virtual void GetValue( wxVariant &variant,
344 const wxDataViewItem &item, unsigned int col ) const;
345 virtual bool SetValue( const wxVariant &variant,
346 const wxDataViewItem &item, unsigned int col );
347 virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr );
348 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
349 virtual bool IsContainer( const wxDataViewItem &item ) const;
350 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
351
352 // internal
353 virtual bool IsVirtualListModel() const { return true; }
354 unsigned int GetLastIndex() const { return m_lastIndex; }
355
356 private:
357 wxDataViewItemArray m_hash;
358 unsigned int m_lastIndex;
359 bool m_ordered;
360 };
361 #endif
362
363 //-----------------------------------------------------------------------------
364 // wxDataViewEditorCtrlEvtHandler
365 //-----------------------------------------------------------------------------
366
367 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
368 {
369 public:
370 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
371
372 void AcceptChangesAndFinish();
373 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
374
375 protected:
376 void OnChar( wxKeyEvent &event );
377 void OnKillFocus( wxFocusEvent &event );
378 void OnIdle( wxIdleEvent &event );
379
380 private:
381 wxDataViewRenderer *m_owner;
382 wxControl *m_editorCtrl;
383 bool m_finished;
384 bool m_focusOnIdle;
385
386 private:
387 DECLARE_EVENT_TABLE()
388 };
389
390 // ---------------------------------------------------------
391 // wxDataViewRendererBase
392 // ---------------------------------------------------------
393
394 enum wxDataViewCellMode
395 {
396 wxDATAVIEW_CELL_INERT,
397 wxDATAVIEW_CELL_ACTIVATABLE,
398 wxDATAVIEW_CELL_EDITABLE
399 };
400
401 enum wxDataViewCellRenderState
402 {
403 wxDATAVIEW_CELL_SELECTED = 1,
404 wxDATAVIEW_CELL_PRELIT = 2,
405 wxDATAVIEW_CELL_INSENSITIVE = 4,
406 wxDATAVIEW_CELL_FOCUSED = 8
407 };
408
409 class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
410 {
411 public:
412 wxDataViewRendererBase( const wxString &varianttype,
413 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
414 int alignment = wxDVR_DEFAULT_ALIGNMENT );
415
416 virtual bool Validate( wxVariant& WXUNUSED(value) )
417 { return true; }
418
419 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
420 wxDataViewColumn* GetOwner() { return m_owner; }
421
422 // renderer properties:
423
424 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
425 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
426
427 wxString GetVariantType() const { return m_variantType; }
428
429 virtual void SetMode( wxDataViewCellMode mode ) = 0;
430 virtual wxDataViewCellMode GetMode() const = 0;
431
432 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
433 // rather an "int"; that's because for rendering cells it's allowed
434 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
435 virtual void SetAlignment( int align ) = 0;
436 virtual int GetAlignment() const = 0;
437
438 // in-place editing
439 virtual bool HasEditorCtrl()
440 { return false; }
441 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
442 wxRect WXUNUSED(labelRect),
443 const wxVariant& WXUNUSED(value))
444 { return NULL; }
445 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
446 wxVariant& WXUNUSED(value))
447 { return false; }
448
449 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
450 virtual void CancelEditing();
451 virtual bool FinishEditing();
452
453 wxControl *GetEditorCtrl() { return m_editorCtrl; }
454
455 protected:
456 wxString m_variantType;
457 wxDataViewColumn *m_owner;
458 wxControl *m_editorCtrl;
459 wxDataViewItem m_item; // for m_editorCtrl
460
461 // internal utility:
462 const wxDataViewCtrl* GetView() const;
463
464 protected:
465 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
466 };
467
468 //-----------------------------------------------------------------------------
469 // wxDataViewIconText
470 //-----------------------------------------------------------------------------
471
472 class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
473 {
474 public:
475 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
476 : m_text(text), m_icon(icon)
477 { }
478 wxDataViewIconText( const wxDataViewIconText &other )
479 { m_icon = other.m_icon; m_text = other.m_text; }
480
481 void SetText( const wxString &text ) { m_text = text; }
482 wxString GetText() const { return m_text; }
483 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
484 const wxIcon &GetIcon() const { return m_icon; }
485
486 private:
487 wxString m_text;
488 wxIcon m_icon;
489
490 private:
491 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
492 };
493
494 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two);
495
496 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
497
498 // ---------------------------------------------------------
499 // wxDataViewColumnBase
500 // ---------------------------------------------------------
501
502 enum wxDataViewColumnFlags
503 {
504 wxDATAVIEW_COL_RESIZABLE = 1,
505 wxDATAVIEW_COL_SORTABLE = 2,
506 wxDATAVIEW_COL_REORDERABLE = 4,
507 wxDATAVIEW_COL_HIDDEN = 8
508 };
509
510 class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
511 {
512 public:
513 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
514 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
515 wxAlignment align = wxALIGN_CENTER,
516 int flags = wxDATAVIEW_COL_RESIZABLE );
517 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
518 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
519 wxAlignment align = wxALIGN_CENTER,
520 int flags = wxDATAVIEW_COL_RESIZABLE );
521 virtual ~wxDataViewColumnBase();
522
523 // setters:
524
525 virtual void SetTitle( const wxString &title ) = 0;
526 virtual void SetAlignment( wxAlignment align ) = 0;
527 virtual void SetSortable( bool sortable ) = 0;
528 virtual void SetReorderable(bool reorderable) = 0;
529 virtual void SetResizeable( bool resizeable ) = 0;
530 virtual void SetHidden( bool hidden ) = 0;
531 virtual void SetSortOrder( bool ascending ) = 0;
532 virtual void SetFlags( int flags );
533 virtual void SetOwner( wxDataViewCtrl *owner )
534 { m_owner = owner; }
535 virtual void SetBitmap( const wxBitmap &bitmap )
536 { m_bitmap=bitmap; }
537
538 virtual void SetMinWidth( int minWidth ) = 0;
539 virtual void SetWidth( int width ) = 0;
540
541
542 // getters:
543
544 virtual wxString GetTitle() const = 0;
545 virtual wxAlignment GetAlignment() const = 0;
546 virtual int GetWidth() const = 0;
547 virtual int GetMinWidth() const = 0;
548
549 virtual int GetFlags() const;
550
551 virtual bool IsHidden() const = 0;
552 virtual bool IsReorderable() const = 0;
553 virtual bool IsResizeable() const = 0;
554 virtual bool IsSortable() const = 0;
555 virtual bool IsSortOrderAscending() const = 0;
556
557 const wxBitmap &GetBitmap() const { return m_bitmap; }
558 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
559
560 wxDataViewCtrl *GetOwner() const { return m_owner; }
561 wxDataViewRenderer* GetRenderer() const { return m_renderer; }
562
563 protected:
564 wxDataViewRenderer *m_renderer;
565 int m_model_column;
566 wxBitmap m_bitmap;
567 wxDataViewCtrl *m_owner;
568
569 protected:
570 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
571 };
572
573 // ---------------------------------------------------------
574 // wxDataViewCtrlBase
575 // ---------------------------------------------------------
576
577 #define wxDV_SINGLE 0x0000 // for convenience
578 #define wxDV_MULTIPLE 0x0001 // can select multiple items
579
580 #define wxDV_NO_HEADER 0x0002 // column titles not visible
581 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
582 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
583
584 #define wxDV_ROW_LINES 0x0010 // alternating colour in rows
585
586 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
587 {
588 public:
589 wxDataViewCtrlBase();
590 virtual ~wxDataViewCtrlBase();
591
592 virtual bool AssociateModel( wxDataViewModel *model );
593 wxDataViewModel* GetModel();
594 const wxDataViewModel* GetModel() const;
595
596 // short cuts
597 wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
598 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
599 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
600 int flags = wxDATAVIEW_COL_RESIZABLE );
601 wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column,
602 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
603 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
604 int flags = wxDATAVIEW_COL_RESIZABLE );
605 wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column,
606 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
607 wxAlignment align = wxALIGN_CENTER,
608 int flags = wxDATAVIEW_COL_RESIZABLE );
609 wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column,
610 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
611 wxAlignment align = wxALIGN_CENTER,
612 int flags = wxDATAVIEW_COL_RESIZABLE );
613 wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column,
614 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
615 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
616 int flags = wxDATAVIEW_COL_RESIZABLE );
617 wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column,
618 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
619 wxAlignment align = wxALIGN_CENTER,
620 int flags = wxDATAVIEW_COL_RESIZABLE );
621 wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column,
622 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
623 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
624 int flags = wxDATAVIEW_COL_RESIZABLE );
625 wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
626 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
627 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
628 int flags = wxDATAVIEW_COL_RESIZABLE );
629 wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
630 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
631 wxAlignment align = wxALIGN_CENTER,
632 int flags = wxDATAVIEW_COL_RESIZABLE );
633 wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
634 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
635 wxAlignment align = wxALIGN_CENTER,
636 int flags = wxDATAVIEW_COL_RESIZABLE );
637 wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column,
638 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
639 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
640 int flags = wxDATAVIEW_COL_RESIZABLE );
641 wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
642 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
643 wxAlignment align = wxALIGN_CENTER,
644 int flags = wxDATAVIEW_COL_RESIZABLE );
645
646 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
647 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
648 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
649 int flags = wxDATAVIEW_COL_RESIZABLE );
650 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
651 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
652 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
653 int flags = wxDATAVIEW_COL_RESIZABLE );
654 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
655 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
656 wxAlignment align = wxALIGN_CENTER,
657 int flags = wxDATAVIEW_COL_RESIZABLE );
658 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
659 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
660 wxAlignment align = wxALIGN_CENTER,
661 int flags = wxDATAVIEW_COL_RESIZABLE );
662 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
663 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
664 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
665 int flags = wxDATAVIEW_COL_RESIZABLE );
666 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
667 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
668 wxAlignment align = wxALIGN_CENTER,
669 int flags = wxDATAVIEW_COL_RESIZABLE );
670 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
671 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
672 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
673 int flags = wxDATAVIEW_COL_RESIZABLE );
674 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
675 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
676 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
677 int flags = wxDATAVIEW_COL_RESIZABLE );
678 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
679 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
680 wxAlignment align = wxALIGN_CENTER,
681 int flags = wxDATAVIEW_COL_RESIZABLE );
682 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
683 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
684 wxAlignment align = wxALIGN_CENTER,
685 int flags = wxDATAVIEW_COL_RESIZABLE );
686 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
687 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
688 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
689 int flags = wxDATAVIEW_COL_RESIZABLE );
690 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
691 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
692 wxAlignment align = wxALIGN_CENTER,
693 int flags = wxDATAVIEW_COL_RESIZABLE );
694
695
696 virtual bool PrependColumn( wxDataViewColumn *col );
697 virtual bool AppendColumn( wxDataViewColumn *col );
698
699 virtual unsigned int GetColumnCount() const = 0;
700 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
701 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
702
703 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
704 virtual bool ClearColumns() = 0;
705
706 void SetExpanderColumn( wxDataViewColumn *col )
707 { m_expander_column = col ; DoSetExpanderColumn(); }
708 wxDataViewColumn *GetExpanderColumn() const
709 { return m_expander_column; }
710
711 virtual wxDataViewColumn *GetSortingColumn() const = 0;
712
713 void SetIndent( int indent )
714 { m_indent = indent ; DoSetIndent(); }
715 int GetIndent() const
716 { return m_indent; }
717
718 virtual wxDataViewItem GetSelection() const = 0;
719 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
720 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
721 virtual void Select( const wxDataViewItem & item ) = 0;
722 virtual void Unselect( const wxDataViewItem & item ) = 0;
723 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
724
725 virtual void SelectAll() = 0;
726 virtual void UnselectAll() = 0;
727
728 virtual void Expand( const wxDataViewItem & item ) = 0;
729 virtual void Collapse( const wxDataViewItem & item ) = 0;
730
731 virtual void EnsureVisible( const wxDataViewItem & item,
732 const wxDataViewColumn *column = NULL ) = 0;
733 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
734 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
735
736 protected:
737 virtual void DoSetExpanderColumn() = 0 ;
738 virtual void DoSetIndent() = 0;
739
740 private:
741 wxDataViewModel *m_model;
742 wxDataViewColumn *m_expander_column;
743 int m_indent ;
744
745 protected:
746 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
747 };
748
749 // ----------------------------------------------------------------------------
750 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
751 // ----------------------------------------------------------------------------
752
753 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
754 {
755 public:
756 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
757 : wxNotifyEvent(commandType, winid),
758 m_item(0),
759 m_col(-1),
760 m_model(NULL),
761 m_value(wxNullVariant),
762 m_column(NULL),
763 m_pos(-1,-1)
764 { }
765
766 wxDataViewEvent(const wxDataViewEvent& event)
767 : wxNotifyEvent(event),
768 m_item(event.m_item),
769 m_col(event.m_col),
770 m_model(event.m_model),
771 m_value(event.m_value),
772 m_column(event.m_column),
773 m_pos(m_pos)
774 { }
775
776 wxDataViewItem GetItem() const { return m_item; }
777 void SetItem( const wxDataViewItem &item ) { m_item = item; }
778
779 int GetColumn() const { return m_col; }
780 void SetColumn( int col ) { m_col = col; }
781
782 wxDataViewModel* GetModel() const { return m_model; }
783 void SetModel( wxDataViewModel *model ) { m_model = model; }
784
785 const wxVariant &GetValue() const { return m_value; }
786 void SetValue( const wxVariant &value ) { m_value = value; }
787
788 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
789 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
790 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
791
792 // for wxEVT_DATAVIEW_CONTEXT_MENU only
793 wxPoint GetPosition() const { return m_pos; }
794 void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; }
795
796 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
797
798 protected:
799 wxDataViewItem m_item;
800 int m_col;
801 wxDataViewModel *m_model;
802 wxVariant m_value;
803 wxDataViewColumn *m_column;
804 wxPoint m_pos;
805
806 private:
807 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
808 };
809
810 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED;
811
812 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED;
813 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED;
814 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED;
815 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING;
816 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING;
817 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED;
818 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE;
819 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED;
820
821 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU;
822
823 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK;
824 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
825 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED;
826 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED;
827
828 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
829
830 #define wxDataViewEventHandler(func) \
831 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
832
833 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
834 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
835
836 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
837
838 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
839 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
840 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
841 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
842 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
843 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
844 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
845 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
846
847 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
848
849 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
850 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
851 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
852 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
853
854 #if defined(wxUSE_GENERICDATAVIEWCTRL)
855 #include "wx/generic/dataview.h"
856 #elif defined(__WXGTK20__)
857 #include "wx/gtk/dataview.h"
858 #elif defined(__WXMAC__)
859 #include "wx/mac/dataview.h"
860 #else
861 #include "wx/generic/dataview.h"
862 #endif
863
864 // -------------------------------------
865 // wxDataViewSpinRenderer
866 // -------------------------------------
867
868 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
869 {
870 public:
871 wxDataViewSpinRenderer( int min, int max,
872 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
873 int alignment = wxDVR_DEFAULT_ALIGNMENT );
874 virtual bool HasEditorCtrl() { return true; }
875 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
876 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
877 virtual bool Render( wxRect rect, wxDC *dc, int state );
878 virtual wxSize GetSize() const;
879 virtual bool SetValue( const wxVariant &value );
880 virtual bool GetValue( wxVariant &value ) const;
881
882 private:
883 long m_data;
884 long m_min,m_max;
885 };
886
887 //-----------------------------------------------------------------------------
888 // wxDataViewTreeStore
889 //-----------------------------------------------------------------------------
890
891 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
892 {
893 public:
894 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
895 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
896 virtual ~wxDataViewTreeStoreNode();
897
898 void SetText( const wxString &text )
899 { m_text = text; }
900 wxString GetText() const
901 { return m_text; }
902 void SetIcon( const wxIcon &icon )
903 { m_icon = icon; }
904 const wxIcon &GetIcon() const
905 { return m_icon; }
906 void SetData( wxClientData *data )
907 { if (m_data) delete m_data; m_data = data; }
908 wxClientData *GetData() const
909 { return m_data; }
910
911 wxDataViewItem GetItem() const
912 { return wxDataViewItem( (void*) this ); }
913
914 virtual bool IsContainer()
915 { return false; }
916
917 wxDataViewTreeStoreNode *GetParent()
918 { return m_parent; }
919
920 private:
921 wxDataViewTreeStoreNode *m_parent;
922 wxString m_text;
923 wxIcon m_icon;
924 wxClientData *m_data;
925 };
926
927 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
928 class WXDLLIMPEXP_ADV);
929
930 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
931 {
932 public:
933 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
934 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
935 wxClientData *data = NULL );
936 virtual ~wxDataViewTreeStoreContainerNode();
937
938 const wxDataViewTreeStoreNodeList &GetChildren() const
939 { return m_children; }
940 wxDataViewTreeStoreNodeList &GetChildren()
941 { return m_children; }
942
943 void SetExpandedIcon( const wxIcon &icon )
944 { m_iconExpanded = icon; }
945 const wxIcon &GetExpandedIcon() const
946 { return m_iconExpanded; }
947
948 void SetExpanded( bool expanded = true )
949 { m_isExpanded = expanded; }
950 bool IsExpanded() const
951 { return m_isExpanded; }
952
953 virtual bool IsContainer()
954 { return true; }
955
956 private:
957 wxDataViewTreeStoreNodeList m_children;
958 wxIcon m_iconExpanded;
959 bool m_isExpanded;
960 };
961
962 //-----------------------------------------------------------------------------
963
964 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
965 {
966 public:
967 wxDataViewTreeStore();
968 ~wxDataViewTreeStore();
969
970 wxDataViewItem AppendItem( const wxDataViewItem& parent,
971 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
972 wxDataViewItem PrependItem( const wxDataViewItem& parent,
973 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
974 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
975 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
976
977 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
978 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
979 wxClientData *data = NULL );
980 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
981 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
982 wxClientData *data = NULL );
983 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
984 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
985 wxClientData *data = NULL );
986
987 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
988 int GetChildCount( const wxDataViewItem& parent ) const;
989
990 void SetItemText( const wxDataViewItem& item, const wxString &text );
991 wxString GetItemText( const wxDataViewItem& item ) const;
992 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
993 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
994 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
995 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
996 void SetItemData( const wxDataViewItem& item, wxClientData *data );
997 wxClientData *GetItemData( const wxDataViewItem& item ) const;
998
999 void DeleteItem( const wxDataViewItem& item );
1000 void DeleteChildren( const wxDataViewItem& item );
1001 void DeleteAllItems();
1002
1003 // implement base methods
1004
1005 virtual void GetValue( wxVariant &variant,
1006 const wxDataViewItem &item, unsigned int col ) const;
1007 virtual bool SetValue( const wxVariant &variant,
1008 const wxDataViewItem &item, unsigned int col );
1009 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
1010 virtual bool IsContainer( const wxDataViewItem &item ) const;
1011 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
1012
1013 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1014 unsigned int column, bool ascending );
1015
1016 virtual bool HasDefaultCompare() const
1017 { return true; }
1018 virtual unsigned int GetColumnCount() const
1019 { return 1; };
1020 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
1021 { return wxT("wxDataViewIconText"); }
1022
1023 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
1024 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
1025 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
1026
1027 public:
1028 wxDataViewTreeStoreNode *m_root;
1029 };
1030
1031 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
1032 {
1033 public:
1034 wxDataViewTreeCtrl();
1035 wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
1036 const wxPoint& pos = wxDefaultPosition,
1037 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1038 const wxValidator& validator = wxDefaultValidator );
1039 ~wxDataViewTreeCtrl();
1040
1041 bool Create( wxWindow *parent, wxWindowID id,
1042 const wxPoint& pos = wxDefaultPosition,
1043 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1044 const wxValidator& validator = wxDefaultValidator );
1045
1046 wxDataViewTreeStore *GetStore()
1047 { return (wxDataViewTreeStore*) GetModel(); }
1048 const wxDataViewTreeStore *GetStore() const
1049 { return (const wxDataViewTreeStore*) GetModel(); }
1050
1051 void SetImageList( wxImageList *imagelist );
1052 wxImageList* GetImageList() { return m_imageList; }
1053
1054 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1055 const wxString &text, int icon = -1, wxClientData *data = NULL );
1056 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1057 const wxString &text, int icon = -1, wxClientData *data = NULL );
1058 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1059 const wxString &text, int icon = -1, wxClientData *data = NULL );
1060
1061 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1062 const wxString &text, int icon = -1, int expanded = -1,
1063 wxClientData *data = NULL );
1064 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1065 const wxString &text, int icon = -1, int expanded = -1,
1066 wxClientData *data = NULL );
1067 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1068 const wxString &text, int icon = -1, int expanded = -1,
1069 wxClientData *data = NULL );
1070
1071 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1072 { return GetStore()->GetNthChild(parent, pos); }
1073 int GetChildCount( const wxDataViewItem& parent ) const
1074 { return GetStore()->GetChildCount(parent); }
1075
1076 void SetItemText( const wxDataViewItem& item, const wxString &text )
1077 { GetStore()->SetItemText(item,text); }
1078 wxString GetItemText( const wxDataViewItem& item ) const
1079 { return GetStore()->GetItemText(item); }
1080 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
1081 { GetStore()->SetItemIcon(item,icon); }
1082 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const
1083 { return GetStore()->GetItemIcon(item); }
1084 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
1085 { GetStore()->SetItemExpandedIcon(item,icon); }
1086 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const
1087 { return GetStore()->GetItemExpandedIcon(item); }
1088 void SetItemData( const wxDataViewItem& item, wxClientData *data )
1089 { GetStore()->SetItemData(item,data); }
1090 wxClientData *GetItemData( const wxDataViewItem& item ) const
1091 { return GetStore()->GetItemData(item); }
1092
1093 void DeleteItem( const wxDataViewItem& item )
1094 { GetStore()->DeleteItem(item); }
1095 void DeleteChildren( const wxDataViewItem& item )
1096 { GetStore()->DeleteChildren(item); }
1097 void DeleteAllItems()
1098 { GetStore()->DeleteAllItems(); }
1099
1100 void OnExpanded( wxDataViewEvent &event );
1101 void OnCollapsed( wxDataViewEvent &event );
1102 void OnSize( wxSizeEvent &event );
1103
1104 private:
1105 wxImageList *m_imageList;
1106
1107 private:
1108 DECLARE_EVENT_TABLE()
1109 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
1110 };
1111
1112 #endif // wxUSE_DATAVIEWCTRL
1113
1114 #endif
1115 // _WX_DATAVIEW_H_BASE_