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