2 /////////////////////////////////////////////////////////////////////////////
3 // Name: wx/osx/dataview.h
4 // Purpose: wxDataViewCtrl native implementation header for OSX
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_DATAVIEWCTRL_OSX_H_
12 #define _WX_DATAVIEWCTRL_OSX_H_
14 #ifdef __WXMAC_CLASSIC__
15 # error "Native wxDataViewCtrl for classic environment not defined. Please use generic control."
18 // --------------------------------------------------------
19 // Class declarations to mask native types
20 // --------------------------------------------------------
21 class wxDataViewColumnNativeData
; // class storing environment dependent data for the native implementation
22 class wxDataViewRendererNativeData
; // class storing environment dependent data for the native renderer
23 class wxDataViewWidgetImpl
; // class used as a common interface for carbon and cocoa implementation
25 // ---------------------------------------------------------
27 // ---------------------------------------------------------
28 class WXDLLIMPEXP_ADV wxDataViewRenderer
: public wxDataViewRendererBase
32 // constructors / destructor
34 wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
36 virtual ~wxDataViewRenderer();
39 // inherited methods from wxDataViewRendererBase
41 virtual int GetAlignment() const
45 virtual wxDataViewCellMode
GetMode() const
49 virtual bool GetValue(wxVariant
& value
) const
55 virtual void SetAlignment(int align
); // carbon: is always identical to the header alignment;
56 // cocoa: cell alignment is independent from header alignment
57 virtual void SetMode(wxDataViewCellMode mode
);
58 virtual bool SetValue(wxVariant
const& newValue
)
64 virtual void EnableEllipsize(wxEllipsizeMode mode
= wxELLIPSIZE_MIDDLE
);
65 virtual wxEllipsizeMode
GetEllipsizeMode() const;
70 wxVariant
const& GetValue() const
75 wxDataViewRendererNativeData
* GetNativeData() const
77 return m_NativeDataPtr
;
80 virtual bool MacRender() = 0; // a call to the native data browser function to render the data;
81 // returns true if the data value could be rendered, false otherwise
83 void SetNativeData(wxDataViewRendererNativeData
* newNativeDataPtr
);
87 // called when a value was edited by user
88 virtual void OSXOnCellChanged(const wxVariant
& value
,
89 const wxDataViewItem
& item
,
97 int m_alignment
; // contains the alignment flags
99 wxDataViewCellMode m_mode
; // storing the mode that determines how the cell is going to be shown
101 wxDataViewRendererNativeData
* m_NativeDataPtr
; // data used by implementation of the native renderer
103 wxVariant m_value
; // value that is going to be rendered
106 // wxWidget internal stuff
108 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
111 // ---------------------------------------------------------
112 // wxDataViewCustomRenderer
113 // ---------------------------------------------------------
114 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
118 // constructors / destructor
120 wxDataViewCustomRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
122 virtual ~wxDataViewCustomRenderer();
124 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
127 // methods handling render space
129 virtual wxSize
GetSize() const = 0;
132 // methods handling user actions
134 virtual bool Render(wxRect cell
, wxDC
* dc
, int state
) = 0;
136 virtual bool Activate( wxRect
WXUNUSED(cell
),
137 wxDataViewModel
*WXUNUSED(model
),
138 const wxDataViewItem
& WXUNUSED(item
),
139 unsigned int WXUNUSED(col
) )
142 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
143 wxRect
WXUNUSED(cell
),
144 wxDataViewModel
*WXUNUSED(model
),
145 const wxDataViewItem
& WXUNUSED(item
),
146 unsigned int WXUNUSED(col
) )
149 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
150 wxRect
WXUNUSED(cell
),
151 wxDataViewModel
*WXUNUSED(model
),
152 const wxDataViewItem
& WXUNUSED(item
),
153 unsigned int WXUNUSED(col
) )
157 // device context handling
159 virtual wxDC
* GetDC(); // creates a device context and keeps it
164 virtual bool MacRender();
166 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
173 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
178 // wxWidget internal stuff
180 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
183 // ---------------------------------------------------------
184 // wxDataViewTextRenderer
185 // ---------------------------------------------------------
187 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
191 // constructors / destructor
193 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
196 // inherited functions from wxDataViewRenderer
198 virtual bool MacRender();
202 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
205 // ---------------------------------------------------------
206 // wxDataViewBitmapRenderer
207 // ---------------------------------------------------------
209 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
213 // constructors / destructor
215 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
218 // inherited functions from wxDataViewRenderer
220 virtual bool MacRender();
224 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
227 #if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
229 // -------------------------------------
230 // wxDataViewChoiceRenderer
231 // -------------------------------------
232 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewRenderer
236 // constructors / destructor
238 wxDataViewChoiceRenderer(wxArrayString
const& choices
,
239 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
240 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
243 // inherited functions from wxDataViewRenderer
245 virtual bool MacRender();
250 wxString
GetChoice(size_t index
) const
252 return m_Choices
[index
];
254 wxArrayString
const& GetChoices() const
263 wxArrayString m_Choices
;
265 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer
)
270 // ---------------------------------------------------------
271 // wxDataViewIconTextRenderer
272 // ---------------------------------------------------------
273 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
276 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
279 // inherited functions from wxDataViewRenderer
281 virtual bool MacRender();
284 // called when a value was edited by user
285 virtual void OSXOnCellChanged(const wxVariant
& value
,
286 const wxDataViewItem
& item
,
292 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
295 // ---------------------------------------------------------
296 // wxDataViewToggleRenderer
297 // ---------------------------------------------------------
299 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
302 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
305 // inherited functions from wxDataViewRenderer
307 virtual bool MacRender();
311 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
314 // ---------------------------------------------------------
315 // wxDataViewProgressRenderer
316 // ---------------------------------------------------------
318 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
321 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
322 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
325 // inherited functions from wxDataViewRenderer
327 virtual bool MacRender();
331 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
334 // ---------------------------------------------------------
335 // wxDataViewDateRenderer
336 // ---------------------------------------------------------
338 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
341 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
344 // inherited functions from wxDataViewRenderer
346 virtual bool MacRender();
350 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
353 // ---------------------------------------------------------
355 // ---------------------------------------------------------
357 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
360 // constructors / destructor
361 wxDataViewColumn(const wxString
& title
,
362 wxDataViewRenderer
* renderer
,
363 unsigned int model_column
,
364 int width
= wxDVC_DEFAULT_WIDTH
,
365 wxAlignment align
= wxALIGN_CENTER
,
366 int flags
= wxDATAVIEW_COL_RESIZABLE
);
367 wxDataViewColumn(const wxBitmap
& bitmap
,
368 wxDataViewRenderer
* renderer
,
369 unsigned int model_column
,
370 int width
= wxDVC_DEFAULT_WIDTH
,
371 wxAlignment align
= wxALIGN_CENTER
,
372 int flags
= wxDATAVIEW_COL_RESIZABLE
);
373 virtual ~wxDataViewColumn();
375 // implement wxHeaderColumnBase pure virtual methods
376 virtual wxAlignment
GetAlignment() const { return m_alignment
; }
377 virtual int GetFlags() const { return m_flags
; }
378 virtual int GetMaxWidth() const { return m_maxWidth
; }
379 virtual int GetMinWidth() const { return m_minWidth
; }
380 virtual wxString
GetTitle() const { return m_title
; }
381 virtual int GetWidth() const { return m_width
; }
382 virtual bool IsHidden() const { return false; } // TODO
383 virtual bool IsSortOrderAscending() const { return m_ascending
; }
384 virtual bool IsSortKey() const;
386 virtual void SetAlignment (wxAlignment align
);
387 virtual void SetBitmap (wxBitmap
const& bitmap
);
388 virtual void SetFlags (int flags
) { SetIndividualFlags(flags
); }
389 virtual void SetHidden (bool WXUNUSED(hidden
)) { } // TODO
390 virtual void SetMaxWidth (int maxWidth
);
391 virtual void SetMinWidth (int minWidth
);
392 virtual void SetReorderable(bool reorderable
);
393 virtual void SetResizeable (bool resizeable
);
394 virtual void SetSortable (bool sortable
);
395 virtual void SetSortOrder (bool ascending
);
396 virtual void SetTitle (wxString
const& title
);
397 virtual void SetWidth (int width
);
398 virtual void SetAsSortKey (bool sort
= true);
400 // implementation only
401 wxDataViewColumnNativeData
* GetNativeData() const
403 return m_NativeDataPtr
;
406 void SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
); // class takes ownership of pointer
407 void SetWidthVariable(int NewWidth
)
411 void SetSortOrderVariable(bool NewOrder
)
413 m_ascending
= NewOrder
;
417 // common part of all ctors
418 void InitCommon(int width
, wxAlignment align
, int flags
)
421 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
424 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
428 bool m_ascending
; // sorting order
430 int m_flags
; // flags for the column
431 int m_maxWidth
; // maximum width for the column
432 int m_minWidth
; // minimum width for the column
433 int m_width
; // column width
435 wxAlignment m_alignment
; // column header alignment
437 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
439 wxString m_title
; // column title
443 // type definitions related to wxDataViewColumn
445 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
447 // ---------------------------------------------------------
449 // ---------------------------------------------------------
450 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
453 // Constructors / destructor:
458 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
459 const wxValidator
& validator
= wxDefaultValidator
)
462 Create(parent
, id
, pos
, size
, style
, validator
);
467 // explicit control creation
468 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
469 const wxValidator
& validator
=wxDefaultValidator
);
471 virtual wxControl
* GetMainWindow() // not used for the native implementation
476 // inherited methods from wxDataViewCtrlBase:
477 virtual bool AssociateModel(wxDataViewModel
* model
);
479 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
480 virtual bool ClearColumns ();
481 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
482 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
483 virtual unsigned int GetColumnCount () const;
484 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
485 virtual wxDataViewColumn
* GetSortingColumn () const;
486 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
487 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
489 virtual void Collapse( const wxDataViewItem
& item
);
490 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
491 virtual void Expand(const wxDataViewItem
& item
);
492 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
495 virtual unsigned int GetCount() const;
496 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
497 virtual wxDataViewItem
GetSelection() const;
498 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
500 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
502 virtual bool IsSelected(const wxDataViewItem
& item
) const;
504 virtual void SelectAll();
505 virtual void Select(const wxDataViewItem
& item
);
506 virtual void SetSelections(const wxDataViewItemArray
& sel
);
508 virtual void Unselect(const wxDataViewItem
& item
);
509 virtual void UnselectAll();
514 // returns a pointer to the native implementation
515 wxDataViewWidgetImpl
* GetDataViewPeer() const;
517 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
518 void AddChildren(wxDataViewItem
const& parentItem
);
520 // finishes editing of custom items; if no custom item is currently edited the method does nothing
521 void FinishCustomItemEditing();
523 // returns the n-th pointer to a column;
524 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
525 // position in the internal list/array of column pointers
526 wxDataViewColumn
* GetColumnPtr(size_t n
) const
528 return m_ColumnPtrs
[n
];
530 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
531 wxDataViewItem
const& GetCustomRendererItem() const
533 return m_CustomRendererItem
;
535 // returns a pointer to a customized renderer (this pointer is only valid during editing)
536 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
538 return m_CustomRendererPtr
;
541 // checks if currently a delete process is running
542 bool IsDeleting() const
547 // with CG, we need to get the context from an kEventControlDraw event
548 // unfortunately, the DataBrowser callbacks don't provide the context
549 // and we need it, so we need to set/remove it before and after draw
550 // events so we can access it in the callbacks.
551 void MacSetDrawingContext(void* context
)
553 m_cgContext
= context
;
555 void* MacGetDrawingContext() const
560 // sets the currently being edited item of the custom renderer
561 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
563 m_CustomRendererItem
= NewItem
;
565 // sets the custom renderer
566 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
568 m_CustomRendererPtr
= NewCustomRendererPtr
;
570 // sets the flag indicating a deletion process:
571 void SetDeleting(bool deleting
)
573 m_Deleting
= deleting
;
576 virtual wxVisualAttributes
GetDefaultAttributes() const
578 return GetClassDefaultAttributes(GetWindowVariant());
581 static wxVisualAttributes
582 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
585 // inherited methods from wxDataViewCtrlBase
586 virtual void DoSetExpanderColumn();
587 virtual void DoSetIndent();
589 virtual wxSize
DoGetBestSize() const;
592 void OnSize(wxSizeEvent
&event
);
593 void OnMouse(wxMouseEvent
&event
);
596 // 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, native callback functions/delegates may try to update data of variables that are already deleted;
604 // if this flag is set all native variable update requests will be ignored
606 void* m_cgContext
; // pointer to core graphics context
608 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
610 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
612 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
614 // wxWidget internal stuff:
615 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
616 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
617 DECLARE_EVENT_TABLE()
620 #endif // _WX_DATAVIEWCTRL_OSX_H_