]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
17544e7d533f742e5ee29df2ebcb4371134df9aa
[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/bitmap.h"
22 #include "wx/variant.h"
23 #include "wx/listctrl.h"
24 #include "wx/dynarray.h"
25 #include "wx/icon.h"
26
27 #if defined(__WXGTK20__)
28 // for testing
29 // #define wxUSE_GENERICDATAVIEWCTRL 1
30 #elif defined(__WXMAC__)
31 #else
32 #define wxUSE_GENERICDATAVIEWCTRL 1
33 #endif
34
35 // ----------------------------------------------------------------------------
36 // wxDataViewCtrl flags
37 // ----------------------------------------------------------------------------
38
39 // ----------------------------------------------------------------------------
40 // wxDataViewCtrl globals
41 // ----------------------------------------------------------------------------
42
43 class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
44 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
45 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
48 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
49
50 extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
51
52 // the default width of new (text) columns:
53 #define wxDVC_DEFAULT_WIDTH 80
54
55 // the default width of new toggle columns:
56 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
57
58 // the default minimal width of the columns:
59 #define wxDVC_DEFAULT_MINWIDTH 30
60
61 // the default alignment of wxDataViewRenderers:
62 #define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_TOP)
63
64
65 // ---------------------------------------------------------
66 // wxDataViewItem
67 // ---------------------------------------------------------
68
69 class WXDLLIMPEXP_ADV wxDataViewItem
70 {
71 public:
72 wxDataViewItem( void* id = NULL )
73 { m_id = id; }
74 wxDataViewItem( const wxDataViewItem &item )
75 { m_id = item.m_id; }
76 bool IsOk() const { return m_id != NULL; }
77 void* GetID() const { return m_id; }
78 operator const void* () const { return m_id; }
79
80 private:
81 void* m_id;
82 };
83
84 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right);
85
86 WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
87
88 // ---------------------------------------------------------
89 // wxDataViewModelNotifier
90 // ---------------------------------------------------------
91
92 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
93 {
94 public:
95 wxDataViewModelNotifier() { }
96 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
97
98 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
99 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
100 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
101 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
102 virtual bool Cleared() = 0;
103
104 virtual void Resort() = 0;
105
106 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
107 wxDataViewModel *GetOwner() { return m_owner; }
108
109 private:
110 wxDataViewModel *m_owner;
111 };
112
113
114 // ---------------------------------------------------------
115 // wxDataViewModel
116 // ---------------------------------------------------------
117
118 WX_DECLARE_LIST(wxDataViewModelNotifier, wxDataViewModelNotifiers );
119
120 class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
121 {
122 public:
123 wxDataViewModel();
124
125 virtual unsigned int GetColumnCount() const = 0;
126
127 // return type as reported by wxVariant
128 virtual wxString GetColumnType( unsigned int col ) const = 0;
129
130 // get value into a wxVariant
131 virtual void GetValue( wxVariant &variant,
132 const wxDataViewItem &item, unsigned int col ) const = 0;
133
134 // set value, call ValueChanged() afterwards!
135 virtual bool SetValue( const wxVariant &variant,
136 const wxDataViewItem &item, unsigned int col ) = 0;
137
138 // define hierachy
139 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
140 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
141 virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0;
142 virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0;
143
144 // delegated notifiers
145 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
146 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
147 virtual bool ItemChanged( const wxDataViewItem &item );
148 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
149 virtual bool Cleared();
150
151 // delegatd action
152 virtual void Resort();
153
154 void AddNotifier( wxDataViewModelNotifier *notifier );
155 void RemoveNotifier( wxDataViewModelNotifier *notifier );
156
157 // default compare function
158 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
159 unsigned int column, bool ascending );
160 virtual bool HasDefaultCompare() { return false; }
161
162 protected:
163 // the user should not delete this class directly: he should use DecRef() instead!
164 virtual ~wxDataViewModel() { }
165
166 wxDataViewModelNotifiers m_notifiers;
167 };
168
169 // ---------------------------------------------------------
170 // wxDataViewIndexListModel
171 // ---------------------------------------------------------
172
173 class wxDataViewIndexListModel: public wxDataViewModel
174 {
175 public:
176 wxDataViewIndexListModel( unsigned int initial_size = 0 );
177 ~wxDataViewIndexListModel();
178
179 virtual unsigned int GetRowCount() = 0;
180
181 virtual void GetValue( wxVariant &variant,
182 unsigned int row, unsigned int col ) const = 0;
183
184 virtual bool SetValue( const wxVariant &variant,
185 unsigned int row, unsigned int col ) = 0;
186
187 void RowPrepended();
188 void RowInserted( unsigned int before );
189 void RowAppended();
190 void RowDeleted( unsigned int row );
191 void RowChanged( unsigned int row );
192 void RowValueChanged( unsigned int row, unsigned int col );
193
194 // convert to/from row/wxDataViewItem
195
196 unsigned int GetRow( const wxDataViewItem &item ) const;
197 wxDataViewItem GetItem( unsigned int row ) const;
198
199 // compare based on index
200
201 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
202 unsigned int column, bool ascending );
203 virtual bool HasDefaultCompare() { return true; }
204
205 // implement base methods
206
207 virtual void GetValue( wxVariant &variant,
208 const wxDataViewItem &item, unsigned int col ) const;
209 virtual bool SetValue( const wxVariant &variant,
210 const wxDataViewItem &item, unsigned int col );
211 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
212 virtual bool IsContainer( const wxDataViewItem &item ) const;
213 virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const;
214 virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const;
215
216 private:
217 wxDataViewItemArray m_hash;
218 unsigned int m_lastIndex;
219 };
220
221 //-----------------------------------------------------------------------------
222 // wxDataViewEditorCtrlEvtHandler
223 //-----------------------------------------------------------------------------
224
225 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
226 {
227 public:
228 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
229
230 void AcceptChangesAndFinish();
231 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
232
233 protected:
234 void OnChar( wxKeyEvent &event );
235 void OnKillFocus( wxFocusEvent &event );
236 void OnIdle( wxIdleEvent &event );
237
238 private:
239 wxDataViewRenderer *m_owner;
240 wxControl *m_editorCtrl;
241 bool m_finished;
242 bool m_focusOnIdle;
243
244 private:
245 DECLARE_EVENT_TABLE()
246 };
247
248 // ---------------------------------------------------------
249 // wxDataViewRendererBase
250 // ---------------------------------------------------------
251
252 enum wxDataViewCellMode
253 {
254 wxDATAVIEW_CELL_INERT,
255 wxDATAVIEW_CELL_ACTIVATABLE,
256 wxDATAVIEW_CELL_EDITABLE
257 };
258
259 enum wxDataViewCellRenderState
260 {
261 wxDATAVIEW_CELL_SELECTED = 1,
262 wxDATAVIEW_CELL_PRELIT = 2,
263 wxDATAVIEW_CELL_INSENSITIVE = 4,
264 wxDATAVIEW_CELL_FOCUSED = 8
265 };
266
267 class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
268 {
269 public:
270 wxDataViewRendererBase( const wxString &varianttype,
271 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
272 int alignment = wxDVR_DEFAULT_ALIGNMENT );
273
274 virtual bool Validate( wxVariant& WXUNUSED(value) )
275 { return true; }
276
277 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
278 wxDataViewColumn* GetOwner() { return m_owner; }
279
280 // renderer properties:
281
282 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
283 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
284
285 wxString GetVariantType() const { return m_variantType; }
286
287 virtual void SetMode( wxDataViewCellMode mode ) = 0;
288 virtual wxDataViewCellMode GetMode() const = 0;
289
290 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
291 // rather an "int"; that's because for rendering cells it's allowed
292 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
293 virtual void SetAlignment( int align ) = 0;
294 virtual int GetAlignment() const = 0;
295
296 // in-place editing
297 virtual bool HasEditorCtrl()
298 { return false; }
299 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
300 wxRect WXUNUSED(labelRect),
301 const wxVariant& WXUNUSED(value))
302 { return NULL; }
303 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
304 wxVariant& WXUNUSED(value))
305 { return false; }
306
307 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
308 virtual void CancelEditing();
309 virtual bool FinishEditing();
310
311 wxControl *GetEditorCtrl() { return m_editorCtrl; }
312
313 protected:
314 wxString m_variantType;
315 wxDataViewColumn *m_owner;
316 wxControl *m_editorCtrl;
317 wxDataViewItem m_item; // for m_editorCtrl
318
319 // internal utility:
320 const wxDataViewCtrl* GetView() const;
321
322 protected:
323 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
324 };
325
326 //-----------------------------------------------------------------------------
327 // wxDataViewIconText
328 //-----------------------------------------------------------------------------
329
330 class wxDataViewIconText: public wxObject
331 {
332 public:
333 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
334 { m_icon = icon; m_text = text; }
335 wxDataViewIconText( const wxDataViewIconText &other )
336 { m_icon = other.m_icon; m_text = other.m_text; }
337
338 void SetText( const wxString &text ) { m_text = text; }
339 wxString GetText() const { return m_text; }
340 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
341 const wxIcon &GetIcon() const { return m_icon; }
342
343 private:
344 wxString m_text;
345 wxIcon m_icon;
346
347 private:
348 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
349 };
350
351 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two);
352
353 DECLARE_VARIANT_OBJECT(wxDataViewIconText)
354
355 // ---------------------------------------------------------
356 // wxDataViewColumnBase
357 // ---------------------------------------------------------
358
359 enum wxDataViewColumnFlags
360 {
361 wxDATAVIEW_COL_RESIZABLE = 1,
362 wxDATAVIEW_COL_SORTABLE = 2,
363 wxDATAVIEW_COL_HIDDEN = 4
364 };
365
366 class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
367 {
368 public:
369 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
370 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
371 wxAlignment align = wxALIGN_CENTER,
372 int flags = wxDATAVIEW_COL_RESIZABLE );
373 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
374 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
375 wxAlignment align = wxALIGN_CENTER,
376 int flags = wxDATAVIEW_COL_RESIZABLE );
377 virtual ~wxDataViewColumnBase();
378
379 // setters:
380
381 virtual void SetTitle( const wxString &title ) = 0;
382 virtual void SetAlignment( wxAlignment align ) = 0;
383 virtual void SetSortable( bool sortable ) = 0;
384 virtual void SetResizeable( bool resizeable ) = 0;
385 virtual void SetHidden( bool hidden ) = 0;
386 virtual void SetSortOrder( bool ascending ) = 0;
387 virtual void SetFlags( int flags );
388 virtual void SetOwner( wxDataViewCtrl *owner )
389 { m_owner = owner; }
390 virtual void SetBitmap( const wxBitmap &bitmap )
391 { m_bitmap=bitmap; }
392
393 virtual void SetMinWidth( int minWidth ) = 0;
394 virtual void SetWidth( int width ) = 0;
395
396
397 // getters:
398
399 virtual wxString GetTitle() const = 0;
400 virtual wxAlignment GetAlignment() const = 0;
401 virtual int GetWidth() const = 0;
402 virtual int GetMinWidth() const = 0;
403
404 virtual int GetFlags() const;
405
406 virtual bool IsSortable() const = 0;
407 virtual bool IsResizeable() const = 0;
408 virtual bool IsHidden() const = 0;
409 virtual bool IsSortOrderAscending() const = 0;
410
411 const wxBitmap &GetBitmap() const { return m_bitmap; }
412 unsigned int GetModelColumn() const { return m_model_column; }
413
414 wxDataViewCtrl *GetOwner() { return m_owner; }
415 wxDataViewRenderer* GetRenderer() { return m_renderer; }
416
417 protected:
418 wxDataViewRenderer *m_renderer;
419 int m_model_column;
420 wxBitmap m_bitmap;
421 wxDataViewCtrl *m_owner;
422
423 protected:
424 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
425 };
426
427 // ---------------------------------------------------------
428 // wxDataViewCtrlBase
429 // ---------------------------------------------------------
430
431 #define wxDV_SINGLE 0x0000 // for convenience
432 #define wxDV_MULTIPLE 0x0001 // can select multiple items
433
434 #define wxDV_NO_HEADER 0x0002 // column titles not visible
435 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
436 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
437
438 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
439 {
440 public:
441 wxDataViewCtrlBase();
442 virtual ~wxDataViewCtrlBase();
443
444 virtual bool AssociateModel( wxDataViewModel *model );
445 wxDataViewModel* GetModel();
446
447 // short cuts
448 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
449 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
450 wxAlignment align = wxALIGN_CENTER,
451 int flags = wxDATAVIEW_COL_RESIZABLE );
452 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
453 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
454 wxAlignment align = wxALIGN_CENTER,
455 int flags = wxDATAVIEW_COL_RESIZABLE );
456 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
457 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
458 wxAlignment align = wxALIGN_CENTER,
459 int flags = wxDATAVIEW_COL_RESIZABLE );
460 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
461 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
462 wxAlignment align = wxALIGN_CENTER,
463 int flags = wxDATAVIEW_COL_RESIZABLE );
464 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
465 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
466 wxAlignment align = wxALIGN_CENTER,
467 int flags = wxDATAVIEW_COL_RESIZABLE );
468 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
469 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
470 wxAlignment align = wxALIGN_CENTER,
471 int flags = wxDATAVIEW_COL_RESIZABLE );
472 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
473 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
474 wxAlignment align = wxALIGN_CENTER,
475 int flags = wxDATAVIEW_COL_RESIZABLE );
476 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
477 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
478 wxAlignment align = wxALIGN_CENTER,
479 int flags = wxDATAVIEW_COL_RESIZABLE );
480 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
481 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
482 wxAlignment align = wxALIGN_CENTER,
483 int flags = wxDATAVIEW_COL_RESIZABLE );
484 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
485 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
486 wxAlignment align = wxALIGN_CENTER,
487 int flags = wxDATAVIEW_COL_RESIZABLE );
488 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
489 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
490 wxAlignment align = wxALIGN_CENTER,
491 int flags = wxDATAVIEW_COL_RESIZABLE );
492
493 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
494 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
495 wxAlignment align = wxALIGN_CENTER,
496 int flags = wxDATAVIEW_COL_RESIZABLE );
497
498 virtual bool AppendColumn( wxDataViewColumn *col );
499
500 virtual unsigned int GetColumnCount() const = 0;
501 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
502
503 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
504 virtual bool ClearColumns() = 0;
505
506 void SetExpanderColumn( wxDataViewColumn *col )
507 { m_expander_column = col ; DoSetExpanderColumn(); }
508 wxDataViewColumn *GetExpanderColumn() const
509 { return m_expander_column; }
510
511 void SetIndent( int indent )
512 { m_indent = indent ; DoSetIndent(); }
513 int GetIndent() const
514 { return m_indent; }
515
516 virtual wxDataViewItem GetSelection() const = 0;
517 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
518 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
519 virtual void Select( const wxDataViewItem & item ) = 0;
520 virtual void Unselect( const wxDataViewItem & item ) = 0;
521 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
522
523 virtual void SelectAll() = 0;
524 virtual void UnselectAll() = 0;
525
526 virtual void Expand( const wxDataViewItem & item ) = 0;
527 virtual void Collapse( const wxDataViewItem & item ) = 0;
528
529 virtual void EnsureVisible( const wxDataViewItem & item,
530 const wxDataViewColumn *column = NULL ) = 0;
531 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
532 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
533
534 protected:
535 virtual void DoSetExpanderColumn() = 0 ;
536 virtual void DoSetIndent() = 0;
537
538 private:
539 wxDataViewModel *m_model;
540 wxDataViewColumn *m_expander_column;
541 int m_indent ;
542
543 protected:
544 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
545 };
546
547 // ----------------------------------------------------------------------------
548 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
549 // ----------------------------------------------------------------------------
550
551 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
552 {
553 public:
554 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
555 : wxNotifyEvent(commandType, winid),
556 m_item(0),
557 m_col(-1),
558 m_model(NULL),
559 m_value(wxNullVariant),
560 m_column(NULL)
561 { }
562
563 wxDataViewEvent(const wxDataViewEvent& event)
564 : wxNotifyEvent(event),
565 m_item(event.m_item),
566 m_col(event.m_col),
567 m_model(event.m_model),
568 m_value(event.m_value),
569 m_column(event.m_column)
570 { }
571
572 wxDataViewItem GetItem() const { return m_item; }
573 void SetItem( const wxDataViewItem &item ) { m_item = item; }
574
575 int GetColumn() const { return m_col; }
576 void SetColumn( int col ) { m_col = col; }
577
578 wxDataViewModel* GetModel() const { return m_model; }
579 void SetModel( wxDataViewModel *model ) { m_model = model; }
580
581 const wxVariant &GetValue() const { return m_value; }
582 void SetValue( const wxVariant &value ) { m_value = value; }
583
584 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
585 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
586 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
587
588 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
589
590 protected:
591 wxDataViewItem m_item;
592 int m_col;
593 wxDataViewModel *m_model;
594 wxVariant m_value;
595 wxDataViewColumn *m_column;
596
597 private:
598 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
599 };
600
601 BEGIN_DECLARE_EVENT_TYPES()
602 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, -1)
603 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DESELECTED, -1)
604 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1)
605 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, -1)
606 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, -1)
607 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, -1)
608 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, -1)
609 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, -1)
610 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, -1)
611
612 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
613 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
614 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1)
615
616 // notifications from the model to the control
617 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, -1)
618 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, -1)
619 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED, -1)
620 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, -1)
621 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, -1)
622 END_DECLARE_EVENT_TYPES()
623
624 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
625
626 #define wxDataViewEventHandler(func) \
627 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
628
629 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
630 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
631
632 #define EVT_DATAVIEW_ITEM_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_SELECTED, id, fn)
633 #define EVT_DATAVIEW_ITEM_DESELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DESELECTED, id, fn)
634 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
635 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
636 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
637 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
638 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
639 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
640 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
641
642 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
643 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
644 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
645
646 #define EVT_DATAVIEW_MODEL_ITEM_ADDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_ADDED, id, fn)
647 #define EVT_DATAVIEW_MODEL_ITEM_DELETED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_DELETED, id, fn)
648 #define EVT_DATAVIEW_MODEL_ITEM_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_CHANGED, id, fn)
649 #define EVT_DATAVIEW_MODEL_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_VALUE_CHANGED, id, fn)
650 #define EVT_DATAVIEW_MODEL_CLEARED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_CLEARED, id, fn)
651
652
653 #if defined(wxUSE_GENERICDATAVIEWCTRL)
654 #include "wx/generic/dataview.h"
655 #elif defined(__WXGTK20__)
656 #include "wx/gtk/dataview.h"
657 #elif defined(__WXMAC__)
658 #include "wx/mac/dataview.h"
659 #else
660 #include "wx/generic/dataview.h"
661 #endif
662
663 #endif // wxUSE_DATAVIEWCTRL
664
665 #endif
666 // _WX_DATAVIEW_H_BASE_