]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/dataview.h
don't need to paint tlw background, GTK does it
[wxWidgets.git] / include / wx / mac / carbon / dataview.h
CommitLineData
c0a66d92
RR
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 __MACCARBONDATAVIEWCTRL_H__
11#define __MACCARBONDATAVIEWCTRL_H__
12
13#include <Carbon/carbon.h>
14
15#include "wx/defs.h"
16#include "wx/object.h"
17#include "wx/list.h"
18#include "wx/control.h"
19#include "wx/scrolwin.h"
20#include "wx/icon.h"
21
22// ---------------------------------------------------------
23// classes
24// ---------------------------------------------------------
25
b5dbe15d 26class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
c0a66d92
RR
27
28// ---------------------------------------------------------
29// wxDataViewRenderer
30// ---------------------------------------------------------
31
32class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
33{
34public:
35//
36// constructors / destructor
37//
38 wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
39
40//
41// inherited methods from wxDataViewRendererBase
42//
43 virtual int GetAlignment(void) const
44 {
45 return this->m_alignment;
46 }
47 virtual wxDataViewCellMode GetMode(void) const
48 {
49 return this->m_mode;
50 }
51 virtual bool GetValue(wxVariant& value) const
52 {
53 value = this->m_value;
54 return true;
55 }
56
57 virtual void SetAlignment(int WXUNUSED(align)) // is always identical to the header alignment
58 {
59 }
60 virtual void SetMode(wxDataViewCellMode mode);
61 virtual bool SetValue(wxVariant const& newValue)
62 {
63 this->m_value = newValue;
64 return true;
65 }
66
67//
68// implementation
69//
70 DataBrowserItemDataRef GetDataReference(void) const
71 {
72 return this->m_dataReference;
73 }
74 wxVariant const& GetValue(void) const
75 {
76 return this->m_value;
77 }
78
79 virtual DataBrowserPropertyType GetPropertyType(void) const = 0;
80
81 virtual bool Render(void) = 0; // a call to the appropriate data browser function filling the data reference with the stored datum;
82 // returns 'true' if the data value could be rendered, 'false' otherwise
83
84 void SetDataReference(DataBrowserItemDataRef const& newDataReference)
85 {
86 this->m_dataReference = newDataReference;
87 }
88
89private:
90//
91// variables
92//
93 DataBrowserItemDataRef m_dataReference; // data reference of the data browser; the data will be assigned to this reference during rendering
94
95 int m_alignment; // contains the alignment flags
96
97 wxDataViewCellMode m_mode; // storing the mode that determines how the cell is going to be shown
98
99 wxVariant m_value; // value that is going to be rendered
100
101//
102// wxWidget internal stuff
103//
104 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
105};
106
107// ---------------------------------------------------------
108// wxDataViewCustomRenderer
109// ---------------------------------------------------------
110
111class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
112{
113public:
114//
115// constructors / destructor
116//
117 wxDataViewCustomRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
118
119 virtual ~wxDataViewCustomRenderer(void);
120
121//
122// methods handling render space
123//
124 virtual wxSize GetSize() const = 0;
125
126//
127// methods handling user actions
128//
129 virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
130
194027ac 131 virtual bool Activate(wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
c0a66d92
RR
132 {
133 return false;
134 }
135
194027ac 136 virtual bool LeftClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
c0a66d92
RR
137 {
138 return false;
139 }
140
194027ac 141 virtual bool RightClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
c0a66d92
RR
142 {
143 return false;
144 }
145
194027ac 146 virtual bool StartDrag(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
c0a66d92
RR
147 {
148 return false;
149 }
150
151//
152// in-place editing
153//
154 virtual void CancelEditing()
155 {
156 }
157
158 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), wxRect WXUNUSED(labelRect), const wxVariant& WXUNUSED(value))
159 {
160 return NULL;
161 }
162
163 virtual bool FinishEditing()
164 {
165 return false;
166 }
167
168 wxControl* GetEditorCtrl(void) const
169 {
170 return this->m_editorCtrlPtr;
171 }
172 virtual bool GetValueFromEditorCtrl(wxControl* WXUNUSED(editor), wxVariant& WXUNUSED(value))
173 {
174 return false;
175 }
176
177 virtual bool HasEditorCtrl(void)
178 {
179 return false;
180 }
181
6d9ecc87 182 virtual bool StartEditing(wxDataViewItem const& WXUNUSED(item), wxRect WXUNUSED(labelRect))
c0a66d92
RR
183 {
184 return false;
185 }
186
187//
188// device context handling
189//
190 virtual wxDC* GetDC(void); // creates a device context and keeps it
191
192//
193// implementation
194//
195 virtual bool Render(void); // declared in wxDataViewRenderer but will not be used here, therefore calling this function will
c17b2e31 196 // return 'true' without having done anything
c0a66d92
RR
197
198 virtual DataBrowserPropertyType GetPropertyType(void) const
199 {
200 return kDataBrowserCustomType;
201 }
202
203 void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
204
205protected:
206private:
207//
208// variables
209//
210 wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
211
212 wxDC* m_DCPtr;
213
214//
215// wxWidget internal stuff
216//
217 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
218};
219
220// ---------------------------------------------------------
221// wxDataViewTextRenderer
222// ---------------------------------------------------------
223
224class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
225{
226public:
227//
228// constructors / destructor
229//
230 wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
231
232//
233// inherited functions from wxDataViewRenderer
234//
235 virtual bool Render(void);
236
237//
238// implementation
239//
240 virtual DataBrowserPropertyType GetPropertyType(void) const
241 {
242 return kDataBrowserTextType;
243 }
244
245protected:
246private:
247 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
248};
249
250// ---------------------------------------------------------
251// wxDataViewBitmapRenderer
252// ---------------------------------------------------------
253
254class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
255{
256public:
257//
258// constructors / destructor
259//
260 wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), 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 DataBrowserPropertyType GetPropertyType(void) const
271 {
272 return kDataBrowserIconType;
273 }
274
275protected:
276private:
277 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
278};
279
280// ---------------------------------------------------------
281// wxDataViewToggleRenderer
282// ---------------------------------------------------------
283
c17b2e31
RR
284class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
285{
286public:
287 wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
288
289//
290// inherited functions from wxDataViewRenderer
291//
292 virtual bool Render(void);
293
294//
295// implementation
296//
297 virtual DataBrowserPropertyType GetPropertyType(void) const
298 {
299 return kDataBrowserIconAndTextType;
300 }
301
302protected:
303private:
304 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
305};
306
307// ---------------------------------------------------------
308// wxDataViewToggleRenderer
309// ---------------------------------------------------------
310
c0a66d92
RR
311class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
312{
313public:
314 wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
315
316//
317// inherited functions from wxDataViewRenderer
318//
319 virtual bool Render(void);
320
321//
322// implementation
323//
324 virtual DataBrowserPropertyType GetPropertyType(void) const
325 {
326 return kDataBrowserCheckboxType;
327 }
328
329protected:
330private:
331 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
332};
333
334// ---------------------------------------------------------
335// wxDataViewProgressRenderer
336// ---------------------------------------------------------
337
338class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
339{
340public:
341 wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
342 wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
343
344//
345// inherited functions from wxDataViewRenderer
346//
347 virtual bool Render(void);
348
349//
350// implementation
351//
352 virtual DataBrowserPropertyType GetPropertyType(void) const
353 {
354 return kDataBrowserProgressBarType;
355 }
356
357protected:
358private:
359 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
360};
361
362// ---------------------------------------------------------
363// wxDataViewDateRenderer
364// ---------------------------------------------------------
365
366class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
367{
368public:
369 wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
370
371//
372// inherited functions from wxDataViewRenderer
373//
374 virtual bool Render(void);
375
376//
377// implementation
378//
379 virtual DataBrowserPropertyType GetPropertyType(void) const
380 {
381 return kDataBrowserDateTimeType;
382 }
383
384protected:
385private:
386 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
387};
388
389// ---------------------------------------------------------
390// wxDataViewColumn
391// ---------------------------------------------------------
392
393class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
394{
395public:
396//
397// constructors / destructor
398//
399 wxDataViewColumn(wxString const& title, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
400 int flags=wxDATAVIEW_COL_RESIZABLE);
401 wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width=80, wxAlignment align=wxALIGN_CENTER,
402 int flags=wxDATAVIEW_COL_RESIZABLE);
403
404//
405// inherited methods from wxDataViewColumnBase
406//
407 virtual wxAlignment GetAlignment(void) const
408 {
409 return this->m_alignment;
410 }
411 virtual int GetFlags(void) const
412 {
413 return this->m_flags;
414 }
415 virtual int GetMaxWidth(void) const
416 {
417 return this->m_maxWidth;
418 }
419 virtual int GetMinWidth(void) const
420 {
421 return this->m_minWidth;
422 }
423 virtual wxString GetTitle(void) const
424 {
425 return this->m_title;
426 }
427 virtual int GetWidth(void) const
428 {
429 return this->m_width;
430 }
431
432 virtual bool IsHidden(void) const
433 {
434 return false; // not implemented
435 }
436 virtual bool IsResizeable(void) const
437 {
438 return ((this->m_flags & wxDATAVIEW_COL_RESIZABLE) != 0);
439 }
440 virtual bool IsSortable(void) const
441 {
442 return ((this->m_flags & wxDATAVIEW_COL_SORTABLE) != 0);
443 }
444 virtual bool IsSortOrderAscending(void) const
445 {
446 return this->m_ascending;
447 }
448
449 virtual void SetAlignment(wxAlignment align);
450 virtual void SetBitmap (wxBitmap const& bitmap);
451 virtual void SetFlags (int flags);
452 virtual void SetHidden(bool WXUNUSED(hidden))
453 {
454 }
455 virtual void SetMaxWidth (int maxWidth);
456 virtual void SetMinWidth (int minWidth);
457 virtual void SetResizeable(bool resizeable);
458 virtual void SetSortable (bool sortable);
459 virtual void SetSortOrder (bool ascending);
460 virtual void SetTitle (wxString const& title);
461 virtual void SetWidth (int width);
462
463//
464// implementation
465//
466 DataBrowserPropertyID GetPropertyID(void) const
467 {
468 return this->m_propertyID;
469 }
470
471 void SetPropertyID(DataBrowserPropertyID newID)
472 {
473 this->m_propertyID = newID;
474 }
6d9ecc87
RR
475 void SetWidthVariable(int NewWidth)
476 {
477 this->m_width = NewWidth;
478 }
c0a66d92
RR
479
480protected:
481private:
482//
483// variables
484//
485 bool m_ascending; // sorting order
486
487 DataBrowserPropertyID m_propertyID; // each column is identified by its unique property ID (NOT by the column index)
488
489 int m_flags; // flags for the column
490 int m_maxWidth; // maximum width for the column
491 int m_minWidth; // minimum width for the column
492 int m_width; // column width
493
494 wxAlignment m_alignment; // column header alignment
495
496 wxString m_title; // column title
497
498 // wxWidget internal stuff:
499 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
500};
501
502// ---------------------------------------------------------
503// wxDataViewCtrl
504// ---------------------------------------------------------
c0a66d92
RR
505class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
506{
507public:
508 // Constructors / destructor:
194027ac
RR
509 wxDataViewCtrl()
510 {
511 this->Init();
512 }
513 wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
514 wxValidator const& validator = wxDefaultValidator)
515 {
516 this->Init();
517 this->Create(parent, id, pos, size, style, validator );
518 }
519
520 // explicit control creation
521 bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
522 wxValidator const& validator=wxDefaultValidator);
523
194027ac
RR
524 virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
525 {
526 return this;
527 }
528
c17b2e31
RR
529 // inherited methods from 'wxDataViewCtrlBase':
530 virtual bool AssociateModel(wxDataViewModel* model);
531
532 virtual bool AppendColumn(wxDataViewColumn* columnPtr);
533 virtual bool ClearColumns(void);
534 virtual bool DeleteColumn(wxDataViewColumn* columnPtr);
535 virtual wxDataViewColumn* GetColumn(unsigned int pos) const;
536 virtual unsigned int GetColumnCount(void) const;
6d9ecc87 537 virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const;
21f47fb9 538
c17b2e31 539 virtual void Collapse(wxDataViewItem const& item);
07c51ff1 540 virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr=NULL);
c17b2e31 541 virtual void Expand(wxDataViewItem const& item);
07c51ff1 542
6d9ecc87
RR
543 virtual wxDataViewColumn* GetSortingColumn(void) const;
544
b741dd40 545 virtual unsigned int GetCount(void) const;
07c51ff1
RR
546 virtual wxRect GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const;
547 virtual wxDataViewItem GetSelection(void) const;
548 virtual int GetSelections(wxDataViewItemArray& sel) const;
549
550 virtual void HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
551
552 virtual bool IsSelected(wxDataViewItem const& item) const;
553
554 virtual void SelectAll(void);
555 virtual void Select(wxDataViewItem const& item);
556 virtual void SetSelections(wxDataViewItemArray const& sel);
c0a66d92 557
07c51ff1
RR
558 virtual void Unselect(wxDataViewItem const& item);
559 virtual void UnselectAll(void);
c17b2e31 560
c0a66d92
RR
561//
562// implementation
563//
564
07c51ff1 565 // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
194027ac
RR
566 void AddChildrenLevel(wxDataViewItem const& parentItem);
567
c17b2e31
RR
568 // returns a pointer to a column;
569 // in case the pointer cannot be found NULL is returned:
570 wxDataViewColumn* GetColumnPtr(DataBrowserPropertyID propertyID) const;
571
07c51ff1
RR
572 // checks if currently a delete process is running:
573 bool IsDeleting(void) const
574 {
575 return this->m_Deleting;
576 }
577
c0a66d92
RR
578 // with CG, we need to get the context from an kEventControlDraw event
579 // unfortunately, the DataBrowser callbacks don't provide the context
580 // and we need it, so we need to set/remove it before and after draw
581 // events so we can access it in the callbacks.
582 void MacSetDrawingContext(void* context)
583 {
584 this->m_cgContext = context;
585 }
586 void* MacGetDrawingContext(void) const
587 {
588 return this->m_cgContext;
589 }
590
07c51ff1
RR
591 /// sets the flag indicating a deletion process:
592 void SetDeleting(bool deleting)
593 {
594 this->m_Deleting = deleting;
595 }
596
c0a66d92 597protected:
194027ac
RR
598 // inherited methods from wxDataViewCtrlBase:
599 virtual void DoSetExpanderColumn(void);
600 virtual void DoSetIndent(void);
601
c0a66d92
RR
602 // event handling:
603 void OnSize(wxSizeEvent &event);
604
605private:
c17b2e31
RR
606 // type definitions:
607 WX_DECLARE_HASH_MAP(DataBrowserPropertyID,wxDataViewColumn*,wxIntegerHash,wxIntegerEqual,ColumnPointerHashMapType);
608
c0a66d92
RR
609 // initializing of local variables:
610 void Init(void);
611
612///
613// variables
614//
615
07c51ff1
RR
616 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
617 // after the actual deletion of the item; then, the callback function "wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc" may
618 // try to update data into variables that are already deleted; this flag will ignore all variable update requests during item deletion
c0a66d92
RR
619
620 void* m_cgContext; // pointer to core graphics context
07c51ff1 621
c17b2e31 622 ColumnPointerHashMapType m_ColumnPointers; // all column pointers are stored in a hash map with the property ID as a key
c0a66d92
RR
623
624 // wxWidget internal stuff:
625 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
626 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
627 DECLARE_EVENT_TABLE()
628};
629
630
631#endif // __MACDATAVIEWCTRL_H__