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