]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataview.cpp
implement editing_started and _done events for GTK+ >= 2.6
[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 //-----------------------------------------------------------------------------
96 // local function pointers
97 //-----------------------------------------------------------------------------
98
99 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler)
100
101 // ---------------------------------------------------------
102 // wxMacDataViewModelNotifier
103 // ---------------------------------------------------------
104 #pragma mark -
105 class wxMacDataViewModelNotifier : public wxDataViewModelNotifier
106 {
107 public:
108 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
109 {
110 }
111
112 virtual bool ItemAdded(const wxDataViewItem &parent, const wxDataViewItem &item)
113 {
114 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
115
116
117 wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
118 return (!(parent.IsOk()) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&itemID) == noErr) ||
119 parent.IsOk() && (this->m_dataViewControlPtr->AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr));
120 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
121
122 virtual bool ItemChanged(wxDataViewItem const& item)
123 {
124 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
125
126
127 wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
128 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
129 if (this->m_dataViewControlPtr->UpdateItems(&itemID) == noErr)
130 {
131 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
132
133 // sent the equivalent wxWidget event:
134 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
135
136 dataViewEvent.SetEventObject(dataViewCtrlPtr);
137 dataViewEvent.SetItem(item);
138 // sent the equivalent wxWidget event:
139 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
140 // done
141 return true;
142 } /* if */
143 else
144 return false;
145 } /* ItemChanged(wxDataViewItem const&) */
146
147 virtual bool ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
148 {
149 if (item.IsOk())
150 {
151 // variable definition and initialization:
152 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
153 OSStatus errorStatus;
154 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
155
156 // 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
157 // not to be identical because the being edited item might be below the passed item in the hierarchy); therefore, the control is informed that currently a deleting process
158 // is started and that variables can currently not be updated even when requested by the system:
159 dataViewCtrlPtr->SetDeleting(true);
160 errorStatus = this->m_dataViewControlPtr->RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID);
161 dataViewCtrlPtr->SetDeleting(false);
162 return (errorStatus == noErr);
163 } /* if */
164 else
165 return false;
166 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
167
168 virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col)
169 {
170 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
171 DataBrowserItemID parentID;
172
173 DataBrowserPropertyID propertyID;
174
175 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
176
177
178 wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
179 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
180 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Control is wrongly initialized."));
181 parentID = reinterpret_cast<DataBrowserItemID>(this->GetOwner()->GetParent(item).GetID());
182 if ((this->m_dataViewControlPtr->GetPropertyID(col,&propertyID) == noErr) &&
183 (this->m_dataViewControlPtr->UpdateItems(parentID,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
184 {
185 // variable definition and initialization:
186 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED,dataViewCtrlPtr->GetId());
187
188 dataViewEvent.SetEventObject(dataViewCtrlPtr);
189 dataViewEvent.SetColumn(col);
190 dataViewEvent.SetItem(item);
191 // send the equivalent wxWidget event:
192 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
193 // done
194 return true;
195 } /* if */
196 else
197 return false;
198 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
199
200 virtual bool Cleared(void)
201 {
202 if (this->m_dataViewControlPtr->RemoveItems() == noErr)
203 {
204 // variable definitions and initializations:
205 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
206 wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED,dataViewCtrlPtr->GetId());
207
208 dataViewEvent.SetEventObject(dataViewCtrlPtr);
209 // send the equivalent wxWidget event:
210 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
211 // done
212 return true;
213 } /* if */
214 else
215 return false;
216 } /* Cleared(void) */
217
218 virtual void Resort(void)
219 {
220 this->m_dataViewControlPtr->Resort();
221 }
222
223 protected:
224 private:
225 //
226 // variables
227 //
228 wxMacDataViewDataBrowserListViewControl* m_dataViewControlPtr;
229 };
230
231 // ---------------------------------------------------------
232 // wxDataViewRenderer
233 // ---------------------------------------------------------
234 #pragma mark -
235 wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
236 :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode)
237 {
238 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
239
240 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode)
241 {
242 wxDataViewColumn* dataViewColumnPtr;
243
244
245 this->m_mode = mode;
246 dataViewColumnPtr = this->GetOwner();
247 if (dataViewColumnPtr != NULL)
248 {
249 // variable definition and initialization:
250 wxDataViewCtrl* dataViewCtrlPtr(dataViewColumnPtr->GetOwner());
251
252 if (dataViewCtrlPtr != NULL)
253 {
254 // variable definition and initialization:
255 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
256
257 if (macDataViewListCtrlPtr != NULL)
258 {
259 // variable definition and initialization:
260 DataBrowserPropertyFlags flags;
261
262 verify_noerr(macDataViewListCtrlPtr->GetPropertyFlags(dataViewColumnPtr->GetPropertyID(),&flags));
263 if (mode == wxDATAVIEW_CELL_EDITABLE)
264 flags |= kDataBrowserPropertyIsEditable;
265 else
266 flags &= ~kDataBrowserPropertyIsEditable;
267 verify_noerr(macDataViewListCtrlPtr->SetPropertyFlags(dataViewColumnPtr->GetPropertyID(),flags));
268 } /* if */
269 } /* if */
270 } /* if */
271 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
272
273 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
274
275 // ---------------------------------------------------------
276 // wxDataViewCustomRenderer
277 // ---------------------------------------------------------
278 #pragma mark -
279 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
280 :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL)
281 {
282 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
283
284 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
285 {
286 if (this->m_DCPtr != NULL)
287 delete this->m_DCPtr;
288 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
289
290 wxDC* wxDataViewCustomRenderer::GetDC(void)
291 {
292 if (this->m_DCPtr == NULL)
293 {
294 if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL))
295 return NULL;
296 this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner());
297 } /* if */
298 return this->m_DCPtr;
299 } /* wxDataViewCustomRenderer::GetDC(void) */
300
301 bool wxDataViewCustomRenderer::Render(void)
302 {
303 return false;
304 } /* wxDataViewCustomRenderer::Render(void) */
305
306 void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
307 {
308 delete this->m_DCPtr;
309 this->m_DCPtr = newDCPtr;
310 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
311
312
313 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
314
315 // ---------------------------------------------------------
316 // wxDataViewTextRenderer
317 // ---------------------------------------------------------
318 #pragma mark -
319 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
320 :wxDataViewRenderer(varianttype,mode,align)
321 {
322 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
323
324 bool wxDataViewTextRenderer::Render(void)
325 {
326 if (this->GetValue().GetType() == this->GetVariantType())
327 {
328 // variable definition:
329 wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
330
331 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
332 } /* if */
333 else
334 return false;
335 } /* wxDataViewTextRenderer::Render(void) */
336
337 IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
338
339 // ---------------------------------------------------------
340 // wxDataViewBitmapRenderer
341 // ---------------------------------------------------------
342 #pragma mark -
343 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
344 :wxDataViewRenderer(varianttype,mode,align)
345 {
346 }
347
348 bool wxDataViewBitmapRenderer::Render(void)
349 {
350 if (this->GetValue().GetType() == this->GetVariantType())
351 {
352 wxBitmap bitmap;
353
354 bitmap << this->GetValue();
355 if (bitmap.Ok())
356 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
357 else
358 return false;
359 } /* if */
360 else
361 return false;
362 } /* wxDataViewBitmapRenderer::Render(void) */
363
364 IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
365
366 // ---------------------------------------------------------
367 // wxDataViewToggleRenderer
368 // ---------------------------------------------------------
369 #pragma mark -
370 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
371 :wxDataViewRenderer(varianttype,mode)
372 {
373 }
374
375 bool wxDataViewToggleRenderer::Render(void)
376 {
377 if (this->GetValue().GetType() == this->GetVariantType())
378 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr);
379 else
380 return false;
381 } /* wxDataViewToggleRenderer::Render(void) */
382
383 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
384
385 // ---------------------------------------------------------
386 // wxDataViewProgressRenderer
387 // ---------------------------------------------------------
388 #pragma mark -
389 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align)
390 :wxDataViewRenderer(varianttype,mode,align)
391 {
392 }
393
394 bool wxDataViewProgressRenderer::Render(void)
395 {
396 if (this->GetValue().GetType() == this->GetVariantType())
397 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) &&
398 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) &&
399 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr));
400 else
401 return false;
402 } /* wxDataViewProgressRenderer::Render(void) */
403
404 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
405
406 // ---------------------------------------------------------
407 // wxDataViewDateRenderer
408 // ---------------------------------------------------------
409 #pragma mark -
410 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
411 :wxDataViewRenderer(varianttype,mode,align)
412 {
413 }
414
415 bool wxDataViewDateRenderer::Render(void)
416 {
417 if (this->GetValue().GetType() == this->GetVariantType())
418 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
419 else
420 return false;
421 } /* wxDataViewDateRenderer::Render(void) */
422
423 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
424
425 // ---------------------------------------------------------
426 // wxDataViewColumn
427 // ---------------------------------------------------------
428 #pragma mark -
429 wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
430 :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
431 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits<int>::max()), m_minWidth(0), m_width(width),
432 m_alignment(align), m_title(title)
433 {
434 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
435
436 wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
437 :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
438 m_flags(flags & (wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits<int>::max()), m_minWidth(0), m_width(width),
439 m_alignment(align)
440 {
441 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
442
443 void wxDataViewColumn::SetAlignment(wxAlignment align)
444 {
445 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
446
447
448 this->m_alignment = align;
449 if (dataViewCtrlPtr != NULL)
450 {
451 // variable definition and initialization:
452 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
453
454 if (macDataViewListCtrlPtr != NULL)
455 {
456 // variable definition and initialization:
457 DataBrowserListViewHeaderDesc headerDescription;
458
459 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
460 switch (align)
461 {
462 case wxALIGN_CENTER:
463 case wxALIGN_CENTER_HORIZONTAL:
464 headerDescription.btnFontStyle.just = teCenter;
465 break;
466 case wxALIGN_LEFT:
467 headerDescription.btnFontStyle.just = teFlushLeft;
468 break;
469 case wxALIGN_RIGHT:
470 headerDescription.btnFontStyle.just = teFlushRight;
471 break;
472 default:
473 headerDescription.btnFontStyle.just = teFlushDefault;
474 } /* switch */
475 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
476 } /* if */
477 } /* if */
478 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
479
480 void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
481 {
482 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
483
484
485 wxDataViewColumnBase::SetBitmap(bitmap);
486 if (dataViewCtrlPtr != NULL)
487 {
488 // variable definition and initialization:
489 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
490
491 if (macDataViewListCtrlPtr != NULL)
492 {
493 // variable definition and initialization:
494 DataBrowserListViewHeaderDesc headerDescription;
495
496 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
497 if (this->GetBitmap().Ok())
498 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
499 else
500 headerDescription.btnContentInfo.u.iconRef = NULL;
501 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
502 } /* if */
503 } /* if */
504 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
505
506 void wxDataViewColumn::SetFlags(int flags)
507 {
508 this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0);
509 this->SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
510 this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0);
511 } /* wxDataViewColumn::SetFlags(int) */
512
513 void wxDataViewColumn::SetMaxWidth(int maxWidth)
514 {
515 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
516
517
518 this->m_maxWidth = maxWidth;
519 if (dataViewCtrlPtr != NULL)
520 {
521 // variable definition and initialization:
522 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
523
524 if (macDataViewListCtrlPtr != NULL)
525 {
526 // variable definition and initialization:
527 DataBrowserListViewHeaderDesc headerDescription;
528
529 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
530 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
531 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
532 } /* if */
533 } /* if */
534 } /* wxDataViewColumn::SetMaxWidth(int) */
535
536 void wxDataViewColumn::SetMinWidth(int minWidth)
537 {
538 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
539
540
541 this->m_minWidth = minWidth;
542 if (dataViewCtrlPtr != NULL)
543 {
544 // variable definition and initialization:
545 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
546
547 if (macDataViewListCtrlPtr != NULL)
548 {
549 // variable definition and initialization:
550 DataBrowserListViewHeaderDesc headerDescription;
551
552 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
553 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
554 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
555 } /* if */
556 } /* if */
557 } /* wxDataViewColumn::SetMaxWidth(int) */
558
559 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable))
560 {
561 } /* wxDataViewColumn::SetResizeable(bool) */
562
563 void wxDataViewColumn::SetSortable(bool sortable)
564 {
565 // variable definition and initialization:
566 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
567
568 if (dataViewCtrlPtr != NULL)
569 {
570 // variable definition and initialization:
571 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
572
573 if (macDataViewListCtrlPtr != NULL)
574 {
575 // variable definition and initialization:
576 DataBrowserPropertyFlags flags;
577
578 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
579 if (sortable)
580 {
581 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
582 flags |= kDataBrowserListViewSortableColumn;
583 } /* if */
584 else
585 {
586 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
587 flags &= ~kDataBrowserPropertyIsEditable;
588 } /* if */
589 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
590 } /* if */
591 } /* if */
592 } /* wxDataViewColumn::SetSortable(bool) */
593
594 void wxDataViewColumn::SetSortOrder(bool ascending)
595 {
596 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
597
598
599 this->m_ascending = ascending;
600 if (dataViewCtrlPtr != NULL)
601 {
602 // variable definition and initialization:
603 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
604
605 if (macDataViewListCtrlPtr != NULL)
606 {
607 // variable definition and initialization:
608 DataBrowserListViewHeaderDesc headerDescription;
609
610 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
611 if (ascending)
612 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
613 else
614 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
615 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
616 } /* if */
617 } /* if */
618 } /* wxDataViewColumn::SetSortOrder(bool) */
619
620 void wxDataViewColumn::SetTitle(wxString const& title)
621 {
622 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
623
624
625 this->m_title = title;
626 if (dataViewCtrlPtr != NULL)
627 {
628 // variable definition and initialization:
629 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
630
631 if (macDataViewListCtrlPtr != NULL)
632 {
633 // variable definition and initialization:
634 DataBrowserListViewHeaderDesc headerDescription;
635 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
636
637 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
638 headerDescription.titleString = cfTitle;
639 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
640 } /* if */
641 } /* if */
642 } /* wxDataViewColumn::SetTitle(wxString const&) */
643
644 void wxDataViewColumn::SetWidth(int width)
645 {
646 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
647
648
649 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
650 {
651 this->m_width = width;
652 if (dataViewCtrlPtr != NULL)
653 {
654 // variable definition and initialization:
655 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
656
657 if (macDataViewListCtrlPtr != NULL)
658 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
659 } /* if */
660 } /* if */
661 } /* wxDataViewColumn::SetWidth(int) */
662
663 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
664
665 //-----------------------------------------------------------------------------
666 // wxDataViewCtrl
667 //-----------------------------------------------------------------------------
668 #pragma mark -
669 void wxDataViewCtrl::Init(void)
670 {
671 this->m_Deleting = false;
672 this->m_macIsUserPane = false;
673 this->m_NotifierPtr = NULL;
674 this->m_cgContext = NULL;
675 } /* wxDataViewCtrl::Init(void) */
676
677 bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
678 {
679 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
680 return false;
681
682 #ifdef __WXMAC__
683 MacSetClipChildren(true) ;
684 #endif
685
686 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
687 this->MacPostControlCreate(pos,size);
688 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer->GetControlRef()),true);
689
690 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
691
692 return true;
693 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
694
695 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
696 {
697 // first, some error checking:
698 wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL."));
699 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
700 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
701 wxCHECK_MSG((dataViewColumnPtr->GetModelColumn() >= 0) &&
702 (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
703 if (this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr))
704 {
705 // variable definitions:
706 DataBrowserPropertyID NewPropertyID;
707 DataBrowserListViewColumnDesc columnDescription;
708 wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding()));
709 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
710
711 // initialize column description:
712 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
713 wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Maximum number of columns reached."));
714 dataViewColumnPtr->SetPropertyID(NewPropertyID);
715 if (dataViewColumnPtr->GetWidth() <= 0)
716 dataViewColumnPtr->SetWidth(wxDVC_DEFAULT_WIDTH);
717 columnDescription.propertyDesc.propertyID = NewPropertyID;
718 columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType();
719 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable
720 if (dataViewColumnPtr->IsSortable())
721 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
722 #if 0
723 if (dataViewColumnPtr->IsMovable())
724 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
725 #endif
726 if (dataViewColumnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE)
727 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
728 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
729 if ((columnDescription.propertyDesc.propertyType == kDataBrowserTextType) ||
730 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
731 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType))
732 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
733 #endif
734 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
735 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
736 #endif
737 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
738 if (dataViewColumnPtr->IsResizable())
739 {
740 columnDescription.headerBtnDesc.minimumWidth = 0;
741 columnDescription.headerBtnDesc.maximumWidth = 30000;
742 } /* if */
743 else
744 {
745 columnDescription.headerBtnDesc.minimumWidth = dataViewColumnPtr->GetWidth();
746 columnDescription.headerBtnDesc.maximumWidth = dataViewColumnPtr->GetWidth();
747 } /* if */
748 columnDescription.headerBtnDesc.titleOffset = 0;
749 columnDescription.headerBtnDesc.titleString = cfTitle; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
750 // having called 'AddColumn' where the title (CFStringRef) is going to be used
751 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
752 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
753 switch (dataViewColumnPtr->GetAlignment())
754 {
755 case wxALIGN_CENTER:
756 case wxALIGN_CENTER_HORIZONTAL:
757 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
758 break;
759 case wxALIGN_LEFT:
760 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
761 break;
762 case wxALIGN_RIGHT:
763 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
764 break;
765 default:
766 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
767 } /* switch */
768 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
769 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
770 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
771 if (dataViewColumnPtr->GetBitmap().Ok())
772 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef();
773 // add column:
774 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
775
776 // final adjustments for the layout:
777 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
778 #if 0
779 if (dataViewColumnPtr->IsSortable()) // if the current column is marked sortable this column will become the active sortable column, otherwise don't do anything
780 MacDataViewListCtrlPtr->SetSortProperty(NewPropertyID);
781 #endif
782 if (dataViewColumnPtr == this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column
783 MacDataViewListCtrlPtr->SetDisclosureColumn(NewPropertyID,true);
784
785 // make sure that the data is up-to-date...
786 // if the newly appended column is the first column add the initial data to the control otherwise ask the control to 'update' the data in the newly appended column:
787 if (this->GetColumnCount() == 1)
788 this->AddChildrenLevel(wxDataViewItem());
789 else
790 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
791 // done:
792 return true;
793 } /* if */
794 else
795 return false;
796 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
797
798 bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
799 {
800 if (!wxDataViewCtrlBase::AssociateModel(model))
801 return false;
802
803 this->m_NotifierPtr = new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer));
804 model->AddNotifier(this->m_NotifierPtr);
805
806 return true;
807 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
808
809 void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
810 {
811 if (item.IsOk())
812 {
813 // variable definition and initialization:
814 DataBrowserPropertyID propertyID;
815 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
816
817 if (columnPtr != NULL)
818 propertyID = columnPtr->GetPropertyID();
819 else
820 propertyID = kDataBrowserNoItem;
821 MacDataViewListCtrlPtr->RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
822 } /* if */
823 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
824
825 wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
826 {
827 if (item.IsOk() && (columnPtr != NULL))
828 {
829 // variable definition:
830 Rect MacRectangle;
831 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
832
833 if (MacDataViewListCtrlPtr->GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
834 {
835 // variable definition:
836 wxRect rectangle;
837
838 ::wxMacNativeToRect(&MacRectangle,&rectangle);
839 return rectangle;
840 } /* if */
841 else
842 return wxRect();
843 } /* if */
844 else
845 return wxRect();
846 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
847
848 wxDataViewItem wxDataViewCtrl::GetSelection(void) const
849 {
850 wxArrayDataBrowserItemID itemIDs;
851
852 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
853
854
855 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
856 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
857 else
858 return wxDataViewItem();
859 } /* wxDataViewCtrl::GetSelection(void) const */
860
861 int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
862 {
863 size_t NoOfSelectedItems;
864
865 wxArrayDataBrowserItemID itemIDs;
866
867 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
868
869
870 NoOfSelectedItems = MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
871 sel.Empty();
872 sel.SetCount(NoOfSelectedItems);
873 for (size_t i=0; i<NoOfSelectedItems; ++i)
874 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
875 return static_cast<int>(NoOfSelectedItems);
876 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
877
878 void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
879 {
880 item = wxDataViewItem();
881 columnPtr = NULL;
882 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
883
884 bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
885 {
886 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
887
888
889 return MacDataViewListCtrlPtr->IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
890 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
891
892 void wxDataViewCtrl::SelectAll(void)
893 {
894 DataBrowserItemID* itemIDPtr;
895
896 Handle handle(::NewHandle(0));
897
898 size_t NoOfItems;
899
900 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
901
902
903 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
904 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
905 HLock(handle);
906 itemIDPtr = (DataBrowserItemID*) (*handle);
907 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsAssign);
908 HUnlock(handle);
909 DisposeHandle(handle);
910 } /* wxDataViewCtrl::SelectAll(void) */
911
912 void wxDataViewCtrl::Select(wxDataViewItem const& item)
913 {
914 if (item.IsOk())
915 {
916 // variable definition and initialization:
917 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
918 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
919
920 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
921 } /* if */
922 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
923
924 void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
925 {
926 size_t const NoOfSelections = sel.GetCount();
927
928 DataBrowserItemID* itemIDs;
929
930 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
931
932
933 itemIDs = new DataBrowserItemID[NoOfSelections];
934 for (size_t i=0; i<NoOfSelections; ++i)
935 itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
936 MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
937 delete[] itemIDs;
938 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
939
940 void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
941 {
942 if (item.IsOk())
943 {
944 // variable definition and initialization:
945 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
946 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
947
948 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
949 } /* if */
950 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
951
952 void wxDataViewCtrl::UnselectAll(void)
953 {
954 DataBrowserItemID* itemIDPtr;
955
956 Handle handle(::NewHandle(0));
957
958 size_t NoOfItems;
959
960 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
961
962
963 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
964 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
965 HLock(handle);
966 itemIDPtr = (DataBrowserItemID*) (*handle);
967 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsRemove);
968 HUnlock(handle);
969 DisposeHandle(handle);
970 } /* wxDataViewCtrl::UnselectAll(void) */
971
972 // data handling:
973 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
974 {
975 wxDataViewItem item;
976
977
978 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
979 item = this->GetModel()->GetFirstChild(parentItem);
980 while (item.IsOk())
981 {
982 (void) this->GetModel()->ItemAdded(parentItem,item);
983 item = this->GetModel()->GetNextSibling(item);
984 } /* while */
985 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
986
987 // inherited methods from wxDataViewCtrlBase
988 void wxDataViewCtrl::DoSetExpanderColumn(void)
989 {
990 if (this->GetExpanderColumn() < this->GetColumnCount())
991 {
992 // variable definition and initialization:
993 DataBrowserPropertyID propertyID;
994 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
995
996 if (MacDataViewListCtrlPtr->GetPropertyID(this->GetExpanderColumn(),&propertyID) == noErr)
997 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(propertyID);
998 } /* if */
999 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1000
1001 void wxDataViewCtrl::DoSetIndent(void)
1002 {
1003 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1004
1005 // event handling:
1006 void wxDataViewCtrl::OnSize(wxSizeEvent& event)
1007 {
1008 unsigned int const NoOfColumns = this->GetColumnCount();
1009
1010
1011 for (unsigned int i=0; i<NoOfColumns; ++i)
1012 {
1013 // variable definition and initialization:
1014 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
1015
1016 if (dataViewColumnPtr != NULL)
1017 {
1018 // variable definition and initialization:
1019 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
1020
1021 if (dataViewCustomRendererPtr != NULL)
1022 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
1023 } /* if */
1024 } /* for */
1025 event.Skip();
1026 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1027
1028 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
1029
1030 BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
1031 EVT_SIZE(wxDataViewCtrl::OnSize)
1032 END_EVENT_TABLE()
1033
1034 #endif
1035 // !wxUSE_GENERICDATAVIEWCTRL
1036
1037 #endif
1038 // wxUSE_DATAVIEWCTRL
1039