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