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 // wxDataViewBitmapRenderer
237 // ---------------------------------------------------------
239 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
243 // constructors / destructor
245 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
248 // inherited functions from wxDataViewRenderer
250 virtual bool Render(void);
255 virtual WXDataBrowserPropertyType
GetPropertyType() const;
259 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
262 // ---------------------------------------------------------
263 // wxDataViewToggleRenderer
264 // ---------------------------------------------------------
266 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
269 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
272 // inherited functions from wxDataViewRenderer
274 virtual bool Render(void);
279 virtual WXDataBrowserPropertyType
GetPropertyType() const;
283 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
286 // ---------------------------------------------------------
287 // wxDataViewToggleRenderer
288 // ---------------------------------------------------------
290 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
293 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
296 // inherited functions from wxDataViewRenderer
298 virtual bool Render(void);
303 virtual WXDataBrowserPropertyType
GetPropertyType() const;
307 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
310 // ---------------------------------------------------------
311 // wxDataViewProgressRenderer
312 // ---------------------------------------------------------
314 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
317 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
318 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
321 // inherited functions from wxDataViewRenderer
323 virtual bool Render(void);
328 virtual WXDataBrowserPropertyType
GetPropertyType() const;
332 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
335 // ---------------------------------------------------------
336 // wxDataViewDateRenderer
337 // ---------------------------------------------------------
339 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
342 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
345 // inherited functions from wxDataViewRenderer
347 virtual bool Render(void);
352 virtual WXDataBrowserPropertyType
GetPropertyType() const;
356 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
359 // ---------------------------------------------------------
361 // ---------------------------------------------------------
363 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
367 // constructors / destructor
369 wxDataViewColumn(wxString
const& title
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
370 int flags
=wxDATAVIEW_COL_RESIZABLE
);
371 wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
372 int flags
=wxDATAVIEW_COL_RESIZABLE
);
375 // inherited methods from wxDataViewColumnBase
377 virtual wxAlignment
GetAlignment(void) const
379 return this->m_alignment
;
381 virtual int GetFlags(void) const
383 return this->m_flags
;
385 virtual int GetMaxWidth(void) const
387 return this->m_maxWidth
;
389 virtual int GetMinWidth(void) const
391 return this->m_minWidth
;
393 virtual wxString
GetTitle(void) const
395 return this->m_title
;
397 virtual int GetWidth(void) const
399 return this->m_width
;
402 virtual bool IsHidden(void) const
404 return false; // not implemented
406 virtual bool IsResizeable(void) const
408 return ((this->m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
410 virtual bool IsSortable(void) const
412 return ((this->m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
414 virtual bool IsSortOrderAscending(void) const
416 return this->m_ascending
;
419 virtual void SetAlignment(wxAlignment align
);
420 virtual void SetBitmap (wxBitmap
const& bitmap
);
421 virtual void SetFlags (int flags
);
422 virtual void SetHidden(bool WXUNUSED(hidden
))
425 virtual void SetMaxWidth (int maxWidth
);
426 virtual void SetMinWidth (int minWidth
);
427 virtual void SetResizeable(bool resizeable
);
428 virtual void SetSortable (bool sortable
);
429 virtual void SetSortOrder (bool ascending
);
430 virtual void SetTitle (wxString
const& title
);
431 virtual void SetWidth (int width
);
436 WXDataBrowserPropertyID
GetPropertyID() const
438 return this->m_propertyID
;
441 void SetPropertyID(WXDataBrowserPropertyID newID
)
443 this->m_propertyID
= newID
;
445 void SetWidthVariable(int NewWidth
)
447 this->m_width
= NewWidth
;
455 bool m_ascending
; // sorting order
457 WXDataBrowserPropertyID m_propertyID
; // each column is identified by its unique property ID (NOT by the column index)
459 int m_flags
; // flags for the column
460 int m_maxWidth
; // maximum width for the column
461 int m_minWidth
; // minimum width for the column
462 int m_width
; // column width
464 wxAlignment m_alignment
; // column header alignment
466 wxString m_title
; // column title
468 // wxWidget internal stuff:
469 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
472 // ---------------------------------------------------------
474 // ---------------------------------------------------------
475 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
478 // Constructors / destructor:
483 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
= wxDefaultPosition
, wxSize
const& size
= wxDefaultSize
, long style
= 0,
484 wxValidator
const& validator
= wxDefaultValidator
)
487 this->Create(parent
, id
, pos
, size
, style
, validator
);
490 // explicit control creation
491 bool Create(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
=wxDefaultPosition
, wxSize
const& size
=wxDefaultSize
, long style
=0,
492 wxValidator
const& validator
=wxDefaultValidator
);
494 virtual wxControl
* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
499 // inherited methods from 'wxDataViewCtrlBase':
500 virtual bool AssociateModel(wxDataViewModel
* model
);
502 virtual bool AppendColumn(wxDataViewColumn
* columnPtr
);
503 virtual bool ClearColumns(void);
504 virtual bool DeleteColumn(wxDataViewColumn
* columnPtr
);
505 virtual wxDataViewColumn
* GetColumn(unsigned int pos
) const;
506 virtual unsigned int GetColumnCount(void) const;
507 virtual int GetColumnPosition(wxDataViewColumn
const* columnPtr
) const;
509 virtual void Collapse(wxDataViewItem
const& item
);
510 virtual void EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
=NULL
);
511 virtual void Expand(wxDataViewItem
const& item
);
513 virtual wxDataViewColumn
* GetSortingColumn(void) const;
515 virtual unsigned int GetCount(void) const;
516 virtual wxRect
GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const;
517 virtual wxDataViewItem
GetSelection(void) const;
518 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
520 virtual void HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
522 virtual bool IsSelected(wxDataViewItem
const& item
) const;
524 virtual void SelectAll(void);
525 virtual void Select(wxDataViewItem
const& item
);
526 virtual void SetSelections(wxDataViewItemArray
const& sel
);
528 virtual void Unselect(wxDataViewItem
const& item
);
529 virtual void UnselectAll(void);
535 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
536 void AddChildrenLevel(wxDataViewItem
const& parentItem
);
538 // returns a pointer to a column;
539 // in case the pointer cannot be found NULL is returned:
540 wxDataViewColumn
* GetColumnPtr(WXDataBrowserPropertyID propertyID
) const;
542 // checks if currently a delete process is running:
543 bool IsDeleting(void) const
545 return this->m_Deleting
;
548 // with CG, we need to get the context from an kEventControlDraw event
549 // unfortunately, the DataBrowser callbacks don't provide the context
550 // and we need it, so we need to set/remove it before and after draw
551 // events so we can access it in the callbacks.
552 void MacSetDrawingContext(void* context
)
554 this->m_cgContext
= context
;
556 void* MacGetDrawingContext(void) const
558 return this->m_cgContext
;
561 /// sets the flag indicating a deletion process:
562 void SetDeleting(bool deleting
)
564 this->m_Deleting
= deleting
;
568 // inherited methods from wxDataViewCtrlBase:
569 virtual void DoSetExpanderColumn(void);
570 virtual void DoSetIndent(void);
573 void OnSize(wxSizeEvent
&event
);
577 WX_DECLARE_HASH_MAP(WXDataBrowserPropertyID
,wxDataViewColumn
*,wxIntegerHash
,wxIntegerEqual
,ColumnPointerHashMapType
);
579 // initializing of local variables:
586 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
587 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
588 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
590 void* m_cgContext
; // pointer to core graphics context
592 ColumnPointerHashMapType m_ColumnPointers
; // all column pointers are stored in a hash map with the property ID as a key
594 // wxWidget internal stuff:
595 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
596 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
597 DECLARE_EVENT_TABLE()
601 #endif // _WX_MACCARBONDATAVIEWCTRL_H_