]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dataview.h
define wxUSE_BOOKCTRL when wxUSE_NOTE/LIST/CHOICEBOOK are 0; also define it as as...
[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
4627af27 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;
46class WXDLLIMPEXP_ADV wxDataViewCell;
fa28826d 47
f460c29d 48extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
bcd846ea 49
f554a14b 50// ---------------------------------------------------------
239eaa41 51// wxDataViewModel
f554a14b 52// ---------------------------------------------------------
239eaa41 53
f460c29d 54class WXDLLIMPEXP_ADV wxDataViewModel: public wxObject
239eaa41
RR
55{
56public:
57 wxDataViewModel() { }
58 virtual ~wxDataViewModel() { }
f554a14b 59
239eaa41 60protected:
260b9be7 61 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel)
239eaa41
RR
62};
63
f554a14b 64// ---------------------------------------------------------
239eaa41 65// wxDataViewListModelNotifier
f554a14b 66// ---------------------------------------------------------
239eaa41 67
8f850e28 68
f460c29d 69class WXDLLIMPEXP_ADV wxDataViewListModelNotifier: public wxObject
239eaa41
RR
70{
71public:
72 wxDataViewListModelNotifier() { }
73 virtual ~wxDataViewListModelNotifier() { }
f554a14b 74
239eaa41
RR
75 virtual bool RowAppended() = 0;
76 virtual bool RowPrepended() = 0;
77 virtual bool RowInserted( size_t before ) = 0;
78 virtual bool RowDeleted( size_t row ) = 0;
79 virtual bool RowChanged( size_t row ) = 0;
b5d777c7 80 virtual bool ValueChanged( size_t col, size_t row ) = 0;
4eccd3a1 81 virtual bool RowsReordered( size_t *new_order ) = 0;
239eaa41 82 virtual bool Cleared() = 0;
f554a14b 83
8f850e28
RR
84 void SetOwner( wxDataViewListModel *owner ) { m_owner = owner; }
85 wxDataViewListModel *GetOwner() { return m_owner; }
f554a14b 86
8f850e28
RR
87private:
88 wxDataViewListModel *m_owner;
64ffb888 89};
239eaa41 90
f554a14b 91// ---------------------------------------------------------
239eaa41 92// wxDataViewListModel
f554a14b 93// ---------------------------------------------------------
239eaa41 94
f460c29d 95class WXDLLIMPEXP_ADV wxDataViewViewingColumn: public wxObject
8f850e28
RR
96{
97public:
98 wxDataViewViewingColumn( wxDataViewColumn *view_column, size_t model_column )
99 {
100 m_viewColumn = view_column;
101 m_modelColumn = model_column;
102 }
f554a14b 103
8f850e28
RR
104 wxDataViewColumn *m_viewColumn;
105 size_t m_modelColumn;
106};
107
f460c29d 108class WXDLLIMPEXP_ADV wxDataViewListModel: public wxDataViewModel
239eaa41
RR
109{
110public:
111 wxDataViewListModel();
112 virtual ~wxDataViewListModel();
113
114 virtual size_t GetNumberOfRows() = 0;
115 virtual size_t GetNumberOfCols() = 0;
a7f61f76 116 // return type as reported by wxVariant
239eaa41 117 virtual wxString GetColType( size_t col ) = 0;
a7f61f76 118 // get value into a wxVariant
3f3af7e7 119 virtual void GetValue( wxVariant &variant, size_t col, size_t row ) = 0;
a7f61f76
RR
120 // set value, call ValueChanged() afterwards!
121 virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) = 0;
239eaa41
RR
122
123 // delegated notifiers
8981608c
RR
124 virtual bool RowAppended();
125 virtual bool RowPrepended();
126 virtual bool RowInserted( size_t before );
127 virtual bool RowDeleted( size_t row );
128 virtual bool RowChanged( size_t row );
129 virtual bool ValueChanged( size_t col, size_t row );
4eccd3a1 130 virtual bool RowsReordered( size_t *new_order );
8981608c 131 virtual bool Cleared();
b5d777c7 132
f554a14b 133 // Used internally
8981608c
RR
134 virtual void AddViewingColumn( wxDataViewColumn *view_column, size_t model_column );
135 virtual void RemoveViewingColumn( wxDataViewColumn *column );
f554a14b 136
8f850e28
RR
137 virtual void AddNotifier( wxDataViewListModelNotifier *notifier );
138 virtual void RemoveNotifier( wxDataViewListModelNotifier *notifier );
f554a14b 139
8f850e28
RR
140 wxList m_notifiers;
141 wxList m_viewingColumns;
239eaa41
RR
142
143protected:
260b9be7 144 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel)
239eaa41
RR
145};
146
f554a14b 147// ---------------------------------------------------------
8981608c 148// wxDataViewSortedListModel
f554a14b 149// ---------------------------------------------------------
8981608c
RR
150
151typedef int (wxCALLBACK *wxDataViewListModelCompare)
152 (size_t row1, size_t row2, size_t col, wxDataViewListModel* model );
153
f460c29d 154WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(size_t, wxDataViewSortedIndexArray, WXDLLIMPEXP_ADV);
8981608c 155
f460c29d 156class WXDLLIMPEXP_ADV wxDataViewSortedListModel: public wxDataViewListModel
8981608c
RR
157{
158public:
159 wxDataViewSortedListModel( wxDataViewListModel *child );
160 virtual ~wxDataViewSortedListModel();
161
162 virtual size_t GetNumberOfRows();
163 virtual size_t GetNumberOfCols();
164 // return type as reported by wxVariant
165 virtual wxString GetColType( size_t col );
166 // get value into a wxVariant
3f3af7e7 167 virtual void GetValue( wxVariant &variant, size_t col, size_t row );
8981608c
RR
168 // set value, call ValueChanged() afterwards!
169 virtual bool SetValue( wxVariant &variant, size_t col, size_t row );
170
4627af27 171 // called from user
8981608c
RR
172 virtual bool RowAppended();
173 virtual bool RowPrepended();
174 virtual bool RowInserted( size_t before );
175 virtual bool RowDeleted( size_t row );
176 virtual bool RowChanged( size_t row );
177 virtual bool ValueChanged( size_t col, size_t row );
4eccd3a1 178 virtual bool RowsReordered( size_t *new_order );
8981608c
RR
179 virtual bool Cleared();
180
4627af27
RR
181 // called if child's notifiers are called
182 bool ChildRowAppended();
183 bool ChildRowPrepended();
184 bool ChildRowInserted( size_t before );
185 bool ChildRowDeleted( size_t row );
186 bool ChildRowChanged( size_t row );
4eccd3a1 187 bool ChildValueChanged( size_t col, size_t row );
4627af27
RR
188 bool ChildRowsReordered( size_t *new_order );
189 bool ChildCleared();
4eccd3a1 190
8f850e28
RR
191 virtual void Resort();
192
8981608c
RR
193private:
194 wxDataViewListModel *m_child;
195 wxDataViewSortedIndexArray m_array;
4eccd3a1 196 wxDataViewListModelNotifier *m_notifierOnChild;
8981608c
RR
197
198protected:
199 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel)
200};
201
f554a14b 202// ---------------------------------------------------------
6842a71a 203// wxDataViewCellBase
f554a14b 204// ---------------------------------------------------------
fa28826d 205
6842a71a 206enum wxDataViewCellMode
fa28826d 207{
6842a71a
RR
208 wxDATAVIEW_CELL_INERT,
209 wxDATAVIEW_CELL_ACTIVATABLE,
210 wxDATAVIEW_CELL_EDITABLE
fa28826d
RR
211};
212
6842a71a
RR
213enum wxDataViewCellRenderState
214{
215 wxDATAVIEW_CELL_SELECTED = 1,
216 wxDATAVIEW_CELL_PRELIT = 2,
217 wxDATAVIEW_CELL_INSENSITIVE = 4,
218 wxDATAVIEW_CELL_FOCUSED = 8
219};
220
f460c29d 221class WXDLLIMPEXP_ADV wxDataViewCellBase: public wxObject
6842a71a
RR
222{
223public:
224 wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
225
f554a14b
WS
226 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) { return true; }
227 virtual bool GetValue( wxVariant& WXUNUSED(value) ) { return true; }
228 virtual bool Validate( wxVariant& WXUNUSED(value) ) { return true; }
229
0fdc2321
RR
230 wxString GetVariantType() { return m_variantType; }
231 wxDataViewCellMode GetMode() { return m_mode; }
f554a14b 232
6842a71a
RR
233 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
234 wxDataViewColumn* GetOwner() { return m_owner; }
f554a14b 235
a7f61f76 236protected:
6842a71a
RR
237 wxDataViewCellMode m_mode;
238 wxString m_variantType;
239 wxDataViewColumn *m_owner;
240
241protected:
242 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase)
243};
244
f554a14b 245// ---------------------------------------------------------
6842a71a 246// wxDataViewColumnBase
f554a14b 247// ---------------------------------------------------------
6842a71a 248
fa28826d
RR
249enum wxDataViewColumnFlags
250{
251 wxDATAVIEW_COL_RESIZABLE = 1,
252 wxDATAVIEW_COL_SORTABLE = 2,
253 wxDATAVIEW_COL_HIDDEN = 4
254};
255
533544f2
RR
256enum wxDataViewColumnSizing
257{
258 wxDATAVIEW_COL_WIDTH_FIXED,
259 wxDATAVIEW_COL_WIDTH_AUTO,
260 wxDATAVIEW_COL_WIDTH_GROW
261};
262
f460c29d 263class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
fa28826d
RR
264{
265public:
07b6378f 266 wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column,
533544f2 267 int fixed_width = 80, wxDataViewColumnSizing sizing = wxDATAVIEW_COL_WIDTH_FIXED, int flags = 0 );
d3c7fc99 268 virtual ~wxDataViewColumnBase();
fa28826d
RR
269
270 virtual void SetTitle( const wxString &title );
271 virtual wxString GetTitle();
07b6378f 272
6842a71a 273 wxDataViewCell* GetCell() { return m_cell; }
f554a14b 274
6842a71a 275 size_t GetModelColumn() { return m_model_column; }
f554a14b 276
6842a71a
RR
277 void SetOwner( wxDataViewCtrl *owner ) { m_owner = owner; }
278 wxDataViewCtrl *GetOwner() { return m_owner; }
07b6378f 279
533544f2 280 virtual int GetWidth() = 0;
07b6378f 281
533544f2
RR
282 virtual void SetFixedWidth( int width ) = 0;
283 virtual int GetFixedWidth() = 0;
fa28826d
RR
284
285private:
286 wxDataViewCtrl *m_ctrl;
6842a71a
RR
287 wxDataViewCell *m_cell;
288 int m_model_column;
fa28826d
RR
289 int m_flags;
290 wxString m_title;
6842a71a 291 wxDataViewCtrl *m_owner;
fa28826d
RR
292
293protected:
294 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
295};
296
f554a14b 297// ---------------------------------------------------------
239eaa41 298// wxDataViewCtrlBase
f554a14b 299// ---------------------------------------------------------
239eaa41 300
c21f7aa1
RR
301#define wxDV_SINGLE 0x0000 // for convenience
302#define wxDV_MULTIPLE 0x0020 // can select multiple items
303
f460c29d 304class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
239eaa41
RR
305{
306public:
307 wxDataViewCtrlBase();
d3c7fc99 308 virtual ~wxDataViewCtrlBase();
f554a14b 309
6e2e590f
RR
310 virtual bool AssociateModel( wxDataViewListModel *model );
311 wxDataViewListModel* GetModel();
f554a14b 312
605c2c4a
RR
313 virtual bool AppendTextColumn( const wxString &label, size_t model_column );
314 virtual bool AppendToggleColumn( const wxString &label, size_t model_column );
ad63bf41 315 virtual bool AppendProgressColumn( const wxString &label, size_t model_column );
4d496ecb 316 virtual bool AppendDateColumn( const wxString &label, size_t model_column );
f554a14b 317 virtual bool AppendColumn( wxDataViewColumn *col );
fa28826d
RR
318 virtual size_t GetNumberOfColumns();
319 virtual bool DeleteColumn( size_t pos );
320 virtual bool ClearColumns();
321 virtual wxDataViewColumn* GetColumn( size_t pos );
f554a14b 322
239eaa41 323private:
6e2e590f 324 wxDataViewListModel *m_model;
fa28826d 325 wxList m_cols;
bcd846ea 326
239eaa41 327protected:
260b9be7 328 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
239eaa41 329};
bcd846ea 330
4ed7af08
RR
331#if defined(wxUSE_GENERICDATAVIEWCTRL)
332 #include "wx/generic/dataview.h"
333#elif defined(__WXGTK20__)
bcd846ea
RR
334 #include "wx/gtk/dataview.h"
335#elif defined(__WXMAC__)
07b6378f
WS
336 // TODO
337 // #include "wx/mac/dataview.h"
bcd846ea
RR
338#else
339 #include "wx/generic/dataview.h"
340#endif
341
342#endif // wxUSE_DATAVIEWCTRL
343
344#endif
345 // _WX_DATAVIEW_H_BASE_