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