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