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