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