]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/dataview.h
861844963599935bde3a910169595da42112d8fe
[wxWidgets.git] / include / wx / osx / dataview.h
1
2 /////////////////////////////////////////////////////////////////////////////
3 // Name: wx/osx/dataview.h
4 // Purpose: wxDataViewCtrl native implementation header for OSX
5 // Author:
6 // Id: $Id$
7 // Copyright: (c) 2009
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_DATAVIEWCTRL_OSX_H_
12 #define _WX_DATAVIEWCTRL_OSX_H_
13
14 #ifdef __WXMAC_CLASSIC__
15 # error "Native wxDataViewCtrl for classic environment not defined. Please use generic control."
16 #endif
17
18 // --------------------------------------------------------
19 // Class declarations to mask native types
20 // --------------------------------------------------------
21 class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation
22 class wxDataViewRendererNativeData; // class storing environment dependent data for the native renderer
23 class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation
24
25 // ---------------------------------------------------------
26 // wxDataViewRenderer
27 // ---------------------------------------------------------
28 class WXDLLIMPEXP_ADV wxDataViewRenderer : public wxDataViewRendererBase
29 {
30 public:
31 //
32 // constructors / destructor
33 //
34 wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
35
36 virtual ~wxDataViewRenderer(void);
37
38 //
39 // inherited methods from wxDataViewRendererBase
40 //
41 virtual int GetAlignment() const
42 {
43 return this->m_alignment;
44 }
45 virtual wxDataViewCellMode GetMode() const
46 {
47 return this->m_mode;
48 }
49 virtual bool GetValue(wxVariant& value) const
50 {
51 value = this->m_value;
52 return true;
53 }
54
55 virtual void SetAlignment(int align); // carbon: is always identical to the header alignment;
56 // cocoa: cell alignment is independent from header alignment
57 virtual void SetMode(wxDataViewCellMode mode);
58 virtual bool SetValue(wxVariant const& newValue)
59 {
60 this->m_value = newValue;
61 return true;
62 }
63
64 //
65 // implementation
66 //
67 wxVariant const& GetValue() const
68 {
69 return this->m_value;
70 }
71
72 wxDataViewRendererNativeData* GetNativeData() const
73 {
74 return this->m_NativeDataPtr;
75 }
76
77 virtual bool Render() = 0; // a call to the native data browser function to render the data;
78 // returns true if the data value could be rendered, false otherwise
79
80 void SetNativeData(wxDataViewRendererNativeData* newNativeDataPtr);
81
82 private:
83 //
84 // variables
85 //
86 int m_alignment; // contains the alignment flags
87
88 wxDataViewCellMode m_mode; // storing the mode that determines how the cell is going to be shown
89
90 wxDataViewRendererNativeData* m_NativeDataPtr; // data used by implementation of the native renderer
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 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
104 {
105 public:
106 //
107 // constructors / destructor
108 //
109 wxDataViewCustomRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
110
111 virtual ~wxDataViewCustomRenderer();
112
113 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
114
115 //
116 // methods handling render space
117 //
118 virtual wxSize GetSize() const = 0;
119
120 //
121 // methods handling user actions
122 //
123 virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
124
125 virtual bool Activate( wxRect WXUNUSED(cell),
126 wxDataViewModel *WXUNUSED(model),
127 const wxDataViewItem & WXUNUSED(item),
128 unsigned int WXUNUSED(col) )
129 { return false; }
130
131 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
132 wxRect WXUNUSED(cell),
133 wxDataViewModel *WXUNUSED(model),
134 const wxDataViewItem & WXUNUSED(item),
135 unsigned int WXUNUSED(col) )
136 { return false; }
137
138 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
139 wxRect WXUNUSED(cell),
140 wxDataViewModel *WXUNUSED(model),
141 const wxDataViewItem & WXUNUSED(item),
142 unsigned int WXUNUSED(col) )
143 { return false; }
144
145 //
146 // device context handling
147 //
148 virtual wxDC* GetDC(); // creates a device context and keeps it
149
150 //
151 // implementation
152 //
153 virtual bool Render();
154
155 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
156
157 protected:
158 private:
159 //
160 // variables
161 //
162 wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
163
164 wxDC* m_DCPtr;
165
166 //
167 // wxWidget internal stuff
168 //
169 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
170 };
171
172 // ---------------------------------------------------------
173 // wxDataViewTextRenderer
174 // ---------------------------------------------------------
175
176 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
177 {
178 public:
179 //
180 // constructors / destructor
181 //
182 wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
183
184 //
185 // inherited functions from wxDataViewRenderer
186 //
187 virtual bool Render();
188
189 protected:
190 private:
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
192 };
193
194 // ---------------------------------------------------------
195 // wxDataViewTextRendererAttr
196 // ---------------------------------------------------------
197
198 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
199 {
200 public:
201 //
202 // constructors / destructor
203 //
204 wxDataViewTextRendererAttr(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
205
206 private:
207 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
208 };
209
210 // ---------------------------------------------------------
211 // wxDataViewBitmapRenderer
212 // ---------------------------------------------------------
213
214 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
215 {
216 public:
217 //
218 // constructors / destructor
219 //
220 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
221
222 //
223 // inherited functions from wxDataViewRenderer
224 //
225 virtual bool Render();
226
227 protected:
228 private:
229 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
230 };
231
232 #if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
233
234 // -------------------------------------
235 // wxDataViewChoiceRenderer
236 // -------------------------------------
237 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewRenderer
238 {
239 public:
240 //
241 // constructors / destructor
242 //
243 wxDataViewChoiceRenderer(wxArrayString const& choices,
244 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
245 int alignment = wxDVR_DEFAULT_ALIGNMENT );
246
247 //
248 // inherited functions from wxDataViewRenderer
249 //
250 virtual bool Render();
251
252 //
253 // implementation
254 //
255 wxString GetChoice(size_t index) const
256 {
257 return this->m_Choices[index];
258 }
259 wxArrayString const& GetChoices(void) const
260 {
261 return this->m_Choices;
262 }
263
264 private:
265 //
266 // variables
267 //
268 wxArrayString m_Choices;
269
270 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer)
271 };
272
273 #endif
274
275 // ---------------------------------------------------------
276 // wxDataViewIconTextRenderer
277 // ---------------------------------------------------------
278 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
279 {
280 public:
281 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
282
283 //
284 // inherited functions from wxDataViewRenderer
285 //
286 virtual bool Render();
287
288 protected:
289 private:
290 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
291 };
292
293 // ---------------------------------------------------------
294 // wxDataViewToggleRenderer
295 // ---------------------------------------------------------
296
297 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
298 {
299 public:
300 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
301
302 //
303 // inherited functions from wxDataViewRenderer
304 //
305 virtual bool Render();
306
307 protected:
308 private:
309 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
310 };
311
312 // ---------------------------------------------------------
313 // wxDataViewProgressRenderer
314 // ---------------------------------------------------------
315
316 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
317 {
318 public:
319 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
320 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
321
322 //
323 // inherited functions from wxDataViewRenderer
324 //
325 virtual bool Render();
326
327 protected:
328 private:
329 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
330 };
331
332 // ---------------------------------------------------------
333 // wxDataViewDateRenderer
334 // ---------------------------------------------------------
335
336 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
337 {
338 public:
339 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
340
341 //
342 // inherited functions from wxDataViewRenderer
343 //
344 virtual bool Render();
345
346 protected:
347 private:
348 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
349 };
350
351 // ---------------------------------------------------------
352 // wxDataViewColumn
353 // ---------------------------------------------------------
354
355 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
356 {
357 public:
358 // constructors / destructor
359 wxDataViewColumn(const wxString& title,
360 wxDataViewRenderer* renderer,
361 unsigned int model_column,
362 int width = wxDVC_DEFAULT_WIDTH,
363 wxAlignment align = wxALIGN_CENTER,
364 int flags = wxDATAVIEW_COL_RESIZABLE);
365 wxDataViewColumn(const wxBitmap& bitmap,
366 wxDataViewRenderer* renderer,
367 unsigned int model_column,
368 int width = wxDVC_DEFAULT_WIDTH,
369 wxAlignment align = wxALIGN_CENTER,
370 int flags = wxDATAVIEW_COL_RESIZABLE);
371 virtual ~wxDataViewColumn(void);
372
373 // implement wxHeaderColumnBase pure virtual methods
374 virtual wxAlignment GetAlignment() const { return m_alignment; }
375 virtual int GetFlags() const { return m_flags; }
376 virtual int GetMaxWidth() const { return m_maxWidth; }
377 virtual int GetMinWidth() const { return m_minWidth; }
378 virtual wxString GetTitle() const { return m_title; }
379 virtual int GetWidth() const { return m_width; }
380 virtual bool IsHidden() const { return false; } // TODO
381 virtual bool IsSortOrderAscending() const { return m_ascending; }
382 virtual bool IsSortKey() const;
383
384 virtual void SetAlignment (wxAlignment align);
385 virtual void SetBitmap (wxBitmap const& bitmap);
386 virtual void SetFlags (int flags) { SetIndividualFlags(flags); }
387 virtual void SetHidden (bool WXUNUSED(hidden)) { } // TODO
388 virtual void SetMaxWidth (int maxWidth);
389 virtual void SetMinWidth (int minWidth);
390 virtual void SetReorderable(bool reorderable);
391 virtual void SetResizeable (bool resizeable);
392 virtual void SetSortable (bool sortable);
393 virtual void SetSortOrder (bool ascending);
394 virtual void SetTitle (wxString const& title);
395 virtual void SetWidth (int width);
396 virtual void SetAsSortKey (bool sort = true);
397
398 // implementation only
399 wxDataViewColumnNativeData* GetNativeData(void) const
400 {
401 return this->m_NativeDataPtr;
402 }
403
404 void SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr); // class takes ownership of pointer
405 void SetWidthVariable(int NewWidth)
406 {
407 m_width = NewWidth;
408 }
409
410 private:
411 // common part of all ctors
412 void InitCommon(int width, wxAlignment align, int flags)
413 {
414 m_ascending = true;
415 m_flags = flags & ~wxDATAVIEW_COL_HIDDEN; // TODO
416 m_maxWidth = 30000;
417 m_minWidth = 0;
418 m_width = width >= 0 ? width : wxDVC_DEFAULT_WIDTH;
419 m_alignment = align;
420 }
421
422 bool m_ascending; // sorting order
423
424 int m_flags; // flags for the column
425 int m_maxWidth; // maximum width for the column
426 int m_minWidth; // minimum width for the column
427 int m_width; // column width
428
429 wxAlignment m_alignment; // column header alignment
430
431 wxDataViewColumnNativeData* m_NativeDataPtr; // storing environment dependent data for the native implementation
432
433 wxString m_title; // column title
434 };
435
436 //
437 // type definitions related to wxDataViewColumn
438 //
439 WX_DEFINE_ARRAY(wxDataViewColumn*,wxDataViewColumnPtrArrayType);
440
441 // ---------------------------------------------------------
442 // wxDataViewCtrl
443 // ---------------------------------------------------------
444 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
445 {
446 public:
447 // Constructors / destructor:
448 wxDataViewCtrl()
449 {
450 this->Init();
451 }
452 wxDataViewCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
453 const wxValidator& validator = wxDefaultValidator)
454 {
455 this->Init();
456 this->Create(parent, id, pos, size, style, validator );
457 }
458
459 ~wxDataViewCtrl();
460
461 // explicit control creation
462 bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0,
463 const wxValidator& validator=wxDefaultValidator);
464
465 virtual wxControl* GetMainWindow() // not used for the native implementation
466 {
467 return this;
468 }
469
470 // inherited methods from wxDataViewCtrlBase:
471 virtual bool AssociateModel(wxDataViewModel* model);
472
473 virtual bool AppendColumn (wxDataViewColumn* columnPtr);
474 virtual bool ClearColumns (void);
475 virtual bool DeleteColumn (wxDataViewColumn* columnPtr);
476 virtual wxDataViewColumn* GetColumn (unsigned int pos) const;
477 virtual unsigned int GetColumnCount (void) const;
478 virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const;
479 virtual wxDataViewColumn* GetSortingColumn (void) const;
480 virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col);
481 virtual bool PrependColumn (wxDataViewColumn* columnPtr);
482
483 virtual void Collapse( const wxDataViewItem& item);
484 virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL);
485 virtual void Expand(const wxDataViewItem& item);
486 virtual bool IsExpanded(const wxDataViewItem & item) const;
487
488
489 virtual unsigned int GetCount() const;
490 virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr) const;
491 virtual wxDataViewItem GetSelection() const;
492 virtual int GetSelections(wxDataViewItemArray& sel) const;
493
494 virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
495
496 virtual bool IsSelected(const wxDataViewItem& item) const;
497
498 virtual void SelectAll();
499 virtual void Select(const wxDataViewItem& item);
500 virtual void SetSelections(const wxDataViewItemArray& sel);
501
502 virtual void Unselect(const wxDataViewItem& item);
503 virtual void UnselectAll();
504
505 //
506 // implementation
507 //
508 // returns a pointer to the native implementation
509 wxDataViewWidgetImpl* GetDataViewPeer(void) const;
510
511 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
512 void AddChildren(wxDataViewItem const& parentItem);
513
514 // finishes editing of custom items; if no custom item is currently edited the method does nothing
515 void FinishCustomItemEditing(void);
516
517 // returns the n-th pointer to a column;
518 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
519 // position in the internal list/array of column pointers
520 wxDataViewColumn* GetColumnPtr(size_t n) const
521 {
522 return this->m_ColumnPtrs[n];
523 }
524 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
525 wxDataViewItem const& GetCustomRendererItem() const
526 {
527 return this->m_CustomRendererItem;
528 }
529 // returns a pointer to a customized renderer (this pointer is only valid during editing)
530 wxDataViewCustomRenderer* GetCustomRendererPtr() const
531 {
532 return this->m_CustomRendererPtr;
533 }
534
535 // checks if currently a delete process is running
536 bool IsDeleting() const
537 {
538 return this->m_Deleting;
539 }
540
541 // with CG, we need to get the context from an kEventControlDraw event
542 // unfortunately, the DataBrowser callbacks don't provide the context
543 // and we need it, so we need to set/remove it before and after draw
544 // events so we can access it in the callbacks.
545 void MacSetDrawingContext(void* context)
546 {
547 this->m_cgContext = context;
548 }
549 void* MacGetDrawingContext() const
550 {
551 return this->m_cgContext;
552 }
553
554 // sets the currently being edited item of the custom renderer
555 void SetCustomRendererItem(wxDataViewItem const& NewItem)
556 {
557 this->m_CustomRendererItem = NewItem;
558 }
559 // sets the custom renderer
560 void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
561 {
562 this->m_CustomRendererPtr = NewCustomRendererPtr;
563 }
564 // sets the flag indicating a deletion process:
565 void SetDeleting(bool deleting)
566 {
567 this->m_Deleting = deleting;
568 }
569
570 virtual wxVisualAttributes GetDefaultAttributes() const
571 {
572 return GetClassDefaultAttributes(GetWindowVariant());
573 }
574
575 static wxVisualAttributes
576 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
577
578 protected:
579 // inherited methods from wxDataViewCtrlBase
580 virtual void DoSetExpanderColumn();
581 virtual void DoSetIndent();
582
583 // event handling
584 void OnSize(wxSizeEvent &event);
585
586 private:
587 // initializing of local variables:
588 void Init();
589
590 //
591 // variables
592 //
593 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
594 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
595 // if this flag is set all native variable update requests will be ignored
596
597 void* m_cgContext; // pointer to core graphics context
598
599 wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
600
601 wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item
602
603 wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array
604
605 // wxWidget internal stuff:
606 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
607 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
608 DECLARE_EVENT_TABLE()
609 };
610
611 #endif // _WX_DATAVIEWCTRL_OSX_H_
612