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