1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/dataview.h
3 // Purpose: wxDataViewCtrl native implementation header for OSX
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_DATAVIEWCTRL_OSX_H_
11 #define _WX_DATAVIEWCTRL_OSX_H_
13 #ifdef __WXMAC_CLASSIC__
14 # error "Native wxDataViewCtrl for classic environment not defined. Please use generic control."
17 // --------------------------------------------------------
18 // Class declarations to mask native types
19 // --------------------------------------------------------
20 class wxDataViewColumnNativeData
; // class storing environment dependent data for the native implementation
21 class wxDataViewWidgetImpl
; // class used as a common interface for carbon and cocoa implementation
23 // ---------------------------------------------------------
25 // ---------------------------------------------------------
27 class WXDLLIMPEXP_ADV wxDataViewColumn
: public wxDataViewColumnBase
30 // constructors / destructor
31 wxDataViewColumn(const wxString
& title
,
32 wxDataViewRenderer
* renderer
,
33 unsigned int model_column
,
34 int width
= wxDVC_DEFAULT_WIDTH
,
35 wxAlignment align
= wxALIGN_CENTER
,
36 int flags
= wxDATAVIEW_COL_RESIZABLE
);
37 wxDataViewColumn(const wxBitmap
& bitmap
,
38 wxDataViewRenderer
* renderer
,
39 unsigned int model_column
,
40 int width
= wxDVC_DEFAULT_WIDTH
,
41 wxAlignment align
= wxALIGN_CENTER
,
42 int flags
= wxDATAVIEW_COL_RESIZABLE
);
43 virtual ~wxDataViewColumn();
45 // implement wxHeaderColumnBase pure virtual methods
46 virtual wxAlignment
GetAlignment() const { return m_alignment
; }
47 virtual int GetFlags() const { return m_flags
; }
48 virtual int GetMaxWidth() const { return m_maxWidth
; }
49 virtual int GetMinWidth() const { return m_minWidth
; }
50 virtual wxString
GetTitle() const { return m_title
; }
51 virtual int GetWidth() const;
52 virtual bool IsSortOrderAscending() const { return m_ascending
; }
53 virtual bool IsSortKey() const;
54 virtual bool IsHidden() const;
56 virtual void SetAlignment (wxAlignment align
);
57 virtual void SetBitmap (wxBitmap
const& bitmap
);
58 virtual void SetFlags (int flags
) { SetIndividualFlags(flags
); }
59 virtual void SetHidden (bool hidden
);
60 virtual void SetMaxWidth (int maxWidth
);
61 virtual void SetMinWidth (int minWidth
);
62 virtual void SetReorderable(bool reorderable
);
63 virtual void SetResizeable (bool resizable
);
64 virtual void SetSortable (bool sortable
);
65 virtual void SetSortOrder (bool ascending
);
66 virtual void SetTitle (wxString
const& title
);
67 virtual void SetWidth (int width
);
69 // implementation only
70 wxDataViewColumnNativeData
* GetNativeData() const
72 return m_NativeDataPtr
;
75 void SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
); // class takes ownership of pointer
76 int GetWidthVariable() const
80 void SetWidthVariable(int NewWidth
)
84 void SetSortOrderVariable(bool NewOrder
)
86 m_ascending
= NewOrder
;
90 // common part of all ctors
91 void InitCommon(int width
, wxAlignment align
, int flags
)
94 m_flags
= flags
& ~wxDATAVIEW_COL_HIDDEN
; // TODO
101 bool m_ascending
; // sorting order
103 int m_flags
; // flags for the column
104 int m_maxWidth
; // maximum width for the column
105 int m_minWidth
; // minimum width for the column
106 int m_width
; // column width
108 wxAlignment m_alignment
; // column header alignment
110 wxDataViewColumnNativeData
* m_NativeDataPtr
; // storing environment dependent data for the native implementation
112 wxString m_title
; // column title
116 // type definitions related to wxDataViewColumn
118 WX_DEFINE_ARRAY(wxDataViewColumn
*,wxDataViewColumnPtrArrayType
);
120 // ---------------------------------------------------------
122 // ---------------------------------------------------------
123 class WXDLLIMPEXP_ADV wxDataViewCtrl
: public wxDataViewCtrlBase
126 // Constructors / destructor:
131 wxDataViewCtrl(wxWindow
*parent
,
133 const wxPoint
& pos
= wxDefaultPosition
,
134 const wxSize
& size
= wxDefaultSize
,
136 const wxValidator
& validator
= wxDefaultValidator
,
137 const wxString
& name
= wxDataViewCtrlNameStr
)
140 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
145 bool Create(wxWindow
*parent
,
147 const wxPoint
& pos
= wxDefaultPosition
,
148 const wxSize
& size
= wxDefaultSize
,
150 const wxValidator
& validator
= wxDefaultValidator
,
151 const wxString
& name
= wxDataViewCtrlNameStr
);
153 virtual wxWindow
* GetMainWindow() // not used for the native implementation
158 // inherited methods from wxDataViewCtrlBase:
159 virtual bool AssociateModel(wxDataViewModel
* model
);
161 virtual bool AppendColumn (wxDataViewColumn
* columnPtr
);
162 virtual bool ClearColumns ();
163 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
164 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
165 virtual unsigned int GetColumnCount () const;
166 virtual int GetColumnPosition(const wxDataViewColumn
* columnPtr
) const;
167 virtual wxDataViewColumn
* GetSortingColumn () const;
168 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
*col
);
169 virtual bool PrependColumn (wxDataViewColumn
* columnPtr
);
171 virtual void Collapse( const wxDataViewItem
& item
);
172 virtual void EnsureVisible(const wxDataViewItem
& item
, const wxDataViewColumn
* columnPtr
=NULL
);
173 virtual void Expand(const wxDataViewItem
& item
);
174 virtual bool IsExpanded(const wxDataViewItem
& item
) const;
176 virtual unsigned int GetCount() const;
177 virtual wxRect
GetItemRect(const wxDataViewItem
& item
,
178 const wxDataViewColumn
* columnPtr
= NULL
) const;
179 virtual int GetSelectedItemsCount() const;
180 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
182 virtual void HitTest(const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
184 virtual bool IsSelected(const wxDataViewItem
& item
) const;
186 virtual void SelectAll();
187 virtual void Select(const wxDataViewItem
& item
);
188 virtual void SetSelections(const wxDataViewItemArray
& sel
);
190 virtual void Unselect(const wxDataViewItem
& item
);
191 virtual void UnselectAll();
196 // returns a pointer to the native implementation
197 wxDataViewWidgetImpl
* GetDataViewPeer() const;
199 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
200 void AddChildren(wxDataViewItem
const& parentItem
);
202 // finishes editing of custom items; if no custom item is currently edited the method does nothing
203 void FinishCustomItemEditing();
205 virtual void EditItem(const wxDataViewItem
& item
, const wxDataViewColumn
*column
);
207 // returns the n-th pointer to a column;
208 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
209 // position in the internal list/array of column pointers
210 wxDataViewColumn
* GetColumnPtr(size_t n
) const
212 return m_ColumnPtrs
[n
];
214 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
215 wxDataViewItem
const& GetCustomRendererItem() const
217 return m_CustomRendererItem
;
219 // returns a pointer to a customized renderer (this pointer is only valid during editing)
220 wxDataViewCustomRenderer
* GetCustomRendererPtr() const
222 return m_CustomRendererPtr
;
225 // checks if currently a delete process is running
226 bool IsDeleting() const
231 // with CG, we need to get the context from an kEventControlDraw event
232 // unfortunately, the DataBrowser callbacks don't provide the context
233 // and we need it, so we need to set/remove it before and after draw
234 // events so we can access it in the callbacks.
235 void MacSetDrawingContext(void* context
)
237 m_cgContext
= context
;
239 void* MacGetDrawingContext() const
244 // sets the currently being edited item of the custom renderer
245 void SetCustomRendererItem(wxDataViewItem
const& NewItem
)
247 m_CustomRendererItem
= NewItem
;
249 // sets the custom renderer
250 void SetCustomRendererPtr(wxDataViewCustomRenderer
* NewCustomRendererPtr
)
252 m_CustomRendererPtr
= NewCustomRendererPtr
;
254 // sets the flag indicating a deletion process:
255 void SetDeleting(bool deleting
)
257 m_Deleting
= deleting
;
260 virtual wxDataViewColumn
*GetCurrentColumn() const;
262 virtual wxVisualAttributes
GetDefaultAttributes() const
264 return GetClassDefaultAttributes(GetWindowVariant());
267 static wxVisualAttributes
268 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
271 // inherited methods from wxDataViewCtrlBase
272 virtual void DoSetExpanderColumn();
273 virtual void DoSetIndent();
275 virtual wxSize
DoGetBestSize() const;
278 void OnSize(wxSizeEvent
&event
);
279 void OnMouse(wxMouseEvent
&event
);
282 // initializing of local variables:
285 virtual wxDataViewItem
DoGetCurrentItem() const;
286 virtual void DoSetCurrentItem(const wxDataViewItem
& item
);
291 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
292 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
293 // if this flag is set all native variable update requests will be ignored
295 void* m_cgContext
; // pointer to core graphics context
297 wxDataViewCustomRenderer
* m_CustomRendererPtr
; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
299 wxDataViewItem m_CustomRendererItem
; // currently edited item by the customrenderer; it is invalid while not editing a custom item
301 wxDataViewColumnPtrArrayType m_ColumnPtrs
; // all column pointers are stored in an array
303 // wxWidget internal stuff:
304 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl
)
305 DECLARE_NO_COPY_CLASS(wxDataViewCtrl
)
306 DECLARE_EVENT_TABLE()
309 #endif // _WX_DATAVIEWCTRL_OSX_H_