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