]>
Commit | Line | Data |
---|---|---|
e86edab0 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/osx/dataview.h | |
3 | // Purpose: wxDataViewCtrl native implementation header for OSX | |
4 | // Author: | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 2009 | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_DATAVIEWCTRL_OSX_H_ | |
11 | #define _WX_DATAVIEWCTRL_OSX_H_ | |
12 | ||
5c6eb3a8 SC |
13 | #ifdef __WXMAC_CLASSIC__ |
14 | # error "Native wxDataViewCtrl for classic environment not defined. Please use generic control." | |
5c6eb3a8 | 15 | #endif |
e86edab0 RR |
16 | |
17 | // -------------------------------------------------------- | |
18 | // Class declarations to mask native types | |
19 | // -------------------------------------------------------- | |
20 | class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation | |
e86edab0 RR |
21 | class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation |
22 | ||
e86edab0 RR |
23 | // --------------------------------------------------------- |
24 | // wxDataViewColumn | |
25 | // --------------------------------------------------------- | |
26 | ||
27 | class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase | |
28 | { | |
29 | public: | |
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); | |
de40d736 | 43 | virtual ~wxDataViewColumn(); |
e86edab0 RR |
44 | |
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; } | |
d831e2db | 51 | virtual int GetWidth() const; |
e86edab0 RR |
52 | virtual bool IsSortOrderAscending() const { return m_ascending; } |
53 | virtual bool IsSortKey() const; | |
f6cb92b8 | 54 | virtual bool IsHidden() const; |
e86edab0 RR |
55 | |
56 | virtual void SetAlignment (wxAlignment align); | |
57 | virtual void SetBitmap (wxBitmap const& bitmap); | |
58 | virtual void SetFlags (int flags) { SetIndividualFlags(flags); } | |
f6cb92b8 | 59 | virtual void SetHidden (bool hidden); |
e86edab0 RR |
60 | virtual void SetMaxWidth (int maxWidth); |
61 | virtual void SetMinWidth (int minWidth); | |
62 | virtual void SetReorderable(bool reorderable); | |
d13b34d3 | 63 | virtual void SetResizeable (bool resizable); |
e86edab0 RR |
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); | |
e86edab0 RR |
68 | |
69 | // implementation only | |
de40d736 | 70 | wxDataViewColumnNativeData* GetNativeData() const |
e86edab0 | 71 | { |
de40d736 | 72 | return m_NativeDataPtr; |
e86edab0 | 73 | } |
03647350 | 74 | |
e86edab0 | 75 | void SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr); // class takes ownership of pointer |
d831e2db VZ |
76 | int GetWidthVariable() const |
77 | { | |
78 | return m_width; | |
79 | } | |
e86edab0 RR |
80 | void SetWidthVariable(int NewWidth) |
81 | { | |
82 | m_width = NewWidth; | |
83 | } | |
8ba01d35 RR |
84 | void SetSortOrderVariable(bool NewOrder) |
85 | { | |
86 | m_ascending = NewOrder; | |
87 | } | |
e86edab0 RR |
88 | |
89 | private: | |
90 | // common part of all ctors | |
91 | void InitCommon(int width, wxAlignment align, int flags) | |
92 | { | |
93 | m_ascending = true; | |
94 | m_flags = flags & ~wxDATAVIEW_COL_HIDDEN; // TODO | |
95 | m_maxWidth = 30000; | |
96 | m_minWidth = 0; | |
e86edab0 | 97 | m_alignment = align; |
b06ed2f8 | 98 | SetWidth(width); |
e86edab0 RR |
99 | } |
100 | ||
101 | bool m_ascending; // sorting order | |
102 | ||
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 | |
107 | ||
108 | wxAlignment m_alignment; // column header alignment | |
109 | ||
110 | wxDataViewColumnNativeData* m_NativeDataPtr; // storing environment dependent data for the native implementation | |
111 | ||
112 | wxString m_title; // column title | |
113 | }; | |
114 | ||
115 | // | |
116 | // type definitions related to wxDataViewColumn | |
117 | // | |
118 | WX_DEFINE_ARRAY(wxDataViewColumn*,wxDataViewColumnPtrArrayType); | |
119 | ||
120 | // --------------------------------------------------------- | |
121 | // wxDataViewCtrl | |
122 | // --------------------------------------------------------- | |
123 | class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase | |
124 | { | |
125 | public: | |
126 | // Constructors / destructor: | |
127 | wxDataViewCtrl() | |
128 | { | |
de40d736 | 129 | Init(); |
e86edab0 | 130 | } |
62e9285a VZ |
131 | wxDataViewCtrl(wxWindow *parent, |
132 | wxWindowID winid, | |
133 | const wxPoint& pos = wxDefaultPosition, | |
134 | const wxSize& size = wxDefaultSize, | |
135 | long style = 0, | |
136 | const wxValidator& validator = wxDefaultValidator, | |
137 | const wxString& name = wxDataViewCtrlNameStr ) | |
e86edab0 | 138 | { |
de40d736 | 139 | Init(); |
62e9285a | 140 | Create(parent, winid, pos, size, style, validator, name); |
e86edab0 RR |
141 | } |
142 | ||
143 | ~wxDataViewCtrl(); | |
144 | ||
62e9285a VZ |
145 | bool Create(wxWindow *parent, |
146 | wxWindowID winid, | |
147 | const wxPoint& pos = wxDefaultPosition, | |
148 | const wxSize& size = wxDefaultSize, | |
149 | long style = 0, | |
150 | const wxValidator& validator = wxDefaultValidator, | |
151 | const wxString& name = wxDataViewCtrlNameStr); | |
e86edab0 RR |
152 | |
153 | virtual wxControl* GetMainWindow() // not used for the native implementation | |
154 | { | |
155 | return this; | |
156 | } | |
157 | ||
158 | // inherited methods from wxDataViewCtrlBase: | |
159 | virtual bool AssociateModel(wxDataViewModel* model); | |
160 | ||
161 | virtual bool AppendColumn (wxDataViewColumn* columnPtr); | |
de40d736 | 162 | virtual bool ClearColumns (); |
e86edab0 RR |
163 | virtual bool DeleteColumn (wxDataViewColumn* columnPtr); |
164 | virtual wxDataViewColumn* GetColumn (unsigned int pos) const; | |
de40d736 | 165 | virtual unsigned int GetColumnCount () const; |
e86edab0 | 166 | virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const; |
de40d736 | 167 | virtual wxDataViewColumn* GetSortingColumn () const; |
e86edab0 RR |
168 | virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col); |
169 | virtual bool PrependColumn (wxDataViewColumn* columnPtr); | |
170 | ||
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; | |
175 | ||
e86edab0 RR |
176 | virtual unsigned int GetCount() const; |
177 | virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr) const; | |
fa93d732 | 178 | virtual int GetSelectedItemsCount() const; |
e86edab0 RR |
179 | virtual int GetSelections(wxDataViewItemArray& sel) const; |
180 | ||
181 | virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const; | |
182 | ||
183 | virtual bool IsSelected(const wxDataViewItem& item) const; | |
184 | ||
185 | virtual void SelectAll(); | |
186 | virtual void Select(const wxDataViewItem& item); | |
187 | virtual void SetSelections(const wxDataViewItemArray& sel); | |
188 | ||
189 | virtual void Unselect(const wxDataViewItem& item); | |
190 | virtual void UnselectAll(); | |
191 | ||
192 | // | |
193 | // implementation | |
194 | // | |
195 | // returns a pointer to the native implementation | |
de40d736 | 196 | wxDataViewWidgetImpl* GetDataViewPeer() const; |
e86edab0 RR |
197 | |
198 | // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added: | |
199 | void AddChildren(wxDataViewItem const& parentItem); | |
200 | ||
201 | // finishes editing of custom items; if no custom item is currently edited the method does nothing | |
de40d736 | 202 | void FinishCustomItemEditing(); |
eeea3b03 RD |
203 | |
204 | virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); | |
e86edab0 RR |
205 | |
206 | // returns the n-th pointer to a column; | |
207 | // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th | |
208 | // position in the internal list/array of column pointers | |
209 | wxDataViewColumn* GetColumnPtr(size_t n) const | |
210 | { | |
de40d736 | 211 | return m_ColumnPtrs[n]; |
e86edab0 RR |
212 | } |
213 | // returns the current being rendered item of the customized renderer (this item is only valid during editing) | |
214 | wxDataViewItem const& GetCustomRendererItem() const | |
215 | { | |
de40d736 | 216 | return m_CustomRendererItem; |
e86edab0 RR |
217 | } |
218 | // returns a pointer to a customized renderer (this pointer is only valid during editing) | |
219 | wxDataViewCustomRenderer* GetCustomRendererPtr() const | |
220 | { | |
de40d736 | 221 | return m_CustomRendererPtr; |
e86edab0 RR |
222 | } |
223 | ||
224 | // checks if currently a delete process is running | |
225 | bool IsDeleting() const | |
226 | { | |
de40d736 | 227 | return m_Deleting; |
e86edab0 RR |
228 | } |
229 | ||
230 | // with CG, we need to get the context from an kEventControlDraw event | |
231 | // unfortunately, the DataBrowser callbacks don't provide the context | |
232 | // and we need it, so we need to set/remove it before and after draw | |
233 | // events so we can access it in the callbacks. | |
234 | void MacSetDrawingContext(void* context) | |
235 | { | |
de40d736 | 236 | m_cgContext = context; |
e86edab0 RR |
237 | } |
238 | void* MacGetDrawingContext() const | |
239 | { | |
de40d736 | 240 | return m_cgContext; |
e86edab0 RR |
241 | } |
242 | ||
243 | // sets the currently being edited item of the custom renderer | |
244 | void SetCustomRendererItem(wxDataViewItem const& NewItem) | |
245 | { | |
de40d736 | 246 | m_CustomRendererItem = NewItem; |
e86edab0 RR |
247 | } |
248 | // sets the custom renderer | |
249 | void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr) | |
250 | { | |
de40d736 | 251 | m_CustomRendererPtr = NewCustomRendererPtr; |
e86edab0 RR |
252 | } |
253 | // sets the flag indicating a deletion process: | |
254 | void SetDeleting(bool deleting) | |
255 | { | |
de40d736 | 256 | m_Deleting = deleting; |
e86edab0 RR |
257 | } |
258 | ||
259 | virtual wxVisualAttributes GetDefaultAttributes() const | |
260 | { | |
261 | return GetClassDefaultAttributes(GetWindowVariant()); | |
262 | } | |
263 | ||
264 | static wxVisualAttributes | |
265 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
266 | ||
267 | protected: | |
268 | // inherited methods from wxDataViewCtrlBase | |
269 | virtual void DoSetExpanderColumn(); | |
270 | virtual void DoSetIndent(); | |
271 | ||
ca6de8c0 RR |
272 | virtual wxSize DoGetBestSize() const; |
273 | ||
e86edab0 RR |
274 | // event handling |
275 | void OnSize(wxSizeEvent &event); | |
ca6de8c0 | 276 | void OnMouse(wxMouseEvent &event); |
e86edab0 RR |
277 | |
278 | private: | |
279 | // initializing of local variables: | |
280 | void Init(); | |
281 | ||
80ce465c VZ |
282 | virtual wxDataViewItem DoGetCurrentItem() const; |
283 | virtual void DoSetCurrentItem(const wxDataViewItem& item); | |
284 | ||
e86edab0 RR |
285 | // |
286 | // variables | |
287 | // | |
288 | 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 | |
289 | // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted; | |
290 | // if this flag is set all native variable update requests will be ignored | |
291 | ||
292 | void* m_cgContext; // pointer to core graphics context | |
293 | ||
294 | wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer | |
295 | ||
296 | wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item | |
297 | ||
298 | wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array | |
299 | ||
300 | // wxWidget internal stuff: | |
301 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
302 | DECLARE_NO_COPY_CLASS(wxDataViewCtrl) | |
303 | DECLARE_EVENT_TABLE() | |
304 | }; | |
305 | ||
306 | #endif // _WX_DATAVIEWCTRL_OSX_H_ | |
307 |