]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dataview.h
Minimal (nearly empty) wxDisplay for wxMGL (to compensate src/common/tplvcmn.cpp...
[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
bcd846ea
RR
24// ----------------------------------------------------------------------------
25// wxDataViewCtrl flags
26// ----------------------------------------------------------------------------
27
239eaa41
RR
28// ----------------------------------------------------------------------------
29// wxDataViewCtrl globals
30// ----------------------------------------------------------------------------
bcd846ea 31
8f850e28
RR
32class WXDLLIMPEXP_CORE wxDataViewModel;
33class WXDLLIMPEXP_CORE wxDataViewListModel;
fa28826d
RR
34class WXDLLIMPEXP_CORE wxDataViewCtrl;
35class WXDLLIMPEXP_CORE wxDataViewColumn;
6842a71a 36class WXDLLIMPEXP_CORE wxDataViewCell;
fa28826d 37
63ec432b 38extern WXDLLEXPORT_DATA(const wxChar) wxDataViewCtrlNameStr[];
bcd846ea 39
239eaa41
RR
40// ---------------------------------------------------------
41// wxDataViewModel
42// ---------------------------------------------------------
43
44class wxDataViewModel: public wxObject
45{
46public:
47 wxDataViewModel() { }
48 virtual ~wxDataViewModel() { }
49
50protected:
260b9be7 51 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel)
239eaa41
RR
52};
53
54// ---------------------------------------------------------
55// wxDataViewListModelNotifier
56// ---------------------------------------------------------
57
8f850e28
RR
58
59class wxDataViewListModelNotifier: public wxObject
239eaa41
RR
60{
61public:
62 wxDataViewListModelNotifier() { }
63 virtual ~wxDataViewListModelNotifier() { }
64
65 virtual bool RowAppended() = 0;
66 virtual bool RowPrepended() = 0;
67 virtual bool RowInserted( size_t before ) = 0;
68 virtual bool RowDeleted( size_t row ) = 0;
69 virtual bool RowChanged( size_t row ) = 0;
b5d777c7 70 virtual bool ValueChanged( size_t col, size_t row ) = 0;
4eccd3a1 71 virtual bool RowsReordered( size_t *new_order ) = 0;
239eaa41 72 virtual bool Cleared() = 0;
8f850e28
RR
73
74 void SetOwner( wxDataViewListModel *owner ) { m_owner = owner; }
75 wxDataViewListModel *GetOwner() { return m_owner; }
76
77private:
78 wxDataViewListModel *m_owner;
64ffb888 79};
239eaa41
RR
80
81// ---------------------------------------------------------
82// wxDataViewListModel
83// ---------------------------------------------------------
84
8f850e28
RR
85class wxDataViewViewingColumn: public wxObject
86{
87public:
88 wxDataViewViewingColumn( wxDataViewColumn *view_column, size_t model_column )
89 {
90 m_viewColumn = view_column;
91 m_modelColumn = model_column;
92 }
93
94 wxDataViewColumn *m_viewColumn;
95 size_t m_modelColumn;
96};
97
239eaa41
RR
98class wxDataViewListModel: public wxDataViewModel
99{
100public:
101 wxDataViewListModel();
102 virtual ~wxDataViewListModel();
103
104 virtual size_t GetNumberOfRows() = 0;
105 virtual size_t GetNumberOfCols() = 0;
a7f61f76 106 // return type as reported by wxVariant
239eaa41 107 virtual wxString GetColType( size_t col ) = 0;
a7f61f76 108 // get value into a wxVariant
3f3af7e7 109 virtual void GetValue( wxVariant &variant, size_t col, size_t row ) = 0;
a7f61f76
RR
110 // set value, call ValueChanged() afterwards!
111 virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) = 0;
239eaa41
RR
112
113 // delegated notifiers
8981608c
RR
114 virtual bool RowAppended();
115 virtual bool RowPrepended();
116 virtual bool RowInserted( size_t before );
117 virtual bool RowDeleted( size_t row );
118 virtual bool RowChanged( size_t row );
119 virtual bool ValueChanged( size_t col, size_t row );
4eccd3a1 120 virtual bool RowsReordered( size_t *new_order );
8981608c 121 virtual bool Cleared();
b5d777c7
RR
122
123 // Used internally
8981608c
RR
124 virtual void AddViewingColumn( wxDataViewColumn *view_column, size_t model_column );
125 virtual void RemoveViewingColumn( wxDataViewColumn *column );
239eaa41 126
8f850e28
RR
127 virtual void AddNotifier( wxDataViewListModelNotifier *notifier );
128 virtual void RemoveNotifier( wxDataViewListModelNotifier *notifier );
239eaa41 129
8f850e28
RR
130 wxList m_notifiers;
131 wxList m_viewingColumns;
239eaa41
RR
132
133protected:
260b9be7 134 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel)
239eaa41
RR
135};
136
8981608c
RR
137// ---------------------------------------------------------
138// wxDataViewSortedListModel
139// ---------------------------------------------------------
140
141typedef int (wxCALLBACK *wxDataViewListModelCompare)
142 (size_t row1, size_t row2, size_t col, wxDataViewListModel* model );
143
144WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(size_t, wxDataViewSortedIndexArray );
145
146class wxDataViewSortedListModel: public wxDataViewListModel
147{
148public:
149 wxDataViewSortedListModel( wxDataViewListModel *child );
150 virtual ~wxDataViewSortedListModel();
151
152 virtual size_t GetNumberOfRows();
153 virtual size_t GetNumberOfCols();
154 // return type as reported by wxVariant
155 virtual wxString GetColType( size_t col );
156 // get value into a wxVariant
3f3af7e7 157 virtual void GetValue( wxVariant &variant, size_t col, size_t row );
8981608c
RR
158 // set value, call ValueChanged() afterwards!
159 virtual bool SetValue( wxVariant &variant, size_t col, size_t row );
160
161 // delegated notifiers
162 virtual bool RowAppended();
163 virtual bool RowPrepended();
164 virtual bool RowInserted( size_t before );
165 virtual bool RowDeleted( size_t row );
166 virtual bool RowChanged( size_t row );
167 virtual bool ValueChanged( size_t col, size_t row );
4eccd3a1 168 virtual bool RowsReordered( size_t *new_order );
8981608c
RR
169 virtual bool Cleared();
170
4eccd3a1
RR
171 bool ChildValueChanged( size_t col, size_t row );
172
8f850e28
RR
173 virtual void Resort();
174
8981608c
RR
175private:
176 wxDataViewListModel *m_child;
177 wxDataViewSortedIndexArray m_array;
4eccd3a1 178 wxDataViewListModelNotifier *m_notifierOnChild;
8981608c
RR
179
180protected:
181 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel)
182};
183
fa28826d 184// ---------------------------------------------------------
6842a71a 185// wxDataViewCellBase
fa28826d
RR
186// ---------------------------------------------------------
187
6842a71a 188enum wxDataViewCellMode
fa28826d 189{
6842a71a
RR
190 wxDATAVIEW_CELL_INERT,
191 wxDATAVIEW_CELL_ACTIVATABLE,
192 wxDATAVIEW_CELL_EDITABLE
fa28826d
RR
193};
194
6842a71a
RR
195enum wxDataViewCellRenderState
196{
197 wxDATAVIEW_CELL_SELECTED = 1,
198 wxDATAVIEW_CELL_PRELIT = 2,
199 wxDATAVIEW_CELL_INSENSITIVE = 4,
200 wxDATAVIEW_CELL_FOCUSED = 8
201};
202
203class wxDataViewCellBase: public wxObject
204{
205public:
206 wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
207
208 virtual bool SetValue( const wxVariant &value ) { return true; }
209 virtual bool GetValue( wxVariant &value ) { return true; }
a7f61f76 210 virtual bool Validate( wxVariant &value ) { return true; }
6842a71a 211
e152afc3 212 wxString GetVariantType() { return m_variantType; }
6842a71a
RR
213
214 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
215 wxDataViewColumn* GetOwner() { return m_owner; }
216
a7f61f76 217protected:
6842a71a
RR
218 wxDataViewCellMode m_mode;
219 wxString m_variantType;
220 wxDataViewColumn *m_owner;
221
222protected:
223 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase)
224};
225
226// ---------------------------------------------------------
227// wxDataViewColumnBase
228// ---------------------------------------------------------
229
fa28826d
RR
230enum wxDataViewColumnFlags
231{
232 wxDATAVIEW_COL_RESIZABLE = 1,
233 wxDATAVIEW_COL_SORTABLE = 2,
234 wxDATAVIEW_COL_HIDDEN = 4
235};
236
237class wxDataViewColumnBase: public wxObject
238{
239public:
6842a71a
RR
240 wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags = 0 );
241 ~wxDataViewColumnBase();
fa28826d
RR
242
243 virtual void SetTitle( const wxString &title );
244 virtual wxString GetTitle();
6842a71a
RR
245
246 wxDataViewCell* GetCell() { return m_cell; }
247
248 size_t GetModelColumn() { return m_model_column; }
249
250 void SetOwner( wxDataViewCtrl *owner ) { m_owner = owner; }
251 wxDataViewCtrl *GetOwner() { return m_owner; }
fa28826d
RR
252
253private:
254 wxDataViewCtrl *m_ctrl;
6842a71a
RR
255 wxDataViewCell *m_cell;
256 int m_model_column;
fa28826d
RR
257 int m_flags;
258 wxString m_title;
6842a71a 259 wxDataViewCtrl *m_owner;
fa28826d
RR
260
261protected:
262 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
263};
264
239eaa41
RR
265// ---------------------------------------------------------
266// wxDataViewCtrlBase
267// ---------------------------------------------------------
268
269class wxDataViewCtrlBase: public wxControl
270{
271public:
272 wxDataViewCtrlBase();
273 ~wxDataViewCtrlBase();
239eaa41 274
6e2e590f
RR
275 virtual bool AssociateModel( wxDataViewListModel *model );
276 wxDataViewListModel* GetModel();
239eaa41 277
605c2c4a
RR
278 virtual bool AppendTextColumn( const wxString &label, size_t model_column );
279 virtual bool AppendToggleColumn( const wxString &label, size_t model_column );
ad63bf41 280 virtual bool AppendProgressColumn( const wxString &label, size_t model_column );
4d496ecb 281 virtual bool AppendDateColumn( const wxString &label, size_t model_column );
fa28826d
RR
282 virtual bool AppendColumn( wxDataViewColumn *col );
283 virtual size_t GetNumberOfColumns();
284 virtual bool DeleteColumn( size_t pos );
285 virtual bool ClearColumns();
286 virtual wxDataViewColumn* GetColumn( size_t pos );
287
239eaa41 288private:
6e2e590f 289 wxDataViewListModel *m_model;
fa28826d 290 wxList m_cols;
bcd846ea 291
239eaa41 292protected:
260b9be7 293 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
239eaa41 294};
bcd846ea 295
bcd846ea
RR
296#if defined(__WXGTK20__)
297 #include "wx/gtk/dataview.h"
298#elif defined(__WXMAC__)
299 #include "wx/mac/dataview.h"
300#else
301 #include "wx/generic/dataview.h"
302#endif
303
304#endif // wxUSE_DATAVIEWCTRL
305
306#endif
307 // _WX_DATAVIEW_H_BASE_