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