]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/dataview.h
New API for wxdataViewCtrl (doesn't run yet).
[wxWidgets.git] / include / wx / mac / carbon / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/carbon/dataview.h
3 // Purpose: wxDataViewCtrl native implementation header
4 // Author:
5 // Id: $Id$
6 // Copyright: (c) 2007
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __MACCARBONDATAVIEWCTRL_H__
11 #define __MACCARBONDATAVIEWCTRL_H__
12
13 #include <Carbon/carbon.h>
14
15 #include "wx/defs.h"
16 #include "wx/object.h"
17 #include "wx/list.h"
18 #include "wx/control.h"
19 #include "wx/scrolwin.h"
20 #include "wx/icon.h"
21
22 // ---------------------------------------------------------
23 // classes
24 // ---------------------------------------------------------
25
26 class WXDLLIMPEXP_ADV wxDataViewCtrl;
27
28 // ---------------------------------------------------------
29 // wxDataViewRenderer
30 // ---------------------------------------------------------
31
32 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
33 {
34 public:
35 //
36 // constructors / destructor
37 //
38 wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
39
40 //
41 // inherited methods from wxDataViewRendererBase
42 //
43 virtual int GetAlignment(void) const
44 {
45 return this->m_alignment;
46 }
47 virtual wxDataViewCellMode GetMode(void) const
48 {
49 return this->m_mode;
50 }
51 virtual bool GetValue(wxVariant& value) const
52 {
53 value = this->m_value;
54 return true;
55 }
56
57 virtual void SetAlignment(int WXUNUSED(align)) // is always identical to the header alignment
58 {
59 }
60 virtual void SetMode(wxDataViewCellMode mode);
61 virtual bool SetValue(wxVariant const& newValue)
62 {
63 this->m_value = newValue;
64 return true;
65 }
66
67 //
68 // implementation
69 //
70 DataBrowserItemDataRef GetDataReference(void) const
71 {
72 return this->m_dataReference;
73 }
74 wxVariant const& GetValue(void) const
75 {
76 return this->m_value;
77 }
78
79 virtual DataBrowserPropertyType GetPropertyType(void) const = 0;
80
81 virtual bool Render(void) = 0; // a call to the appropriate data browser function filling the data reference with the stored datum;
82 // returns 'true' if the data value could be rendered, 'false' otherwise
83
84 void SetDataReference(DataBrowserItemDataRef const& newDataReference)
85 {
86 this->m_dataReference = newDataReference;
87 }
88
89 private:
90 //
91 // variables
92 //
93 DataBrowserItemDataRef m_dataReference; // data reference of the data browser; the data will be assigned to this reference during rendering
94
95 int m_alignment; // contains the alignment flags
96
97 wxDataViewCellMode m_mode; // storing the mode that determines how the cell is going to be shown
98
99 wxVariant m_value; // value that is going to be rendered
100
101 //
102 // wxWidget internal stuff
103 //
104 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
105 };
106
107 // ---------------------------------------------------------
108 // wxDataViewCustomRenderer
109 // ---------------------------------------------------------
110
111 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
112 {
113 public:
114 //
115 // constructors / destructor
116 //
117 wxDataViewCustomRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
118
119 virtual ~wxDataViewCustomRenderer(void);
120
121 //
122 // methods handling render space
123 //
124 virtual wxSize GetSize() const = 0;
125
126 //
127 // methods handling user actions
128 //
129 virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
130
131 virtual bool Activate(wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
132 {
133 return false;
134 }
135
136 virtual bool LeftClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
137 {
138 return false;
139 }
140
141 virtual bool RightClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
142 {
143 return false;
144 }
145
146 virtual bool StartDrag(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
147 {
148 return false;
149 }
150
151 //
152 // in-place editing
153 //
154 virtual void CancelEditing()
155 {
156 }
157
158 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), wxRect WXUNUSED(labelRect), const wxVariant& WXUNUSED(value))
159 {
160 return NULL;
161 }
162
163 virtual bool FinishEditing()
164 {
165 return false;
166 }
167
168 wxControl* GetEditorCtrl(void) const
169 {
170 return this->m_editorCtrlPtr;
171 }
172 virtual bool GetValueFromEditorCtrl(wxControl* WXUNUSED(editor), wxVariant& WXUNUSED(value))
173 {
174 return false;
175 }
176
177 virtual bool HasEditorCtrl(void)
178 {
179 return false;
180 }
181
182 virtual bool StartEditing(unsigned int WXUNUSED(row), wxRect WXUNUSED(labelRect))
183 {
184 return false;
185 }
186
187 //
188 // device context handling
189 //
190 virtual wxDC* GetDC(void); // creates a device context and keeps it
191
192 //
193 // implementation
194 //
195 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
196 // return 'false' without having done anything
197
198 virtual DataBrowserPropertyType GetPropertyType(void) const
199 {
200 return kDataBrowserCustomType;
201 }
202
203 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
204
205 protected:
206 private:
207 //
208 // variables
209 //
210 wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
211
212 wxDC* m_DCPtr;
213
214 //
215 // wxWidget internal stuff
216 //
217 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
218 };
219
220 // ---------------------------------------------------------
221 // wxDataViewTextRenderer
222 // ---------------------------------------------------------
223
224 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
225 {
226 public:
227 //
228 // constructors / destructor
229 //
230 wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
231
232 //
233 // inherited functions from wxDataViewRenderer
234 //
235 virtual bool Render(void);
236
237 //
238 // implementation
239 //
240 virtual DataBrowserPropertyType GetPropertyType(void) const
241 {
242 return kDataBrowserTextType;
243 }
244
245 protected:
246 private:
247 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
248 };
249
250 // ---------------------------------------------------------
251 // wxDataViewBitmapRenderer
252 // ---------------------------------------------------------
253
254 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
255 {
256 public:
257 //
258 // constructors / destructor
259 //
260 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
261
262 //
263 // inherited functions from wxDataViewRenderer
264 //
265 virtual bool Render(void);
266
267 //
268 // implementation
269 //
270 virtual DataBrowserPropertyType GetPropertyType(void) const
271 {
272 return kDataBrowserIconType;
273 }
274
275 protected:
276 private:
277 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
278 };
279
280 // ---------------------------------------------------------
281 // wxDataViewToggleRenderer
282 // ---------------------------------------------------------
283
284 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
285 {
286 public:
287 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
288
289 //
290 // inherited functions from wxDataViewRenderer
291 //
292 virtual bool Render(void);
293
294 //
295 // implementation
296 //
297 virtual DataBrowserPropertyType GetPropertyType(void) const
298 {
299 return kDataBrowserCheckboxType;
300 }
301
302 protected:
303 private:
304 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
305 };
306
307 // ---------------------------------------------------------
308 // wxDataViewProgressRenderer
309 // ---------------------------------------------------------
310
311 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
312 {
313 public:
314 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
315 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
316
317 //
318 // inherited functions from wxDataViewRenderer
319 //
320 virtual bool Render(void);
321
322 //
323 // implementation
324 //
325 virtual DataBrowserPropertyType GetPropertyType(void) const
326 {
327 return kDataBrowserProgressBarType;
328 }
329
330 protected:
331 private:
332 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
333 };
334
335 // ---------------------------------------------------------
336 // wxDataViewDateRenderer
337 // ---------------------------------------------------------
338
339 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
340 {
341 public:
342 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
343
344 //
345 // inherited functions from wxDataViewRenderer
346 //
347 virtual bool Render(void);
348
349 //
350 // implementation
351 //
352 virtual DataBrowserPropertyType GetPropertyType(void) const
353 {
354 return kDataBrowserDateTimeType;
355 }
356
357 protected:
358 private:
359 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
360 };
361
362 // ---------------------------------------------------------
363 // wxDataViewColumn
364 // ---------------------------------------------------------
365
366 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
367 {
368 public:
369 //
370 // constructors / destructor
371 //
372 wxDataViewColumn(wxString const& title, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
373 int flags=wxDATAVIEW_COL_RESIZABLE);
374 wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
375 int flags=wxDATAVIEW_COL_RESIZABLE);
376
377 //
378 // inherited methods from wxDataViewColumnBase
379 //
380 virtual wxAlignment GetAlignment(void) const
381 {
382 return this->m_alignment;
383 }
384 virtual int GetFlags(void) const
385 {
386 return this->m_flags;
387 }
388 virtual int GetMaxWidth(void) const
389 {
390 return this->m_maxWidth;
391 }
392 virtual int GetMinWidth(void) const
393 {
394 return this->m_minWidth;
395 }
396 virtual wxString GetTitle(void) const
397 {
398 return this->m_title;
399 }
400 virtual int GetWidth(void) const
401 {
402 return this->m_width;
403 }
404
405 virtual bool IsHidden(void) const
406 {
407 return false; // not implemented
408 }
409 virtual bool IsResizeable(void) const
410 {
411 return ((this->m_flags & wxDATAVIEW_COL_RESIZABLE) != 0);
412 }
413 virtual bool IsSortable(void) const
414 {
415 return ((this->m_flags & wxDATAVIEW_COL_SORTABLE) != 0);
416 }
417 virtual bool IsSortOrderAscending(void) const
418 {
419 return this->m_ascending;
420 }
421
422 virtual void SetAlignment(wxAlignment align);
423 virtual void SetBitmap (wxBitmap const& bitmap);
424 virtual void SetFlags (int flags);
425 virtual void SetHidden(bool WXUNUSED(hidden))
426 {
427 }
428 virtual void SetMaxWidth (int maxWidth);
429 virtual void SetMinWidth (int minWidth);
430 virtual void SetResizeable(bool resizeable);
431 virtual void SetSortable (bool sortable);
432 virtual void SetSortOrder (bool ascending);
433 virtual void SetTitle (wxString const& title);
434 virtual void SetWidth (int width);
435
436 //
437 // implementation
438 //
439 DataBrowserPropertyID GetPropertyID(void) const
440 {
441 return this->m_propertyID;
442 }
443
444 void SetPropertyID(DataBrowserPropertyID newID)
445 {
446 this->m_propertyID = newID;
447 }
448
449 protected:
450 private:
451 //
452 // variables
453 //
454 bool m_ascending; // sorting order
455
456 DataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
457
458 int m_flags; // flags for the column
459 int m_maxWidth; // maximum width for the column
460 int m_minWidth; // minimum width for the column
461 int m_width; // column width
462
463 wxAlignment m_alignment; // column header alignment
464
465 wxString m_title; // column title
466
467 // wxWidget internal stuff:
468 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
469 };
470
471 // ---------------------------------------------------------
472 // wxDataViewCtrl
473 // ---------------------------------------------------------
474
475 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
476 {
477 public:
478 // Constructors / destructor:
479 wxDataViewCtrl()
480 {
481 this->Init();
482 }
483 wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
484 wxValidator const& validator = wxDefaultValidator)
485 {
486 this->Init();
487 this->Create(parent, id, pos, size, style, validator );
488 }
489
490 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
491 wxValidator const& validator=wxDefaultValidator);
492
493 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
494
495 virtual bool AssociateModel(wxDataViewListModel* model);
496
497 virtual void SetSelection( int row ); // -1 for unselect
498 virtual void SetSelectionRange( unsigned int from, unsigned int to );
499 virtual void SetSelections( const wxArrayInt& aSelections);
500 virtual void Unselect( unsigned int row );
501
502 virtual bool IsSelected( unsigned int row ) const;
503 virtual int GetSelection() const;
504 virtual int GetSelections(wxArrayInt& aSelections) const;
505
506 virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
507 {
508 return this;
509 }
510
511 //
512 // implementation
513 //
514
515 // with CG, we need to get the context from an kEventControlDraw event
516 // unfortunately, the DataBrowser callbacks don't provide the context
517 // and we need it, so we need to set/remove it before and after draw
518 // events so we can access it in the callbacks.
519 void MacSetDrawingContext(void* context)
520 {
521 this->m_cgContext = context;
522 }
523 void* MacGetDrawingContext(void) const
524 {
525 return this->m_cgContext;
526 }
527
528 // reverts the sorting order of the hash map if wxDataViewColumn data and control data do not match;
529 // wxDataViewColumn data will NOT be updated
530 void ReverseSorting(DataBrowserPropertyID columnID);
531
532 protected:
533 // event handling:
534 void OnSize(wxSizeEvent &event);
535
536 private:
537 // initializing of local variables:
538 void Init(void);
539
540 ///
541 // variables
542 //
543
544 wxDataViewListModelNotifier* m_NotifierPtr; // the notifier is NOT owned by this class but by the associated model
545
546 void* m_cgContext; // pointer to core graphics context
547
548 // wxWidget internal stuff:
549 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
550 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
551 DECLARE_EVENT_TABLE()
552 };
553
554
555 #endif // __MACDATAVIEWCTRL_H__