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