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(void);
39 // inherited methods from wxDataViewRendererBase
41 virtual int GetAlignment() const
43 return this->m_alignment
;
45 virtual wxDataViewCellMode
GetMode() const
49 virtual bool GetValue(wxVariant
& value
) const
51 value
= this->m_value
;
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
)
60 this->m_value
= newValue
;
67 wxVariant
const& GetValue() const
72 wxDataViewRendererNativeData
* GetNativeData() const
74 return this->m_NativeDataPtr
;
77 virtual bool Render() = 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 Render();
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 Render();
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
194 // ---------------------------------------------------------
195 // wxDataViewTextRendererAttr
196 // ---------------------------------------------------------
198 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr
: public wxDataViewTextRenderer
202 // constructors / destructor
204 wxDataViewTextRendererAttr(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
207 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr
)
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 Render();
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 Render();
255 wxString
GetChoice(size_t index
) const
257 return this->m_Choices
[index
];
259 wxArrayString
const& GetChoices(void) const
261 return this->m_Choices
;
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 Render();
290 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
293 // ---------------------------------------------------------
294 // wxDataViewToggleRenderer
295 // ---------------------------------------------------------
297 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
300 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
303 // inherited functions from wxDataViewRenderer
305 virtual bool Render();
309 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
312 // ---------------------------------------------------------
313 // wxDataViewProgressRenderer
314 // ---------------------------------------------------------
316 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
319 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
320 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
323 // inherited functions from wxDataViewRenderer
325 virtual bool Render();
329 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
332 // ---------------------------------------------------------
333 // wxDataViewDateRenderer
334 // ---------------------------------------------------------
336 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
339 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
342 // inherited functions from wxDataViewRenderer
344 virtual bool Render();
348 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
351 // ---------------------------------------------------------
353 // ---------------------------------------------------------
355 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
358 // constructors / destructor
359 wxDataViewColumn(const wxString
& title
,
360 wxDataViewRenderer
* renderer
,
361 unsigned int model_column
,
362 int width
= wxDVC_DEFAULT_WIDTH
,
363 wxAlignment align
= wxALIGN_CENTER
,
364 int flags
= wxDATAVIEW_COL_RESIZABLE
);
365 wxDataViewColumn(const wxBitmap
& bitmap
,
366 wxDataViewRenderer
* renderer
,
367 unsigned int model_column
,
368 int width
= wxDVC_DEFAULT_WIDTH
,
369 wxAlignment align
= wxALIGN_CENTER
,
370 int flags
= wxDATAVIEW_COL_RESIZABLE
);
371 virtual ~wxDataViewColumn(void);
373 // implement wxHeaderColumnBase pure virtual methods
374 virtual wxAlignment
GetAlignment() const { return m_alignment
; }
375 virtual int GetFlags() const { return m_flags
; }
376 virtual int GetMaxWidth() const { return m_maxWidth
; }
377 virtual int GetMinWidth() const { return m_minWidth
; }
378 virtual wxString
GetTitle() const { return m_title
; }
379 virtual int GetWidth() const { return m_width
; }
380 virtual bool IsHidden() const { return false; } // TODO
381 virtual bool IsSortOrderAscending() const { return m_ascending
; }
382 virtual bool IsSortKey() const;
384 virtual void SetAlignment (wxAlignment align
);
385 virtual void SetBitmap (wxBitmap
const& bitmap
);
386 virtual void SetFlags (int flags
) { SetIndividualFlags(flags
); }
387 virtual void SetHidden (bool WXUNUSED(hidden
)) { } // TODO
388 virtual void SetMaxWidth (int maxWidth
);
389 virtual void SetMinWidth (int minWidth
);
390 virtual void SetReorderable(bool reorderable
);
391 virtual void SetResizeable (bool resizeable
);
392 virtual void SetSortable (bool sortable
);
393 virtual void SetSortOrder (bool ascending
);
394 virtual void SetTitle (wxString
const& title
);
395 virtual void SetWidth (int width
);
396 virtual void SetAsSortKey (bool sort
= true);
398 // implementation only
399 wxDataViewColumnNativeData
* GetNativeData(void) const
401 return this->m_NativeDataPtr
;
404 void SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
); // class takes ownership of pointer
405 void SetWidthVariable(int NewWidth
)
411 // common part of all ctors
412 void InitCommon(int width
, wxAlignment align
, int flags
)
415 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
418 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
422 bool m_ascending
; // sorting order
424 int m_flags
; // flags for the column
425 int m_maxWidth
; // maximum width for the column
426 int m_minWidth
; // minimum width for the column
427 int m_width
; // column width
429 wxAlignment m_alignment
; // column header alignment
431 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
433 wxString m_title
; // column title
437 // type definitions related to wxDataViewColumn
439 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
441 // ---------------------------------------------------------
443 // ---------------------------------------------------------
444 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
447 // Constructors / destructor:
452 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
453 const wxValidator
& validator
= wxDefaultValidator
)
456 this->Create(parent
, id
, pos
, size
, style
, validator
);
461 // explicit control creation
462 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
463 const wxValidator
& validator
=wxDefaultValidator
);
465 virtual wxControl
* GetMainWindow() // not used for the native implementation
470 // inherited methods from wxDataViewCtrlBase:
471 virtual bool AssociateModel(wxDataViewModel
* model
);
473 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
474 virtual bool ClearColumns (void);
475 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
476 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
477 virtual unsigned int GetColumnCount (void) const;
478 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
479 virtual wxDataViewColumn
* GetSortingColumn (void) const;
480 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
481 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
483 virtual void Collapse( const wxDataViewItem
& item
);
484 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
485 virtual void Expand(const wxDataViewItem
& item
);
486 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
489 virtual unsigned int GetCount() const;
490 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
491 virtual wxDataViewItem
GetSelection() const;
492 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
494 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
496 virtual bool IsSelected(const wxDataViewItem
& item
) const;
498 virtual void SelectAll();
499 virtual void Select(const wxDataViewItem
& item
);
500 virtual void SetSelections(const wxDataViewItemArray
& sel
);
502 virtual void Unselect(const wxDataViewItem
& item
);
503 virtual void UnselectAll();
508 // returns a pointer to the native implementation
509 wxDataViewWidgetImpl
* GetDataViewPeer(void) const;
511 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
512 void AddChildren(wxDataViewItem
const& parentItem
);
514 // finishes editing of custom items; if no custom item is currently edited the method does nothing
515 void FinishCustomItemEditing(void);
517 // returns the n-th pointer to a column;
518 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
519 // position in the internal list/array of column pointers
520 wxDataViewColumn
* GetColumnPtr(size_t n
) const
522 return this->m_ColumnPtrs
[n
];
524 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
525 wxDataViewItem
const& GetCustomRendererItem() const
527 return this->m_CustomRendererItem
;
529 // returns a pointer to a customized renderer (this pointer is only valid during editing)
530 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
532 return this->m_CustomRendererPtr
;
535 // checks if currently a delete process is running
536 bool IsDeleting() const
538 return this->m_Deleting
;
541 // with CG, we need to get the context from an kEventControlDraw event
542 // unfortunately, the DataBrowser callbacks don't provide the context
543 // and we need it, so we need to set/remove it before and after draw
544 // events so we can access it in the callbacks.
545 void MacSetDrawingContext(void* context
)
547 this->m_cgContext
= context
;
549 void* MacGetDrawingContext() const
551 return this->m_cgContext
;
554 // sets the currently being edited item of the custom renderer
555 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
557 this->m_CustomRendererItem
= NewItem
;
559 // sets the custom renderer
560 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
562 this->m_CustomRendererPtr
= NewCustomRendererPtr
;
564 // sets the flag indicating a deletion process:
565 void SetDeleting(bool deleting
)
567 this->m_Deleting
= deleting
;
570 virtual wxVisualAttributes
GetDefaultAttributes() const
572 return GetClassDefaultAttributes(GetWindowVariant());
575 static wxVisualAttributes
576 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
579 // inherited methods from wxDataViewCtrlBase
580 virtual void DoSetExpanderColumn();
581 virtual void DoSetIndent();
584 void OnSize(wxSizeEvent
&event
);
587 // initializing of local variables:
593 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
594 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
595 // if this flag is set all native variable update requests will be ignored
597 void* m_cgContext
; // pointer to core graphics context
599 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
601 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
603 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
605 // wxWidget internal stuff:
606 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
607 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
608 DECLARE_EVENT_TABLE()
611 #endif // _WX_DATAVIEWCTRL_OSX_H_