]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/carbon/dataview.h
generic implementation of wxHeaderCtrl API so far
[wxWidgets.git] / include / wx / osx / 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 // --------------------------------------------------------
14 // Type definitions to mask native types
15 // --------------------------------------------------------
16
17 typedef void* WXDataBrowserItemDataRef;
18 typedef unsigned long WXDataBrowserPropertyType;
19 typedef wxUint32 WXDataBrowserPropertyID;
20
21 // ---------------------------------------------------------
22 // wxDataViewRenderer
23 // ---------------------------------------------------------
24
25 class WXDLLIMPEXP_ADV wxDataViewRenderer : public wxDataViewRendererBase
26 {
27 public:
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() const
37 {
38 return this->m_alignment;
39 }
40 virtual wxDataViewCellMode GetMode() 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 //
63 WXDataBrowserItemDataRef GetDataReference() const
64 {
65 return this->m_dataReference;
66 }
67 wxVariant const& GetValue() const
68 {
69 return this->m_value;
70 }
71
72 virtual WXDataBrowserPropertyType GetPropertyType() const = 0;
73
74 virtual bool Render() = 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
77 void SetDataReference(WXDataBrowserItemDataRef const& newDataReference)
78 {
79 this->m_dataReference = newDataReference;
80 }
81
82 private:
83 //
84 // variables
85 //
86 WXDataBrowserItemDataRef m_dataReference; // data reference of the data browser; the data will be assigned to this reference during rendering
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
104 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
105 {
106 public:
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();
113
114 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
115
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
126 virtual bool Activate( wxRect WXUNUSED(cell),
127 wxDataViewModel *WXUNUSED(model),
128 const wxDataViewItem & WXUNUSED(item),
129 unsigned int WXUNUSED(col) )
130 { return false; }
131
132 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
133 wxRect WXUNUSED(cell),
134 wxDataViewModel *WXUNUSED(model),
135 const wxDataViewItem & WXUNUSED(item),
136 unsigned int WXUNUSED(col) )
137 { return false; }
138
139 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
140 wxRect WXUNUSED(cell),
141 wxDataViewModel *WXUNUSED(model),
142 const wxDataViewItem & WXUNUSED(item),
143 unsigned int WXUNUSED(col) )
144 { return false; }
145
146 //
147 // device context handling
148 //
149 virtual wxDC* GetDC(); // creates a device context and keeps it
150
151 //
152 // implementation
153 //
154 virtual bool Render(); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
155 // return 'true' without having done anything
156
157 virtual WXDataBrowserPropertyType GetPropertyType() const;
158
159 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
160
161 protected:
162 private:
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
180 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
181 {
182 public:
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();
192
193 //
194 // implementation
195 //
196 virtual WXDataBrowserPropertyType GetPropertyType() const;
197
198 protected:
199 private:
200 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
201 };
202
203 // ---------------------------------------------------------
204 // wxDataViewTextRendererAttr
205 // ---------------------------------------------------------
206
207 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
208 {
209 public:
210 //
211 // constructors / destructor
212 //
213 wxDataViewTextRendererAttr(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
214
215 private:
216 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
217 };
218
219 // ---------------------------------------------------------
220 // wxDataViewBitmapRenderer
221 // ---------------------------------------------------------
222
223 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
224 {
225 public:
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();
235
236 //
237 // implementation
238 //
239 virtual WXDataBrowserPropertyType GetPropertyType() const;
240
241 protected:
242 private:
243 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
244 };
245
246 // ---------------------------------------------------------
247 // wxDataViewToggleRenderer
248 // ---------------------------------------------------------
249
250 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
251 {
252 public:
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();
259
260 //
261 // implementation
262 //
263 virtual WXDataBrowserPropertyType GetPropertyType() const;
264
265 protected:
266 private:
267 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
268 };
269
270 // ---------------------------------------------------------
271 // wxDataViewToggleRenderer
272 // ---------------------------------------------------------
273
274 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
275 {
276 public:
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();
283
284 //
285 // implementation
286 //
287 virtual WXDataBrowserPropertyType GetPropertyType() const;
288
289 protected:
290 private:
291 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
292 };
293
294 // ---------------------------------------------------------
295 // wxDataViewProgressRenderer
296 // ---------------------------------------------------------
297
298 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
299 {
300 public:
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();
308
309 //
310 // implementation
311 //
312 virtual WXDataBrowserPropertyType GetPropertyType() const;
313
314 protected:
315 private:
316 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
317 };
318
319 // ---------------------------------------------------------
320 // wxDataViewDateRenderer
321 // ---------------------------------------------------------
322
323 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
324 {
325 public:
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();
332
333 //
334 // implementation
335 //
336 virtual WXDataBrowserPropertyType GetPropertyType() const;
337
338 protected:
339 private:
340 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
341 };
342
343 // ---------------------------------------------------------
344 // wxDataViewColumn
345 // ---------------------------------------------------------
346
347 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
348 {
349 public:
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() const
362 {
363 return this->m_alignment;
364 }
365 virtual int GetFlags() const
366 {
367 return this->m_flags;
368 }
369 virtual int GetMaxWidth() const
370 {
371 return this->m_maxWidth;
372 }
373 virtual int GetMinWidth() const
374 {
375 return this->m_minWidth;
376 }
377 virtual wxString GetTitle() const
378 {
379 return this->m_title;
380 }
381 virtual int GetWidth() const
382 {
383 return this->m_width;
384 }
385
386 virtual bool IsHidden() const
387 {
388 return false; // not implemented
389 }
390 virtual bool IsSortOrderAscending() const
391 {
392 return this->m_ascending;
393 }
394
395 virtual void SetAlignment(wxAlignment align);
396 virtual void SetBitmap (wxBitmap const& bitmap);
397 virtual void SetFlags (int flags);
398 virtual void SetHidden(bool WXUNUSED(hidden))
399 {
400 }
401 virtual void SetMaxWidth (int maxWidth);
402 virtual void SetMinWidth (int minWidth);
403 virtual void SetReorderable(bool reorderable);
404 virtual void SetResizeable (bool resizeable);
405 virtual void SetSortable (bool sortable);
406 virtual void SetSortOrder (bool ascending);
407 virtual void SetTitle (wxString const& title);
408 virtual void SetWidth (int width);
409
410 //
411 // implementation
412 //
413 WXDataBrowserPropertyID GetPropertyID() const
414 {
415 return this->m_propertyID;
416 }
417
418 void SetPropertyID(WXDataBrowserPropertyID newID)
419 {
420 this->m_propertyID = newID;
421 }
422 void SetWidthVariable(int NewWidth)
423 {
424 this->m_width = NewWidth;
425 }
426
427 protected:
428 private:
429 //
430 // variables
431 //
432 bool m_ascending; // sorting order
433
434 WXDataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
435
436 int m_flags; // flags for the column
437 int m_maxWidth; // maximum width for the column
438 int m_minWidth; // minimum width for the column
439 int m_width; // column width
440
441 wxAlignment m_alignment; // column header alignment
442
443 wxString m_title; // column title
444
445 // wxWidget internal stuff:
446 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
447 };
448
449 // ---------------------------------------------------------
450 // wxDataViewCtrl
451 // ---------------------------------------------------------
452 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
453 {
454 public:
455 // Constructors / destructor:
456 wxDataViewCtrl()
457 {
458 this->Init();
459 }
460 wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
461 wxValidator const& validator = wxDefaultValidator)
462 {
463 this->Init();
464 this->Create(parent, id, pos, size, style, validator );
465 }
466
467 ~wxDataViewCtrl();
468
469 // explicit control creation
470 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
471 wxValidator const& validator=wxDefaultValidator);
472
473 virtual wxControl* GetMainWindow() // should disappear as it is not of any use for the native implementation
474 {
475 return this;
476 }
477
478 // inherited methods from 'wxDataViewCtrlBase':
479 virtual bool AssociateModel(wxDataViewModel* model);
480
481 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
482 virtual bool PrependColumn(wxDataViewColumn* columnPtr);
483 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
484
485 virtual bool ClearColumns();
486 virtual bool DeleteColumn(wxDataViewColumn* columnPtr);
487 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
488 virtual unsigned int GetColumnCount() const;
489 virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const;
490
491 virtual void Collapse(wxDataViewItem const& item);
492 virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr=NULL);
493 virtual void Expand(wxDataViewItem const& item);
494
495 virtual wxDataViewColumn* GetSortingColumn() const;
496
497 virtual unsigned int GetCount() const;
498 virtual wxRect GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const;
499 virtual wxDataViewItem GetSelection() const;
500 virtual int GetSelections(wxDataViewItemArray& sel) const;
501
502 virtual void HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
503
504 virtual bool IsSelected(wxDataViewItem const& item) const;
505
506 virtual void SelectAll();
507 virtual void Select(wxDataViewItem const& item);
508 virtual void SetSelections(wxDataViewItemArray const& sel);
509
510 virtual void Unselect(wxDataViewItem const& item);
511 virtual void UnselectAll();
512
513 //
514 // implementation
515 //
516
517 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
518 void AddChildrenLevel(wxDataViewItem const& parentItem);
519
520 // finishes editing of custom items; if no custom item is currently edited the method does nothing
521 void FinishCustomItemEditing();
522
523 // returns a pointer to a column;
524 // in case the pointer cannot be found NULL is returned:
525 wxDataViewColumn* GetColumnPtr(WXDataBrowserPropertyID propertyID) const;
526 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
527 wxDataViewItem const& GetCustomRendererItem() const
528 {
529 return this->m_CustomRendererItem;
530 }
531 // returns a pointer to a customized renderer (this pointer is only valid during editing)
532 wxDataViewCustomRenderer* GetCustomRendererPtr() const
533 {
534 return this->m_CustomRendererPtr;
535 }
536
537 // checks if currently a delete process is running:
538 bool IsDeleting() const
539 {
540 return this->m_Deleting;
541 }
542
543 // with CG, we need to get the context from an kEventControlDraw event
544 // unfortunately, the DataBrowser callbacks don't provide the context
545 // and we need it, so we need to set/remove it before and after draw
546 // events so we can access it in the callbacks.
547 void MacSetDrawingContext(void* context)
548 {
549 this->m_cgContext = context;
550 }
551 void* MacGetDrawingContext() const
552 {
553 return this->m_cgContext;
554 }
555
556 // sets the currently being edited item of the custom renderer
557 void SetCustomRendererItem(wxDataViewItem const& NewItem)
558 {
559 this->m_CustomRendererItem = NewItem;
560 }
561 // sets the custom renderer
562 void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
563 {
564 this->m_CustomRendererPtr = NewCustomRendererPtr;
565 }
566 // sets the flag indicating a deletion process:
567 void SetDeleting(bool deleting)
568 {
569 this->m_Deleting = deleting;
570 }
571
572 virtual wxVisualAttributes GetDefaultAttributes() const
573 {
574 return GetClassDefaultAttributes(GetWindowVariant());
575 }
576
577 static wxVisualAttributes
578 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
579
580 protected:
581 // inherited methods from wxDataViewCtrlBase:
582 virtual void DoSetExpanderColumn();
583 virtual void DoSetIndent();
584
585 // event handling:
586 void OnSize(wxSizeEvent &event);
587
588 private:
589 // type definitions:
590 WX_DECLARE_HASH_MAP(WXDataBrowserPropertyID,wxDataViewColumn*,wxIntegerHash,wxIntegerEqual,ColumnPointerHashMapType);
591
592 // initializing of local variables:
593 void Init();
594
595 ///
596 // variables
597 //
598
599 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
600 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
601 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
602
603 void* m_cgContext; // pointer to core graphics context
604
605 wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
606
607 wxDataViewItem m_CustomRendererItem; // currently edited item by the customerenderer; it is invalid while not editing
608
609 ColumnPointerHashMapType m_ColumnPointers; // all column pointers are stored in a hash map with the property ID as a key
610
611 // wxWidget internal stuff:
612 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
613 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
614 DECLARE_EVENT_TABLE()
615 };
616
617
618 #endif // _WX_MACCARBONDATAVIEWCTRL_H_