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