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