]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/dataview.h
add support for asynchronous execution in wxBase (patch 1906889)
[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
c0a66d92
RR
146//
147// device context handling
148//
149 virtual wxDC* GetDC(void); // creates a device context and keeps it
150
151//
152// implementation
153//
154 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
c17b2e31 155 // return 'true' without having done anything
c0a66d92 156
594d5596 157 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c0a66d92
RR
158
159 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
160
161protected:
162private:
163//
164// variables
165//
166 wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
167
168 wxDC* m_DCPtr;
169
170//
171// wxWidget internal stuff
172//
173 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
174};
175
176// ---------------------------------------------------------
177// wxDataViewTextRenderer
178// ---------------------------------------------------------
179
180class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
181{
182public:
183//
184// constructors / destructor
185//
186 wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
187
188//
189// inherited functions from wxDataViewRenderer
190//
191 virtual bool Render(void);
192
193//
194// implementation
195//
594d5596 196 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c0a66d92
RR
197
198protected:
199private:
200 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
201};
202
4264606e
RR
203// ---------------------------------------------------------
204// wxDataViewTextRendererAttr
205// ---------------------------------------------------------
206
207class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
208{
209public:
210//
211// constructors / destructor
212//
213 wxDataViewTextRendererAttr(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
214
215private:
216 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
217};
218
c0a66d92
RR
219// ---------------------------------------------------------
220// wxDataViewBitmapRenderer
221// ---------------------------------------------------------
222
223class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
224{
225public:
226//
227// constructors / destructor
228//
229 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
230
231//
232// inherited functions from wxDataViewRenderer
233//
234 virtual bool Render(void);
235
236//
237// implementation
238//
594d5596 239 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c0a66d92
RR
240
241protected:
242private:
243 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
244};
245
246// ---------------------------------------------------------
247// wxDataViewToggleRenderer
248// ---------------------------------------------------------
249
c17b2e31
RR
250class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
251{
252public:
253 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
254
255//
256// inherited functions from wxDataViewRenderer
257//
258 virtual bool Render(void);
259
260//
261// implementation
262//
594d5596 263 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c17b2e31
RR
264
265protected:
266private:
267 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
268};
269
270// ---------------------------------------------------------
271// wxDataViewToggleRenderer
272// ---------------------------------------------------------
273
c0a66d92
RR
274class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
275{
276public:
277 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
278
279//
280// inherited functions from wxDataViewRenderer
281//
282 virtual bool Render(void);
283
284//
285// implementation
286//
594d5596 287 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c0a66d92
RR
288
289protected:
290private:
291 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
292};
293
294// ---------------------------------------------------------
295// wxDataViewProgressRenderer
296// ---------------------------------------------------------
297
298class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
299{
300public:
301 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
302 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
303
304//
305// inherited functions from wxDataViewRenderer
306//
307 virtual bool Render(void);
308
309//
310// implementation
311//
594d5596 312 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c0a66d92
RR
313
314protected:
315private:
316 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
317};
318
319// ---------------------------------------------------------
320// wxDataViewDateRenderer
321// ---------------------------------------------------------
322
323class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
324{
325public:
326 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
327
328//
329// inherited functions from wxDataViewRenderer
330//
331 virtual bool Render(void);
332
333//
334// implementation
335//
594d5596 336 virtual WXDataBrowserPropertyType GetPropertyType(void) const;
c0a66d92
RR
337
338protected:
339private:
340 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
341};
342
343// ---------------------------------------------------------
344// wxDataViewColumn
345// ---------------------------------------------------------
346
347class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
348{
349public:
350//
351// constructors / destructor
352//
353 wxDataViewColumn(wxString const& title, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
354 int flags=wxDATAVIEW_COL_RESIZABLE);
355 wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
356 int flags=wxDATAVIEW_COL_RESIZABLE);
357
358//
359// inherited methods from wxDataViewColumnBase
360//
361 virtual wxAlignment GetAlignment(void) const
362 {
363 return this->m_alignment;
364 }
365 virtual int GetFlags(void) const
366 {
367 return this->m_flags;
368 }
369 virtual int GetMaxWidth(void) const
370 {
371 return this->m_maxWidth;
372 }
373 virtual int GetMinWidth(void) const
374 {
375 return this->m_minWidth;
376 }
377 virtual wxString GetTitle(void) const
378 {
379 return this->m_title;
380 }
381 virtual int GetWidth(void) const
382 {
383 return this->m_width;
384 }
385
386 virtual bool IsHidden(void) const
387 {
388 return false; // not implemented
389 }
99c75ebc
RR
390 virtual bool IsReorderable(void) const
391 {
392 return ((this->m_flags & wxDATAVIEW_COL_REORDERABLE) != 0);
393 }
c0a66d92
RR
394 virtual bool IsResizeable(void) const
395 {
396 return ((this->m_flags & wxDATAVIEW_COL_RESIZABLE) != 0);
397 }
398 virtual bool IsSortable(void) const
399 {
400 return ((this->m_flags & wxDATAVIEW_COL_SORTABLE) != 0);
401 }
402 virtual bool IsSortOrderAscending(void) const
403 {
404 return this->m_ascending;
405 }
406
407 virtual void SetAlignment(wxAlignment align);
408 virtual void SetBitmap (wxBitmap const& bitmap);
409 virtual void SetFlags (int flags);
410 virtual void SetHidden(bool WXUNUSED(hidden))
411 {
412 }
99c75ebc
RR
413 virtual void SetMaxWidth (int maxWidth);
414 virtual void SetMinWidth (int minWidth);
415 virtual void SetReorderable(bool reorderable);
416 virtual void SetResizeable (bool resizeable);
417 virtual void SetSortable (bool sortable);
418 virtual void SetSortOrder (bool ascending);
419 virtual void SetTitle (wxString const& title);
420 virtual void SetWidth (int width);
c0a66d92
RR
421
422//
423// implementation
424//
34b1fdeb 425 WXDataBrowserPropertyID GetPropertyID() const
c0a66d92
RR
426 {
427 return this->m_propertyID;
428 }
429
34b1fdeb 430 void SetPropertyID(WXDataBrowserPropertyID newID)
c0a66d92
RR
431 {
432 this->m_propertyID = newID;
433 }
6d9ecc87
RR
434 void SetWidthVariable(int NewWidth)
435 {
436 this->m_width = NewWidth;
437 }
c0a66d92
RR
438
439protected:
440private:
441//
442// variables
443//
444 bool m_ascending; // sorting order
445
34b1fdeb 446 WXDataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
c0a66d92
RR
447
448 int m_flags; // flags for the column
449 int m_maxWidth; // maximum width for the column
450 int m_minWidth; // minimum width for the column
451 int m_width; // column width
452
453 wxAlignment m_alignment; // column header alignment
454
455 wxString m_title; // column title
456
457 // wxWidget internal stuff:
458 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
459};
460
461// ---------------------------------------------------------
462// wxDataViewCtrl
463// ---------------------------------------------------------
c0a66d92
RR
464class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
465{
466public:
467 // Constructors / destructor:
99c75ebc 468 wxDataViewCtrl(void)
194027ac
RR
469 {
470 this->Init();
471 }
472 wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
473 wxValidator const& validator = wxDefaultValidator)
474 {
475 this->Init();
476 this->Create(parent, id, pos, size, style, validator );
477 }
478
479 // explicit control creation
480 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
481 wxValidator const& validator=wxDefaultValidator);
482
194027ac
RR
483 virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
484 {
485 return this;
486 }
487
c17b2e31
RR
488 // inherited methods from 'wxDataViewCtrlBase':
489 virtual bool AssociateModel(wxDataViewModel* model);
490
491 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
492 virtual bool ClearColumns(void);
493 virtual bool DeleteColumn(wxDataViewColumn* columnPtr);
494 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
495 virtual unsigned int GetColumnCount(void) const;
6d9ecc87 496 virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const;
594d5596 497 virtual bool PrependColumn(wxDataViewColumn* columnPtr);
21f47fb9 498
c17b2e31 499 virtual void Collapse(wxDataViewItem const& item);
07c51ff1 500 virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr=NULL);
c17b2e31 501 virtual void Expand(wxDataViewItem const& item);
07c51ff1 502
6d9ecc87
RR
503 virtual wxDataViewColumn* GetSortingColumn(void) const;
504
b741dd40 505 virtual unsigned int GetCount(void) const;
07c51ff1
RR
506 virtual wxRect GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const;
507 virtual wxDataViewItem GetSelection(void) const;
508 virtual int GetSelections(wxDataViewItemArray& sel) const;
509
510 virtual void HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
511
512 virtual bool IsSelected(wxDataViewItem const& item) const;
513
514 virtual void SelectAll(void);
515 virtual void Select(wxDataViewItem const& item);
516 virtual void SetSelections(wxDataViewItemArray const& sel);
c0a66d92 517
07c51ff1
RR
518 virtual void Unselect(wxDataViewItem const& item);
519 virtual void UnselectAll(void);
c17b2e31 520
c0a66d92
RR
521//
522// implementation
523//
524
07c51ff1 525 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
194027ac
RR
526 void AddChildrenLevel(wxDataViewItem const& parentItem);
527
99c75ebc
RR
528 // finishes editing of custom items; if no custom item is currently edited the method does nothing
529 void FinishCustomItemEditing(void);
530
c17b2e31
RR
531 // returns a pointer to a column;
532 // in case the pointer cannot be found NULL is returned:
34b1fdeb 533 wxDataViewColumn* GetColumnPtr(WXDataBrowserPropertyID propertyID) const;
99c75ebc
RR
534 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
535 wxDataViewItem const& GetCustomRendererItem(void) const
536 {
537 return this->m_CustomRendererItem;
538 }
539 // returns a pointer to a customized renderer (this pointer is only valid during editing)
540 wxDataViewCustomRenderer* GetCustomRendererPtr(void) const
541 {
542 return this->m_CustomRendererPtr;
543 }
c17b2e31 544
07c51ff1
RR
545 // checks if currently a delete process is running:
546 bool IsDeleting(void) const
547 {
548 return this->m_Deleting;
549 }
550
c0a66d92
RR
551 // with CG, we need to get the context from an kEventControlDraw event
552 // unfortunately, the DataBrowser callbacks don't provide the context
553 // and we need it, so we need to set/remove it before and after draw
554 // events so we can access it in the callbacks.
555 void MacSetDrawingContext(void* context)
556 {
557 this->m_cgContext = context;
558 }
559 void* MacGetDrawingContext(void) const
560 {
561 return this->m_cgContext;
562 }
563
99c75ebc
RR
564 // sets the currently being edited item of the custom renderer
565 void SetCustomRendererItem(wxDataViewItem const& NewItem)
566 {
567 this->m_CustomRendererItem = NewItem;
568 }
569 // sets the custom renderer
570 void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
571 {
572 this->m_CustomRendererPtr = NewCustomRendererPtr;
573 }
574 // sets the flag indicating a deletion process:
07c51ff1
RR
575 void SetDeleting(bool deleting)
576 {
577 this->m_Deleting = deleting;
578 }
579
4bff335a
VS
580 virtual wxVisualAttributes GetDefaultAttributes() const
581 {
582 return GetClassDefaultAttributes(GetWindowVariant());
583 }
584
585 static wxVisualAttributes
586 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
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
99c75ebc
RR
612
613 wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
07c51ff1 614
99c75ebc
RR
615 wxDataViewItem m_CustomRendererItem; // currently edited item by the customerenderer; it is invalid while not editing
616
c17b2e31 617 ColumnPointerHashMapType m_ColumnPointers; // all column pointers are stored in a hash map with the property ID as a key
c0a66d92
RR
618
619 // wxWidget internal stuff:
620 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
621 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
622 DECLARE_EVENT_TABLE()
623};
624
625
34b1fdeb 626#endif // _WX_MACCARBONDATAVIEWCTRL_H_