]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
simplify toolbar and statusbar create/set code
[wxWidgets.git] / include / wx / dataview.h
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/listctrl.h"
24 #include "wx/dynarray.h"
25 #include "wx/icon.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 { wxPrintf( "item %s: %d\n", text, (int) m_id ); }
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 // wxDataViewModel
123 // ---------------------------------------------------------
124
125 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
126 class WXDLLIMPEXP_ADV);
127
128 class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
129 {
130 public:
131 wxDataViewModel();
132
133 virtual unsigned int GetColumnCount() const = 0;
134
135 // return type as reported by wxVariant
136 virtual wxString GetColumnType( unsigned int col ) const = 0;
137
138 // get value into a wxVariant
139 virtual void GetValue( wxVariant &variant,
140 const wxDataViewItem &item, unsigned int col ) const = 0;
141
142 // set value, call ValueChanged() afterwards!
143 virtual bool SetValue( const wxVariant &variant,
144 const wxDataViewItem &item, unsigned int col ) = 0;
145
146 // define hierachy
147 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
148 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
149 // Is the container just a header or an item with all columns
150 virtual bool HasContainerColumns( const wxDataViewItem &item ) const { return false; }
151 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0;
152
153 // delegated notifiers
154 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
155 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
156 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
157 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
158 virtual bool ItemChanged( const wxDataViewItem &item );
159 virtual bool ItemsChanged( const wxDataViewItemArray &items );
160 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
161 virtual bool Cleared();
162
163 // delegatd action
164 virtual void Resort();
165
166 void AddNotifier( wxDataViewModelNotifier *notifier );
167 void RemoveNotifier( wxDataViewModelNotifier *notifier );
168
169 // default compare function
170 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
171 unsigned int column, bool ascending );
172 virtual bool HasDefaultCompare() const { return false; }
173
174 protected:
175 // the user should not delete this class directly: he should use DecRef() instead!
176 virtual ~wxDataViewModel() { }
177
178 wxDataViewModelNotifiers m_notifiers;
179 };
180
181 // ---------------------------------------------------------
182 // wxDataViewIndexListModel
183 // ---------------------------------------------------------
184
185 class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewModel
186 {
187 public:
188 wxDataViewIndexListModel( unsigned int initial_size = 0 );
189 ~wxDataViewIndexListModel();
190
191 virtual unsigned int GetRowCount() = 0;
192
193 virtual void GetValue( wxVariant &variant,
194 unsigned int row, unsigned int col ) const = 0;
195
196 virtual bool SetValue( const wxVariant &variant,
197 unsigned int row, unsigned int col ) = 0;
198
199 void RowPrepended();
200 void RowInserted( unsigned int before );
201 void RowAppended();
202 void RowDeleted( unsigned int row );
203 void RowChanged( unsigned int row );
204 void RowValueChanged( unsigned int row, unsigned int col );
205
206 // convert to/from row/wxDataViewItem
207
208 unsigned int GetRow( const wxDataViewItem &item ) const;
209 wxDataViewItem GetItem( unsigned int row ) const;
210
211 // compare based on index
212
213 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
214 unsigned int column, bool ascending );
215 virtual bool HasDefaultCompare() const { return true; }
216
217 // implement base methods
218
219 virtual void GetValue( wxVariant &variant,
220 const wxDataViewItem &item, unsigned int col ) const;
221 virtual bool SetValue( const wxVariant &variant,
222 const wxDataViewItem &item, unsigned int col );
223 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
224 virtual bool IsContainer( const wxDataViewItem &item ) const;
225 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
226
227 private:
228 wxDataViewItemArray m_hash;
229 unsigned int m_lastIndex;
230 };
231
232
233 //-----------------------------------------------------------------------------
234 // wxDataViewEditorCtrlEvtHandler
235 //-----------------------------------------------------------------------------
236
237 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
238 {
239 public:
240 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
241
242 void AcceptChangesAndFinish();
243 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
244
245 protected:
246 void OnChar( wxKeyEvent &event );
247 void OnKillFocus( wxFocusEvent &event );
248 void OnIdle( wxIdleEvent &event );
249
250 private:
251 wxDataViewRenderer *m_owner;
252 wxControl *m_editorCtrl;
253 bool m_finished;
254 bool m_focusOnIdle;
255
256 private:
257 DECLARE_EVENT_TABLE()
258 };
259
260 // ---------------------------------------------------------
261 // wxDataViewRendererBase
262 // ---------------------------------------------------------
263
264 enum wxDataViewCellMode
265 {
266 wxDATAVIEW_CELL_INERT,
267 wxDATAVIEW_CELL_ACTIVATABLE,
268 wxDATAVIEW_CELL_EDITABLE
269 };
270
271 enum wxDataViewCellRenderState
272 {
273 wxDATAVIEW_CELL_SELECTED = 1,
274 wxDATAVIEW_CELL_PRELIT = 2,
275 wxDATAVIEW_CELL_INSENSITIVE = 4,
276 wxDATAVIEW_CELL_FOCUSED = 8
277 };
278
279 class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
280 {
281 public:
282 wxDataViewRendererBase( const wxString &varianttype,
283 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
284 int alignment = wxDVR_DEFAULT_ALIGNMENT );
285
286 virtual bool Validate( wxVariant& WXUNUSED(value) )
287 { return true; }
288
289 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
290 wxDataViewColumn* GetOwner() { return m_owner; }
291
292 // renderer properties:
293
294 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
295 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
296
297 wxString GetVariantType() const { return m_variantType; }
298
299 virtual void SetMode( wxDataViewCellMode mode ) = 0;
300 virtual wxDataViewCellMode GetMode() const = 0;
301
302 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
303 // rather an "int"; that's because for rendering cells it's allowed
304 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
305 virtual void SetAlignment( int align ) = 0;
306 virtual int GetAlignment() const = 0;
307
308 // in-place editing
309 virtual bool HasEditorCtrl()
310 { return false; }
311 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
312 wxRect WXUNUSED(labelRect),
313 const wxVariant& WXUNUSED(value))
314 { return NULL; }
315 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
316 wxVariant& WXUNUSED(value))
317 { return false; }
318
319 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
320 virtual void CancelEditing();
321 virtual bool FinishEditing();
322
323 wxControl *GetEditorCtrl() { return m_editorCtrl; }
324
325 protected:
326 wxString m_variantType;
327 wxDataViewColumn *m_owner;
328 wxControl *m_editorCtrl;
329 wxDataViewItem m_item; // for m_editorCtrl
330
331 // internal utility:
332 const wxDataViewCtrl* GetView() const;
333
334 protected:
335 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
336 };
337
338 //-----------------------------------------------------------------------------
339 // wxDataViewIconText
340 //-----------------------------------------------------------------------------
341
342 class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
343 {
344 public:
345 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
346 { m_icon = icon; m_text = text; }
347 wxDataViewIconText( const wxDataViewIconText &other )
348 { m_icon = other.m_icon; m_text = other.m_text; }
349
350 void SetText( const wxString &text ) { m_text = text; }
351 wxString GetText() const { return m_text; }
352 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
353 const wxIcon &GetIcon() const { return m_icon; }
354
355 private:
356 wxString m_text;
357 wxIcon m_icon;
358
359 private:
360 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
361 };
362
363 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two);
364
365 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
366
367 // ---------------------------------------------------------
368 // wxDataViewColumnBase
369 // ---------------------------------------------------------
370
371 enum wxDataViewColumnFlags
372 {
373 wxDATAVIEW_COL_RESIZABLE = 1,
374 wxDATAVIEW_COL_SORTABLE = 2,
375 wxDATAVIEW_COL_HIDDEN = 4
376 };
377
378 class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
379 {
380 public:
381 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
382 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
383 wxAlignment align = wxALIGN_CENTER,
384 int flags = wxDATAVIEW_COL_RESIZABLE );
385 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
386 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
387 wxAlignment align = wxALIGN_CENTER,
388 int flags = wxDATAVIEW_COL_RESIZABLE );
389 virtual ~wxDataViewColumnBase();
390
391 // setters:
392
393 virtual void SetTitle( const wxString &title ) = 0;
394 virtual void SetAlignment( wxAlignment align ) = 0;
395 virtual void SetSortable( bool sortable ) = 0;
396 virtual void SetResizeable( bool resizeable ) = 0;
397 virtual void SetHidden( bool hidden ) = 0;
398 virtual void SetSortOrder( bool ascending ) = 0;
399 virtual void SetFlags( int flags );
400 virtual void SetOwner( wxDataViewCtrl *owner )
401 { m_owner = owner; }
402 virtual void SetBitmap( const wxBitmap &bitmap )
403 { m_bitmap=bitmap; }
404
405 virtual void SetMinWidth( int minWidth ) = 0;
406 virtual void SetWidth( int width ) = 0;
407
408
409 // getters:
410
411 virtual wxString GetTitle() const = 0;
412 virtual wxAlignment GetAlignment() const = 0;
413 virtual int GetWidth() const = 0;
414 virtual int GetMinWidth() const = 0;
415
416 virtual int GetFlags() const;
417
418 virtual bool IsSortable() const = 0;
419 virtual bool IsResizeable() const = 0;
420 virtual bool IsHidden() const = 0;
421 virtual bool IsSortOrderAscending() const = 0;
422
423 const wxBitmap &GetBitmap() const { return m_bitmap; }
424 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
425
426 wxDataViewCtrl *GetOwner() { return m_owner; }
427 wxDataViewRenderer* GetRenderer() { return m_renderer; }
428
429 protected:
430 wxDataViewRenderer *m_renderer;
431 int m_model_column;
432 wxBitmap m_bitmap;
433 wxDataViewCtrl *m_owner;
434
435 protected:
436 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
437 };
438
439 // ---------------------------------------------------------
440 // wxDataViewCtrlBase
441 // ---------------------------------------------------------
442
443 #define wxDV_SINGLE 0x0000 // for convenience
444 #define wxDV_MULTIPLE 0x0001 // can select multiple items
445
446 #define wxDV_NO_HEADER 0x0002 // column titles not visible
447 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
448 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
449
450 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
451 {
452 public:
453 wxDataViewCtrlBase();
454 virtual ~wxDataViewCtrlBase();
455
456 virtual bool AssociateModel( wxDataViewModel *model );
457 wxDataViewModel* GetModel();
458
459 // short cuts
460 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
461 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
462 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
463 int flags = wxDATAVIEW_COL_RESIZABLE );
464 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
465 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
466 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
467 int flags = wxDATAVIEW_COL_RESIZABLE );
468 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
469 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
470 wxAlignment align = wxALIGN_CENTER,
471 int flags = wxDATAVIEW_COL_RESIZABLE );
472 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
473 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
474 wxAlignment align = wxALIGN_CENTER,
475 int flags = wxDATAVIEW_COL_RESIZABLE );
476 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
477 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
478 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
479 int flags = wxDATAVIEW_COL_RESIZABLE );
480 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
481 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
482 wxAlignment align = wxALIGN_CENTER,
483 int flags = wxDATAVIEW_COL_RESIZABLE );
484 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
485 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
486 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
487 int flags = wxDATAVIEW_COL_RESIZABLE );
488 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
489 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
490 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
491 int flags = wxDATAVIEW_COL_RESIZABLE );
492 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
493 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
494 wxAlignment align = wxALIGN_CENTER,
495 int flags = wxDATAVIEW_COL_RESIZABLE );
496 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
497 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
498 wxAlignment align = wxALIGN_CENTER,
499 int flags = wxDATAVIEW_COL_RESIZABLE );
500 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
501 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
502 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
503 int flags = wxDATAVIEW_COL_RESIZABLE );
504
505 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
506 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
507 wxAlignment align = wxALIGN_CENTER,
508 int flags = wxDATAVIEW_COL_RESIZABLE );
509
510 virtual bool AppendColumn( wxDataViewColumn *col );
511
512 virtual unsigned int GetColumnCount() const = 0;
513 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
514 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
515
516 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
517 virtual bool ClearColumns() = 0;
518
519 void SetExpanderColumn( wxDataViewColumn *col )
520 { m_expander_column = col ; DoSetExpanderColumn(); }
521 wxDataViewColumn *GetExpanderColumn() const
522 { return m_expander_column; }
523
524 virtual wxDataViewColumn *GetSortingColumn() const = 0;
525
526 void SetIndent( int indent )
527 { m_indent = indent ; DoSetIndent(); }
528 int GetIndent() const
529 { return m_indent; }
530
531 virtual wxDataViewItem GetSelection() const = 0;
532 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
533 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
534 virtual void Select( const wxDataViewItem & item ) = 0;
535 virtual void Unselect( const wxDataViewItem & item ) = 0;
536 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
537
538 virtual void SelectAll() = 0;
539 virtual void UnselectAll() = 0;
540
541 virtual void Expand( const wxDataViewItem & item ) = 0;
542 virtual void Collapse( const wxDataViewItem & item ) = 0;
543
544 virtual void EnsureVisible( const wxDataViewItem & item,
545 const wxDataViewColumn *column = NULL ) = 0;
546 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
547 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
548
549 protected:
550 virtual void DoSetExpanderColumn() = 0 ;
551 virtual void DoSetIndent() = 0;
552
553 private:
554 wxDataViewModel *m_model;
555 wxDataViewColumn *m_expander_column;
556 int m_indent ;
557
558 protected:
559 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
560 };
561
562 // ----------------------------------------------------------------------------
563 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
564 // ----------------------------------------------------------------------------
565
566 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
567 {
568 public:
569 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
570 : wxNotifyEvent(commandType, winid),
571 m_item(0),
572 m_col(-1),
573 m_model(NULL),
574 m_value(wxNullVariant),
575 m_column(NULL)
576 { }
577
578 wxDataViewEvent(const wxDataViewEvent& event)
579 : wxNotifyEvent(event),
580 m_item(event.m_item),
581 m_col(event.m_col),
582 m_model(event.m_model),
583 m_value(event.m_value),
584 m_column(event.m_column)
585 { }
586
587 wxDataViewItem GetItem() const { return m_item; }
588 void SetItem( const wxDataViewItem &item ) { m_item = item; }
589
590 int GetColumn() const { return m_col; }
591 void SetColumn( int col ) { m_col = col; }
592
593 wxDataViewModel* GetModel() const { return m_model; }
594 void SetModel( wxDataViewModel *model ) { m_model = model; }
595
596 const wxVariant &GetValue() const { return m_value; }
597 void SetValue( const wxVariant &value ) { m_value = value; }
598
599 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
600 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
601 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
602
603 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
604
605 protected:
606 wxDataViewItem m_item;
607 int m_col;
608 wxDataViewModel *m_model;
609 wxVariant m_value;
610 wxDataViewColumn *m_column;
611
612 private:
613 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
614 };
615
616 BEGIN_DECLARE_EVENT_TYPES()
617 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, -1)
618
619 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1)
620 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, -1)
621 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, -1)
622 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, -1)
623 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, -1)
624 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, -1)
625 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, -1)
626 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, -1)
627
628 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
629 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
630 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1)
631 END_DECLARE_EVENT_TYPES()
632
633 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
634
635 #define wxDataViewEventHandler(func) \
636 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
637
638 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
639 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
640
641 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
642
643 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
644 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
645 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
646 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
647 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
648 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
649 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
650 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
651
652 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
653 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
654 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
655
656 #if defined(wxUSE_GENERICDATAVIEWCTRL)
657 #include "wx/generic/dataview.h"
658 #elif defined(__WXGTK20__)
659 #include "wx/gtk/dataview.h"
660 #elif defined(__WXMAC__)
661 #include "wx/mac/dataview.h"
662 #else
663 #include "wx/generic/dataview.h"
664 #endif
665
666 //-----------------------------------------------------------------------------
667 // wxDataViewTreeStore
668 //-----------------------------------------------------------------------------
669
670 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
671 {
672 public:
673 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
674 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
675 virtual ~wxDataViewTreeStoreNode();
676
677 void SetText( const wxString &text )
678 { m_text = text; }
679 wxString GetText() const
680 { return m_text; }
681 void SetIcon( const wxIcon &icon )
682 { m_icon = icon; }
683 const wxIcon &GetIcon() const
684 { return m_icon; }
685 void SetData( wxClientData *data )
686 { if (m_data) delete m_data; m_data = data; }
687 wxClientData *GetData() const
688 { return m_data; }
689
690 wxDataViewItem GetItem() const
691 { return wxDataViewItem( (void*) this ); }
692
693 virtual bool IsContainer()
694 { return false; }
695
696 wxDataViewTreeStoreNode *GetParent()
697 { return m_parent; }
698
699 private:
700 wxDataViewTreeStoreNode *m_parent;
701 wxString m_text;
702 wxIcon m_icon;
703 wxClientData *m_data;
704 };
705
706 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
707 class WXDLLIMPEXP_ADV);
708
709 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
710 {
711 public:
712 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
713 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
714 wxClientData *data = NULL );
715 virtual ~wxDataViewTreeStoreContainerNode();
716
717 const wxDataViewTreeStoreNodeList &GetChildren() const
718 { return m_children; }
719 wxDataViewTreeStoreNodeList &GetChildren()
720 { return m_children; }
721
722 void SetExpandedIcon( const wxIcon &icon )
723 { m_iconExpanded = icon; }
724 const wxIcon &GetExpandedIcon() const
725 { return m_iconExpanded; }
726
727 virtual bool IsContainer()
728 { return true; }
729
730 private:
731 wxDataViewTreeStoreNodeList m_children;
732 wxIcon m_iconExpanded;
733 };
734
735 //-----------------------------------------------------------------------------
736
737 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
738 {
739 public:
740 wxDataViewTreeStore();
741 ~wxDataViewTreeStore();
742
743 wxDataViewItem AppendItem( const wxDataViewItem& parent,
744 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
745 wxDataViewItem PrependItem( const wxDataViewItem& parent,
746 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
747 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
748 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
749
750 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
751 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
752 wxClientData *data = NULL );
753 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
754 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
755 wxClientData *data = NULL );
756 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
757 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
758 wxClientData *data = NULL );
759
760 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
761 int GetChildCount( const wxDataViewItem& parent ) const;
762
763 void SetItemText( const wxDataViewItem& item, const wxString &text );
764 wxString GetItemText( const wxDataViewItem& item ) const;
765 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
766 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
767 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
768 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
769 void SetItemData( const wxDataViewItem& item, wxClientData *data );
770 wxClientData *GetItemData( const wxDataViewItem& item ) const;
771
772 void DeleteItem( const wxDataViewItem& item );
773 void DeleteChildren( const wxDataViewItem& item );
774 void DeleteAllItems();
775
776 // implement base methods
777
778 virtual void GetValue( wxVariant &variant,
779 const wxDataViewItem &item, unsigned int col ) const;
780 virtual bool SetValue( const wxVariant &variant,
781 const wxDataViewItem &item, unsigned int col );
782 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
783 virtual bool IsContainer( const wxDataViewItem &item ) const;
784 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
785
786 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
787 unsigned int column, bool ascending );
788
789 virtual bool HasDefaultCompare() const
790 { return true; }
791 virtual unsigned int GetColumnCount() const
792 { return 1; };
793 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
794 { return "wxDataViewIconText"; }
795
796 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
797 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
798 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
799
800 public:
801 wxDataViewTreeStoreNode *m_root;
802 };
803
804 #if 0
805 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
806 {
807 public:
808 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
809 const wxPoint& pos = wxDefaultPosition,
810 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER,
811 const wxValidator& validator = wxDefaultValidator );
812
813 bool Create( wxWindow *parent, wxWindowID id,
814 const wxPoint& pos = wxDefaultPosition,
815 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER,
816 const wxValidator& validator = wxDefaultValidator );
817
818 wxDataViewTreeStore *GetStore()
819 { return (wxDataViewTreeStore*) GetModel(); }
820
821 void OnExpand( wxDataViewCtrl &event );
822 void OnCollapse( wxDataViewCtrl &event );
823
824 private:
825 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
826 };
827 #endif
828
829 #endif // wxUSE_DATAVIEWCTRL
830
831 #endif
832 // _WX_DATAVIEW_H_BASE_