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