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