]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/dataview.h | |
3 | // Purpose: wxDataViewCtrl base classes | |
4 | // Author: Robert Roebling | |
5 | // Modified by: Bo Yang | |
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/textctrl.h" | |
20 | #include "wx/headercol.h" | |
21 | #include "wx/variant.h" | |
22 | #include "wx/dynarray.h" | |
23 | #include "wx/icon.h" | |
24 | #include "wx/weakref.h" | |
25 | #include "wx/vector.h" | |
26 | #include "wx/dataobj.h" | |
27 | ||
28 | class WXDLLIMPEXP_FWD_CORE wxImageList; | |
29 | ||
30 | #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__) | |
31 | // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__) | |
32 | #define wxHAS_GENERIC_DATAVIEWCTRL | |
33 | #endif | |
34 | ||
35 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
36 | // this symbol doesn't follow the convention for wxUSE_XXX symbols which | |
37 | // are normally always defined as either 0 or 1, so its use is deprecated | |
38 | // and it only exists for backwards compatibility, don't use it any more | |
39 | // and use wxHAS_GENERIC_DATAVIEWCTRL instead | |
40 | #define wxUSE_GENERICDATAVIEWCTRL | |
41 | #endif | |
42 | ||
43 | // ---------------------------------------------------------------------------- | |
44 | // wxDataViewCtrl globals | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
47 | class WXDLLIMPEXP_FWD_ADV wxDataViewItem; | |
48 | class WXDLLIMPEXP_FWD_ADV wxDataViewModel; | |
49 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; | |
50 | class WXDLLIMPEXP_FWD_ADV wxDataViewColumn; | |
51 | class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer; | |
52 | class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier; | |
53 | ||
54 | extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[]; | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // wxDataViewCtrl flags | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | // size of a wxDataViewRenderer without contents: | |
61 | #define wxDVC_DEFAULT_RENDERER_SIZE 20 | |
62 | ||
63 | // the default width of new (text) columns: | |
64 | #define wxDVC_DEFAULT_WIDTH 80 | |
65 | ||
66 | // the default width of new toggle columns: | |
67 | #define wxDVC_TOGGLE_DEFAULT_WIDTH 30 | |
68 | ||
69 | // the default minimal width of the columns: | |
70 | #define wxDVC_DEFAULT_MINWIDTH 30 | |
71 | ||
72 | // The default alignment of wxDataViewRenderers is to take | |
73 | // the alignment from the column it owns. | |
74 | #define wxDVR_DEFAULT_ALIGNMENT -1 | |
75 | ||
76 | ||
77 | // --------------------------------------------------------- | |
78 | // wxDataViewItem | |
79 | // --------------------------------------------------------- | |
80 | ||
81 | class WXDLLIMPEXP_ADV wxDataViewItem | |
82 | { | |
83 | public: | |
84 | wxDataViewItem( void* id = NULL ) | |
85 | { m_id = id; } | |
86 | wxDataViewItem( const wxDataViewItem &item ) | |
87 | { m_id = item.m_id; } | |
88 | bool IsOk() const { return m_id != NULL; } | |
89 | void* GetID() const { return m_id; } | |
90 | operator const void* () const { return m_id; } | |
91 | ||
92 | private: | |
93 | void* m_id; | |
94 | }; | |
95 | ||
96 | inline | |
97 | bool operator==(const wxDataViewItem& left, const wxDataViewItem& right) | |
98 | { | |
99 | return left.GetID() == right.GetID(); | |
100 | } | |
101 | ||
102 | inline | |
103 | bool operator!=(const wxDataViewItem& left, const wxDataViewItem& right) | |
104 | { | |
105 | return !(left == right); | |
106 | } | |
107 | ||
108 | WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray); | |
109 | ||
110 | // --------------------------------------------------------- | |
111 | // wxDataViewModelNotifier | |
112 | // --------------------------------------------------------- | |
113 | ||
114 | class WXDLLIMPEXP_ADV wxDataViewModelNotifier | |
115 | { | |
116 | public: | |
117 | wxDataViewModelNotifier() { m_owner = NULL; } | |
118 | virtual ~wxDataViewModelNotifier() { m_owner = NULL; } | |
119 | ||
120 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
121 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
122 | virtual bool ItemChanged( const wxDataViewItem &item ) = 0; | |
123 | virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
124 | virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
125 | virtual bool ItemsChanged( const wxDataViewItemArray &items ); | |
126 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0; | |
127 | virtual bool Cleared() = 0; | |
128 | ||
129 | virtual void Resort() = 0; | |
130 | ||
131 | void SetOwner( wxDataViewModel *owner ) { m_owner = owner; } | |
132 | wxDataViewModel *GetOwner() const { return m_owner; } | |
133 | ||
134 | private: | |
135 | wxDataViewModel *m_owner; | |
136 | }; | |
137 | ||
138 | ||
139 | ||
140 | // ---------------------------------------------------------------------------- | |
141 | // wxDataViewItemAttr: a structure containing the visual attributes of an item | |
142 | // ---------------------------------------------------------------------------- | |
143 | ||
144 | // TODO: this should be renamed to wxItemAttr or something general like this | |
145 | ||
146 | class WXDLLIMPEXP_ADV wxDataViewItemAttr | |
147 | { | |
148 | public: | |
149 | // ctors | |
150 | wxDataViewItemAttr() | |
151 | { | |
152 | m_bold = false; | |
153 | m_italic = false; | |
154 | } | |
155 | ||
156 | // setters | |
157 | void SetColour(const wxColour& colour) { m_colour = colour; } | |
158 | void SetBold( bool set ) { m_bold = set; } | |
159 | void SetItalic( bool set ) { m_italic = set; } | |
160 | ||
161 | // accessors | |
162 | bool HasColour() const { return m_colour.Ok(); } | |
163 | const wxColour& GetColour() const { return m_colour; } | |
164 | ||
165 | bool HasFont() const { return m_bold || m_italic; } | |
166 | bool GetBold() const { return m_bold; } | |
167 | bool GetItalic() const { return m_italic; } | |
168 | ||
169 | private: | |
170 | wxColour m_colour; | |
171 | bool m_bold; | |
172 | bool m_italic; | |
173 | }; | |
174 | ||
175 | ||
176 | // --------------------------------------------------------- | |
177 | // wxDataViewModel | |
178 | // --------------------------------------------------------- | |
179 | ||
180 | WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers, | |
181 | class WXDLLIMPEXP_ADV); | |
182 | ||
183 | class WXDLLIMPEXP_ADV wxDataViewModel: public wxRefCounter | |
184 | { | |
185 | public: | |
186 | wxDataViewModel(); | |
187 | ||
188 | virtual unsigned int GetColumnCount() const = 0; | |
189 | ||
190 | // return type as reported by wxVariant | |
191 | virtual wxString GetColumnType( unsigned int col ) const = 0; | |
192 | ||
193 | // get value into a wxVariant | |
194 | virtual void GetValue( wxVariant &variant, | |
195 | const wxDataViewItem &item, unsigned int col ) const = 0; | |
196 | ||
197 | // return true if the given item has a value to display in the given | |
198 | // column: this is always true except for container items which by default | |
199 | // only show their label in the first column (but see HasContainerColumns()) | |
200 | bool HasValue(const wxDataViewItem& item, unsigned col) const | |
201 | { | |
202 | return col == 0 || !IsContainer(item) || HasContainerColumns(item); | |
203 | } | |
204 | ||
205 | // usually ValueChanged() should be called after changing the value in the | |
206 | // model to update the control, ChangeValue() does it on its own while | |
207 | // SetValue() does not -- so while you will override SetValue(), you should | |
208 | // be usually calling ChangeValue() | |
209 | virtual bool SetValue(const wxVariant &variant, | |
210 | const wxDataViewItem &item, | |
211 | unsigned int col) = 0; | |
212 | ||
213 | bool ChangeValue(const wxVariant& variant, | |
214 | const wxDataViewItem& item, | |
215 | unsigned int col) | |
216 | { | |
217 | return SetValue(variant, item, col) && ValueChanged(item, col); | |
218 | } | |
219 | ||
220 | // Get text attribute, return false of default attributes should be used | |
221 | virtual bool GetAttr(const wxDataViewItem &WXUNUSED(item), | |
222 | unsigned int WXUNUSED(col), | |
223 | wxDataViewItemAttr &WXUNUSED(attr)) const | |
224 | { | |
225 | return false; | |
226 | } | |
227 | ||
228 | // define hierachy | |
229 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0; | |
230 | virtual bool IsContainer( const wxDataViewItem &item ) const = 0; | |
231 | // Is the container just a header or an item with all columns | |
232 | virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const | |
233 | { return false; } | |
234 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0; | |
235 | ||
236 | // delegated notifiers | |
237 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
238 | virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
239 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
240 | virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
241 | virtual bool ItemChanged( const wxDataViewItem &item ); | |
242 | virtual bool ItemsChanged( const wxDataViewItemArray &items ); | |
243 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
244 | virtual bool Cleared(); | |
245 | ||
246 | // delegatd action | |
247 | virtual void Resort(); | |
248 | ||
249 | void AddNotifier( wxDataViewModelNotifier *notifier ); | |
250 | void RemoveNotifier( wxDataViewModelNotifier *notifier ); | |
251 | ||
252 | // default compare function | |
253 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
254 | unsigned int column, bool ascending ) const; | |
255 | virtual bool HasDefaultCompare() const { return false; } | |
256 | ||
257 | // internal | |
258 | virtual bool IsVirtualListModel() const { return false; } | |
259 | ||
260 | protected: | |
261 | // the user should not delete this class directly: he should use DecRef() instead! | |
262 | virtual ~wxDataViewModel() { } | |
263 | ||
264 | wxDataViewModelNotifiers m_notifiers; | |
265 | }; | |
266 | ||
267 | // ---------------------------------------------------------------------------- | |
268 | // wxDataViewListModel: a model of a list, i.e. flat data structure without any | |
269 | // branches/containers, used as base class by wxDataViewIndexListModel and | |
270 | // wxDataViewVirtualListModel | |
271 | // ---------------------------------------------------------------------------- | |
272 | ||
273 | class WXDLLIMPEXP_ADV wxDataViewListModel : public wxDataViewModel | |
274 | { | |
275 | public: | |
276 | // derived classes should override these methods instead of | |
277 | // {Get,Set}Value() and GetAttr() inherited from the base class | |
278 | ||
279 | virtual void GetValueByRow(wxVariant &variant, | |
280 | unsigned row, unsigned col) const = 0; | |
281 | ||
282 | virtual bool SetValueByRow(const wxVariant &variant, | |
283 | unsigned row, unsigned col) = 0; | |
284 | ||
285 | virtual bool | |
286 | GetAttrByRow(unsigned WXUNUSED(row), unsigned WXUNUSED(col), | |
287 | wxDataViewItemAttr &WXUNUSED(attr)) const | |
288 | { | |
289 | return false; | |
290 | } | |
291 | ||
292 | ||
293 | // helper methods provided by list models only | |
294 | virtual unsigned GetRow( const wxDataViewItem &item ) const = 0; | |
295 | ||
296 | ||
297 | // implement some base class pure virtual directly | |
298 | virtual wxDataViewItem | |
299 | GetParent( const wxDataViewItem & WXUNUSED(item) ) const | |
300 | { | |
301 | // items never have valid parent in this model | |
302 | return wxDataViewItem(); | |
303 | } | |
304 | ||
305 | virtual bool IsContainer( const wxDataViewItem &item ) const | |
306 | { | |
307 | // only the invisible (and invalid) root item has children | |
308 | return !item.IsOk(); | |
309 | } | |
310 | ||
311 | // and implement some others by forwarding them to our own ones | |
312 | virtual void GetValue( wxVariant &variant, | |
313 | const wxDataViewItem &item, unsigned int col ) const | |
314 | { | |
315 | GetValueByRow(variant, GetRow(item), col); | |
316 | } | |
317 | ||
318 | virtual bool SetValue( const wxVariant &variant, | |
319 | const wxDataViewItem &item, unsigned int col ) | |
320 | { | |
321 | return SetValueByRow( variant, GetRow(item), col ); | |
322 | } | |
323 | ||
324 | virtual bool GetAttr(const wxDataViewItem &item, unsigned int col, | |
325 | wxDataViewItemAttr &attr) const | |
326 | { | |
327 | return GetAttrByRow( GetRow(item), col, attr ); | |
328 | } | |
329 | }; | |
330 | ||
331 | // --------------------------------------------------------- | |
332 | // wxDataViewIndexListModel | |
333 | // --------------------------------------------------------- | |
334 | ||
335 | class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewListModel | |
336 | { | |
337 | public: | |
338 | wxDataViewIndexListModel( unsigned int initial_size = 0 ); | |
339 | ||
340 | void RowPrepended(); | |
341 | void RowInserted( unsigned int before ); | |
342 | void RowAppended(); | |
343 | void RowDeleted( unsigned int row ); | |
344 | void RowsDeleted( const wxArrayInt &rows ); | |
345 | void RowChanged( unsigned int row ); | |
346 | void RowValueChanged( unsigned int row, unsigned int col ); | |
347 | void Reset( unsigned int new_size ); | |
348 | ||
349 | // convert to/from row/wxDataViewItem | |
350 | ||
351 | virtual unsigned GetRow( const wxDataViewItem &item ) const; | |
352 | wxDataViewItem GetItem( unsigned int row ) const; | |
353 | ||
354 | // compare based on index | |
355 | ||
356 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
357 | unsigned int column, bool ascending ) const; | |
358 | virtual bool HasDefaultCompare() const; | |
359 | ||
360 | // implement base methods | |
361 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; | |
362 | ||
363 | unsigned int GetCount() const { return m_hash.GetCount(); } | |
364 | ||
365 | private: | |
366 | wxDataViewItemArray m_hash; | |
367 | unsigned int m_nextFreeID; | |
368 | bool m_ordered; | |
369 | }; | |
370 | ||
371 | // --------------------------------------------------------- | |
372 | // wxDataViewVirtualListModel | |
373 | // --------------------------------------------------------- | |
374 | ||
375 | #ifdef __WXMAC__ | |
376 | // better than nothing | |
377 | typedef wxDataViewIndexListModel wxDataViewVirtualListModel; | |
378 | #else | |
379 | ||
380 | class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewListModel | |
381 | { | |
382 | public: | |
383 | wxDataViewVirtualListModel( unsigned int initial_size = 0 ); | |
384 | ||
385 | void RowPrepended(); | |
386 | void RowInserted( unsigned int before ); | |
387 | void RowAppended(); | |
388 | void RowDeleted( unsigned int row ); | |
389 | void RowsDeleted( const wxArrayInt &rows ); | |
390 | void RowChanged( unsigned int row ); | |
391 | void RowValueChanged( unsigned int row, unsigned int col ); | |
392 | void Reset( unsigned int new_size ); | |
393 | ||
394 | // convert to/from row/wxDataViewItem | |
395 | ||
396 | virtual unsigned GetRow( const wxDataViewItem &item ) const; | |
397 | wxDataViewItem GetItem( unsigned int row ) const; | |
398 | ||
399 | // compare based on index | |
400 | ||
401 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
402 | unsigned int column, bool ascending ) const; | |
403 | virtual bool HasDefaultCompare() const; | |
404 | ||
405 | // implement base methods | |
406 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; | |
407 | ||
408 | unsigned int GetCount() const { return m_size; } | |
409 | ||
410 | // internal | |
411 | virtual bool IsVirtualListModel() const { return true; } | |
412 | ||
413 | private: | |
414 | unsigned int m_size; | |
415 | bool m_ordered; | |
416 | }; | |
417 | #endif | |
418 | ||
419 | //----------------------------------------------------------------------------- | |
420 | // wxDataViewEditorCtrlEvtHandler | |
421 | //----------------------------------------------------------------------------- | |
422 | ||
423 | class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler | |
424 | { | |
425 | public: | |
426 | wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner ); | |
427 | ||
428 | void AcceptChangesAndFinish(); | |
429 | void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; } | |
430 | ||
431 | protected: | |
432 | void OnChar( wxKeyEvent &event ); | |
433 | void OnTextEnter( wxCommandEvent &event ); | |
434 | void OnKillFocus( wxFocusEvent &event ); | |
435 | void OnIdle( wxIdleEvent &event ); | |
436 | ||
437 | private: | |
438 | wxDataViewRenderer *m_owner; | |
439 | wxControl *m_editorCtrl; | |
440 | bool m_finished; | |
441 | bool m_focusOnIdle; | |
442 | ||
443 | private: | |
444 | DECLARE_EVENT_TABLE() | |
445 | }; | |
446 | ||
447 | // ---------------------------------------------------------------------------- | |
448 | // wxDataViewRenderer and related classes | |
449 | // ---------------------------------------------------------------------------- | |
450 | ||
451 | #include "wx/dvrenderers.h" | |
452 | ||
453 | // --------------------------------------------------------- | |
454 | // wxDataViewColumnBase | |
455 | // --------------------------------------------------------- | |
456 | ||
457 | // for compatibility only, do not use | |
458 | enum wxDataViewColumnFlags | |
459 | { | |
460 | wxDATAVIEW_COL_RESIZABLE = wxCOL_RESIZABLE, | |
461 | wxDATAVIEW_COL_SORTABLE = wxCOL_SORTABLE, | |
462 | wxDATAVIEW_COL_REORDERABLE = wxCOL_REORDERABLE, | |
463 | wxDATAVIEW_COL_HIDDEN = wxCOL_HIDDEN | |
464 | }; | |
465 | ||
466 | class WXDLLIMPEXP_ADV wxDataViewColumnBase : public wxSettableHeaderColumn | |
467 | { | |
468 | public: | |
469 | // ctor for the text columns: takes ownership of renderer | |
470 | wxDataViewColumnBase(wxDataViewRenderer *renderer, | |
471 | unsigned int model_column) | |
472 | { | |
473 | Init(renderer, model_column); | |
474 | } | |
475 | ||
476 | // ctor for the bitmap columns | |
477 | wxDataViewColumnBase(const wxBitmap& bitmap, | |
478 | wxDataViewRenderer *renderer, | |
479 | unsigned int model_column) | |
480 | : m_bitmap(bitmap) | |
481 | { | |
482 | Init(renderer, model_column); | |
483 | } | |
484 | ||
485 | virtual ~wxDataViewColumnBase(); | |
486 | ||
487 | // setters: | |
488 | virtual void SetOwner( wxDataViewCtrl *owner ) | |
489 | { m_owner = owner; } | |
490 | ||
491 | // getters: | |
492 | unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); } | |
493 | wxDataViewCtrl *GetOwner() const { return m_owner; } | |
494 | wxDataViewRenderer* GetRenderer() const { return m_renderer; } | |
495 | ||
496 | // implement some of base class pure virtuals (the rest is port-dependent | |
497 | // and done differently in generic and native versions) | |
498 | virtual void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; } | |
499 | virtual wxBitmap GetBitmap() const { return m_bitmap; } | |
500 | ||
501 | protected: | |
502 | wxDataViewRenderer *m_renderer; | |
503 | int m_model_column; | |
504 | wxBitmap m_bitmap; | |
505 | wxDataViewCtrl *m_owner; | |
506 | ||
507 | private: | |
508 | // common part of all ctors | |
509 | void Init(wxDataViewRenderer *renderer, unsigned int model_column); | |
510 | }; | |
511 | ||
512 | // --------------------------------------------------------- | |
513 | // wxDataViewCtrlBase | |
514 | // --------------------------------------------------------- | |
515 | ||
516 | #define wxDV_SINGLE 0x0000 // for convenience | |
517 | #define wxDV_MULTIPLE 0x0001 // can select multiple items | |
518 | ||
519 | #define wxDV_NO_HEADER 0x0002 // column titles not visible | |
520 | #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows | |
521 | #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns | |
522 | ||
523 | #define wxDV_ROW_LINES 0x0010 // alternating colour in rows | |
524 | #define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height | |
525 | ||
526 | class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl | |
527 | { | |
528 | public: | |
529 | wxDataViewCtrlBase(); | |
530 | virtual ~wxDataViewCtrlBase(); | |
531 | ||
532 | // model | |
533 | // ----- | |
534 | ||
535 | virtual bool AssociateModel( wxDataViewModel *model ); | |
536 | wxDataViewModel* GetModel(); | |
537 | const wxDataViewModel* GetModel() const; | |
538 | ||
539 | ||
540 | // column management | |
541 | // ----------------- | |
542 | ||
543 | wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column, | |
544 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
545 | wxAlignment align = wxALIGN_NOT, | |
546 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
547 | wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column, | |
548 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
549 | wxAlignment align = wxALIGN_NOT, | |
550 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
551 | wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column, | |
552 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
553 | wxAlignment align = wxALIGN_CENTER, | |
554 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
555 | wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column, | |
556 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
557 | wxAlignment align = wxALIGN_CENTER, | |
558 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
559 | wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column, | |
560 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
561 | wxAlignment align = wxALIGN_NOT, | |
562 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
563 | wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column, | |
564 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
565 | wxAlignment align = wxALIGN_CENTER, | |
566 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
567 | wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column, | |
568 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
569 | wxAlignment align = wxALIGN_NOT, | |
570 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
571 | wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
572 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
573 | wxAlignment align = wxALIGN_NOT, | |
574 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
575 | wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column, | |
576 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
577 | wxAlignment align = wxALIGN_CENTER, | |
578 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
579 | wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column, | |
580 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
581 | wxAlignment align = wxALIGN_CENTER, | |
582 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
583 | wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column, | |
584 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
585 | wxAlignment align = wxALIGN_NOT, | |
586 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
587 | wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
588 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
589 | wxAlignment align = wxALIGN_CENTER, | |
590 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
591 | ||
592 | wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column, | |
593 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
594 | wxAlignment align = wxALIGN_NOT, | |
595 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
596 | wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column, | |
597 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
598 | wxAlignment align = wxALIGN_NOT, | |
599 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
600 | wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column, | |
601 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
602 | wxAlignment align = wxALIGN_CENTER, | |
603 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
604 | wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column, | |
605 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
606 | wxAlignment align = wxALIGN_CENTER, | |
607 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
608 | wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column, | |
609 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
610 | wxAlignment align = wxALIGN_NOT, | |
611 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
612 | wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
613 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
614 | wxAlignment align = wxALIGN_CENTER, | |
615 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
616 | wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
617 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
618 | wxAlignment align = wxALIGN_NOT, | |
619 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
620 | wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
621 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
622 | wxAlignment align = wxALIGN_NOT, | |
623 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
624 | wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
625 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
626 | wxAlignment align = wxALIGN_CENTER, | |
627 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
628 | wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
629 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
630 | wxAlignment align = wxALIGN_CENTER, | |
631 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
632 | wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
633 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
634 | wxAlignment align = wxALIGN_NOT, | |
635 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
636 | wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
637 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
638 | wxAlignment align = wxALIGN_CENTER, | |
639 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
640 | ||
641 | virtual bool PrependColumn( wxDataViewColumn *col ); | |
642 | virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); | |
643 | virtual bool AppendColumn( wxDataViewColumn *col ); | |
644 | ||
645 | virtual unsigned int GetColumnCount() const = 0; | |
646 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0; | |
647 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0; | |
648 | ||
649 | virtual bool DeleteColumn( wxDataViewColumn *column ) = 0; | |
650 | virtual bool ClearColumns() = 0; | |
651 | ||
652 | void SetExpanderColumn( wxDataViewColumn *col ) | |
653 | { m_expander_column = col ; DoSetExpanderColumn(); } | |
654 | wxDataViewColumn *GetExpanderColumn() const | |
655 | { return m_expander_column; } | |
656 | ||
657 | virtual wxDataViewColumn *GetSortingColumn() const = 0; | |
658 | ||
659 | ||
660 | // items management | |
661 | // ---------------- | |
662 | ||
663 | void SetIndent( int indent ) | |
664 | { m_indent = indent ; DoSetIndent(); } | |
665 | int GetIndent() const | |
666 | { return m_indent; } | |
667 | ||
668 | virtual wxDataViewItem GetSelection() const = 0; | |
669 | virtual int GetSelections( wxDataViewItemArray & sel ) const = 0; | |
670 | virtual void SetSelections( const wxDataViewItemArray & sel ) = 0; | |
671 | virtual void Select( const wxDataViewItem & item ) = 0; | |
672 | virtual void Unselect( const wxDataViewItem & item ) = 0; | |
673 | virtual bool IsSelected( const wxDataViewItem & item ) const = 0; | |
674 | ||
675 | virtual void SelectAll() = 0; | |
676 | virtual void UnselectAll() = 0; | |
677 | ||
678 | virtual void Expand( const wxDataViewItem & item ) = 0; | |
679 | virtual void ExpandAncestors( const wxDataViewItem & item ); | |
680 | virtual void Collapse( const wxDataViewItem & item ) = 0; | |
681 | virtual bool IsExpanded( const wxDataViewItem & item ) const = 0; | |
682 | ||
683 | virtual void EnsureVisible( const wxDataViewItem & item, | |
684 | const wxDataViewColumn *column = NULL ) = 0; | |
685 | virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0; | |
686 | virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0; | |
687 | ||
688 | #if wxUSE_DRAG_AND_DROP | |
689 | virtual bool EnableDragSource(const wxDataFormat& WXUNUSED(format)) | |
690 | { return false; } | |
691 | virtual bool EnableDropTarget(const wxDataFormat& WXUNUSED(format)) | |
692 | { return false; } | |
693 | #endif // wxUSE_DRAG_AND_DROP | |
694 | ||
695 | // define control visual attributes | |
696 | // -------------------------------- | |
697 | ||
698 | virtual wxVisualAttributes GetDefaultAttributes() const | |
699 | { | |
700 | return GetClassDefaultAttributes(GetWindowVariant()); | |
701 | } | |
702 | ||
703 | static wxVisualAttributes | |
704 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL) | |
705 | { | |
706 | return wxControl::GetCompositeControlsDefaultAttributes(variant); | |
707 | } | |
708 | ||
709 | protected: | |
710 | virtual void DoSetExpanderColumn() = 0 ; | |
711 | virtual void DoSetIndent() = 0; | |
712 | ||
713 | private: | |
714 | wxDataViewModel *m_model; | |
715 | wxDataViewColumn *m_expander_column; | |
716 | int m_indent ; | |
717 | ||
718 | protected: | |
719 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) | |
720 | }; | |
721 | ||
722 | // ---------------------------------------------------------------------------- | |
723 | // wxDataViewEvent - the event class for the wxDataViewCtrl notifications | |
724 | // ---------------------------------------------------------------------------- | |
725 | ||
726 | class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent | |
727 | { | |
728 | public: | |
729 | wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
730 | : wxNotifyEvent(commandType, winid), | |
731 | m_item(0), | |
732 | m_col(-1), | |
733 | m_model(NULL), | |
734 | m_value(wxNullVariant), | |
735 | m_column(NULL), | |
736 | m_pos(-1,-1), | |
737 | m_cacheFrom(0), | |
738 | m_cacheTo(0) | |
739 | #if wxUSE_DRAG_AND_DROP | |
740 | , m_dataObject(NULL), | |
741 | m_dataBuffer(NULL), | |
742 | m_dataSize(0) | |
743 | #endif | |
744 | { } | |
745 | ||
746 | wxDataViewEvent(const wxDataViewEvent& event) | |
747 | : wxNotifyEvent(event), | |
748 | m_item(event.m_item), | |
749 | m_col(event.m_col), | |
750 | m_model(event.m_model), | |
751 | m_value(event.m_value), | |
752 | m_column(event.m_column), | |
753 | m_pos(m_pos), | |
754 | m_cacheFrom(event.m_cacheFrom), | |
755 | m_cacheTo(event.m_cacheTo) | |
756 | #if wxUSE_DRAG_AND_DROP | |
757 | , m_dataObject(event.m_dataObject), | |
758 | m_dataFormat(event.m_dataFormat), | |
759 | m_dataBuffer(event.m_dataBuffer), | |
760 | m_dataSize(event.m_dataSize) | |
761 | #endif | |
762 | { } | |
763 | ||
764 | wxDataViewItem GetItem() const { return m_item; } | |
765 | void SetItem( const wxDataViewItem &item ) { m_item = item; } | |
766 | ||
767 | int GetColumn() const { return m_col; } | |
768 | void SetColumn( int col ) { m_col = col; } | |
769 | ||
770 | wxDataViewModel* GetModel() const { return m_model; } | |
771 | void SetModel( wxDataViewModel *model ) { m_model = model; } | |
772 | ||
773 | const wxVariant &GetValue() const { return m_value; } | |
774 | void SetValue( const wxVariant &value ) { m_value = value; } | |
775 | ||
776 | // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only | |
777 | void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } | |
778 | wxDataViewColumn *GetDataViewColumn() const { return m_column; } | |
779 | ||
780 | // for wxEVT_DATAVIEW_CONTEXT_MENU only | |
781 | wxPoint GetPosition() const { return m_pos; } | |
782 | void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; } | |
783 | ||
784 | // For wxEVT_COMMAND_DATAVIEW_CACHE_HINT | |
785 | int GetCacheFrom() const { return m_cacheFrom; } | |
786 | int GetCacheTo() const { return m_cacheTo; } | |
787 | void SetCache(int from, int to) { m_cacheFrom = from; m_cacheTo = to; } | |
788 | ||
789 | ||
790 | #if wxUSE_DRAG_AND_DROP | |
791 | // For drag operations | |
792 | void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; } | |
793 | wxDataObject *GetDataObject() const { return m_dataObject; } | |
794 | ||
795 | // For drop operations | |
796 | void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; } | |
797 | wxDataFormat GetDataFormat() const { return m_dataFormat; } | |
798 | void SetDataSize( size_t size ) { m_dataSize = size; } | |
799 | size_t GetDataSize() const { return m_dataSize; } | |
800 | void SetDataBuffer( void* buf ) { m_dataBuffer = buf;} | |
801 | void *GetDataBuffer() const { return m_dataBuffer; } | |
802 | #endif // wxUSE_DRAG_AND_DROP | |
803 | ||
804 | virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } | |
805 | ||
806 | protected: | |
807 | wxDataViewItem m_item; | |
808 | int m_col; | |
809 | wxDataViewModel *m_model; | |
810 | wxVariant m_value; | |
811 | wxDataViewColumn *m_column; | |
812 | wxPoint m_pos; | |
813 | int m_cacheFrom; | |
814 | int m_cacheTo; | |
815 | ||
816 | #if wxUSE_DRAG_AND_DROP | |
817 | wxDataObject *m_dataObject; | |
818 | ||
819 | wxDataFormat m_dataFormat; | |
820 | void* m_dataBuffer; | |
821 | size_t m_dataSize; | |
822 | #endif // wxUSE_DRAG_AND_DROP | |
823 | ||
824 | private: | |
825 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) | |
826 | }; | |
827 | ||
828 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent ); | |
829 | ||
830 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent ); | |
831 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent ); | |
832 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent ); | |
833 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent ); | |
834 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent ); | |
835 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent ); | |
836 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent ); | |
837 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent ); | |
838 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent ); | |
839 | ||
840 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent ); | |
841 | ||
842 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent ); | |
843 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent ); | |
844 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent ); | |
845 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent ); | |
846 | ||
847 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent ); | |
848 | ||
849 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent ); | |
850 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent ); | |
851 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent ); | |
852 | ||
853 | typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); | |
854 | ||
855 | #define wxDataViewEventHandler(func) \ | |
856 | wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func) | |
857 | ||
858 | #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \ | |
859 | wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn)) | |
860 | ||
861 | #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn) | |
862 | ||
863 | #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn) | |
864 | #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn) | |
865 | #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn) | |
866 | #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn) | |
867 | #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn) | |
868 | #define EVT_DATAVIEW_ITEM_START_EDITING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_START_EDITING, id, fn) | |
869 | #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn) | |
870 | #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn) | |
871 | #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn) | |
872 | ||
873 | #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn) | |
874 | ||
875 | #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn) | |
876 | #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn) | |
877 | #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn) | |
878 | #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn) | |
879 | #define EVT_DATAVIEW_CACHE_HINT(id, fn) wx__DECLARE_DATAVIEWEVT(CACHE_HINT, id, fn) | |
880 | ||
881 | #define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn) | |
882 | #define EVT_DATAVIEW_ITEM_DROP_POSSIBLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP_POSSIBLE, id, fn) | |
883 | #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn) | |
884 | ||
885 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
886 | #include "wx/generic/dataview.h" | |
887 | #elif defined(__WXGTK20__) | |
888 | #include "wx/gtk/dataview.h" | |
889 | #elif defined(__WXMAC__) | |
890 | #include "wx/osx/dataview.h" | |
891 | #else | |
892 | #error "unknown native wxDataViewCtrl implementation" | |
893 | #endif | |
894 | ||
895 | //----------------------------------------------------------------------------- | |
896 | // wxDataViewListStore | |
897 | //----------------------------------------------------------------------------- | |
898 | ||
899 | class WXDLLIMPEXP_ADV wxDataViewListStoreLine | |
900 | { | |
901 | public: | |
902 | wxDataViewListStoreLine( wxClientData *data = NULL ) | |
903 | { | |
904 | m_data = data; | |
905 | } | |
906 | virtual ~wxDataViewListStoreLine() | |
907 | { | |
908 | delete m_data; | |
909 | } | |
910 | ||
911 | void SetData( wxClientData *data ) | |
912 | { if (m_data) delete m_data; m_data = data; } | |
913 | wxClientData *GetData() const | |
914 | { return m_data; } | |
915 | ||
916 | wxVector<wxVariant> m_values; | |
917 | ||
918 | private: | |
919 | wxClientData *m_data; | |
920 | }; | |
921 | ||
922 | ||
923 | class WXDLLIMPEXP_ADV wxDataViewListStore: public wxDataViewIndexListModel | |
924 | { | |
925 | public: | |
926 | wxDataViewListStore(); | |
927 | ~wxDataViewListStore(); | |
928 | ||
929 | void PrependColumn( const wxString &varianttype ); | |
930 | void InsertColumn( unsigned int pos, const wxString &varianttype ); | |
931 | void AppendColumn( const wxString &varianttype ); | |
932 | ||
933 | void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL ); | |
934 | void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL ); | |
935 | void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL ); | |
936 | void DeleteItem( unsigned int pos ); | |
937 | void DeleteAllItems(); | |
938 | ||
939 | // override base virtuals | |
940 | ||
941 | virtual unsigned int GetColumnCount() const; | |
942 | ||
943 | virtual wxString GetColumnType( unsigned int col ) const; | |
944 | ||
945 | virtual void GetValueByRow( wxVariant &value, | |
946 | unsigned int row, unsigned int col ) const; | |
947 | ||
948 | virtual bool SetValueByRow( const wxVariant &value, | |
949 | unsigned int row, unsigned int col ); | |
950 | ||
951 | ||
952 | public: | |
953 | wxVector<wxDataViewListStoreLine*> m_data; | |
954 | wxArrayString m_cols; | |
955 | }; | |
956 | ||
957 | //----------------------------------------------------------------------------- | |
958 | ||
959 | class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl | |
960 | { | |
961 | public: | |
962 | wxDataViewListCtrl(); | |
963 | wxDataViewListCtrl( wxWindow *parent, wxWindowID id, | |
964 | const wxPoint& pos = wxDefaultPosition, | |
965 | const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES, | |
966 | const wxValidator& validator = wxDefaultValidator ); | |
967 | ~wxDataViewListCtrl(); | |
968 | ||
969 | bool Create( wxWindow *parent, wxWindowID id, | |
970 | const wxPoint& pos = wxDefaultPosition, | |
971 | const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES, | |
972 | const wxValidator& validator = wxDefaultValidator ); | |
973 | ||
974 | wxDataViewListStore *GetStore() | |
975 | { return (wxDataViewListStore*) GetModel(); } | |
976 | const wxDataViewListStore *GetStore() const | |
977 | { return (const wxDataViewListStore*) GetModel(); } | |
978 | ||
979 | bool AppendColumn( wxDataViewColumn *column, const wxString &varianttype ); | |
980 | bool PrependColumn( wxDataViewColumn *column, const wxString &varianttype ); | |
981 | bool InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype ); | |
982 | ||
983 | // overridden from base class | |
984 | virtual bool PrependColumn( wxDataViewColumn *col ); | |
985 | virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col ); | |
986 | virtual bool AppendColumn( wxDataViewColumn *col ); | |
987 | ||
988 | wxDataViewColumn *AppendTextColumn( const wxString &label, | |
989 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
990 | int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE ); | |
991 | wxDataViewColumn *AppendToggleColumn( const wxString &label, | |
992 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, | |
993 | int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE ); | |
994 | wxDataViewColumn *AppendProgressColumn( const wxString &label, | |
995 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
996 | int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE ); | |
997 | wxDataViewColumn *AppendIconTextColumn( const wxString &label, | |
998 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
999 | int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1000 | ||
1001 | void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL ) | |
1002 | { GetStore()->AppendItem( values, data ); } | |
1003 | void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL ) | |
1004 | { GetStore()->PrependItem( values, data ); } | |
1005 | void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL ) | |
1006 | { GetStore()->InsertItem( row, values, data ); } | |
1007 | void DeleteItem( unsigned row ) | |
1008 | { GetStore()->DeleteItem( row ); } | |
1009 | void DeleteAllItems() | |
1010 | { GetStore()->DeleteAllItems(); } | |
1011 | ||
1012 | void SetValue( const wxVariant &value, unsigned int row, unsigned int col ) | |
1013 | { GetStore()->SetValueByRow( value, row, col ); | |
1014 | GetStore()->RowValueChanged( row, col); } | |
1015 | void GetValue( wxVariant &value, unsigned int row, unsigned int col ) | |
1016 | { GetStore()->GetValueByRow( value, row, col ); } | |
1017 | ||
1018 | void SetTextValue( const wxString &value, unsigned int row, unsigned int col ) | |
1019 | { GetStore()->SetValueByRow( value, row, col ); | |
1020 | GetStore()->RowValueChanged( row, col); } | |
1021 | wxString GetTextValue( unsigned int row, unsigned int col ) const | |
1022 | { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); } | |
1023 | ||
1024 | void SetToggleValue( bool value, unsigned int row, unsigned int col ) | |
1025 | { GetStore()->SetValueByRow( value, row, col ); | |
1026 | GetStore()->RowValueChanged( row, col); } | |
1027 | bool GetToggleValue( unsigned int row, unsigned int col ) const | |
1028 | { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); } | |
1029 | ||
1030 | void OnSize( wxSizeEvent &event ); | |
1031 | ||
1032 | private: | |
1033 | DECLARE_EVENT_TABLE() | |
1034 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl) | |
1035 | }; | |
1036 | ||
1037 | //----------------------------------------------------------------------------- | |
1038 | // wxDataViewTreeStore | |
1039 | //----------------------------------------------------------------------------- | |
1040 | ||
1041 | class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode | |
1042 | { | |
1043 | public: | |
1044 | wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent, | |
1045 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
1046 | virtual ~wxDataViewTreeStoreNode(); | |
1047 | ||
1048 | void SetText( const wxString &text ) | |
1049 | { m_text = text; } | |
1050 | wxString GetText() const | |
1051 | { return m_text; } | |
1052 | void SetIcon( const wxIcon &icon ) | |
1053 | { m_icon = icon; } | |
1054 | const wxIcon &GetIcon() const | |
1055 | { return m_icon; } | |
1056 | void SetData( wxClientData *data ) | |
1057 | { if (m_data) delete m_data; m_data = data; } | |
1058 | wxClientData *GetData() const | |
1059 | { return m_data; } | |
1060 | ||
1061 | wxDataViewItem GetItem() const | |
1062 | { return wxDataViewItem( (void*) this ); } | |
1063 | ||
1064 | virtual bool IsContainer() | |
1065 | { return false; } | |
1066 | ||
1067 | wxDataViewTreeStoreNode *GetParent() | |
1068 | { return m_parent; } | |
1069 | ||
1070 | private: | |
1071 | wxDataViewTreeStoreNode *m_parent; | |
1072 | wxString m_text; | |
1073 | wxIcon m_icon; | |
1074 | wxClientData *m_data; | |
1075 | }; | |
1076 | ||
1077 | WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList, | |
1078 | class WXDLLIMPEXP_ADV); | |
1079 | ||
1080 | class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode | |
1081 | { | |
1082 | public: | |
1083 | wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent, | |
1084 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
1085 | wxClientData *data = NULL ); | |
1086 | virtual ~wxDataViewTreeStoreContainerNode(); | |
1087 | ||
1088 | const wxDataViewTreeStoreNodeList &GetChildren() const | |
1089 | { return m_children; } | |
1090 | wxDataViewTreeStoreNodeList &GetChildren() | |
1091 | { return m_children; } | |
1092 | ||
1093 | void SetExpandedIcon( const wxIcon &icon ) | |
1094 | { m_iconExpanded = icon; } | |
1095 | const wxIcon &GetExpandedIcon() const | |
1096 | { return m_iconExpanded; } | |
1097 | ||
1098 | void SetExpanded( bool expanded = true ) | |
1099 | { m_isExpanded = expanded; } | |
1100 | bool IsExpanded() const | |
1101 | { return m_isExpanded; } | |
1102 | ||
1103 | virtual bool IsContainer() | |
1104 | { return true; } | |
1105 | ||
1106 | private: | |
1107 | wxDataViewTreeStoreNodeList m_children; | |
1108 | wxIcon m_iconExpanded; | |
1109 | bool m_isExpanded; | |
1110 | }; | |
1111 | ||
1112 | //----------------------------------------------------------------------------- | |
1113 | ||
1114 | class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel | |
1115 | { | |
1116 | public: | |
1117 | wxDataViewTreeStore(); | |
1118 | ~wxDataViewTreeStore(); | |
1119 | ||
1120 | wxDataViewItem AppendItem( const wxDataViewItem& parent, | |
1121 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
1122 | wxDataViewItem PrependItem( const wxDataViewItem& parent, | |
1123 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
1124 | wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1125 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
1126 | ||
1127 | wxDataViewItem PrependContainer( const wxDataViewItem& parent, | |
1128 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
1129 | wxClientData *data = NULL ); | |
1130 | wxDataViewItem AppendContainer( const wxDataViewItem& parent, | |
1131 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
1132 | wxClientData *data = NULL ); | |
1133 | wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1134 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
1135 | wxClientData *data = NULL ); | |
1136 | ||
1137 | wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const; | |
1138 | int GetChildCount( const wxDataViewItem& parent ) const; | |
1139 | ||
1140 | void SetItemText( const wxDataViewItem& item, const wxString &text ); | |
1141 | wxString GetItemText( const wxDataViewItem& item ) const; | |
1142 | void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ); | |
1143 | const wxIcon &GetItemIcon( const wxDataViewItem& item ) const; | |
1144 | void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ); | |
1145 | const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const; | |
1146 | void SetItemData( const wxDataViewItem& item, wxClientData *data ); | |
1147 | wxClientData *GetItemData( const wxDataViewItem& item ) const; | |
1148 | ||
1149 | void DeleteItem( const wxDataViewItem& item ); | |
1150 | void DeleteChildren( const wxDataViewItem& item ); | |
1151 | void DeleteAllItems(); | |
1152 | ||
1153 | // implement base methods | |
1154 | ||
1155 | virtual void GetValue( wxVariant &variant, | |
1156 | const wxDataViewItem &item, unsigned int col ) const; | |
1157 | virtual bool SetValue( const wxVariant &variant, | |
1158 | const wxDataViewItem &item, unsigned int col ); | |
1159 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; | |
1160 | virtual bool IsContainer( const wxDataViewItem &item ) const; | |
1161 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; | |
1162 | ||
1163 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
1164 | unsigned int column, bool ascending ) const; | |
1165 | ||
1166 | virtual bool HasDefaultCompare() const | |
1167 | { return true; } | |
1168 | virtual unsigned int GetColumnCount() const | |
1169 | { return 1; }; | |
1170 | virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const | |
1171 | { return wxT("wxDataViewIconText"); } | |
1172 | ||
1173 | wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const; | |
1174 | wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const; | |
1175 | wxDataViewTreeStoreNode *GetRoot() const { return m_root; } | |
1176 | ||
1177 | public: | |
1178 | wxDataViewTreeStoreNode *m_root; | |
1179 | }; | |
1180 | ||
1181 | //----------------------------------------------------------------------------- | |
1182 | ||
1183 | class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl | |
1184 | { | |
1185 | public: | |
1186 | wxDataViewTreeCtrl() { Init(); } | |
1187 | wxDataViewTreeCtrl(wxWindow *parent, | |
1188 | wxWindowID id, | |
1189 | const wxPoint& pos = wxDefaultPosition, | |
1190 | const wxSize& size = wxDefaultSize, | |
1191 | long style = wxDV_NO_HEADER | wxDV_ROW_LINES, | |
1192 | const wxValidator& validator = wxDefaultValidator) | |
1193 | { | |
1194 | Init(); | |
1195 | ||
1196 | Create(parent, id, pos, size, style, validator); | |
1197 | } | |
1198 | ||
1199 | virtual ~wxDataViewTreeCtrl(); | |
1200 | ||
1201 | bool Create(wxWindow *parent, | |
1202 | wxWindowID id, | |
1203 | const wxPoint& pos = wxDefaultPosition, | |
1204 | const wxSize& size = wxDefaultSize, | |
1205 | long style = wxDV_NO_HEADER | wxDV_ROW_LINES, | |
1206 | const wxValidator& validator = wxDefaultValidator); | |
1207 | ||
1208 | wxDataViewTreeStore *GetStore() | |
1209 | { return (wxDataViewTreeStore*) GetModel(); } | |
1210 | const wxDataViewTreeStore *GetStore() const | |
1211 | { return (const wxDataViewTreeStore*) GetModel(); } | |
1212 | ||
1213 | void SetImageList( wxImageList *imagelist ); | |
1214 | wxImageList* GetImageList() { return m_imageList; } | |
1215 | ||
1216 | wxDataViewItem AppendItem( const wxDataViewItem& parent, | |
1217 | const wxString &text, int icon = -1, wxClientData *data = NULL ); | |
1218 | wxDataViewItem PrependItem( const wxDataViewItem& parent, | |
1219 | const wxString &text, int icon = -1, wxClientData *data = NULL ); | |
1220 | wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1221 | const wxString &text, int icon = -1, wxClientData *data = NULL ); | |
1222 | ||
1223 | wxDataViewItem PrependContainer( const wxDataViewItem& parent, | |
1224 | const wxString &text, int icon = -1, int expanded = -1, | |
1225 | wxClientData *data = NULL ); | |
1226 | wxDataViewItem AppendContainer( const wxDataViewItem& parent, | |
1227 | const wxString &text, int icon = -1, int expanded = -1, | |
1228 | wxClientData *data = NULL ); | |
1229 | wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1230 | const wxString &text, int icon = -1, int expanded = -1, | |
1231 | wxClientData *data = NULL ); | |
1232 | ||
1233 | wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const | |
1234 | { return GetStore()->GetNthChild(parent, pos); } | |
1235 | int GetChildCount( const wxDataViewItem& parent ) const | |
1236 | { return GetStore()->GetChildCount(parent); } | |
1237 | ||
1238 | void SetItemText( const wxDataViewItem& item, const wxString &text ); | |
1239 | wxString GetItemText( const wxDataViewItem& item ) const | |
1240 | { return GetStore()->GetItemText(item); } | |
1241 | void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ); | |
1242 | const wxIcon &GetItemIcon( const wxDataViewItem& item ) const | |
1243 | { return GetStore()->GetItemIcon(item); } | |
1244 | void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ); | |
1245 | const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const | |
1246 | { return GetStore()->GetItemExpandedIcon(item); } | |
1247 | void SetItemData( const wxDataViewItem& item, wxClientData *data ) | |
1248 | { GetStore()->SetItemData(item,data); } | |
1249 | wxClientData *GetItemData( const wxDataViewItem& item ) const | |
1250 | { return GetStore()->GetItemData(item); } | |
1251 | ||
1252 | void DeleteItem( const wxDataViewItem& item ); | |
1253 | void DeleteChildren( const wxDataViewItem& item ); | |
1254 | void DeleteAllItems(); | |
1255 | ||
1256 | void OnExpanded( wxDataViewEvent &event ); | |
1257 | void OnCollapsed( wxDataViewEvent &event ); | |
1258 | void OnSize( wxSizeEvent &event ); | |
1259 | ||
1260 | private: | |
1261 | void Init() | |
1262 | { | |
1263 | m_imageList = NULL; | |
1264 | } | |
1265 | ||
1266 | wxImageList *m_imageList; | |
1267 | ||
1268 | private: | |
1269 | DECLARE_EVENT_TABLE() | |
1270 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl) | |
1271 | }; | |
1272 | ||
1273 | #endif // wxUSE_DATAVIEWCTRL | |
1274 | ||
1275 | #endif | |
1276 | // _WX_DATAVIEW_H_BASE_ |