]>
Commit | Line | Data |
---|---|---|
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 | |
6ff7eee7 | 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 |
42 | class WXDLLIMPEXP_ADV wxDataViewModel; |
43 | class WXDLLIMPEXP_ADV wxDataViewListModel; | |
44 | class WXDLLIMPEXP_ADV wxDataViewCtrl; | |
45 | class WXDLLIMPEXP_ADV wxDataViewColumn; | |
46 | class WXDLLIMPEXP_ADV wxDataViewCell; | |
fa28826d | 47 | |
f460c29d | 48 | extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[]; |
bcd846ea | 49 | |
f554a14b | 50 | // --------------------------------------------------------- |
239eaa41 | 51 | // wxDataViewModel |
f554a14b | 52 | // --------------------------------------------------------- |
239eaa41 | 53 | |
f460c29d | 54 | class WXDLLIMPEXP_ADV wxDataViewModel: public wxObject |
239eaa41 RR |
55 | { |
56 | public: | |
57 | wxDataViewModel() { } | |
58 | virtual ~wxDataViewModel() { } | |
f554a14b | 59 | |
239eaa41 | 60 | protected: |
260b9be7 | 61 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel) |
239eaa41 RR |
62 | }; |
63 | ||
f554a14b | 64 | // --------------------------------------------------------- |
239eaa41 | 65 | // wxDataViewListModelNotifier |
f554a14b | 66 | // --------------------------------------------------------- |
239eaa41 | 67 | |
8f850e28 | 68 | |
f460c29d | 69 | class WXDLLIMPEXP_ADV wxDataViewListModelNotifier: public wxObject |
239eaa41 RR |
70 | { |
71 | public: | |
72 | wxDataViewListModelNotifier() { } | |
73 | virtual ~wxDataViewListModelNotifier() { } | |
f554a14b | 74 | |
239eaa41 RR |
75 | virtual bool RowAppended() = 0; |
76 | virtual bool RowPrepended() = 0; | |
0a71f9e9 RR |
77 | virtual bool RowInserted( unsigned int before ) = 0; |
78 | virtual bool RowDeleted( unsigned int row ) = 0; | |
79 | virtual bool RowChanged( unsigned int row ) = 0; | |
80 | virtual bool ValueChanged( unsigned int col, unsigned int row ) = 0; | |
81 | virtual bool RowsReordered( unsigned int *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 |
87 | private: |
88 | wxDataViewListModel *m_owner; | |
64ffb888 | 89 | }; |
239eaa41 | 90 | |
f554a14b | 91 | // --------------------------------------------------------- |
239eaa41 | 92 | // wxDataViewListModel |
f554a14b | 93 | // --------------------------------------------------------- |
239eaa41 | 94 | |
f460c29d | 95 | class WXDLLIMPEXP_ADV wxDataViewViewingColumn: public wxObject |
8f850e28 RR |
96 | { |
97 | public: | |
0a71f9e9 | 98 | wxDataViewViewingColumn( wxDataViewColumn *view_column, unsigned int model_column ) |
8f850e28 RR |
99 | { |
100 | m_viewColumn = view_column; | |
101 | m_modelColumn = model_column; | |
102 | } | |
f554a14b | 103 | |
8f850e28 | 104 | wxDataViewColumn *m_viewColumn; |
6ff7eee7 | 105 | unsigned int m_modelColumn; |
8f850e28 RR |
106 | }; |
107 | ||
f460c29d | 108 | class WXDLLIMPEXP_ADV wxDataViewListModel: public wxDataViewModel |
239eaa41 RR |
109 | { |
110 | public: | |
111 | wxDataViewListModel(); | |
112 | virtual ~wxDataViewListModel(); | |
113 | ||
0a71f9e9 RR |
114 | virtual unsigned int GetNumberOfRows() = 0; |
115 | virtual unsigned int GetNumberOfCols() = 0; | |
a7f61f76 | 116 | // return type as reported by wxVariant |
0a71f9e9 | 117 | virtual wxString GetColType( unsigned int col ) = 0; |
a7f61f76 | 118 | // get value into a wxVariant |
0a71f9e9 | 119 | virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row ) = 0; |
a7f61f76 | 120 | // set value, call ValueChanged() afterwards! |
0a71f9e9 | 121 | virtual bool SetValue( wxVariant &variant, unsigned int col, unsigned int row ) = 0; |
239eaa41 RR |
122 | |
123 | // delegated notifiers | |
8981608c RR |
124 | virtual bool RowAppended(); |
125 | virtual bool RowPrepended(); | |
0a71f9e9 RR |
126 | virtual bool RowInserted( unsigned int before ); |
127 | virtual bool RowDeleted( unsigned int row ); | |
128 | virtual bool RowChanged( unsigned int row ); | |
129 | virtual bool ValueChanged( unsigned int col, unsigned int row ); | |
130 | virtual bool RowsReordered( unsigned int *new_order ); | |
8981608c | 131 | virtual bool Cleared(); |
b5d777c7 | 132 | |
f554a14b | 133 | // Used internally |
0a71f9e9 | 134 | virtual void AddViewingColumn( wxDataViewColumn *view_column, unsigned int model_column ); |
8981608c | 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 | |
143 | protected: | |
260b9be7 | 144 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel) |
239eaa41 RR |
145 | }; |
146 | ||
f554a14b | 147 | // --------------------------------------------------------- |
8981608c | 148 | // wxDataViewSortedListModel |
f554a14b | 149 | // --------------------------------------------------------- |
8981608c RR |
150 | |
151 | typedef int (wxCALLBACK *wxDataViewListModelCompare) | |
0a71f9e9 | 152 | (unsigned int row1, unsigned int row2, unsigned int col, wxDataViewListModel* model ); |
8981608c | 153 | |
0a71f9e9 | 154 | WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSortedIndexArray, WXDLLIMPEXP_ADV); |
8981608c | 155 | |
f460c29d | 156 | class WXDLLIMPEXP_ADV wxDataViewSortedListModel: public wxDataViewListModel |
8981608c RR |
157 | { |
158 | public: | |
159 | wxDataViewSortedListModel( wxDataViewListModel *child ); | |
160 | virtual ~wxDataViewSortedListModel(); | |
161 | ||
0a71f9e9 RR |
162 | virtual unsigned int GetNumberOfRows(); |
163 | virtual unsigned int GetNumberOfCols(); | |
8981608c | 164 | // return type as reported by wxVariant |
0a71f9e9 | 165 | virtual wxString GetColType( unsigned int col ); |
8981608c | 166 | // get value into a wxVariant |
0a71f9e9 | 167 | virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row ); |
8981608c | 168 | // set value, call ValueChanged() afterwards! |
0a71f9e9 | 169 | virtual bool SetValue( wxVariant &variant, unsigned int col, unsigned int row ); |
8981608c | 170 | |
4627af27 | 171 | // called from user |
8981608c RR |
172 | virtual bool RowAppended(); |
173 | virtual bool RowPrepended(); | |
0a71f9e9 RR |
174 | virtual bool RowInserted( unsigned int before ); |
175 | virtual bool RowDeleted( unsigned int row ); | |
176 | virtual bool RowChanged( unsigned int row ); | |
177 | virtual bool ValueChanged( unsigned int col, unsigned int row ); | |
178 | virtual bool RowsReordered( unsigned int *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(); | |
0a71f9e9 RR |
184 | bool ChildRowInserted( unsigned int before ); |
185 | bool ChildRowDeleted( unsigned int row ); | |
186 | bool ChildRowChanged( unsigned int row ); | |
187 | bool ChildValueChanged( unsigned int col, unsigned int row ); | |
188 | bool ChildRowsReordered( unsigned int *new_order ); | |
4627af27 | 189 | bool ChildCleared(); |
4eccd3a1 | 190 | |
8f850e28 RR |
191 | virtual void Resort(); |
192 | ||
8981608c RR |
193 | private: |
194 | wxDataViewListModel *m_child; | |
195 | wxDataViewSortedIndexArray m_array; | |
4eccd3a1 | 196 | wxDataViewListModelNotifier *m_notifierOnChild; |
8981608c RR |
197 | |
198 | protected: | |
199 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel) | |
200 | }; | |
201 | ||
f554a14b | 202 | // --------------------------------------------------------- |
6842a71a | 203 | // wxDataViewCellBase |
f554a14b | 204 | // --------------------------------------------------------- |
fa28826d | 205 | |
6842a71a | 206 | enum wxDataViewCellMode |
fa28826d | 207 | { |
6842a71a RR |
208 | wxDATAVIEW_CELL_INERT, |
209 | wxDATAVIEW_CELL_ACTIVATABLE, | |
210 | wxDATAVIEW_CELL_EDITABLE | |
fa28826d RR |
211 | }; |
212 | ||
6842a71a RR |
213 | enum 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 | 221 | class WXDLLIMPEXP_ADV wxDataViewCellBase: public wxObject |
6842a71a RR |
222 | { |
223 | public: | |
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 | 236 | protected: |
6842a71a RR |
237 | wxDataViewCellMode m_mode; |
238 | wxString m_variantType; | |
239 | wxDataViewColumn *m_owner; | |
240 | ||
241 | protected: | |
242 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase) | |
243 | }; | |
244 | ||
f554a14b | 245 | // --------------------------------------------------------- |
6842a71a | 246 | // wxDataViewColumnBase |
f554a14b | 247 | // --------------------------------------------------------- |
6842a71a | 248 | |
fa28826d RR |
249 | enum wxDataViewColumnFlags |
250 | { | |
251 | wxDATAVIEW_COL_RESIZABLE = 1, | |
252 | wxDATAVIEW_COL_SORTABLE = 2, | |
253 | wxDATAVIEW_COL_HIDDEN = 4 | |
254 | }; | |
255 | ||
f460c29d | 256 | class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject |
fa28826d RR |
257 | { |
258 | public: | |
0a71f9e9 | 259 | wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, unsigned int model_column, |
008b5a66 | 260 | int width = 80, int flags = wxDATAVIEW_COL_RESIZABLE ); |
d3c7fc99 | 261 | virtual ~wxDataViewColumnBase(); |
fa28826d RR |
262 | |
263 | virtual void SetTitle( const wxString &title ); | |
264 | virtual wxString GetTitle(); | |
07b6378f | 265 | |
6842a71a | 266 | wxDataViewCell* GetCell() { return m_cell; } |
f554a14b | 267 | |
0a71f9e9 | 268 | unsigned int GetModelColumn() { return m_model_column; } |
f554a14b | 269 | |
6842a71a RR |
270 | void SetOwner( wxDataViewCtrl *owner ) { m_owner = owner; } |
271 | wxDataViewCtrl *GetOwner() { return m_owner; } | |
07b6378f | 272 | |
533544f2 | 273 | virtual int GetWidth() = 0; |
07b6378f | 274 | |
fa28826d RR |
275 | private: |
276 | wxDataViewCtrl *m_ctrl; | |
6842a71a RR |
277 | wxDataViewCell *m_cell; |
278 | int m_model_column; | |
fa28826d RR |
279 | int m_flags; |
280 | wxString m_title; | |
6842a71a | 281 | wxDataViewCtrl *m_owner; |
fa28826d RR |
282 | |
283 | protected: | |
284 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase) | |
285 | }; | |
286 | ||
f554a14b | 287 | // --------------------------------------------------------- |
239eaa41 | 288 | // wxDataViewCtrlBase |
f554a14b | 289 | // --------------------------------------------------------- |
239eaa41 | 290 | |
c21f7aa1 RR |
291 | #define wxDV_SINGLE 0x0000 // for convenience |
292 | #define wxDV_MULTIPLE 0x0020 // can select multiple items | |
293 | ||
f460c29d | 294 | class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl |
239eaa41 RR |
295 | { |
296 | public: | |
297 | wxDataViewCtrlBase(); | |
d3c7fc99 | 298 | virtual ~wxDataViewCtrlBase(); |
f554a14b | 299 | |
6e2e590f RR |
300 | virtual bool AssociateModel( wxDataViewListModel *model ); |
301 | wxDataViewListModel* GetModel(); | |
f554a14b | 302 | |
0a71f9e9 RR |
303 | virtual bool AppendTextColumn( const wxString &label, unsigned int model_column ); |
304 | virtual bool AppendToggleColumn( const wxString &label, unsigned int model_column ); | |
305 | virtual bool AppendProgressColumn( const wxString &label, unsigned int model_column ); | |
306 | virtual bool AppendDateColumn( const wxString &label, unsigned int model_column ); | |
f554a14b | 307 | virtual bool AppendColumn( wxDataViewColumn *col ); |
0a71f9e9 RR |
308 | virtual unsigned int GetNumberOfColumns(); |
309 | virtual bool DeleteColumn( unsigned int pos ); | |
fa28826d | 310 | virtual bool ClearColumns(); |
0a71f9e9 | 311 | virtual wxDataViewColumn* GetColumn( unsigned int pos ); |
f554a14b | 312 | |
6ff7eee7 RR |
313 | virtual void SetSelection( int row ) = 0; // -1 for unselect |
314 | inline void ClearSelection() { SetSelection( -1 ); } | |
315 | virtual void SetSelectionRange( unsigned int from, unsigned int to ) = 0; | |
316 | virtual void SetSelections( const wxArrayInt& aSelections) = 0; | |
317 | ||
318 | virtual bool IsSelected( unsigned int row ) const = 0; | |
319 | virtual int GetSelection() const = 0; | |
320 | virtual int GetSelections(wxArrayInt& aSelections) const = 0; | |
321 | ||
239eaa41 | 322 | private: |
6e2e590f | 323 | wxDataViewListModel *m_model; |
fa28826d | 324 | wxList m_cols; |
bcd846ea | 325 | |
239eaa41 | 326 | protected: |
260b9be7 | 327 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) |
239eaa41 | 328 | }; |
bcd846ea | 329 | |
eb7f97f8 RR |
330 | |
331 | // ---------------------------------------------------------------------------- | |
332 | // wxDataViewEvent - the event class for the wxDataViewCtrl notifications | |
333 | // ---------------------------------------------------------------------------- | |
334 | ||
335 | class WXDLLEXPORT wxDataViewEvent : public wxNotifyEvent | |
336 | { | |
337 | public: | |
338 | wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
339 | : wxNotifyEvent(commandType, winid), | |
340 | m_col(-1), | |
341 | m_row(-1), | |
342 | m_model(NULL), | |
343 | m_value(wxNullVariant), | |
344 | m_editCancelled(false) | |
345 | { } | |
346 | ||
347 | wxDataViewEvent(const wxDataViewEvent& event) | |
348 | : wxNotifyEvent(event), | |
349 | m_col(event.m_col), | |
350 | m_row(event.m_col), | |
351 | m_model(event.m_model), | |
352 | m_value(event.m_value), | |
353 | m_editCancelled(event.m_editCancelled) | |
354 | { } | |
355 | ||
356 | int GetColumn() const { return m_col; } | |
357 | void SetColumn( int col ) { m_col = col; } | |
358 | int GetRow() const { return m_row; } | |
359 | void SetRow( int row ) { m_row = row; } | |
360 | wxDataViewModel* GetModel() const { return m_model; } | |
361 | void SetModel( wxDataViewModel *model ) { m_model = model; } | |
362 | const wxVariant &GetValue() const { return m_value; } | |
363 | void SetValue( const wxVariant &value ) { m_value = value; } | |
364 | ||
365 | // was label editing canceled? (for wxEVT_COMMAND_DATVIEW_END_LABEL_EDIT only) | |
366 | bool IsEditCancelled() const { return m_editCancelled; } | |
367 | void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; } | |
368 | ||
369 | virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } | |
370 | ||
371 | protected: | |
372 | int m_col; | |
373 | int m_row; | |
374 | wxDataViewModel *m_model; | |
375 | wxVariant m_value; | |
376 | bool m_editCancelled; | |
377 | ||
378 | private: | |
379 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) | |
380 | }; | |
381 | ||
382 | BEGIN_DECLARE_EVENT_TYPES() | |
383 | DECLARE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, -1) | |
384 | END_DECLARE_EVENT_TYPES() | |
385 | ||
386 | typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); | |
387 | ||
388 | #define wxDataViewEventHandler(func) \ | |
389 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func) | |
390 | ||
391 | #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \ | |
392 | wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn)) | |
393 | ||
394 | #define EVT_DATAVIEW_ROW_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ROW_SELECTED, id, fn) | |
395 | ||
396 | ||
4ed7af08 RR |
397 | #if defined(wxUSE_GENERICDATAVIEWCTRL) |
398 | #include "wx/generic/dataview.h" | |
399 | #elif defined(__WXGTK20__) | |
bcd846ea RR |
400 | #include "wx/gtk/dataview.h" |
401 | #elif defined(__WXMAC__) | |
07b6378f WS |
402 | // TODO |
403 | // #include "wx/mac/dataview.h" | |
bcd846ea RR |
404 | #else |
405 | #include "wx/generic/dataview.h" | |
406 | #endif | |
407 | ||
408 | #endif // wxUSE_DATAVIEWCTRL | |
409 | ||
410 | #endif | |
411 | // _WX_DATAVIEW_H_BASE_ |