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