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