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 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 // 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 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 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 MacRender();
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 MacRender();
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 MacRender();
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 MacRender();
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
)
409 void SetSortOrderVariable(bool NewOrder
)
411 m_ascending
= NewOrder
;
415 // common part of all ctors
416 void InitCommon(int width
, wxAlignment align
, int flags
)
419 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
422 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
426 bool m_ascending
; // sorting order
428 int m_flags
; // flags for the column
429 int m_maxWidth
; // maximum width for the column
430 int m_minWidth
; // minimum width for the column
431 int m_width
; // column width
433 wxAlignment m_alignment
; // column header alignment
435 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
437 wxString m_title
; // column title
441 // type definitions related to wxDataViewColumn
443 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
445 // ---------------------------------------------------------
447 // ---------------------------------------------------------
448 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
451 // Constructors / destructor:
456 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
457 const wxValidator
& validator
= wxDefaultValidator
)
460 this->Create(parent
, id
, pos
, size
, style
, validator
);
465 // explicit control creation
466 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
467 const wxValidator
& validator
=wxDefaultValidator
);
469 virtual wxControl
* GetMainWindow() // not used for the native implementation
474 // inherited methods from wxDataViewCtrlBase:
475 virtual bool AssociateModel(wxDataViewModel
* model
);
477 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
478 virtual bool ClearColumns (void);
479 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
480 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
481 virtual unsigned int GetColumnCount (void) const;
482 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
483 virtual wxDataViewColumn
* GetSortingColumn (void) const;
484 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
485 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
487 virtual void Collapse( const wxDataViewItem
& item
);
488 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
489 virtual void Expand(const wxDataViewItem
& item
);
490 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
493 virtual unsigned int GetCount() const;
494 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
495 virtual wxDataViewItem
GetSelection() const;
496 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
498 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
500 virtual bool IsSelected(const wxDataViewItem
& item
) const;
502 virtual void SelectAll();
503 virtual void Select(const wxDataViewItem
& item
);
504 virtual void SetSelections(const wxDataViewItemArray
& sel
);
506 virtual void Unselect(const wxDataViewItem
& item
);
507 virtual void UnselectAll();
512 // returns a pointer to the native implementation
513 wxDataViewWidgetImpl
* GetDataViewPeer(void) const;
515 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
516 void AddChildren(wxDataViewItem
const& parentItem
);
518 // finishes editing of custom items; if no custom item is currently edited the method does nothing
519 void FinishCustomItemEditing(void);
521 // returns the n-th pointer to a column;
522 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
523 // position in the internal list/array of column pointers
524 wxDataViewColumn
* GetColumnPtr(size_t n
) const
526 return this->m_ColumnPtrs
[n
];
528 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
529 wxDataViewItem
const& GetCustomRendererItem() const
531 return this->m_CustomRendererItem
;
533 // returns a pointer to a customized renderer (this pointer is only valid during editing)
534 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
536 return this->m_CustomRendererPtr
;
539 // checks if currently a delete process is running
540 bool IsDeleting() const
542 return this->m_Deleting
;
545 // with CG, we need to get the context from an kEventControlDraw event
546 // unfortunately, the DataBrowser callbacks don't provide the context
547 // and we need it, so we need to set/remove it before and after draw
548 // events so we can access it in the callbacks.
549 void MacSetDrawingContext(void* context
)
551 this->m_cgContext
= context
;
553 void* MacGetDrawingContext() const
555 return this->m_cgContext
;
558 // sets the currently being edited item of the custom renderer
559 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
561 this->m_CustomRendererItem
= NewItem
;
563 // sets the custom renderer
564 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
566 this->m_CustomRendererPtr
= NewCustomRendererPtr
;
568 // sets the flag indicating a deletion process:
569 void SetDeleting(bool deleting
)
571 this->m_Deleting
= deleting
;
574 virtual wxVisualAttributes
GetDefaultAttributes() const
576 return GetClassDefaultAttributes(GetWindowVariant());
579 static wxVisualAttributes
580 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
583 // inherited methods from wxDataViewCtrlBase
584 virtual void DoSetExpanderColumn();
585 virtual void DoSetIndent();
587 virtual wxSize
DoGetBestSize() const;
590 void OnSize(wxSizeEvent
&event
);
591 void OnMouse(wxMouseEvent
&event
);
594 // initializing of local variables:
600 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
601 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
602 // if this flag is set all native variable update requests will be ignored
604 void* m_cgContext
; // pointer to core graphics context
606 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
608 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
610 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
612 // wxWidget internal stuff:
613 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
614 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
615 DECLARE_EVENT_TABLE()
618 #endif // _WX_DATAVIEWCTRL_OSX_H_