]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/dataview.h
suppress (harmless) gcc warning about non-virtual dtor in a class with virtual functions
[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 _WX_MACCARBONDATAVIEWCTRL_H_
11 #define _WX_MACCARBONDATAVIEWCTRL_H_
12
13 typedef void* DataBrowserItemDataRef;
14 typedef unsigned long WXDataBrowserPropertyType;
15 typedef wxUint32 WXDataBrowserPropertyID;
16
17 // ---------------------------------------------------------
18 // wxDataViewRenderer
19 // ---------------------------------------------------------
20
21 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
22 {
23 public:
24 //
25 // constructors / destructor
26 //
27 wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
28
29 //
30 // inherited methods from wxDataViewRendererBase
31 //
32 virtual int GetAlignment(void) const
33 {
34 return this->m_alignment;
35 }
36 virtual wxDataViewCellMode GetMode(void) const
37 {
38 return this->m_mode;
39 }
40 virtual bool GetValue(wxVariant& value) const
41 {
42 value = this->m_value;
43 return true;
44 }
45
46 virtual void SetAlignment(int WXUNUSED(align)) // is always identical to the header alignment
47 {
48 }
49 virtual void SetMode(wxDataViewCellMode mode);
50 virtual bool SetValue(wxVariant const& newValue)
51 {
52 this->m_value = newValue;
53 return true;
54 }
55
56 //
57 // implementation
58 //
59 DataBrowserItemDataRef GetDataReference(void) const
60 {
61 return this->m_dataReference;
62 }
63 wxVariant const& GetValue(void) const
64 {
65 return this->m_value;
66 }
67
68 virtual WXDataBrowserPropertyType GetPropertyType() const = 0;
69
70 virtual bool Render(void) = 0; // a call to the appropriate data browser function filling the data reference with the stored datum;
71 // returns 'true' if the data value could be rendered, 'false' otherwise
72
73 void SetDataReference(DataBrowserItemDataRef const& newDataReference)
74 {
75 this->m_dataReference = newDataReference;
76 }
77
78 private:
79 //
80 // variables
81 //
82 DataBrowserItemDataRef m_dataReference; // data reference of the data browser; the data will be assigned to this reference during rendering
83
84 int m_alignment; // contains the alignment flags
85
86 wxDataViewCellMode m_mode; // storing the mode that determines how the cell is going to be shown
87
88 wxVariant m_value; // value that is going to be rendered
89
90 //
91 // wxWidget internal stuff
92 //
93 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
94 };
95
96 // ---------------------------------------------------------
97 // wxDataViewCustomRenderer
98 // ---------------------------------------------------------
99
100 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
101 {
102 public:
103 //
104 // constructors / destructor
105 //
106 wxDataViewCustomRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
107
108 virtual ~wxDataViewCustomRenderer(void);
109
110 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
111
112 //
113 // methods handling render space
114 //
115 virtual wxSize GetSize() const = 0;
116
117 //
118 // methods handling user actions
119 //
120 virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
121
122 virtual bool Activate(wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
123 {
124 return false;
125 }
126
127 virtual bool LeftClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
128 {
129 return false;
130 }
131
132 virtual bool RightClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
133 {
134 return false;
135 }
136
137 virtual bool StartDrag(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
138 {
139 return false;
140 }
141
142 //
143 // in-place editing
144 //
145 virtual void CancelEditing()
146 {
147 }
148
149 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), wxRect WXUNUSED(labelRect), const wxVariant& WXUNUSED(value))
150 {
151 return NULL;
152 }
153
154 virtual bool FinishEditing()
155 {
156 return false;
157 }
158
159 wxControl* GetEditorCtrl(void) const
160 {
161 return this->m_editorCtrlPtr;
162 }
163 virtual bool GetValueFromEditorCtrl(wxControl* WXUNUSED(editor), wxVariant& WXUNUSED(value))
164 {
165 return false;
166 }
167
168 virtual bool HasEditorCtrl(void)
169 {
170 return false;
171 }
172
173 virtual bool StartEditing(wxDataViewItem const& WXUNUSED(item), wxRect WXUNUSED(labelRect))
174 {
175 return false;
176 }
177
178 //
179 // device context handling
180 //
181 virtual wxDC* GetDC(void); // creates a device context and keeps it
182
183 //
184 // implementation
185 //
186 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
187 // return 'true' without having done anything
188
189 virtual WXDataBrowserPropertyType GetPropertyType() const;
190
191 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
192
193 protected:
194 private:
195 //
196 // variables
197 //
198 wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
199
200 wxDC* m_DCPtr;
201
202 //
203 // wxWidget internal stuff
204 //
205 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
206 };
207
208 // ---------------------------------------------------------
209 // wxDataViewTextRenderer
210 // ---------------------------------------------------------
211
212 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
213 {
214 public:
215 //
216 // constructors / destructor
217 //
218 wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
219
220 //
221 // inherited functions from wxDataViewRenderer
222 //
223 virtual bool Render(void);
224
225 //
226 // implementation
227 //
228 virtual WXDataBrowserPropertyType GetPropertyType() const;
229
230 protected:
231 private:
232 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
233 };
234
235 // ---------------------------------------------------------
236 // wxDataViewBitmapRenderer
237 // ---------------------------------------------------------
238
239 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
240 {
241 public:
242 //
243 // constructors / destructor
244 //
245 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
246
247 //
248 // inherited functions from wxDataViewRenderer
249 //
250 virtual bool Render(void);
251
252 //
253 // implementation
254 //
255 virtual WXDataBrowserPropertyType GetPropertyType() const;
256
257 protected:
258 private:
259 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
260 };
261
262 // ---------------------------------------------------------
263 // wxDataViewToggleRenderer
264 // ---------------------------------------------------------
265
266 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
267 {
268 public:
269 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
270
271 //
272 // inherited functions from wxDataViewRenderer
273 //
274 virtual bool Render(void);
275
276 //
277 // implementation
278 //
279 virtual WXDataBrowserPropertyType GetPropertyType() const;
280
281 protected:
282 private:
283 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
284 };
285
286 // ---------------------------------------------------------
287 // wxDataViewToggleRenderer
288 // ---------------------------------------------------------
289
290 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
291 {
292 public:
293 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
294
295 //
296 // inherited functions from wxDataViewRenderer
297 //
298 virtual bool Render(void);
299
300 //
301 // implementation
302 //
303 virtual WXDataBrowserPropertyType GetPropertyType() const;
304
305 protected:
306 private:
307 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
308 };
309
310 // ---------------------------------------------------------
311 // wxDataViewProgressRenderer
312 // ---------------------------------------------------------
313
314 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
315 {
316 public:
317 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
318 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
319
320 //
321 // inherited functions from wxDataViewRenderer
322 //
323 virtual bool Render(void);
324
325 //
326 // implementation
327 //
328 virtual WXDataBrowserPropertyType GetPropertyType() const;
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 WXDataBrowserPropertyType GetPropertyType() const;
353
354 protected:
355 private:
356 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
357 };
358
359 // ---------------------------------------------------------
360 // wxDataViewColumn
361 // ---------------------------------------------------------
362
363 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
364 {
365 public:
366 //
367 // constructors / destructor
368 //
369 wxDataViewColumn(wxString const& title, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
370 int flags=wxDATAVIEW_COL_RESIZABLE);
371 wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
372 int flags=wxDATAVIEW_COL_RESIZABLE);
373
374 //
375 // inherited methods from wxDataViewColumnBase
376 //
377 virtual wxAlignment GetAlignment(void) const
378 {
379 return this->m_alignment;
380 }
381 virtual int GetFlags(void) const
382 {
383 return this->m_flags;
384 }
385 virtual int GetMaxWidth(void) const
386 {
387 return this->m_maxWidth;
388 }
389 virtual int GetMinWidth(void) const
390 {
391 return this->m_minWidth;
392 }
393 virtual wxString GetTitle(void) const
394 {
395 return this->m_title;
396 }
397 virtual int GetWidth(void) const
398 {
399 return this->m_width;
400 }
401
402 virtual bool IsHidden(void) const
403 {
404 return false; // not implemented
405 }
406 virtual bool IsResizeable(void) const
407 {
408 return ((this->m_flags & wxDATAVIEW_COL_RESIZABLE) != 0);
409 }
410 virtual bool IsSortable(void) const
411 {
412 return ((this->m_flags & wxDATAVIEW_COL_SORTABLE) != 0);
413 }
414 virtual bool IsSortOrderAscending(void) const
415 {
416 return this->m_ascending;
417 }
418
419 virtual void SetAlignment(wxAlignment align);
420 virtual void SetBitmap (wxBitmap const& bitmap);
421 virtual void SetFlags (int flags);
422 virtual void SetHidden(bool WXUNUSED(hidden))
423 {
424 }
425 virtual void SetMaxWidth (int maxWidth);
426 virtual void SetMinWidth (int minWidth);
427 virtual void SetResizeable(bool resizeable);
428 virtual void SetSortable (bool sortable);
429 virtual void SetSortOrder (bool ascending);
430 virtual void SetTitle (wxString const& title);
431 virtual void SetWidth (int width);
432
433 //
434 // implementation
435 //
436 WXDataBrowserPropertyID GetPropertyID() const
437 {
438 return this->m_propertyID;
439 }
440
441 void SetPropertyID(WXDataBrowserPropertyID newID)
442 {
443 this->m_propertyID = newID;
444 }
445 void SetWidthVariable(int NewWidth)
446 {
447 this->m_width = NewWidth;
448 }
449
450 protected:
451 private:
452 //
453 // variables
454 //
455 bool m_ascending; // sorting order
456
457 WXDataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
458
459 int m_flags; // flags for the column
460 int m_maxWidth; // maximum width for the column
461 int m_minWidth; // minimum width for the column
462 int m_width; // column width
463
464 wxAlignment m_alignment; // column header alignment
465
466 wxString m_title; // column title
467
468 // wxWidget internal stuff:
469 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
470 };
471
472 // ---------------------------------------------------------
473 // wxDataViewCtrl
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 // explicit control creation
491 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
492 wxValidator const& validator=wxDefaultValidator);
493
494 virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
495 {
496 return this;
497 }
498
499 // inherited methods from 'wxDataViewCtrlBase':
500 virtual bool AssociateModel(wxDataViewModel* model);
501
502 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
503 virtual bool ClearColumns(void);
504 virtual bool DeleteColumn(wxDataViewColumn* columnPtr);
505 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
506 virtual unsigned int GetColumnCount(void) const;
507 virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const;
508
509 virtual void Collapse(wxDataViewItem const& item);
510 virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr=NULL);
511 virtual void Expand(wxDataViewItem const& item);
512
513 virtual wxDataViewColumn* GetSortingColumn(void) const;
514
515 virtual unsigned int GetCount(void) const;
516 virtual wxRect GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const;
517 virtual wxDataViewItem GetSelection(void) const;
518 virtual int GetSelections(wxDataViewItemArray& sel) const;
519
520 virtual void HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
521
522 virtual bool IsSelected(wxDataViewItem const& item) const;
523
524 virtual void SelectAll(void);
525 virtual void Select(wxDataViewItem const& item);
526 virtual void SetSelections(wxDataViewItemArray const& sel);
527
528 virtual void Unselect(wxDataViewItem const& item);
529 virtual void UnselectAll(void);
530
531 //
532 // implementation
533 //
534
535 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
536 void AddChildrenLevel(wxDataViewItem const& parentItem);
537
538 // returns a pointer to a column;
539 // in case the pointer cannot be found NULL is returned:
540 wxDataViewColumn* GetColumnPtr(WXDataBrowserPropertyID propertyID) const;
541
542 // checks if currently a delete process is running:
543 bool IsDeleting(void) const
544 {
545 return this->m_Deleting;
546 }
547
548 // with CG, we need to get the context from an kEventControlDraw event
549 // unfortunately, the DataBrowser callbacks don't provide the context
550 // and we need it, so we need to set/remove it before and after draw
551 // events so we can access it in the callbacks.
552 void MacSetDrawingContext(void* context)
553 {
554 this->m_cgContext = context;
555 }
556 void* MacGetDrawingContext(void) const
557 {
558 return this->m_cgContext;
559 }
560
561 /// sets the flag indicating a deletion process:
562 void SetDeleting(bool deleting)
563 {
564 this->m_Deleting = deleting;
565 }
566
567 protected:
568 // inherited methods from wxDataViewCtrlBase:
569 virtual void DoSetExpanderColumn(void);
570 virtual void DoSetIndent(void);
571
572 // event handling:
573 void OnSize(wxSizeEvent &event);
574
575 private:
576 // type definitions:
577 WX_DECLARE_HASH_MAP(WXDataBrowserPropertyID,wxDataViewColumn*,wxIntegerHash,wxIntegerEqual,ColumnPointerHashMapType);
578
579 // initializing of local variables:
580 void Init(void);
581
582 ///
583 // variables
584 //
585
586 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
587 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
588 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
589
590 void* m_cgContext; // pointer to core graphics context
591
592 ColumnPointerHashMapType m_ColumnPointers; // all column pointers are stored in a hash map with the property ID as a key
593
594 // wxWidget internal stuff:
595 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
596 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
597 DECLARE_EVENT_TABLE()
598 };
599
600
601 #endif // _WX_MACCARBONDATAVIEWCTRL_H_