]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/dataview.h
wxDateTime timezone functions now dynamic (no caching).
[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 MacRender() = 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 MacRender();
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 MacRender();
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 MacRender();
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 MacRender();
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 MacRender();
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 MacRender();
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 MacRender();
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 MacRender();
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 void SetSortOrderVariable(bool NewOrder)
410 {
411 m_ascending = NewOrder;
412 }
413
414 private:
415 // common part of all ctors
416 void InitCommon(int width, wxAlignment align, int flags)
417 {
418 m_ascending = true;
419 m_flags = flags & ~wxDATAVIEW_COL_HIDDEN; // TODO
420 m_maxWidth = 30000;
421 m_minWidth = 0;
422 m_width = width >= 0 ? width : wxDVC_DEFAULT_WIDTH;
423 m_alignment = align;
424 }
425
426 bool m_ascending; // sorting order
427
428 int m_flags; // flags for the column
429 int m_maxWidth; // maximum width for the column
430 int m_minWidth; // minimum width for the column
431 int m_width; // column width
432
433 wxAlignment m_alignment; // column header alignment
434
435 wxDataViewColumnNativeData* m_NativeDataPtr; // storing environment dependent data for the native implementation
436
437 wxString m_title; // column title
438 };
439
440 //
441 // type definitions related to wxDataViewColumn
442 //
443 WX_DEFINE_ARRAY(wxDataViewColumn*,wxDataViewColumnPtrArrayType);
444
445 // ---------------------------------------------------------
446 // wxDataViewCtrl
447 // ---------------------------------------------------------
448 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
449 {
450 public:
451 // Constructors / destructor:
452 wxDataViewCtrl()
453 {
454 this->Init();
455 }
456 wxDataViewCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
457 const wxValidator& validator = wxDefaultValidator)
458 {
459 this->Init();
460 this->Create(parent, id, pos, size, style, validator );
461 }
462
463 ~wxDataViewCtrl();
464
465 // explicit control creation
466 bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0,
467 const wxValidator& validator=wxDefaultValidator);
468
469 virtual wxControl* GetMainWindow() // not used for the native implementation
470 {
471 return this;
472 }
473
474 // inherited methods from wxDataViewCtrlBase:
475 virtual bool AssociateModel(wxDataViewModel* model);
476
477 virtual bool AppendColumn (wxDataViewColumn* columnPtr);
478 virtual bool ClearColumns (void);
479 virtual bool DeleteColumn (wxDataViewColumn* columnPtr);
480 virtual wxDataViewColumn* GetColumn (unsigned int pos) const;
481 virtual unsigned int GetColumnCount (void) const;
482 virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const;
483 virtual wxDataViewColumn* GetSortingColumn (void) const;
484 virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col);
485 virtual bool PrependColumn (wxDataViewColumn* columnPtr);
486
487 virtual void Collapse( const wxDataViewItem& item);
488 virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL);
489 virtual void Expand(const wxDataViewItem& item);
490 virtual bool IsExpanded(const wxDataViewItem & item) const;
491
492
493 virtual unsigned int GetCount() const;
494 virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr) const;
495 virtual wxDataViewItem GetSelection() const;
496 virtual int GetSelections(wxDataViewItemArray& sel) const;
497
498 virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
499
500 virtual bool IsSelected(const wxDataViewItem& item) const;
501
502 virtual void SelectAll();
503 virtual void Select(const wxDataViewItem& item);
504 virtual void SetSelections(const wxDataViewItemArray& sel);
505
506 virtual void Unselect(const wxDataViewItem& item);
507 virtual void UnselectAll();
508
509 //
510 // implementation
511 //
512 // returns a pointer to the native implementation
513 wxDataViewWidgetImpl* GetDataViewPeer(void) const;
514
515 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
516 void AddChildren(wxDataViewItem const& parentItem);
517
518 // finishes editing of custom items; if no custom item is currently edited the method does nothing
519 void FinishCustomItemEditing(void);
520
521 // returns the n-th pointer to a column;
522 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
523 // position in the internal list/array of column pointers
524 wxDataViewColumn* GetColumnPtr(size_t n) const
525 {
526 return this->m_ColumnPtrs[n];
527 }
528 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
529 wxDataViewItem const& GetCustomRendererItem() const
530 {
531 return this->m_CustomRendererItem;
532 }
533 // returns a pointer to a customized renderer (this pointer is only valid during editing)
534 wxDataViewCustomRenderer* GetCustomRendererPtr() const
535 {
536 return this->m_CustomRendererPtr;
537 }
538
539 // checks if currently a delete process is running
540 bool IsDeleting() const
541 {
542 return this->m_Deleting;
543 }
544
545 // with CG, we need to get the context from an kEventControlDraw event
546 // unfortunately, the DataBrowser callbacks don't provide the context
547 // and we need it, so we need to set/remove it before and after draw
548 // events so we can access it in the callbacks.
549 void MacSetDrawingContext(void* context)
550 {
551 this->m_cgContext = context;
552 }
553 void* MacGetDrawingContext() const
554 {
555 return this->m_cgContext;
556 }
557
558 // sets the currently being edited item of the custom renderer
559 void SetCustomRendererItem(wxDataViewItem const& NewItem)
560 {
561 this->m_CustomRendererItem = NewItem;
562 }
563 // sets the custom renderer
564 void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
565 {
566 this->m_CustomRendererPtr = NewCustomRendererPtr;
567 }
568 // sets the flag indicating a deletion process:
569 void SetDeleting(bool deleting)
570 {
571 this->m_Deleting = deleting;
572 }
573
574 virtual wxVisualAttributes GetDefaultAttributes() const
575 {
576 return GetClassDefaultAttributes(GetWindowVariant());
577 }
578
579 static wxVisualAttributes
580 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
581
582 protected:
583 // inherited methods from wxDataViewCtrlBase
584 virtual void DoSetExpanderColumn();
585 virtual void DoSetIndent();
586
587 virtual wxSize DoGetBestSize() const;
588
589 // event handling
590 void OnSize(wxSizeEvent &event);
591 void OnMouse(wxMouseEvent &event);
592
593 private:
594 // initializing of local variables:
595 void Init();
596
597 //
598 // variables
599 //
600 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
601 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
602 // if this flag is set all native variable update requests will be ignored
603
604 void* m_cgContext; // pointer to core graphics context
605
606 wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
607
608 wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item
609
610 wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array
611
612 // wxWidget internal stuff:
613 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
614 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
615 DECLARE_EVENT_TABLE()
616 };
617
618 #endif // _WX_DATAVIEWCTRL_OSX_H_
619