]>
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/control.h" | |
20 | #include "wx/textctrl.h" | |
21 | #include "wx/bitmap.h" | |
22 | #include "wx/variant.h" | |
23 | #include "wx/dynarray.h" | |
24 | #include "wx/icon.h" | |
25 | #include "wx/imaglist.h" | |
26 | #include "wx/weakref.h" | |
27 | ||
28 | class WXDLLIMPEXP_FWD_CORE wxDataFormat; | |
29 | ||
30 | #if defined(__WXGTK20__) | |
31 | // for testing | |
32 | // #define wxUSE_GENERICDATAVIEWCTRL 1 | |
33 | #elif defined(__WXMAC__) | |
34 | #else | |
35 | #define wxUSE_GENERICDATAVIEWCTRL 1 | |
36 | #endif | |
37 | ||
38 | // ---------------------------------------------------------------------------- | |
39 | // wxDataViewCtrl flags | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | // ---------------------------------------------------------------------------- | |
43 | // wxDataViewCtrl globals | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | class WXDLLIMPEXP_FWD_ADV wxDataViewItem; | |
47 | class WXDLLIMPEXP_FWD_ADV wxDataViewModel; | |
48 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; | |
49 | class WXDLLIMPEXP_FWD_ADV wxDataViewColumn; | |
50 | class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer; | |
51 | class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier; | |
52 | ||
53 | extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[]; | |
54 | ||
55 | // the default width of new (text) columns: | |
56 | #define wxDVC_DEFAULT_WIDTH 80 | |
57 | ||
58 | // the default width of new toggle columns: | |
59 | #define wxDVC_TOGGLE_DEFAULT_WIDTH 30 | |
60 | ||
61 | // the default minimal width of the columns: | |
62 | #define wxDVC_DEFAULT_MINWIDTH 30 | |
63 | ||
64 | // The default alignment of wxDataViewRenderers is to take | |
65 | // the alignment from the column it owns. | |
66 | #define wxDVR_DEFAULT_ALIGNMENT -1 | |
67 | ||
68 | ||
69 | // --------------------------------------------------------- | |
70 | // wxDataViewItem | |
71 | // --------------------------------------------------------- | |
72 | ||
73 | class WXDLLIMPEXP_ADV wxDataViewItem | |
74 | { | |
75 | public: | |
76 | wxDataViewItem( void* id = NULL ) | |
77 | { m_id = id; } | |
78 | wxDataViewItem( const wxDataViewItem &item ) | |
79 | { m_id = item.m_id; } | |
80 | bool IsOk() const { return m_id != NULL; } | |
81 | void* GetID() const { return m_id; } | |
82 | operator const void* () const { return m_id; } | |
83 | ||
84 | #ifdef __WXDEBUG__ | |
85 | void Print( const wxString &text ) const; | |
86 | #endif | |
87 | ||
88 | private: | |
89 | void* m_id; | |
90 | }; | |
91 | ||
92 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right); | |
93 | ||
94 | WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray); | |
95 | ||
96 | // --------------------------------------------------------- | |
97 | // wxDataViewModelNotifier | |
98 | // --------------------------------------------------------- | |
99 | ||
100 | class WXDLLIMPEXP_ADV wxDataViewModelNotifier | |
101 | { | |
102 | public: | |
103 | wxDataViewModelNotifier() { m_owner = NULL; } | |
104 | virtual ~wxDataViewModelNotifier() { m_owner = NULL; } | |
105 | ||
106 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
107 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
108 | virtual bool ItemChanged( const wxDataViewItem &item ) = 0; | |
109 | virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
110 | virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
111 | virtual bool ItemsChanged( const wxDataViewItemArray &items ); | |
112 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0; | |
113 | virtual bool Cleared() = 0; | |
114 | ||
115 | virtual void Resort() = 0; | |
116 | ||
117 | void SetOwner( wxDataViewModel *owner ) { m_owner = owner; } | |
118 | wxDataViewModel *GetOwner() const { return m_owner; } | |
119 | ||
120 | private: | |
121 | wxDataViewModel *m_owner; | |
122 | }; | |
123 | ||
124 | ||
125 | ||
126 | // ---------------------------------------------------------------------------- | |
127 | // wxDataViewItemAttr: a structure containing the visual attributes of an item | |
128 | // ---------------------------------------------------------------------------- | |
129 | ||
130 | // TODO: this should be renamed to wxItemAttr or something general like this | |
131 | ||
132 | class WXDLLIMPEXP_ADV wxDataViewItemAttr | |
133 | { | |
134 | public: | |
135 | // ctors | |
136 | wxDataViewItemAttr() | |
137 | { | |
138 | m_bold = false; | |
139 | m_italic = false; | |
140 | } | |
141 | ||
142 | // setters | |
143 | void SetColour(const wxColour& colour) { m_colour = colour; } | |
144 | void SetBold( bool set ) { m_bold = set; } | |
145 | void SetItalic( bool set ) { m_italic = set; } | |
146 | ||
147 | // accessors | |
148 | bool HasColour() const { return m_colour.Ok(); } | |
149 | const wxColour& GetColour() const { return m_colour; } | |
150 | ||
151 | bool GetBold() const { return m_bold; } | |
152 | bool GetItalic() const { return m_italic; } | |
153 | ||
154 | private: | |
155 | wxColour m_colour; | |
156 | bool m_bold; | |
157 | bool m_italic; | |
158 | }; | |
159 | ||
160 | ||
161 | // --------------------------------------------------------- | |
162 | // wxDataViewModel | |
163 | // --------------------------------------------------------- | |
164 | ||
165 | WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers, | |
166 | class WXDLLIMPEXP_ADV); | |
167 | ||
168 | class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData | |
169 | { | |
170 | public: | |
171 | wxDataViewModel(); | |
172 | ||
173 | virtual unsigned int GetColumnCount() const = 0; | |
174 | ||
175 | // return type as reported by wxVariant | |
176 | virtual wxString GetColumnType( unsigned int col ) const = 0; | |
177 | ||
178 | // get value into a wxVariant | |
179 | virtual void GetValue( wxVariant &variant, | |
180 | const wxDataViewItem &item, unsigned int col ) const = 0; | |
181 | ||
182 | // set value, call ValueChanged() afterwards! | |
183 | virtual bool SetValue( const wxVariant &variant, | |
184 | const wxDataViewItem &item, unsigned int col ) = 0; | |
185 | ||
186 | // Get text attribute, return false of default attributes should be used | |
187 | virtual bool GetAttr( const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) ) | |
188 | { return false; } | |
189 | ||
190 | // define hierachy | |
191 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0; | |
192 | virtual bool IsContainer( const wxDataViewItem &item ) const = 0; | |
193 | // Is the container just a header or an item with all columns | |
194 | virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const | |
195 | { return false; } | |
196 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0; | |
197 | ||
198 | // define DnD capabilities | |
199 | virtual bool IsDraggable( const wxDataViewItem &WXUNUSED(item) ) | |
200 | { return false; } | |
201 | virtual size_t GetDragDataSize( const wxDataViewItem &WXUNUSED(item), const wxDataFormat &WXUNUSED(format) ) | |
202 | { return 0; } | |
203 | virtual bool GetDragData( const wxDataViewItem &WXUNUSED(item), const wxDataFormat &WXUNUSED(format), | |
204 | void* WXUNUSED(data), size_t WXUNUSED(size) ) | |
205 | { return FALSE; } | |
206 | ||
207 | // delegated notifiers | |
208 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
209 | virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
210 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ); | |
211 | virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ); | |
212 | virtual bool ItemChanged( const wxDataViewItem &item ); | |
213 | virtual bool ItemsChanged( const wxDataViewItemArray &items ); | |
214 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
215 | virtual bool Cleared(); | |
216 | ||
217 | // delegatd action | |
218 | virtual void Resort(); | |
219 | ||
220 | void AddNotifier( wxDataViewModelNotifier *notifier ); | |
221 | void RemoveNotifier( wxDataViewModelNotifier *notifier ); | |
222 | ||
223 | // default compare function | |
224 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
225 | unsigned int column, bool ascending ); | |
226 | virtual bool HasDefaultCompare() const { return false; } | |
227 | ||
228 | // internal | |
229 | virtual bool IsVirtualListModel() const { return false; } | |
230 | ||
231 | protected: | |
232 | // the user should not delete this class directly: he should use DecRef() instead! | |
233 | virtual ~wxDataViewModel() { } | |
234 | ||
235 | wxDataViewModelNotifiers m_notifiers; | |
236 | }; | |
237 | ||
238 | // --------------------------------------------------------- | |
239 | // wxDataViewIndexListModel | |
240 | // --------------------------------------------------------- | |
241 | ||
242 | class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewModel | |
243 | { | |
244 | public: | |
245 | wxDataViewIndexListModel( unsigned int initial_size = 0 ); | |
246 | ~wxDataViewIndexListModel(); | |
247 | ||
248 | virtual void GetValue( wxVariant &variant, | |
249 | unsigned int row, unsigned int col ) const = 0; | |
250 | ||
251 | virtual bool SetValue( const wxVariant &variant, | |
252 | unsigned int row, unsigned int col ) = 0; | |
253 | ||
254 | virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) ) | |
255 | { return false; } | |
256 | ||
257 | void RowPrepended(); | |
258 | void RowInserted( unsigned int before ); | |
259 | void RowAppended(); | |
260 | void RowDeleted( unsigned int row ); | |
261 | void RowsDeleted( const wxArrayInt &rows ); | |
262 | void RowChanged( unsigned int row ); | |
263 | void RowValueChanged( unsigned int row, unsigned int col ); | |
264 | void Reset( unsigned int new_size ); | |
265 | ||
266 | // convert to/from row/wxDataViewItem | |
267 | ||
268 | unsigned int GetRow( const wxDataViewItem &item ) const; | |
269 | wxDataViewItem GetItem( unsigned int row ) const; | |
270 | ||
271 | // compare based on index | |
272 | ||
273 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
274 | unsigned int column, bool ascending ); | |
275 | virtual bool HasDefaultCompare() const; | |
276 | ||
277 | // implement base methods | |
278 | ||
279 | virtual void GetValue( wxVariant &variant, | |
280 | const wxDataViewItem &item, unsigned int col ) const; | |
281 | virtual bool SetValue( const wxVariant &variant, | |
282 | const wxDataViewItem &item, unsigned int col ); | |
283 | virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ); | |
284 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; | |
285 | virtual bool IsContainer( const wxDataViewItem &item ) const; | |
286 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; | |
287 | ||
288 | // internal | |
289 | virtual bool IsVirtualListModel() const { return false; } | |
290 | unsigned int GetLastIndex() const { return m_lastIndex; } | |
291 | ||
292 | private: | |
293 | wxDataViewItemArray m_hash; | |
294 | unsigned int m_lastIndex; | |
295 | bool m_ordered; | |
296 | bool m_useHash; | |
297 | }; | |
298 | ||
299 | // --------------------------------------------------------- | |
300 | // wxDataViewVirtualListModel | |
301 | // --------------------------------------------------------- | |
302 | ||
303 | #ifdef __WXMAC__ | |
304 | // better than nothing | |
305 | typedef wxDataViewIndexListModel wxDataViewVirtualListModel; | |
306 | #else | |
307 | ||
308 | class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewModel | |
309 | { | |
310 | public: | |
311 | wxDataViewVirtualListModel( unsigned int initial_size = 0 ); | |
312 | ~wxDataViewVirtualListModel(); | |
313 | ||
314 | virtual void GetValue( wxVariant &variant, | |
315 | unsigned int row, unsigned int col ) const = 0; | |
316 | ||
317 | virtual bool SetValue( const wxVariant &variant, | |
318 | unsigned int row, unsigned int col ) = 0; | |
319 | ||
320 | virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) ) | |
321 | { return false; } | |
322 | ||
323 | void RowPrepended(); | |
324 | void RowInserted( unsigned int before ); | |
325 | void RowAppended(); | |
326 | void RowDeleted( unsigned int row ); | |
327 | void RowsDeleted( const wxArrayInt &rows ); | |
328 | void RowChanged( unsigned int row ); | |
329 | void RowValueChanged( unsigned int row, unsigned int col ); | |
330 | void Reset( unsigned int new_size ); | |
331 | ||
332 | // convert to/from row/wxDataViewItem | |
333 | ||
334 | unsigned int GetRow( const wxDataViewItem &item ) const; | |
335 | wxDataViewItem GetItem( unsigned int row ) const; | |
336 | ||
337 | // compare based on index | |
338 | ||
339 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
340 | unsigned int column, bool ascending ); | |
341 | virtual bool HasDefaultCompare() const; | |
342 | ||
343 | // implement base methods | |
344 | ||
345 | virtual void GetValue( wxVariant &variant, | |
346 | const wxDataViewItem &item, unsigned int col ) const; | |
347 | virtual bool SetValue( const wxVariant &variant, | |
348 | const wxDataViewItem &item, unsigned int col ); | |
349 | virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ); | |
350 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; | |
351 | virtual bool IsContainer( const wxDataViewItem &item ) const; | |
352 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; | |
353 | ||
354 | // internal | |
355 | virtual bool IsVirtualListModel() const { return true; } | |
356 | unsigned int GetLastIndex() const { return m_lastIndex; } | |
357 | ||
358 | private: | |
359 | wxDataViewItemArray m_hash; | |
360 | unsigned int m_lastIndex; | |
361 | bool m_ordered; | |
362 | }; | |
363 | #endif | |
364 | ||
365 | //----------------------------------------------------------------------------- | |
366 | // wxDataViewEditorCtrlEvtHandler | |
367 | //----------------------------------------------------------------------------- | |
368 | ||
369 | class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler | |
370 | { | |
371 | public: | |
372 | wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner ); | |
373 | ||
374 | void AcceptChangesAndFinish(); | |
375 | void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; } | |
376 | ||
377 | protected: | |
378 | void OnChar( wxKeyEvent &event ); | |
379 | void OnKillFocus( wxFocusEvent &event ); | |
380 | void OnIdle( wxIdleEvent &event ); | |
381 | ||
382 | private: | |
383 | wxDataViewRenderer *m_owner; | |
384 | wxControl *m_editorCtrl; | |
385 | bool m_finished; | |
386 | bool m_focusOnIdle; | |
387 | ||
388 | private: | |
389 | DECLARE_EVENT_TABLE() | |
390 | }; | |
391 | ||
392 | // --------------------------------------------------------- | |
393 | // wxDataViewRendererBase | |
394 | // --------------------------------------------------------- | |
395 | ||
396 | enum wxDataViewCellMode | |
397 | { | |
398 | wxDATAVIEW_CELL_INERT, | |
399 | wxDATAVIEW_CELL_ACTIVATABLE, | |
400 | wxDATAVIEW_CELL_EDITABLE | |
401 | }; | |
402 | ||
403 | enum wxDataViewCellRenderState | |
404 | { | |
405 | wxDATAVIEW_CELL_SELECTED = 1, | |
406 | wxDATAVIEW_CELL_PRELIT = 2, | |
407 | wxDATAVIEW_CELL_INSENSITIVE = 4, | |
408 | wxDATAVIEW_CELL_FOCUSED = 8 | |
409 | }; | |
410 | ||
411 | class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject | |
412 | { | |
413 | public: | |
414 | wxDataViewRendererBase( const wxString &varianttype, | |
415 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
416 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
417 | ~wxDataViewRendererBase(); | |
418 | ||
419 | virtual bool Validate( wxVariant& WXUNUSED(value) ) | |
420 | { return true; } | |
421 | ||
422 | void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; } | |
423 | wxDataViewColumn* GetOwner() const { return m_owner; } | |
424 | ||
425 | // renderer properties: | |
426 | ||
427 | virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0; | |
428 | virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0; | |
429 | ||
430 | wxString GetVariantType() const { return m_variantType; } | |
431 | ||
432 | virtual void SetMode( wxDataViewCellMode mode ) = 0; | |
433 | virtual wxDataViewCellMode GetMode() const = 0; | |
434 | ||
435 | // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but | |
436 | // rather an "int"; that's because for rendering cells it's allowed | |
437 | // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM) | |
438 | virtual void SetAlignment( int align ) = 0; | |
439 | virtual int GetAlignment() const = 0; | |
440 | ||
441 | // in-place editing | |
442 | virtual bool HasEditorCtrl() | |
443 | { return false; } | |
444 | virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), | |
445 | wxRect WXUNUSED(labelRect), | |
446 | const wxVariant& WXUNUSED(value)) | |
447 | { return NULL; } | |
448 | virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor), | |
449 | wxVariant& WXUNUSED(value)) | |
450 | { return false; } | |
451 | ||
452 | virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect ); | |
453 | virtual void CancelEditing(); | |
454 | virtual bool FinishEditing(); | |
455 | ||
456 | wxControl *GetEditorCtrl() { return m_editorCtrl; } | |
457 | ||
458 | protected: | |
459 | wxString m_variantType; | |
460 | wxDataViewColumn *m_owner; | |
461 | wxWeakRef<wxControl> m_editorCtrl; | |
462 | wxDataViewItem m_item; // for m_editorCtrl | |
463 | ||
464 | // internal utility: | |
465 | const wxDataViewCtrl* GetView() const; | |
466 | ||
467 | protected: | |
468 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase) | |
469 | }; | |
470 | ||
471 | //----------------------------------------------------------------------------- | |
472 | // wxDataViewIconText | |
473 | //----------------------------------------------------------------------------- | |
474 | ||
475 | class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject | |
476 | { | |
477 | public: | |
478 | wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon ) | |
479 | : m_text(text), m_icon(icon) | |
480 | { } | |
481 | wxDataViewIconText( const wxDataViewIconText &other ) | |
482 | { m_icon = other.m_icon; m_text = other.m_text; } | |
483 | ||
484 | void SetText( const wxString &text ) { m_text = text; } | |
485 | wxString GetText() const { return m_text; } | |
486 | void SetIcon( const wxIcon &icon ) { m_icon = icon; } | |
487 | const wxIcon &GetIcon() const { return m_icon; } | |
488 | ||
489 | private: | |
490 | wxString m_text; | |
491 | wxIcon m_icon; | |
492 | ||
493 | private: | |
494 | DECLARE_DYNAMIC_CLASS(wxDataViewIconText) | |
495 | }; | |
496 | ||
497 | bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two); | |
498 | ||
499 | DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) | |
500 | ||
501 | // --------------------------------------------------------- | |
502 | // wxDataViewColumnBase | |
503 | // --------------------------------------------------------- | |
504 | ||
505 | enum wxDataViewColumnFlags | |
506 | { | |
507 | wxDATAVIEW_COL_RESIZABLE = 1, | |
508 | wxDATAVIEW_COL_SORTABLE = 2, | |
509 | wxDATAVIEW_COL_REORDERABLE = 4, | |
510 | wxDATAVIEW_COL_HIDDEN = 8 | |
511 | }; | |
512 | ||
513 | class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject | |
514 | { | |
515 | public: | |
516 | wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer, | |
517 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
518 | wxAlignment align = wxALIGN_CENTER, | |
519 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
520 | wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer, | |
521 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
522 | wxAlignment align = wxALIGN_CENTER, | |
523 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
524 | virtual ~wxDataViewColumnBase(); | |
525 | ||
526 | // setters: | |
527 | ||
528 | virtual void SetTitle( const wxString &title ) = 0; | |
529 | virtual void SetAlignment( wxAlignment align ) = 0; | |
530 | virtual void SetSortable( bool sortable ) = 0; | |
531 | virtual void SetReorderable(bool reorderable) = 0; | |
532 | virtual void SetResizeable( bool resizeable ) = 0; | |
533 | virtual void SetHidden( bool hidden ) = 0; | |
534 | virtual void SetSortOrder( bool ascending ) = 0; | |
535 | virtual void SetFlags( int flags ); | |
536 | virtual void SetOwner( wxDataViewCtrl *owner ) | |
537 | { m_owner = owner; } | |
538 | virtual void SetBitmap( const wxBitmap &bitmap ) | |
539 | { m_bitmap=bitmap; } | |
540 | ||
541 | virtual void SetMinWidth( int minWidth ) = 0; | |
542 | virtual void SetWidth( int width ) = 0; | |
543 | ||
544 | ||
545 | // getters: | |
546 | ||
547 | virtual wxString GetTitle() const = 0; | |
548 | virtual wxAlignment GetAlignment() const = 0; | |
549 | virtual int GetWidth() const = 0; | |
550 | virtual int GetMinWidth() const = 0; | |
551 | ||
552 | virtual int GetFlags() const; | |
553 | ||
554 | virtual bool IsHidden() const = 0; | |
555 | virtual bool IsReorderable() const = 0; | |
556 | virtual bool IsResizeable() const = 0; | |
557 | virtual bool IsSortable() const = 0; | |
558 | virtual bool IsSortOrderAscending() const = 0; | |
559 | ||
560 | const wxBitmap &GetBitmap() const { return m_bitmap; } | |
561 | unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); } | |
562 | ||
563 | wxDataViewCtrl *GetOwner() const { return m_owner; } | |
564 | wxDataViewRenderer* GetRenderer() const { return m_renderer; } | |
565 | ||
566 | protected: | |
567 | wxDataViewRenderer *m_renderer; | |
568 | int m_model_column; | |
569 | wxBitmap m_bitmap; | |
570 | wxDataViewCtrl *m_owner; | |
571 | ||
572 | protected: | |
573 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase) | |
574 | }; | |
575 | ||
576 | // --------------------------------------------------------- | |
577 | // wxDataViewCtrlBase | |
578 | // --------------------------------------------------------- | |
579 | ||
580 | #define wxDV_SINGLE 0x0000 // for convenience | |
581 | #define wxDV_MULTIPLE 0x0001 // can select multiple items | |
582 | ||
583 | #define wxDV_NO_HEADER 0x0002 // column titles not visible | |
584 | #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows | |
585 | #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns | |
586 | ||
587 | #define wxDV_ROW_LINES 0x0010 // alternating colour in rows | |
588 | ||
589 | class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl | |
590 | { | |
591 | public: | |
592 | wxDataViewCtrlBase(); | |
593 | virtual ~wxDataViewCtrlBase(); | |
594 | ||
595 | virtual bool AssociateModel( wxDataViewModel *model ); | |
596 | wxDataViewModel* GetModel(); | |
597 | const wxDataViewModel* GetModel() const; | |
598 | ||
599 | // short cuts | |
600 | wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column, | |
601 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
602 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
603 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
604 | wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column, | |
605 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
606 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
607 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
608 | wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column, | |
609 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
610 | wxAlignment align = wxALIGN_CENTER, | |
611 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
612 | wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column, | |
613 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
614 | wxAlignment align = wxALIGN_CENTER, | |
615 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
616 | wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column, | |
617 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
618 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
619 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
620 | wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column, | |
621 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
622 | wxAlignment align = wxALIGN_CENTER, | |
623 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
624 | wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column, | |
625 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
626 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
627 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
628 | wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
629 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
630 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
631 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
632 | wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column, | |
633 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
634 | wxAlignment align = wxALIGN_CENTER, | |
635 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
636 | wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column, | |
637 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
638 | wxAlignment align = wxALIGN_CENTER, | |
639 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
640 | wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column, | |
641 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
642 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
643 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
644 | wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
645 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
646 | wxAlignment align = wxALIGN_CENTER, | |
647 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
648 | ||
649 | wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column, | |
650 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
651 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
652 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
653 | wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column, | |
654 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
655 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
656 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
657 | wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column, | |
658 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
659 | wxAlignment align = wxALIGN_CENTER, | |
660 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
661 | wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column, | |
662 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
663 | wxAlignment align = wxALIGN_CENTER, | |
664 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
665 | wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column, | |
666 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
667 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
668 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
669 | wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
670 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
671 | wxAlignment align = wxALIGN_CENTER, | |
672 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
673 | wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
674 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
675 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
676 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
677 | wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
678 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
679 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
680 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
681 | wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
682 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, | |
683 | wxAlignment align = wxALIGN_CENTER, | |
684 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
685 | wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
686 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, | |
687 | wxAlignment align = wxALIGN_CENTER, | |
688 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
689 | wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
690 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, | |
691 | wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), | |
692 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
693 | wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
694 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, | |
695 | wxAlignment align = wxALIGN_CENTER, | |
696 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
697 | ||
698 | ||
699 | virtual bool PrependColumn( wxDataViewColumn *col ); | |
700 | virtual bool AppendColumn( wxDataViewColumn *col ); | |
701 | ||
702 | virtual unsigned int GetColumnCount() const = 0; | |
703 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0; | |
704 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0; | |
705 | ||
706 | virtual bool DeleteColumn( wxDataViewColumn *column ) = 0; | |
707 | virtual bool ClearColumns() = 0; | |
708 | ||
709 | void SetExpanderColumn( wxDataViewColumn *col ) | |
710 | { m_expander_column = col ; DoSetExpanderColumn(); } | |
711 | wxDataViewColumn *GetExpanderColumn() const | |
712 | { return m_expander_column; } | |
713 | ||
714 | virtual wxDataViewColumn *GetSortingColumn() const = 0; | |
715 | ||
716 | void SetIndent( int indent ) | |
717 | { m_indent = indent ; DoSetIndent(); } | |
718 | int GetIndent() const | |
719 | { return m_indent; } | |
720 | ||
721 | virtual wxDataViewItem GetSelection() const = 0; | |
722 | virtual int GetSelections( wxDataViewItemArray & sel ) const = 0; | |
723 | virtual void SetSelections( const wxDataViewItemArray & sel ) = 0; | |
724 | virtual void Select( const wxDataViewItem & item ) = 0; | |
725 | virtual void Unselect( const wxDataViewItem & item ) = 0; | |
726 | virtual bool IsSelected( const wxDataViewItem & item ) const = 0; | |
727 | ||
728 | virtual void SelectAll() = 0; | |
729 | virtual void UnselectAll() = 0; | |
730 | ||
731 | virtual void Expand( const wxDataViewItem & item ) = 0; | |
732 | virtual void Collapse( const wxDataViewItem & item ) = 0; | |
733 | ||
734 | virtual void EnsureVisible( const wxDataViewItem & item, | |
735 | const wxDataViewColumn *column = NULL ) = 0; | |
736 | virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0; | |
737 | virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0; | |
738 | ||
739 | protected: | |
740 | virtual void DoSetExpanderColumn() = 0 ; | |
741 | virtual void DoSetIndent() = 0; | |
742 | ||
743 | private: | |
744 | wxDataViewModel *m_model; | |
745 | wxDataViewColumn *m_expander_column; | |
746 | int m_indent ; | |
747 | ||
748 | protected: | |
749 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) | |
750 | }; | |
751 | ||
752 | // ---------------------------------------------------------------------------- | |
753 | // wxDataViewEvent - the event class for the wxDataViewCtrl notifications | |
754 | // ---------------------------------------------------------------------------- | |
755 | ||
756 | class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent | |
757 | { | |
758 | public: | |
759 | wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
760 | : wxNotifyEvent(commandType, winid), | |
761 | m_item(0), | |
762 | m_col(-1), | |
763 | m_model(NULL), | |
764 | m_value(wxNullVariant), | |
765 | m_column(NULL), | |
766 | m_pos(-1,-1) | |
767 | { } | |
768 | ||
769 | wxDataViewEvent(const wxDataViewEvent& event) | |
770 | : wxNotifyEvent(event), | |
771 | m_item(event.m_item), | |
772 | m_col(event.m_col), | |
773 | m_model(event.m_model), | |
774 | m_value(event.m_value), | |
775 | m_column(event.m_column), | |
776 | m_pos(m_pos) | |
777 | { } | |
778 | ||
779 | wxDataViewItem GetItem() const { return m_item; } | |
780 | void SetItem( const wxDataViewItem &item ) { m_item = item; } | |
781 | ||
782 | int GetColumn() const { return m_col; } | |
783 | void SetColumn( int col ) { m_col = col; } | |
784 | ||
785 | wxDataViewModel* GetModel() const { return m_model; } | |
786 | void SetModel( wxDataViewModel *model ) { m_model = model; } | |
787 | ||
788 | const wxVariant &GetValue() const { return m_value; } | |
789 | void SetValue( const wxVariant &value ) { m_value = value; } | |
790 | ||
791 | // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only | |
792 | void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } | |
793 | wxDataViewColumn *GetDataViewColumn() const { return m_column; } | |
794 | ||
795 | // for wxEVT_DATAVIEW_CONTEXT_MENU only | |
796 | wxPoint GetPosition() const { return m_pos; } | |
797 | void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; } | |
798 | ||
799 | virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } | |
800 | ||
801 | protected: | |
802 | wxDataViewItem m_item; | |
803 | int m_col; | |
804 | wxDataViewModel *m_model; | |
805 | wxVariant m_value; | |
806 | wxDataViewColumn *m_column; | |
807 | wxPoint m_pos; | |
808 | ||
809 | private: | |
810 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) | |
811 | }; | |
812 | ||
813 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED; | |
814 | ||
815 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED; | |
816 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED; | |
817 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED; | |
818 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING; | |
819 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING; | |
820 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED; | |
821 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE; | |
822 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED; | |
823 | ||
824 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU; | |
825 | ||
826 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK; | |
827 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK; | |
828 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED; | |
829 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED; | |
830 | ||
831 | typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); | |
832 | ||
833 | #define wxDataViewEventHandler(func) \ | |
834 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func) | |
835 | ||
836 | #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \ | |
837 | wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn)) | |
838 | ||
839 | #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn) | |
840 | ||
841 | #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn) | |
842 | #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn) | |
843 | #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn) | |
844 | #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn) | |
845 | #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn) | |
846 | #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn) | |
847 | #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn) | |
848 | #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn) | |
849 | ||
850 | #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn) | |
851 | ||
852 | #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn) | |
853 | #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn) | |
854 | #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn) | |
855 | #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn) | |
856 | ||
857 | #if defined(wxUSE_GENERICDATAVIEWCTRL) | |
858 | #include "wx/generic/dataview.h" | |
859 | #elif defined(__WXGTK20__) | |
860 | #include "wx/gtk/dataview.h" | |
861 | #elif defined(__WXMAC__) | |
862 | #include "wx/mac/dataview.h" | |
863 | #else | |
864 | #include "wx/generic/dataview.h" | |
865 | #endif | |
866 | ||
867 | // ------------------------------------- | |
868 | // wxDataViewSpinRenderer | |
869 | // ------------------------------------- | |
870 | ||
871 | class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer | |
872 | { | |
873 | public: | |
874 | wxDataViewSpinRenderer( int min, int max, | |
875 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
876 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
877 | virtual bool HasEditorCtrl() { return true; } | |
878 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
879 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
880 | virtual bool Render( wxRect rect, wxDC *dc, int state ); | |
881 | virtual wxSize GetSize() const; | |
882 | virtual bool SetValue( const wxVariant &value ); | |
883 | virtual bool GetValue( wxVariant &value ) const; | |
884 | ||
885 | private: | |
886 | long m_data; | |
887 | long m_min,m_max; | |
888 | }; | |
889 | ||
890 | //----------------------------------------------------------------------------- | |
891 | // wxDataViewTreeStore | |
892 | //----------------------------------------------------------------------------- | |
893 | ||
894 | class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode | |
895 | { | |
896 | public: | |
897 | wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent, | |
898 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
899 | virtual ~wxDataViewTreeStoreNode(); | |
900 | ||
901 | void SetText( const wxString &text ) | |
902 | { m_text = text; } | |
903 | wxString GetText() const | |
904 | { return m_text; } | |
905 | void SetIcon( const wxIcon &icon ) | |
906 | { m_icon = icon; } | |
907 | const wxIcon &GetIcon() const | |
908 | { return m_icon; } | |
909 | void SetData( wxClientData *data ) | |
910 | { if (m_data) delete m_data; m_data = data; } | |
911 | wxClientData *GetData() const | |
912 | { return m_data; } | |
913 | ||
914 | wxDataViewItem GetItem() const | |
915 | { return wxDataViewItem( (void*) this ); } | |
916 | ||
917 | virtual bool IsContainer() | |
918 | { return false; } | |
919 | ||
920 | wxDataViewTreeStoreNode *GetParent() | |
921 | { return m_parent; } | |
922 | ||
923 | private: | |
924 | wxDataViewTreeStoreNode *m_parent; | |
925 | wxString m_text; | |
926 | wxIcon m_icon; | |
927 | wxClientData *m_data; | |
928 | }; | |
929 | ||
930 | WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList, | |
931 | class WXDLLIMPEXP_ADV); | |
932 | ||
933 | class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode | |
934 | { | |
935 | public: | |
936 | wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent, | |
937 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
938 | wxClientData *data = NULL ); | |
939 | virtual ~wxDataViewTreeStoreContainerNode(); | |
940 | ||
941 | const wxDataViewTreeStoreNodeList &GetChildren() const | |
942 | { return m_children; } | |
943 | wxDataViewTreeStoreNodeList &GetChildren() | |
944 | { return m_children; } | |
945 | ||
946 | void SetExpandedIcon( const wxIcon &icon ) | |
947 | { m_iconExpanded = icon; } | |
948 | const wxIcon &GetExpandedIcon() const | |
949 | { return m_iconExpanded; } | |
950 | ||
951 | void SetExpanded( bool expanded = true ) | |
952 | { m_isExpanded = expanded; } | |
953 | bool IsExpanded() const | |
954 | { return m_isExpanded; } | |
955 | ||
956 | virtual bool IsContainer() | |
957 | { return true; } | |
958 | ||
959 | private: | |
960 | wxDataViewTreeStoreNodeList m_children; | |
961 | wxIcon m_iconExpanded; | |
962 | bool m_isExpanded; | |
963 | }; | |
964 | ||
965 | //----------------------------------------------------------------------------- | |
966 | ||
967 | class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel | |
968 | { | |
969 | public: | |
970 | wxDataViewTreeStore(); | |
971 | ~wxDataViewTreeStore(); | |
972 | ||
973 | wxDataViewItem AppendItem( const wxDataViewItem& parent, | |
974 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
975 | wxDataViewItem PrependItem( const wxDataViewItem& parent, | |
976 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
977 | wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
978 | const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL ); | |
979 | ||
980 | wxDataViewItem PrependContainer( const wxDataViewItem& parent, | |
981 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
982 | wxClientData *data = NULL ); | |
983 | wxDataViewItem AppendContainer( const wxDataViewItem& parent, | |
984 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
985 | wxClientData *data = NULL ); | |
986 | wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
987 | const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon, | |
988 | wxClientData *data = NULL ); | |
989 | ||
990 | wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const; | |
991 | int GetChildCount( const wxDataViewItem& parent ) const; | |
992 | ||
993 | void SetItemText( const wxDataViewItem& item, const wxString &text ); | |
994 | wxString GetItemText( const wxDataViewItem& item ) const; | |
995 | void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ); | |
996 | const wxIcon &GetItemIcon( const wxDataViewItem& item ) const; | |
997 | void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ); | |
998 | const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const; | |
999 | void SetItemData( const wxDataViewItem& item, wxClientData *data ); | |
1000 | wxClientData *GetItemData( const wxDataViewItem& item ) const; | |
1001 | ||
1002 | void DeleteItem( const wxDataViewItem& item ); | |
1003 | void DeleteChildren( const wxDataViewItem& item ); | |
1004 | void DeleteAllItems(); | |
1005 | ||
1006 | // implement base methods | |
1007 | ||
1008 | virtual void GetValue( wxVariant &variant, | |
1009 | const wxDataViewItem &item, unsigned int col ) const; | |
1010 | virtual bool SetValue( const wxVariant &variant, | |
1011 | const wxDataViewItem &item, unsigned int col ); | |
1012 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; | |
1013 | virtual bool IsContainer( const wxDataViewItem &item ) const; | |
1014 | virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const; | |
1015 | ||
1016 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
1017 | unsigned int column, bool ascending ); | |
1018 | ||
1019 | virtual bool HasDefaultCompare() const | |
1020 | { return true; } | |
1021 | virtual unsigned int GetColumnCount() const | |
1022 | { return 1; }; | |
1023 | virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const | |
1024 | { return wxT("wxDataViewIconText"); } | |
1025 | ||
1026 | wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const; | |
1027 | wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const; | |
1028 | wxDataViewTreeStoreNode *GetRoot() const { return m_root; } | |
1029 | ||
1030 | public: | |
1031 | wxDataViewTreeStoreNode *m_root; | |
1032 | }; | |
1033 | ||
1034 | class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl | |
1035 | { | |
1036 | public: | |
1037 | wxDataViewTreeCtrl(); | |
1038 | wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id, | |
1039 | const wxPoint& pos = wxDefaultPosition, | |
1040 | const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES, | |
1041 | const wxValidator& validator = wxDefaultValidator ); | |
1042 | ~wxDataViewTreeCtrl(); | |
1043 | ||
1044 | bool Create( wxWindow *parent, wxWindowID id, | |
1045 | const wxPoint& pos = wxDefaultPosition, | |
1046 | const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER | wxDV_ROW_LINES, | |
1047 | const wxValidator& validator = wxDefaultValidator ); | |
1048 | ||
1049 | wxDataViewTreeStore *GetStore() | |
1050 | { return (wxDataViewTreeStore*) GetModel(); } | |
1051 | const wxDataViewTreeStore *GetStore() const | |
1052 | { return (const wxDataViewTreeStore*) GetModel(); } | |
1053 | ||
1054 | void SetImageList( wxImageList *imagelist ); | |
1055 | wxImageList* GetImageList() { return m_imageList; } | |
1056 | ||
1057 | wxDataViewItem AppendItem( const wxDataViewItem& parent, | |
1058 | const wxString &text, int icon = -1, wxClientData *data = NULL ); | |
1059 | wxDataViewItem PrependItem( const wxDataViewItem& parent, | |
1060 | const wxString &text, int icon = -1, wxClientData *data = NULL ); | |
1061 | wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1062 | const wxString &text, int icon = -1, wxClientData *data = NULL ); | |
1063 | ||
1064 | wxDataViewItem PrependContainer( const wxDataViewItem& parent, | |
1065 | const wxString &text, int icon = -1, int expanded = -1, | |
1066 | wxClientData *data = NULL ); | |
1067 | wxDataViewItem AppendContainer( const wxDataViewItem& parent, | |
1068 | const wxString &text, int icon = -1, int expanded = -1, | |
1069 | wxClientData *data = NULL ); | |
1070 | wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1071 | const wxString &text, int icon = -1, int expanded = -1, | |
1072 | wxClientData *data = NULL ); | |
1073 | ||
1074 | wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const | |
1075 | { return GetStore()->GetNthChild(parent, pos); } | |
1076 | int GetChildCount( const wxDataViewItem& parent ) const | |
1077 | { return GetStore()->GetChildCount(parent); } | |
1078 | ||
1079 | void SetItemText( const wxDataViewItem& item, const wxString &text ) | |
1080 | { GetStore()->SetItemText(item,text); } | |
1081 | wxString GetItemText( const wxDataViewItem& item ) const | |
1082 | { return GetStore()->GetItemText(item); } | |
1083 | void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1084 | { GetStore()->SetItemIcon(item,icon); } | |
1085 | const wxIcon &GetItemIcon( const wxDataViewItem& item ) const | |
1086 | { return GetStore()->GetItemIcon(item); } | |
1087 | void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1088 | { GetStore()->SetItemExpandedIcon(item,icon); } | |
1089 | const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const | |
1090 | { return GetStore()->GetItemExpandedIcon(item); } | |
1091 | void SetItemData( const wxDataViewItem& item, wxClientData *data ) | |
1092 | { GetStore()->SetItemData(item,data); } | |
1093 | wxClientData *GetItemData( const wxDataViewItem& item ) const | |
1094 | { return GetStore()->GetItemData(item); } | |
1095 | ||
1096 | void DeleteItem( const wxDataViewItem& item ) | |
1097 | { GetStore()->DeleteItem(item); } | |
1098 | void DeleteChildren( const wxDataViewItem& item ) | |
1099 | { GetStore()->DeleteChildren(item); } | |
1100 | void DeleteAllItems() | |
1101 | { GetStore()->DeleteAllItems(); } | |
1102 | ||
1103 | void OnExpanded( wxDataViewEvent &event ); | |
1104 | void OnCollapsed( wxDataViewEvent &event ); | |
1105 | void OnSize( wxSizeEvent &event ); | |
1106 | ||
1107 | private: | |
1108 | wxImageList *m_imageList; | |
1109 | ||
1110 | private: | |
1111 | DECLARE_EVENT_TABLE() | |
1112 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl) | |
1113 | }; | |
1114 | ||
1115 | #endif // wxUSE_DATAVIEWCTRL | |
1116 | ||
1117 | #endif | |
1118 | // _WX_DATAVIEW_H_BASE_ |