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