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