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;
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 int GetWidthVariable() const
430 void SetWidthVariable(int NewWidth
)
434 void SetSortOrderVariable(bool NewOrder
)
436 m_ascending
= NewOrder
;
440 // common part of all ctors
441 void InitCommon(int width
, wxAlignment align
, int flags
)
444 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
447 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
451 bool m_ascending
; // sorting order
453 int m_flags
; // flags for the column
454 int m_maxWidth
; // maximum width for the column
455 int m_minWidth
; // minimum width for the column
456 int m_width
; // column width
458 wxAlignment m_alignment
; // column header alignment
460 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
462 wxString m_title
; // column title
466 // type definitions related to wxDataViewColumn
468 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
470 // ---------------------------------------------------------
472 // ---------------------------------------------------------
473 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
476 // Constructors / destructor:
481 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
482 const wxValidator
& validator
= wxDefaultValidator
)
485 Create(parent
, id
, pos
, size
, style
, validator
);
490 // explicit control creation
491 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
492 const wxValidator
& validator
=wxDefaultValidator
);
494 virtual wxControl
* GetMainWindow() // not used 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 ();
504 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
505 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
506 virtual unsigned int GetColumnCount () const;
507 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
508 virtual wxDataViewColumn
* GetSortingColumn () const;
509 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
510 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
512 virtual void Collapse( const wxDataViewItem
& item
);
513 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
514 virtual void Expand(const wxDataViewItem
& item
);
515 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
518 virtual unsigned int GetCount() const;
519 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
520 virtual wxDataViewItem
GetSelection() const;
521 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
523 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
525 virtual bool IsSelected(const wxDataViewItem
& item
) const;
527 virtual void SelectAll();
528 virtual void Select(const wxDataViewItem
& item
);
529 virtual void SetSelections(const wxDataViewItemArray
& sel
);
531 virtual void Unselect(const wxDataViewItem
& item
);
532 virtual void UnselectAll();
537 // returns a pointer to the native implementation
538 wxDataViewWidgetImpl
* GetDataViewPeer() const;
540 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
541 void AddChildren(wxDataViewItem
const& parentItem
);
543 // finishes editing of custom items; if no custom item is currently edited the method does nothing
544 void FinishCustomItemEditing();
546 // returns the n-th pointer to a column;
547 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
548 // position in the internal list/array of column pointers
549 wxDataViewColumn
* GetColumnPtr(size_t n
) const
551 return m_ColumnPtrs
[n
];
553 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
554 wxDataViewItem
const& GetCustomRendererItem() const
556 return m_CustomRendererItem
;
558 // returns a pointer to a customized renderer (this pointer is only valid during editing)
559 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
561 return m_CustomRendererPtr
;
564 // checks if currently a delete process is running
565 bool IsDeleting() const
570 // with CG, we need to get the context from an kEventControlDraw event
571 // unfortunately, the DataBrowser callbacks don't provide the context
572 // and we need it, so we need to set/remove it before and after draw
573 // events so we can access it in the callbacks.
574 void MacSetDrawingContext(void* context
)
576 m_cgContext
= context
;
578 void* MacGetDrawingContext() const
583 // sets the currently being edited item of the custom renderer
584 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
586 m_CustomRendererItem
= NewItem
;
588 // sets the custom renderer
589 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
591 m_CustomRendererPtr
= NewCustomRendererPtr
;
593 // sets the flag indicating a deletion process:
594 void SetDeleting(bool deleting
)
596 m_Deleting
= deleting
;
599 virtual wxVisualAttributes
GetDefaultAttributes() const
601 return GetClassDefaultAttributes(GetWindowVariant());
604 static wxVisualAttributes
605 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
608 // inherited methods from wxDataViewCtrlBase
609 virtual void DoSetExpanderColumn();
610 virtual void DoSetIndent();
612 virtual wxSize
DoGetBestSize() const;
615 void OnSize(wxSizeEvent
&event
);
616 void OnMouse(wxMouseEvent
&event
);
619 // initializing of local variables:
625 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
626 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
627 // if this flag is set all native variable update requests will be ignored
629 void* m_cgContext
; // pointer to core graphics context
631 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
633 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
635 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
637 // wxWidget internal stuff:
638 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
639 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
640 DECLARE_EVENT_TABLE()
643 #endif // _WX_DATAVIEWCTRL_OSX_H_