]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dataview.cpp
Correct signature of HitTest()
[wxWidgets.git] / src / mac / carbon / dataview.cpp
CommitLineData
c0a66d92
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/datavgen.cpp
3// Purpose: wxDataViewCtrl native mac implementation
4// Author:
5// Id: $Id$
6// Copyright: (c) 2007
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_DATAVIEWCTRL
14
15#include "wx/dataview.h"
16
17#if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)
18
19#include <limits>
20
21#include "wx/mac/carbon/databrow.h"
22
23#ifndef WX_PRECOMP
24 #include "wx/timer.h"
25#endif
26
27#include "wx/icon.h"
28#include "wx/renderer.h"
29
30//-----------------------------------------------------------------------------
31// local constants
32//-----------------------------------------------------------------------------
33
34// a list of all catchable events:
35static EventTypeSpec const eventList[] =
36{
37 {kEventClassControl, kEventControlDraw},
38 {kEventClassControl, kEventControlHit}
39};
40
41//-----------------------------------------------------------------------------
42// local functions
43//-----------------------------------------------------------------------------
44
45static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler, EventRef EventReference, void* Data)
46{
47 wxDataViewCtrl* DataViewCtrlPtr((wxDataViewCtrl*) Data); // the 'Data' variable always contains a pointer to the data view control that installed the handler
48
49 wxMacCarbonEvent CarbonEvent(EventReference) ;
50
51
52 switch (GetEventKind(EventReference))
53 {
54 case kEventControlDraw:
55 {
56 OSStatus status;
57
58 DataViewCtrlPtr->MacSetDrawingContext(CarbonEvent.GetParameter<CGContextRef>(kEventParamCGContextRef,typeCGContextRef));
59 status = ::CallNextEventHandler(handler,EventReference);
60 DataViewCtrlPtr->MacSetDrawingContext(NULL);
61 return status;
62 } /* block */
63 case kEventControlHit :
64 if (CarbonEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) == kControlButtonPart) // we only care about the header
65 {
66 ControlRef controlReference;
67 DataBrowserPropertyID columnPropertyID;
68 unsigned long columnIndex;
69 OSStatus status;
70 wxDataViewEvent DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,DataViewCtrlPtr->GetId());
71
72 CarbonEvent.GetParameter(kEventParamDirectObject,&controlReference);
73 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
74 status = ::GetDataBrowserSortProperty(controlReference,&columnPropertyID);
75 wxCHECK(status == noErr,status);
76 status = ::GetDataBrowserTableViewColumnPosition(controlReference,columnPropertyID,&columnIndex);
77 if (status == errDataBrowserPropertyNotFound) // user clicked into part of the header that does not have a property
78 return ::CallNextEventHandler(handler,EventReference);
79 wxCHECK(status == noErr,status);
80 // initialize wxWidget event handler:
81 DataViewEvent.SetEventObject(DataViewCtrlPtr);
82 DataViewEvent.SetColumn(columnIndex);
83 DataViewEvent.SetDataViewColumn(DataViewCtrlPtr->GetColumn(columnIndex));
84 // finally sent the equivalent wxWidget event:
85 DataViewCtrlPtr->GetEventHandler()->ProcessEvent(DataViewEvent);
86 return ::CallNextEventHandler(handler,EventReference);
87 } /* if */
88 else
89 return eventNotHandledErr;
90 } /* switch */
91
92 return eventNotHandledErr;
93} /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
94
95//-----------------------------------------------------------------------------
96// local function pointers
97//-----------------------------------------------------------------------------
98
99DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler)
100
101// ---------------------------------------------------------
194027ac 102// wxMacDataViewModelNotifier
c0a66d92
RR
103// ---------------------------------------------------------
104#pragma mark -
194027ac 105class wxMacDataViewModelNotifier : public wxDataViewModelNotifier
c0a66d92
RR
106{
107public:
194027ac 108 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
c0a66d92
RR
109 {
110 }
111
194027ac 112 virtual bool ItemAdded(const wxDataViewItem &parent, const wxDataViewItem &item)
c0a66d92 113 {
194027ac
RR
114 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
115
116
117 wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
118 if (!(parent.IsOk()) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem, &itemID) == noErr) ||
119 parent.IsOk() && (this->m_dataViewControlPtr->AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr))
c0a66d92 120 {
194027ac 121 // variable definitions and initializations:
c0a66d92 122 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
194027ac 123 wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED,dataViewCtrlPtr->GetId());
c0a66d92 124
c0a66d92 125 dataViewEvent.SetEventObject(dataViewCtrlPtr);
194027ac 126 dataViewEvent.SetItem(item);
c0a66d92
RR
127 // sent the equivalent wxWidget event:
128 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
194027ac 129 // done:
c0a66d92
RR
130 return true;
131 } /* if */
132 else
133 return false;
194027ac
RR
134 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
135
136 virtual bool ItemChanged(wxDataViewItem const& item)
c0a66d92 137 {
194027ac 138 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
c0a66d92
RR
139
140
194027ac
RR
141 wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
142 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
143 if (this->m_dataViewControlPtr->UpdateItems(&itemID) == noErr)
c0a66d92
RR
144 {
145 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
146
147 // sent the equivalent wxWidget event:
194027ac 148 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
c0a66d92
RR
149
150 dataViewEvent.SetEventObject(dataViewCtrlPtr);
194027ac 151 dataViewEvent.SetItem(item);
c0a66d92
RR
152 // sent the equivalent wxWidget event:
153 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
154 // done
155 return true;
156 } /* if */
157 else
158 return false;
194027ac 159 } /* ItemChanged(wxDataViewItem const&) */
c0a66d92 160
194027ac 161 virtual bool ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
c0a66d92 162 {
194027ac 163 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
c0a66d92
RR
164
165
194027ac
RR
166 wxCHECK_MSG(item.IsOk(),false,_("Deleted item is invalid."));
167 if (this->m_dataViewControlPtr->RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr)
c0a66d92 168 {
194027ac
RR
169 // variable definitions and initializations:
170 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
171 wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED,dataViewCtrlPtr->GetId());
c0a66d92 172
194027ac
RR
173 dataViewEvent.SetEventObject(dataViewCtrlPtr);
174 dataViewEvent.SetItem(item);
175 // sent the equivalent wxWidget event:
176 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
177 // done
178 return true;
c0a66d92
RR
179 } /* if */
180 else
181 return false;
194027ac
RR
182 } /* ItemDeleted(wxDataViewItem const&) */
183
184 virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col)
c0a66d92 185 {
194027ac
RR
186 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
187 DataBrowserItemID parentID;
c0a66d92
RR
188
189 DataBrowserPropertyID propertyID;
190
194027ac
RR
191 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
192
193
194 wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
195 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
196 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Control is wrongly initialized."));
197 parentID = reinterpret_cast<DataBrowserItemID>(this->GetOwner()->GetParent(item).GetID());
198 if ((this->m_dataViewControlPtr->GetPropertyID(col,&propertyID) == noErr) &&
199 (this->m_dataViewControlPtr->UpdateItems(parentID,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
c0a66d92 200 {
194027ac
RR
201 // variable definition and initialization:
202 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED,dataViewCtrlPtr->GetId());
c0a66d92
RR
203
204 dataViewEvent.SetEventObject(dataViewCtrlPtr);
205 dataViewEvent.SetColumn(col);
194027ac
RR
206 dataViewEvent.SetItem(item);
207 // send the equivalent wxWidget event:
c0a66d92
RR
208 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
209 // done
210 return true;
211 } /* if */
212 else
213 return false;
194027ac 214 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
c0a66d92 215
c0a66d92
RR
216 virtual bool Cleared(void)
217 {
c0a66d92
RR
218 if (this->m_dataViewControlPtr->RemoveItems() == noErr)
219 {
194027ac 220 // variable definitions and initializations:
c0a66d92 221 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
194027ac 222 wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED,dataViewCtrlPtr->GetId());
c0a66d92
RR
223
224 dataViewEvent.SetEventObject(dataViewCtrlPtr);
194027ac 225 // send the equivalent wxWidget event:
c0a66d92
RR
226 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
227 // done
228 return true;
229 } /* if */
230 else
231 return false;
194027ac 232 } /* Cleared(void) */
c0a66d92
RR
233
234protected:
235private:
236//
237// variables
238//
239 wxMacDataViewDataBrowserListViewControl* m_dataViewControlPtr;
240};
241
242// ---------------------------------------------------------
243// wxDataViewRenderer
244// ---------------------------------------------------------
245#pragma mark -
246wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
247 :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode)
248{
249} /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
250
251void wxDataViewRenderer::SetMode(wxDataViewCellMode mode)
252{
253 wxDataViewColumn* dataViewColumnPtr;
254
255
256 this->m_mode = mode;
257 dataViewColumnPtr = this->GetOwner();
258 if (dataViewColumnPtr != NULL)
259 {
260 // variable definition and initialization:
261 wxDataViewCtrl* dataViewCtrlPtr(dataViewColumnPtr->GetOwner());
262
263 if (dataViewCtrlPtr != NULL)
264 {
265 // variable definition and initialization:
266 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
267
268 if (macDataViewListCtrlPtr != NULL)
269 {
270 // variable definition and initialization:
271 DataBrowserPropertyFlags flags;
272
273 verify_noerr(macDataViewListCtrlPtr->GetPropertyFlags(dataViewColumnPtr->GetPropertyID(),&flags));
274 if (mode == wxDATAVIEW_CELL_EDITABLE)
275 flags |= kDataBrowserPropertyIsEditable;
276 else
277 flags &= ~kDataBrowserPropertyIsEditable;
278 verify_noerr(macDataViewListCtrlPtr->SetPropertyFlags(dataViewColumnPtr->GetPropertyID(),flags));
279 } /* if */
280 } /* if */
281 } /* if */
282} /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
283
284IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
285
286// ---------------------------------------------------------
287// wxDataViewCustomRenderer
288// ---------------------------------------------------------
289#pragma mark -
290wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
291 :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL)
292{
293} /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
294
295wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
296{
297 if (this->m_DCPtr != NULL)
298 delete this->m_DCPtr;
299} /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
300
301wxDC* wxDataViewCustomRenderer::GetDC(void)
302{
303 if (this->m_DCPtr == NULL)
304 {
305 if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL))
306 return NULL;
307 this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner());
308 } /* if */
309 return this->m_DCPtr;
310} /* wxDataViewCustomRenderer::GetDC(void) */
311
312bool wxDataViewCustomRenderer::Render(void)
313{
314 return false;
315} /* wxDataViewCustomRenderer::Render(void) */
316
317void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
318{
319 delete this->m_DCPtr;
320 this->m_DCPtr = newDCPtr;
321} /* wxDataViewCustomRenderer::SetDC(wxDC*) */
322
323
324IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
325
326// ---------------------------------------------------------
327// wxDataViewTextRenderer
328// ---------------------------------------------------------
329#pragma mark -
330wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
331 :wxDataViewRenderer(varianttype,mode,align)
332{
333} /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
334
335bool wxDataViewTextRenderer::Render(void)
336{
337 if (this->GetValue().GetType() == this->GetVariantType())
338 {
339 // variable definition:
340 wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
341
342 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
343 } /* if */
344 else
345 return false;
346} /* wxDataViewTextRenderer::Render(void) */
347
348IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
349
350// ---------------------------------------------------------
351// wxDataViewBitmapRenderer
352// ---------------------------------------------------------
353#pragma mark -
354wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
355 :wxDataViewRenderer(varianttype,mode,align)
356{
357}
358
359bool wxDataViewBitmapRenderer::Render(void)
360{
361 if (this->GetValue().GetType() == this->GetVariantType())
362 {
363 wxBitmap bitmap;
364
365 bitmap << this->GetValue();
366 if (bitmap.Ok())
367 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
368 else
369 return false;
370 } /* if */
371 else
372 return false;
373} /* wxDataViewBitmapRenderer::Render(void) */
374
375IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
376
377// ---------------------------------------------------------
378// wxDataViewToggleRenderer
379// ---------------------------------------------------------
380#pragma mark -
381wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
382 :wxDataViewRenderer(varianttype,mode)
383{
384}
385
386bool wxDataViewToggleRenderer::Render(void)
387{
388 if (this->GetValue().GetType() == this->GetVariantType())
389 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr);
390 else
391 return false;
392} /* wxDataViewToggleRenderer::Render(void) */
393
394IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
395
396// ---------------------------------------------------------
397// wxDataViewProgressRenderer
398// ---------------------------------------------------------
399#pragma mark -
400wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align)
401 :wxDataViewRenderer(varianttype,mode,align)
402{
403}
404
405bool wxDataViewProgressRenderer::Render(void)
406{
407 if (this->GetValue().GetType() == this->GetVariantType())
408 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) &&
409 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) &&
410 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr));
411 else
412 return false;
413} /* wxDataViewProgressRenderer::Render(void) */
414
415IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
416
417// ---------------------------------------------------------
418// wxDataViewDateRenderer
419// ---------------------------------------------------------
420#pragma mark -
421wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
422 :wxDataViewRenderer(varianttype,mode,align)
423{
424}
425
426bool wxDataViewDateRenderer::Render(void)
427{
428 if (this->GetValue().GetType() == this->GetVariantType())
429 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
430 else
431 return false;
432} /* wxDataViewDateRenderer::Render(void) */
433
434IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
435
436// ---------------------------------------------------------
437// wxDataViewColumn
438// ---------------------------------------------------------
439#pragma mark -
440wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
194027ac
RR
441 :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
442 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits<int>::max()), m_minWidth(0), m_width(width),
443 m_alignment(align), m_title(title)
c0a66d92
RR
444{
445} /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
446
447wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
194027ac
RR
448 :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
449 m_flags(flags & (wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits<int>::max()), m_minWidth(0), m_width(width),
450 m_alignment(align)
c0a66d92
RR
451{
452} /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
453
454void wxDataViewColumn::SetAlignment(wxAlignment align)
455{
456 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
457
458
459 this->m_alignment = align;
460 if (dataViewCtrlPtr != NULL)
461 {
462 // variable definition and initialization:
463 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
464
465 if (macDataViewListCtrlPtr != NULL)
466 {
467 // variable definition and initialization:
468 DataBrowserListViewHeaderDesc headerDescription;
469
470 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
471 switch (align)
472 {
473 case wxALIGN_CENTER:
474 case wxALIGN_CENTER_HORIZONTAL:
475 headerDescription.btnFontStyle.just = teCenter;
476 break;
477 case wxALIGN_LEFT:
478 headerDescription.btnFontStyle.just = teFlushLeft;
479 break;
480 case wxALIGN_RIGHT:
481 headerDescription.btnFontStyle.just = teFlushRight;
482 break;
483 default:
484 headerDescription.btnFontStyle.just = teFlushDefault;
485 } /* switch */
486 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
487 } /* if */
488 } /* if */
489} /* wxDataViewColumn::SetAlignment(wxAlignment) */
490
491void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
492{
493 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
494
495
496 wxDataViewColumnBase::SetBitmap(bitmap);
497 if (dataViewCtrlPtr != NULL)
498 {
499 // variable definition and initialization:
500 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
501
502 if (macDataViewListCtrlPtr != NULL)
503 {
504 // variable definition and initialization:
505 DataBrowserListViewHeaderDesc headerDescription;
506
507 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
508 if (this->GetBitmap().Ok())
509 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
510 else
511 headerDescription.btnContentInfo.u.iconRef = NULL;
512 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
513 } /* if */
514 } /* if */
515} /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
516
517void wxDataViewColumn::SetFlags(int flags)
518{
519 this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0);
520 this->SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
521 this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0);
522} /* wxDataViewColumn::SetFlags(int) */
523
524void wxDataViewColumn::SetMaxWidth(int maxWidth)
525{
526 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
527
528
529 this->m_maxWidth = maxWidth;
530 if (dataViewCtrlPtr != NULL)
531 {
532 // variable definition and initialization:
533 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
534
535 if (macDataViewListCtrlPtr != NULL)
536 {
537 // variable definition and initialization:
538 DataBrowserListViewHeaderDesc headerDescription;
539
540 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
541 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
542 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
543 } /* if */
544 } /* if */
545} /* wxDataViewColumn::SetMaxWidth(int) */
546
547void wxDataViewColumn::SetMinWidth(int minWidth)
548{
549 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
550
551
552 this->m_minWidth = minWidth;
553 if (dataViewCtrlPtr != NULL)
554 {
555 // variable definition and initialization:
556 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
557
558 if (macDataViewListCtrlPtr != NULL)
559 {
560 // variable definition and initialization:
561 DataBrowserListViewHeaderDesc headerDescription;
562
563 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
564 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
565 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
566 } /* if */
567 } /* if */
568} /* wxDataViewColumn::SetMaxWidth(int) */
569
570void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable))
571{
572} /* wxDataViewColumn::SetResizeable(bool) */
573
574void wxDataViewColumn::SetSortable(bool sortable)
575{
576 // variable definition and initialization:
577 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
578
579 if (dataViewCtrlPtr != NULL)
580 {
581 // variable definition and initialization:
582 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
583
584 if (macDataViewListCtrlPtr != NULL)
585 {
586 // variable definition and initialization:
587 DataBrowserPropertyFlags flags;
588
589 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
590 if (sortable)
591 {
592 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
593 flags |= kDataBrowserListViewSortableColumn;
594 } /* if */
595 else
596 {
597 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
598 flags &= ~kDataBrowserPropertyIsEditable;
599 } /* if */
600 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
601 } /* if */
602 } /* if */
603} /* wxDataViewColumn::SetSortable(bool) */
604
605void wxDataViewColumn::SetSortOrder(bool ascending)
606{
607 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
608
609
610 this->m_ascending = ascending;
611 if (dataViewCtrlPtr != NULL)
612 {
613 // variable definition and initialization:
614 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
615
616 if (macDataViewListCtrlPtr != NULL)
617 {
618 // variable definition and initialization:
619 DataBrowserListViewHeaderDesc headerDescription;
620
621 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
622 if (ascending)
623 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
624 else
625 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
626 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
627 } /* if */
628 } /* if */
629} /* wxDataViewColumn::SetSortOrder(bool) */
630
631void wxDataViewColumn::SetTitle(wxString const& title)
632{
633 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
634
635
636 this->m_title = title;
637 if (dataViewCtrlPtr != NULL)
638 {
639 // variable definition and initialization:
640 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
641
642 if (macDataViewListCtrlPtr != NULL)
643 {
644 // variable definition and initialization:
645 DataBrowserListViewHeaderDesc headerDescription;
646 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
647
648 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
649 headerDescription.titleString = cfTitle;
650 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
651 } /* if */
652 } /* if */
653} /* wxDataViewColumn::SetTitle(wxString const&) */
654
655void wxDataViewColumn::SetWidth(int width)
656{
657 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
658
659
660 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
661 {
662 this->m_width = width;
663 if (dataViewCtrlPtr != NULL)
664 {
665 // variable definition and initialization:
666 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
667
668 if (macDataViewListCtrlPtr != NULL)
669 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
670 } /* if */
671 } /* if */
672} /* wxDataViewColumn::SetWidth(int) */
673
674IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
675
676//-----------------------------------------------------------------------------
677// wxDataViewCtrl
678//-----------------------------------------------------------------------------
679#pragma mark -
680void wxDataViewCtrl::Init(void)
681{
682 this->m_macIsUserPane = false;
683 this->m_NotifierPtr = NULL;
684 this->m_cgContext = NULL;
685} /* wxDataViewCtrl::Init(void) */
686
687bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
688{
689 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
690 return false;
691
692#ifdef __WXMAC__
693 MacSetClipChildren(true) ;
694#endif
695
696 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
697 this->MacPostControlCreate(pos,size);
698
699 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
700
701 return true;
702} /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
703
c0a66d92
RR
704bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
705{
194027ac
RR
706 // first, some error checking:
707 wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL."));
708 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
709 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
710 wxCHECK_MSG((dataViewColumnPtr->GetModelColumn() >= 0) &&
711 (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
c0a66d92
RR
712 if (this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr))
713 {
714 // variable definition:
194027ac 715 DataBrowserPropertyID NewPropertyID;
c0a66d92
RR
716 DataBrowserListViewColumnDesc columnDescription;
717 wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding()));
718 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
719
720 // initialize column description:
194027ac
RR
721 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
722 wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Maximum number of columns reached."));
723 dataViewColumnPtr->SetPropertyID(NewPropertyID);
724 columnDescription.propertyDesc.propertyID = NewPropertyID;
c0a66d92
RR
725 columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType();
726 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn;
727 if (dataViewColumnPtr->IsSortable())
728 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
729 if (dataViewColumnPtr->IsResizeable())
730 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
731 if (dataViewColumnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE)
732 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
733#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
734 if ((columnDescription.propertyDesc.propertyType == kDataBrowserTextType) ||
735 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
736 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType))
737 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
738#endif
739#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
740 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
741#endif
742 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
743 columnDescription.headerBtnDesc.minimumWidth = 0;
744 columnDescription.headerBtnDesc.maximumWidth = 30000;
745 columnDescription.headerBtnDesc.titleOffset = 0;
746 columnDescription.headerBtnDesc.titleString = cfTitle; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
747 // having called 'AddColumn' where the title (CFStringRef) is going to be used
748 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
749 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
750 switch (dataViewColumnPtr->GetAlignment())
751 {
752 case wxALIGN_CENTER:
753 case wxALIGN_CENTER_HORIZONTAL:
754 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
755 break;
756 case wxALIGN_LEFT:
757 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
758 break;
759 case wxALIGN_RIGHT:
760 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
761 break;
762 default:
763 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
764 } /* switch */
765 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
766 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
767 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
768 if (dataViewColumnPtr->GetBitmap().Ok())
769 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef();
770 // add column:
194027ac
RR
771 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
772
c0a66d92
RR
773 // final adjustments for the layout:
774 if (dataViewColumnPtr->GetWidth() <= 0)
194027ac
RR
775 dataViewColumnPtr->SetWidth(wxDVC_DEFAULT_WIDTH);
776 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
777 if (dataViewColumnPtr->IsSortable()) // if the current column is marked sortable this column will become the active sortable column, otherwise don't do anything
778 MacDataViewListCtrlPtr->SetSortProperty(NewPropertyID);
779 if (this->GetColumnCount()-1 == this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column
780 MacDataViewListCtrlPtr->SetDisclosureColumn(NewPropertyID,true);
781
782 // make sure that the data is up-to-date...
783 // if the newly appended column is the first column add the initial data to the control otherwise ask the control to 'update' the data in the newly appended column:
784 if (this->GetColumnCount() == 1)
785 this->AddChildrenLevel(wxDataViewItem());
786 else
787 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
c0a66d92
RR
788 // done:
789 return true;
790 } /* if */
791 else
792 return false;
793} /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
794
194027ac 795wxDataViewItem wxDataViewCtrl::GetSelection(void)
c0a66d92 796{
c0a66d92 797 wxArrayDataBrowserItemID itemIDs;
c0a66d92 798
194027ac 799 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
c0a66d92
RR
800
801
194027ac
RR
802 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
803 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
804 else
805 return wxDataViewItem();
806} /* wxDataViewCtrl::GetSelection(void) */
c0a66d92 807
194027ac 808bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
c0a66d92 809{
194027ac
RR
810 if (!wxDataViewCtrlBase::AssociateModel(model))
811 return false;
c0a66d92 812
194027ac
RR
813 this->m_NotifierPtr = new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer));
814 model->AddNotifier(this->m_NotifierPtr);
c0a66d92 815
194027ac
RR
816 return true;
817} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
c0a66d92 818
194027ac
RR
819// data handling:
820void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
c0a66d92 821{
194027ac 822 wxDataViewItem item;
c0a66d92 823
c0a66d92 824
194027ac
RR
825 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
826 item = this->GetModel()->GetFirstChild(parentItem);
827 while (item.IsOk())
828 {
829 (void) this->GetModel()->ItemAdded(parentItem,item);
830 item = this->GetModel()->GetNextSibling(item);
831 } /* while */
832} /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
c0a66d92 833
194027ac
RR
834// inherited methods from wxDataViewCtrlBase
835void wxDataViewCtrl::DoSetExpanderColumn(void)
c0a66d92 836{
194027ac 837 if (this->GetExpanderColumn() < this->GetColumnCount())
c0a66d92 838 {
194027ac
RR
839 // variable definition and initialization:
840 DataBrowserPropertyID propertyID;
841 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
842
843 if (MacDataViewListCtrlPtr->GetPropertyID(this->GetExpanderColumn(),&propertyID) == noErr)
844 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(propertyID);
c0a66d92 845 } /* if */
194027ac 846} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
c0a66d92 847
194027ac 848void wxDataViewCtrl::DoSetIndent(void)
c0a66d92 849{
194027ac 850} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
c0a66d92 851
194027ac
RR
852// event handling:
853void wxDataViewCtrl::OnSize(wxSizeEvent& event)
c0a66d92 854{
194027ac 855 unsigned int const NoOfColumns = this->GetColumnCount();
c0a66d92 856
194027ac
RR
857
858 for (unsigned int i=0; i<NoOfColumns; ++i)
c0a66d92
RR
859 {
860 // variable definition and initialization:
194027ac
RR
861 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
862
863 if (dataViewColumnPtr != NULL)
c0a66d92 864 {
194027ac
RR
865 // variable definition and initialization:
866 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
867
868 if (dataViewCustomRendererPtr != NULL)
869 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
c0a66d92 870 } /* if */
194027ac
RR
871 } /* for */
872 event.Skip();
873} /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
c0a66d92
RR
874
875IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
876
877BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
878 EVT_SIZE(wxDataViewCtrl::OnSize)
879END_EVENT_TABLE()
880
881#endif
882 // !wxUSE_GENERICDATAVIEWCTRL
883
884#endif
885 // wxUSE_DATAVIEWCTRL
886