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