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