1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by: Bo Yang
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
17 #if wxUSE_DATAVIEWCTRL
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"
26 #if defined(__WXGTK20__)
28 // #define wxUSE_GENERICDATAVIEWCTRL 1
29 #elif defined(__WXMAC__)
31 #define wxUSE_GENERICDATAVIEWCTRL 1
34 // ----------------------------------------------------------------------------
35 // wxDataViewCtrl flags
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
39 // wxDataViewCtrl globals
40 // ----------------------------------------------------------------------------
42 class WXDLLIMPEXP_FWD_ADV wxDataViewItem
;
43 class WXDLLIMPEXP_FWD_ADV wxDataViewModel
;
44 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
45 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn
;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer
;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier
;
49 extern WXDLLIMPEXP_DATA_ADV(const wxChar
) wxDataViewCtrlNameStr
[];
51 // the default width of new (text) columns:
52 #define wxDVC_DEFAULT_WIDTH 80
54 // the default width of new toggle columns:
55 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
57 // the default minimal width of the columns:
58 #define wxDVC_DEFAULT_MINWIDTH 30
60 // the default alignment of wxDataViewRenderers:
61 #define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL)
64 // ---------------------------------------------------------
66 // ---------------------------------------------------------
68 class WXDLLIMPEXP_ADV wxDataViewItem
71 wxDataViewItem( void* id
= NULL
)
73 wxDataViewItem( const wxDataViewItem
&item
)
75 bool IsOk() const { return m_id
!= NULL
; }
76 void* GetID() const { return m_id
; }
77 operator const void* () const { return m_id
; }
80 void Print( const wxString
&text
) const;
87 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
);
89 WX_DEFINE_ARRAY(wxDataViewItem
, wxDataViewItemArray
);
91 // ---------------------------------------------------------
92 // wxDataViewModelNotifier
93 // ---------------------------------------------------------
95 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
98 wxDataViewModelNotifier() { }
99 virtual ~wxDataViewModelNotifier() { m_owner
= NULL
; }
101 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
102 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
103 virtual bool ItemChanged( const wxDataViewItem
&item
) = 0;
104 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
105 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
106 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
107 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
) = 0;
108 virtual bool Cleared() = 0;
110 virtual void Resort() = 0;
112 void SetOwner( wxDataViewModel
*owner
) { m_owner
= owner
; }
113 wxDataViewModel
*GetOwner() { return m_owner
; }
116 wxDataViewModel
*m_owner
;
121 // ----------------------------------------------------------------------------
122 // wxDataViewItemAttr: a structure containing the visual attributes of an item
123 // ----------------------------------------------------------------------------
125 // TODO: this should be renamed to wxItemAttr or something general like this
127 class WXDLLIMPEXP_ADV wxDataViewItemAttr
138 void SetColour(const wxColour
& colour
) { m_colour
= colour
; }
139 void SetBold( bool set
) { m_bold
= set
; }
140 void SetItalic( bool set
) { m_italic
= set
; }
143 bool HasColour() const { return m_colour
.Ok(); }
144 const wxColour
& GetColour() const { return m_colour
; }
146 bool GetBold() const { return m_bold
; }
147 bool GetItalic() const { return m_italic
; }
156 // ---------------------------------------------------------
158 // ---------------------------------------------------------
160 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier
, wxDataViewModelNotifiers
,
161 class WXDLLIMPEXP_ADV
);
163 class WXDLLIMPEXP_ADV wxDataViewModel
: public wxObjectRefData
168 virtual unsigned int GetColumnCount() const = 0;
170 // return type as reported by wxVariant
171 virtual wxString
GetColumnType( unsigned int col
) const = 0;
173 // get value into a wxVariant
174 virtual void GetValue( wxVariant
&variant
,
175 const wxDataViewItem
&item
, unsigned int col
) const = 0;
177 // set value, call ValueChanged() afterwards!
178 virtual bool SetValue( const wxVariant
&variant
,
179 const wxDataViewItem
&item
, unsigned int col
) = 0;
181 // Get text attribute, return false of default attributes should be used
182 virtual bool GetAttr( const wxDataViewItem
&WXUNUSED(item
), unsigned int WXUNUSED(col
), wxDataViewItemAttr
&WXUNUSED(attr
) )
186 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const = 0;
187 virtual bool IsContainer( const wxDataViewItem
&item
) const = 0;
188 // Is the container just a header or an item with all columns
189 virtual bool HasContainerColumns(const wxDataViewItem
& WXUNUSED(item
)) const
191 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const = 0;
193 // delegated notifiers
194 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
195 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
196 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
197 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
198 virtual bool ItemChanged( const wxDataViewItem
&item
);
199 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
200 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
201 virtual bool Cleared();
204 virtual void Resort();
206 void AddNotifier( wxDataViewModelNotifier
*notifier
);
207 void RemoveNotifier( wxDataViewModelNotifier
*notifier
);
209 // default compare function
210 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
211 unsigned int column
, bool ascending
);
212 virtual bool HasDefaultCompare() const { return false; }
215 // the user should not delete this class directly: he should use DecRef() instead!
216 virtual ~wxDataViewModel() { }
218 wxDataViewModelNotifiers m_notifiers
;
221 // ---------------------------------------------------------
222 // wxDataViewIndexListModel
223 // ---------------------------------------------------------
225 class WXDLLIMPEXP_ADV wxDataViewIndexListModel
: public wxDataViewModel
228 wxDataViewIndexListModel( unsigned int initial_size
= 0 );
229 ~wxDataViewIndexListModel();
231 virtual unsigned int GetRowCount() = 0;
233 virtual void GetValue( wxVariant
&variant
,
234 unsigned int row
, unsigned int col
) const = 0;
236 virtual bool SetValue( const wxVariant
&variant
,
237 unsigned int row
, unsigned int col
) = 0;
239 virtual bool GetAttr( unsigned int WXUNUSED(row
), unsigned int WXUNUSED(col
), wxDataViewItemAttr
&WXUNUSED(attr
) )
243 void RowInserted( unsigned int before
);
245 void RowDeleted( unsigned int row
);
246 void RowChanged( unsigned int row
);
247 void RowValueChanged( unsigned int row
, unsigned int col
);
249 // convert to/from row/wxDataViewItem
251 unsigned int GetRow( const wxDataViewItem
&item
) const;
252 wxDataViewItem
GetItem( unsigned int row
) const;
254 // compare based on index
256 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
257 unsigned int column
, bool ascending
);
258 virtual bool HasDefaultCompare() const;
260 // implement base methods
262 virtual void GetValue( wxVariant
&variant
,
263 const wxDataViewItem
&item
, unsigned int col
) const;
264 virtual bool SetValue( const wxVariant
&variant
,
265 const wxDataViewItem
&item
, unsigned int col
);
266 virtual bool GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
);
267 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
268 virtual bool IsContainer( const wxDataViewItem
&item
) const;
269 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
272 wxDataViewItemArray m_hash
;
273 unsigned int m_lastIndex
;
278 //-----------------------------------------------------------------------------
279 // wxDataViewEditorCtrlEvtHandler
280 //-----------------------------------------------------------------------------
282 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
285 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
287 void AcceptChangesAndFinish();
288 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
291 void OnChar( wxKeyEvent
&event
);
292 void OnKillFocus( wxFocusEvent
&event
);
293 void OnIdle( wxIdleEvent
&event
);
296 wxDataViewRenderer
*m_owner
;
297 wxControl
*m_editorCtrl
;
302 DECLARE_EVENT_TABLE()
305 // ---------------------------------------------------------
306 // wxDataViewRendererBase
307 // ---------------------------------------------------------
309 enum wxDataViewCellMode
311 wxDATAVIEW_CELL_INERT
,
312 wxDATAVIEW_CELL_ACTIVATABLE
,
313 wxDATAVIEW_CELL_EDITABLE
316 enum wxDataViewCellRenderState
318 wxDATAVIEW_CELL_SELECTED
= 1,
319 wxDATAVIEW_CELL_PRELIT
= 2,
320 wxDATAVIEW_CELL_INSENSITIVE
= 4,
321 wxDATAVIEW_CELL_FOCUSED
= 8
324 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
327 wxDataViewRendererBase( const wxString
&varianttype
,
328 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
329 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
331 virtual bool Validate( wxVariant
& WXUNUSED(value
) )
334 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
335 wxDataViewColumn
* GetOwner() { return m_owner
; }
337 // renderer properties:
339 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) = 0;
340 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) const = 0;
342 wxString
GetVariantType() const { return m_variantType
; }
344 virtual void SetMode( wxDataViewCellMode mode
) = 0;
345 virtual wxDataViewCellMode
GetMode() const = 0;
347 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
348 // rather an "int"; that's because for rendering cells it's allowed
349 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
350 virtual void SetAlignment( int align
) = 0;
351 virtual int GetAlignment() const = 0;
354 virtual bool HasEditorCtrl()
356 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
357 wxRect
WXUNUSED(labelRect
),
358 const wxVariant
& WXUNUSED(value
))
360 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
361 wxVariant
& WXUNUSED(value
))
364 virtual bool StartEditing( const wxDataViewItem
&item
, wxRect labelRect
);
365 virtual void CancelEditing();
366 virtual bool FinishEditing();
368 wxControl
*GetEditorCtrl() { return m_editorCtrl
; }
371 wxString m_variantType
;
372 wxDataViewColumn
*m_owner
;
373 wxControl
*m_editorCtrl
;
374 wxDataViewItem m_item
; // for m_editorCtrl
377 const wxDataViewCtrl
* GetView() const;
380 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
383 //-----------------------------------------------------------------------------
384 // wxDataViewIconText
385 //-----------------------------------------------------------------------------
387 class WXDLLIMPEXP_ADV wxDataViewIconText
: public wxObject
390 wxDataViewIconText( const wxString
&text
= wxEmptyString
, const wxIcon
& icon
= wxNullIcon
)
391 { m_icon
= icon
; m_text
= text
; }
392 wxDataViewIconText( const wxDataViewIconText
&other
)
393 { m_icon
= other
.m_icon
; m_text
= other
.m_text
; }
395 void SetText( const wxString
&text
) { m_text
= text
; }
396 wxString
GetText() const { return m_text
; }
397 void SetIcon( const wxIcon
&icon
) { m_icon
= icon
; }
398 const wxIcon
&GetIcon() const { return m_icon
; }
405 DECLARE_DYNAMIC_CLASS(wxDataViewIconText
)
408 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
);
410 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
412 // ---------------------------------------------------------
413 // wxDataViewColumnBase
414 // ---------------------------------------------------------
416 enum wxDataViewColumnFlags
418 wxDATAVIEW_COL_RESIZABLE
= 1,
419 wxDATAVIEW_COL_SORTABLE
= 2,
420 wxDATAVIEW_COL_HIDDEN
= 4
423 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
426 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
,
427 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
428 wxAlignment align
= wxALIGN_CENTER
,
429 int flags
= wxDATAVIEW_COL_RESIZABLE
);
430 wxDataViewColumnBase( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
431 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
432 wxAlignment align
= wxALIGN_CENTER
,
433 int flags
= wxDATAVIEW_COL_RESIZABLE
);
434 virtual ~wxDataViewColumnBase();
438 virtual void SetTitle( const wxString
&title
) = 0;
439 virtual void SetAlignment( wxAlignment align
) = 0;
440 virtual void SetSortable( bool sortable
) = 0;
441 virtual void SetResizeable( bool resizeable
) = 0;
442 virtual void SetHidden( bool hidden
) = 0;
443 virtual void SetSortOrder( bool ascending
) = 0;
444 virtual void SetFlags( int flags
);
445 virtual void SetOwner( wxDataViewCtrl
*owner
)
447 virtual void SetBitmap( const wxBitmap
&bitmap
)
450 virtual void SetMinWidth( int minWidth
) = 0;
451 virtual void SetWidth( int width
) = 0;
456 virtual wxString
GetTitle() const = 0;
457 virtual wxAlignment
GetAlignment() const = 0;
458 virtual int GetWidth() const = 0;
459 virtual int GetMinWidth() const = 0;
461 virtual int GetFlags() const;
463 virtual bool IsSortable() const = 0;
464 virtual bool IsResizeable() const = 0;
465 virtual bool IsHidden() const = 0;
466 virtual bool IsSortOrderAscending() const = 0;
468 const wxBitmap
&GetBitmap() const { return m_bitmap
; }
469 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
471 wxDataViewCtrl
*GetOwner() { return m_owner
; }
472 wxDataViewRenderer
* GetRenderer() { return m_renderer
; }
475 wxDataViewRenderer
*m_renderer
;
478 wxDataViewCtrl
*m_owner
;
481 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
484 // ---------------------------------------------------------
485 // wxDataViewCtrlBase
486 // ---------------------------------------------------------
488 #define wxDV_SINGLE 0x0000 // for convenience
489 #define wxDV_MULTIPLE 0x0001 // can select multiple items
491 #define wxDV_NO_HEADER 0x0002 // column titles not visible
492 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
493 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
495 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
498 wxDataViewCtrlBase();
499 virtual ~wxDataViewCtrlBase();
501 virtual bool AssociateModel( wxDataViewModel
*model
);
502 wxDataViewModel
* GetModel();
505 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
506 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
507 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
508 int flags
= wxDATAVIEW_COL_RESIZABLE
);
509 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
510 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
511 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
512 int flags
= wxDATAVIEW_COL_RESIZABLE
);
513 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
514 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
515 wxAlignment align
= wxALIGN_CENTER
,
516 int flags
= wxDATAVIEW_COL_RESIZABLE
);
517 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
518 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
519 wxAlignment align
= wxALIGN_CENTER
,
520 int flags
= wxDATAVIEW_COL_RESIZABLE
);
521 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
522 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
523 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
524 int flags
= wxDATAVIEW_COL_RESIZABLE
);
525 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
526 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
527 wxAlignment align
= wxALIGN_CENTER
,
528 int flags
= wxDATAVIEW_COL_RESIZABLE
);
529 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
530 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
531 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
532 int flags
= wxDATAVIEW_COL_RESIZABLE
);
533 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
534 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
535 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
536 int flags
= wxDATAVIEW_COL_RESIZABLE
);
537 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
538 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
539 wxAlignment align
= wxALIGN_CENTER
,
540 int flags
= wxDATAVIEW_COL_RESIZABLE
);
541 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
542 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
543 wxAlignment align
= wxALIGN_CENTER
,
544 int flags
= wxDATAVIEW_COL_RESIZABLE
);
545 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
546 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
547 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
548 int flags
= wxDATAVIEW_COL_RESIZABLE
);
549 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
550 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
551 wxAlignment align
= wxALIGN_CENTER
,
552 int flags
= wxDATAVIEW_COL_RESIZABLE
);
554 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
555 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
556 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
557 int flags
= wxDATAVIEW_COL_RESIZABLE
);
558 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
559 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
560 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
561 int flags
= wxDATAVIEW_COL_RESIZABLE
);
562 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
563 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
564 wxAlignment align
= wxALIGN_CENTER
,
565 int flags
= wxDATAVIEW_COL_RESIZABLE
);
566 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
567 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
568 wxAlignment align
= wxALIGN_CENTER
,
569 int flags
= wxDATAVIEW_COL_RESIZABLE
);
570 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
571 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
572 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
573 int flags
= wxDATAVIEW_COL_RESIZABLE
);
574 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
575 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
576 wxAlignment align
= wxALIGN_CENTER
,
577 int flags
= wxDATAVIEW_COL_RESIZABLE
);
578 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
579 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
580 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
581 int flags
= wxDATAVIEW_COL_RESIZABLE
);
582 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
583 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
584 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
585 int flags
= wxDATAVIEW_COL_RESIZABLE
);
586 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
587 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
588 wxAlignment align
= wxALIGN_CENTER
,
589 int flags
= wxDATAVIEW_COL_RESIZABLE
);
590 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
591 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
592 wxAlignment align
= wxALIGN_CENTER
,
593 int flags
= wxDATAVIEW_COL_RESIZABLE
);
594 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
595 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
596 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
597 int flags
= wxDATAVIEW_COL_RESIZABLE
);
598 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
599 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
600 wxAlignment align
= wxALIGN_CENTER
,
601 int flags
= wxDATAVIEW_COL_RESIZABLE
);
604 virtual bool PrependColumn( wxDataViewColumn
*col
);
605 virtual bool AppendColumn( wxDataViewColumn
*col
);
607 virtual unsigned int GetColumnCount() const = 0;
608 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
609 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
611 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
612 virtual bool ClearColumns() = 0;
614 void SetExpanderColumn( wxDataViewColumn
*col
)
615 { m_expander_column
= col
; DoSetExpanderColumn(); }
616 wxDataViewColumn
*GetExpanderColumn() const
617 { return m_expander_column
; }
619 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
621 void SetIndent( int indent
)
622 { m_indent
= indent
; DoSetIndent(); }
623 int GetIndent() const
626 virtual wxDataViewItem
GetSelection() const = 0;
627 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
628 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
629 virtual void Select( const wxDataViewItem
& item
) = 0;
630 virtual void Unselect( const wxDataViewItem
& item
) = 0;
631 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
633 virtual void SelectAll() = 0;
634 virtual void UnselectAll() = 0;
636 virtual void Expand( const wxDataViewItem
& item
) = 0;
637 virtual void Collapse( const wxDataViewItem
& item
) = 0;
639 virtual void EnsureVisible( const wxDataViewItem
& item
,
640 const wxDataViewColumn
*column
= NULL
) = 0;
641 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
642 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
645 virtual void DoSetExpanderColumn() = 0 ;
646 virtual void DoSetIndent() = 0;
649 wxDataViewModel
*m_model
;
650 wxDataViewColumn
*m_expander_column
;
654 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
657 // ----------------------------------------------------------------------------
658 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
659 // ----------------------------------------------------------------------------
661 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
664 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
665 : wxNotifyEvent(commandType
, winid
),
669 m_value(wxNullVariant
),
673 wxDataViewEvent(const wxDataViewEvent
& event
)
674 : wxNotifyEvent(event
),
675 m_item(event
.m_item
),
677 m_model(event
.m_model
),
678 m_value(event
.m_value
),
679 m_column(event
.m_column
)
682 wxDataViewItem
GetItem() const { return m_item
; }
683 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
685 int GetColumn() const { return m_col
; }
686 void SetColumn( int col
) { m_col
= col
; }
688 wxDataViewModel
* GetModel() const { return m_model
; }
689 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
691 const wxVariant
&GetValue() const { return m_value
; }
692 void SetValue( const wxVariant
&value
) { m_value
= value
; }
694 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
695 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
696 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
698 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
701 wxDataViewItem m_item
;
703 wxDataViewModel
*m_model
;
705 wxDataViewColumn
*m_column
;
708 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
711 BEGIN_DECLARE_EVENT_TYPES()
712 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, -1)
714 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, -1)
715 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, -1)
716 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, -1)
717 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, -1)
718 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, -1)
719 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, -1)
720 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, -1)
721 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, -1)
723 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, -1)
724 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, -1)
725 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, -1)
726 END_DECLARE_EVENT_TYPES()
728 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
730 #define wxDataViewEventHandler(func) \
731 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
733 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
734 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
736 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
738 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
739 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
740 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
741 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
742 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
743 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
744 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
745 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
747 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
748 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
749 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
751 #if defined(wxUSE_GENERICDATAVIEWCTRL)
752 #include "wx/generic/dataview.h"
753 #elif defined(__WXGTK20__)
754 #include "wx/gtk/dataview.h"
755 #elif defined(__WXMAC__)
756 #include "wx/mac/dataview.h"
758 #include "wx/generic/dataview.h"
761 // -------------------------------------
762 // wxDataViewSpinRenderer
763 // -------------------------------------
765 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer
: public wxDataViewCustomRenderer
768 wxDataViewSpinRenderer( int min
, int max
,
769 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
770 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
771 virtual bool HasEditorCtrl() { return true; }
772 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
773 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
774 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
775 virtual wxSize
GetSize() const;
776 virtual bool SetValue( const wxVariant
&value
);
777 virtual bool GetValue( wxVariant
&value
) const;
784 //-----------------------------------------------------------------------------
785 // wxDataViewTreeStore
786 //-----------------------------------------------------------------------------
788 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
791 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
792 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
793 virtual ~wxDataViewTreeStoreNode();
795 void SetText( const wxString
&text
)
797 wxString
GetText() const
799 void SetIcon( const wxIcon
&icon
)
801 const wxIcon
&GetIcon() const
803 void SetData( wxClientData
*data
)
804 { if (m_data
) delete m_data
; m_data
= data
; }
805 wxClientData
*GetData() const
808 wxDataViewItem
GetItem() const
809 { return wxDataViewItem( (void*) this ); }
811 virtual bool IsContainer()
814 wxDataViewTreeStoreNode
*GetParent()
818 wxDataViewTreeStoreNode
*m_parent
;
821 wxClientData
*m_data
;
824 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
825 class WXDLLIMPEXP_ADV
);
827 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
830 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
831 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
832 wxClientData
*data
= NULL
);
833 virtual ~wxDataViewTreeStoreContainerNode();
835 const wxDataViewTreeStoreNodeList
&GetChildren() const
836 { return m_children
; }
837 wxDataViewTreeStoreNodeList
&GetChildren()
838 { return m_children
; }
840 void SetExpandedIcon( const wxIcon
&icon
)
841 { m_iconExpanded
= icon
; }
842 const wxIcon
&GetExpandedIcon() const
843 { return m_iconExpanded
; }
845 virtual bool IsContainer()
849 wxDataViewTreeStoreNodeList m_children
;
850 wxIcon m_iconExpanded
;
853 //-----------------------------------------------------------------------------
855 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
858 wxDataViewTreeStore();
859 ~wxDataViewTreeStore();
861 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
862 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
863 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
864 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
865 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
866 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
868 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
869 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
870 wxClientData
*data
= NULL
);
871 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
872 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
873 wxClientData
*data
= NULL
);
874 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
875 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
876 wxClientData
*data
= NULL
);
878 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
879 int GetChildCount( const wxDataViewItem
& parent
) const;
881 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
882 wxString
GetItemText( const wxDataViewItem
& item
) const;
883 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
884 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
885 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
886 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
887 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
888 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
890 void DeleteItem( const wxDataViewItem
& item
);
891 void DeleteChildren( const wxDataViewItem
& item
);
892 void DeleteAllItems();
894 // implement base methods
896 virtual void GetValue( wxVariant
&variant
,
897 const wxDataViewItem
&item
, unsigned int col
) const;
898 virtual bool SetValue( const wxVariant
&variant
,
899 const wxDataViewItem
&item
, unsigned int col
);
900 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
901 virtual bool IsContainer( const wxDataViewItem
&item
) const;
902 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
904 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
905 unsigned int column
, bool ascending
);
907 virtual bool HasDefaultCompare() const
909 virtual unsigned int GetColumnCount() const
911 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
912 { return "wxDataViewIconText"; }
914 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
915 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
916 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
919 wxDataViewTreeStoreNode
*m_root
;
923 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
926 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
927 const wxPoint
& pos
= wxDefaultPosition
,
928 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
929 const wxValidator
& validator
= wxDefaultValidator
);
931 bool Create( wxWindow
*parent
, wxWindowID id
,
932 const wxPoint
& pos
= wxDefaultPosition
,
933 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
934 const wxValidator
& validator
= wxDefaultValidator
);
936 wxDataViewTreeStore
*GetStore()
937 { return (wxDataViewTreeStore
*) GetModel(); }
939 void OnExpand( wxDataViewCtrl
&event
);
940 void OnCollapse( wxDataViewCtrl
&event
);
943 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
947 #endif // wxUSE_DATAVIEWCTRL
950 // _WX_DATAVIEW_H_BASE_