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
)
67 wxVariant
const& GetValue() const
72 wxDataViewRendererNativeData
* GetNativeData() const
74 return m_NativeDataPtr
;
77 virtual bool MacRender() = 0; // a call to the native data browser function to render the data;
78 // returns true if the data value could be rendered, false otherwise
80 void SetNativeData(wxDataViewRendererNativeData
* newNativeDataPtr
);
86 int m_alignment
; // contains the alignment flags
88 wxDataViewCellMode m_mode
; // storing the mode that determines how the cell is going to be shown
90 wxDataViewRendererNativeData
* m_NativeDataPtr
; // data used by implementation of the native renderer
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 // ---------------------------------------------------------
103 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
107 // constructors / destructor
109 wxDataViewCustomRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
111 virtual ~wxDataViewCustomRenderer();
113 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
116 // methods handling render space
118 virtual wxSize
GetSize() const = 0;
121 // methods handling user actions
123 virtual bool Render(wxRect cell
, wxDC
* dc
, int state
) = 0;
125 virtual bool Activate( wxRect
WXUNUSED(cell
),
126 wxDataViewModel
*WXUNUSED(model
),
127 const wxDataViewItem
& WXUNUSED(item
),
128 unsigned int WXUNUSED(col
) )
131 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
132 wxRect
WXUNUSED(cell
),
133 wxDataViewModel
*WXUNUSED(model
),
134 const wxDataViewItem
& WXUNUSED(item
),
135 unsigned int WXUNUSED(col
) )
138 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
139 wxRect
WXUNUSED(cell
),
140 wxDataViewModel
*WXUNUSED(model
),
141 const wxDataViewItem
& WXUNUSED(item
),
142 unsigned int WXUNUSED(col
) )
146 // device context handling
148 virtual wxDC
* GetDC(); // creates a device context and keeps it
153 virtual bool MacRender();
155 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
162 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
167 // wxWidget internal stuff
169 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
172 // ---------------------------------------------------------
173 // wxDataViewTextRenderer
174 // ---------------------------------------------------------
176 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
180 // constructors / destructor
182 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
185 // inherited functions from wxDataViewRenderer
187 virtual bool MacRender();
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
194 // ---------------------------------------------------------
195 // wxDataViewBitmapRenderer
196 // ---------------------------------------------------------
198 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
202 // constructors / destructor
204 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
207 // inherited functions from wxDataViewRenderer
209 virtual bool MacRender();
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
216 #if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
218 // -------------------------------------
219 // wxDataViewChoiceRenderer
220 // -------------------------------------
221 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewRenderer
225 // constructors / destructor
227 wxDataViewChoiceRenderer(wxArrayString
const& choices
,
228 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
229 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
232 // inherited functions from wxDataViewRenderer
234 virtual bool MacRender();
239 wxString
GetChoice(size_t index
) const
241 return m_Choices
[index
];
243 wxArrayString
const& GetChoices() const
252 wxArrayString m_Choices
;
254 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer
)
259 // ---------------------------------------------------------
260 // wxDataViewIconTextRenderer
261 // ---------------------------------------------------------
262 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
265 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
268 // inherited functions from wxDataViewRenderer
270 virtual bool MacRender();
274 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
277 // ---------------------------------------------------------
278 // wxDataViewToggleRenderer
279 // ---------------------------------------------------------
281 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
284 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
287 // inherited functions from wxDataViewRenderer
289 virtual bool MacRender();
293 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
296 // ---------------------------------------------------------
297 // wxDataViewProgressRenderer
298 // ---------------------------------------------------------
300 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
303 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
304 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
307 // inherited functions from wxDataViewRenderer
309 virtual bool MacRender();
313 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
316 // ---------------------------------------------------------
317 // wxDataViewDateRenderer
318 // ---------------------------------------------------------
320 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
323 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
326 // inherited functions from wxDataViewRenderer
328 virtual bool MacRender();
332 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
335 // ---------------------------------------------------------
337 // ---------------------------------------------------------
339 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
342 // constructors / destructor
343 wxDataViewColumn(const wxString
& title
,
344 wxDataViewRenderer
* renderer
,
345 unsigned int model_column
,
346 int width
= wxDVC_DEFAULT_WIDTH
,
347 wxAlignment align
= wxALIGN_CENTER
,
348 int flags
= wxDATAVIEW_COL_RESIZABLE
);
349 wxDataViewColumn(const wxBitmap
& bitmap
,
350 wxDataViewRenderer
* renderer
,
351 unsigned int model_column
,
352 int width
= wxDVC_DEFAULT_WIDTH
,
353 wxAlignment align
= wxALIGN_CENTER
,
354 int flags
= wxDATAVIEW_COL_RESIZABLE
);
355 virtual ~wxDataViewColumn();
357 // implement wxHeaderColumnBase pure virtual methods
358 virtual wxAlignment
GetAlignment() const { return m_alignment
; }
359 virtual int GetFlags() const { return m_flags
; }
360 virtual int GetMaxWidth() const { return m_maxWidth
; }
361 virtual int GetMinWidth() const { return m_minWidth
; }
362 virtual wxString
GetTitle() const { return m_title
; }
363 virtual int GetWidth() const { return m_width
; }
364 virtual bool IsHidden() const { return false; } // TODO
365 virtual bool IsSortOrderAscending() const { return m_ascending
; }
366 virtual bool IsSortKey() const;
368 virtual void SetAlignment (wxAlignment align
);
369 virtual void SetBitmap (wxBitmap
const& bitmap
);
370 virtual void SetFlags (int flags
) { SetIndividualFlags(flags
); }
371 virtual void SetHidden (bool WXUNUSED(hidden
)) { } // TODO
372 virtual void SetMaxWidth (int maxWidth
);
373 virtual void SetMinWidth (int minWidth
);
374 virtual void SetReorderable(bool reorderable
);
375 virtual void SetResizeable (bool resizeable
);
376 virtual void SetSortable (bool sortable
);
377 virtual void SetSortOrder (bool ascending
);
378 virtual void SetTitle (wxString
const& title
);
379 virtual void SetWidth (int width
);
380 virtual void SetAsSortKey (bool sort
= true);
382 // implementation only
383 wxDataViewColumnNativeData
* GetNativeData() const
385 return m_NativeDataPtr
;
388 void SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
); // class takes ownership of pointer
389 void SetWidthVariable(int NewWidth
)
393 void SetSortOrderVariable(bool NewOrder
)
395 m_ascending
= NewOrder
;
399 // common part of all ctors
400 void InitCommon(int width
, wxAlignment align
, int flags
)
403 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
406 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
410 bool m_ascending
; // sorting order
412 int m_flags
; // flags for the column
413 int m_maxWidth
; // maximum width for the column
414 int m_minWidth
; // minimum width for the column
415 int m_width
; // column width
417 wxAlignment m_alignment
; // column header alignment
419 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
421 wxString m_title
; // column title
425 // type definitions related to wxDataViewColumn
427 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
429 // ---------------------------------------------------------
431 // ---------------------------------------------------------
432 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
435 // Constructors / destructor:
440 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
441 const wxValidator
& validator
= wxDefaultValidator
)
444 Create(parent
, id
, pos
, size
, style
, validator
);
449 // explicit control creation
450 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
451 const wxValidator
& validator
=wxDefaultValidator
);
453 virtual wxControl
* GetMainWindow() // not used for the native implementation
458 // inherited methods from wxDataViewCtrlBase:
459 virtual bool AssociateModel(wxDataViewModel
* model
);
461 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
462 virtual bool ClearColumns ();
463 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
464 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
465 virtual unsigned int GetColumnCount () const;
466 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
467 virtual wxDataViewColumn
* GetSortingColumn () const;
468 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
469 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
471 virtual void Collapse( const wxDataViewItem
& item
);
472 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
473 virtual void Expand(const wxDataViewItem
& item
);
474 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
477 virtual unsigned int GetCount() const;
478 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
479 virtual wxDataViewItem
GetSelection() const;
480 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
482 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
484 virtual bool IsSelected(const wxDataViewItem
& item
) const;
486 virtual void SelectAll();
487 virtual void Select(const wxDataViewItem
& item
);
488 virtual void SetSelections(const wxDataViewItemArray
& sel
);
490 virtual void Unselect(const wxDataViewItem
& item
);
491 virtual void UnselectAll();
496 // returns a pointer to the native implementation
497 wxDataViewWidgetImpl
* GetDataViewPeer() const;
499 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
500 void AddChildren(wxDataViewItem
const& parentItem
);
502 // finishes editing of custom items; if no custom item is currently edited the method does nothing
503 void FinishCustomItemEditing();
505 // returns the n-th pointer to a column;
506 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
507 // position in the internal list/array of column pointers
508 wxDataViewColumn
* GetColumnPtr(size_t n
) const
510 return m_ColumnPtrs
[n
];
512 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
513 wxDataViewItem
const& GetCustomRendererItem() const
515 return m_CustomRendererItem
;
517 // returns a pointer to a customized renderer (this pointer is only valid during editing)
518 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
520 return m_CustomRendererPtr
;
523 // checks if currently a delete process is running
524 bool IsDeleting() const
529 // with CG, we need to get the context from an kEventControlDraw event
530 // unfortunately, the DataBrowser callbacks don't provide the context
531 // and we need it, so we need to set/remove it before and after draw
532 // events so we can access it in the callbacks.
533 void MacSetDrawingContext(void* context
)
535 m_cgContext
= context
;
537 void* MacGetDrawingContext() const
542 // sets the currently being edited item of the custom renderer
543 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
545 m_CustomRendererItem
= NewItem
;
547 // sets the custom renderer
548 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
550 m_CustomRendererPtr
= NewCustomRendererPtr
;
552 // sets the flag indicating a deletion process:
553 void SetDeleting(bool deleting
)
555 m_Deleting
= deleting
;
558 virtual wxVisualAttributes
GetDefaultAttributes() const
560 return GetClassDefaultAttributes(GetWindowVariant());
563 static wxVisualAttributes
564 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
567 // inherited methods from wxDataViewCtrlBase
568 virtual void DoSetExpanderColumn();
569 virtual void DoSetIndent();
571 virtual wxSize
DoGetBestSize() const;
574 void OnSize(wxSizeEvent
&event
);
575 void OnMouse(wxMouseEvent
&event
);
578 // initializing of local variables:
584 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
585 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
586 // if this flag is set all native variable update requests will be ignored
588 void* m_cgContext
; // pointer to core graphics context
590 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
592 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
594 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
596 // wxWidget internal stuff:
597 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
598 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
599 DECLARE_EVENT_TABLE()
602 #endif // _WX_DATAVIEWCTRL_OSX_H_