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