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