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 void GetValue( wxVariant
&variant
,
232 unsigned int row
, unsigned int col
) const = 0;
234 virtual bool SetValue( const wxVariant
&variant
,
235 unsigned int row
, unsigned int col
) = 0;
237 virtual bool GetAttr( unsigned int WXUNUSED(row
), unsigned int WXUNUSED(col
), wxDataViewItemAttr
&WXUNUSED(attr
) )
241 void RowInserted( unsigned int before
);
243 void RowDeleted( unsigned int row
);
244 void RowChanged( unsigned int row
);
245 void RowValueChanged( unsigned int row
, unsigned int col
);
247 // convert to/from row/wxDataViewItem
249 unsigned int GetRow( const wxDataViewItem
&item
) const;
250 wxDataViewItem
GetItem( unsigned int row
) const;
252 // compare based on index
254 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
255 unsigned int column
, bool ascending
);
256 virtual bool HasDefaultCompare() const;
258 // implement base methods
260 virtual void GetValue( wxVariant
&variant
,
261 const wxDataViewItem
&item
, unsigned int col
) const;
262 virtual bool SetValue( const wxVariant
&variant
,
263 const wxDataViewItem
&item
, unsigned int col
);
264 virtual bool GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
);
265 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
266 virtual bool IsContainer( const wxDataViewItem
&item
) const;
267 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
270 wxDataViewItemArray m_hash
;
271 unsigned int m_lastIndex
;
276 //-----------------------------------------------------------------------------
277 // wxDataViewEditorCtrlEvtHandler
278 //-----------------------------------------------------------------------------
280 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
283 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
285 void AcceptChangesAndFinish();
286 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
289 void OnChar( wxKeyEvent
&event
);
290 void OnKillFocus( wxFocusEvent
&event
);
291 void OnIdle( wxIdleEvent
&event
);
294 wxDataViewRenderer
*m_owner
;
295 wxControl
*m_editorCtrl
;
300 DECLARE_EVENT_TABLE()
303 // ---------------------------------------------------------
304 // wxDataViewRendererBase
305 // ---------------------------------------------------------
307 enum wxDataViewCellMode
309 wxDATAVIEW_CELL_INERT
,
310 wxDATAVIEW_CELL_ACTIVATABLE
,
311 wxDATAVIEW_CELL_EDITABLE
314 enum wxDataViewCellRenderState
316 wxDATAVIEW_CELL_SELECTED
= 1,
317 wxDATAVIEW_CELL_PRELIT
= 2,
318 wxDATAVIEW_CELL_INSENSITIVE
= 4,
319 wxDATAVIEW_CELL_FOCUSED
= 8
322 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
325 wxDataViewRendererBase( const wxString
&varianttype
,
326 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
327 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
329 virtual bool Validate( wxVariant
& WXUNUSED(value
) )
332 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
333 wxDataViewColumn
* GetOwner() { return m_owner
; }
335 // renderer properties:
337 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) = 0;
338 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) const = 0;
340 wxString
GetVariantType() const { return m_variantType
; }
342 virtual void SetMode( wxDataViewCellMode mode
) = 0;
343 virtual wxDataViewCellMode
GetMode() const = 0;
345 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
346 // rather an "int"; that's because for rendering cells it's allowed
347 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
348 virtual void SetAlignment( int align
) = 0;
349 virtual int GetAlignment() const = 0;
352 virtual bool HasEditorCtrl()
354 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
355 wxRect
WXUNUSED(labelRect
),
356 const wxVariant
& WXUNUSED(value
))
358 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
359 wxVariant
& WXUNUSED(value
))
362 virtual bool StartEditing( const wxDataViewItem
&item
, wxRect labelRect
);
363 virtual void CancelEditing();
364 virtual bool FinishEditing();
366 wxControl
*GetEditorCtrl() { return m_editorCtrl
; }
369 wxString m_variantType
;
370 wxDataViewColumn
*m_owner
;
371 wxControl
*m_editorCtrl
;
372 wxDataViewItem m_item
; // for m_editorCtrl
375 const wxDataViewCtrl
* GetView() const;
378 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
381 //-----------------------------------------------------------------------------
382 // wxDataViewIconText
383 //-----------------------------------------------------------------------------
385 class WXDLLIMPEXP_ADV wxDataViewIconText
: public wxObject
388 wxDataViewIconText( const wxString
&text
= wxEmptyString
, const wxIcon
& icon
= wxNullIcon
)
389 { m_icon
= icon
; m_text
= text
; }
390 wxDataViewIconText( const wxDataViewIconText
&other
)
391 { m_icon
= other
.m_icon
; m_text
= other
.m_text
; }
393 void SetText( const wxString
&text
) { m_text
= text
; }
394 wxString
GetText() const { return m_text
; }
395 void SetIcon( const wxIcon
&icon
) { m_icon
= icon
; }
396 const wxIcon
&GetIcon() const { return m_icon
; }
403 DECLARE_DYNAMIC_CLASS(wxDataViewIconText
)
406 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
);
408 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
410 // ---------------------------------------------------------
411 // wxDataViewColumnBase
412 // ---------------------------------------------------------
414 enum wxDataViewColumnFlags
416 wxDATAVIEW_COL_RESIZABLE
= 1,
417 wxDATAVIEW_COL_SORTABLE
= 2,
418 wxDATAVIEW_COL_HIDDEN
= 4
421 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
424 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
,
425 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
426 wxAlignment align
= wxALIGN_CENTER
,
427 int flags
= wxDATAVIEW_COL_RESIZABLE
);
428 wxDataViewColumnBase( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
429 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
430 wxAlignment align
= wxALIGN_CENTER
,
431 int flags
= wxDATAVIEW_COL_RESIZABLE
);
432 virtual ~wxDataViewColumnBase();
436 virtual void SetTitle( const wxString
&title
) = 0;
437 virtual void SetAlignment( wxAlignment align
) = 0;
438 virtual void SetSortable( bool sortable
) = 0;
439 virtual void SetResizeable( bool resizeable
) = 0;
440 virtual void SetHidden( bool hidden
) = 0;
441 virtual void SetSortOrder( bool ascending
) = 0;
442 virtual void SetFlags( int flags
);
443 virtual void SetOwner( wxDataViewCtrl
*owner
)
445 virtual void SetBitmap( const wxBitmap
&bitmap
)
448 virtual void SetMinWidth( int minWidth
) = 0;
449 virtual void SetWidth( int width
) = 0;
454 virtual wxString
GetTitle() const = 0;
455 virtual wxAlignment
GetAlignment() const = 0;
456 virtual int GetWidth() const = 0;
457 virtual int GetMinWidth() const = 0;
459 virtual int GetFlags() const;
461 virtual bool IsSortable() const = 0;
462 virtual bool IsResizeable() const = 0;
463 virtual bool IsHidden() const = 0;
464 virtual bool IsSortOrderAscending() const = 0;
466 const wxBitmap
&GetBitmap() const { return m_bitmap
; }
467 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
469 wxDataViewCtrl
*GetOwner() const { return m_owner
; }
470 wxDataViewRenderer
* GetRenderer() const { return m_renderer
; }
473 wxDataViewRenderer
*m_renderer
;
476 wxDataViewCtrl
*m_owner
;
479 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
482 // ---------------------------------------------------------
483 // wxDataViewCtrlBase
484 // ---------------------------------------------------------
486 #define wxDV_SINGLE 0x0000 // for convenience
487 #define wxDV_MULTIPLE 0x0001 // can select multiple items
489 #define wxDV_NO_HEADER 0x0002 // column titles not visible
490 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
491 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
493 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
496 wxDataViewCtrlBase();
497 virtual ~wxDataViewCtrlBase();
499 virtual bool AssociateModel( wxDataViewModel
*model
);
500 wxDataViewModel
* GetModel();
503 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
504 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
505 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
506 int flags
= wxDATAVIEW_COL_RESIZABLE
);
507 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
508 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
509 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
510 int flags
= wxDATAVIEW_COL_RESIZABLE
);
511 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
512 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
513 wxAlignment align
= wxALIGN_CENTER
,
514 int flags
= wxDATAVIEW_COL_RESIZABLE
);
515 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
516 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
517 wxAlignment align
= wxALIGN_CENTER
,
518 int flags
= wxDATAVIEW_COL_RESIZABLE
);
519 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
520 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
521 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
522 int flags
= wxDATAVIEW_COL_RESIZABLE
);
523 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
524 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
525 wxAlignment align
= wxALIGN_CENTER
,
526 int flags
= wxDATAVIEW_COL_RESIZABLE
);
527 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
528 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
529 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
530 int flags
= wxDATAVIEW_COL_RESIZABLE
);
531 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
532 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
533 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
534 int flags
= wxDATAVIEW_COL_RESIZABLE
);
535 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
536 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
537 wxAlignment align
= wxALIGN_CENTER
,
538 int flags
= wxDATAVIEW_COL_RESIZABLE
);
539 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
540 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
541 wxAlignment align
= wxALIGN_CENTER
,
542 int flags
= wxDATAVIEW_COL_RESIZABLE
);
543 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
544 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
545 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
546 int flags
= wxDATAVIEW_COL_RESIZABLE
);
547 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
548 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
549 wxAlignment align
= wxALIGN_CENTER
,
550 int flags
= wxDATAVIEW_COL_RESIZABLE
);
552 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
553 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
554 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
555 int flags
= wxDATAVIEW_COL_RESIZABLE
);
556 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
557 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
558 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
559 int flags
= wxDATAVIEW_COL_RESIZABLE
);
560 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
561 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
562 wxAlignment align
= wxALIGN_CENTER
,
563 int flags
= wxDATAVIEW_COL_RESIZABLE
);
564 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
565 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
566 wxAlignment align
= wxALIGN_CENTER
,
567 int flags
= wxDATAVIEW_COL_RESIZABLE
);
568 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
569 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
570 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
571 int flags
= wxDATAVIEW_COL_RESIZABLE
);
572 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
573 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
574 wxAlignment align
= wxALIGN_CENTER
,
575 int flags
= wxDATAVIEW_COL_RESIZABLE
);
576 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
577 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
578 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
579 int flags
= wxDATAVIEW_COL_RESIZABLE
);
580 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
581 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
582 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
583 int flags
= wxDATAVIEW_COL_RESIZABLE
);
584 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
585 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
586 wxAlignment align
= wxALIGN_CENTER
,
587 int flags
= wxDATAVIEW_COL_RESIZABLE
);
588 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
589 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
590 wxAlignment align
= wxALIGN_CENTER
,
591 int flags
= wxDATAVIEW_COL_RESIZABLE
);
592 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
593 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
594 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
595 int flags
= wxDATAVIEW_COL_RESIZABLE
);
596 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
597 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
598 wxAlignment align
= wxALIGN_CENTER
,
599 int flags
= wxDATAVIEW_COL_RESIZABLE
);
602 virtual bool PrependColumn( wxDataViewColumn
*col
);
603 virtual bool AppendColumn( wxDataViewColumn
*col
);
605 virtual unsigned int GetColumnCount() const = 0;
606 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
607 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
609 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
610 virtual bool ClearColumns() = 0;
612 void SetExpanderColumn( wxDataViewColumn
*col
)
613 { m_expander_column
= col
; DoSetExpanderColumn(); }
614 wxDataViewColumn
*GetExpanderColumn() const
615 { return m_expander_column
; }
617 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
619 void SetIndent( int indent
)
620 { m_indent
= indent
; DoSetIndent(); }
621 int GetIndent() const
624 virtual wxDataViewItem
GetSelection() const = 0;
625 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
626 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
627 virtual void Select( const wxDataViewItem
& item
) = 0;
628 virtual void Unselect( const wxDataViewItem
& item
) = 0;
629 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
631 virtual void SelectAll() = 0;
632 virtual void UnselectAll() = 0;
634 virtual void Expand( const wxDataViewItem
& item
) = 0;
635 virtual void Collapse( const wxDataViewItem
& item
) = 0;
637 virtual void EnsureVisible( const wxDataViewItem
& item
,
638 const wxDataViewColumn
*column
= NULL
) = 0;
639 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
640 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
643 virtual void DoSetExpanderColumn() = 0 ;
644 virtual void DoSetIndent() = 0;
647 wxDataViewModel
*m_model
;
648 wxDataViewColumn
*m_expander_column
;
652 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
655 // ----------------------------------------------------------------------------
656 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
657 // ----------------------------------------------------------------------------
659 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
662 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
663 : wxNotifyEvent(commandType
, winid
),
667 m_value(wxNullVariant
),
671 wxDataViewEvent(const wxDataViewEvent
& event
)
672 : wxNotifyEvent(event
),
673 m_item(event
.m_item
),
675 m_model(event
.m_model
),
676 m_value(event
.m_value
),
677 m_column(event
.m_column
)
680 wxDataViewItem
GetItem() const { return m_item
; }
681 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
683 int GetColumn() const { return m_col
; }
684 void SetColumn( int col
) { m_col
= col
; }
686 wxDataViewModel
* GetModel() const { return m_model
; }
687 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
689 const wxVariant
&GetValue() const { return m_value
; }
690 void SetValue( const wxVariant
&value
) { m_value
= value
; }
692 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
693 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
694 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
696 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
699 wxDataViewItem m_item
;
701 wxDataViewModel
*m_model
;
703 wxDataViewColumn
*m_column
;
706 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
709 BEGIN_DECLARE_EVENT_TYPES()
710 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, -1)
712 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, -1)
713 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, -1)
714 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, -1)
715 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, -1)
716 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, -1)
717 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, -1)
718 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, -1)
719 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, -1)
721 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, -1)
722 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, -1)
723 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, -1)
724 END_DECLARE_EVENT_TYPES()
726 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
728 #define wxDataViewEventHandler(func) \
729 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
731 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
732 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
734 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
736 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
737 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
738 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
739 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
740 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
741 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
742 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
743 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
745 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
746 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
747 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
749 #if defined(wxUSE_GENERICDATAVIEWCTRL)
750 #include "wx/generic/dataview.h"
751 #elif defined(__WXGTK20__)
752 #include "wx/gtk/dataview.h"
753 #elif defined(__WXMAC__)
754 #include "wx/mac/dataview.h"
756 #include "wx/generic/dataview.h"
759 // -------------------------------------
760 // wxDataViewSpinRenderer
761 // -------------------------------------
763 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer
: public wxDataViewCustomRenderer
766 wxDataViewSpinRenderer( int min
, int max
,
767 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
768 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
769 virtual bool HasEditorCtrl() { return true; }
770 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
771 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
772 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
773 virtual wxSize
GetSize() const;
774 virtual bool SetValue( const wxVariant
&value
);
775 virtual bool GetValue( wxVariant
&value
) const;
782 //-----------------------------------------------------------------------------
783 // wxDataViewTreeStore
784 //-----------------------------------------------------------------------------
786 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
789 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
790 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
791 virtual ~wxDataViewTreeStoreNode();
793 void SetText( const wxString
&text
)
795 wxString
GetText() const
797 void SetIcon( const wxIcon
&icon
)
799 const wxIcon
&GetIcon() const
801 void SetData( wxClientData
*data
)
802 { if (m_data
) delete m_data
; m_data
= data
; }
803 wxClientData
*GetData() const
806 wxDataViewItem
GetItem() const
807 { return wxDataViewItem( (void*) this ); }
809 virtual bool IsContainer()
812 wxDataViewTreeStoreNode
*GetParent()
816 wxDataViewTreeStoreNode
*m_parent
;
819 wxClientData
*m_data
;
822 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
823 class WXDLLIMPEXP_ADV
);
825 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
828 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
829 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
830 wxClientData
*data
= NULL
);
831 virtual ~wxDataViewTreeStoreContainerNode();
833 const wxDataViewTreeStoreNodeList
&GetChildren() const
834 { return m_children
; }
835 wxDataViewTreeStoreNodeList
&GetChildren()
836 { return m_children
; }
838 void SetExpandedIcon( const wxIcon
&icon
)
839 { m_iconExpanded
= icon
; }
840 const wxIcon
&GetExpandedIcon() const
841 { return m_iconExpanded
; }
843 virtual bool IsContainer()
847 wxDataViewTreeStoreNodeList m_children
;
848 wxIcon m_iconExpanded
;
851 //-----------------------------------------------------------------------------
853 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
856 wxDataViewTreeStore();
857 ~wxDataViewTreeStore();
859 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
860 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
861 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
862 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
863 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
864 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
866 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
867 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
868 wxClientData
*data
= NULL
);
869 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
870 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
871 wxClientData
*data
= NULL
);
872 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
873 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
874 wxClientData
*data
= NULL
);
876 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
877 int GetChildCount( const wxDataViewItem
& parent
) const;
879 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
880 wxString
GetItemText( const wxDataViewItem
& item
) const;
881 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
882 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
883 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
884 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
885 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
886 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
888 void DeleteItem( const wxDataViewItem
& item
);
889 void DeleteChildren( const wxDataViewItem
& item
);
890 void DeleteAllItems();
892 // implement base methods
894 virtual void GetValue( wxVariant
&variant
,
895 const wxDataViewItem
&item
, unsigned int col
) const;
896 virtual bool SetValue( const wxVariant
&variant
,
897 const wxDataViewItem
&item
, unsigned int col
);
898 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
899 virtual bool IsContainer( const wxDataViewItem
&item
) const;
900 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
902 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
903 unsigned int column
, bool ascending
);
905 virtual bool HasDefaultCompare() const
907 virtual unsigned int GetColumnCount() const
909 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
910 { return wxT("wxDataViewIconText"); }
912 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
913 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
914 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
917 wxDataViewTreeStoreNode
*m_root
;
921 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
924 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
925 const wxPoint
& pos
= wxDefaultPosition
,
926 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
927 const wxValidator
& validator
= wxDefaultValidator
);
929 bool Create( wxWindow
*parent
, wxWindowID id
,
930 const wxPoint
& pos
= wxDefaultPosition
,
931 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
932 const wxValidator
& validator
= wxDefaultValidator
);
934 wxDataViewTreeStore
*GetStore()
935 { return (wxDataViewTreeStore
*) GetModel(); }
937 void OnExpand( wxDataViewCtrl
&event
);
938 void OnCollapse( wxDataViewCtrl
&event
);
941 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
945 #endif // wxUSE_DATAVIEWCTRL
948 // _WX_DATAVIEW_H_BASE_