]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dataview.h
provide overloads for all kinds of strings for wxDataFormat ctor to allow passing...
[wxWidgets.git] / include / wx / dataview.h
CommitLineData
bcd846ea
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/dataview.h
3// Purpose: wxDataViewCtrl base classes
4// Author: Robert Roebling
5// Modified by:
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
239eaa41
RR
19#include "wx/control.h"
20#include "wx/textctrl.h"
21#include "wx/bitmap.h"
64ffb888 22#include "wx/variant.h"
b9b8b59c 23#include "wx/listctrl.h"
4ed7af08
RR
24
25#if defined(__WXGTK20__)
26 // for testing
30715fa1 27 // #define wxUSE_GENERICDATAVIEWCTRL 1
4ed7af08
RR
28#elif defined(__WXMAC__)
29 #define wxUSE_GENERICDATAVIEWCTRL 1
30#else
31 #define wxUSE_GENERICDATAVIEWCTRL 1
32#endif
33
bcd846ea 34// ----------------------------------------------------------------------------
f554a14b 35// wxDataViewCtrl flags
bcd846ea
RR
36// ----------------------------------------------------------------------------
37
239eaa41
RR
38// ----------------------------------------------------------------------------
39// wxDataViewCtrl globals
40// ----------------------------------------------------------------------------
bcd846ea 41
f460c29d
RD
42class WXDLLIMPEXP_ADV wxDataViewModel;
43class WXDLLIMPEXP_ADV wxDataViewListModel;
44class WXDLLIMPEXP_ADV wxDataViewCtrl;
45class WXDLLIMPEXP_ADV wxDataViewColumn;
baa9ebc4 46class WXDLLIMPEXP_ADV wxDataViewRenderer;
1821abd1 47class wxDataViewEventListModelNotifier;
fa28826d 48
f460c29d 49extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
bcd846ea 50
87f0efe2
RR
51// the default width of new (text) columns:
52#define wxDVC_DEFAULT_WIDTH 80
53
54// the default width of new toggle columns:
55#define wxDVC_TOGGLE_DEFAULT_WIDTH 30
56
9861f022
RR
57// the default minimal width of the columns:
58#define wxDVC_DEFAULT_MINWIDTH 30
59
60// the default alignment of wxDataViewRenderers:
61#define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_TOP)
62
87f0efe2 63
f554a14b 64// ---------------------------------------------------------
239eaa41 65// wxDataViewModel
f554a14b 66// ---------------------------------------------------------
239eaa41 67
87f0efe2 68class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
239eaa41
RR
69{
70public:
71 wxDataViewModel() { }
f554a14b 72
239eaa41 73protected:
87f0efe2
RR
74 // the user should not delete this class directly: he should use DecRef() instead!
75 virtual ~wxDataViewModel() { }
239eaa41
RR
76};
77
f554a14b 78// ---------------------------------------------------------
239eaa41 79// wxDataViewListModelNotifier
f554a14b 80// ---------------------------------------------------------
239eaa41 81
f460c29d 82class WXDLLIMPEXP_ADV wxDataViewListModelNotifier: public wxObject
239eaa41
RR
83{
84public:
85 wxDataViewListModelNotifier() { }
f7ed8c89 86 virtual ~wxDataViewListModelNotifier() { m_owner = NULL; }
f554a14b 87
239eaa41
RR
88 virtual bool RowAppended() = 0;
89 virtual bool RowPrepended() = 0;
0a71f9e9
RR
90 virtual bool RowInserted( unsigned int before ) = 0;
91 virtual bool RowDeleted( unsigned int row ) = 0;
92 virtual bool RowChanged( unsigned int row ) = 0;
93 virtual bool ValueChanged( unsigned int col, unsigned int row ) = 0;
94 virtual bool RowsReordered( unsigned int *new_order ) = 0;
239eaa41 95 virtual bool Cleared() = 0;
f554a14b 96
8f850e28
RR
97 void SetOwner( wxDataViewListModel *owner ) { m_owner = owner; }
98 wxDataViewListModel *GetOwner() { return m_owner; }
f554a14b 99
8f850e28
RR
100private:
101 wxDataViewListModel *m_owner;
64ffb888 102};
239eaa41 103
f554a14b 104// ---------------------------------------------------------
239eaa41 105// wxDataViewListModel
f554a14b 106// ---------------------------------------------------------
239eaa41 107
f460c29d 108class WXDLLIMPEXP_ADV wxDataViewListModel: public wxDataViewModel
239eaa41
RR
109{
110public:
111 wxDataViewListModel();
239eaa41 112
9861f022
RR
113 virtual unsigned int GetRowCount() const = 0;
114 virtual unsigned int GetColumnCount() const = 0;
87f0efe2 115
a7f61f76 116 // return type as reported by wxVariant
9861f022 117 virtual wxString GetColumnType( unsigned int col ) const = 0;
87f0efe2 118
a7f61f76 119 // get value into a wxVariant
9861f022 120 virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const = 0;
87f0efe2 121
a7f61f76 122 // set value, call ValueChanged() afterwards!
2fa73716 123 virtual bool SetValue( const wxVariant &variant, unsigned int col, unsigned int row ) = 0;
239eaa41 124
b9b8b59c
RR
125 // override to set cell attributes
126 virtual void GetAttr( wxListItemAttr &attr, unsigned int col, unsigned int row ) { }
127
239eaa41 128 // delegated notifiers
8981608c
RR
129 virtual bool RowAppended();
130 virtual bool RowPrepended();
0a71f9e9
RR
131 virtual bool RowInserted( unsigned int before );
132 virtual bool RowDeleted( unsigned int row );
133 virtual bool RowChanged( unsigned int row );
134 virtual bool ValueChanged( unsigned int col, unsigned int row );
135 virtual bool RowsReordered( unsigned int *new_order );
8981608c 136 virtual bool Cleared();
b5d777c7 137
63415a42
RR
138 void AddNotifier( wxDataViewListModelNotifier *notifier );
139 void RemoveNotifier( wxDataViewListModelNotifier *notifier );
140
87f0efe2
RR
141protected:
142 // the user should not delete this class directly: he should use DecRef() instead!
143 virtual ~wxDataViewListModel();
144
1821abd1 145 wxList m_notifiers;
239eaa41
RR
146};
147
f554a14b 148// ---------------------------------------------------------
8981608c 149// wxDataViewSortedListModel
f554a14b 150// ---------------------------------------------------------
8981608c
RR
151
152typedef int (wxCALLBACK *wxDataViewListModelCompare)
0a71f9e9 153 (unsigned int row1, unsigned int row2, unsigned int col, wxDataViewListModel* model );
8981608c 154
9861f022
RR
155WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int,
156 wxDataViewSortedIndexArray, WXDLLIMPEXP_ADV);
8981608c 157
f460c29d 158class WXDLLIMPEXP_ADV wxDataViewSortedListModel: public wxDataViewListModel
8981608c 159{
87f0efe2
RR
160 friend class wxDataViewSortedListModelNotifier;
161
8981608c
RR
162public:
163 wxDataViewSortedListModel( wxDataViewListModel *child );
164 virtual ~wxDataViewSortedListModel();
165
31fb32e1 166 void SetAscending( bool ascending ) { m_ascending = ascending; }
9861f022
RR
167 bool IsAscending() const { return m_ascending; }
168
169 virtual unsigned int GetRowCount() const;
170 virtual unsigned int GetColumnCount() const;
31fb32e1 171
8981608c 172 // return type as reported by wxVariant
9861f022
RR
173 virtual wxString GetColumnType( unsigned int col ) const;
174
8981608c 175 // get value into a wxVariant
9861f022
RR
176 virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const;
177
8981608c 178 // set value, call ValueChanged() afterwards!
2fa73716 179 virtual bool SetValue( const wxVariant &variant, unsigned int col, unsigned int row );
8981608c 180
4627af27 181 // called from user
8981608c
RR
182 virtual bool RowAppended();
183 virtual bool RowPrepended();
0a71f9e9
RR
184 virtual bool RowInserted( unsigned int before );
185 virtual bool RowDeleted( unsigned int row );
186 virtual bool RowChanged( unsigned int row );
187 virtual bool ValueChanged( unsigned int col, unsigned int row );
188 virtual bool RowsReordered( unsigned int *new_order );
8981608c
RR
189 virtual bool Cleared();
190
4627af27
RR
191 // called if child's notifiers are called
192 bool ChildRowAppended();
193 bool ChildRowPrepended();
0a71f9e9
RR
194 bool ChildRowInserted( unsigned int before );
195 bool ChildRowDeleted( unsigned int row );
196 bool ChildRowChanged( unsigned int row );
197 bool ChildValueChanged( unsigned int col, unsigned int row );
198 bool ChildRowsReordered( unsigned int *new_order );
4627af27 199 bool ChildCleared();
4eccd3a1 200
8f850e28 201 virtual void Resort();
f7ed8c89
RR
202
203 void DetachChild();
8f850e28 204
8981608c 205private:
31fb32e1 206 bool m_ascending;
8981608c
RR
207 wxDataViewListModel *m_child;
208 wxDataViewSortedIndexArray m_array;
4eccd3a1 209 wxDataViewListModelNotifier *m_notifierOnChild;
31fb32e1
RR
210
211 void InitStatics(); // BAD
8981608c
RR
212};
213
1e510b1e
RR
214//-----------------------------------------------------------------------------
215// wxDataViewEditorCtrlEvtHandler
216//-----------------------------------------------------------------------------
217
218class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
219{
220public:
221 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
222
223 void AcceptChangesAndFinish();
30715fa1 224 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
1e510b1e
RR
225
226protected:
227 void OnChar( wxKeyEvent &event );
228 void OnKillFocus( wxFocusEvent &event );
30715fa1 229 void OnIdle( wxIdleEvent &event );
1e510b1e
RR
230
231private:
232 wxDataViewRenderer *m_owner;
233 wxControl *m_editorCtrl;
234 bool m_finished;
30715fa1 235 bool m_focusOnIdle;
1e510b1e
RR
236
237private:
238 DECLARE_EVENT_TABLE()
239};
240
f554a14b 241// ---------------------------------------------------------
baa9ebc4 242// wxDataViewRendererBase
f554a14b 243// ---------------------------------------------------------
fa28826d 244
6842a71a 245enum wxDataViewCellMode
fa28826d 246{
6842a71a
RR
247 wxDATAVIEW_CELL_INERT,
248 wxDATAVIEW_CELL_ACTIVATABLE,
249 wxDATAVIEW_CELL_EDITABLE
fa28826d
RR
250};
251
6842a71a
RR
252enum wxDataViewCellRenderState
253{
254 wxDATAVIEW_CELL_SELECTED = 1,
255 wxDATAVIEW_CELL_PRELIT = 2,
256 wxDATAVIEW_CELL_INSENSITIVE = 4,
257 wxDATAVIEW_CELL_FOCUSED = 8
258};
259
baa9ebc4 260class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
6842a71a
RR
261{
262public:
9861f022
RR
263 wxDataViewRendererBase( const wxString &varianttype,
264 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
265 int alignment = wxDVR_DEFAULT_ALIGNMENT );
6842a71a 266
9861f022
RR
267 virtual bool Validate( wxVariant& WXUNUSED(value) )
268 { return true; }
f554a14b 269
6842a71a
RR
270 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
271 wxDataViewColumn* GetOwner() { return m_owner; }
f554a14b 272
9861f022
RR
273 // renderer properties:
274
275 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
276 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
277
278 wxString GetVariantType() const { return m_variantType; }
279
280 virtual void SetMode( wxDataViewCellMode mode ) = 0;
281 virtual wxDataViewCellMode GetMode() const = 0;
282
283 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
284 // rather an "int"; that's because for rendering cells it's allowed
285 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
286 virtual void SetAlignment( int align ) = 0;
287 virtual int GetAlignment() const = 0;
99d471a5 288
1e510b1e
RR
289 // in-place editing
290 virtual bool HasEditorCtrl()
291 { return false; }
96c2a0dd
VZ
292 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
293 wxRect WXUNUSED(labelRect),
294 const wxVariant& WXUNUSED(value))
1e510b1e 295 { return NULL; }
96c2a0dd
VZ
296 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
297 wxVariant& WXUNUSED(value))
1e510b1e
RR
298 { return false; }
299
300 virtual bool StartEditing( unsigned int row, wxRect labelRect );
301 virtual void CancelEditing();
302 virtual bool FinishEditing();
303
304 wxControl *GetEditorCtrl() { return m_editorCtrl; }
305
a7f61f76 306protected:
6842a71a
RR
307 wxString m_variantType;
308 wxDataViewColumn *m_owner;
1e510b1e
RR
309 wxControl *m_editorCtrl;
310 unsigned int m_row; // for m_editorCtrl
6842a71a 311
9861f022
RR
312 // internal utility:
313 const wxDataViewCtrl* GetView() const;
314
6842a71a 315protected:
baa9ebc4 316 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
6842a71a
RR
317};
318
f554a14b 319// ---------------------------------------------------------
6842a71a 320// wxDataViewColumnBase
f554a14b 321// ---------------------------------------------------------
6842a71a 322
fa28826d
RR
323enum wxDataViewColumnFlags
324{
325 wxDATAVIEW_COL_RESIZABLE = 1,
326 wxDATAVIEW_COL_SORTABLE = 2,
327 wxDATAVIEW_COL_HIDDEN = 4
328};
329
f460c29d 330class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
fa28826d
RR
331{
332public:
87f0efe2
RR
333 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
334 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
335 wxAlignment align = wxALIGN_CENTER,
336 int flags = wxDATAVIEW_COL_RESIZABLE );
337 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
338 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
339 wxAlignment align = wxALIGN_CENTER,
340 int flags = wxDATAVIEW_COL_RESIZABLE );
d3c7fc99 341 virtual ~wxDataViewColumnBase();
fa28826d 342
9861f022 343 // setters:
07b6378f 344
9861f022 345 virtual void SetTitle( const wxString &title ) = 0;
47cef10f 346 virtual void SetAlignment( wxAlignment align ) = 0;
31fb32e1 347 virtual void SetSortable( bool sortable ) = 0;
9861f022
RR
348 virtual void SetResizeable( bool resizeable ) = 0;
349 virtual void SetHidden( bool hidden ) = 0;
47cef10f 350 virtual void SetSortOrder( bool ascending ) = 0;
9861f022
RR
351 virtual void SetFlags( int flags );
352 virtual void SetOwner( wxDataViewCtrl *owner )
353 { m_owner = owner; }
354 virtual void SetBitmap( const wxBitmap &bitmap )
355 { m_bitmap=bitmap; }
07a84e7b 356
9861f022
RR
357 virtual void SetMinWidth( int minWidth ) = 0;
358 virtual void SetWidth( int width ) = 0;
f554a14b 359
f554a14b 360
9861f022 361 // getters:
07b6378f 362
9861f022
RR
363 virtual wxString GetTitle() const = 0;
364 virtual wxAlignment GetAlignment() const = 0;
87f0efe2 365 virtual int GetWidth() const = 0;
9861f022 366 virtual int GetMinWidth() const = 0;
07b6378f 367
9861f022
RR
368 virtual int GetFlags() const;
369
370 virtual bool IsSortable() const = 0;
371 virtual bool IsResizeable() const = 0;
372 virtual bool IsHidden() const = 0;
373 virtual bool IsSortOrderAscending() const = 0;
374
375 const wxBitmap &GetBitmap() const { return m_bitmap; }
376 unsigned int GetModelColumn() const { return m_model_column; }
377
378 wxDataViewCtrl *GetOwner() { return m_owner; }
379 wxDataViewRenderer* GetRenderer() { return m_renderer; }
380
381protected:
baa9ebc4 382 wxDataViewRenderer *m_renderer;
6842a71a 383 int m_model_column;
07a84e7b 384 wxBitmap m_bitmap;
6842a71a 385 wxDataViewCtrl *m_owner;
fa28826d
RR
386
387protected:
388 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
389};
390
f554a14b 391// ---------------------------------------------------------
239eaa41 392// wxDataViewCtrlBase
f554a14b 393// ---------------------------------------------------------
239eaa41 394
c21f7aa1 395#define wxDV_SINGLE 0x0000 // for convenience
9861f022
RR
396#define wxDV_MULTIPLE 0x0001 // can select multiple items
397
398#define wxDV_NO_HEADER 0x0002 // column titles not visible
399#define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
400#define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
c21f7aa1 401
f460c29d 402class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
239eaa41
RR
403{
404public:
405 wxDataViewCtrlBase();
d3c7fc99 406 virtual ~wxDataViewCtrlBase();
f554a14b 407
6e2e590f
RR
408 virtual bool AssociateModel( wxDataViewListModel *model );
409 wxDataViewListModel* GetModel();
f554a14b 410
07a84e7b 411 // short cuts
1286b7ba 412 bool AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2
RR
413 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
414 wxAlignment align = wxALIGN_CENTER,
415 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 416 bool AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2
RR
417 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
418 wxAlignment align = wxALIGN_CENTER,
419 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 420 bool AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2
RR
421 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
422 wxAlignment align = wxALIGN_CENTER,
423 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 424 bool AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2
RR
425 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
426 wxAlignment align = wxALIGN_CENTER,
427 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 428 bool AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2
RR
429 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
430 wxAlignment align = wxALIGN_CENTER,
431 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 432 bool AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2
RR
433 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
434 wxAlignment align = wxALIGN_CENTER,
435 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 436 bool AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2
RR
437 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
438 wxAlignment align = wxALIGN_CENTER,
439 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 440 bool AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2
RR
441 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
442 wxAlignment align = wxALIGN_CENTER,
443 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 444 bool AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2
RR
445 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
446 wxAlignment align = wxALIGN_CENTER,
447 int flags = wxDATAVIEW_COL_RESIZABLE );
1286b7ba 448 bool AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2
RR
449 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
450 wxAlignment align = wxALIGN_CENTER,
451 int flags = wxDATAVIEW_COL_RESIZABLE );
07a84e7b 452
f554a14b 453 virtual bool AppendColumn( wxDataViewColumn *col );
9861f022
RR
454
455 virtual unsigned int GetColumnCount() const;
456
0a71f9e9 457 virtual bool DeleteColumn( unsigned int pos );
fa28826d 458 virtual bool ClearColumns();
0a71f9e9 459 virtual wxDataViewColumn* GetColumn( unsigned int pos );
f554a14b 460
6ff7eee7
RR
461 virtual void SetSelection( int row ) = 0; // -1 for unselect
462 inline void ClearSelection() { SetSelection( -1 ); }
fc211fe5 463 virtual void Unselect( unsigned int row ) = 0;
6ff7eee7
RR
464 virtual void SetSelectionRange( unsigned int from, unsigned int to ) = 0;
465 virtual void SetSelections( const wxArrayInt& aSelections) = 0;
466
467 virtual bool IsSelected( unsigned int row ) const = 0;
468 virtual int GetSelection() const = 0;
469 virtual int GetSelections(wxArrayInt& aSelections) const = 0;
470
239eaa41 471private:
6e2e590f 472 wxDataViewListModel *m_model;
fa28826d 473 wxList m_cols;
1821abd1 474 wxDataViewEventListModelNotifier *m_eventNotifier;
30715fa1 475
239eaa41 476protected:
260b9be7 477 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
239eaa41 478};
bcd846ea 479
eb7f97f8
RR
480
481// ----------------------------------------------------------------------------
482// wxDataViewEvent - the event class for the wxDataViewCtrl notifications
483// ----------------------------------------------------------------------------
484
2f799ae8 485class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
eb7f97f8
RR
486{
487public:
488 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
489 : wxNotifyEvent(commandType, winid),
490 m_col(-1),
491 m_row(-1),
492 m_model(NULL),
493 m_value(wxNullVariant),
31fb32e1
RR
494 m_editCancelled(false),
495 m_column(NULL)
eb7f97f8
RR
496 { }
497
498 wxDataViewEvent(const wxDataViewEvent& event)
499 : wxNotifyEvent(event),
500 m_col(event.m_col),
501 m_row(event.m_col),
502 m_model(event.m_model),
503 m_value(event.m_value),
31fb32e1
RR
504 m_editCancelled(event.m_editCancelled),
505 m_column(event.m_column)
eb7f97f8
RR
506 { }
507
508 int GetColumn() const { return m_col; }
509 void SetColumn( int col ) { m_col = col; }
9861f022 510
eb7f97f8
RR
511 int GetRow() const { return m_row; }
512 void SetRow( int row ) { m_row = row; }
9861f022 513
eb7f97f8
RR
514 wxDataViewModel* GetModel() const { return m_model; }
515 void SetModel( wxDataViewModel *model ) { m_model = model; }
9861f022 516
eb7f97f8
RR
517 const wxVariant &GetValue() const { return m_value; }
518 void SetValue( const wxVariant &value ) { m_value = value; }
519
31fb32e1
RR
520 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
521 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
9861f022 522 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
31fb32e1 523
eb7f97f8
RR
524 // was label editing canceled? (for wxEVT_COMMAND_DATVIEW_END_LABEL_EDIT only)
525 bool IsEditCancelled() const { return m_editCancelled; }
526 void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
527
528 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
529
530protected:
531 int m_col;
532 int m_row;
533 wxDataViewModel *m_model;
534 wxVariant m_value;
535 bool m_editCancelled;
31fb32e1 536 wxDataViewColumn *m_column;
eb7f97f8
RR
537
538private:
539 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
540};
541
542BEGIN_DECLARE_EVENT_TYPES()
e07c1146
PC
543 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, -1)
544 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED, -1)
545 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
546 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
1821abd1
RR
547 // notifications from the model to the control
548 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED, -1)
549 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED, -1)
550 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED, -1)
551 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED, -1)
552 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED, -1)
553 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, -1)
554 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED, -1)
555 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, -1)
eb7f97f8
RR
556END_DECLARE_EVENT_TYPES()
557
558typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
559
560#define wxDataViewEventHandler(func) \
561 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
562
563#define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
564 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
565
566#define EVT_DATAVIEW_ROW_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ROW_SELECTED, id, fn)
f828871d 567#define EVT_DATAVIEW_ROW_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ROW_ACTIVATED, id, fn)
31fb32e1
RR
568#define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
569#define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
eb7f97f8 570
1821abd1
RR
571#define EVT_DATAVIEW_MODEL_ROW_APPENDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_APPENDED, id, fn)
572#define EVT_DATAVIEW_MODEL_ROW_PREPENDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_PREPENDED, id, fn)
573#define EVT_DATAVIEW_MODEL_ROW_INSERTED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_INSERTED, id, fn)
574#define EVT_DATAVIEW_MODEL_ROW_DELETED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_DELETED, id, fn)
575#define EVT_DATAVIEW_MODEL_ROW_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROW_CHANGED, id, fn)
576#define EVT_DATAVIEW_MODEL_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_VALUE_CHANGED, id, fn)
577#define EVT_DATAVIEW_MODEL_ROWS_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ROWS_REORDERED, id, fn)
578#define EVT_DATAVIEW_MODEL_CLEARED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_CLEARED, id, fn)
579
eb7f97f8 580
4ed7af08
RR
581#if defined(wxUSE_GENERICDATAVIEWCTRL)
582 #include "wx/generic/dataview.h"
583#elif defined(__WXGTK20__)
bcd846ea
RR
584 #include "wx/gtk/dataview.h"
585#elif defined(__WXMAC__)
07b6378f
WS
586 // TODO
587 // #include "wx/mac/dataview.h"
bcd846ea
RR
588#else
589 #include "wx/generic/dataview.h"
590#endif
591
592#endif // wxUSE_DATAVIEWCTRL
593
594#endif
595 // _WX_DATAVIEW_H_BASE_