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