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