]>
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 | #else | |
30 | #define wxUSE_GENERICDATAVIEWCTRL 1 | |
31 | #endif | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // wxDataViewCtrl flags | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | // ---------------------------------------------------------------------------- | |
38 | // wxDataViewCtrl globals | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
41 | class WXDLLIMPEXP_FWD_ADV wxDataViewItem; | |
42 | class WXDLLIMPEXP_FWD_ADV wxDataViewModel; | |
43 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; | |
44 | class WXDLLIMPEXP_FWD_ADV wxDataViewColumn; | |
45 | class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer; | |
46 | class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier; | |
47 | class wxDataViewEventModelNotifier; | |
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 | // wxDataViewItem | |
66 | // --------------------------------------------------------- | |
67 | ||
68 | class WXDLLIMPEXP_ADV wxDataViewItem | |
69 | { | |
70 | public: | |
71 | wxDataViewItem( void* id = NULL ) | |
72 | { m_id = id; } | |
73 | wxDataViewItem( const wxDataViewItem &item ) | |
74 | { m_id = item.m_id; } | |
75 | bool IsOk() const { return m_id != NULL; } | |
76 | void* GetID() const { return m_id; } | |
77 | ||
78 | private: | |
79 | void* m_id; | |
80 | }; | |
81 | ||
82 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right); | |
83 | ||
84 | // --------------------------------------------------------- | |
85 | // wxDataViewModel | |
86 | // --------------------------------------------------------- | |
87 | ||
88 | class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData | |
89 | { | |
90 | public: | |
91 | wxDataViewModel(); | |
92 | ||
93 | virtual unsigned int GetColumnCount() const = 0; | |
94 | ||
95 | // return type as reported by wxVariant | |
96 | virtual wxString GetColumnType( unsigned int col ) const = 0; | |
97 | ||
98 | // get value into a wxVariant | |
99 | virtual void GetValue( wxVariant &variant, | |
100 | const wxDataViewItem &item, unsigned int col ) const = 0; | |
101 | ||
102 | // set value, call ValueChanged() afterwards! | |
103 | virtual bool SetValue( const wxVariant &variant, | |
104 | const wxDataViewItem &item, unsigned int col ) = 0; | |
105 | ||
106 | // define hierachy | |
107 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0; | |
108 | virtual bool IsContainer( const wxDataViewItem &item ) const = 0; | |
109 | virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0; | |
110 | virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0; | |
111 | ||
112 | // delegated notifiers | |
113 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
114 | virtual bool ItemDeleted( const wxDataViewItem &item ); | |
115 | virtual bool ItemChanged( const wxDataViewItem &item ); | |
116 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
117 | virtual bool Cleared(); | |
118 | ||
119 | // delegatd action | |
120 | virtual void Resort(); | |
121 | ||
122 | void AddNotifier( wxDataViewModelNotifier *notifier ); | |
123 | void RemoveNotifier( wxDataViewModelNotifier *notifier ); | |
124 | ||
125 | // default compare function | |
126 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 ); | |
127 | ||
128 | void SetSortingColumn( unsigned int col ) { m_sortingColumn = col; } | |
129 | unsigned int GetSortingColumn() { return m_sortingColumn; } | |
130 | void SetSortOrderAscending( bool ascending ) { m_ascending = ascending; } | |
131 | bool GetSortOrderAscending() { return m_ascending; } | |
132 | ||
133 | ||
134 | protected: | |
135 | // the user should not delete this class directly: he should use DecRef() instead! | |
136 | virtual ~wxDataViewModel() { } | |
137 | ||
138 | wxList m_notifiers; | |
139 | unsigned int m_sortingColumn; | |
140 | bool m_ascending; | |
141 | }; | |
142 | ||
143 | // --------------------------------------------------------- | |
144 | // wxDataViewVirtualListModel | |
145 | // --------------------------------------------------------- | |
146 | ||
147 | class wxDataViewIndexListModel: public wxDataViewModel | |
148 | { | |
149 | public: | |
150 | wxDataViewIndexListModel(); | |
151 | ~wxDataViewIndexListModel(); | |
152 | ||
153 | virtual unsigned int GetRowCount() = 0; | |
154 | ||
155 | virtual void GetValue( wxVariant &variant, | |
156 | unsigned int row, unsigned int col ) const = 0; | |
157 | ||
158 | virtual bool SetValue( const wxVariant &variant, | |
159 | unsigned int row, unsigned int col ) = 0; | |
160 | ||
161 | void ItemPrepended(); | |
162 | void ItemInserted( unsigned int before ); | |
163 | void ItemAppended(); | |
164 | void ItemChanged( unsigned int row ); | |
165 | void ValueChanged( unsigned int row, unsigned int col ); | |
166 | ||
167 | wxDataViewItem GetItem( unsigned int row ); | |
168 | ||
169 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 ); | |
170 | ||
171 | }; | |
172 | ||
173 | // --------------------------------------------------------- | |
174 | // wxDataViewModelNotifier | |
175 | // --------------------------------------------------------- | |
176 | ||
177 | class WXDLLIMPEXP_ADV wxDataViewModelNotifier: public wxObject | |
178 | { | |
179 | public: | |
180 | wxDataViewModelNotifier() { } | |
181 | virtual ~wxDataViewModelNotifier() { m_owner = NULL; } | |
182 | ||
183 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
184 | virtual bool ItemDeleted( const wxDataViewItem &item ) = 0; | |
185 | virtual bool ItemChanged( const wxDataViewItem &item ) = 0; | |
186 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0; | |
187 | virtual bool Cleared() = 0; | |
188 | ||
189 | virtual void Resort() { }; | |
190 | ||
191 | void SetOwner( wxDataViewModel *owner ) { m_owner = owner; } | |
192 | wxDataViewModel *GetOwner() { return m_owner; } | |
193 | ||
194 | private: | |
195 | wxDataViewModel *m_owner; | |
196 | }; | |
197 | ||
198 | ||
199 | //----------------------------------------------------------------------------- | |
200 | // wxDataViewEditorCtrlEvtHandler | |
201 | //----------------------------------------------------------------------------- | |
202 | ||
203 | class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler | |
204 | { | |
205 | public: | |
206 | wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner ); | |
207 | ||
208 | void AcceptChangesAndFinish(); | |
209 | void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; } | |
210 | ||
211 | protected: | |
212 | void OnChar( wxKeyEvent &event ); | |
213 | void OnKillFocus( wxFocusEvent &event ); | |
214 | void OnIdle( wxIdleEvent &event ); | |
215 | ||
216 | private: | |
217 | wxDataViewRenderer *m_owner; | |
218 | wxControl *m_editorCtrl; | |
219 | bool m_finished; | |
220 | bool m_focusOnIdle; | |
221 | ||
222 | private: | |
223 | DECLARE_EVENT_TABLE() | |
224 | }; | |
225 | ||
226 | // --------------------------------------------------------- | |
227 | // wxDataViewRendererBase | |
228 | // --------------------------------------------------------- | |
229 | ||
230 | enum wxDataViewCellMode | |
231 | { | |
232 | wxDATAVIEW_CELL_INERT, | |
233 | wxDATAVIEW_CELL_ACTIVATABLE, | |
234 | wxDATAVIEW_CELL_EDITABLE | |
235 | }; | |
236 | ||
237 | enum wxDataViewCellRenderState | |
238 | { | |
239 | wxDATAVIEW_CELL_SELECTED = 1, | |
240 | wxDATAVIEW_CELL_PRELIT = 2, | |
241 | wxDATAVIEW_CELL_INSENSITIVE = 4, | |
242 | wxDATAVIEW_CELL_FOCUSED = 8 | |
243 | }; | |
244 | ||
245 | class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject | |
246 | { | |
247 | public: | |
248 | wxDataViewRendererBase( const wxString &varianttype, | |
249 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
250 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
251 | ||
252 | virtual bool Validate( wxVariant& WXUNUSED(value) ) | |
253 | { return true; } | |
254 | ||
255 | void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; } | |
256 | wxDataViewColumn* GetOwner() { return m_owner; } | |
257 | ||
258 | // renderer properties: | |
259 | ||
260 | virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0; | |
261 | virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0; | |
262 | ||
263 | wxString GetVariantType() const { return m_variantType; } | |
264 | ||
265 | virtual void SetMode( wxDataViewCellMode mode ) = 0; | |
266 | virtual wxDataViewCellMode GetMode() const = 0; | |
267 | ||
268 | // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but | |
269 | // rather an "int"; that's because for rendering cells it's allowed | |
270 | // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM) | |
271 | virtual void SetAlignment( int align ) = 0; | |
272 | virtual int GetAlignment() const = 0; | |
273 | ||
274 | // in-place editing | |
275 | virtual bool HasEditorCtrl() | |
276 | { return false; } | |
277 | virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), | |
278 | wxRect WXUNUSED(labelRect), | |
279 | const wxVariant& WXUNUSED(value)) | |
280 | { return NULL; } | |
281 | virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor), | |
282 | wxVariant& WXUNUSED(value)) | |
283 | { return false; } | |
284 | ||
285 | virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect ); | |
286 | virtual void CancelEditing(); | |
287 | virtual bool FinishEditing(); | |
288 | ||
289 | wxControl *GetEditorCtrl() { return m_editorCtrl; } | |
290 | ||
291 | protected: | |
292 | wxString m_variantType; | |
293 | wxDataViewColumn *m_owner; | |
294 | wxControl *m_editorCtrl; | |
295 | wxDataViewItem m_item; // for m_editorCtrl | |
296 | ||
297 | // internal utility: | |
298 | const wxDataViewCtrl* GetView() const; | |
299 | ||
300 | protected: | |
301 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase) | |
302 | }; | |
303 | ||
304 | // --------------------------------------------------------- | |
305 | // wxDataViewColumnBase | |
306 | // --------------------------------------------------------- | |
307 | ||
308 | enum wxDataViewColumnFlags | |
309 | { | |
310 | wxDATAVIEW_COL_RESIZABLE = 1, | |
311 | wxDATAVIEW_COL_SORTABLE = 2, | |
312 | wxDATAVIEW_COL_HIDDEN = 4 | |
313 | }; | |
314 | ||
315 | class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject | |
316 | { | |
317 | public: | |
318 | wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer, | |
319 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
320 | wxAlignment align = wxALIGN_CENTER, | |
321 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
322 | wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer, | |
323 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
324 | wxAlignment align = wxALIGN_CENTER, | |
325 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
326 | virtual ~wxDataViewColumnBase(); | |
327 | ||
328 | // setters: | |
329 | ||
330 | virtual void SetTitle( const wxString &title ) = 0; | |
331 | virtual void SetAlignment( wxAlignment align ) = 0; | |
332 | virtual void SetSortable( bool sortable ) = 0; | |
333 | virtual void SetResizeable( bool resizeable ) = 0; | |
334 | virtual void SetHidden( bool hidden ) = 0; | |
335 | virtual void SetSortOrder( bool ascending ) = 0; | |
336 | virtual void SetFlags( int flags ); | |
337 | virtual void SetOwner( wxDataViewCtrl *owner ) | |
338 | { m_owner = owner; } | |
339 | virtual void SetBitmap( const wxBitmap &bitmap ) | |
340 | { m_bitmap=bitmap; } | |
341 | ||
342 | virtual void SetMinWidth( int minWidth ) = 0; | |
343 | virtual void SetWidth( int width ) = 0; | |
344 | ||
345 | ||
346 | // getters: | |
347 | ||
348 | virtual wxString GetTitle() const = 0; | |
349 | virtual wxAlignment GetAlignment() const = 0; | |
350 | virtual int GetWidth() const = 0; | |
351 | virtual int GetMinWidth() const = 0; | |
352 | ||
353 | virtual int GetFlags() const; | |
354 | ||
355 | virtual bool IsSortable() const = 0; | |
356 | virtual bool IsResizeable() const = 0; | |
357 | virtual bool IsHidden() const = 0; | |
358 | virtual bool IsSortOrderAscending() const = 0; | |
359 | ||
360 | const wxBitmap &GetBitmap() const { return m_bitmap; } | |
361 | unsigned int GetModelColumn() const { return m_model_column; } | |
362 | ||
363 | wxDataViewCtrl *GetOwner() { return m_owner; } | |
364 | wxDataViewRenderer* GetRenderer() { return m_renderer; } | |
365 | ||
366 | protected: | |
367 | wxDataViewRenderer *m_renderer; | |
368 | int m_model_column; | |
369 | wxBitmap m_bitmap; | |
370 | wxDataViewCtrl *m_owner; | |
371 | ||
372 | protected: | |
373 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase) | |
374 | }; | |
375 | ||
376 | // --------------------------------------------------------- | |
377 | // wxDataViewCtrlBase | |
378 | // --------------------------------------------------------- | |
379 | ||
380 | #define wxDV_SINGLE 0x0000 // for convenience | |
381 | #define wxDV_MULTIPLE 0x0001 // can select multiple items | |
382 | ||
383 | #define wxDV_NO_HEADER 0x0002 // column titles not visible | |
384 | #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows | |
385 | #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns | |
386 | ||
387 | class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl | |
388 | { | |
389 | public: | |
390 | wxDataViewCtrlBase(); | |
391 | virtual ~wxDataViewCtrlBase(); | |
392 | ||
393 | virtual bool AssociateModel( wxDataViewModel *model ); | |
394 | wxDataViewModel* GetModel(); | |
395 | ||
396 | // short cuts | |
397 | bool AppendTextColumn( const wxString &label, unsigned int model_column, | |
398 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
399 | wxAlignment align = wxALIGN_CENTER, | |
400 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
401 | bool AppendToggleColumn( const wxString &label, unsigned int model_column, | |
402 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
403 | wxAlignment align = wxALIGN_CENTER, | |
404 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
405 | bool AppendProgressColumn( const wxString &label, unsigned int model_column, | |
406 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
407 | wxAlignment align = wxALIGN_CENTER, | |
408 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
409 | bool AppendDateColumn( const wxString &label, unsigned int model_column, | |
410 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
411 | wxAlignment align = wxALIGN_CENTER, | |
412 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
413 | bool AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
414 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
415 | wxAlignment align = wxALIGN_CENTER, | |
416 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
417 | bool AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
418 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
419 | wxAlignment align = wxALIGN_CENTER, | |
420 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
421 | bool AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
422 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
423 | wxAlignment align = wxALIGN_CENTER, | |
424 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
425 | bool AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
426 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
427 | wxAlignment align = wxALIGN_CENTER, | |
428 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
429 | bool AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
430 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
431 | wxAlignment align = wxALIGN_CENTER, | |
432 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
433 | bool AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
434 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
435 | wxAlignment align = wxALIGN_CENTER, | |
436 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
437 | ||
438 | virtual bool AppendColumn( wxDataViewColumn *col ); | |
439 | ||
440 | virtual unsigned int GetColumnCount() const; | |
441 | ||
442 | virtual bool DeleteColumn( unsigned int pos ); | |
443 | virtual bool ClearColumns(); | |
444 | virtual wxDataViewColumn* GetColumn( unsigned int pos ); | |
445 | ||
446 | void SetExpanderColumn( unsigned int col ) | |
447 | { m_expander_column = col ; DoSetExpanderColumn(); } | |
448 | unsigned int GetExpanderColumn() const | |
449 | { return m_expander_column; } | |
450 | ||
451 | void SetIndent( int indent ) | |
452 | { m_indent = indent ; DoSetIndent(); } | |
453 | int GetIndent() const | |
454 | { return m_indent; } | |
455 | ||
456 | // TODO selection code | |
457 | virtual wxDataViewItem GetSelection() = 0; | |
458 | ||
459 | protected: | |
460 | virtual void DoSetExpanderColumn() = 0 ; | |
461 | virtual void DoSetIndent() = 0; | |
462 | ||
463 | private: | |
464 | wxDataViewModel *m_model; | |
465 | wxList m_cols; | |
466 | wxDataViewEventModelNotifier *m_eventNotifier; | |
467 | unsigned int m_expander_column; | |
468 | int m_indent ; | |
469 | ||
470 | protected: | |
471 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) | |
472 | }; | |
473 | ||
474 | // ---------------------------------------------------------------------------- | |
475 | // wxDataViewEvent - the event class for the wxDataViewCtrl notifications | |
476 | // ---------------------------------------------------------------------------- | |
477 | ||
478 | class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent | |
479 | { | |
480 | public: | |
481 | wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
482 | : wxNotifyEvent(commandType, winid), | |
483 | m_item(0), | |
484 | m_col(-1), | |
485 | m_model(NULL), | |
486 | m_value(wxNullVariant), | |
487 | m_column(NULL) | |
488 | { } | |
489 | ||
490 | wxDataViewEvent(const wxDataViewEvent& event) | |
491 | : wxNotifyEvent(event), | |
492 | m_item(event.m_item), | |
493 | m_col(event.m_col), | |
494 | m_model(event.m_model), | |
495 | m_value(event.m_value), | |
496 | m_column(event.m_column) | |
497 | { } | |
498 | ||
499 | wxDataViewItem GetItem() const { return m_item; } | |
500 | void SetItem( const wxDataViewItem &item ) { m_item = item; } | |
501 | ||
502 | int GetColumn() const { return m_col; } | |
503 | void SetColumn( int col ) { m_col = col; } | |
504 | ||
505 | wxDataViewModel* GetModel() const { return m_model; } | |
506 | void SetModel( wxDataViewModel *model ) { m_model = model; } | |
507 | ||
508 | const wxVariant &GetValue() const { return m_value; } | |
509 | void SetValue( const wxVariant &value ) { m_value = value; } | |
510 | ||
511 | // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only | |
512 | void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } | |
513 | wxDataViewColumn *GetDataViewColumn() const { return m_column; } | |
514 | ||
515 | virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } | |
516 | ||
517 | protected: | |
518 | wxDataViewItem m_item; | |
519 | int m_col; | |
520 | wxDataViewModel *m_model; | |
521 | wxVariant m_value; | |
522 | wxDataViewColumn *m_column; | |
523 | ||
524 | private: | |
525 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) | |
526 | }; | |
527 | ||
528 | BEGIN_DECLARE_EVENT_TYPES() | |
529 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, -1) | |
530 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1) | |
531 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1) | |
532 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1) | |
533 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1) | |
534 | // notifications from the model to the control | |
535 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, -1) | |
536 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, -1) | |
537 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED, -1) | |
538 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, -1) | |
539 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, -1) | |
540 | END_DECLARE_EVENT_TYPES() | |
541 | ||
542 | typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); | |
543 | ||
544 | #define wxDataViewEventHandler(func) \ | |
545 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func) | |
546 | ||
547 | #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \ | |
548 | wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn)) | |
549 | ||
550 | #define EVT_DATAVIEW_ITEM_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_SELECTED, id, fn) | |
551 | #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn) | |
552 | #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn) | |
553 | #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn) | |
554 | #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn) | |
555 | ||
556 | #define EVT_DATAVIEW_MODEL_ITEM_ADDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_APPENDED, id, fn) | |
557 | #define EVT_DATAVIEW_MODEL_ITEM_DELETED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_DELETED, id, fn) | |
558 | #define EVT_DATAVIEW_MODEL_ITEM_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_CHANGED, id, fn) | |
559 | #define EVT_DATAVIEW_MODEL_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_VALUE_CHANGED, id, fn) | |
560 | #define EVT_DATAVIEW_MODEL_CLEARED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_CLEARED, id, fn) | |
561 | ||
562 | ||
563 | #if defined(wxUSE_GENERICDATAVIEWCTRL) | |
564 | #include "wx/generic/dataview.h" | |
565 | #elif defined(__WXGTK20__) | |
566 | #include "wx/gtk/dataview.h" | |
567 | #elif defined(__WXMAC__) | |
568 | #include "wx/mac/dataview.h" | |
569 | #else | |
570 | #include "wx/generic/dataview.h" | |
571 | #endif | |
572 | ||
573 | #endif // wxUSE_DATAVIEWCTRL | |
574 | ||
575 | #endif | |
576 | // _WX_DATAVIEW_H_BASE_ |