]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/dataview.h
Add wxDataViewTextRendererAttr, blind noop under wxMac
[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 // wxDataViewTextRendererAttr
237 // ---------------------------------------------------------
238
239 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
240 {
241 public:
242 //
243 // constructors / destructor
244 //
245 wxDataViewTextRendererAttr(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
246
247 private:
248 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
249 };
250
251 // ---------------------------------------------------------
252 // wxDataViewBitmapRenderer
253 // ---------------------------------------------------------
254
255 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
256 {
257 public:
258 //
259 // constructors / destructor
260 //
261 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
262
263 //
264 // inherited functions from wxDataViewRenderer
265 //
266 virtual bool Render(void);
267
268 //
269 // implementation
270 //
271 virtual WXDataBrowserPropertyType GetPropertyType() const;
272
273 protected:
274 private:
275 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
276 };
277
278 // ---------------------------------------------------------
279 // wxDataViewToggleRenderer
280 // ---------------------------------------------------------
281
282 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
283 {
284 public:
285 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
286
287 //
288 // inherited functions from wxDataViewRenderer
289 //
290 virtual bool Render(void);
291
292 //
293 // implementation
294 //
295 virtual WXDataBrowserPropertyType GetPropertyType() const;
296
297 protected:
298 private:
299 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
300 };
301
302 // ---------------------------------------------------------
303 // wxDataViewToggleRenderer
304 // ---------------------------------------------------------
305
306 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
307 {
308 public:
309 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
310
311 //
312 // inherited functions from wxDataViewRenderer
313 //
314 virtual bool Render(void);
315
316 //
317 // implementation
318 //
319 virtual WXDataBrowserPropertyType GetPropertyType() const;
320
321 protected:
322 private:
323 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
324 };
325
326 // ---------------------------------------------------------
327 // wxDataViewProgressRenderer
328 // ---------------------------------------------------------
329
330 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
331 {
332 public:
333 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
334 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
335
336 //
337 // inherited functions from wxDataViewRenderer
338 //
339 virtual bool Render(void);
340
341 //
342 // implementation
343 //
344 virtual WXDataBrowserPropertyType GetPropertyType() const;
345
346 protected:
347 private:
348 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
349 };
350
351 // ---------------------------------------------------------
352 // wxDataViewDateRenderer
353 // ---------------------------------------------------------
354
355 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
356 {
357 public:
358 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
359
360 //
361 // inherited functions from wxDataViewRenderer
362 //
363 virtual bool Render(void);
364
365 //
366 // implementation
367 //
368 virtual WXDataBrowserPropertyType GetPropertyType() const;
369
370 protected:
371 private:
372 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
373 };
374
375 // ---------------------------------------------------------
376 // wxDataViewColumn
377 // ---------------------------------------------------------
378
379 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
380 {
381 public:
382 //
383 // constructors / destructor
384 //
385 wxDataViewColumn(wxString const& title, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
386 int flags=wxDATAVIEW_COL_RESIZABLE);
387 wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
388 int flags=wxDATAVIEW_COL_RESIZABLE);
389
390 //
391 // inherited methods from wxDataViewColumnBase
392 //
393 virtual wxAlignment GetAlignment(void) const
394 {
395 return this->m_alignment;
396 }
397 virtual int GetFlags(void) const
398 {
399 return this->m_flags;
400 }
401 virtual int GetMaxWidth(void) const
402 {
403 return this->m_maxWidth;
404 }
405 virtual int GetMinWidth(void) const
406 {
407 return this->m_minWidth;
408 }
409 virtual wxString GetTitle(void) const
410 {
411 return this->m_title;
412 }
413 virtual int GetWidth(void) const
414 {
415 return this->m_width;
416 }
417
418 virtual bool IsHidden(void) const
419 {
420 return false; // not implemented
421 }
422 virtual bool IsResizeable(void) const
423 {
424 return ((this->m_flags & wxDATAVIEW_COL_RESIZABLE) != 0);
425 }
426 virtual bool IsSortable(void) const
427 {
428 return ((this->m_flags & wxDATAVIEW_COL_SORTABLE) != 0);
429 }
430 virtual bool IsSortOrderAscending(void) const
431 {
432 return this->m_ascending;
433 }
434
435 virtual void SetAlignment(wxAlignment align);
436 virtual void SetBitmap (wxBitmap const& bitmap);
437 virtual void SetFlags (int flags);
438 virtual void SetHidden(bool WXUNUSED(hidden))
439 {
440 }
441 virtual void SetMaxWidth (int maxWidth);
442 virtual void SetMinWidth (int minWidth);
443 virtual void SetResizeable(bool resizeable);
444 virtual void SetSortable (bool sortable);
445 virtual void SetSortOrder (bool ascending);
446 virtual void SetTitle (wxString const& title);
447 virtual void SetWidth (int width);
448
449 //
450 // implementation
451 //
452 WXDataBrowserPropertyID GetPropertyID() const
453 {
454 return this->m_propertyID;
455 }
456
457 void SetPropertyID(WXDataBrowserPropertyID newID)
458 {
459 this->m_propertyID = newID;
460 }
461 void SetWidthVariable(int NewWidth)
462 {
463 this->m_width = NewWidth;
464 }
465
466 protected:
467 private:
468 //
469 // variables
470 //
471 bool m_ascending; // sorting order
472
473 WXDataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
474
475 int m_flags; // flags for the column
476 int m_maxWidth; // maximum width for the column
477 int m_minWidth; // minimum width for the column
478 int m_width; // column width
479
480 wxAlignment m_alignment; // column header alignment
481
482 wxString m_title; // column title
483
484 // wxWidget internal stuff:
485 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
486 };
487
488 // ---------------------------------------------------------
489 // wxDataViewCtrl
490 // ---------------------------------------------------------
491 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
492 {
493 public:
494 // Constructors / destructor:
495 wxDataViewCtrl()
496 {
497 this->Init();
498 }
499 wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
500 wxValidator const& validator = wxDefaultValidator)
501 {
502 this->Init();
503 this->Create(parent, id, pos, size, style, validator );
504 }
505
506 // explicit control creation
507 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
508 wxValidator const& validator=wxDefaultValidator);
509
510 virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
511 {
512 return this;
513 }
514
515 // inherited methods from 'wxDataViewCtrlBase':
516 virtual bool AssociateModel(wxDataViewModel* model);
517
518 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
519 virtual bool ClearColumns(void);
520 virtual bool DeleteColumn(wxDataViewColumn* columnPtr);
521 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
522 virtual unsigned int GetColumnCount(void) const;
523 virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const;
524
525 virtual void Collapse(wxDataViewItem const& item);
526 virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr=NULL);
527 virtual void Expand(wxDataViewItem const& item);
528
529 virtual wxDataViewColumn* GetSortingColumn(void) const;
530
531 virtual unsigned int GetCount(void) const;
532 virtual wxRect GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const;
533 virtual wxDataViewItem GetSelection(void) const;
534 virtual int GetSelections(wxDataViewItemArray& sel) const;
535
536 virtual void HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
537
538 virtual bool IsSelected(wxDataViewItem const& item) const;
539
540 virtual void SelectAll(void);
541 virtual void Select(wxDataViewItem const& item);
542 virtual void SetSelections(wxDataViewItemArray const& sel);
543
544 virtual void Unselect(wxDataViewItem const& item);
545 virtual void UnselectAll(void);
546
547 //
548 // implementation
549 //
550
551 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
552 void AddChildrenLevel(wxDataViewItem const& parentItem);
553
554 // returns a pointer to a column;
555 // in case the pointer cannot be found NULL is returned:
556 wxDataViewColumn* GetColumnPtr(WXDataBrowserPropertyID propertyID) const;
557
558 // checks if currently a delete process is running:
559 bool IsDeleting(void) const
560 {
561 return this->m_Deleting;
562 }
563
564 // with CG, we need to get the context from an kEventControlDraw event
565 // unfortunately, the DataBrowser callbacks don't provide the context
566 // and we need it, so we need to set/remove it before and after draw
567 // events so we can access it in the callbacks.
568 void MacSetDrawingContext(void* context)
569 {
570 this->m_cgContext = context;
571 }
572 void* MacGetDrawingContext(void) const
573 {
574 return this->m_cgContext;
575 }
576
577 /// sets the flag indicating a deletion process:
578 void SetDeleting(bool deleting)
579 {
580 this->m_Deleting = deleting;
581 }
582
583 protected:
584 // inherited methods from wxDataViewCtrlBase:
585 virtual void DoSetExpanderColumn(void);
586 virtual void DoSetIndent(void);
587
588 // event handling:
589 void OnSize(wxSizeEvent &event);
590
591 private:
592 // type definitions:
593 WX_DECLARE_HASH_MAP(WXDataBrowserPropertyID,wxDataViewColumn*,wxIntegerHash,wxIntegerEqual,ColumnPointerHashMapType);
594
595 // initializing of local variables:
596 void Init(void);
597
598 ///
599 // variables
600 //
601
602 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
603 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
604 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
605
606 void* m_cgContext; // pointer to core graphics context
607
608 ColumnPointerHashMapType m_ColumnPointers; // all column pointers are stored in a hash map with the property ID as a key
609
610 // wxWidget internal stuff:
611 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
612 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
613 DECLARE_EVENT_TABLE()
614 };
615
616
617 #endif // _WX_MACCARBONDATAVIEWCTRL_H_