1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/carbon/dataview.h
3 // Purpose: wxDataViewCtrl native implementation header
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __MACCARBONDATAVIEWCTRL_H__
11 #define __MACCARBONDATAVIEWCTRL_H__
13 #include <Carbon/carbon.h>
16 #include "wx/object.h"
18 #include "wx/control.h"
19 #include "wx/scrolwin.h"
22 // ---------------------------------------------------------
24 // ---------------------------------------------------------
26 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
28 // ---------------------------------------------------------
30 // ---------------------------------------------------------
32 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
36 // constructors / destructor
38 wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
41 // inherited methods from wxDataViewRendererBase
43 virtual int GetAlignment(void) const
45 return this->m_alignment
;
47 virtual wxDataViewCellMode
GetMode(void) const
51 virtual bool GetValue(wxVariant
& value
) const
53 value
= this->m_value
;
57 virtual void SetAlignment(int WXUNUSED(align
)) // is always identical to the header alignment
60 virtual void SetMode(wxDataViewCellMode mode
);
61 virtual bool SetValue(wxVariant
const& newValue
)
63 this->m_value
= newValue
;
70 DataBrowserItemDataRef
GetDataReference(void) const
72 return this->m_dataReference
;
74 wxVariant
const& GetValue(void) const
79 virtual DataBrowserPropertyType
GetPropertyType(void) const = 0;
81 virtual bool Render(void) = 0; // a call to the appropriate data browser function filling the data reference with the stored datum;
82 // returns 'true' if the data value could be rendered, 'false' otherwise
84 void SetDataReference(DataBrowserItemDataRef
const& newDataReference
)
86 this->m_dataReference
= newDataReference
;
93 DataBrowserItemDataRef m_dataReference
; // data reference of the data browser; the data will be assigned to this reference during rendering
95 int m_alignment
; // contains the alignment flags
97 wxDataViewCellMode m_mode
; // storing the mode that determines how the cell is going to be shown
99 wxVariant m_value
; // value that is going to be rendered
102 // wxWidget internal stuff
104 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
107 // ---------------------------------------------------------
108 // wxDataViewCustomRenderer
109 // ---------------------------------------------------------
111 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
115 // constructors / destructor
117 wxDataViewCustomRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
119 virtual ~wxDataViewCustomRenderer(void);
121 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
124 // methods handling render space
126 virtual wxSize
GetSize() const = 0;
129 // methods handling user actions
131 virtual bool Render(wxRect cell
, wxDC
* dc
, int state
) = 0;
133 virtual bool Activate(wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
138 virtual bool LeftClick(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
143 virtual bool RightClick(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
148 virtual bool StartDrag(wxPoint
WXUNUSED(cursor
), wxRect
WXUNUSED(cell
), wxDataViewModel
*WXUNUSED(model
), unsigned int WXUNUSED(col
), unsigned int WXUNUSED(row
))
156 virtual void CancelEditing()
160 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
), wxRect
WXUNUSED(labelRect
), const wxVariant
& WXUNUSED(value
))
165 virtual bool FinishEditing()
170 wxControl
* GetEditorCtrl(void) const
172 return this->m_editorCtrlPtr
;
174 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
), wxVariant
& WXUNUSED(value
))
179 virtual bool HasEditorCtrl(void)
184 virtual bool StartEditing(wxDataViewItem
const& WXUNUSED(item
), wxRect
WXUNUSED(labelRect
))
190 // device context handling
192 virtual wxDC
* GetDC(void); // creates a device context and keeps it
197 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
198 // return 'true' without having done anything
200 virtual DataBrowserPropertyType
GetPropertyType(void) const
202 return kDataBrowserCustomType
;
205 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
212 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
217 // wxWidget internal stuff
219 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
222 // ---------------------------------------------------------
223 // wxDataViewTextRenderer
224 // ---------------------------------------------------------
226 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
230 // constructors / destructor
232 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
235 // inherited functions from wxDataViewRenderer
237 virtual bool Render(void);
242 virtual DataBrowserPropertyType
GetPropertyType(void) const
244 return kDataBrowserTextType
;
249 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
252 // ---------------------------------------------------------
253 // wxDataViewBitmapRenderer
254 // ---------------------------------------------------------
256 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
260 // constructors / destructor
262 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
265 // inherited functions from wxDataViewRenderer
267 virtual bool Render(void);
272 virtual DataBrowserPropertyType
GetPropertyType(void) const
274 return kDataBrowserIconType
;
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 DataBrowserPropertyType
GetPropertyType(void) const
301 return kDataBrowserIconAndTextType
;
306 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
309 // ---------------------------------------------------------
310 // wxDataViewToggleRenderer
311 // ---------------------------------------------------------
313 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
316 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
319 // inherited functions from wxDataViewRenderer
321 virtual bool Render(void);
326 virtual DataBrowserPropertyType
GetPropertyType(void) const
328 return kDataBrowserCheckboxType
;
333 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
336 // ---------------------------------------------------------
337 // wxDataViewProgressRenderer
338 // ---------------------------------------------------------
340 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
343 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
344 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
347 // inherited functions from wxDataViewRenderer
349 virtual bool Render(void);
354 virtual DataBrowserPropertyType
GetPropertyType(void) const
356 return kDataBrowserProgressBarType
;
361 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
364 // ---------------------------------------------------------
365 // wxDataViewDateRenderer
366 // ---------------------------------------------------------
368 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
371 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
374 // inherited functions from wxDataViewRenderer
376 virtual bool Render(void);
381 virtual DataBrowserPropertyType
GetPropertyType(void) const
383 return kDataBrowserDateTimeType
;
388 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
391 // ---------------------------------------------------------
393 // ---------------------------------------------------------
395 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
399 // constructors / destructor
401 wxDataViewColumn(wxString
const& title
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
402 int flags
=wxDATAVIEW_COL_RESIZABLE
);
403 wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
404 int flags
=wxDATAVIEW_COL_RESIZABLE
);
407 // inherited methods from wxDataViewColumnBase
409 virtual wxAlignment
GetAlignment(void) const
411 return this->m_alignment
;
413 virtual int GetFlags(void) const
415 return this->m_flags
;
417 virtual int GetMaxWidth(void) const
419 return this->m_maxWidth
;
421 virtual int GetMinWidth(void) const
423 return this->m_minWidth
;
425 virtual wxString
GetTitle(void) const
427 return this->m_title
;
429 virtual int GetWidth(void) const
431 return this->m_width
;
434 virtual bool IsHidden(void) const
436 return false; // not implemented
438 virtual bool IsResizeable(void) const
440 return ((this->m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
442 virtual bool IsSortable(void) const
444 return ((this->m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
446 virtual bool IsSortOrderAscending(void) const
448 return this->m_ascending
;
451 virtual void SetAlignment(wxAlignment align
);
452 virtual void SetBitmap (wxBitmap
const& bitmap
);
453 virtual void SetFlags (int flags
);
454 virtual void SetHidden(bool WXUNUSED(hidden
))
457 virtual void SetMaxWidth (int maxWidth
);
458 virtual void SetMinWidth (int minWidth
);
459 virtual void SetResizeable(bool resizeable
);
460 virtual void SetSortable (bool sortable
);
461 virtual void SetSortOrder (bool ascending
);
462 virtual void SetTitle (wxString
const& title
);
463 virtual void SetWidth (int width
);
468 DataBrowserPropertyID
GetPropertyID(void) const
470 return this->m_propertyID
;
473 void SetPropertyID(DataBrowserPropertyID newID
)
475 this->m_propertyID
= newID
;
477 void SetWidthVariable(int NewWidth
)
479 this->m_width
= NewWidth
;
487 bool m_ascending
; // sorting order
489 DataBrowserPropertyID m_propertyID
; // each column is identified by its unique property ID (NOT by the column index)
491 int m_flags
; // flags for the column
492 int m_maxWidth
; // maximum width for the column
493 int m_minWidth
; // minimum width for the column
494 int m_width
; // column width
496 wxAlignment m_alignment
; // column header alignment
498 wxString m_title
; // column title
500 // wxWidget internal stuff:
501 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
504 // ---------------------------------------------------------
506 // ---------------------------------------------------------
507 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
510 // Constructors / destructor:
515 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
= wxDefaultPosition
, wxSize
const& size
= wxDefaultSize
, long style
= 0,
516 wxValidator
const& validator
= wxDefaultValidator
)
519 this->Create(parent
, id
, pos
, size
, style
, validator
);
522 // explicit control creation
523 bool Create(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
=wxDefaultPosition
, wxSize
const& size
=wxDefaultSize
, long style
=0,
524 wxValidator
const& validator
=wxDefaultValidator
);
526 virtual wxControl
* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
531 // inherited methods from 'wxDataViewCtrlBase':
532 virtual bool AssociateModel(wxDataViewModel
* model
);
534 virtual bool AppendColumn(wxDataViewColumn
* columnPtr
);
535 virtual bool ClearColumns(void);
536 virtual bool DeleteColumn(wxDataViewColumn
* columnPtr
);
537 virtual wxDataViewColumn
* GetColumn(unsigned int pos
) const;
538 virtual unsigned int GetColumnCount(void) const;
539 virtual int GetColumnPosition(wxDataViewColumn
const* columnPtr
) const;
541 virtual void Collapse(wxDataViewItem
const& item
);
542 virtual void EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
=NULL
);
543 virtual void Expand(wxDataViewItem
const& item
);
545 virtual wxDataViewColumn
* GetSortingColumn(void) const;
547 virtual unsigned int GetCount(void) const;
548 virtual wxRect
GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const;
549 virtual wxDataViewItem
GetSelection(void) const;
550 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
552 virtual void HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
554 virtual bool IsSelected(wxDataViewItem
const& item
) const;
556 virtual void SelectAll(void);
557 virtual void Select(wxDataViewItem
const& item
);
558 virtual void SetSelections(wxDataViewItemArray
const& sel
);
560 virtual void Unselect(wxDataViewItem
const& item
);
561 virtual void UnselectAll(void);
567 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
568 void AddChildrenLevel(wxDataViewItem
const& parentItem
);
570 // returns a pointer to a column;
571 // in case the pointer cannot be found NULL is returned:
572 wxDataViewColumn
* GetColumnPtr(DataBrowserPropertyID propertyID
) const;
574 // checks if currently a delete process is running:
575 bool IsDeleting(void) const
577 return this->m_Deleting
;
580 // with CG, we need to get the context from an kEventControlDraw event
581 // unfortunately, the DataBrowser callbacks don't provide the context
582 // and we need it, so we need to set/remove it before and after draw
583 // events so we can access it in the callbacks.
584 void MacSetDrawingContext(void* context
)
586 this->m_cgContext
= context
;
588 void* MacGetDrawingContext(void) const
590 return this->m_cgContext
;
593 /// sets the flag indicating a deletion process:
594 void SetDeleting(bool deleting
)
596 this->m_Deleting
= deleting
;
600 // inherited methods from wxDataViewCtrlBase:
601 virtual void DoSetExpanderColumn(void);
602 virtual void DoSetIndent(void);
605 void OnSize(wxSizeEvent
&event
);
609 WX_DECLARE_HASH_MAP(DataBrowserPropertyID
,wxDataViewColumn
*,wxIntegerHash
,wxIntegerEqual
,ColumnPointerHashMapType
);
611 // initializing of local variables:
618 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
619 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
620 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
622 void* m_cgContext
; // pointer to core graphics context
624 ColumnPointerHashMapType m_ColumnPointers
; // all column pointers are stored in a hash map with the property ID as a key
626 // wxWidget internal stuff:
627 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
628 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
629 DECLARE_EVENT_TABLE()
633 #endif // __MACDATAVIEWCTRL_H__