]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dataview.cpp
cleanup
[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"
34b1fdeb
PC
25 #include "wx/settings.h"
26 #include "wx/dcclient.h"
c0a66d92
RR
27#endif
28
29#include "wx/icon.h"
30#include "wx/renderer.h"
31
32//-----------------------------------------------------------------------------
33// local constants
34//-----------------------------------------------------------------------------
35
36// a list of all catchable events:
37static EventTypeSpec const eventList[] =
38{
39 {kEventClassControl, kEventControlDraw},
40 {kEventClassControl, kEventControlHit}
41};
42
43//-----------------------------------------------------------------------------
44// local functions
45//-----------------------------------------------------------------------------
46
47static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler, EventRef EventReference, void* Data)
48{
49 wxDataViewCtrl* DataViewCtrlPtr((wxDataViewCtrl*) Data); // the 'Data' variable always contains a pointer to the data view control that installed the handler
50
51 wxMacCarbonEvent CarbonEvent(EventReference) ;
52
53
54 switch (GetEventKind(EventReference))
55 {
56 case kEventControlDraw:
57 {
58 OSStatus status;
59
60 DataViewCtrlPtr->MacSetDrawingContext(CarbonEvent.GetParameter<CGContextRef>(kEventParamCGContextRef,typeCGContextRef));
61 status = ::CallNextEventHandler(handler,EventReference);
62 DataViewCtrlPtr->MacSetDrawingContext(NULL);
63 return status;
64 } /* block */
65 case kEventControlHit :
66 if (CarbonEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) == kControlButtonPart) // we only care about the header
67 {
68 ControlRef controlReference;
69 DataBrowserPropertyID columnPropertyID;
70 unsigned long columnIndex;
71 OSStatus status;
72 wxDataViewEvent DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,DataViewCtrlPtr->GetId());
73
74 CarbonEvent.GetParameter(kEventParamDirectObject,&controlReference);
75 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
76 status = ::GetDataBrowserSortProperty(controlReference,&columnPropertyID);
77 wxCHECK(status == noErr,status);
78 status = ::GetDataBrowserTableViewColumnPosition(controlReference,columnPropertyID,&columnIndex);
79 if (status == errDataBrowserPropertyNotFound) // user clicked into part of the header that does not have a property
80 return ::CallNextEventHandler(handler,EventReference);
81 wxCHECK(status == noErr,status);
82 // initialize wxWidget event handler:
83 DataViewEvent.SetEventObject(DataViewCtrlPtr);
84 DataViewEvent.SetColumn(columnIndex);
85 DataViewEvent.SetDataViewColumn(DataViewCtrlPtr->GetColumn(columnIndex));
86 // finally sent the equivalent wxWidget event:
87 DataViewCtrlPtr->GetEventHandler()->ProcessEvent(DataViewEvent);
88 return ::CallNextEventHandler(handler,EventReference);
89 } /* if */
90 else
91 return eventNotHandledErr;
92 } /* switch */
93
94 return eventNotHandledErr;
95} /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
96
a5fb9253
RR
97static DataBrowserItemID* CreateDataBrowserItemIDArray(size_t& noOfEntries, wxDataViewItemArray const& items) // returns a newly allocated pointer to valid data browser item IDs
98{
99 size_t const noOfItems = items.GetCount();
100
101 DataBrowserItemID* itemIDs(new DataBrowserItemID[noOfItems]);
102
103
104 // convert all valid data view items to data browser items
105 noOfEntries = 0;
106 for (size_t i=0; i<noOfItems; ++i)
107 if (items[i].IsOk())
108 {
109 itemIDs[noOfEntries] = reinterpret_cast<DataBrowserItemID>(items[i].GetID());
110 ++noOfEntries;
111 } /* if */
112 // done:
113 return itemIDs;
114} /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
115
c0a66d92
RR
116//-----------------------------------------------------------------------------
117// local function pointers
118//-----------------------------------------------------------------------------
119
120DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler)
121
122// ---------------------------------------------------------
194027ac 123// wxMacDataViewModelNotifier
c0a66d92
RR
124// ---------------------------------------------------------
125#pragma mark -
194027ac 126class wxMacDataViewModelNotifier : public wxDataViewModelNotifier
c0a66d92
RR
127{
128public:
194027ac 129 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
c0a66d92
RR
130 {
131 }
132
194027ac 133 virtual bool ItemAdded(const wxDataViewItem &parent, const wxDataViewItem &item)
c0a66d92 134 {
194027ac
RR
135 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
136
137
138 wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
07c51ff1
RR
139 return (!(parent.IsOk()) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&itemID) == noErr) ||
140 parent.IsOk() && (this->m_dataViewControlPtr->AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr));
194027ac
RR
141 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
142
a5fb9253
RR
143 virtual bool ItemsAdded(wxDataViewItem const& parent, wxDataViewItemArray const& items)
144 {
145 bool noFailureFlag;
146
147 DataBrowserItemID* itemIDs;
148
149 size_t noOfEntries;
150
151
152 // convert all valid data view items to data browser items:
153 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
154 // insert all valid items into control:
155 noFailureFlag = ((noOfEntries == 0) ||
156 !(parent.IsOk()) && (this->m_dataViewControlPtr->AddItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr) ||
157 parent.IsOk() && (this->m_dataViewControlPtr->AddItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr));
158 // give allocated array space free again:
159 delete[] itemIDs;
160 // done:
161 return noFailureFlag;
162 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
163
194027ac 164 virtual bool ItemChanged(wxDataViewItem const& item)
c0a66d92 165 {
194027ac 166 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
c0a66d92
RR
167
168
a5fb9253 169 wxCHECK_MSG(item.IsOk(),false,_("Changed item is invalid."));
194027ac 170 if (this->m_dataViewControlPtr->UpdateItems(&itemID) == noErr)
c0a66d92
RR
171 {
172 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
173
174 // sent the equivalent wxWidget event:
a5fb9253 175 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
c0a66d92
RR
176
177 dataViewEvent.SetEventObject(dataViewCtrlPtr);
194027ac 178 dataViewEvent.SetItem(item);
c0a66d92
RR
179 // sent the equivalent wxWidget event:
180 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
181 // done
182 return true;
183 } /* if */
184 else
185 return false;
194027ac 186 } /* ItemChanged(wxDataViewItem const&) */
c0a66d92 187
a5fb9253
RR
188 virtual bool ItemsChanged(wxDataViewItemArray const& items)
189 {
190 bool noFailureFlag;
191
192 DataBrowserItemID* itemIDs;
193
194 size_t noOfEntries;
195
196
197 // convert all valid data view items to data browser items:
198 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
199 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
200 noFailureFlag = (this->m_dataViewControlPtr->UpdateItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty,kDataBrowserItemNoProperty) == noErr);
201 if (noFailureFlag)
202 {
203 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
204
205 // send for all changed items a wxWidget event:
206 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
207
208 dataViewEvent.SetEventObject(dataViewCtrlPtr);
209 for (size_t i=0; i<noOfEntries; ++i)
210 {
211 dataViewEvent.SetItem(reinterpret_cast<void*>(itemIDs[i]));
212 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
213 } /* for */
214 } /* if */
215 // release allocated array space:
216 delete[] itemIDs;
217 // done:
218 return noFailureFlag;
219 } /* ItemsChanged(wxDataViewItem const&) */
220
194027ac 221 virtual bool ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
c0a66d92 222 {
07c51ff1 223 if (item.IsOk())
c0a66d92 224 {
07c51ff1
RR
225 // variable definition and initialization:
226 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
227 OSStatus errorStatus;
228 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
229
230 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
a5fb9253
RR
231 // not to be identical because the being edited item might be below the passed item in the hierarchy);
232 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
233 // has been started and that variables can currently not be updated even when requested by the system:
07c51ff1
RR
234 dataViewCtrlPtr->SetDeleting(true);
235 errorStatus = this->m_dataViewControlPtr->RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID);
a5fb9253 236 // enable automatic updating again:
07c51ff1
RR
237 dataViewCtrlPtr->SetDeleting(false);
238 return (errorStatus == noErr);
c0a66d92
RR
239 } /* if */
240 else
241 return false;
07c51ff1 242 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
194027ac 243
a5fb9253
RR
244 virtual bool ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items)
245 {
246 bool noFailureFlag;
247
248 DataBrowserItemID* itemIDs;
249
250 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
251
252 size_t noOfEntries;
253
254
255 wxCHECK_MSG(dataViewCtrlPtr != NULL,false,_("Data view control is not correctly initialized"));
256 // convert all valid data view items to data browser items:
257 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
258 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
259 // not to be identical because the being edited item might be below the passed item in the hierarchy);
260 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
261 // has been started and that variables can currently not be updated even when requested by the system:
262 dataViewCtrlPtr->SetDeleting(true);
263 // insert all valid items into control:
264 noFailureFlag = ((noOfEntries == 0) ||
265 !(parent.IsOk()) && (this->m_dataViewControlPtr->RemoveItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr) ||
266 parent.IsOk() && (this->m_dataViewControlPtr->RemoveItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr));
267 // enable automatic updating again:
268 dataViewCtrlPtr->SetDeleting(false);
269 // give allocated array space free again:
270 delete[] itemIDs;
271 // done:
272 return noFailureFlag;
273 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
274
194027ac 275 virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col)
c0a66d92 276 {
194027ac
RR
277 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
278 DataBrowserItemID parentID;
c0a66d92
RR
279
280 DataBrowserPropertyID propertyID;
281
194027ac
RR
282 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
283
284
285 wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
286 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
287 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Control is wrongly initialized."));
288 parentID = reinterpret_cast<DataBrowserItemID>(this->GetOwner()->GetParent(item).GetID());
289 if ((this->m_dataViewControlPtr->GetPropertyID(col,&propertyID) == noErr) &&
290 (this->m_dataViewControlPtr->UpdateItems(parentID,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
c0a66d92 291 {
194027ac 292 // variable definition and initialization:
6608fdab 293 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,dataViewCtrlPtr->GetId());
c0a66d92
RR
294
295 dataViewEvent.SetEventObject(dataViewCtrlPtr);
296 dataViewEvent.SetColumn(col);
194027ac
RR
297 dataViewEvent.SetItem(item);
298 // send the equivalent wxWidget event:
c0a66d92
RR
299 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
300 // done
301 return true;
302 } /* if */
303 else
304 return false;
194027ac 305 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
c0a66d92 306
c0a66d92
RR
307 virtual bool Cleared(void)
308 {
a5fb9253 309 return (this->m_dataViewControlPtr->RemoveItems() == noErr);
194027ac 310 } /* Cleared(void) */
c0a66d92 311
07c51ff1
RR
312 virtual void Resort(void)
313 {
314 this->m_dataViewControlPtr->Resort();
315 }
316
c0a66d92
RR
317protected:
318private:
319//
320// variables
321//
322 wxMacDataViewDataBrowserListViewControl* m_dataViewControlPtr;
323};
324
325// ---------------------------------------------------------
326// wxDataViewRenderer
327// ---------------------------------------------------------
328#pragma mark -
329wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
330 :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode)
331{
332} /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
333
334void wxDataViewRenderer::SetMode(wxDataViewCellMode mode)
335{
336 wxDataViewColumn* dataViewColumnPtr;
337
338
339 this->m_mode = mode;
340 dataViewColumnPtr = this->GetOwner();
341 if (dataViewColumnPtr != NULL)
342 {
343 // variable definition and initialization:
344 wxDataViewCtrl* dataViewCtrlPtr(dataViewColumnPtr->GetOwner());
345
346 if (dataViewCtrlPtr != NULL)
347 {
348 // variable definition and initialization:
349 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
350
351 if (macDataViewListCtrlPtr != NULL)
352 {
353 // variable definition and initialization:
354 DataBrowserPropertyFlags flags;
355
356 verify_noerr(macDataViewListCtrlPtr->GetPropertyFlags(dataViewColumnPtr->GetPropertyID(),&flags));
357 if (mode == wxDATAVIEW_CELL_EDITABLE)
358 flags |= kDataBrowserPropertyIsEditable;
359 else
360 flags &= ~kDataBrowserPropertyIsEditable;
361 verify_noerr(macDataViewListCtrlPtr->SetPropertyFlags(dataViewColumnPtr->GetPropertyID(),flags));
362 } /* if */
363 } /* if */
364 } /* if */
365} /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
366
367IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
368
369// ---------------------------------------------------------
370// wxDataViewCustomRenderer
371// ---------------------------------------------------------
372#pragma mark -
373wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
c17b2e31 374 :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL)
c0a66d92
RR
375{
376} /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
377
378wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
379{
380 if (this->m_DCPtr != NULL)
381 delete this->m_DCPtr;
382} /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
383
52e750fc
RR
384void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
385{
386 wxDataViewCtrl *view = GetOwner()->GetOwner();
387 wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
388 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
389 view->GetForegroundColour();
390 dc->SetTextForeground(col);
391 dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
392}
393
c0a66d92
RR
394wxDC* wxDataViewCustomRenderer::GetDC(void)
395{
396 if (this->m_DCPtr == NULL)
397 {
398 if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL))
399 return NULL;
400 this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner());
401 } /* if */
402 return this->m_DCPtr;
403} /* wxDataViewCustomRenderer::GetDC(void) */
404
405bool wxDataViewCustomRenderer::Render(void)
406{
c17b2e31 407 return true;
c0a66d92
RR
408} /* wxDataViewCustomRenderer::Render(void) */
409
410void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
411{
412 delete this->m_DCPtr;
413 this->m_DCPtr = newDCPtr;
414} /* wxDataViewCustomRenderer::SetDC(wxDC*) */
415
34b1fdeb
PC
416WXDataBrowserPropertyType wxDataViewCustomRenderer::GetPropertyType() const
417{
f53c8638 418 return kDataBrowserCustomType;
34b1fdeb 419}
c0a66d92
RR
420
421IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
422
423// ---------------------------------------------------------
424// wxDataViewTextRenderer
425// ---------------------------------------------------------
426#pragma mark -
427wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
428 :wxDataViewRenderer(varianttype,mode,align)
429{
430} /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
431
432bool wxDataViewTextRenderer::Render(void)
433{
434 if (this->GetValue().GetType() == this->GetVariantType())
435 {
436 // variable definition:
437 wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
438
439 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
440 } /* if */
441 else
442 return false;
443} /* wxDataViewTextRenderer::Render(void) */
444
34b1fdeb
PC
445WXDataBrowserPropertyType wxDataViewTextRenderer::GetPropertyType() const
446{
f53c8638 447 return kDataBrowserTextType;
34b1fdeb
PC
448}
449
c0a66d92
RR
450IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
451
452// ---------------------------------------------------------
453// wxDataViewBitmapRenderer
454// ---------------------------------------------------------
455#pragma mark -
456wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
457 :wxDataViewRenderer(varianttype,mode,align)
458{
459}
460
461bool wxDataViewBitmapRenderer::Render(void)
462{
463 if (this->GetValue().GetType() == this->GetVariantType())
464 {
465 wxBitmap bitmap;
466
467 bitmap << this->GetValue();
468 if (bitmap.Ok())
469 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
470 else
b741dd40 471 return true;
c0a66d92
RR
472 } /* if */
473 else
474 return false;
475} /* wxDataViewBitmapRenderer::Render(void) */
476
34b1fdeb
PC
477WXDataBrowserPropertyType wxDataViewBitmapRenderer::GetPropertyType() const
478{
f53c8638 479 return kDataBrowserIconType;
34b1fdeb
PC
480}
481
c0a66d92
RR
482IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
483
c17b2e31
RR
484// ---------------------------------------------------------
485// wxDataViewIconTextRenderer
486// ---------------------------------------------------------
487#pragma mark -
488wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
489 :wxDataViewRenderer(varianttype,mode)
490{
491}
492
493bool wxDataViewIconTextRenderer::Render(void)
494{
c17b2e31
RR
495 if (this->GetValue().GetType() == this->GetVariantType())
496 {
497 // variable definition:
498 wxDataViewIconText iconText;
499
500 iconText << this->GetValue();
501
502 // variable definition:
503 wxMacCFStringHolder cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
504
505 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) == noErr) &&
506 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr));
507 } /* if */
508 else
509 return false;
510} /* wxDataViewIconTextRenderer::Render(void) */
511
34b1fdeb
PC
512WXDataBrowserPropertyType wxDataViewIconTextRenderer::GetPropertyType() const
513{
f53c8638 514 return kDataBrowserIconAndTextType;
34b1fdeb
PC
515}
516
c17b2e31
RR
517IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer)
518
519
c0a66d92
RR
520// ---------------------------------------------------------
521// wxDataViewToggleRenderer
522// ---------------------------------------------------------
523#pragma mark -
524wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
525 :wxDataViewRenderer(varianttype,mode)
526{
527}
528
529bool wxDataViewToggleRenderer::Render(void)
530{
531 if (this->GetValue().GetType() == this->GetVariantType())
532 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr);
533 else
534 return false;
535} /* wxDataViewToggleRenderer::Render(void) */
536
34b1fdeb
PC
537WXDataBrowserPropertyType wxDataViewToggleRenderer::GetPropertyType() const
538{
f53c8638 539 return kDataBrowserCheckboxType;
34b1fdeb
PC
540}
541
c0a66d92
RR
542IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
543
544// ---------------------------------------------------------
545// wxDataViewProgressRenderer
546// ---------------------------------------------------------
547#pragma mark -
548wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align)
549 :wxDataViewRenderer(varianttype,mode,align)
550{
551}
552
553bool wxDataViewProgressRenderer::Render(void)
554{
555 if (this->GetValue().GetType() == this->GetVariantType())
556 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) &&
557 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) &&
558 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr));
559 else
560 return false;
561} /* wxDataViewProgressRenderer::Render(void) */
562
34b1fdeb
PC
563WXDataBrowserPropertyType wxDataViewProgressRenderer::GetPropertyType() const
564{
f53c8638 565 return kDataBrowserProgressBarType;
34b1fdeb
PC
566}
567
c0a66d92
RR
568IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
569
570// ---------------------------------------------------------
571// wxDataViewDateRenderer
572// ---------------------------------------------------------
573#pragma mark -
574wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
575 :wxDataViewRenderer(varianttype,mode,align)
576{
577}
578
579bool wxDataViewDateRenderer::Render(void)
580{
581 if (this->GetValue().GetType() == this->GetVariantType())
582 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
583 else
584 return false;
585} /* wxDataViewDateRenderer::Render(void) */
586
34b1fdeb
PC
587WXDataBrowserPropertyType wxDataViewDateRenderer::GetPropertyType() const
588{
f53c8638 589 return kDataBrowserDateTimeType;
34b1fdeb
PC
590}
591
c0a66d92
RR
592IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
593
594// ---------------------------------------------------------
595// wxDataViewColumn
596// ---------------------------------------------------------
597#pragma mark -
598wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
194027ac 599 :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
b741dd40 600 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH),
194027ac 601 m_alignment(align), m_title(title)
c0a66d92
RR
602{
603} /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
604
605wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
194027ac 606 :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
b741dd40 607 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH),
194027ac 608 m_alignment(align)
c0a66d92
RR
609{
610} /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
611
612void wxDataViewColumn::SetAlignment(wxAlignment align)
613{
614 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
615
616
617 this->m_alignment = align;
618 if (dataViewCtrlPtr != NULL)
619 {
620 // variable definition and initialization:
621 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
622
623 if (macDataViewListCtrlPtr != NULL)
624 {
625 // variable definition and initialization:
626 DataBrowserListViewHeaderDesc headerDescription;
627
628 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
629 switch (align)
630 {
631 case wxALIGN_CENTER:
632 case wxALIGN_CENTER_HORIZONTAL:
633 headerDescription.btnFontStyle.just = teCenter;
634 break;
635 case wxALIGN_LEFT:
636 headerDescription.btnFontStyle.just = teFlushLeft;
637 break;
638 case wxALIGN_RIGHT:
639 headerDescription.btnFontStyle.just = teFlushRight;
640 break;
641 default:
642 headerDescription.btnFontStyle.just = teFlushDefault;
643 } /* switch */
644 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
645 } /* if */
646 } /* if */
647} /* wxDataViewColumn::SetAlignment(wxAlignment) */
648
649void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
650{
651 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
652
653
654 wxDataViewColumnBase::SetBitmap(bitmap);
655 if (dataViewCtrlPtr != NULL)
656 {
657 // variable definition and initialization:
658 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
659
660 if (macDataViewListCtrlPtr != NULL)
661 {
662 // variable definition and initialization:
663 DataBrowserListViewHeaderDesc headerDescription;
664
665 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
666 if (this->GetBitmap().Ok())
667 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
668 else
669 headerDescription.btnContentInfo.u.iconRef = NULL;
670 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
671 } /* if */
672 } /* if */
673} /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
674
675void wxDataViewColumn::SetFlags(int flags)
676{
677 this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0);
678 this->SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
679 this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0);
680} /* wxDataViewColumn::SetFlags(int) */
681
682void wxDataViewColumn::SetMaxWidth(int maxWidth)
683{
684 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
685
686
687 this->m_maxWidth = maxWidth;
688 if (dataViewCtrlPtr != NULL)
689 {
690 // variable definition and initialization:
691 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
692
693 if (macDataViewListCtrlPtr != NULL)
694 {
695 // variable definition and initialization:
696 DataBrowserListViewHeaderDesc headerDescription;
697
698 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
699 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
700 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
701 } /* if */
702 } /* if */
703} /* wxDataViewColumn::SetMaxWidth(int) */
704
705void wxDataViewColumn::SetMinWidth(int minWidth)
706{
707 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
708
709
710 this->m_minWidth = minWidth;
711 if (dataViewCtrlPtr != NULL)
712 {
713 // variable definition and initialization:
714 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
715
716 if (macDataViewListCtrlPtr != NULL)
717 {
718 // variable definition and initialization:
719 DataBrowserListViewHeaderDesc headerDescription;
720
721 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
722 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
723 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
724 } /* if */
725 } /* if */
726} /* wxDataViewColumn::SetMaxWidth(int) */
727
728void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable))
729{
730} /* wxDataViewColumn::SetResizeable(bool) */
731
732void wxDataViewColumn::SetSortable(bool sortable)
733{
734 // variable definition and initialization:
735 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
736
737 if (dataViewCtrlPtr != NULL)
738 {
739 // variable definition and initialization:
740 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
741
742 if (macDataViewListCtrlPtr != NULL)
743 {
744 // variable definition and initialization:
745 DataBrowserPropertyFlags flags;
746
747 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
748 if (sortable)
749 {
750 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
751 flags |= kDataBrowserListViewSortableColumn;
752 } /* if */
753 else
754 {
755 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
756 flags &= ~kDataBrowserPropertyIsEditable;
757 } /* if */
758 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
759 } /* if */
760 } /* if */
761} /* wxDataViewColumn::SetSortable(bool) */
762
763void wxDataViewColumn::SetSortOrder(bool ascending)
764{
765 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
766
767
768 this->m_ascending = ascending;
769 if (dataViewCtrlPtr != NULL)
770 {
771 // variable definition and initialization:
772 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
773
774 if (macDataViewListCtrlPtr != NULL)
775 {
776 // variable definition and initialization:
777 DataBrowserListViewHeaderDesc headerDescription;
778
779 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
780 if (ascending)
781 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
782 else
783 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
784 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
6d9ecc87 785 macDataViewListCtrlPtr->SetSortProperty(this->GetPropertyID());
c0a66d92
RR
786 } /* if */
787 } /* if */
788} /* wxDataViewColumn::SetSortOrder(bool) */
789
790void wxDataViewColumn::SetTitle(wxString const& title)
791{
792 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
793
794
795 this->m_title = title;
796 if (dataViewCtrlPtr != NULL)
797 {
798 // variable definition and initialization:
799 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
800
801 if (macDataViewListCtrlPtr != NULL)
802 {
803 // variable definition and initialization:
804 DataBrowserListViewHeaderDesc headerDescription;
805 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
806
807 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
808 headerDescription.titleString = cfTitle;
809 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
810 } /* if */
811 } /* if */
812} /* wxDataViewColumn::SetTitle(wxString const&) */
813
814void wxDataViewColumn::SetWidth(int width)
815{
816 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
817
818
819 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
820 {
821 this->m_width = width;
822 if (dataViewCtrlPtr != NULL)
823 {
824 // variable definition and initialization:
825 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
826
827 if (macDataViewListCtrlPtr != NULL)
828 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
829 } /* if */
830 } /* if */
831} /* wxDataViewColumn::SetWidth(int) */
832
833IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
834
835//-----------------------------------------------------------------------------
836// wxDataViewCtrl
837//-----------------------------------------------------------------------------
838#pragma mark -
839void wxDataViewCtrl::Init(void)
840{
07c51ff1 841 this->m_Deleting = false;
c0a66d92 842 this->m_macIsUserPane = false;
c0a66d92
RR
843 this->m_cgContext = NULL;
844} /* wxDataViewCtrl::Init(void) */
845
846bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
847{
848 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
849 return false;
850
851#ifdef __WXMAC__
852 MacSetClipChildren(true) ;
853#endif
854
855 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
856 this->MacPostControlCreate(pos,size);
07c51ff1 857 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer->GetControlRef()),true);
c0a66d92
RR
858
859 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
860
861 return true;
862} /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
863
c17b2e31
RR
864bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
865{
866 if (!wxDataViewCtrlBase::AssociateModel(model))
867 return false;
868
869 model->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer)));
870
871 return true;
872} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
873
c0a66d92
RR
874bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
875{
c17b2e31
RR
876 DataBrowserPropertyID NewPropertyID;
877
878 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
879
880
194027ac 881 // first, some error checking:
c17b2e31 882 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
194027ac
RR
883 wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL."));
884 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
885 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
886 wxCHECK_MSG((dataViewColumnPtr->GetModelColumn() >= 0) &&
887 (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
c17b2e31 888 if ((MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr))
c0a66d92 889 {
c17b2e31
RR
890 // insert column into hash map:
891 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,dataViewColumnPtr));
892
07c51ff1 893 // variable definitions:
c17b2e31
RR
894 DataBrowserListViewColumnDesc columnDescription;
895 wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding()));
c0a66d92
RR
896
897 // initialize column description:
194027ac
RR
898 dataViewColumnPtr->SetPropertyID(NewPropertyID);
899 columnDescription.propertyDesc.propertyID = NewPropertyID;
34b1fdeb 900 columnDescription.propertyDesc.propertyType = DataBrowserPropertyType(dataViewColumnPtr->GetRenderer()->GetPropertyType());
07c51ff1 901 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable
c0a66d92
RR
902 if (dataViewColumnPtr->IsSortable())
903 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
07c51ff1
RR
904#if 0
905 if (dataViewColumnPtr->IsMovable())
c0a66d92 906 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
07c51ff1 907#endif
c0a66d92
RR
908 if (dataViewColumnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE)
909 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
80f3f3be 910
c0a66d92
RR
911 if ((columnDescription.propertyDesc.propertyType == kDataBrowserTextType) ||
912 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
913 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType))
914 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
80f3f3be 915
c0a66d92
RR
916#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
917 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
918#endif
919 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
c17b2e31 920 if (dataViewColumnPtr->IsResizeable())
07c51ff1
RR
921 {
922 columnDescription.headerBtnDesc.minimumWidth = 0;
923 columnDescription.headerBtnDesc.maximumWidth = 30000;
924 } /* if */
925 else
926 {
927 columnDescription.headerBtnDesc.minimumWidth = dataViewColumnPtr->GetWidth();
928 columnDescription.headerBtnDesc.maximumWidth = dataViewColumnPtr->GetWidth();
929 } /* if */
c0a66d92
RR
930 columnDescription.headerBtnDesc.titleOffset = 0;
931 columnDescription.headerBtnDesc.titleString = cfTitle; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
932 // having called 'AddColumn' where the title (CFStringRef) is going to be used
933 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
934 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
935 switch (dataViewColumnPtr->GetAlignment())
936 {
937 case wxALIGN_CENTER:
938 case wxALIGN_CENTER_HORIZONTAL:
939 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
940 break;
941 case wxALIGN_LEFT:
942 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
943 break;
944 case wxALIGN_RIGHT:
945 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
946 break;
947 default:
948 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
949 } /* switch */
950 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
951 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
952 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
953 if (dataViewColumnPtr->GetBitmap().Ok())
954 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef();
955 // add column:
194027ac
RR
956 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
957
c0a66d92 958 // final adjustments for the layout:
194027ac 959 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
194027ac
RR
960
961 // make sure that the data is up-to-date...
b741dd40
RR
962 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
963 // otherwise ask the control to 'update' the data in the newly appended column:
194027ac 964 if (this->GetColumnCount() == 1)
b741dd40
RR
965 {
966 this->SetExpanderColumn(dataViewColumnPtr);
194027ac 967 this->AddChildrenLevel(wxDataViewItem());
b741dd40 968 } /* if */
194027ac
RR
969 else
970 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
c0a66d92
RR
971 // done:
972 return true;
973 } /* if */
974 else
975 return false;
976} /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
977
c17b2e31 978bool wxDataViewCtrl::ClearColumns(void)
07c51ff1 979{
c17b2e31
RR
980 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
981
982
983 while (this->m_ColumnPointers.begin() != this->m_ColumnPointers.end())
984 {
985 wxCHECK_MSG(MacDataViewListCtrlPtr->RemoveColumnByProperty(this->m_ColumnPointers.begin()->first) == noErr,false,_("Could not remove column."));
986 delete this->m_ColumnPointers.begin()->second;
987 this->m_ColumnPointers.erase(this->m_ColumnPointers.begin());
988 } /* while */
989 return true;
990} /* wxDataViewCtrl::ClearColumns(void) */
991
992bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
993{
994 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
995
996
997 if ((MacDataViewListCtrlPtr->RemoveColumnByProperty(columnPtr->GetPropertyID()) == noErr) && (this->m_ColumnPointers.erase(columnPtr->GetPropertyID()) > 0))
998 {
999 delete columnPtr;
1000 return true;
1001 } /* if */
1002 else
07c51ff1 1003 return false;
c17b2e31
RR
1004} /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1005
1006wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
1007{
1008 DataBrowserPropertyID propertyID;
07c51ff1 1009
c17b2e31 1010 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
07c51ff1 1011
c17b2e31
RR
1012
1013 if (MacDataViewListCtrlPtr->GetPropertyID(pos,&propertyID) == noErr)
1014 {
1015 // variable definition:
1016 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1017
1018 if (Result != this->m_ColumnPointers.end())
1019 return Result->second;
1020 else
1021 return NULL;
1022 } /* if */
1023 else
1024 return NULL;
1025} /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1026
1027unsigned int wxDataViewCtrl::GetColumnCount(void) const
1028{
1029 return this->m_ColumnPointers.size();
1030} /* wxDataViewCtrl::GetColumnCount(void) const */
1031
6d9ecc87 1032int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
453091c2 1033{
6d9ecc87
RR
1034 if (columnPtr != NULL)
1035 {
1036 // variable definition and initialization:
1037 DataBrowserTableViewColumnIndex Position;
1038 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1039
1040 wxCHECK_MSG(MacDataViewListCtrlPtr->GetColumnIndex(columnPtr->GetPropertyID(),&Position) == noErr,-1,_("Could not determine column's position"));
1041 return static_cast<int>(Position);
1042 } /* if */
1043 else
1044 return wxNOT_FOUND;
1045} /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
21f47fb9 1046
c17b2e31
RR
1047void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
1048{
1049 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1050
1051
1052 MacDataViewListCtrlPtr->CloseContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1053} /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
07c51ff1
RR
1054
1055void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
1056{
1057 if (item.IsOk())
1058 {
1059 // variable definition and initialization:
1060 DataBrowserPropertyID propertyID;
1061 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1062
1063 if (columnPtr != NULL)
1064 propertyID = columnPtr->GetPropertyID();
1065 else
1066 propertyID = kDataBrowserNoItem;
1067 MacDataViewListCtrlPtr->RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
1068 } /* if */
1069} /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1070
c17b2e31
RR
1071void wxDataViewCtrl::Expand(wxDataViewItem const& item)
1072{
1073 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1074
1075
1076 MacDataViewListCtrlPtr->OpenContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1077} /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1078
6d9ecc87
RR
1079wxDataViewColumn* wxDataViewCtrl::GetSortingColumn(void) const
1080{
1081 DataBrowserPropertyID propertyID;
1082
1083 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1084
1085
1086 if (MacDataViewListCtrlPtr->GetSortProperty(&propertyID) == noErr)
1087 return this->GetColumnPtr(propertyID);
1088 else
1089 return NULL;
1090} /* wxDataViewCtrl::GetSortingColumn(void) const */
1091
b741dd40
RR
1092unsigned int wxDataViewCtrl::GetCount(void) const
1093{
1094 ItemCount noOfItems;
1095
1096
1097 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)->GetItemCount(&noOfItems) == noErr,0,_("Could not determine number of items"));
1098 return noOfItems;
1099} /* wxDataViewCtrl::GetCount(void) const */
1100
07c51ff1
RR
1101wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
1102{
1103 if (item.IsOk() && (columnPtr != NULL))
1104 {
1105 // variable definition:
1106 Rect MacRectangle;
1107 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1108
1109 if (MacDataViewListCtrlPtr->GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
1110 {
1111 // variable definition:
1112 wxRect rectangle;
1113
1114 ::wxMacNativeToRect(&MacRectangle,&rectangle);
1115 return rectangle;
1116 } /* if */
1117 else
1118 return wxRect();
1119 } /* if */
1120 else
1121 return wxRect();
1122} /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1123
1124wxDataViewItem wxDataViewCtrl::GetSelection(void) const
c0a66d92 1125{
c0a66d92 1126 wxArrayDataBrowserItemID itemIDs;
c0a66d92 1127
194027ac 1128 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
c0a66d92
RR
1129
1130
194027ac
RR
1131 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
1132 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
1133 else
1134 return wxDataViewItem();
07c51ff1 1135} /* wxDataViewCtrl::GetSelection(void) const */
c0a66d92 1136
07c51ff1 1137int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
c0a66d92 1138{
07c51ff1
RR
1139 size_t NoOfSelectedItems;
1140
1141 wxArrayDataBrowserItemID itemIDs;
c0a66d92 1142
07c51ff1
RR
1143 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1144
1145
1146 NoOfSelectedItems = MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
1147 sel.Empty();
1148 sel.SetCount(NoOfSelectedItems);
1149 for (size_t i=0; i<NoOfSelectedItems; ++i)
1150 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
1151 return static_cast<int>(NoOfSelectedItems);
1152} /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
c0a66d92 1153
07c51ff1
RR
1154void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
1155{
1156 item = wxDataViewItem();
1157 columnPtr = NULL;
1158} /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1159
1160bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
1161{
1162 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1163
1164
1165 return MacDataViewListCtrlPtr->IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1166} /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1167
1168void wxDataViewCtrl::SelectAll(void)
1169{
1170 DataBrowserItemID* itemIDPtr;
1171
1172 Handle handle(::NewHandle(0));
1173
1174 size_t NoOfItems;
1175
1176 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1177
1178
1179 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1180 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1181 HLock(handle);
1182 itemIDPtr = (DataBrowserItemID*) (*handle);
1183 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsAssign);
1184 HUnlock(handle);
1185 DisposeHandle(handle);
1186} /* wxDataViewCtrl::SelectAll(void) */
1187
1188void wxDataViewCtrl::Select(wxDataViewItem const& item)
1189{
1190 if (item.IsOk())
1191 {
1192 // variable definition and initialization:
1193 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1194 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1195
1196 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
1197 } /* if */
1198} /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1199
1200void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
1201{
1202 size_t const NoOfSelections = sel.GetCount();
1203
1204 DataBrowserItemID* itemIDs;
1205
1206 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1207
1208
1209 itemIDs = new DataBrowserItemID[NoOfSelections];
1210 for (size_t i=0; i<NoOfSelections; ++i)
1211 itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
1212 MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
1213 delete[] itemIDs;
1214} /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1215
1216void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
1217{
1218 if (item.IsOk())
1219 {
1220 // variable definition and initialization:
1221 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1222 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1223
1224 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
1225 } /* if */
1226} /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1227
1228void wxDataViewCtrl::UnselectAll(void)
1229{
1230 DataBrowserItemID* itemIDPtr;
1231
1232 Handle handle(::NewHandle(0));
1233
1234 size_t NoOfItems;
1235
1236 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1237
1238
1239 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1240 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1241 HLock(handle);
1242 itemIDPtr = (DataBrowserItemID*) (*handle);
1243 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsRemove);
1244 HUnlock(handle);
1245 DisposeHandle(handle);
1246} /* wxDataViewCtrl::UnselectAll(void) */
c0a66d92 1247
194027ac
RR
1248// data handling:
1249void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
c0a66d92 1250{
b741dd40
RR
1251 int NoOfChildren;
1252
1253 wxDataViewItemArray items;
c0a66d92 1254
c0a66d92 1255
194027ac 1256 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
b741dd40 1257 NoOfChildren = this->GetModel()->GetChildren(parentItem,items);
a5fb9253 1258#if 0
b741dd40
RR
1259 for (int i=0; i<NoOfChildren; ++i)
1260 (void) this->GetModel()->ItemAdded(parentItem,items[i]);
a5fb9253
RR
1261#else
1262 (void) this->GetModel()->ItemsAdded(parentItem,items);
1263#endif
194027ac 1264} /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
c0a66d92 1265
34b1fdeb 1266wxDataViewColumn* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID) const
c17b2e31
RR
1267{
1268 // variable definition:
1269 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1270
1271 if (Result != this->m_ColumnPointers.end())
1272 return Result->second;
1273 else
1274 return NULL;
1275} /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1276
194027ac
RR
1277// inherited methods from wxDataViewCtrlBase
1278void wxDataViewCtrl::DoSetExpanderColumn(void)
c0a66d92 1279{
c17b2e31 1280 if (this->GetExpanderColumn() != NULL)
c0a66d92 1281 {
194027ac 1282 // variable definition and initialization:
194027ac
RR
1283 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1284
c17b2e31 1285 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
c0a66d92 1286 } /* if */
194027ac 1287} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
c0a66d92 1288
194027ac 1289void wxDataViewCtrl::DoSetIndent(void)
c0a66d92 1290{
c17b2e31
RR
1291 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1292
1293
1294 (void) MacDataViewListCtrlPtr->SetIndent(static_cast<float>(this->GetIndent()));
1295} /* wxDataViewCtrl::DoSetIndent(void) */
c0a66d92 1296
194027ac
RR
1297// event handling:
1298void wxDataViewCtrl::OnSize(wxSizeEvent& event)
c0a66d92 1299{
194027ac 1300 unsigned int const NoOfColumns = this->GetColumnCount();
c0a66d92 1301
194027ac
RR
1302
1303 for (unsigned int i=0; i<NoOfColumns; ++i)
c0a66d92
RR
1304 {
1305 // variable definition and initialization:
194027ac
RR
1306 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
1307
1308 if (dataViewColumnPtr != NULL)
c0a66d92 1309 {
194027ac
RR
1310 // variable definition and initialization:
1311 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
1312
1313 if (dataViewCustomRendererPtr != NULL)
1314 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
c0a66d92 1315 } /* if */
194027ac
RR
1316 } /* for */
1317 event.Skip();
1318} /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
c0a66d92
RR
1319
1320IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
1321
1322BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
1323 EVT_SIZE(wxDataViewCtrl::OnSize)
1324END_EVENT_TABLE()
1325
1326#endif
1327 // !wxUSE_GENERICDATAVIEWCTRL
1328
1329#endif
1330 // wxUSE_DATAVIEWCTRL
1331