]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/dataview.h
fix memory leak in the usage example
[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_FWD_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 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
122
123 //
124 // methods handling render space
125 //
126 virtual wxSize GetSize() const = 0;
127
128 //
129 // methods handling user actions
130 //
131 virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
132
133 virtual bool Activate(wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
134 {
135 return false;
136 }
137
138 virtual bool LeftClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
139 {
140 return false;
141 }
142
143 virtual bool RightClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
144 {
145 return false;
146 }
147
148 virtual bool StartDrag(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
149 {
150 return false;
151 }
152
153 //
154 // in-place editing
155 //
156 virtual void CancelEditing()
157 {
158 }
159
160 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), wxRect WXUNUSED(labelRect), const wxVariant& WXUNUSED(value))
161 {
162 return NULL;
163 }
164
165 virtual bool FinishEditing()
166 {
167 return false;
168 }
169
170 wxControl* GetEditorCtrl(void) const
171 {
172 return this->m_editorCtrlPtr;
173 }
174 virtual bool GetValueFromEditorCtrl(wxControl* WXUNUSED(editor), wxVariant& WXUNUSED(value))
175 {
176 return false;
177 }
178
179 virtual bool HasEditorCtrl(void)
180 {
181 return false;
182 }
183
184 virtual bool StartEditing(wxDataViewItem const& WXUNUSED(item), wxRect WXUNUSED(labelRect))
185 {
186 return false;
187 }
188
189 //
190 // device context handling
191 //
192 virtual wxDC* GetDC(void); // creates a device context and keeps it
193
194 //
195 // implementation
196 //
197 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
198 // return 'true' without having done anything
199
200 virtual DataBrowserPropertyType GetPropertyType(void) const
201 {
202 return kDataBrowserCustomType;
203 }
204
205 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
206
207 protected:
208 private:
209 //
210 // variables
211 //
212 wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
213
214 wxDC* m_DCPtr;
215
216 //
217 // wxWidget internal stuff
218 //
219 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
220 };
221
222 // ---------------------------------------------------------
223 // wxDataViewTextRenderer
224 // ---------------------------------------------------------
225
226 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
227 {
228 public:
229 //
230 // constructors / destructor
231 //
232 wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
233
234 //
235 // inherited functions from wxDataViewRenderer
236 //
237 virtual bool Render(void);
238
239 //
240 // implementation
241 //
242 virtual DataBrowserPropertyType GetPropertyType(void) const
243 {
244 return kDataBrowserTextType;
245 }
246
247 protected:
248 private:
249 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
250 };
251
252 // ---------------------------------------------------------
253 // wxDataViewBitmapRenderer
254 // ---------------------------------------------------------
255
256 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
257 {
258 public:
259 //
260 // constructors / destructor
261 //
262 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
263
264 //
265 // inherited functions from wxDataViewRenderer
266 //
267 virtual bool Render(void);
268
269 //
270 // implementation
271 //
272 virtual DataBrowserPropertyType GetPropertyType(void) const
273 {
274 return kDataBrowserIconType;
275 }
276
277 protected:
278 private:
279 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
280 };
281
282 // ---------------------------------------------------------
283 // wxDataViewToggleRenderer
284 // ---------------------------------------------------------
285
286 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
287 {
288 public:
289 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
290
291 //
292 // inherited functions from wxDataViewRenderer
293 //
294 virtual bool Render(void);
295
296 //
297 // implementation
298 //
299 virtual DataBrowserPropertyType GetPropertyType(void) const
300 {
301 return kDataBrowserIconAndTextType;
302 }
303
304 protected:
305 private:
306 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
307 };
308
309 // ---------------------------------------------------------
310 // wxDataViewToggleRenderer
311 // ---------------------------------------------------------
312
313 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
314 {
315 public:
316 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
317
318 //
319 // inherited functions from wxDataViewRenderer
320 //
321 virtual bool Render(void);
322
323 //
324 // implementation
325 //
326 virtual DataBrowserPropertyType GetPropertyType(void) const
327 {
328 return kDataBrowserCheckboxType;
329 }
330
331 protected:
332 private:
333 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
334 };
335
336 // ---------------------------------------------------------
337 // wxDataViewProgressRenderer
338 // ---------------------------------------------------------
339
340 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
341 {
342 public:
343 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
344 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
345
346 //
347 // inherited functions from wxDataViewRenderer
348 //
349 virtual bool Render(void);
350
351 //
352 // implementation
353 //
354 virtual DataBrowserPropertyType GetPropertyType(void) const
355 {
356 return kDataBrowserProgressBarType;
357 }
358
359 protected:
360 private:
361 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
362 };
363
364 // ---------------------------------------------------------
365 // wxDataViewDateRenderer
366 // ---------------------------------------------------------
367
368 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
369 {
370 public:
371 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
372
373 //
374 // inherited functions from wxDataViewRenderer
375 //
376 virtual bool Render(void);
377
378 //
379 // implementation
380 //
381 virtual DataBrowserPropertyType GetPropertyType(void) const
382 {
383 return kDataBrowserDateTimeType;
384 }
385
386 protected:
387 private:
388 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
389 };
390
391 // ---------------------------------------------------------
392 // wxDataViewColumn
393 // ---------------------------------------------------------
394
395 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
396 {
397 public:
398 //
399 // constructors / destructor
400 //
401 wxDataViewColumn(wxString const& title, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
402 int flags=wxDATAVIEW_COL_RESIZABLE);
403 wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
404 int flags=wxDATAVIEW_COL_RESIZABLE);
405
406 //
407 // inherited methods from wxDataViewColumnBase
408 //
409 virtual wxAlignment GetAlignment(void) const
410 {
411 return this->m_alignment;
412 }
413 virtual int GetFlags(void) const
414 {
415 return this->m_flags;
416 }
417 virtual int GetMaxWidth(void) const
418 {
419 return this->m_maxWidth;
420 }
421 virtual int GetMinWidth(void) const
422 {
423 return this->m_minWidth;
424 }
425 virtual wxString GetTitle(void) const
426 {
427 return this->m_title;
428 }
429 virtual int GetWidth(void) const
430 {
431 return this->m_width;
432 }
433
434 virtual bool IsHidden(void) const
435 {
436 return false; // not implemented
437 }
438 virtual bool IsResizeable(void) const
439 {
440 return ((this->m_flags & wxDATAVIEW_COL_RESIZABLE) != 0);
441 }
442 virtual bool IsSortable(void) const
443 {
444 return ((this->m_flags & wxDATAVIEW_COL_SORTABLE) != 0);
445 }
446 virtual bool IsSortOrderAscending(void) const
447 {
448 return this->m_ascending;
449 }
450
451 virtual void SetAlignment(wxAlignment align);
452 virtual void SetBitmap (wxBitmap const& bitmap);
453 virtual void SetFlags (int flags);
454 virtual void SetHidden(bool WXUNUSED(hidden))
455 {
456 }
457 virtual void SetMaxWidth (int maxWidth);
458 virtual void SetMinWidth (int minWidth);
459 virtual void SetResizeable(bool resizeable);
460 virtual void SetSortable (bool sortable);
461 virtual void SetSortOrder (bool ascending);
462 virtual void SetTitle (wxString const& title);
463 virtual void SetWidth (int width);
464
465 //
466 // implementation
467 //
468 DataBrowserPropertyID GetPropertyID(void) const
469 {
470 return this->m_propertyID;
471 }
472
473 void SetPropertyID(DataBrowserPropertyID newID)
474 {
475 this->m_propertyID = newID;
476 }
477 void SetWidthVariable(int NewWidth)
478 {
479 this->m_width = NewWidth;
480 }
481
482 protected:
483 private:
484 //
485 // variables
486 //
487 bool m_ascending; // sorting order
488
489 DataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
490
491 int m_flags; // flags for the column
492 int m_maxWidth; // maximum width for the column
493 int m_minWidth; // minimum width for the column
494 int m_width; // column width
495
496 wxAlignment m_alignment; // column header alignment
497
498 wxString m_title; // column title
499
500 // wxWidget internal stuff:
501 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
502 };
503
504 // ---------------------------------------------------------
505 // wxDataViewCtrl
506 // ---------------------------------------------------------
507 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
508 {
509 public:
510 // Constructors / destructor:
511 wxDataViewCtrl()
512 {
513 this->Init();
514 }
515 wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
516 wxValidator const& validator = wxDefaultValidator)
517 {
518 this->Init();
519 this->Create(parent, id, pos, size, style, validator );
520 }
521
522 // explicit control creation
523 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
524 wxValidator const& validator=wxDefaultValidator);
525
526 virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
527 {
528 return this;
529 }
530
531 // inherited methods from 'wxDataViewCtrlBase':
532 virtual bool AssociateModel(wxDataViewModel* model);
533
534 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
535 virtual bool ClearColumns(void);
536 virtual bool DeleteColumn(wxDataViewColumn* columnPtr);
537 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
538 virtual unsigned int GetColumnCount(void) const;
539 virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const;
540
541 virtual void Collapse(wxDataViewItem const& item);
542 virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr=NULL);
543 virtual void Expand(wxDataViewItem const& item);
544
545 virtual wxDataViewColumn* GetSortingColumn(void) const;
546
547 virtual unsigned int GetCount(void) const;
548 virtual wxRect GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const;
549 virtual wxDataViewItem GetSelection(void) const;
550 virtual int GetSelections(wxDataViewItemArray& sel) const;
551
552 virtual void HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
553
554 virtual bool IsSelected(wxDataViewItem const& item) const;
555
556 virtual void SelectAll(void);
557 virtual void Select(wxDataViewItem const& item);
558 virtual void SetSelections(wxDataViewItemArray const& sel);
559
560 virtual void Unselect(wxDataViewItem const& item);
561 virtual void UnselectAll(void);
562
563 //
564 // implementation
565 //
566
567 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
568 void AddChildrenLevel(wxDataViewItem const& parentItem);
569
570 // returns a pointer to a column;
571 // in case the pointer cannot be found NULL is returned:
572 wxDataViewColumn* GetColumnPtr(DataBrowserPropertyID propertyID) const;
573
574 // checks if currently a delete process is running:
575 bool IsDeleting(void) const
576 {
577 return this->m_Deleting;
578 }
579
580 // with CG, we need to get the context from an kEventControlDraw event
581 // unfortunately, the DataBrowser callbacks don't provide the context
582 // and we need it, so we need to set/remove it before and after draw
583 // events so we can access it in the callbacks.
584 void MacSetDrawingContext(void* context)
585 {
586 this->m_cgContext = context;
587 }
588 void* MacGetDrawingContext(void) const
589 {
590 return this->m_cgContext;
591 }
592
593 /// sets the flag indicating a deletion process:
594 void SetDeleting(bool deleting)
595 {
596 this->m_Deleting = deleting;
597 }
598
599 protected:
600 // inherited methods from wxDataViewCtrlBase:
601 virtual void DoSetExpanderColumn(void);
602 virtual void DoSetIndent(void);
603
604 // event handling:
605 void OnSize(wxSizeEvent &event);
606
607 private:
608 // type definitions:
609 WX_DECLARE_HASH_MAP(DataBrowserPropertyID,wxDataViewColumn*,wxIntegerHash,wxIntegerEqual,ColumnPointerHashMapType);
610
611 // initializing of local variables:
612 void Init(void);
613
614 ///
615 // variables
616 //
617
618 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
619 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
620 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
621
622 void* m_cgContext; // pointer to core graphics context
623
624 ColumnPointerHashMapType m_ColumnPointers; // all column pointers are stored in a hash map with the property ID as a key
625
626 // wxWidget internal stuff:
627 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
628 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
629 DECLARE_EVENT_TABLE()
630 };
631
632
633 #endif // __MACDATAVIEWCTRL_H__