]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
don't use annoying and unneeded in C++ casts of NULL to "T *"
[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 #include "wx/vector.h"
28
29 #if !(defined(__WXGTK20__) || defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
30 // #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
31 #define wxHAS_GENERIC_DATAVIEWCTRL
32 #endif
33
34 class WXDLLIMPEXP_FWD_CORE wxDataFormat;
35
36 // ----------------------------------------------------------------------------
37 // wxDataViewCtrl flags
38 // ----------------------------------------------------------------------------
39
40 // ----------------------------------------------------------------------------
41 // wxDataViewCtrl globals
42 // ----------------------------------------------------------------------------
43
44 class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
45 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
48 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
49 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
50
51 extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[];
52
53 // the default width of new (text) columns:
54 #define wxDVC_DEFAULT_WIDTH 80
55
56 // the default width of new toggle columns:
57 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
58
59 // the default minimal width of the columns:
60 #define wxDVC_DEFAULT_MINWIDTH 30
61
62 // The default alignment of wxDataViewRenderers is to take
63 // the alignment from the column it owns.
64 #define wxDVR_DEFAULT_ALIGNMENT -1
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() const { 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 GetValueByRow( wxVariant &variant,
247 unsigned int row, unsigned int col ) const = 0;
248
249 virtual bool SetValueByRow( const wxVariant &variant,
250 unsigned int row, unsigned int col ) = 0;
251
252 virtual bool GetAttrByRow( 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 };
295
296 // ---------------------------------------------------------
297 // wxDataViewVirtualListModel
298 // ---------------------------------------------------------
299
300 #ifdef __WXMAC__
301 // better than nothing
302 typedef wxDataViewIndexListModel wxDataViewVirtualListModel;
303 #else
304
305 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewModel
306 {
307 public:
308 wxDataViewVirtualListModel( unsigned int initial_size = 0 );
309 ~wxDataViewVirtualListModel();
310
311 virtual void GetValueByRow( wxVariant &variant,
312 unsigned int row, unsigned int col ) const = 0;
313
314 virtual bool SetValueByRow( const wxVariant &variant,
315 unsigned int row, unsigned int col ) = 0;
316
317 virtual bool GetAttrByRow( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
318 { return false; }
319
320 void RowPrepended();
321 void RowInserted( unsigned int before );
322 void RowAppended();
323 void RowDeleted( unsigned int row );
324 void RowsDeleted( const wxArrayInt &rows );
325 void RowChanged( unsigned int row );
326 void RowValueChanged( unsigned int row, unsigned int col );
327 void Reset( unsigned int new_size );
328
329 // convert to/from row/wxDataViewItem
330
331 unsigned int GetRow( const wxDataViewItem &item ) const;
332 wxDataViewItem GetItem( unsigned int row ) const;
333
334 // compare based on index
335
336 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
337 unsigned int column, bool ascending );
338 virtual bool HasDefaultCompare() const;
339
340 // implement base methods
341
342 virtual void GetValue( wxVariant &variant,
343 const wxDataViewItem &item, unsigned int col ) const;
344 virtual bool SetValue( const wxVariant &variant,
345 const wxDataViewItem &item, unsigned int col );
346 virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr );
347 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
348 virtual bool IsContainer( const wxDataViewItem &item ) const;
349 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
350
351 // internal
352 virtual bool IsVirtualListModel() const { return true; }
353 unsigned int GetLastIndex() const { return m_lastIndex; }
354
355 private:
356 wxDataViewItemArray m_hash;
357 unsigned int m_lastIndex;
358 bool m_ordered;
359 };
360 #endif
361
362 //-----------------------------------------------------------------------------
363 // wxDataViewEditorCtrlEvtHandler
364 //-----------------------------------------------------------------------------
365
366 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
367 {
368 public:
369 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
370
371 void AcceptChangesAndFinish();
372 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
373
374 protected:
375 void OnChar( wxKeyEvent &event );
376 void OnTextEnter( wxCommandEvent &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 ~wxDataViewRendererBase();
416
417 virtual bool Validate( wxVariant& WXUNUSED(value) )
418 { return true; }
419
420 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
421 wxDataViewColumn* GetOwner() const { return m_owner; }
422
423 // renderer properties:
424
425 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
426 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
427
428 wxString GetVariantType() const { return m_variantType; }
429
430 virtual void SetMode( wxDataViewCellMode mode ) = 0;
431 virtual wxDataViewCellMode GetMode() const = 0;
432
433 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
434 // rather an "int"; that's because for rendering cells it's allowed
435 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
436 virtual void SetAlignment( int align ) = 0;
437 virtual int GetAlignment() const = 0;
438
439 // in-place editing
440 virtual bool HasEditorCtrl()
441 { return false; }
442 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
443 wxRect WXUNUSED(labelRect),
444 const wxVariant& WXUNUSED(value))
445 { return NULL; }
446 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
447 wxVariant& WXUNUSED(value))
448 { return false; }
449
450 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
451 virtual void CancelEditing();
452 virtual bool FinishEditing();
453
454 wxControl *GetEditorCtrl() { return m_editorCtrl; }
455
456 protected:
457 wxString m_variantType;
458 wxDataViewColumn *m_owner;
459 wxWeakRef<wxControl> m_editorCtrl;
460 wxDataViewItem m_item; // for m_editorCtrl
461
462 // internal utility:
463 const wxDataViewCtrl* GetView() const;
464
465 protected:
466 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
467 };
468
469 //-----------------------------------------------------------------------------
470 // wxDataViewIconText
471 //-----------------------------------------------------------------------------
472
473 class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
474 {
475 public:
476 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
477 : m_text(text), m_icon(icon)
478 { }
479 wxDataViewIconText( const wxDataViewIconText &other )
480 : wxObject()
481 { m_icon = other.m_icon; m_text = other.m_text; }
482
483 void SetText( const wxString &text ) { m_text = text; }
484 wxString GetText() const { return m_text; }
485 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
486 const wxIcon &GetIcon() const { return m_icon; }
487
488 private:
489 wxString m_text;
490 wxIcon m_icon;
491
492 private:
493 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
494 };
495
496 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two);
497
498 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
499
500 // ---------------------------------------------------------
501 // wxDataViewColumnBase
502 // ---------------------------------------------------------
503
504 // for compatibility only, do not use
505 enum wxDataViewColumnFlags
506 {
507 wxDATAVIEW_COL_RESIZABLE = wxCOL_RESIZABLE,
508 wxDATAVIEW_COL_SORTABLE = wxCOL_SORTABLE,
509 wxDATAVIEW_COL_REORDERABLE = wxCOL_REORDERABLE,
510 wxDATAVIEW_COL_HIDDEN = wxCOL_HIDDEN
511 };
512
513 class WXDLLIMPEXP_ADV wxDataViewColumnBase : public wxSettableHeaderColumn
514 {
515 public:
516 // ctor for the text columns: takes ownership of renderer
517 wxDataViewColumnBase(wxDataViewRenderer *renderer,
518 unsigned int model_column)
519 {
520 Init(renderer, model_column);
521 }
522
523 // ctor for the bitmap columns
524 wxDataViewColumnBase(const wxBitmap& bitmap,
525 wxDataViewRenderer *renderer,
526 unsigned int model_column)
527 : m_bitmap(bitmap)
528 {
529 Init(renderer, model_column);
530 }
531
532 virtual ~wxDataViewColumnBase();
533
534 // setters:
535 virtual void SetOwner( wxDataViewCtrl *owner )
536 { m_owner = owner; }
537
538 // getters:
539 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
540 wxDataViewCtrl *GetOwner() const { return m_owner; }
541 wxDataViewRenderer* GetRenderer() const { return m_renderer; }
542
543 // implement some of base class pure virtuals (the rest is port-dependent
544 // and done differently in generic and native versions)
545 virtual void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
546 virtual wxBitmap GetBitmap() const { return m_bitmap; }
547
548 protected:
549 wxDataViewRenderer *m_renderer;
550 int m_model_column;
551 wxBitmap m_bitmap;
552 wxDataViewCtrl *m_owner;
553
554 private:
555 // common part of all ctors
556 void Init(wxDataViewRenderer *renderer, unsigned int model_column);
557 };
558
559 // ---------------------------------------------------------
560 // wxDataViewCtrlBase
561 // ---------------------------------------------------------
562
563 #define wxDV_SINGLE 0x0000 // for convenience
564 #define wxDV_MULTIPLE 0x0001 // can select multiple items
565
566 #define wxDV_NO_HEADER 0x0002 // column titles not visible
567 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
568 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
569
570 #define wxDV_ROW_LINES 0x0010 // alternating colour in rows
571 #define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height
572
573 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
574 {
575 public:
576 wxDataViewCtrlBase();
577 virtual ~wxDataViewCtrlBase();
578
579 virtual bool AssociateModel( wxDataViewModel *model );
580 wxDataViewModel* GetModel();
581 const wxDataViewModel* GetModel() const;
582
583 // short cuts
584 wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
585 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
586 wxAlignment align = wxALIGN_NOT,
587 int flags = wxDATAVIEW_COL_RESIZABLE );
588 wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column,
589 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
590 wxAlignment align = wxALIGN_NOT,
591 int flags = wxDATAVIEW_COL_RESIZABLE );
592 wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column,
593 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
594 wxAlignment align = wxALIGN_CENTER,
595 int flags = wxDATAVIEW_COL_RESIZABLE );
596 wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column,
597 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
598 wxAlignment align = wxALIGN_CENTER,
599 int flags = wxDATAVIEW_COL_RESIZABLE );
600 wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column,
601 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
602 wxAlignment align = wxALIGN_NOT,
603 int flags = wxDATAVIEW_COL_RESIZABLE );
604 wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column,
605 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
606 wxAlignment align = wxALIGN_CENTER,
607 int flags = wxDATAVIEW_COL_RESIZABLE );
608 wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column,
609 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
610 wxAlignment align = wxALIGN_NOT,
611 int flags = wxDATAVIEW_COL_RESIZABLE );
612 wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
613 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
614 wxAlignment align = wxALIGN_NOT,
615 int flags = wxDATAVIEW_COL_RESIZABLE );
616 wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
617 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
618 wxAlignment align = wxALIGN_CENTER,
619 int flags = wxDATAVIEW_COL_RESIZABLE );
620 wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
621 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
622 wxAlignment align = wxALIGN_CENTER,
623 int flags = wxDATAVIEW_COL_RESIZABLE );
624 wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column,
625 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
626 wxAlignment align = wxALIGN_NOT,
627 int flags = wxDATAVIEW_COL_RESIZABLE );
628 wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
629 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
630 wxAlignment align = wxALIGN_CENTER,
631 int flags = wxDATAVIEW_COL_RESIZABLE );
632
633 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
634 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
635 wxAlignment align = wxALIGN_NOT,
636 int flags = wxDATAVIEW_COL_RESIZABLE );
637 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
638 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
639 wxAlignment align = wxALIGN_NOT,
640 int flags = wxDATAVIEW_COL_RESIZABLE );
641 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
642 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
643 wxAlignment align = wxALIGN_CENTER,
644 int flags = wxDATAVIEW_COL_RESIZABLE );
645 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
646 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
647 wxAlignment align = wxALIGN_CENTER,
648 int flags = wxDATAVIEW_COL_RESIZABLE );
649 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
650 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
651 wxAlignment align = wxALIGN_NOT,
652 int flags = wxDATAVIEW_COL_RESIZABLE );
653 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
654 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
655 wxAlignment align = wxALIGN_CENTER,
656 int flags = wxDATAVIEW_COL_RESIZABLE );
657 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
658 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
659 wxAlignment align = wxALIGN_NOT,
660 int flags = wxDATAVIEW_COL_RESIZABLE );
661 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
662 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
663 wxAlignment align = wxALIGN_NOT,
664 int flags = wxDATAVIEW_COL_RESIZABLE );
665 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
666 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
667 wxAlignment align = wxALIGN_CENTER,
668 int flags = wxDATAVIEW_COL_RESIZABLE );
669 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
670 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
671 wxAlignment align = wxALIGN_CENTER,
672 int flags = wxDATAVIEW_COL_RESIZABLE );
673 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
674 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
675 wxAlignment align = wxALIGN_NOT,
676 int flags = wxDATAVIEW_COL_RESIZABLE );
677 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
678 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
679 wxAlignment align = wxALIGN_CENTER,
680 int flags = wxDATAVIEW_COL_RESIZABLE );
681
682
683 virtual bool PrependColumn( wxDataViewColumn *col );
684 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
685 virtual bool AppendColumn( wxDataViewColumn *col );
686
687 virtual unsigned int GetColumnCount() const = 0;
688 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
689 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
690
691 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
692 virtual bool ClearColumns() = 0;
693
694 void SetExpanderColumn( wxDataViewColumn *col )
695 { m_expander_column = col ; DoSetExpanderColumn(); }
696 wxDataViewColumn *GetExpanderColumn() const
697 { return m_expander_column; }
698
699 virtual wxDataViewColumn *GetSortingColumn() const = 0;
700
701 void SetIndent( int indent )
702 { m_indent = indent ; DoSetIndent(); }
703 int GetIndent() const
704 { return m_indent; }
705
706 virtual wxDataViewItem GetSelection() const = 0;
707 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
708 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
709 virtual void Select( const wxDataViewItem & item ) = 0;
710 virtual void Unselect( const wxDataViewItem & item ) = 0;
711 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
712
713 virtual void SelectAll() = 0;
714 virtual void UnselectAll() = 0;
715
716 virtual void Expand( const wxDataViewItem & item ) = 0;
717 virtual void ExpandAncestors( const wxDataViewItem & item );
718 virtual void Collapse( const wxDataViewItem & item ) = 0;
719 virtual bool IsExpanded( const wxDataViewItem & item ) const = 0;
720
721 virtual void EnsureVisible( const wxDataViewItem & item,
722 const wxDataViewColumn *column = NULL ) = 0;
723 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
724 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
725
726 protected:
727 virtual void DoSetExpanderColumn() = 0 ;
728 virtual void DoSetIndent() = 0;
729
730 private:
731 wxDataViewModel *m_model;
732 wxDataViewColumn *m_expander_column;
733 int m_indent ;
734
735 protected:
736 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
737 };
738
739 // ----------------------------------------------------------------------------
740 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
741 // ----------------------------------------------------------------------------
742
743 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
744 {
745 public:
746 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
747 : wxNotifyEvent(commandType, winid),
748 m_item(0),
749 m_col(-1),
750 m_model(NULL),
751 m_value(wxNullVariant),
752 m_column(NULL),
753 m_pos(-1,-1)
754 { }
755
756 wxDataViewEvent(const wxDataViewEvent& event)
757 : wxNotifyEvent(event),
758 m_item(event.m_item),
759 m_col(event.m_col),
760 m_model(event.m_model),
761 m_value(event.m_value),
762 m_column(event.m_column),
763 m_pos(m_pos)
764 { }
765
766 wxDataViewItem GetItem() const { return m_item; }
767 void SetItem( const wxDataViewItem &item ) { m_item = item; }
768
769 int GetColumn() const { return m_col; }
770 void SetColumn( int col ) { m_col = col; }
771
772 wxDataViewModel* GetModel() const { return m_model; }
773 void SetModel( wxDataViewModel *model ) { m_model = model; }
774
775 const wxVariant &GetValue() const { return m_value; }
776 void SetValue( const wxVariant &value ) { m_value = value; }
777
778 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
779 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
780 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
781
782 // for wxEVT_DATAVIEW_CONTEXT_MENU only
783 wxPoint GetPosition() const { return m_pos; }
784 void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; }
785
786 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
787
788 protected:
789 wxDataViewItem m_item;
790 int m_col;
791 wxDataViewModel *m_model;
792 wxVariant m_value;
793 wxDataViewColumn *m_column;
794 wxPoint m_pos;
795
796 private:
797 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
798 };
799
800 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent )
801
802 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent )
803 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent )
804 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent )
805 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent )
806 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent )
807 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent )
808 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent )
809 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent )
810
811 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent )
812
813 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent )
814 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent )
815 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent )
816 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent )
817
818 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
819
820 #define wxDataViewEventHandler(func) \
821 wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func)
822
823 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
824 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
825
826 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
827
828 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
829 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
830 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
831 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
832 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
833 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
834 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
835 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
836
837 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
838
839 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
840 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
841 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
842 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
843
844
845 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
846 // this symbol doesn't follow the convention for wxUSE_XXX symbols which
847 // are normally always defined as either 0 or 1, so its use is deprecated
848 // and it only exists for backwards compatibility, don't use it any more
849 // and use wxHAS_GENERIC_DATAVIEWCTRL instead
850 #define wxUSE_GENERICDATAVIEWCTRL
851
852 #include "wx/generic/dataview.h"
853 #elif defined(__WXGTK20__)
854 #include "wx/gtk/dataview.h"
855 #elif defined(__WXMAC__)
856 #include "wx/osx/dataview.h"
857 #else
858 #error "unknown native wxDataViewCtrl implementation"
859 #endif
860
861 // -------------------------------------
862 // wxDataViewSpinRenderer
863 // -------------------------------------
864
865 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
866 {
867 public:
868 wxDataViewSpinRenderer( int min, int max,
869 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
870 int alignment = wxDVR_DEFAULT_ALIGNMENT );
871 virtual bool HasEditorCtrl() { return true; }
872 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
873 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
874 virtual bool Render( wxRect rect, wxDC *dc, int state );
875 virtual wxSize GetSize() const;
876 virtual bool SetValue( const wxVariant &value );
877 virtual bool GetValue( wxVariant &value ) const;
878
879 private:
880 long m_data;
881 long m_min,m_max;
882 };
883
884 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
885
886 // -------------------------------------
887 // wxDataViewChoiceRenderer
888 // -------------------------------------
889
890 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
891 {
892 public:
893 wxDataViewChoiceRenderer( const wxArrayString &choices,
894 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
895 int alignment = wxDVR_DEFAULT_ALIGNMENT );
896 virtual bool HasEditorCtrl() { return true; }
897 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
898 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
899 virtual bool Render( wxRect rect, wxDC *dc, int state );
900 virtual wxSize GetSize() const;
901 virtual bool SetValue( const wxVariant &value );
902 virtual bool GetValue( wxVariant &value ) const;
903
904 private:
905 wxArrayString m_choices;
906 wxString m_data;
907 };
908
909 #endif
910
911 //-----------------------------------------------------------------------------
912 // wxDataViewListStore
913 //-----------------------------------------------------------------------------
914
915 class WXDLLIMPEXP_ADV wxDataViewListStoreLine
916 {
917 public:
918 wxDataViewListStoreLine( wxClientData *data = NULL )
919 {
920 m_data = data;
921 }
922 virtual ~wxDataViewListStoreLine()
923 {
924 delete m_data;
925 }
926
927 void SetData( wxClientData *data )
928 { if (m_data) delete m_data; m_data = data; }
929 wxClientData *GetData() const
930 { return m_data; }
931
932 wxVector<wxVariant> m_values;
933
934 private:
935 wxClientData *m_data;
936 };
937
938
939 class WXDLLIMPEXP_ADV wxDataViewListStore: public wxDataViewIndexListModel
940 {
941 public:
942 wxDataViewListStore();
943 ~wxDataViewListStore();
944
945 void PrependColumn( const wxString &varianttype );
946 void InsertColumn( unsigned int pos, const wxString &varianttype );
947 void AppendColumn( const wxString &varianttype );
948
949 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
950 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
951 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
952 void DeleteItem( unsigned pos );
953 void DeleteAllItems();
954
955 // override base virtuals
956
957 virtual unsigned int GetColumnCount() const;
958
959 virtual wxString GetColumnType( unsigned int col ) const;
960
961 virtual void GetValueByRow( wxVariant &value,
962 unsigned int row, unsigned int col ) const;
963
964 virtual bool SetValueByRow( const wxVariant &value,
965 unsigned int row, unsigned int col );
966
967
968 public:
969 wxVector<wxDataViewListStoreLine*> m_data;
970 wxArrayString m_cols;
971 };
972
973 //-----------------------------------------------------------------------------
974
975 class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl
976 {
977 public:
978 wxDataViewListCtrl();
979 wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
980 const wxPoint& pos = wxDefaultPosition,
981 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
982 const wxValidator& validator = wxDefaultValidator );
983 ~wxDataViewListCtrl();
984
985 bool Create( wxWindow *parent, wxWindowID id,
986 const wxPoint& pos = wxDefaultPosition,
987 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
988 const wxValidator& validator = wxDefaultValidator );
989
990 wxDataViewListStore *GetStore()
991 { return (wxDataViewListStore*) GetModel(); }
992 const wxDataViewListStore *GetStore() const
993 { return (const wxDataViewListStore*) GetModel(); }
994
995 void AppendCol( wxDataViewColumn *column, const wxString &varianttype );
996 void PrependCol( wxDataViewColumn *column, const wxString &varianttype );
997 void InsertCol( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
998
999 wxDataViewColumn *AppendTextCol( const wxString &label,
1000 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1001 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1002 wxDataViewColumn *AppendToggleCol( const wxString &label,
1003 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
1004 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1005 wxDataViewColumn *AppendProgressCol( const wxString &label,
1006 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1007 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1008 wxDataViewColumn *AppendIconTextCol( const wxString &label,
1009 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1010 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1011
1012 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1013 { GetStore()->AppendItem( values, data ); }
1014 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1015 { GetStore()->PrependItem( values, data ); }
1016 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL )
1017 { GetStore()->InsertItem( row, values, data ); }
1018 void DeleteItem( unsigned row )
1019 { GetStore()->DeleteItem( row ); }
1020 void DeleteAllItems()
1021 { GetStore()->DeleteAllItems(); }
1022
1023 void SetValue( const wxVariant &value, unsigned int row, unsigned int col )
1024 { GetStore()->SetValueByRow( value, row, col );
1025 GetStore()->RowValueChanged( row, col); }
1026 void GetValue( wxVariant &value, unsigned int row, unsigned int col )
1027 { GetStore()->GetValueByRow( value, row, col ); }
1028
1029 void SetTextValue( const wxString &value, unsigned int row, unsigned int col )
1030 { GetStore()->SetValueByRow( value, row, col );
1031 GetStore()->RowValueChanged( row, col); }
1032 wxString GetTextValue( unsigned int row, unsigned int col ) const
1033 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); }
1034
1035 void SetToggleValue( bool value, unsigned int row, unsigned int col )
1036 { GetStore()->SetValueByRow( value, row, col );
1037 GetStore()->RowValueChanged( row, col); }
1038 bool GetToggleValue( unsigned int row, unsigned int col ) const
1039 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
1040
1041 void OnSize( wxSizeEvent &event );
1042
1043 private:
1044 DECLARE_EVENT_TABLE()
1045 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl)
1046 };
1047
1048 //-----------------------------------------------------------------------------
1049 // wxDataViewTreeStore
1050 //-----------------------------------------------------------------------------
1051
1052 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
1053 {
1054 public:
1055 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
1056 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1057 virtual ~wxDataViewTreeStoreNode();
1058
1059 void SetText( const wxString &text )
1060 { m_text = text; }
1061 wxString GetText() const
1062 { return m_text; }
1063 void SetIcon( const wxIcon &icon )
1064 { m_icon = icon; }
1065 const wxIcon &GetIcon() const
1066 { return m_icon; }
1067 void SetData( wxClientData *data )
1068 { if (m_data) delete m_data; m_data = data; }
1069 wxClientData *GetData() const
1070 { return m_data; }
1071
1072 wxDataViewItem GetItem() const
1073 { return wxDataViewItem( (void*) this ); }
1074
1075 virtual bool IsContainer()
1076 { return false; }
1077
1078 wxDataViewTreeStoreNode *GetParent()
1079 { return m_parent; }
1080
1081 private:
1082 wxDataViewTreeStoreNode *m_parent;
1083 wxString m_text;
1084 wxIcon m_icon;
1085 wxClientData *m_data;
1086 };
1087
1088 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
1089 class WXDLLIMPEXP_ADV);
1090
1091 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
1092 {
1093 public:
1094 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
1095 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1096 wxClientData *data = NULL );
1097 virtual ~wxDataViewTreeStoreContainerNode();
1098
1099 const wxDataViewTreeStoreNodeList &GetChildren() const
1100 { return m_children; }
1101 wxDataViewTreeStoreNodeList &GetChildren()
1102 { return m_children; }
1103
1104 void SetExpandedIcon( const wxIcon &icon )
1105 { m_iconExpanded = icon; }
1106 const wxIcon &GetExpandedIcon() const
1107 { return m_iconExpanded; }
1108
1109 void SetExpanded( bool expanded = true )
1110 { m_isExpanded = expanded; }
1111 bool IsExpanded() const
1112 { return m_isExpanded; }
1113
1114 virtual bool IsContainer()
1115 { return true; }
1116
1117 private:
1118 wxDataViewTreeStoreNodeList m_children;
1119 wxIcon m_iconExpanded;
1120 bool m_isExpanded;
1121 };
1122
1123 //-----------------------------------------------------------------------------
1124
1125 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
1126 {
1127 public:
1128 wxDataViewTreeStore();
1129 ~wxDataViewTreeStore();
1130
1131 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1132 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1133 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1134 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1135 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1136 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1137
1138 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1139 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1140 wxClientData *data = NULL );
1141 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1142 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1143 wxClientData *data = NULL );
1144 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1145 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1146 wxClientData *data = NULL );
1147
1148 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
1149 int GetChildCount( const wxDataViewItem& parent ) const;
1150
1151 void SetItemText( const wxDataViewItem& item, const wxString &text );
1152 wxString GetItemText( const wxDataViewItem& item ) const;
1153 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1154 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
1155 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1156 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
1157 void SetItemData( const wxDataViewItem& item, wxClientData *data );
1158 wxClientData *GetItemData( const wxDataViewItem& item ) const;
1159
1160 void DeleteItem( const wxDataViewItem& item );
1161 void DeleteChildren( const wxDataViewItem& item );
1162 void DeleteAllItems();
1163
1164 // implement base methods
1165
1166 virtual void GetValue( wxVariant &variant,
1167 const wxDataViewItem &item, unsigned int col ) const;
1168 virtual bool SetValue( const wxVariant &variant,
1169 const wxDataViewItem &item, unsigned int col );
1170 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
1171 virtual bool IsContainer( const wxDataViewItem &item ) const;
1172 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
1173
1174 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1175 unsigned int column, bool ascending );
1176
1177 virtual bool HasDefaultCompare() const
1178 { return true; }
1179 virtual unsigned int GetColumnCount() const
1180 { return 1; };
1181 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
1182 { return wxT("wxDataViewIconText"); }
1183
1184 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
1185 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
1186 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
1187
1188 public:
1189 wxDataViewTreeStoreNode *m_root;
1190 };
1191
1192 //-----------------------------------------------------------------------------
1193
1194 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
1195 {
1196 public:
1197 wxDataViewTreeCtrl();
1198 wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
1199 const wxPoint& pos = wxDefaultPosition,
1200 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1201 const wxValidator& validator = wxDefaultValidator );
1202 ~wxDataViewTreeCtrl();
1203
1204 bool Create( wxWindow *parent, wxWindowID id,
1205 const wxPoint& pos = wxDefaultPosition,
1206 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1207 const wxValidator& validator = wxDefaultValidator );
1208
1209 wxDataViewTreeStore *GetStore()
1210 { return (wxDataViewTreeStore*) GetModel(); }
1211 const wxDataViewTreeStore *GetStore() const
1212 { return (const wxDataViewTreeStore*) GetModel(); }
1213
1214 void SetImageList( wxImageList *imagelist );
1215 wxImageList* GetImageList() { return m_imageList; }
1216
1217 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1218 const wxString &text, int icon = -1, wxClientData *data = NULL );
1219 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1220 const wxString &text, int icon = -1, wxClientData *data = NULL );
1221 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1222 const wxString &text, int icon = -1, wxClientData *data = NULL );
1223
1224 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1225 const wxString &text, int icon = -1, int expanded = -1,
1226 wxClientData *data = NULL );
1227 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1228 const wxString &text, int icon = -1, int expanded = -1,
1229 wxClientData *data = NULL );
1230 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1231 const wxString &text, int icon = -1, int expanded = -1,
1232 wxClientData *data = NULL );
1233
1234 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1235 { return GetStore()->GetNthChild(parent, pos); }
1236 int GetChildCount( const wxDataViewItem& parent ) const
1237 { return GetStore()->GetChildCount(parent); }
1238
1239 void SetItemText( const wxDataViewItem& item, const wxString &text );
1240 wxString GetItemText( const wxDataViewItem& item ) const
1241 { return GetStore()->GetItemText(item); }
1242 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1243 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const
1244 { return GetStore()->GetItemIcon(item); }
1245 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1246 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const
1247 { return GetStore()->GetItemExpandedIcon(item); }
1248 void SetItemData( const wxDataViewItem& item, wxClientData *data )
1249 { GetStore()->SetItemData(item,data); }
1250 wxClientData *GetItemData( const wxDataViewItem& item ) const
1251 { return GetStore()->GetItemData(item); }
1252
1253 void DeleteItem( const wxDataViewItem& item );
1254 void DeleteChildren( const wxDataViewItem& item );
1255 void DeleteAllItems();
1256
1257 void OnExpanded( wxDataViewEvent &event );
1258 void OnCollapsed( wxDataViewEvent &event );
1259 void OnSize( wxSizeEvent &event );
1260
1261 private:
1262 wxImageList *m_imageList;
1263
1264 private:
1265 DECLARE_EVENT_TABLE()
1266 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
1267 };
1268
1269 #endif // wxUSE_DATAVIEWCTRL
1270
1271 #endif
1272 // _WX_DATAVIEW_H_BASE_