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/listctrl.h"
24 #include "wx/dynarray.h"
27 #if defined(__WXGTK20__)
29 // #define wxUSE_GENERICDATAVIEWCTRL 1
30 #elif defined(__WXMAC__)
32 #define wxUSE_GENERICDATAVIEWCTRL 1
35 // ----------------------------------------------------------------------------
36 // wxDataViewCtrl flags
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
40 // wxDataViewCtrl globals
41 // ----------------------------------------------------------------------------
43 class WXDLLIMPEXP_FWD_ADV wxDataViewItem
;
44 class WXDLLIMPEXP_FWD_ADV wxDataViewModel
;
45 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn
;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer
;
48 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier
;
50 extern WXDLLIMPEXP_DATA_ADV(const wxChar
) wxDataViewCtrlNameStr
[];
52 // the default width of new (text) columns:
53 #define wxDVC_DEFAULT_WIDTH 80
55 // the default width of new toggle columns:
56 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
58 // the default minimal width of the columns:
59 #define wxDVC_DEFAULT_MINWIDTH 30
61 // the default alignment of wxDataViewRenderers:
62 #define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL)
65 // ---------------------------------------------------------
67 // ---------------------------------------------------------
69 class WXDLLIMPEXP_ADV wxDataViewItem
72 wxDataViewItem( void* id
= NULL
)
74 wxDataViewItem( const wxDataViewItem
&item
)
76 bool IsOk() const { return m_id
!= NULL
; }
77 void* GetID() const { return m_id
; }
78 operator const void* () const { return m_id
; }
81 void Print( const wxString
&text
) const { wxPrintf( "item %s: %d\n", text
, (int) m_id
); }
88 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
);
90 WX_DEFINE_ARRAY(wxDataViewItem
, wxDataViewItemArray
);
92 // ---------------------------------------------------------
93 // wxDataViewModelNotifier
94 // ---------------------------------------------------------
96 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
99 wxDataViewModelNotifier() { }
100 virtual ~wxDataViewModelNotifier() { m_owner
= NULL
; }
102 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
103 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
104 virtual bool ItemChanged( const wxDataViewItem
&item
) = 0;
105 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
106 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
107 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
108 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
) = 0;
109 virtual bool Cleared() = 0;
111 virtual void Resort() = 0;
113 void SetOwner( wxDataViewModel
*owner
) { m_owner
= owner
; }
114 wxDataViewModel
*GetOwner() { return m_owner
; }
117 wxDataViewModel
*m_owner
;
121 // ---------------------------------------------------------
123 // ---------------------------------------------------------
125 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier
, wxDataViewModelNotifiers
,
126 class WXDLLIMPEXP_ADV
);
128 class WXDLLIMPEXP_ADV wxDataViewModel
: public wxObjectRefData
133 virtual unsigned int GetColumnCount() const = 0;
135 // return type as reported by wxVariant
136 virtual wxString
GetColumnType( unsigned int col
) const = 0;
138 // get value into a wxVariant
139 virtual void GetValue( wxVariant
&variant
,
140 const wxDataViewItem
&item
, unsigned int col
) const = 0;
142 // set value, call ValueChanged() afterwards!
143 virtual bool SetValue( const wxVariant
&variant
,
144 const wxDataViewItem
&item
, unsigned int col
) = 0;
147 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const = 0;
148 virtual bool IsContainer( const wxDataViewItem
&item
) const = 0;
149 // Is the container just a header or an item with all columns
150 virtual bool HasContainerColumns(const wxDataViewItem
& WXUNUSED(item
)) const
152 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const = 0;
154 // delegated notifiers
155 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
156 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
157 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
158 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
159 virtual bool ItemChanged( const wxDataViewItem
&item
);
160 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
161 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
162 virtual bool Cleared();
165 virtual void Resort();
167 void AddNotifier( wxDataViewModelNotifier
*notifier
);
168 void RemoveNotifier( wxDataViewModelNotifier
*notifier
);
170 // default compare function
171 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
172 unsigned int column
, bool ascending
);
173 virtual bool HasDefaultCompare() const { return false; }
176 // the user should not delete this class directly: he should use DecRef() instead!
177 virtual ~wxDataViewModel() { }
179 wxDataViewModelNotifiers m_notifiers
;
182 // ---------------------------------------------------------
183 // wxDataViewIndexListModel
184 // ---------------------------------------------------------
186 class WXDLLIMPEXP_ADV wxDataViewIndexListModel
: public wxDataViewModel
189 wxDataViewIndexListModel( unsigned int initial_size
= 0 );
190 ~wxDataViewIndexListModel();
192 virtual unsigned int GetRowCount() = 0;
194 virtual void GetValue( wxVariant
&variant
,
195 unsigned int row
, unsigned int col
) const = 0;
197 virtual bool SetValue( const wxVariant
&variant
,
198 unsigned int row
, unsigned int col
) = 0;
201 void RowInserted( unsigned int before
);
203 void RowDeleted( unsigned int row
);
204 void RowChanged( unsigned int row
);
205 void RowValueChanged( unsigned int row
, unsigned int col
);
207 // convert to/from row/wxDataViewItem
209 unsigned int GetRow( const wxDataViewItem
&item
) const;
210 wxDataViewItem
GetItem( unsigned int row
) const;
212 // compare based on index
214 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
215 unsigned int column
, bool ascending
);
216 virtual bool HasDefaultCompare() const { return true; }
218 // implement base methods
220 virtual void GetValue( wxVariant
&variant
,
221 const wxDataViewItem
&item
, unsigned int col
) const;
222 virtual bool SetValue( const wxVariant
&variant
,
223 const wxDataViewItem
&item
, unsigned int col
);
224 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
225 virtual bool IsContainer( const wxDataViewItem
&item
) const;
226 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
229 wxDataViewItemArray m_hash
;
230 unsigned int m_lastIndex
;
234 //-----------------------------------------------------------------------------
235 // wxDataViewEditorCtrlEvtHandler
236 //-----------------------------------------------------------------------------
238 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
241 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
243 void AcceptChangesAndFinish();
244 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
247 void OnChar( wxKeyEvent
&event
);
248 void OnKillFocus( wxFocusEvent
&event
);
249 void OnIdle( wxIdleEvent
&event
);
252 wxDataViewRenderer
*m_owner
;
253 wxControl
*m_editorCtrl
;
258 DECLARE_EVENT_TABLE()
261 // ---------------------------------------------------------
262 // wxDataViewRendererBase
263 // ---------------------------------------------------------
265 enum wxDataViewCellMode
267 wxDATAVIEW_CELL_INERT
,
268 wxDATAVIEW_CELL_ACTIVATABLE
,
269 wxDATAVIEW_CELL_EDITABLE
272 enum wxDataViewCellRenderState
274 wxDATAVIEW_CELL_SELECTED
= 1,
275 wxDATAVIEW_CELL_PRELIT
= 2,
276 wxDATAVIEW_CELL_INSENSITIVE
= 4,
277 wxDATAVIEW_CELL_FOCUSED
= 8
280 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
283 wxDataViewRendererBase( const wxString
&varianttype
,
284 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
285 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
287 virtual bool Validate( wxVariant
& WXUNUSED(value
) )
290 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
291 wxDataViewColumn
* GetOwner() { return m_owner
; }
293 // renderer properties:
295 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) = 0;
296 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) const = 0;
298 wxString
GetVariantType() const { return m_variantType
; }
300 virtual void SetMode( wxDataViewCellMode mode
) = 0;
301 virtual wxDataViewCellMode
GetMode() const = 0;
303 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
304 // rather an "int"; that's because for rendering cells it's allowed
305 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
306 virtual void SetAlignment( int align
) = 0;
307 virtual int GetAlignment() const = 0;
310 virtual bool HasEditorCtrl()
312 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
313 wxRect
WXUNUSED(labelRect
),
314 const wxVariant
& WXUNUSED(value
))
316 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
317 wxVariant
& WXUNUSED(value
))
320 virtual bool StartEditing( const wxDataViewItem
&item
, wxRect labelRect
);
321 virtual void CancelEditing();
322 virtual bool FinishEditing();
324 wxControl
*GetEditorCtrl() { return m_editorCtrl
; }
327 wxString m_variantType
;
328 wxDataViewColumn
*m_owner
;
329 wxControl
*m_editorCtrl
;
330 wxDataViewItem m_item
; // for m_editorCtrl
333 const wxDataViewCtrl
* GetView() const;
336 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
339 //-----------------------------------------------------------------------------
340 // wxDataViewIconText
341 //-----------------------------------------------------------------------------
343 class WXDLLIMPEXP_ADV wxDataViewIconText
: public wxObject
346 wxDataViewIconText( const wxString
&text
= wxEmptyString
, const wxIcon
& icon
= wxNullIcon
)
347 { m_icon
= icon
; m_text
= text
; }
348 wxDataViewIconText( const wxDataViewIconText
&other
)
349 { m_icon
= other
.m_icon
; m_text
= other
.m_text
; }
351 void SetText( const wxString
&text
) { m_text
= text
; }
352 wxString
GetText() const { return m_text
; }
353 void SetIcon( const wxIcon
&icon
) { m_icon
= icon
; }
354 const wxIcon
&GetIcon() const { return m_icon
; }
361 DECLARE_DYNAMIC_CLASS(wxDataViewIconText
)
364 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
);
366 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
368 // ---------------------------------------------------------
369 // wxDataViewColumnBase
370 // ---------------------------------------------------------
372 enum wxDataViewColumnFlags
374 wxDATAVIEW_COL_RESIZABLE
= 1,
375 wxDATAVIEW_COL_SORTABLE
= 2,
376 wxDATAVIEW_COL_HIDDEN
= 4
379 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
382 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
,
383 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
384 wxAlignment align
= wxALIGN_CENTER
,
385 int flags
= wxDATAVIEW_COL_RESIZABLE
);
386 wxDataViewColumnBase( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
387 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
388 wxAlignment align
= wxALIGN_CENTER
,
389 int flags
= wxDATAVIEW_COL_RESIZABLE
);
390 virtual ~wxDataViewColumnBase();
394 virtual void SetTitle( const wxString
&title
) = 0;
395 virtual void SetAlignment( wxAlignment align
) = 0;
396 virtual void SetSortable( bool sortable
) = 0;
397 virtual void SetResizeable( bool resizeable
) = 0;
398 virtual void SetHidden( bool hidden
) = 0;
399 virtual void SetSortOrder( bool ascending
) = 0;
400 virtual void SetFlags( int flags
);
401 virtual void SetOwner( wxDataViewCtrl
*owner
)
403 virtual void SetBitmap( const wxBitmap
&bitmap
)
406 virtual void SetMinWidth( int minWidth
) = 0;
407 virtual void SetWidth( int width
) = 0;
412 virtual wxString
GetTitle() const = 0;
413 virtual wxAlignment
GetAlignment() const = 0;
414 virtual int GetWidth() const = 0;
415 virtual int GetMinWidth() const = 0;
417 virtual int GetFlags() const;
419 virtual bool IsSortable() const = 0;
420 virtual bool IsResizeable() const = 0;
421 virtual bool IsHidden() const = 0;
422 virtual bool IsSortOrderAscending() const = 0;
424 const wxBitmap
&GetBitmap() const { return m_bitmap
; }
425 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
427 wxDataViewCtrl
*GetOwner() { return m_owner
; }
428 wxDataViewRenderer
* GetRenderer() { return m_renderer
; }
431 wxDataViewRenderer
*m_renderer
;
434 wxDataViewCtrl
*m_owner
;
437 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
440 // ---------------------------------------------------------
441 // wxDataViewCtrlBase
442 // ---------------------------------------------------------
444 #define wxDV_SINGLE 0x0000 // for convenience
445 #define wxDV_MULTIPLE 0x0001 // can select multiple items
447 #define wxDV_NO_HEADER 0x0002 // column titles not visible
448 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
449 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
451 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
454 wxDataViewCtrlBase();
455 virtual ~wxDataViewCtrlBase();
457 virtual bool AssociateModel( wxDataViewModel
*model
);
458 wxDataViewModel
* GetModel();
461 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
462 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
463 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
464 int flags
= wxDATAVIEW_COL_RESIZABLE
);
465 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
466 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
467 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
468 int flags
= wxDATAVIEW_COL_RESIZABLE
);
469 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
470 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
471 wxAlignment align
= wxALIGN_CENTER
,
472 int flags
= wxDATAVIEW_COL_RESIZABLE
);
473 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
474 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
475 wxAlignment align
= wxALIGN_CENTER
,
476 int flags
= wxDATAVIEW_COL_RESIZABLE
);
477 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
478 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
479 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
480 int flags
= wxDATAVIEW_COL_RESIZABLE
);
481 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
482 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
483 wxAlignment align
= wxALIGN_CENTER
,
484 int flags
= wxDATAVIEW_COL_RESIZABLE
);
485 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
486 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
487 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
488 int flags
= wxDATAVIEW_COL_RESIZABLE
);
489 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
490 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
491 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
492 int flags
= wxDATAVIEW_COL_RESIZABLE
);
493 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
494 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
495 wxAlignment align
= wxALIGN_CENTER
,
496 int flags
= wxDATAVIEW_COL_RESIZABLE
);
497 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
498 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
499 wxAlignment align
= wxALIGN_CENTER
,
500 int flags
= wxDATAVIEW_COL_RESIZABLE
);
501 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
502 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
503 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
504 int flags
= wxDATAVIEW_COL_RESIZABLE
);
505 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
506 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
507 wxAlignment align
= wxALIGN_CENTER
,
508 int flags
= wxDATAVIEW_COL_RESIZABLE
);
510 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
511 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
512 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
513 int flags
= wxDATAVIEW_COL_RESIZABLE
);
514 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
515 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
516 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
517 int flags
= wxDATAVIEW_COL_RESIZABLE
);
518 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
519 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
520 wxAlignment align
= wxALIGN_CENTER
,
521 int flags
= wxDATAVIEW_COL_RESIZABLE
);
522 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
523 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
524 wxAlignment align
= wxALIGN_CENTER
,
525 int flags
= wxDATAVIEW_COL_RESIZABLE
);
526 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
527 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
528 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
529 int flags
= wxDATAVIEW_COL_RESIZABLE
);
530 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
531 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
532 wxAlignment align
= wxALIGN_CENTER
,
533 int flags
= wxDATAVIEW_COL_RESIZABLE
);
534 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
535 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
536 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
537 int flags
= wxDATAVIEW_COL_RESIZABLE
);
538 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
539 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
540 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
541 int flags
= wxDATAVIEW_COL_RESIZABLE
);
542 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
543 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
544 wxAlignment align
= wxALIGN_CENTER
,
545 int flags
= wxDATAVIEW_COL_RESIZABLE
);
546 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
547 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
548 wxAlignment align
= wxALIGN_CENTER
,
549 int flags
= wxDATAVIEW_COL_RESIZABLE
);
550 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
551 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
552 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
553 int flags
= wxDATAVIEW_COL_RESIZABLE
);
554 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
555 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
556 wxAlignment align
= wxALIGN_CENTER
,
557 int flags
= wxDATAVIEW_COL_RESIZABLE
);
560 virtual bool PrependColumn( wxDataViewColumn
*col
);
561 virtual bool AppendColumn( wxDataViewColumn
*col
);
563 virtual unsigned int GetColumnCount() const = 0;
564 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
565 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
567 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
568 virtual bool ClearColumns() = 0;
570 void SetExpanderColumn( wxDataViewColumn
*col
)
571 { m_expander_column
= col
; DoSetExpanderColumn(); }
572 wxDataViewColumn
*GetExpanderColumn() const
573 { return m_expander_column
; }
575 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
577 void SetIndent( int indent
)
578 { m_indent
= indent
; DoSetIndent(); }
579 int GetIndent() const
582 virtual wxDataViewItem
GetSelection() const = 0;
583 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
584 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
585 virtual void Select( const wxDataViewItem
& item
) = 0;
586 virtual void Unselect( const wxDataViewItem
& item
) = 0;
587 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
589 virtual void SelectAll() = 0;
590 virtual void UnselectAll() = 0;
592 virtual void Expand( const wxDataViewItem
& item
) = 0;
593 virtual void Collapse( const wxDataViewItem
& item
) = 0;
595 virtual void EnsureVisible( const wxDataViewItem
& item
,
596 const wxDataViewColumn
*column
= NULL
) = 0;
597 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
598 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
601 virtual void DoSetExpanderColumn() = 0 ;
602 virtual void DoSetIndent() = 0;
605 wxDataViewModel
*m_model
;
606 wxDataViewColumn
*m_expander_column
;
610 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
613 // ----------------------------------------------------------------------------
614 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
615 // ----------------------------------------------------------------------------
617 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
620 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
621 : wxNotifyEvent(commandType
, winid
),
625 m_value(wxNullVariant
),
629 wxDataViewEvent(const wxDataViewEvent
& event
)
630 : wxNotifyEvent(event
),
631 m_item(event
.m_item
),
633 m_model(event
.m_model
),
634 m_value(event
.m_value
),
635 m_column(event
.m_column
)
638 wxDataViewItem
GetItem() const { return m_item
; }
639 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
641 int GetColumn() const { return m_col
; }
642 void SetColumn( int col
) { m_col
= col
; }
644 wxDataViewModel
* GetModel() const { return m_model
; }
645 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
647 const wxVariant
&GetValue() const { return m_value
; }
648 void SetValue( const wxVariant
&value
) { m_value
= value
; }
650 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
651 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
652 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
654 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
657 wxDataViewItem m_item
;
659 wxDataViewModel
*m_model
;
661 wxDataViewColumn
*m_column
;
664 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
667 BEGIN_DECLARE_EVENT_TYPES()
668 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, -1)
670 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, -1)
671 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, -1)
672 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, -1)
673 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, -1)
674 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, -1)
675 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, -1)
676 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, -1)
677 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, -1)
679 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, -1)
680 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, -1)
681 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, -1)
682 END_DECLARE_EVENT_TYPES()
684 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
686 #define wxDataViewEventHandler(func) \
687 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
689 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
690 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
692 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
694 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
695 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
696 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
697 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
698 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
699 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
700 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
701 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
703 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
704 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
705 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
707 #if defined(wxUSE_GENERICDATAVIEWCTRL)
708 #include "wx/generic/dataview.h"
709 #elif defined(__WXGTK20__)
710 #include "wx/gtk/dataview.h"
711 #elif defined(__WXMAC__)
712 #include "wx/mac/dataview.h"
714 #include "wx/generic/dataview.h"
717 // -------------------------------------
718 // wxDataViewSpinRenderer
719 // -------------------------------------
721 class wxDataViewSpinRenderer
: public wxDataViewCustomRenderer
724 wxDataViewSpinRenderer( int min
, int max
,
725 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
726 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
727 virtual bool HasEditorCtrl() { return true; }
728 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
729 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
730 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
731 virtual wxSize
GetSize() const;
732 virtual bool SetValue( const wxVariant
&value
);
733 virtual bool GetValue( wxVariant
&value
) const;
740 //-----------------------------------------------------------------------------
741 // wxDataViewTreeStore
742 //-----------------------------------------------------------------------------
744 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
747 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
748 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
749 virtual ~wxDataViewTreeStoreNode();
751 void SetText( const wxString
&text
)
753 wxString
GetText() const
755 void SetIcon( const wxIcon
&icon
)
757 const wxIcon
&GetIcon() const
759 void SetData( wxClientData
*data
)
760 { if (m_data
) delete m_data
; m_data
= data
; }
761 wxClientData
*GetData() const
764 wxDataViewItem
GetItem() const
765 { return wxDataViewItem( (void*) this ); }
767 virtual bool IsContainer()
770 wxDataViewTreeStoreNode
*GetParent()
774 wxDataViewTreeStoreNode
*m_parent
;
777 wxClientData
*m_data
;
780 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
781 class WXDLLIMPEXP_ADV
);
783 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
786 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
787 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
788 wxClientData
*data
= NULL
);
789 virtual ~wxDataViewTreeStoreContainerNode();
791 const wxDataViewTreeStoreNodeList
&GetChildren() const
792 { return m_children
; }
793 wxDataViewTreeStoreNodeList
&GetChildren()
794 { return m_children
; }
796 void SetExpandedIcon( const wxIcon
&icon
)
797 { m_iconExpanded
= icon
; }
798 const wxIcon
&GetExpandedIcon() const
799 { return m_iconExpanded
; }
801 virtual bool IsContainer()
805 wxDataViewTreeStoreNodeList m_children
;
806 wxIcon m_iconExpanded
;
809 //-----------------------------------------------------------------------------
811 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
814 wxDataViewTreeStore();
815 ~wxDataViewTreeStore();
817 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
818 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
819 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
820 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
821 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
822 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
824 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
825 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
826 wxClientData
*data
= NULL
);
827 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
828 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
829 wxClientData
*data
= NULL
);
830 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
831 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
832 wxClientData
*data
= NULL
);
834 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
835 int GetChildCount( const wxDataViewItem
& parent
) const;
837 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
838 wxString
GetItemText( const wxDataViewItem
& item
) const;
839 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
840 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
841 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
842 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
843 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
844 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
846 void DeleteItem( const wxDataViewItem
& item
);
847 void DeleteChildren( const wxDataViewItem
& item
);
848 void DeleteAllItems();
850 // implement base methods
852 virtual void GetValue( wxVariant
&variant
,
853 const wxDataViewItem
&item
, unsigned int col
) const;
854 virtual bool SetValue( const wxVariant
&variant
,
855 const wxDataViewItem
&item
, unsigned int col
);
856 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
857 virtual bool IsContainer( const wxDataViewItem
&item
) const;
858 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
860 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
861 unsigned int column
, bool ascending
);
863 virtual bool HasDefaultCompare() const
865 virtual unsigned int GetColumnCount() const
867 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
868 { return "wxDataViewIconText"; }
870 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
871 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
872 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
875 wxDataViewTreeStoreNode
*m_root
;
879 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
882 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
883 const wxPoint
& pos
= wxDefaultPosition
,
884 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
885 const wxValidator
& validator
= wxDefaultValidator
);
887 bool Create( wxWindow
*parent
, wxWindowID id
,
888 const wxPoint
& pos
= wxDefaultPosition
,
889 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
890 const wxValidator
& validator
= wxDefaultValidator
);
892 wxDataViewTreeStore
*GetStore()
893 { return (wxDataViewTreeStore
*) GetModel(); }
895 void OnExpand( wxDataViewCtrl
&event
);
896 void OnCollapse( wxDataViewCtrl
&event
);
899 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
903 #endif // wxUSE_DATAVIEWCTRL
906 // _WX_DATAVIEW_H_BASE_