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 virtual bool IsIndexListModel() const { return false; }
218 // the user should not delete this class directly: he should use DecRef() instead!
219 virtual ~wxDataViewModel() { }
221 wxDataViewModelNotifiers m_notifiers
;
224 // ---------------------------------------------------------
225 // wxDataViewIndexListModel
226 // ---------------------------------------------------------
228 class WXDLLIMPEXP_ADV wxDataViewIndexListModel
: public wxDataViewModel
231 wxDataViewIndexListModel( unsigned int initial_size
= 0 );
232 ~wxDataViewIndexListModel();
234 virtual void GetValue( wxVariant
&variant
,
235 unsigned int row
, unsigned int col
) const = 0;
237 virtual bool SetValue( const wxVariant
&variant
,
238 unsigned int row
, unsigned int col
) = 0;
240 virtual bool GetAttr( unsigned int WXUNUSED(row
), unsigned int WXUNUSED(col
), wxDataViewItemAttr
&WXUNUSED(attr
) )
244 void RowInserted( unsigned int before
);
246 void RowDeleted( unsigned int row
);
247 void RowChanged( unsigned int row
);
248 void RowValueChanged( unsigned int row
, unsigned int col
);
250 // convert to/from row/wxDataViewItem
252 unsigned int GetRow( const wxDataViewItem
&item
) const;
253 wxDataViewItem
GetItem( unsigned int row
) const;
255 // compare based on index
257 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
258 unsigned int column
, bool ascending
);
259 virtual bool HasDefaultCompare() const;
261 // implement base methods
263 virtual void GetValue( wxVariant
&variant
,
264 const wxDataViewItem
&item
, unsigned int col
) const;
265 virtual bool SetValue( const wxVariant
&variant
,
266 const wxDataViewItem
&item
, unsigned int col
);
267 virtual bool GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
);
268 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
269 virtual bool IsContainer( const wxDataViewItem
&item
) const;
270 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
273 virtual bool IsIndexListModel() const { return true; }
274 unsigned int GetLastIndex() const { return m_lastIndex
; }
277 wxDataViewItemArray m_hash
;
278 unsigned int m_lastIndex
;
284 //-----------------------------------------------------------------------------
285 // wxDataViewEditorCtrlEvtHandler
286 //-----------------------------------------------------------------------------
288 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
291 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
293 void AcceptChangesAndFinish();
294 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
297 void OnChar( wxKeyEvent
&event
);
298 void OnKillFocus( wxFocusEvent
&event
);
299 void OnIdle( wxIdleEvent
&event
);
302 wxDataViewRenderer
*m_owner
;
303 wxControl
*m_editorCtrl
;
308 DECLARE_EVENT_TABLE()
311 // ---------------------------------------------------------
312 // wxDataViewRendererBase
313 // ---------------------------------------------------------
315 enum wxDataViewCellMode
317 wxDATAVIEW_CELL_INERT
,
318 wxDATAVIEW_CELL_ACTIVATABLE
,
319 wxDATAVIEW_CELL_EDITABLE
322 enum wxDataViewCellRenderState
324 wxDATAVIEW_CELL_SELECTED
= 1,
325 wxDATAVIEW_CELL_PRELIT
= 2,
326 wxDATAVIEW_CELL_INSENSITIVE
= 4,
327 wxDATAVIEW_CELL_FOCUSED
= 8
330 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
333 wxDataViewRendererBase( const wxString
&varianttype
,
334 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
335 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
337 virtual bool Validate( wxVariant
& WXUNUSED(value
) )
340 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
341 wxDataViewColumn
* GetOwner() { return m_owner
; }
343 // renderer properties:
345 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) = 0;
346 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) const = 0;
348 wxString
GetVariantType() const { return m_variantType
; }
350 virtual void SetMode( wxDataViewCellMode mode
) = 0;
351 virtual wxDataViewCellMode
GetMode() const = 0;
353 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
354 // rather an "int"; that's because for rendering cells it's allowed
355 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
356 virtual void SetAlignment( int align
) = 0;
357 virtual int GetAlignment() const = 0;
360 virtual bool HasEditorCtrl()
362 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
363 wxRect
WXUNUSED(labelRect
),
364 const wxVariant
& WXUNUSED(value
))
366 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
367 wxVariant
& WXUNUSED(value
))
370 virtual bool StartEditing( const wxDataViewItem
&item
, wxRect labelRect
);
371 virtual void CancelEditing();
372 virtual bool FinishEditing();
374 wxControl
*GetEditorCtrl() { return m_editorCtrl
; }
377 wxString m_variantType
;
378 wxDataViewColumn
*m_owner
;
379 wxControl
*m_editorCtrl
;
380 wxDataViewItem m_item
; // for m_editorCtrl
383 const wxDataViewCtrl
* GetView() const;
386 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
389 //-----------------------------------------------------------------------------
390 // wxDataViewIconText
391 //-----------------------------------------------------------------------------
393 class WXDLLIMPEXP_ADV wxDataViewIconText
: public wxObject
396 wxDataViewIconText( const wxString
&text
= wxEmptyString
, const wxIcon
& icon
= wxNullIcon
)
397 { m_icon
= icon
; m_text
= text
; }
398 wxDataViewIconText( const wxDataViewIconText
&other
)
399 { m_icon
= other
.m_icon
; m_text
= other
.m_text
; }
401 void SetText( const wxString
&text
) { m_text
= text
; }
402 wxString
GetText() const { return m_text
; }
403 void SetIcon( const wxIcon
&icon
) { m_icon
= icon
; }
404 const wxIcon
&GetIcon() const { return m_icon
; }
411 DECLARE_DYNAMIC_CLASS(wxDataViewIconText
)
414 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
);
416 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
418 // ---------------------------------------------------------
419 // wxDataViewColumnBase
420 // ---------------------------------------------------------
422 enum wxDataViewColumnFlags
424 wxDATAVIEW_COL_RESIZABLE
= 1,
425 wxDATAVIEW_COL_SORTABLE
= 2,
426 wxDATAVIEW_COL_HIDDEN
= 4
429 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
432 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
,
433 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
434 wxAlignment align
= wxALIGN_CENTER
,
435 int flags
= wxDATAVIEW_COL_RESIZABLE
);
436 wxDataViewColumnBase( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
437 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
438 wxAlignment align
= wxALIGN_CENTER
,
439 int flags
= wxDATAVIEW_COL_RESIZABLE
);
440 virtual ~wxDataViewColumnBase();
444 virtual void SetTitle( const wxString
&title
) = 0;
445 virtual void SetAlignment( wxAlignment align
) = 0;
446 virtual void SetSortable( bool sortable
) = 0;
447 virtual void SetResizeable( bool resizeable
) = 0;
448 virtual void SetHidden( bool hidden
) = 0;
449 virtual void SetSortOrder( bool ascending
) = 0;
450 virtual void SetFlags( int flags
);
451 virtual void SetOwner( wxDataViewCtrl
*owner
)
453 virtual void SetBitmap( const wxBitmap
&bitmap
)
456 virtual void SetMinWidth( int minWidth
) = 0;
457 virtual void SetWidth( int width
) = 0;
462 virtual wxString
GetTitle() const = 0;
463 virtual wxAlignment
GetAlignment() const = 0;
464 virtual int GetWidth() const = 0;
465 virtual int GetMinWidth() const = 0;
467 virtual int GetFlags() const;
469 virtual bool IsSortable() const = 0;
470 virtual bool IsResizeable() const = 0;
471 virtual bool IsHidden() const = 0;
472 virtual bool IsSortOrderAscending() const = 0;
474 const wxBitmap
&GetBitmap() const { return m_bitmap
; }
475 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
477 wxDataViewCtrl
*GetOwner() const { return m_owner
; }
478 wxDataViewRenderer
* GetRenderer() const { return m_renderer
; }
481 wxDataViewRenderer
*m_renderer
;
484 wxDataViewCtrl
*m_owner
;
487 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
490 // ---------------------------------------------------------
491 // wxDataViewCtrlBase
492 // ---------------------------------------------------------
494 #define wxDV_SINGLE 0x0000 // for convenience
495 #define wxDV_MULTIPLE 0x0001 // can select multiple items
497 #define wxDV_NO_HEADER 0x0002 // column titles not visible
498 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
499 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
501 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
504 wxDataViewCtrlBase();
505 virtual ~wxDataViewCtrlBase();
507 virtual bool AssociateModel( wxDataViewModel
*model
);
508 wxDataViewModel
* GetModel();
511 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
512 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
513 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
514 int flags
= wxDATAVIEW_COL_RESIZABLE
);
515 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
516 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
517 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
518 int flags
= wxDATAVIEW_COL_RESIZABLE
);
519 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
520 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
521 wxAlignment align
= wxALIGN_CENTER
,
522 int flags
= wxDATAVIEW_COL_RESIZABLE
);
523 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
524 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
525 wxAlignment align
= wxALIGN_CENTER
,
526 int flags
= wxDATAVIEW_COL_RESIZABLE
);
527 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
528 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
529 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
530 int flags
= wxDATAVIEW_COL_RESIZABLE
);
531 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
532 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
533 wxAlignment align
= wxALIGN_CENTER
,
534 int flags
= wxDATAVIEW_COL_RESIZABLE
);
535 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
536 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
537 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
538 int flags
= wxDATAVIEW_COL_RESIZABLE
);
539 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
540 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
541 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
542 int flags
= wxDATAVIEW_COL_RESIZABLE
);
543 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
544 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
545 wxAlignment align
= wxALIGN_CENTER
,
546 int flags
= wxDATAVIEW_COL_RESIZABLE
);
547 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
548 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
549 wxAlignment align
= wxALIGN_CENTER
,
550 int flags
= wxDATAVIEW_COL_RESIZABLE
);
551 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
552 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
553 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
554 int flags
= wxDATAVIEW_COL_RESIZABLE
);
555 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
556 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
557 wxAlignment align
= wxALIGN_CENTER
,
558 int flags
= wxDATAVIEW_COL_RESIZABLE
);
560 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
561 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
562 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
563 int flags
= wxDATAVIEW_COL_RESIZABLE
);
564 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
565 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
566 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
567 int flags
= wxDATAVIEW_COL_RESIZABLE
);
568 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
569 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
570 wxAlignment align
= wxALIGN_CENTER
,
571 int flags
= wxDATAVIEW_COL_RESIZABLE
);
572 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
573 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
574 wxAlignment align
= wxALIGN_CENTER
,
575 int flags
= wxDATAVIEW_COL_RESIZABLE
);
576 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
577 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
578 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
579 int flags
= wxDATAVIEW_COL_RESIZABLE
);
580 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
581 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
582 wxAlignment align
= wxALIGN_CENTER
,
583 int flags
= wxDATAVIEW_COL_RESIZABLE
);
584 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
585 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
586 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
587 int flags
= wxDATAVIEW_COL_RESIZABLE
);
588 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
589 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
590 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
591 int flags
= wxDATAVIEW_COL_RESIZABLE
);
592 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
593 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
594 wxAlignment align
= wxALIGN_CENTER
,
595 int flags
= wxDATAVIEW_COL_RESIZABLE
);
596 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
597 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
598 wxAlignment align
= wxALIGN_CENTER
,
599 int flags
= wxDATAVIEW_COL_RESIZABLE
);
600 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
601 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
602 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
603 int flags
= wxDATAVIEW_COL_RESIZABLE
);
604 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
605 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
606 wxAlignment align
= wxALIGN_CENTER
,
607 int flags
= wxDATAVIEW_COL_RESIZABLE
);
610 virtual bool PrependColumn( wxDataViewColumn
*col
);
611 virtual bool AppendColumn( wxDataViewColumn
*col
);
613 virtual unsigned int GetColumnCount() const = 0;
614 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
615 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
617 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
618 virtual bool ClearColumns() = 0;
620 void SetExpanderColumn( wxDataViewColumn
*col
)
621 { m_expander_column
= col
; DoSetExpanderColumn(); }
622 wxDataViewColumn
*GetExpanderColumn() const
623 { return m_expander_column
; }
625 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
627 void SetIndent( int indent
)
628 { m_indent
= indent
; DoSetIndent(); }
629 int GetIndent() const
632 virtual wxDataViewItem
GetSelection() const = 0;
633 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
634 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
635 virtual void Select( const wxDataViewItem
& item
) = 0;
636 virtual void Unselect( const wxDataViewItem
& item
) = 0;
637 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
639 virtual void SelectAll() = 0;
640 virtual void UnselectAll() = 0;
642 virtual void Expand( const wxDataViewItem
& item
) = 0;
643 virtual void Collapse( const wxDataViewItem
& item
) = 0;
645 virtual void EnsureVisible( const wxDataViewItem
& item
,
646 const wxDataViewColumn
*column
= NULL
) = 0;
647 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
648 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
651 virtual void DoSetExpanderColumn() = 0 ;
652 virtual void DoSetIndent() = 0;
655 wxDataViewModel
*m_model
;
656 wxDataViewColumn
*m_expander_column
;
660 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
663 // ----------------------------------------------------------------------------
664 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
665 // ----------------------------------------------------------------------------
667 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
670 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
671 : wxNotifyEvent(commandType
, winid
),
675 m_value(wxNullVariant
),
679 wxDataViewEvent(const wxDataViewEvent
& event
)
680 : wxNotifyEvent(event
),
681 m_item(event
.m_item
),
683 m_model(event
.m_model
),
684 m_value(event
.m_value
),
685 m_column(event
.m_column
)
688 wxDataViewItem
GetItem() const { return m_item
; }
689 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
691 int GetColumn() const { return m_col
; }
692 void SetColumn( int col
) { m_col
= col
; }
694 wxDataViewModel
* GetModel() const { return m_model
; }
695 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
697 const wxVariant
&GetValue() const { return m_value
; }
698 void SetValue( const wxVariant
&value
) { m_value
= value
; }
700 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
701 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
702 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
704 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
707 wxDataViewItem m_item
;
709 wxDataViewModel
*m_model
;
711 wxDataViewColumn
*m_column
;
714 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
717 BEGIN_DECLARE_EVENT_TYPES()
718 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, -1)
720 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, -1)
721 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, -1)
722 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, -1)
723 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, -1)
724 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, -1)
725 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, -1)
726 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, -1)
727 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, -1)
729 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, -1)
730 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, -1)
731 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, -1)
732 END_DECLARE_EVENT_TYPES()
734 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
736 #define wxDataViewEventHandler(func) \
737 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
739 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
740 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
742 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
744 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
745 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
746 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
747 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
748 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
749 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
750 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
751 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
753 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
754 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
755 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
757 #if defined(wxUSE_GENERICDATAVIEWCTRL)
758 #include "wx/generic/dataview.h"
759 #elif defined(__WXGTK20__)
760 #include "wx/gtk/dataview.h"
761 #elif defined(__WXMAC__)
762 #include "wx/mac/dataview.h"
764 #include "wx/generic/dataview.h"
767 // -------------------------------------
768 // wxDataViewSpinRenderer
769 // -------------------------------------
771 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer
: public wxDataViewCustomRenderer
774 wxDataViewSpinRenderer( int min
, int max
,
775 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
776 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
777 virtual bool HasEditorCtrl() { return true; }
778 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
779 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
780 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
781 virtual wxSize
GetSize() const;
782 virtual bool SetValue( const wxVariant
&value
);
783 virtual bool GetValue( wxVariant
&value
) const;
790 //-----------------------------------------------------------------------------
791 // wxDataViewTreeStore
792 //-----------------------------------------------------------------------------
794 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
797 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
798 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
799 virtual ~wxDataViewTreeStoreNode();
801 void SetText( const wxString
&text
)
803 wxString
GetText() const
805 void SetIcon( const wxIcon
&icon
)
807 const wxIcon
&GetIcon() const
809 void SetData( wxClientData
*data
)
810 { if (m_data
) delete m_data
; m_data
= data
; }
811 wxClientData
*GetData() const
814 wxDataViewItem
GetItem() const
815 { return wxDataViewItem( (void*) this ); }
817 virtual bool IsContainer()
820 wxDataViewTreeStoreNode
*GetParent()
824 wxDataViewTreeStoreNode
*m_parent
;
827 wxClientData
*m_data
;
830 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
831 class WXDLLIMPEXP_ADV
);
833 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
836 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
837 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
838 wxClientData
*data
= NULL
);
839 virtual ~wxDataViewTreeStoreContainerNode();
841 const wxDataViewTreeStoreNodeList
&GetChildren() const
842 { return m_children
; }
843 wxDataViewTreeStoreNodeList
&GetChildren()
844 { return m_children
; }
846 void SetExpandedIcon( const wxIcon
&icon
)
847 { m_iconExpanded
= icon
; }
848 const wxIcon
&GetExpandedIcon() const
849 { return m_iconExpanded
; }
851 virtual bool IsContainer()
855 wxDataViewTreeStoreNodeList m_children
;
856 wxIcon m_iconExpanded
;
859 //-----------------------------------------------------------------------------
861 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
864 wxDataViewTreeStore();
865 ~wxDataViewTreeStore();
867 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
868 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
869 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
870 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
871 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
872 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
874 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
875 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
876 wxClientData
*data
= NULL
);
877 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
878 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
879 wxClientData
*data
= NULL
);
880 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
881 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
882 wxClientData
*data
= NULL
);
884 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
885 int GetChildCount( const wxDataViewItem
& parent
) const;
887 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
888 wxString
GetItemText( const wxDataViewItem
& item
) const;
889 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
890 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
891 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
892 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
893 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
894 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
896 void DeleteItem( const wxDataViewItem
& item
);
897 void DeleteChildren( const wxDataViewItem
& item
);
898 void DeleteAllItems();
900 // implement base methods
902 virtual void GetValue( wxVariant
&variant
,
903 const wxDataViewItem
&item
, unsigned int col
) const;
904 virtual bool SetValue( const wxVariant
&variant
,
905 const wxDataViewItem
&item
, unsigned int col
);
906 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
907 virtual bool IsContainer( const wxDataViewItem
&item
) const;
908 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
910 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
911 unsigned int column
, bool ascending
);
913 virtual bool HasDefaultCompare() const
915 virtual unsigned int GetColumnCount() const
917 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
918 { return wxT("wxDataViewIconText"); }
920 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
921 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
922 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
925 wxDataViewTreeStoreNode
*m_root
;
929 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
932 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
933 const wxPoint
& pos
= wxDefaultPosition
,
934 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
935 const wxValidator
& validator
= wxDefaultValidator
);
937 bool Create( wxWindow
*parent
, wxWindowID id
,
938 const wxPoint
& pos
= wxDefaultPosition
,
939 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
940 const wxValidator
& validator
= wxDefaultValidator
);
942 wxDataViewTreeStore
*GetStore()
943 { return (wxDataViewTreeStore
*) GetModel(); }
945 void OnExpand( wxDataViewCtrl
&event
);
946 void OnCollapse( wxDataViewCtrl
&event
);
949 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
953 #endif // wxUSE_DATAVIEWCTRL
956 // _WX_DATAVIEW_H_BASE_