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 { return true; }
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
;
277 //-----------------------------------------------------------------------------
278 // wxDataViewEditorCtrlEvtHandler
279 //-----------------------------------------------------------------------------
281 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
284 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
286 void AcceptChangesAndFinish();
287 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
290 void OnChar( wxKeyEvent
&event
);
291 void OnKillFocus( wxFocusEvent
&event
);
292 void OnIdle( wxIdleEvent
&event
);
295 wxDataViewRenderer
*m_owner
;
296 wxControl
*m_editorCtrl
;
301 DECLARE_EVENT_TABLE()
304 // ---------------------------------------------------------
305 // wxDataViewRendererBase
306 // ---------------------------------------------------------
308 enum wxDataViewCellMode
310 wxDATAVIEW_CELL_INERT
,
311 wxDATAVIEW_CELL_ACTIVATABLE
,
312 wxDATAVIEW_CELL_EDITABLE
315 enum wxDataViewCellRenderState
317 wxDATAVIEW_CELL_SELECTED
= 1,
318 wxDATAVIEW_CELL_PRELIT
= 2,
319 wxDATAVIEW_CELL_INSENSITIVE
= 4,
320 wxDATAVIEW_CELL_FOCUSED
= 8
323 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
326 wxDataViewRendererBase( const wxString
&varianttype
,
327 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
328 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
330 virtual bool Validate( wxVariant
& WXUNUSED(value
) )
333 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
334 wxDataViewColumn
* GetOwner() { return m_owner
; }
336 // renderer properties:
338 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) = 0;
339 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) const = 0;
341 wxString
GetVariantType() const { return m_variantType
; }
343 virtual void SetMode( wxDataViewCellMode mode
) = 0;
344 virtual wxDataViewCellMode
GetMode() const = 0;
346 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
347 // rather an "int"; that's because for rendering cells it's allowed
348 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
349 virtual void SetAlignment( int align
) = 0;
350 virtual int GetAlignment() const = 0;
353 virtual bool HasEditorCtrl()
355 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
356 wxRect
WXUNUSED(labelRect
),
357 const wxVariant
& WXUNUSED(value
))
359 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
360 wxVariant
& WXUNUSED(value
))
363 virtual bool StartEditing( const wxDataViewItem
&item
, wxRect labelRect
);
364 virtual void CancelEditing();
365 virtual bool FinishEditing();
367 wxControl
*GetEditorCtrl() { return m_editorCtrl
; }
370 wxString m_variantType
;
371 wxDataViewColumn
*m_owner
;
372 wxControl
*m_editorCtrl
;
373 wxDataViewItem m_item
; // for m_editorCtrl
376 const wxDataViewCtrl
* GetView() const;
379 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
382 //-----------------------------------------------------------------------------
383 // wxDataViewIconText
384 //-----------------------------------------------------------------------------
386 class WXDLLIMPEXP_ADV wxDataViewIconText
: public wxObject
389 wxDataViewIconText( const wxString
&text
= wxEmptyString
, const wxIcon
& icon
= wxNullIcon
)
390 { m_icon
= icon
; m_text
= text
; }
391 wxDataViewIconText( const wxDataViewIconText
&other
)
392 { m_icon
= other
.m_icon
; m_text
= other
.m_text
; }
394 void SetText( const wxString
&text
) { m_text
= text
; }
395 wxString
GetText() const { return m_text
; }
396 void SetIcon( const wxIcon
&icon
) { m_icon
= icon
; }
397 const wxIcon
&GetIcon() const { return m_icon
; }
404 DECLARE_DYNAMIC_CLASS(wxDataViewIconText
)
407 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
);
409 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
411 // ---------------------------------------------------------
412 // wxDataViewColumnBase
413 // ---------------------------------------------------------
415 enum wxDataViewColumnFlags
417 wxDATAVIEW_COL_RESIZABLE
= 1,
418 wxDATAVIEW_COL_SORTABLE
= 2,
419 wxDATAVIEW_COL_HIDDEN
= 4
422 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
425 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
,
426 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
427 wxAlignment align
= wxALIGN_CENTER
,
428 int flags
= wxDATAVIEW_COL_RESIZABLE
);
429 wxDataViewColumnBase( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
430 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
431 wxAlignment align
= wxALIGN_CENTER
,
432 int flags
= wxDATAVIEW_COL_RESIZABLE
);
433 virtual ~wxDataViewColumnBase();
437 virtual void SetTitle( const wxString
&title
) = 0;
438 virtual void SetAlignment( wxAlignment align
) = 0;
439 virtual void SetSortable( bool sortable
) = 0;
440 virtual void SetResizeable( bool resizeable
) = 0;
441 virtual void SetHidden( bool hidden
) = 0;
442 virtual void SetSortOrder( bool ascending
) = 0;
443 virtual void SetFlags( int flags
);
444 virtual void SetOwner( wxDataViewCtrl
*owner
)
446 virtual void SetBitmap( const wxBitmap
&bitmap
)
449 virtual void SetMinWidth( int minWidth
) = 0;
450 virtual void SetWidth( int width
) = 0;
455 virtual wxString
GetTitle() const = 0;
456 virtual wxAlignment
GetAlignment() const = 0;
457 virtual int GetWidth() const = 0;
458 virtual int GetMinWidth() const = 0;
460 virtual int GetFlags() const;
462 virtual bool IsSortable() const = 0;
463 virtual bool IsResizeable() const = 0;
464 virtual bool IsHidden() const = 0;
465 virtual bool IsSortOrderAscending() const = 0;
467 const wxBitmap
&GetBitmap() const { return m_bitmap
; }
468 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
470 wxDataViewCtrl
*GetOwner() { return m_owner
; }
471 wxDataViewRenderer
* GetRenderer() { return m_renderer
; }
474 wxDataViewRenderer
*m_renderer
;
477 wxDataViewCtrl
*m_owner
;
480 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
483 // ---------------------------------------------------------
484 // wxDataViewCtrlBase
485 // ---------------------------------------------------------
487 #define wxDV_SINGLE 0x0000 // for convenience
488 #define wxDV_MULTIPLE 0x0001 // can select multiple items
490 #define wxDV_NO_HEADER 0x0002 // column titles not visible
491 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
492 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
494 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
497 wxDataViewCtrlBase();
498 virtual ~wxDataViewCtrlBase();
500 virtual bool AssociateModel( wxDataViewModel
*model
);
501 wxDataViewModel
* GetModel();
504 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
505 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
506 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
507 int flags
= wxDATAVIEW_COL_RESIZABLE
);
508 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
509 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
510 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
511 int flags
= wxDATAVIEW_COL_RESIZABLE
);
512 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
513 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
514 wxAlignment align
= wxALIGN_CENTER
,
515 int flags
= wxDATAVIEW_COL_RESIZABLE
);
516 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
517 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
518 wxAlignment align
= wxALIGN_CENTER
,
519 int flags
= wxDATAVIEW_COL_RESIZABLE
);
520 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
521 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
522 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
523 int flags
= wxDATAVIEW_COL_RESIZABLE
);
524 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
525 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
526 wxAlignment align
= wxALIGN_CENTER
,
527 int flags
= wxDATAVIEW_COL_RESIZABLE
);
528 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
529 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
530 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
531 int flags
= wxDATAVIEW_COL_RESIZABLE
);
532 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
533 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
534 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
535 int flags
= wxDATAVIEW_COL_RESIZABLE
);
536 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
537 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
538 wxAlignment align
= wxALIGN_CENTER
,
539 int flags
= wxDATAVIEW_COL_RESIZABLE
);
540 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
541 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
542 wxAlignment align
= wxALIGN_CENTER
,
543 int flags
= wxDATAVIEW_COL_RESIZABLE
);
544 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
545 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
546 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
547 int flags
= wxDATAVIEW_COL_RESIZABLE
);
548 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
549 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
550 wxAlignment align
= wxALIGN_CENTER
,
551 int flags
= wxDATAVIEW_COL_RESIZABLE
);
553 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
554 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
555 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
556 int flags
= wxDATAVIEW_COL_RESIZABLE
);
557 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
558 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
559 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
560 int flags
= wxDATAVIEW_COL_RESIZABLE
);
561 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
562 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
563 wxAlignment align
= wxALIGN_CENTER
,
564 int flags
= wxDATAVIEW_COL_RESIZABLE
);
565 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
566 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
567 wxAlignment align
= wxALIGN_CENTER
,
568 int flags
= wxDATAVIEW_COL_RESIZABLE
);
569 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
570 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
571 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
572 int flags
= wxDATAVIEW_COL_RESIZABLE
);
573 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
574 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
575 wxAlignment align
= wxALIGN_CENTER
,
576 int flags
= wxDATAVIEW_COL_RESIZABLE
);
577 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
578 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
579 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
580 int flags
= wxDATAVIEW_COL_RESIZABLE
);
581 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
582 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
583 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
584 int flags
= wxDATAVIEW_COL_RESIZABLE
);
585 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
586 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
587 wxAlignment align
= wxALIGN_CENTER
,
588 int flags
= wxDATAVIEW_COL_RESIZABLE
);
589 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
590 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
591 wxAlignment align
= wxALIGN_CENTER
,
592 int flags
= wxDATAVIEW_COL_RESIZABLE
);
593 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
594 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
595 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
596 int flags
= wxDATAVIEW_COL_RESIZABLE
);
597 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
598 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
599 wxAlignment align
= wxALIGN_CENTER
,
600 int flags
= wxDATAVIEW_COL_RESIZABLE
);
603 virtual bool PrependColumn( wxDataViewColumn
*col
);
604 virtual bool AppendColumn( wxDataViewColumn
*col
);
606 virtual unsigned int GetColumnCount() const = 0;
607 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
608 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
610 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
611 virtual bool ClearColumns() = 0;
613 void SetExpanderColumn( wxDataViewColumn
*col
)
614 { m_expander_column
= col
; DoSetExpanderColumn(); }
615 wxDataViewColumn
*GetExpanderColumn() const
616 { return m_expander_column
; }
618 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
620 void SetIndent( int indent
)
621 { m_indent
= indent
; DoSetIndent(); }
622 int GetIndent() const
625 virtual wxDataViewItem
GetSelection() const = 0;
626 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
627 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
628 virtual void Select( const wxDataViewItem
& item
) = 0;
629 virtual void Unselect( const wxDataViewItem
& item
) = 0;
630 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
632 virtual void SelectAll() = 0;
633 virtual void UnselectAll() = 0;
635 virtual void Expand( const wxDataViewItem
& item
) = 0;
636 virtual void Collapse( const wxDataViewItem
& item
) = 0;
638 virtual void EnsureVisible( const wxDataViewItem
& item
,
639 const wxDataViewColumn
*column
= NULL
) = 0;
640 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
641 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
644 virtual void DoSetExpanderColumn() = 0 ;
645 virtual void DoSetIndent() = 0;
648 wxDataViewModel
*m_model
;
649 wxDataViewColumn
*m_expander_column
;
653 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
656 // ----------------------------------------------------------------------------
657 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
658 // ----------------------------------------------------------------------------
660 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
663 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
664 : wxNotifyEvent(commandType
, winid
),
668 m_value(wxNullVariant
),
672 wxDataViewEvent(const wxDataViewEvent
& event
)
673 : wxNotifyEvent(event
),
674 m_item(event
.m_item
),
676 m_model(event
.m_model
),
677 m_value(event
.m_value
),
678 m_column(event
.m_column
)
681 wxDataViewItem
GetItem() const { return m_item
; }
682 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
684 int GetColumn() const { return m_col
; }
685 void SetColumn( int col
) { m_col
= col
; }
687 wxDataViewModel
* GetModel() const { return m_model
; }
688 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
690 const wxVariant
&GetValue() const { return m_value
; }
691 void SetValue( const wxVariant
&value
) { m_value
= value
; }
693 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
694 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
695 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
697 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
700 wxDataViewItem m_item
;
702 wxDataViewModel
*m_model
;
704 wxDataViewColumn
*m_column
;
707 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
710 BEGIN_DECLARE_EVENT_TYPES()
711 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, -1)
713 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, -1)
714 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, -1)
715 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, -1)
716 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, -1)
717 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, -1)
718 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, -1)
719 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, -1)
720 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, -1)
722 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, -1)
723 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, -1)
724 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, -1)
725 END_DECLARE_EVENT_TYPES()
727 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
729 #define wxDataViewEventHandler(func) \
730 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
732 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
733 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
735 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
737 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
738 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
739 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
740 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
741 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
742 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
743 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
744 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
746 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
747 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
748 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
750 #if defined(wxUSE_GENERICDATAVIEWCTRL)
751 #include "wx/generic/dataview.h"
752 #elif defined(__WXGTK20__)
753 #include "wx/gtk/dataview.h"
754 #elif defined(__WXMAC__)
755 #include "wx/mac/dataview.h"
757 #include "wx/generic/dataview.h"
760 // -------------------------------------
761 // wxDataViewSpinRenderer
762 // -------------------------------------
764 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer
: public wxDataViewCustomRenderer
767 wxDataViewSpinRenderer( int min
, int max
,
768 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
769 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
770 virtual bool HasEditorCtrl() { return true; }
771 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
772 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
773 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
774 virtual wxSize
GetSize() const;
775 virtual bool SetValue( const wxVariant
&value
);
776 virtual bool GetValue( wxVariant
&value
) const;
783 //-----------------------------------------------------------------------------
784 // wxDataViewTreeStore
785 //-----------------------------------------------------------------------------
787 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
790 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
791 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
792 virtual ~wxDataViewTreeStoreNode();
794 void SetText( const wxString
&text
)
796 wxString
GetText() const
798 void SetIcon( const wxIcon
&icon
)
800 const wxIcon
&GetIcon() const
802 void SetData( wxClientData
*data
)
803 { if (m_data
) delete m_data
; m_data
= data
; }
804 wxClientData
*GetData() const
807 wxDataViewItem
GetItem() const
808 { return wxDataViewItem( (void*) this ); }
810 virtual bool IsContainer()
813 wxDataViewTreeStoreNode
*GetParent()
817 wxDataViewTreeStoreNode
*m_parent
;
820 wxClientData
*m_data
;
823 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
824 class WXDLLIMPEXP_ADV
);
826 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
829 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
830 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
831 wxClientData
*data
= NULL
);
832 virtual ~wxDataViewTreeStoreContainerNode();
834 const wxDataViewTreeStoreNodeList
&GetChildren() const
835 { return m_children
; }
836 wxDataViewTreeStoreNodeList
&GetChildren()
837 { return m_children
; }
839 void SetExpandedIcon( const wxIcon
&icon
)
840 { m_iconExpanded
= icon
; }
841 const wxIcon
&GetExpandedIcon() const
842 { return m_iconExpanded
; }
844 virtual bool IsContainer()
848 wxDataViewTreeStoreNodeList m_children
;
849 wxIcon m_iconExpanded
;
852 //-----------------------------------------------------------------------------
854 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
857 wxDataViewTreeStore();
858 ~wxDataViewTreeStore();
860 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
861 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
862 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
863 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
864 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
865 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
867 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
868 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
869 wxClientData
*data
= NULL
);
870 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
871 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
872 wxClientData
*data
= NULL
);
873 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
874 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
875 wxClientData
*data
= NULL
);
877 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
878 int GetChildCount( const wxDataViewItem
& parent
) const;
880 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
881 wxString
GetItemText( const wxDataViewItem
& item
) const;
882 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
883 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
884 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
885 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
886 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
887 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
889 void DeleteItem( const wxDataViewItem
& item
);
890 void DeleteChildren( const wxDataViewItem
& item
);
891 void DeleteAllItems();
893 // implement base methods
895 virtual void GetValue( wxVariant
&variant
,
896 const wxDataViewItem
&item
, unsigned int col
) const;
897 virtual bool SetValue( const wxVariant
&variant
,
898 const wxDataViewItem
&item
, unsigned int col
);
899 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
900 virtual bool IsContainer( const wxDataViewItem
&item
) const;
901 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
903 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
904 unsigned int column
, bool ascending
);
906 virtual bool HasDefaultCompare() const
908 virtual unsigned int GetColumnCount() const
910 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
911 { return "wxDataViewIconText"; }
913 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
914 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
915 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
918 wxDataViewTreeStoreNode
*m_root
;
922 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
925 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
926 const wxPoint
& pos
= wxDefaultPosition
,
927 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
928 const wxValidator
& validator
= wxDefaultValidator
);
930 bool Create( wxWindow
*parent
, wxWindowID id
,
931 const wxPoint
& pos
= wxDefaultPosition
,
932 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
933 const wxValidator
& validator
= wxDefaultValidator
);
935 wxDataViewTreeStore
*GetStore()
936 { return (wxDataViewTreeStore
*) GetModel(); }
938 void OnExpand( wxDataViewCtrl
&event
);
939 void OnCollapse( wxDataViewCtrl
&event
);
942 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
946 #endif // wxUSE_DATAVIEWCTRL
949 // _WX_DATAVIEW_H_BASE_