1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/carbon/dataview.h
3 // Purpose: wxDataViewCtrl native implementation header
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_MACCARBONDATAVIEWCTRL_H_
11 #define _WX_MACCARBONDATAVIEWCTRL_H_
13 typedef void* DataBrowserItemDataRef
;
14 typedef unsigned long WXDataBrowserPropertyType
;
15 typedef wxUint32 WXDataBrowserPropertyID
;
17 // ---------------------------------------------------------
19 // ---------------------------------------------------------
21 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
25 // constructors / destructor
27 wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
30 // inherited methods from wxDataViewRendererBase
32 virtual int GetAlignment(void) const
34 return this->m_alignment
;
36 virtual wxDataViewCellMode
GetMode(void) const
40 virtual bool GetValue(wxVariant
& value
) const
42 value
= this->m_value
;
46 virtual void SetAlignment(int WXUNUSED(align
)) // is always identical to the header alignment
49 virtual void SetMode(wxDataViewCellMode mode
);
50 virtual bool SetValue(wxVariant
const& newValue
)
52 this->m_value
= newValue
;
59 DataBrowserItemDataRef
GetDataReference(void) const
61 return this->m_dataReference
;
63 wxVariant
const& GetValue(void) const
68 virtual WXDataBrowserPropertyType
GetPropertyType() const = 0;
70 virtual bool Render(void) = 0; // a call to the appropriate data browser function filling the data reference with the stored datum;
71 // returns 'true' if the data value could be rendered, 'false' otherwise
73 void SetDataReference(DataBrowserItemDataRef
const& newDataReference
)
75 this->m_dataReference
= newDataReference
;
82 DataBrowserItemDataRef m_dataReference
; // data reference of the data browser; the data will be assigned to this reference during rendering
84 int m_alignment
; // contains the alignment flags
86 wxDataViewCellMode m_mode
; // storing the mode that determines how the cell is going to be shown
88 wxVariant m_value
; // value that is going to be rendered
91 // wxWidget internal stuff
93 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
96 // ---------------------------------------------------------
97 // wxDataViewCustomRenderer
98 // ---------------------------------------------------------
100 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
104 // constructors / destructor
106 wxDataViewCustomRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
108 virtual ~wxDataViewCustomRenderer(void);
110 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
113 // methods handling render space
115 virtual wxSize
GetSize() const = 0;
118 // methods handling user actions
120 virtual bool Render(wxRect cell
, wxDC
* dc
, int state
) = 0;
122 virtual bool Activate(wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
127 virtual bool LeftClick(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
132 virtual bool RightClick(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
137 virtual bool StartDrag(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
145 virtual void CancelEditing()
149 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
& WXUNUSED(value
))
154 virtual bool FinishEditing()
159 wxControl
* GetEditorCtrl(void) const
161 return this->m_editorCtrlPtr
;
163 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
), wxVariant
& WXUNUSED(value
))
168 virtual bool HasEditorCtrl(void)
173 virtual bool StartEditing(wxDataViewItem
const& WXUNUSED(item
), wxRect
WXUNUSED(labelRect
))
179 // device context handling
181 virtual wxDC
* GetDC(void); // creates a device context and keeps it
186 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
187 // return 'true' without having done anything
189 virtual WXDataBrowserPropertyType
GetPropertyType() const;
191 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
198 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
203 // wxWidget internal stuff
205 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
208 // ---------------------------------------------------------
209 // wxDataViewTextRenderer
210 // ---------------------------------------------------------
212 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
216 // constructors / destructor
218 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
221 // inherited functions from wxDataViewRenderer
223 virtual bool Render(void);
228 virtual WXDataBrowserPropertyType
GetPropertyType() const;
232 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
235 // ---------------------------------------------------------
236 // wxDataViewTextRendererAttr
237 // ---------------------------------------------------------
239 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
243 // constructors / destructor
245 wxDataViewTextRendererAttr(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
248 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
251 // ---------------------------------------------------------
252 // wxDataViewBitmapRenderer
253 // ---------------------------------------------------------
255 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
259 // constructors / destructor
261 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
264 // inherited functions from wxDataViewRenderer
266 virtual bool Render(void);
271 virtual WXDataBrowserPropertyType
GetPropertyType() const;
275 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
278 // ---------------------------------------------------------
279 // wxDataViewToggleRenderer
280 // ---------------------------------------------------------
282 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
285 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
288 // inherited functions from wxDataViewRenderer
290 virtual bool Render(void);
295 virtual WXDataBrowserPropertyType
GetPropertyType() const;
299 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
302 // ---------------------------------------------------------
303 // wxDataViewToggleRenderer
304 // ---------------------------------------------------------
306 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
309 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
312 // inherited functions from wxDataViewRenderer
314 virtual bool Render(void);
319 virtual WXDataBrowserPropertyType
GetPropertyType() const;
323 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
326 // ---------------------------------------------------------
327 // wxDataViewProgressRenderer
328 // ---------------------------------------------------------
330 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
333 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
334 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
337 // inherited functions from wxDataViewRenderer
339 virtual bool Render(void);
344 virtual WXDataBrowserPropertyType
GetPropertyType() const;
348 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
351 // ---------------------------------------------------------
352 // wxDataViewDateRenderer
353 // ---------------------------------------------------------
355 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
358 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
361 // inherited functions from wxDataViewRenderer
363 virtual bool Render(void);
368 virtual WXDataBrowserPropertyType
GetPropertyType() const;
372 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
375 // ---------------------------------------------------------
377 // ---------------------------------------------------------
379 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
383 // constructors / destructor
385 wxDataViewColumn(wxString
const& title
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
386 int flags
=wxDATAVIEW_COL_RESIZABLE
);
387 wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
388 int flags
=wxDATAVIEW_COL_RESIZABLE
);
391 // inherited methods from wxDataViewColumnBase
393 virtual wxAlignment
GetAlignment(void) const
395 return this->m_alignment
;
397 virtual int GetFlags(void) const
399 return this->m_flags
;
401 virtual int GetMaxWidth(void) const
403 return this->m_maxWidth
;
405 virtual int GetMinWidth(void) const
407 return this->m_minWidth
;
409 virtual wxString
GetTitle(void) const
411 return this->m_title
;
413 virtual int GetWidth(void) const
415 return this->m_width
;
418 virtual bool IsHidden(void) const
420 return false; // not implemented
422 virtual bool IsResizeable(void) const
424 return ((this->m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
426 virtual bool IsSortable(void) const
428 return ((this->m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
430 virtual bool IsSortOrderAscending(void) const
432 return this->m_ascending
;
435 virtual void SetAlignment(wxAlignment align
);
436 virtual void SetBitmap (wxBitmap
const& bitmap
);
437 virtual void SetFlags (int flags
);
438 virtual void SetHidden(bool WXUNUSED(hidden
))
441 virtual void SetMaxWidth (int maxWidth
);
442 virtual void SetMinWidth (int minWidth
);
443 virtual void SetResizeable(bool resizeable
);
444 virtual void SetSortable (bool sortable
);
445 virtual void SetSortOrder (bool ascending
);
446 virtual void SetTitle (wxString
const& title
);
447 virtual void SetWidth (int width
);
452 WXDataBrowserPropertyID
GetPropertyID() const
454 return this->m_propertyID
;
457 void SetPropertyID(WXDataBrowserPropertyID newID
)
459 this->m_propertyID
= newID
;
461 void SetWidthVariable(int NewWidth
)
463 this->m_width
= NewWidth
;
471 bool m_ascending
; // sorting order
473 WXDataBrowserPropertyID m_propertyID
; // each column is identified by its unique property ID (NOT by the column index)
475 int m_flags
; // flags for the column
476 int m_maxWidth
; // maximum width for the column
477 int m_minWidth
; // minimum width for the column
478 int m_width
; // column width
480 wxAlignment m_alignment
; // column header alignment
482 wxString m_title
; // column title
484 // wxWidget internal stuff:
485 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
488 // ---------------------------------------------------------
490 // ---------------------------------------------------------
491 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
494 // Constructors / destructor:
499 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
= wxDefaultPosition
, wxSize
const& size
= wxDefaultSize
, long style
= 0,
500 wxValidator
const& validator
= wxDefaultValidator
)
503 this->Create(parent
, id
, pos
, size
, style
, validator
);
506 // explicit control creation
507 bool Create(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
=wxDefaultPosition
, wxSize
const& size
=wxDefaultSize
, long style
=0,
508 wxValidator
const& validator
=wxDefaultValidator
);
510 virtual wxControl
* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
515 // inherited methods from 'wxDataViewCtrlBase':
516 virtual bool AssociateModel(wxDataViewModel
* model
);
518 virtual bool AppendColumn(wxDataViewColumn
* columnPtr
);
519 virtual bool ClearColumns(void);
520 virtual bool DeleteColumn(wxDataViewColumn
* columnPtr
);
521 virtual wxDataViewColumn
* GetColumn(unsigned int pos
) const;
522 virtual unsigned int GetColumnCount(void) const;
523 virtual int GetColumnPosition(wxDataViewColumn
const* columnPtr
) const;
525 virtual void Collapse(wxDataViewItem
const& item
);
526 virtual void EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
=NULL
);
527 virtual void Expand(wxDataViewItem
const& item
);
529 virtual wxDataViewColumn
* GetSortingColumn(void) const;
531 virtual unsigned int GetCount(void) const;
532 virtual wxRect
GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const;
533 virtual wxDataViewItem
GetSelection(void) const;
534 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
536 virtual void HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
538 virtual bool IsSelected(wxDataViewItem
const& item
) const;
540 virtual void SelectAll(void);
541 virtual void Select(wxDataViewItem
const& item
);
542 virtual void SetSelections(wxDataViewItemArray
const& sel
);
544 virtual void Unselect(wxDataViewItem
const& item
);
545 virtual void UnselectAll(void);
551 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
552 void AddChildrenLevel(wxDataViewItem
const& parentItem
);
554 // returns a pointer to a column;
555 // in case the pointer cannot be found NULL is returned:
556 wxDataViewColumn
* GetColumnPtr(WXDataBrowserPropertyID propertyID
) const;
558 // checks if currently a delete process is running:
559 bool IsDeleting(void) const
561 return this->m_Deleting
;
564 // with CG, we need to get the context from an kEventControlDraw event
565 // unfortunately, the DataBrowser callbacks don't provide the context
566 // and we need it, so we need to set/remove it before and after draw
567 // events so we can access it in the callbacks.
568 void MacSetDrawingContext(void* context
)
570 this->m_cgContext
= context
;
572 void* MacGetDrawingContext(void) const
574 return this->m_cgContext
;
577 /// sets the flag indicating a deletion process:
578 void SetDeleting(bool deleting
)
580 this->m_Deleting
= deleting
;
584 // inherited methods from wxDataViewCtrlBase:
585 virtual void DoSetExpanderColumn(void);
586 virtual void DoSetIndent(void);
589 void OnSize(wxSizeEvent
&event
);
593 WX_DECLARE_HASH_MAP(WXDataBrowserPropertyID
,wxDataViewColumn
*,wxIntegerHash
,wxIntegerEqual
,ColumnPointerHashMapType
);
595 // initializing of local variables:
602 bool m_Deleting
; // flag indicating if a delete process is running; this flag is necessary because the notifier indicating an item deletion in the model may be called
603 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
604 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
606 void* m_cgContext
; // pointer to core graphics context
608 ColumnPointerHashMapType m_ColumnPointers
; // all column pointers are stored in a hash map with the property ID as a key
610 // wxWidget internal stuff:
611 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
612 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
613 DECLARE_EVENT_TABLE()
617 #endif // _WX_MACCARBONDATAVIEWCTRL_H_