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
),
127 wxDataViewModel
*WXUNUSED(model
),
128 const wxDataViewItem
& WXUNUSED(item
),
129 unsigned int WXUNUSED(col
) )
132 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
133 wxRect
WXUNUSED(cell
),
134 wxDataViewModel
*WXUNUSED(model
),
135 const wxDataViewItem
& WXUNUSED(item
),
136 unsigned int WXUNUSED(col
) )
139 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
140 wxRect
WXUNUSED(cell
),
141 wxDataViewModel
*WXUNUSED(model
),
142 const wxDataViewItem
& WXUNUSED(item
),
143 unsigned int WXUNUSED(col
) )
147 // device context handling
149 virtual wxDC
* GetDC(void); // creates a device context and keeps it
154 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
155 // return 'true' without having done anything
157 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
159 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
166 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
171 // wxWidget internal stuff
173 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
176 // ---------------------------------------------------------
177 // wxDataViewTextRenderer
178 // ---------------------------------------------------------
180 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
184 // constructors / destructor
186 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
189 // inherited functions from wxDataViewRenderer
191 virtual bool Render(void);
196 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
200 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
203 // ---------------------------------------------------------
204 // wxDataViewTextRendererAttr
205 // ---------------------------------------------------------
207 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
211 // constructors / destructor
213 wxDataViewTextRendererAttr(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
216 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
219 // ---------------------------------------------------------
220 // wxDataViewBitmapRenderer
221 // ---------------------------------------------------------
223 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
227 // constructors / destructor
229 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
232 // inherited functions from wxDataViewRenderer
234 virtual bool Render(void);
239 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
243 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
246 // ---------------------------------------------------------
247 // wxDataViewToggleRenderer
248 // ---------------------------------------------------------
250 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
253 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
256 // inherited functions from wxDataViewRenderer
258 virtual bool Render(void);
263 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
267 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
270 // ---------------------------------------------------------
271 // wxDataViewToggleRenderer
272 // ---------------------------------------------------------
274 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
277 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
280 // inherited functions from wxDataViewRenderer
282 virtual bool Render(void);
287 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
291 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
294 // ---------------------------------------------------------
295 // wxDataViewProgressRenderer
296 // ---------------------------------------------------------
298 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
301 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
302 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
305 // inherited functions from wxDataViewRenderer
307 virtual bool Render(void);
312 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
316 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
319 // ---------------------------------------------------------
320 // wxDataViewDateRenderer
321 // ---------------------------------------------------------
323 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
326 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
329 // inherited functions from wxDataViewRenderer
331 virtual bool Render(void);
336 virtual WXDataBrowserPropertyType
GetPropertyType(void) const;
340 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
343 // ---------------------------------------------------------
345 // ---------------------------------------------------------
347 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
351 // constructors / destructor
353 wxDataViewColumn(wxString
const& title
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
354 int flags
=wxDATAVIEW_COL_RESIZABLE
);
355 wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
=80, wxAlignment align
=wxALIGN_CENTER
,
356 int flags
=wxDATAVIEW_COL_RESIZABLE
);
359 // inherited methods from wxDataViewColumnBase
361 virtual wxAlignment
GetAlignment(void) const
363 return this->m_alignment
;
365 virtual int GetFlags(void) const
367 return this->m_flags
;
369 virtual int GetMaxWidth(void) const
371 return this->m_maxWidth
;
373 virtual int GetMinWidth(void) const
375 return this->m_minWidth
;
377 virtual wxString
GetTitle(void) const
379 return this->m_title
;
381 virtual int GetWidth(void) const
383 return this->m_width
;
386 virtual bool IsHidden(void) const
388 return false; // not implemented
390 virtual bool IsReorderable(void) const
392 return ((this->m_flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
394 virtual bool IsResizeable(void) const
396 return ((this->m_flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
398 virtual bool IsSortable(void) const
400 return ((this->m_flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
402 virtual bool IsSortOrderAscending(void) const
404 return this->m_ascending
;
407 virtual void SetAlignment(wxAlignment align
);
408 virtual void SetBitmap (wxBitmap
const& bitmap
);
409 virtual void SetFlags (int flags
);
410 virtual void SetHidden(bool WXUNUSED(hidden
))
413 virtual void SetMaxWidth (int maxWidth
);
414 virtual void SetMinWidth (int minWidth
);
415 virtual void SetReorderable(bool reorderable
);
416 virtual void SetResizeable (bool resizeable
);
417 virtual void SetSortable (bool sortable
);
418 virtual void SetSortOrder (bool ascending
);
419 virtual void SetTitle (wxString
const& title
);
420 virtual void SetWidth (int width
);
425 WXDataBrowserPropertyID
GetPropertyID() const
427 return this->m_propertyID
;
430 void SetPropertyID(WXDataBrowserPropertyID newID
)
432 this->m_propertyID
= newID
;
434 void SetWidthVariable(int NewWidth
)
436 this->m_width
= NewWidth
;
444 bool m_ascending
; // sorting order
446 WXDataBrowserPropertyID m_propertyID
; // each column is identified by its unique property ID (NOT by the column index)
448 int m_flags
; // flags for the column
449 int m_maxWidth
; // maximum width for the column
450 int m_minWidth
; // minimum width for the column
451 int m_width
; // column width
453 wxAlignment m_alignment
; // column header alignment
455 wxString m_title
; // column title
457 // wxWidget internal stuff:
458 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn
)
461 // ---------------------------------------------------------
463 // ---------------------------------------------------------
464 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
467 // Constructors / destructor:
472 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
= wxDefaultPosition
, wxSize
const& size
= wxDefaultSize
, long style
= 0,
473 wxValidator
const& validator
= wxDefaultValidator
)
476 this->Create(parent
, id
, pos
, size
, style
, validator
);
479 // explicit control creation
480 bool Create(wxWindow
*parent
, wxWindowID id
, wxPoint
const& pos
=wxDefaultPosition
, wxSize
const& size
=wxDefaultSize
, long style
=0,
481 wxValidator
const& validator
=wxDefaultValidator
);
483 virtual wxControl
* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
488 // inherited methods from 'wxDataViewCtrlBase':
489 virtual bool AssociateModel(wxDataViewModel
* model
);
491 virtual bool AppendColumn(wxDataViewColumn
* columnPtr
);
492 virtual bool ClearColumns(void);
493 virtual bool DeleteColumn(wxDataViewColumn
* columnPtr
);
494 virtual wxDataViewColumn
* GetColumn(unsigned int pos
) const;
495 virtual unsigned int GetColumnCount(void) const;
496 virtual int GetColumnPosition(wxDataViewColumn
const* columnPtr
) const;
497 virtual bool PrependColumn(wxDataViewColumn
* columnPtr
);
499 virtual void Collapse(wxDataViewItem
const& item
);
500 virtual void EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
=NULL
);
501 virtual void Expand(wxDataViewItem
const& item
);
503 virtual wxDataViewColumn
* GetSortingColumn(void) const;
505 virtual unsigned int GetCount(void) const;
506 virtual wxRect
GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const;
507 virtual wxDataViewItem
GetSelection(void) const;
508 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
510 virtual void HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
512 virtual bool IsSelected(wxDataViewItem
const& item
) const;
514 virtual void SelectAll(void);
515 virtual void Select(wxDataViewItem
const& item
);
516 virtual void SetSelections(wxDataViewItemArray
const& sel
);
518 virtual void Unselect(wxDataViewItem
const& item
);
519 virtual void UnselectAll(void);
525 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
526 void AddChildrenLevel(wxDataViewItem
const& parentItem
);
528 // finishes editing of custom items; if no custom item is currently edited the method does nothing
529 void FinishCustomItemEditing(void);
531 // returns a pointer to a column;
532 // in case the pointer cannot be found NULL is returned:
533 wxDataViewColumn
* GetColumnPtr(WXDataBrowserPropertyID propertyID
) const;
534 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
535 wxDataViewItem
const& GetCustomRendererItem(void) const
537 return this->m_CustomRendererItem
;
539 // returns a pointer to a customized renderer (this pointer is only valid during editing)
540 wxDataViewCustomRenderer
* GetCustomRendererPtr(void) const
542 return this->m_CustomRendererPtr
;
545 // checks if currently a delete process is running:
546 bool IsDeleting(void) const
548 return this->m_Deleting
;
551 // with CG, we need to get the context from an kEventControlDraw event
552 // unfortunately, the DataBrowser callbacks don't provide the context
553 // and we need it, so we need to set/remove it before and after draw
554 // events so we can access it in the callbacks.
555 void MacSetDrawingContext(void* context
)
557 this->m_cgContext
= context
;
559 void* MacGetDrawingContext(void) const
561 return this->m_cgContext
;
564 // sets the currently being edited item of the custom renderer
565 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
567 this->m_CustomRendererItem
= NewItem
;
569 // sets the custom renderer
570 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
572 this->m_CustomRendererPtr
= NewCustomRendererPtr
;
574 // sets the flag indicating a deletion process:
575 void SetDeleting(bool deleting
)
577 this->m_Deleting
= deleting
;
580 virtual wxVisualAttributes
GetDefaultAttributes() const
582 return GetClassDefaultAttributes(GetWindowVariant());
585 static wxVisualAttributes
586 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
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 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
615 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customerenderer; it is invalid while not editing
617 ColumnPointerHashMapType m_ColumnPointers
; // all column pointers are stored in a hash map with the property ID as a key
619 // wxWidget internal stuff:
620 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
621 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
622 DECLARE_EVENT_TABLE()
626 #endif // _WX_MACCARBONDATAVIEWCTRL_H_