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 // --------------------------------------------------------
14 // Type definitions to mask native types
15 // --------------------------------------------------------
17 typedef void* WXDataBrowserItemDataRef
;
18 typedef unsigned long WXDataBrowserPropertyType
;
19 typedef wxUint32 WXDataBrowserPropertyID
;
21 // ---------------------------------------------------------
23 // ---------------------------------------------------------
25 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
29 // constructors / destructor
31 wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
34 // inherited methods from wxDataViewRendererBase
36 virtual int GetAlignment(void) const
38 return this->m_alignment
;
40 virtual wxDataViewCellMode
GetMode(void) const
44 virtual bool GetValue(wxVariant
& value
) const
46 value
= this->m_value
;
50 virtual void SetAlignment(int WXUNUSED(align
)) // is always identical to the header alignment
53 virtual void SetMode(wxDataViewCellMode mode
);
54 virtual bool SetValue(wxVariant
const& newValue
)
56 this->m_value
= newValue
;
63 WXDataBrowserItemDataRef
GetDataReference(void) const
65 return this->m_dataReference
;
67 wxVariant
const& GetValue(void) const
72 virtual WXDataBrowserPropertyType
GetPropertyType(void) const = 0;
74 virtual bool Render(void) = 0; // a call to the appropriate data browser function filling the data reference with the stored datum;
75 // returns 'true' if the data value could be rendered, 'false' otherwise
77 void SetDataReference(WXDataBrowserItemDataRef
const& newDataReference
)
79 this->m_dataReference
= newDataReference
;
86 WXDataBrowserItemDataRef m_dataReference
; // data reference of the data browser; the data will be assigned to this reference during rendering
88 int m_alignment
; // contains the alignment flags
90 wxDataViewCellMode m_mode
; // storing the mode that determines how the cell is going to be shown
92 wxVariant m_value
; // value that is going to be rendered
95 // wxWidget internal stuff
97 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
100 // ---------------------------------------------------------
101 // wxDataViewCustomRenderer
102 // ---------------------------------------------------------
104 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
108 // constructors / destructor
110 wxDataViewCustomRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
112 virtual ~wxDataViewCustomRenderer(void);
114 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
117 // methods handling render space
119 virtual wxSize
GetSize() const = 0;
122 // methods handling user actions
124 virtual bool Render(wxRect cell
, wxDC
* dc
, int state
) = 0;
126 virtual bool Activate(wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
131 virtual bool LeftClick(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
136 virtual bool RightClick(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
141 virtual bool StartDrag(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
149 virtual void CancelEditing()
153 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
& WXUNUSED(value
))
158 virtual bool FinishEditing()
163 wxControl
* GetEditorCtrl(void) const
165 return this->m_editorCtrlPtr
;
167 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
), wxVariant
& WXUNUSED(value
))
172 virtual bool HasEditorCtrl(void)
177 virtual bool StartEditing(wxDataViewItem
const& WXUNUSED(item
), wxRect
WXUNUSED(labelRect
))
183 // device context handling
185 virtual wxDC
* GetDC(void); // creates a device context and keeps it
190 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
191 // return 'true' without having done anything
193 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
195 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
202 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
207 // wxWidget internal stuff
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
212 // ---------------------------------------------------------
213 // wxDataViewTextRenderer
214 // ---------------------------------------------------------
216 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
220 // constructors / destructor
222 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
225 // inherited functions from wxDataViewRenderer
227 virtual bool Render(void);
232 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
236 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
239 // ---------------------------------------------------------
240 // wxDataViewTextRendererAttr
241 // ---------------------------------------------------------
243 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
247 // constructors / destructor
249 wxDataViewTextRendererAttr(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
252 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
255 // ---------------------------------------------------------
256 // wxDataViewBitmapRenderer
257 // ---------------------------------------------------------
259 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
263 // constructors / destructor
265 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
268 // inherited functions from wxDataViewRenderer
270 virtual bool Render(void);
275 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
282 // ---------------------------------------------------------
283 // wxDataViewToggleRenderer
284 // ---------------------------------------------------------
286 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
289 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
292 // inherited functions from wxDataViewRenderer
294 virtual bool Render(void);
299 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
303 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
306 // ---------------------------------------------------------
307 // wxDataViewToggleRenderer
308 // ---------------------------------------------------------
310 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
313 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
316 // inherited functions from wxDataViewRenderer
318 virtual bool Render(void);
323 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
327 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
330 // ---------------------------------------------------------
331 // wxDataViewProgressRenderer
332 // ---------------------------------------------------------
334 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
337 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
338 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
341 // inherited functions from wxDataViewRenderer
343 virtual bool Render(void);
348 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
352 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
355 // ---------------------------------------------------------
356 // wxDataViewDateRenderer
357 // ---------------------------------------------------------
359 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
362 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
365 // inherited functions from wxDataViewRenderer
367 virtual bool Render(void);
372 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
376 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
379 // ---------------------------------------------------------
381 // ---------------------------------------------------------
383 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
387 // constructors / destructor
389 wxDataViewColumn(wxString
const& title
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
390 int flags
=wxDATAVIEW_COL_RESIZABLE
);
391 wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
392 int flags
=wxDATAVIEW_COL_RESIZABLE
);
395 // inherited methods from wxDataViewColumnBase
397 virtual wxAlignment
GetAlignment(void) const
399 return this->m_alignment
;
401 virtual int GetFlags(void) const
403 return this->m_flags
;
405 virtual int GetMaxWidth(void) const
407 return this->m_maxWidth
;
409 virtual int GetMinWidth(void) const
411 return this->m_minWidth
;
413 virtual wxString
GetTitle(void) const
415 return this->m_title
;
417 virtual int GetWidth(void) const
419 return this->m_width
;
422 virtual bool IsHidden(void) const
424 return false; // not implemented
426 virtual bool IsResizeable(void) const
428 return ((this->m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
430 virtual bool IsSortable(void) const
432 return ((this->m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
434 virtual bool IsSortOrderAscending(void) const
436 return this->m_ascending
;
439 virtual void SetAlignment(wxAlignment align
);
440 virtual void SetBitmap (wxBitmap
const& bitmap
);
441 virtual void SetFlags (int flags
);
442 virtual void SetHidden(bool WXUNUSED(hidden
))
445 virtual void SetMaxWidth (int maxWidth
);
446 virtual void SetMinWidth (int minWidth
);
447 virtual void SetResizeable(bool resizeable
);
448 virtual void SetSortable (bool sortable
);
449 virtual void SetSortOrder (bool ascending
);
450 virtual void SetTitle (wxString
const& title
);
451 virtual void SetWidth (int width
);
456 WXDataBrowserPropertyID
GetPropertyID() const
458 return this->m_propertyID
;
461 void SetPropertyID(WXDataBrowserPropertyID newID
)
463 this->m_propertyID
= newID
;
465 void SetWidthVariable(int NewWidth
)
467 this->m_width
= NewWidth
;
475 bool m_ascending
; // sorting order
477 WXDataBrowserPropertyID m_propertyID
; // each column is identified by its unique property ID (NOT by the column index)
479 int m_flags
; // flags for the column
480 int m_maxWidth
; // maximum width for the column
481 int m_minWidth
; // minimum width for the column
482 int m_width
; // column width
484 wxAlignment m_alignment
; // column header alignment
486 wxString m_title
; // column title
488 // wxWidget internal stuff:
489 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
492 // ---------------------------------------------------------
494 // ---------------------------------------------------------
495 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
498 // Constructors / destructor:
503 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
= wxDefaultPosition
, wxSize
const& size
= wxDefaultSize
, long style
= 0,
504 wxValidator
const& validator
= wxDefaultValidator
)
507 this->Create(parent
, id
, pos
, size
, style
, validator
);
510 // explicit control creation
511 bool Create(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
=wxDefaultPosition
, wxSize
const& size
=wxDefaultSize
, long style
=0,
512 wxValidator
const& validator
=wxDefaultValidator
);
514 virtual wxControl
* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
519 // inherited methods from 'wxDataViewCtrlBase':
520 virtual bool AssociateModel(wxDataViewModel
* model
);
522 virtual bool AppendColumn(wxDataViewColumn
* columnPtr
);
523 virtual bool ClearColumns(void);
524 virtual bool DeleteColumn(wxDataViewColumn
* columnPtr
);
525 virtual wxDataViewColumn
* GetColumn(unsigned int pos
) const;
526 virtual unsigned int GetColumnCount(void) const;
527 virtual int GetColumnPosition(wxDataViewColumn
const* columnPtr
) const;
528 virtual bool PrependColumn(wxDataViewColumn
* columnPtr
);
530 virtual void Collapse(wxDataViewItem
const& item
);
531 virtual void EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
=NULL
);
532 virtual void Expand(wxDataViewItem
const& item
);
534 virtual wxDataViewColumn
* GetSortingColumn(void) const;
536 virtual unsigned int GetCount(void) const;
537 virtual wxRect
GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const;
538 virtual wxDataViewItem
GetSelection(void) const;
539 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
541 virtual void HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
543 virtual bool IsSelected(wxDataViewItem
const& item
) const;
545 virtual void SelectAll(void);
546 virtual void Select(wxDataViewItem
const& item
);
547 virtual void SetSelections(wxDataViewItemArray
const& sel
);
549 virtual void Unselect(wxDataViewItem
const& item
);
550 virtual void UnselectAll(void);
556 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
557 void AddChildrenLevel(wxDataViewItem
const& parentItem
);
559 // returns a pointer to a column;
560 // in case the pointer cannot be found NULL is returned:
561 wxDataViewColumn
* GetColumnPtr(WXDataBrowserPropertyID propertyID
) const;
563 // checks if currently a delete process is running:
564 bool IsDeleting(void) const
566 return this->m_Deleting
;
569 // with CG, we need to get the context from an kEventControlDraw event
570 // unfortunately, the DataBrowser callbacks don't provide the context
571 // and we need it, so we need to set/remove it before and after draw
572 // events so we can access it in the callbacks.
573 void MacSetDrawingContext(void* context
)
575 this->m_cgContext
= context
;
577 void* MacGetDrawingContext(void) const
579 return this->m_cgContext
;
582 /// sets the flag indicating a deletion process:
583 void SetDeleting(bool deleting
)
585 this->m_Deleting
= deleting
;
589 // inherited methods from wxDataViewCtrlBase:
590 virtual void DoSetExpanderColumn(void);
591 virtual void DoSetIndent(void);
594 void OnSize(wxSizeEvent
&event
);
598 WX_DECLARE_HASH_MAP(WXDataBrowserPropertyID
,wxDataViewColumn
*,wxIntegerHash
,wxIntegerEqual
,ColumnPointerHashMapType
);
600 // initializing of local variables:
607 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
608 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
609 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
611 void* m_cgContext
; // pointer to core graphics context
613 ColumnPointerHashMapType m_ColumnPointers
; // all column pointers are stored in a hash map with the property ID as a key
615 // wxWidget internal stuff:
616 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
617 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
618 DECLARE_EVENT_TABLE()
622 #endif // _WX_MACCARBONDATAVIEWCTRL_H_