]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/osx/dataview.h
Make generic wxDataViewProgressRenderer fill the entire cell.
[wxWidgets.git] / include / wx / osx / dataview.h
... / ...
CommitLineData
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// --------------------------------------------------------
21class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation
22class wxDataViewRendererNativeData; // class storing environment dependent data for the native renderer
23class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation
24
25// ---------------------------------------------------------
26// wxDataViewRenderer
27// ---------------------------------------------------------
28class WXDLLIMPEXP_ADV wxDataViewRenderer : public wxDataViewRendererBase
29{
30public:
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//
65// implementation
66//
67 wxVariant const& GetValue() const
68 {
69 return m_value;
70 }
71
72 wxDataViewRendererNativeData* GetNativeData() const
73 {
74 return 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
82private:
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// ---------------------------------------------------------
103class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
104{
105public:
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
157protected:
158private:
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
176class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
177{
178public:
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
189protected:
190private:
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
192};
193
194// ---------------------------------------------------------
195// wxDataViewBitmapRenderer
196// ---------------------------------------------------------
197
198class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
199{
200public:
201//
202// constructors / destructor
203//
204 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
205
206//
207// inherited functions from wxDataViewRenderer
208//
209 virtual bool MacRender();
210
211protected:
212private:
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
214};
215
216#if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
217
218// -------------------------------------
219// wxDataViewChoiceRenderer
220// -------------------------------------
221class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewRenderer
222{
223public:
224//
225// constructors / destructor
226//
227 wxDataViewChoiceRenderer(wxArrayString const& choices,
228 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
229 int alignment = wxDVR_DEFAULT_ALIGNMENT );
230
231//
232// inherited functions from wxDataViewRenderer
233//
234 virtual bool MacRender();
235
236//
237// implementation
238//
239 wxString GetChoice(size_t index) const
240 {
241 return m_Choices[index];
242 }
243 wxArrayString const& GetChoices() const
244 {
245 return m_Choices;
246 }
247
248private:
249//
250// variables
251//
252 wxArrayString m_Choices;
253
254 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer)
255};
256
257#endif
258
259// ---------------------------------------------------------
260// wxDataViewIconTextRenderer
261// ---------------------------------------------------------
262class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
263{
264public:
265 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
266
267//
268// inherited functions from wxDataViewRenderer
269//
270 virtual bool MacRender();
271
272protected:
273private:
274 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
275};
276
277// ---------------------------------------------------------
278// wxDataViewToggleRenderer
279// ---------------------------------------------------------
280
281class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
282{
283public:
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 MacRender();
290
291protected:
292private:
293 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
294};
295
296// ---------------------------------------------------------
297// wxDataViewProgressRenderer
298// ---------------------------------------------------------
299
300class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
301{
302public:
303 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
304 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
305
306//
307// inherited functions from wxDataViewRenderer
308//
309 virtual bool MacRender();
310
311protected:
312private:
313 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
314};
315
316// ---------------------------------------------------------
317// wxDataViewDateRenderer
318// ---------------------------------------------------------
319
320class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
321{
322public:
323 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
324
325//
326// inherited functions from wxDataViewRenderer
327//
328 virtual bool MacRender();
329
330protected:
331private:
332 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
333};
334
335// ---------------------------------------------------------
336// wxDataViewColumn
337// ---------------------------------------------------------
338
339class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
340{
341public:
342 // constructors / destructor
343 wxDataViewColumn(const wxString& title,
344 wxDataViewRenderer* renderer,
345 unsigned int model_column,
346 int width = wxDVC_DEFAULT_WIDTH,
347 wxAlignment align = wxALIGN_CENTER,
348 int flags = wxDATAVIEW_COL_RESIZABLE);
349 wxDataViewColumn(const wxBitmap& bitmap,
350 wxDataViewRenderer* renderer,
351 unsigned int model_column,
352 int width = wxDVC_DEFAULT_WIDTH,
353 wxAlignment align = wxALIGN_CENTER,
354 int flags = wxDATAVIEW_COL_RESIZABLE);
355 virtual ~wxDataViewColumn();
356
357 // implement wxHeaderColumnBase pure virtual methods
358 virtual wxAlignment GetAlignment() const { return m_alignment; }
359 virtual int GetFlags() const { return m_flags; }
360 virtual int GetMaxWidth() const { return m_maxWidth; }
361 virtual int GetMinWidth() const { return m_minWidth; }
362 virtual wxString GetTitle() const { return m_title; }
363 virtual int GetWidth() const { return m_width; }
364 virtual bool IsHidden() const { return false; } // TODO
365 virtual bool IsSortOrderAscending() const { return m_ascending; }
366 virtual bool IsSortKey() const;
367
368 virtual void SetAlignment (wxAlignment align);
369 virtual void SetBitmap (wxBitmap const& bitmap);
370 virtual void SetFlags (int flags) { SetIndividualFlags(flags); }
371 virtual void SetHidden (bool WXUNUSED(hidden)) { } // TODO
372 virtual void SetMaxWidth (int maxWidth);
373 virtual void SetMinWidth (int minWidth);
374 virtual void SetReorderable(bool reorderable);
375 virtual void SetResizeable (bool resizeable);
376 virtual void SetSortable (bool sortable);
377 virtual void SetSortOrder (bool ascending);
378 virtual void SetTitle (wxString const& title);
379 virtual void SetWidth (int width);
380 virtual void SetAsSortKey (bool sort = true);
381
382 // implementation only
383 wxDataViewColumnNativeData* GetNativeData() const
384 {
385 return m_NativeDataPtr;
386 }
387
388 void SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr); // class takes ownership of pointer
389 void SetWidthVariable(int NewWidth)
390 {
391 m_width = NewWidth;
392 }
393 void SetSortOrderVariable(bool NewOrder)
394 {
395 m_ascending = NewOrder;
396 }
397
398private:
399 // common part of all ctors
400 void InitCommon(int width, wxAlignment align, int flags)
401 {
402 m_ascending = true;
403 m_flags = flags & ~wxDATAVIEW_COL_HIDDEN; // TODO
404 m_maxWidth = 30000;
405 m_minWidth = 0;
406 m_width = width >= 0 ? width : wxDVC_DEFAULT_WIDTH;
407 m_alignment = align;
408 }
409
410 bool m_ascending; // sorting order
411
412 int m_flags; // flags for the column
413 int m_maxWidth; // maximum width for the column
414 int m_minWidth; // minimum width for the column
415 int m_width; // column width
416
417 wxAlignment m_alignment; // column header alignment
418
419 wxDataViewColumnNativeData* m_NativeDataPtr; // storing environment dependent data for the native implementation
420
421 wxString m_title; // column title
422};
423
424//
425// type definitions related to wxDataViewColumn
426//
427WX_DEFINE_ARRAY(wxDataViewColumn*,wxDataViewColumnPtrArrayType);
428
429// ---------------------------------------------------------
430// wxDataViewCtrl
431// ---------------------------------------------------------
432class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
433{
434public:
435 // Constructors / destructor:
436 wxDataViewCtrl()
437 {
438 Init();
439 }
440 wxDataViewCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
441 const wxValidator& validator = wxDefaultValidator)
442 {
443 Init();
444 Create(parent, id, pos, size, style, validator );
445 }
446
447 ~wxDataViewCtrl();
448
449 // explicit control creation
450 bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0,
451 const wxValidator& validator=wxDefaultValidator);
452
453 virtual wxControl* GetMainWindow() // not used for the native implementation
454 {
455 return this;
456 }
457
458 // inherited methods from wxDataViewCtrlBase:
459 virtual bool AssociateModel(wxDataViewModel* model);
460
461 virtual bool AppendColumn (wxDataViewColumn* columnPtr);
462 virtual bool ClearColumns ();
463 virtual bool DeleteColumn (wxDataViewColumn* columnPtr);
464 virtual wxDataViewColumn* GetColumn (unsigned int pos) const;
465 virtual unsigned int GetColumnCount () const;
466 virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const;
467 virtual wxDataViewColumn* GetSortingColumn () const;
468 virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col);
469 virtual bool PrependColumn (wxDataViewColumn* columnPtr);
470
471 virtual void Collapse( const wxDataViewItem& item);
472 virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL);
473 virtual void Expand(const wxDataViewItem& item);
474 virtual bool IsExpanded(const wxDataViewItem & item) const;
475
476
477 virtual unsigned int GetCount() const;
478 virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr) const;
479 virtual wxDataViewItem GetSelection() const;
480 virtual int GetSelections(wxDataViewItemArray& sel) const;
481
482 virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
483
484 virtual bool IsSelected(const wxDataViewItem& item) const;
485
486 virtual void SelectAll();
487 virtual void Select(const wxDataViewItem& item);
488 virtual void SetSelections(const wxDataViewItemArray& sel);
489
490 virtual void Unselect(const wxDataViewItem& item);
491 virtual void UnselectAll();
492
493//
494// implementation
495//
496 // returns a pointer to the native implementation
497 wxDataViewWidgetImpl* GetDataViewPeer() const;
498
499 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
500 void AddChildren(wxDataViewItem const& parentItem);
501
502 // finishes editing of custom items; if no custom item is currently edited the method does nothing
503 void FinishCustomItemEditing();
504
505 // returns the n-th pointer to a column;
506 // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
507 // position in the internal list/array of column pointers
508 wxDataViewColumn* GetColumnPtr(size_t n) const
509 {
510 return m_ColumnPtrs[n];
511 }
512 // returns the current being rendered item of the customized renderer (this item is only valid during editing)
513 wxDataViewItem const& GetCustomRendererItem() const
514 {
515 return m_CustomRendererItem;
516 }
517 // returns a pointer to a customized renderer (this pointer is only valid during editing)
518 wxDataViewCustomRenderer* GetCustomRendererPtr() const
519 {
520 return m_CustomRendererPtr;
521 }
522
523 // checks if currently a delete process is running
524 bool IsDeleting() const
525 {
526 return m_Deleting;
527 }
528
529 // with CG, we need to get the context from an kEventControlDraw event
530 // unfortunately, the DataBrowser callbacks don't provide the context
531 // and we need it, so we need to set/remove it before and after draw
532 // events so we can access it in the callbacks.
533 void MacSetDrawingContext(void* context)
534 {
535 m_cgContext = context;
536 }
537 void* MacGetDrawingContext() const
538 {
539 return m_cgContext;
540 }
541
542 // sets the currently being edited item of the custom renderer
543 void SetCustomRendererItem(wxDataViewItem const& NewItem)
544 {
545 m_CustomRendererItem = NewItem;
546 }
547 // sets the custom renderer
548 void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
549 {
550 m_CustomRendererPtr = NewCustomRendererPtr;
551 }
552 // sets the flag indicating a deletion process:
553 void SetDeleting(bool deleting)
554 {
555 m_Deleting = deleting;
556 }
557
558 virtual wxVisualAttributes GetDefaultAttributes() const
559 {
560 return GetClassDefaultAttributes(GetWindowVariant());
561 }
562
563 static wxVisualAttributes
564 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
565
566protected:
567 // inherited methods from wxDataViewCtrlBase
568 virtual void DoSetExpanderColumn();
569 virtual void DoSetIndent();
570
571 virtual wxSize DoGetBestSize() const;
572
573 // event handling
574 void OnSize(wxSizeEvent &event);
575 void OnMouse(wxMouseEvent &event);
576
577private:
578 // initializing of local variables:
579 void Init();
580
581 //
582 // variables
583 //
584 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
585 // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
586 // if this flag is set all native variable update requests will be ignored
587
588 void* m_cgContext; // pointer to core graphics context
589
590 wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
591
592 wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item
593
594 wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array
595
596 // wxWidget internal stuff:
597 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
598 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
599 DECLARE_EVENT_TABLE()
600};
601
602#endif // _WX_DATAVIEWCTRL_OSX_H_
603