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(NSObject
*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();
201 virtual void OSXOnCellChanged(NSObject
*value
,
202 const wxDataViewItem
& item
,
207 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
210 // ---------------------------------------------------------
211 // wxDataViewBitmapRenderer
212 // ---------------------------------------------------------
214 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
218 // constructors / destructor
220 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
223 // inherited functions from wxDataViewRenderer
225 virtual bool MacRender();
229 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
232 #if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
234 // -------------------------------------
235 // wxDataViewChoiceRenderer
236 // -------------------------------------
237 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewRenderer
241 // constructors / destructor
243 wxDataViewChoiceRenderer(wxArrayString
const& choices
,
244 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
245 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
248 // inherited functions from wxDataViewRenderer
250 virtual bool MacRender();
255 wxString
GetChoice(size_t index
) const
257 return m_Choices
[index
];
259 wxArrayString
const& GetChoices() const
268 wxArrayString m_Choices
;
270 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer
)
275 // ---------------------------------------------------------
276 // wxDataViewIconTextRenderer
277 // ---------------------------------------------------------
278 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
281 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
284 // inherited functions from wxDataViewRenderer
286 virtual bool MacRender();
289 virtual void OSXOnCellChanged(NSObject
*value
,
290 const wxDataViewItem
& item
,
296 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
299 // ---------------------------------------------------------
300 // wxDataViewToggleRenderer
301 // ---------------------------------------------------------
303 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
306 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
309 // inherited functions from wxDataViewRenderer
311 virtual bool MacRender();
314 virtual void OSXOnCellChanged(NSObject
*value
,
315 const wxDataViewItem
& item
,
320 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
323 // ---------------------------------------------------------
324 // wxDataViewProgressRenderer
325 // ---------------------------------------------------------
327 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
330 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
331 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
334 // inherited functions from wxDataViewRenderer
336 virtual bool MacRender();
339 virtual void OSXOnCellChanged(NSObject
*value
,
340 const wxDataViewItem
& item
,
345 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
348 // ---------------------------------------------------------
349 // wxDataViewDateRenderer
350 // ---------------------------------------------------------
352 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
355 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
358 // inherited functions from wxDataViewRenderer
360 virtual bool MacRender();
363 virtual void OSXOnCellChanged(NSObject
*value
,
364 const wxDataViewItem
& item
,
369 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
372 // ---------------------------------------------------------
374 // ---------------------------------------------------------
376 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
379 // constructors / destructor
380 wxDataViewColumn(const wxString
& title
,
381 wxDataViewRenderer
* renderer
,
382 unsigned int model_column
,
383 int width
= wxDVC_DEFAULT_WIDTH
,
384 wxAlignment align
= wxALIGN_CENTER
,
385 int flags
= wxDATAVIEW_COL_RESIZABLE
);
386 wxDataViewColumn(const wxBitmap
& bitmap
,
387 wxDataViewRenderer
* renderer
,
388 unsigned int model_column
,
389 int width
= wxDVC_DEFAULT_WIDTH
,
390 wxAlignment align
= wxALIGN_CENTER
,
391 int flags
= wxDATAVIEW_COL_RESIZABLE
);
392 virtual ~wxDataViewColumn();
394 // implement wxHeaderColumnBase pure virtual methods
395 virtual wxAlignment
GetAlignment() const { return m_alignment
; }
396 virtual int GetFlags() const { return m_flags
; }
397 virtual int GetMaxWidth() const { return m_maxWidth
; }
398 virtual int GetMinWidth() const { return m_minWidth
; }
399 virtual wxString
GetTitle() const { return m_title
; }
400 virtual int GetWidth() const { return m_width
; }
401 virtual bool IsHidden() const { return false; } // TODO
402 virtual bool IsSortOrderAscending() const { return m_ascending
; }
403 virtual bool IsSortKey() const;
405 virtual void SetAlignment (wxAlignment align
);
406 virtual void SetBitmap (wxBitmap
const& bitmap
);
407 virtual void SetFlags (int flags
) { SetIndividualFlags(flags
); }
408 virtual void SetHidden (bool WXUNUSED(hidden
)) { } // TODO
409 virtual void SetMaxWidth (int maxWidth
);
410 virtual void SetMinWidth (int minWidth
);
411 virtual void SetReorderable(bool reorderable
);
412 virtual void SetResizeable (bool resizeable
);
413 virtual void SetSortable (bool sortable
);
414 virtual void SetSortOrder (bool ascending
);
415 virtual void SetTitle (wxString
const& title
);
416 virtual void SetWidth (int width
);
417 virtual void SetAsSortKey (bool sort
= true);
419 // implementation only
420 wxDataViewColumnNativeData
* GetNativeData() const
422 return m_NativeDataPtr
;
425 void SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
); // class takes ownership of pointer
426 void SetWidthVariable(int NewWidth
)
430 void SetSortOrderVariable(bool NewOrder
)
432 m_ascending
= NewOrder
;
436 // common part of all ctors
437 void InitCommon(int width
, wxAlignment align
, int flags
)
440 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
443 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
447 bool m_ascending
; // sorting order
449 int m_flags
; // flags for the column
450 int m_maxWidth
; // maximum width for the column
451 int m_minWidth
; // minimum width for the column
452 int m_width
; // column width
454 wxAlignment m_alignment
; // column header alignment
456 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
458 wxString m_title
; // column title
462 // type definitions related to wxDataViewColumn
464 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
466 // ---------------------------------------------------------
468 // ---------------------------------------------------------
469 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
472 // Constructors / destructor:
477 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
478 const wxValidator
& validator
= wxDefaultValidator
)
481 Create(parent
, id
, pos
, size
, style
, validator
);
486 // explicit control creation
487 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
488 const wxValidator
& validator
=wxDefaultValidator
);
490 virtual wxControl
* GetMainWindow() // not used for the native implementation
495 // inherited methods from wxDataViewCtrlBase:
496 virtual bool AssociateModel(wxDataViewModel
* model
);
498 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
499 virtual bool ClearColumns ();
500 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
501 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
502 virtual unsigned int GetColumnCount () const;
503 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
504 virtual wxDataViewColumn
* GetSortingColumn () const;
505 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
506 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
508 virtual void Collapse( const wxDataViewItem
& item
);
509 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
510 virtual void Expand(const wxDataViewItem
& item
);
511 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
514 virtual unsigned int GetCount() const;
515 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
516 virtual wxDataViewItem
GetSelection() const;
517 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
519 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
521 virtual bool IsSelected(const wxDataViewItem
& item
) const;
523 virtual void SelectAll();
524 virtual void Select(const wxDataViewItem
& item
);
525 virtual void SetSelections(const wxDataViewItemArray
& sel
);
527 virtual void Unselect(const wxDataViewItem
& item
);
528 virtual void UnselectAll();
533 // returns a pointer to the native implementation
534 wxDataViewWidgetImpl
* GetDataViewPeer() const;
536 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
537 void AddChildren(wxDataViewItem
const& parentItem
);
539 // finishes editing of custom items; if no custom item is currently edited the method does nothing
540 void FinishCustomItemEditing();
542 // returns the n-th pointer to a column;
543 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
544 // position in the internal list/array of column pointers
545 wxDataViewColumn
* GetColumnPtr(size_t n
) const
547 return m_ColumnPtrs
[n
];
549 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
550 wxDataViewItem
const& GetCustomRendererItem() const
552 return m_CustomRendererItem
;
554 // returns a pointer to a customized renderer (this pointer is only valid during editing)
555 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
557 return m_CustomRendererPtr
;
560 // checks if currently a delete process is running
561 bool IsDeleting() const
566 // with CG, we need to get the context from an kEventControlDraw event
567 // unfortunately, the DataBrowser callbacks don't provide the context
568 // and we need it, so we need to set/remove it before and after draw
569 // events so we can access it in the callbacks.
570 void MacSetDrawingContext(void* context
)
572 m_cgContext
= context
;
574 void* MacGetDrawingContext() const
579 // sets the currently being edited item of the custom renderer
580 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
582 m_CustomRendererItem
= NewItem
;
584 // sets the custom renderer
585 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
587 m_CustomRendererPtr
= NewCustomRendererPtr
;
589 // sets the flag indicating a deletion process:
590 void SetDeleting(bool deleting
)
592 m_Deleting
= deleting
;
595 virtual wxVisualAttributes
GetDefaultAttributes() const
597 return GetClassDefaultAttributes(GetWindowVariant());
600 static wxVisualAttributes
601 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
604 // inherited methods from wxDataViewCtrlBase
605 virtual void DoSetExpanderColumn();
606 virtual void DoSetIndent();
608 virtual wxSize
DoGetBestSize() const;
611 void OnSize(wxSizeEvent
&event
);
612 void OnMouse(wxMouseEvent
&event
);
615 // initializing of local variables:
621 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
622 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
623 // if this flag is set all native variable update requests will be ignored
625 void* m_cgContext
; // pointer to core graphics context
627 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
629 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
631 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
633 // wxWidget internal stuff:
634 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
635 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
636 DECLARE_EVENT_TABLE()
639 #endif // _WX_DATAVIEWCTRL_OSX_H_