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
);
89 int m_alignment
; // contains the alignment flags
91 wxDataViewCellMode m_mode
; // storing the mode that determines how the cell is going to be shown
93 wxDataViewRendererNativeData
* m_NativeDataPtr
; // data used by implementation of the native renderer
95 wxVariant m_value
; // value that is going to be rendered
98 // wxWidget internal stuff
100 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer
)
103 // ---------------------------------------------------------
104 // wxDataViewCustomRenderer
105 // ---------------------------------------------------------
106 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewRenderer
110 // constructors / destructor
112 wxDataViewCustomRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
114 virtual ~wxDataViewCustomRenderer();
116 void RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
);
119 // methods handling render space
121 virtual wxSize
GetSize() const = 0;
124 // methods handling user actions
126 virtual bool Render(wxRect cell
, wxDC
* dc
, int state
) = 0;
128 virtual bool Activate( wxRect
WXUNUSED(cell
),
129 wxDataViewModel
*WXUNUSED(model
),
130 const wxDataViewItem
& WXUNUSED(item
),
131 unsigned int WXUNUSED(col
) )
134 virtual bool LeftClick( wxPoint
WXUNUSED(cursor
),
135 wxRect
WXUNUSED(cell
),
136 wxDataViewModel
*WXUNUSED(model
),
137 const wxDataViewItem
& WXUNUSED(item
),
138 unsigned int WXUNUSED(col
) )
141 virtual bool StartDrag( wxPoint
WXUNUSED(cursor
),
142 wxRect
WXUNUSED(cell
),
143 wxDataViewModel
*WXUNUSED(model
),
144 const wxDataViewItem
& WXUNUSED(item
),
145 unsigned int WXUNUSED(col
) )
149 // device context handling
151 virtual wxDC
* GetDC(); // creates a device context and keeps it
156 virtual bool MacRender();
158 void SetDC(wxDC
* newDCPtr
); // this method takes ownership of the pointer
165 wxControl
* m_editorCtrlPtr
; // pointer to an in-place editor control
170 // wxWidget internal stuff
172 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
175 // ---------------------------------------------------------
176 // wxDataViewTextRenderer
177 // ---------------------------------------------------------
179 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
183 // constructors / destructor
185 wxDataViewTextRenderer(wxString
const& varianttype
=wxT("string"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
188 // inherited functions from wxDataViewRenderer
190 virtual bool MacRender();
194 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
197 // ---------------------------------------------------------
198 // wxDataViewBitmapRenderer
199 // ---------------------------------------------------------
201 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
205 // constructors / destructor
207 wxDataViewBitmapRenderer(wxString
const& varianttype
=wxT("wxBitmap"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
210 // inherited functions from wxDataViewRenderer
212 virtual bool MacRender();
216 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
219 #if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
221 // -------------------------------------
222 // wxDataViewChoiceRenderer
223 // -------------------------------------
224 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewRenderer
228 // constructors / destructor
230 wxDataViewChoiceRenderer(wxArrayString
const& choices
,
231 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
232 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
235 // inherited functions from wxDataViewRenderer
237 virtual bool MacRender();
242 wxString
GetChoice(size_t index
) const
244 return m_Choices
[index
];
246 wxArrayString
const& GetChoices() const
255 wxArrayString m_Choices
;
257 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer
)
262 // ---------------------------------------------------------
263 // wxDataViewIconTextRenderer
264 // ---------------------------------------------------------
265 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewRenderer
268 wxDataViewIconTextRenderer(wxString
const& varianttype
= wxT("wxDataViewIconText"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
271 // inherited functions from wxDataViewRenderer
273 virtual bool MacRender();
277 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
280 // ---------------------------------------------------------
281 // wxDataViewToggleRenderer
282 // ---------------------------------------------------------
284 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
287 wxDataViewToggleRenderer(wxString
const& varianttype
= wxT("bool"), wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
290 // inherited functions from wxDataViewRenderer
292 virtual bool MacRender();
296 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
299 // ---------------------------------------------------------
300 // wxDataViewProgressRenderer
301 // ---------------------------------------------------------
303 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewRenderer
306 wxDataViewProgressRenderer(wxString
const& label
= wxEmptyString
, wxString
const& varianttype
=wxT("long"),
307 wxDataViewCellMode mode
=wxDATAVIEW_CELL_INERT
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
310 // inherited functions from wxDataViewRenderer
312 virtual bool MacRender();
316 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
319 // ---------------------------------------------------------
320 // wxDataViewDateRenderer
321 // ---------------------------------------------------------
323 class WXDLLIMPEXP_ADV wxDataViewDateRenderer
: public wxDataViewRenderer
326 wxDataViewDateRenderer(wxString
const& varianttype
=wxT("datetime"), wxDataViewCellMode mode
=wxDATAVIEW_CELL_ACTIVATABLE
, int align
=wxDVR_DEFAULT_ALIGNMENT
);
329 // inherited functions from wxDataViewRenderer
331 virtual bool MacRender();
335 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer
)
338 // ---------------------------------------------------------
340 // ---------------------------------------------------------
342 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
345 // constructors / destructor
346 wxDataViewColumn(const wxString
& title
,
347 wxDataViewRenderer
* renderer
,
348 unsigned int model_column
,
349 int width
= wxDVC_DEFAULT_WIDTH
,
350 wxAlignment align
= wxALIGN_CENTER
,
351 int flags
= wxDATAVIEW_COL_RESIZABLE
);
352 wxDataViewColumn(const wxBitmap
& bitmap
,
353 wxDataViewRenderer
* renderer
,
354 unsigned int model_column
,
355 int width
= wxDVC_DEFAULT_WIDTH
,
356 wxAlignment align
= wxALIGN_CENTER
,
357 int flags
= wxDATAVIEW_COL_RESIZABLE
);
358 virtual ~wxDataViewColumn();
360 // implement wxHeaderColumnBase pure virtual methods
361 virtual wxAlignment
GetAlignment() const { return m_alignment
; }
362 virtual int GetFlags() const { return m_flags
; }
363 virtual int GetMaxWidth() const { return m_maxWidth
; }
364 virtual int GetMinWidth() const { return m_minWidth
; }
365 virtual wxString
GetTitle() const { return m_title
; }
366 virtual int GetWidth() const { return m_width
; }
367 virtual bool IsHidden() const { return false; } // TODO
368 virtual bool IsSortOrderAscending() const { return m_ascending
; }
369 virtual bool IsSortKey() const;
371 virtual void SetAlignment (wxAlignment align
);
372 virtual void SetBitmap (wxBitmap
const& bitmap
);
373 virtual void SetFlags (int flags
) { SetIndividualFlags(flags
); }
374 virtual void SetHidden (bool WXUNUSED(hidden
)) { } // TODO
375 virtual void SetMaxWidth (int maxWidth
);
376 virtual void SetMinWidth (int minWidth
);
377 virtual void SetReorderable(bool reorderable
);
378 virtual void SetResizeable (bool resizeable
);
379 virtual void SetSortable (bool sortable
);
380 virtual void SetSortOrder (bool ascending
);
381 virtual void SetTitle (wxString
const& title
);
382 virtual void SetWidth (int width
);
383 virtual void SetAsSortKey (bool sort
= true);
385 // implementation only
386 wxDataViewColumnNativeData
* GetNativeData() const
388 return m_NativeDataPtr
;
391 void SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
); // class takes ownership of pointer
392 void SetWidthVariable(int NewWidth
)
396 void SetSortOrderVariable(bool NewOrder
)
398 m_ascending
= NewOrder
;
402 // common part of all ctors
403 void InitCommon(int width
, wxAlignment align
, int flags
)
406 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
409 m_width
= width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
;
413 bool m_ascending
; // sorting order
415 int m_flags
; // flags for the column
416 int m_maxWidth
; // maximum width for the column
417 int m_minWidth
; // minimum width for the column
418 int m_width
; // column width
420 wxAlignment m_alignment
; // column header alignment
422 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
424 wxString m_title
; // column title
428 // type definitions related to wxDataViewColumn
430 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
432 // ---------------------------------------------------------
434 // ---------------------------------------------------------
435 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
438 // Constructors / destructor:
443 wxDataViewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0,
444 const wxValidator
& validator
= wxDefaultValidator
)
447 Create(parent
, id
, pos
, size
, style
, validator
);
452 // explicit control creation
453 bool Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
=wxDefaultPosition
, const wxSize
& size
=wxDefaultSize
, long style
=0,
454 const wxValidator
& validator
=wxDefaultValidator
);
456 virtual wxControl
* GetMainWindow() // not used for the native implementation
461 // inherited methods from wxDataViewCtrlBase:
462 virtual bool AssociateModel(wxDataViewModel
* model
);
464 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
465 virtual bool ClearColumns ();
466 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
467 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
468 virtual unsigned int GetColumnCount () const;
469 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
470 virtual wxDataViewColumn
* GetSortingColumn () const;
471 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
472 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
474 virtual void Collapse( const wxDataViewItem
& item
);
475 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
476 virtual void Expand(const wxDataViewItem
& item
);
477 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
480 virtual unsigned int GetCount() const;
481 virtual wxRect
GetItemRect(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
) const;
482 virtual wxDataViewItem
GetSelection() const;
483 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
485 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
487 virtual bool IsSelected(const wxDataViewItem
& item
) const;
489 virtual void SelectAll();
490 virtual void Select(const wxDataViewItem
& item
);
491 virtual void SetSelections(const wxDataViewItemArray
& sel
);
493 virtual void Unselect(const wxDataViewItem
& item
);
494 virtual void UnselectAll();
499 // returns a pointer to the native implementation
500 wxDataViewWidgetImpl
* GetDataViewPeer() const;
502 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
503 void AddChildren(wxDataViewItem
const& parentItem
);
505 // finishes editing of custom items; if no custom item is currently edited the method does nothing
506 void FinishCustomItemEditing();
508 // returns the n-th pointer to a column;
509 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
510 // position in the internal list/array of column pointers
511 wxDataViewColumn
* GetColumnPtr(size_t n
) const
513 return m_ColumnPtrs
[n
];
515 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
516 wxDataViewItem
const& GetCustomRendererItem() const
518 return m_CustomRendererItem
;
520 // returns a pointer to a customized renderer (this pointer is only valid during editing)
521 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
523 return m_CustomRendererPtr
;
526 // checks if currently a delete process is running
527 bool IsDeleting() const
532 // with CG, we need to get the context from an kEventControlDraw event
533 // unfortunately, the DataBrowser callbacks don't provide the context
534 // and we need it, so we need to set/remove it before and after draw
535 // events so we can access it in the callbacks.
536 void MacSetDrawingContext(void* context
)
538 m_cgContext
= context
;
540 void* MacGetDrawingContext() const
545 // sets the currently being edited item of the custom renderer
546 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
548 m_CustomRendererItem
= NewItem
;
550 // sets the custom renderer
551 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
553 m_CustomRendererPtr
= NewCustomRendererPtr
;
555 // sets the flag indicating a deletion process:
556 void SetDeleting(bool deleting
)
558 m_Deleting
= deleting
;
561 virtual wxVisualAttributes
GetDefaultAttributes() const
563 return GetClassDefaultAttributes(GetWindowVariant());
566 static wxVisualAttributes
567 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
570 // inherited methods from wxDataViewCtrlBase
571 virtual void DoSetExpanderColumn();
572 virtual void DoSetIndent();
574 virtual wxSize
DoGetBestSize() const;
577 void OnSize(wxSizeEvent
&event
);
578 void OnMouse(wxMouseEvent
&event
);
581 // initializing of local variables:
587 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
588 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
589 // if this flag is set all native variable update requests will be ignored
591 void* m_cgContext
; // pointer to core graphics context
593 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
595 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
597 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
599 // wxWidget internal stuff:
600 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
601 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
602 DECLARE_EVENT_TABLE()
605 #endif // _WX_DATAVIEWCTRL_OSX_H_