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