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