]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
No real changes, just remove wxIsDebuggerRunning() stub from wxOSX.
[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/itemid.h"
25 #include "wx/weakref.h"
26 #include "wx/vector.h"
27 #include "wx/dataobj.h"
28 #include "wx/withimages.h"
29
30 class WXDLLIMPEXP_FWD_CORE wxImageList;
31
32 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
33 // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
34 #define wxHAS_GENERIC_DATAVIEWCTRL
35 #endif
36
37 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
38 // this symbol doesn't follow the convention for wxUSE_XXX symbols which
39 // are normally always defined as either 0 or 1, so its use is deprecated
40 // and it only exists for backwards compatibility, don't use it any more
41 // and use wxHAS_GENERIC_DATAVIEWCTRL instead
42 #define wxUSE_GENERICDATAVIEWCTRL
43 #endif
44
45 // ----------------------------------------------------------------------------
46 // wxDataViewCtrl globals
47 // ----------------------------------------------------------------------------
48
49 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
50 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
51 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
52 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
53 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
54
55 extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[];
56
57 // ----------------------------------------------------------------------------
58 // wxDataViewCtrl flags
59 // ----------------------------------------------------------------------------
60
61 // size of a wxDataViewRenderer without contents:
62 #define wxDVC_DEFAULT_RENDERER_SIZE 20
63
64 // the default width of new (text) columns:
65 #define wxDVC_DEFAULT_WIDTH 80
66
67 // the default width of new toggle columns:
68 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
69
70 // the default minimal width of the columns:
71 #define wxDVC_DEFAULT_MINWIDTH 30
72
73 // The default alignment of wxDataViewRenderers is to take
74 // the alignment from the column it owns.
75 #define wxDVR_DEFAULT_ALIGNMENT -1
76
77
78 // ---------------------------------------------------------
79 // wxDataViewItem
80 // ---------------------------------------------------------
81
82 // Make it a class and not a typedef to allow forward declaring it.
83 class wxDataViewItem : public wxItemId<void*>
84 {
85 public:
86 wxDataViewItem() : wxItemId<void*>() { }
87 wxEXPLICIT wxDataViewItem(void* pItem) : wxItemId<void*>(pItem) { }
88 };
89
90 WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
91
92 // ---------------------------------------------------------
93 // wxDataViewModelNotifier
94 // ---------------------------------------------------------
95
96 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
97 {
98 public:
99 wxDataViewModelNotifier() { m_owner = NULL; }
100 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
101
102 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
103 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
104 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
105 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
106 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
107 virtual bool ItemsChanged( const wxDataViewItemArray &items );
108 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
109 virtual bool Cleared() = 0;
110
111 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
112 virtual bool BeforeReset() { return true; }
113 virtual bool AfterReset() { return Cleared(); }
114
115 virtual void Resort() = 0;
116
117 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
118 wxDataViewModel *GetOwner() const { return m_owner; }
119
120 private:
121 wxDataViewModel *m_owner;
122 };
123
124
125
126 // ----------------------------------------------------------------------------
127 // wxDataViewItemAttr: a structure containing the visual attributes of an item
128 // ----------------------------------------------------------------------------
129
130 // TODO: this should be renamed to wxItemAttr or something general like this
131
132 class WXDLLIMPEXP_ADV wxDataViewItemAttr
133 {
134 public:
135 // ctors
136 wxDataViewItemAttr()
137 {
138 m_bold = false;
139 m_italic = false;
140 }
141
142 // setters
143 void SetColour(const wxColour& colour) { m_colour = colour; }
144 void SetBold( bool set ) { m_bold = set; }
145 void SetItalic( bool set ) { m_italic = set; }
146 void SetBackgroundColour(const wxColour& colour) { m_bgColour = colour; }
147
148 // accessors
149 bool HasColour() const { return m_colour.IsOk(); }
150 const wxColour& GetColour() const { return m_colour; }
151
152 bool HasFont() const { return m_bold || m_italic; }
153 bool GetBold() const { return m_bold; }
154 bool GetItalic() const { return m_italic; }
155
156 bool HasBackgroundColour() const { return m_bgColour.IsOk(); }
157 const wxColour& GetBackgroundColour() const { return m_bgColour; }
158
159 bool IsDefault() const { return !(HasColour() || HasFont() || HasBackgroundColour()); }
160
161 // Return the font based on the given one with this attribute applied to it.
162 wxFont GetEffectiveFont(const wxFont& font) const;
163
164 private:
165 wxColour m_colour;
166 bool m_bold;
167 bool m_italic;
168 wxColour m_bgColour;
169 };
170
171
172 // ---------------------------------------------------------
173 // wxDataViewModel
174 // ---------------------------------------------------------
175
176 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
177 class WXDLLIMPEXP_ADV);
178
179 class WXDLLIMPEXP_ADV wxDataViewModel: public wxRefCounter
180 {
181 public:
182 wxDataViewModel();
183
184 virtual unsigned int GetColumnCount() const = 0;
185
186 // return type as reported by wxVariant
187 virtual wxString GetColumnType( unsigned int col ) const = 0;
188
189 // get value into a wxVariant
190 virtual void GetValue( wxVariant &variant,
191 const wxDataViewItem &item, unsigned int col ) const = 0;
192
193 // return true if the given item has a value to display in the given
194 // column: this is always true except for container items which by default
195 // only show their label in the first column (but see HasContainerColumns())
196 bool HasValue(const wxDataViewItem& item, unsigned col) const
197 {
198 return col == 0 || !IsContainer(item) || HasContainerColumns(item);
199 }
200
201 // usually ValueChanged() should be called after changing the value in the
202 // model to update the control, ChangeValue() does it on its own while
203 // SetValue() does not -- so while you will override SetValue(), you should
204 // be usually calling ChangeValue()
205 virtual bool SetValue(const wxVariant &variant,
206 const wxDataViewItem &item,
207 unsigned int col) = 0;
208
209 bool ChangeValue(const wxVariant& variant,
210 const wxDataViewItem& item,
211 unsigned int col)
212 {
213 return SetValue(variant, item, col) && ValueChanged(item, col);
214 }
215
216 // Get text attribute, return false of default attributes should be used
217 virtual bool GetAttr(const wxDataViewItem &WXUNUSED(item),
218 unsigned int WXUNUSED(col),
219 wxDataViewItemAttr &WXUNUSED(attr)) const
220 {
221 return false;
222 }
223
224 // Override this if you want to disable specific items
225 virtual bool IsEnabled(const wxDataViewItem &WXUNUSED(item),
226 unsigned int WXUNUSED(col)) const
227 {
228 return true;
229 }
230
231 // define hierachy
232 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
233 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
234 // Is the container just a header or an item with all columns
235 virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const
236 { return false; }
237 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0;
238
239 // delegated notifiers
240 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
241 bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
242 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
243 bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
244 bool ItemChanged( const wxDataViewItem &item );
245 bool ItemsChanged( const wxDataViewItemArray &items );
246 bool ValueChanged( const wxDataViewItem &item, unsigned int col );
247 bool Cleared();
248
249 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
250 bool BeforeReset();
251 bool AfterReset();
252
253
254 // delegated action
255 virtual void Resort();
256
257 void AddNotifier( wxDataViewModelNotifier *notifier );
258 void RemoveNotifier( wxDataViewModelNotifier *notifier );
259
260 // default compare function
261 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
262 unsigned int column, bool ascending ) const;
263 virtual bool HasDefaultCompare() const { return false; }
264
265 // internal
266 virtual bool IsListModel() const { return false; }
267 virtual bool IsVirtualListModel() const { return false; }
268
269 protected:
270 // the user should not delete this class directly: he should use DecRef() instead!
271 virtual ~wxDataViewModel() { }
272
273 wxDataViewModelNotifiers m_notifiers;
274 };
275
276 // ----------------------------------------------------------------------------
277 // wxDataViewListModel: a model of a list, i.e. flat data structure without any
278 // branches/containers, used as base class by wxDataViewIndexListModel and
279 // wxDataViewVirtualListModel
280 // ----------------------------------------------------------------------------
281
282 class WXDLLIMPEXP_ADV wxDataViewListModel : public wxDataViewModel
283 {
284 public:
285 // derived classes should override these methods instead of
286 // {Get,Set}Value() and GetAttr() inherited from the base class
287
288 virtual void GetValueByRow(wxVariant &variant,
289 unsigned row, unsigned col) const = 0;
290
291 virtual bool SetValueByRow(const wxVariant &variant,
292 unsigned row, unsigned col) = 0;
293
294 virtual bool
295 GetAttrByRow(unsigned WXUNUSED(row), unsigned WXUNUSED(col),
296 wxDataViewItemAttr &WXUNUSED(attr)) const
297 {
298 return false;
299 }
300
301 virtual bool IsEnabledByRow(unsigned int WXUNUSED(row),
302 unsigned int WXUNUSED(col)) const
303 {
304 return true;
305 }
306
307
308 // helper methods provided by list models only
309 virtual unsigned GetRow( const wxDataViewItem &item ) const = 0;
310
311 // returns the number of rows
312 virtual unsigned int GetCount() const = 0;
313
314 // implement some base class pure virtual directly
315 virtual wxDataViewItem
316 GetParent( const wxDataViewItem & WXUNUSED(item) ) const
317 {
318 // items never have valid parent in this model
319 return wxDataViewItem();
320 }
321
322 virtual bool IsContainer( const wxDataViewItem &item ) const
323 {
324 // only the invisible (and invalid) root item has children
325 return !item.IsOk();
326 }
327
328 // and implement some others by forwarding them to our own ones
329 virtual void GetValue( wxVariant &variant,
330 const wxDataViewItem &item, unsigned int col ) const
331 {
332 GetValueByRow(variant, GetRow(item), col);
333 }
334
335 virtual bool SetValue( const wxVariant &variant,
336 const wxDataViewItem &item, unsigned int col )
337 {
338 return SetValueByRow( variant, GetRow(item), col );
339 }
340
341 virtual bool GetAttr(const wxDataViewItem &item, unsigned int col,
342 wxDataViewItemAttr &attr) const
343 {
344 return GetAttrByRow( GetRow(item), col, attr );
345 }
346
347 virtual bool IsEnabled(const wxDataViewItem &item, unsigned int col) const
348 {
349 return IsEnabledByRow( GetRow(item), col );
350 }
351
352
353 virtual bool IsListModel() const { return true; }
354 };
355
356 // ---------------------------------------------------------
357 // wxDataViewIndexListModel
358 // ---------------------------------------------------------
359
360 class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewListModel
361 {
362 public:
363 wxDataViewIndexListModel( unsigned int initial_size = 0 );
364
365 void RowPrepended();
366 void RowInserted( unsigned int before );
367 void RowAppended();
368 void RowDeleted( unsigned int row );
369 void RowsDeleted( const wxArrayInt &rows );
370 void RowChanged( unsigned int row );
371 void RowValueChanged( unsigned int row, unsigned int col );
372 void Reset( unsigned int new_size );
373
374 // convert to/from row/wxDataViewItem
375
376 virtual unsigned GetRow( const wxDataViewItem &item ) const;
377 wxDataViewItem GetItem( unsigned int row ) const;
378
379 // implement base methods
380 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
381
382 unsigned int GetCount() const { return m_hash.GetCount(); }
383
384 private:
385 wxDataViewItemArray m_hash;
386 unsigned int m_nextFreeID;
387 bool m_ordered;
388 };
389
390 // ---------------------------------------------------------
391 // wxDataViewVirtualListModel
392 // ---------------------------------------------------------
393
394 #ifdef __WXMAC__
395 // better than nothing
396 typedef wxDataViewIndexListModel wxDataViewVirtualListModel;
397 #else
398
399 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewListModel
400 {
401 public:
402 wxDataViewVirtualListModel( unsigned int initial_size = 0 );
403
404 void RowPrepended();
405 void RowInserted( unsigned int before );
406 void RowAppended();
407 void RowDeleted( unsigned int row );
408 void RowsDeleted( const wxArrayInt &rows );
409 void RowChanged( unsigned int row );
410 void RowValueChanged( unsigned int row, unsigned int col );
411 void Reset( unsigned int new_size );
412
413 // convert to/from row/wxDataViewItem
414
415 virtual unsigned GetRow( const wxDataViewItem &item ) const;
416 wxDataViewItem GetItem( unsigned int row ) const;
417
418 // compare based on index
419
420 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
421 unsigned int column, bool ascending ) const;
422 virtual bool HasDefaultCompare() const;
423
424 // implement base methods
425 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
426
427 unsigned int GetCount() const { return m_size; }
428
429 // internal
430 virtual bool IsVirtualListModel() const { return true; }
431
432 private:
433 unsigned int m_size;
434 bool m_ordered;
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 #endif
766 { }
767
768 wxDataViewEvent(const wxDataViewEvent& event)
769 : wxNotifyEvent(event),
770 m_item(event.m_item),
771 m_col(event.m_col),
772 m_model(event.m_model),
773 m_value(event.m_value),
774 m_column(event.m_column),
775 m_pos(event.m_pos),
776 m_cacheFrom(event.m_cacheFrom),
777 m_cacheTo(event.m_cacheTo),
778 m_editCancelled(event.m_editCancelled)
779 #if wxUSE_DRAG_AND_DROP
780 , m_dataObject(event.m_dataObject),
781 m_dataFormat(event.m_dataFormat),
782 m_dataBuffer(event.m_dataBuffer),
783 m_dataSize(event.m_dataSize)
784 #endif
785 { }
786
787 wxDataViewItem GetItem() const { return m_item; }
788 void SetItem( const wxDataViewItem &item ) { m_item = item; }
789
790 int GetColumn() const { return m_col; }
791 void SetColumn( int col ) { m_col = col; }
792
793 wxDataViewModel* GetModel() const { return m_model; }
794 void SetModel( wxDataViewModel *model ) { m_model = model; }
795
796 const wxVariant &GetValue() const { return m_value; }
797 void SetValue( const wxVariant &value ) { m_value = value; }
798
799 // for wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE only
800 bool IsEditCancelled() const { return m_editCancelled; }
801 void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
802
803 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
804 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
805 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
806
807 // for wxEVT_DATAVIEW_CONTEXT_MENU only
808 wxPoint GetPosition() const { return m_pos; }
809 void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; }
810
811 // For wxEVT_COMMAND_DATAVIEW_CACHE_HINT
812 int GetCacheFrom() const { return m_cacheFrom; }
813 int GetCacheTo() const { return m_cacheTo; }
814 void SetCache(int from, int to) { m_cacheFrom = from; m_cacheTo = to; }
815
816
817 #if wxUSE_DRAG_AND_DROP
818 // For drag operations
819 void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; }
820 wxDataObject *GetDataObject() const { return m_dataObject; }
821
822 // For drop operations
823 void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; }
824 wxDataFormat GetDataFormat() const { return m_dataFormat; }
825 void SetDataSize( size_t size ) { m_dataSize = size; }
826 size_t GetDataSize() const { return m_dataSize; }
827 void SetDataBuffer( void* buf ) { m_dataBuffer = buf;}
828 void *GetDataBuffer() const { return m_dataBuffer; }
829 #endif // wxUSE_DRAG_AND_DROP
830
831 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
832
833 protected:
834 wxDataViewItem m_item;
835 int m_col;
836 wxDataViewModel *m_model;
837 wxVariant m_value;
838 wxDataViewColumn *m_column;
839 wxPoint m_pos;
840 int m_cacheFrom;
841 int m_cacheTo;
842 bool m_editCancelled;
843
844 #if wxUSE_DRAG_AND_DROP
845 wxDataObject *m_dataObject;
846
847 wxDataFormat m_dataFormat;
848 void* m_dataBuffer;
849 size_t m_dataSize;
850 #endif // wxUSE_DRAG_AND_DROP
851
852 private:
853 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
854 };
855
856 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
857
858 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
859 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
860 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
861 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
862 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
863 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
864 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
865 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
866 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
867
868 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
869
870 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
871 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
872 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
873 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
874
875 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent );
876
877 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
878 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
879 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
880
881 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
882
883 #define wxDataViewEventHandler(func) \
884 wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func)
885
886 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
887 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
888
889 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
890
891 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
892 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
893 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
894 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
895 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
896 #define EVT_DATAVIEW_ITEM_START_EDITING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_START_EDITING, id, fn)
897 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
898 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
899 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
900
901 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
902
903 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
904 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
905 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
906 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
907 #define EVT_DATAVIEW_CACHE_HINT(id, fn) wx__DECLARE_DATAVIEWEVT(CACHE_HINT, id, fn)
908
909 #define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn)
910 #define EVT_DATAVIEW_ITEM_DROP_POSSIBLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP_POSSIBLE, id, fn)
911 #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
912
913 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
914 #include "wx/generic/dataview.h"
915 #elif defined(__WXGTK20__)
916 #include "wx/gtk/dataview.h"
917 #elif defined(__WXMAC__)
918 #include "wx/osx/dataview.h"
919 #else
920 #error "unknown native wxDataViewCtrl implementation"
921 #endif
922
923 //-----------------------------------------------------------------------------
924 // wxDataViewListStore
925 //-----------------------------------------------------------------------------
926
927 class WXDLLIMPEXP_ADV wxDataViewListStoreLine
928 {
929 public:
930 wxDataViewListStoreLine( wxClientData *data = NULL )
931 {
932 m_data = data;
933 }
934 virtual ~wxDataViewListStoreLine()
935 {
936 delete m_data;
937 }
938
939 void SetData( wxClientData *data )
940 { if (m_data) delete m_data; m_data = data; }
941 wxClientData *GetData() const
942 { return m_data; }
943
944 wxVector<wxVariant> m_values;
945
946 private:
947 wxClientData *m_data;
948 };
949
950
951 class WXDLLIMPEXP_ADV wxDataViewListStore: public wxDataViewIndexListModel
952 {
953 public:
954 wxDataViewListStore();
955 ~wxDataViewListStore();
956
957 void PrependColumn( const wxString &varianttype );
958 void InsertColumn( unsigned int pos, const wxString &varianttype );
959 void AppendColumn( const wxString &varianttype );
960
961 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
962 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
963 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
964 void DeleteItem( unsigned int pos );
965 void DeleteAllItems();
966
967 // override base virtuals
968
969 virtual unsigned int GetColumnCount() const;
970
971 virtual wxString GetColumnType( unsigned int col ) const;
972
973 virtual void GetValueByRow( wxVariant &value,
974 unsigned int row, unsigned int col ) const;
975
976 virtual bool SetValueByRow( const wxVariant &value,
977 unsigned int row, unsigned int col );
978
979
980 public:
981 wxVector<wxDataViewListStoreLine*> m_data;
982 wxArrayString m_cols;
983 };
984
985 //-----------------------------------------------------------------------------
986
987 class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl
988 {
989 public:
990 wxDataViewListCtrl();
991 wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
992 const wxPoint& pos = wxDefaultPosition,
993 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
994 const wxValidator& validator = wxDefaultValidator );
995 ~wxDataViewListCtrl();
996
997 bool Create( wxWindow *parent, wxWindowID id,
998 const wxPoint& pos = wxDefaultPosition,
999 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1000 const wxValidator& validator = wxDefaultValidator );
1001
1002 wxDataViewListStore *GetStore()
1003 { return (wxDataViewListStore*) GetModel(); }
1004 const wxDataViewListStore *GetStore() const
1005 { return (const wxDataViewListStore*) GetModel(); }
1006
1007 int ItemToRow(const wxDataViewItem &item) const
1008 { return item.IsOk() ? (int)GetStore()->GetRow(item) : wxNOT_FOUND; }
1009 wxDataViewItem RowToItem(int row) const
1010 { return row == wxNOT_FOUND ? wxDataViewItem() : GetStore()->GetItem(row); }
1011
1012 int GetSelectedRow() const
1013 { return ItemToRow(GetSelection()); }
1014 void SelectRow(unsigned row)
1015 { Select(RowToItem(row)); }
1016 void UnselectRow(unsigned row)
1017 { Unselect(RowToItem(row)); }
1018 bool IsRowSelected(unsigned row) const
1019 { return IsSelected(RowToItem(row)); }
1020
1021 bool AppendColumn( wxDataViewColumn *column, const wxString &varianttype );
1022 bool PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
1023 bool InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
1024
1025 // overridden from base class
1026 virtual bool PrependColumn( wxDataViewColumn *col );
1027 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
1028 virtual bool AppendColumn( wxDataViewColumn *col );
1029
1030 wxDataViewColumn *AppendTextColumn( const wxString &label,
1031 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1032 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1033 wxDataViewColumn *AppendToggleColumn( const wxString &label,
1034 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
1035 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1036 wxDataViewColumn *AppendProgressColumn( const wxString &label,
1037 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1038 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1039 wxDataViewColumn *AppendIconTextColumn( const wxString &label,
1040 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1041 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1042
1043 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1044 { GetStore()->AppendItem( values, data ); }
1045 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1046 { GetStore()->PrependItem( values, data ); }
1047 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL )
1048 { GetStore()->InsertItem( row, values, data ); }
1049 void DeleteItem( unsigned row )
1050 { GetStore()->DeleteItem( row ); }
1051 void DeleteAllItems()
1052 { GetStore()->DeleteAllItems(); }
1053
1054 void SetValue( const wxVariant &value, unsigned int row, unsigned int col )
1055 { GetStore()->SetValueByRow( value, row, col );
1056 GetStore()->RowValueChanged( row, col); }
1057 void GetValue( wxVariant &value, unsigned int row, unsigned int col )
1058 { GetStore()->GetValueByRow( value, row, col ); }
1059
1060 void SetTextValue( const wxString &value, unsigned int row, unsigned int col )
1061 { GetStore()->SetValueByRow( value, row, col );
1062 GetStore()->RowValueChanged( row, col); }
1063 wxString GetTextValue( unsigned int row, unsigned int col ) const
1064 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); }
1065
1066 void SetToggleValue( bool value, unsigned int row, unsigned int col )
1067 { GetStore()->SetValueByRow( value, row, col );
1068 GetStore()->RowValueChanged( row, col); }
1069 bool GetToggleValue( unsigned int row, unsigned int col ) const
1070 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
1071
1072 void OnSize( wxSizeEvent &event );
1073
1074 private:
1075 DECLARE_EVENT_TABLE()
1076 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl)
1077 };
1078
1079 //-----------------------------------------------------------------------------
1080 // wxDataViewTreeStore
1081 //-----------------------------------------------------------------------------
1082
1083 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
1084 {
1085 public:
1086 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
1087 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1088 virtual ~wxDataViewTreeStoreNode();
1089
1090 void SetText( const wxString &text )
1091 { m_text = text; }
1092 wxString GetText() const
1093 { return m_text; }
1094 void SetIcon( const wxIcon &icon )
1095 { m_icon = icon; }
1096 const wxIcon &GetIcon() const
1097 { return m_icon; }
1098 void SetData( wxClientData *data )
1099 { if (m_data) delete m_data; m_data = data; }
1100 wxClientData *GetData() const
1101 { return m_data; }
1102
1103 wxDataViewItem GetItem() const
1104 { return wxDataViewItem( (void*) this ); }
1105
1106 virtual bool IsContainer()
1107 { return false; }
1108
1109 wxDataViewTreeStoreNode *GetParent()
1110 { return m_parent; }
1111
1112 private:
1113 wxDataViewTreeStoreNode *m_parent;
1114 wxString m_text;
1115 wxIcon m_icon;
1116 wxClientData *m_data;
1117 };
1118
1119 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
1120 class WXDLLIMPEXP_ADV);
1121
1122 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
1123 {
1124 public:
1125 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
1126 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1127 wxClientData *data = NULL );
1128 virtual ~wxDataViewTreeStoreContainerNode();
1129
1130 const wxDataViewTreeStoreNodeList &GetChildren() const
1131 { return m_children; }
1132 wxDataViewTreeStoreNodeList &GetChildren()
1133 { return m_children; }
1134
1135 void SetExpandedIcon( const wxIcon &icon )
1136 { m_iconExpanded = icon; }
1137 const wxIcon &GetExpandedIcon() const
1138 { return m_iconExpanded; }
1139
1140 void SetExpanded( bool expanded = true )
1141 { m_isExpanded = expanded; }
1142 bool IsExpanded() const
1143 { return m_isExpanded; }
1144
1145 virtual bool IsContainer()
1146 { return true; }
1147
1148 private:
1149 wxDataViewTreeStoreNodeList m_children;
1150 wxIcon m_iconExpanded;
1151 bool m_isExpanded;
1152 };
1153
1154 //-----------------------------------------------------------------------------
1155
1156 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
1157 {
1158 public:
1159 wxDataViewTreeStore();
1160 ~wxDataViewTreeStore();
1161
1162 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1163 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1164 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1165 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1166 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1167 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1168
1169 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1170 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1171 wxClientData *data = NULL );
1172 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1173 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1174 wxClientData *data = NULL );
1175 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1176 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1177 wxClientData *data = NULL );
1178
1179 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
1180 int GetChildCount( const wxDataViewItem& parent ) const;
1181
1182 void SetItemText( const wxDataViewItem& item, const wxString &text );
1183 wxString GetItemText( const wxDataViewItem& item ) const;
1184 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1185 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
1186 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1187 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
1188 void SetItemData( const wxDataViewItem& item, wxClientData *data );
1189 wxClientData *GetItemData( const wxDataViewItem& item ) const;
1190
1191 void DeleteItem( const wxDataViewItem& item );
1192 void DeleteChildren( const wxDataViewItem& item );
1193 void DeleteAllItems();
1194
1195 // implement base methods
1196
1197 virtual void GetValue( wxVariant &variant,
1198 const wxDataViewItem &item, unsigned int col ) const;
1199 virtual bool SetValue( const wxVariant &variant,
1200 const wxDataViewItem &item, unsigned int col );
1201 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
1202 virtual bool IsContainer( const wxDataViewItem &item ) const;
1203 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
1204
1205 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1206 unsigned int column, bool ascending ) const;
1207
1208 virtual bool HasDefaultCompare() const
1209 { return true; }
1210 virtual unsigned int GetColumnCount() const
1211 { return 1; }
1212 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
1213 { return wxT("wxDataViewIconText"); }
1214
1215 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
1216 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
1217 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
1218
1219 public:
1220 wxDataViewTreeStoreNode *m_root;
1221 };
1222
1223 //-----------------------------------------------------------------------------
1224
1225 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl,
1226 public wxWithImages
1227 {
1228 public:
1229 wxDataViewTreeCtrl() { }
1230 wxDataViewTreeCtrl(wxWindow *parent,
1231 wxWindowID id,
1232 const wxPoint& pos = wxDefaultPosition,
1233 const wxSize& size = wxDefaultSize,
1234 long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1235 const wxValidator& validator = wxDefaultValidator)
1236 {
1237 Create(parent, id, pos, size, style, validator);
1238 }
1239
1240 bool Create(wxWindow *parent,
1241 wxWindowID id,
1242 const wxPoint& pos = wxDefaultPosition,
1243 const wxSize& size = wxDefaultSize,
1244 long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1245 const wxValidator& validator = wxDefaultValidator);
1246
1247 wxDataViewTreeStore *GetStore()
1248 { return (wxDataViewTreeStore*) GetModel(); }
1249 const wxDataViewTreeStore *GetStore() const
1250 { return (const wxDataViewTreeStore*) GetModel(); }
1251
1252 bool IsContainer( const wxDataViewItem& item ) const
1253 { return GetStore()->IsContainer(item); }
1254
1255 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1256 const wxString &text, int icon = NO_IMAGE, wxClientData *data = NULL );
1257 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1258 const wxString &text, int icon = NO_IMAGE, wxClientData *data = NULL );
1259 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1260 const wxString &text, int icon = NO_IMAGE, wxClientData *data = NULL );
1261
1262 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1263 const wxString &text, int icon = NO_IMAGE, int expanded = NO_IMAGE,
1264 wxClientData *data = NULL );
1265 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1266 const wxString &text, int icon = NO_IMAGE, int expanded = NO_IMAGE,
1267 wxClientData *data = NULL );
1268 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1269 const wxString &text, int icon = NO_IMAGE, int expanded = NO_IMAGE,
1270 wxClientData *data = NULL );
1271
1272 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1273 { return GetStore()->GetNthChild(parent, pos); }
1274 int GetChildCount( const wxDataViewItem& parent ) const
1275 { return GetStore()->GetChildCount(parent); }
1276
1277 void SetItemText( const wxDataViewItem& item, const wxString &text );
1278 wxString GetItemText( const wxDataViewItem& item ) const
1279 { return GetStore()->GetItemText(item); }
1280 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1281 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const
1282 { return GetStore()->GetItemIcon(item); }
1283 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1284 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const
1285 { return GetStore()->GetItemExpandedIcon(item); }
1286 void SetItemData( const wxDataViewItem& item, wxClientData *data )
1287 { GetStore()->SetItemData(item,data); }
1288 wxClientData *GetItemData( const wxDataViewItem& item ) const
1289 { return GetStore()->GetItemData(item); }
1290
1291 void DeleteItem( const wxDataViewItem& item );
1292 void DeleteChildren( const wxDataViewItem& item );
1293 void DeleteAllItems();
1294
1295 void OnExpanded( wxDataViewEvent &event );
1296 void OnCollapsed( wxDataViewEvent &event );
1297 void OnSize( wxSizeEvent &event );
1298
1299 private:
1300 DECLARE_EVENT_TABLE()
1301 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
1302 };
1303
1304 #endif // wxUSE_DATAVIEWCTRL
1305
1306 #endif
1307 // _WX_DATAVIEW_H_BASE_