]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/carbon/datavgen.cpp | |
3 | // Purpose: wxDataViewCtrl native mac implementation | |
4 | // Author: | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 2007 | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #if wxUSE_DATAVIEWCTRL | |
14 | ||
15 | #include "wx/dataview.h" | |
16 | ||
17 | #if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0) | |
18 | ||
19 | #include <limits> | |
20 | ||
21 | #include "wx/mac/carbon/databrow.h" | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/timer.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/icon.h" | |
28 | #include "wx/renderer.h" | |
29 | ||
30 | //----------------------------------------------------------------------------- | |
31 | // local constants | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | // a list of all catchable events: | |
35 | static EventTypeSpec const eventList[] = | |
36 | { | |
37 | {kEventClassControl, kEventControlDraw}, | |
38 | {kEventClassControl, kEventControlHit} | |
39 | }; | |
40 | ||
41 | //----------------------------------------------------------------------------- | |
42 | // local functions | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler, EventRef EventReference, void* Data) | |
46 | { | |
47 | wxDataViewCtrl* DataViewCtrlPtr((wxDataViewCtrl*) Data); // the 'Data' variable always contains a pointer to the data view control that installed the handler | |
48 | ||
49 | wxMacCarbonEvent CarbonEvent(EventReference) ; | |
50 | ||
51 | ||
52 | switch (GetEventKind(EventReference)) | |
53 | { | |
54 | case kEventControlDraw: | |
55 | { | |
56 | OSStatus status; | |
57 | ||
58 | DataViewCtrlPtr->MacSetDrawingContext(CarbonEvent.GetParameter<CGContextRef>(kEventParamCGContextRef,typeCGContextRef)); | |
59 | status = ::CallNextEventHandler(handler,EventReference); | |
60 | DataViewCtrlPtr->MacSetDrawingContext(NULL); | |
61 | return status; | |
62 | } /* block */ | |
63 | case kEventControlHit : | |
64 | if (CarbonEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) == kControlButtonPart) // we only care about the header | |
65 | { | |
66 | ControlRef controlReference; | |
67 | DataBrowserPropertyID columnPropertyID; | |
68 | unsigned long columnIndex; | |
69 | OSStatus status; | |
70 | wxDataViewEvent DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,DataViewCtrlPtr->GetId()); | |
71 | ||
72 | CarbonEvent.GetParameter(kEventParamDirectObject,&controlReference); | |
73 | // determine the column that triggered the event (this is the column that is responsible for sorting the data view): | |
74 | status = ::GetDataBrowserSortProperty(controlReference,&columnPropertyID); | |
75 | wxCHECK(status == noErr,status); | |
76 | status = ::GetDataBrowserTableViewColumnPosition(controlReference,columnPropertyID,&columnIndex); | |
77 | if (status == errDataBrowserPropertyNotFound) // user clicked into part of the header that does not have a property | |
78 | return ::CallNextEventHandler(handler,EventReference); | |
79 | wxCHECK(status == noErr,status); | |
80 | // initialize wxWidget event handler: | |
81 | DataViewEvent.SetEventObject(DataViewCtrlPtr); | |
82 | DataViewEvent.SetColumn(columnIndex); | |
83 | DataViewEvent.SetDataViewColumn(DataViewCtrlPtr->GetColumn(columnIndex)); | |
84 | // finally sent the equivalent wxWidget event: | |
85 | DataViewCtrlPtr->GetEventHandler()->ProcessEvent(DataViewEvent); | |
86 | return ::CallNextEventHandler(handler,EventReference); | |
87 | } /* if */ | |
88 | else | |
89 | return eventNotHandledErr; | |
90 | } /* switch */ | |
91 | ||
92 | return eventNotHandledErr; | |
93 | } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */ | |
94 | ||
95 | //----------------------------------------------------------------------------- | |
96 | // local function pointers | |
97 | //----------------------------------------------------------------------------- | |
98 | ||
99 | DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler) | |
100 | ||
101 | // --------------------------------------------------------- | |
102 | // wxMacDataViewListModelNotifier | |
103 | // --------------------------------------------------------- | |
104 | #pragma mark - | |
105 | class wxMacDataViewListModelNotifier : public wxDataViewListModelNotifier | |
106 | { | |
107 | public: | |
108 | wxMacDataViewListModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr) | |
109 | { | |
110 | } | |
111 | ||
112 | virtual bool RowAppended(void) | |
113 | { | |
114 | DataBrowserItemID newRowID; | |
115 | ||
116 | ||
117 | if ((this->m_dataViewControlPtr->GetFreeItemID(&newRowID) == noErr) && | |
118 | this->m_dataViewControlPtr->InsertItemIDRowPair(newRowID,this->GetOwner()->GetRowCount()-1) && | |
119 | (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&newRowID) == noErr)) | |
120 | { | |
121 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
122 | ||
123 | // sent the equivalent wxWidget event: | |
124 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED,dataViewCtrlPtr->GetId()); // variable defintion | |
125 | ||
126 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
127 | dataViewEvent.SetRow(this->GetOwner()->GetRowCount()-1); | |
128 | // sent the equivalent wxWidget event: | |
129 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
130 | // done | |
131 | return true; | |
132 | } /* if */ | |
133 | else | |
134 | return false; | |
135 | } | |
136 | virtual bool RowChanged(unsigned int row) | |
137 | { | |
138 | DataBrowserItemID itemID; | |
139 | ||
140 | ||
141 | if (this->m_dataViewControlPtr->GetItemID(row,&itemID) == noErr) | |
142 | { | |
143 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
144 | ||
145 | // sent the equivalent wxWidget event: | |
146 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion | |
147 | ||
148 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
149 | dataViewEvent.SetRow(row); | |
150 | // sent the equivalent wxWidget event: | |
151 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
152 | // done | |
153 | return true; | |
154 | } /* if */ | |
155 | else | |
156 | return false; | |
157 | } | |
158 | virtual bool RowDeleted(unsigned int row) | |
159 | { | |
160 | DataBrowserItemID itemID; | |
161 | ||
162 | ||
163 | if (this->m_dataViewControlPtr->GetItemID(row,&itemID) == noErr) | |
164 | { | |
165 | // variable definition: | |
166 | unsigned long rowIndex; | |
167 | ||
168 | wxCHECK_MSG(this->m_dataViewControlPtr->GetRowIndex(rowIndex,itemID) && this->m_dataViewControlPtr->DeleteItemIDRowPair(itemID),false,_("Unable to delete row data.")); | |
169 | this->m_dataViewControlPtr->RenumberItemIDRowIndicesDeletion(rowIndex); | |
170 | if (this->m_dataViewControlPtr->RemoveItem(kDataBrowserNoItem,&itemID) == noErr) | |
171 | { | |
172 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
173 | ||
174 | // sent the equivalent wxWidget event: | |
175 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED,dataViewCtrlPtr->GetId()); // variable defintion | |
176 | ||
177 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
178 | dataViewEvent.SetRow(row); | |
179 | // sent the equivalent wxWidget event: | |
180 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
181 | // done | |
182 | return true; | |
183 | } /* if */ | |
184 | else | |
185 | return false; | |
186 | } /* if */ | |
187 | else | |
188 | return false; | |
189 | } | |
190 | virtual bool RowInserted(unsigned int before) | |
191 | { | |
192 | DataBrowserItemID newRowID; | |
193 | ||
194 | ||
195 | if (this->m_dataViewControlPtr->GetFreeItemID(&newRowID) == noErr) | |
196 | { | |
197 | this->m_dataViewControlPtr->RenumberItemIDRowIndicesInsertion(before); | |
198 | if (this->m_dataViewControlPtr->InsertItemIDRowPair(newRowID,before) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&newRowID) == noErr)) | |
199 | { | |
200 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
201 | ||
202 | // sent the equivalent wxWidget event: | |
203 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED,dataViewCtrlPtr->GetId()); // variable defintion | |
204 | ||
205 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
206 | dataViewEvent.SetRow(before); | |
207 | // sent the equivalent wxWidget event: | |
208 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
209 | // done | |
210 | return true; | |
211 | } /* if */ | |
212 | else | |
213 | return false; | |
214 | } /* if */ | |
215 | else | |
216 | return false; | |
217 | } | |
218 | virtual bool RowPrepended(void) | |
219 | { | |
220 | DataBrowserItemID newRowID; | |
221 | ||
222 | ||
223 | if (this->m_dataViewControlPtr->GetFreeItemID(&newRowID) == noErr) | |
224 | { | |
225 | this->m_dataViewControlPtr->RenumberItemIDRowIndicesInsertion(0); | |
226 | if (this->m_dataViewControlPtr->InsertItemIDRowPair(newRowID,0) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&newRowID) == noErr)) | |
227 | { | |
228 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
229 | ||
230 | // sent the equivalent wxWidget event: | |
231 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED,dataViewCtrlPtr->GetId()); // variable defintion | |
232 | ||
233 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
234 | dataViewEvent.SetRow(0); | |
235 | // sent the equivalent wxWidget event: | |
236 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
237 | // done | |
238 | return true; | |
239 | } /* if */ | |
240 | else | |
241 | return false; | |
242 | } /* if */ | |
243 | else | |
244 | return false; | |
245 | } | |
246 | virtual bool ValueChanged(unsigned int col, unsigned int row) | |
247 | { | |
248 | DataBrowserItemID itemID; | |
249 | ||
250 | DataBrowserPropertyID propertyID; | |
251 | ||
252 | ||
253 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
254 | ||
255 | if ((dataViewCtrlPtr != NULL) && (this->m_dataViewControlPtr->GetItemID(row,&itemID) == noErr) && (this->m_dataViewControlPtr->GetColumnID(col,&propertyID) == noErr) && | |
256 | (this->m_dataViewControlPtr->UpdateItems(kDataBrowserNoItem,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr)) | |
257 | { | |
258 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
259 | ||
260 | // sent the equivalent wxWidget event: | |
261 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion | |
262 | ||
263 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
264 | dataViewEvent.SetColumn(col); | |
265 | dataViewEvent.SetRow(row); | |
266 | // sent the equivalent wxWidget event: | |
267 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
268 | // done | |
269 | return true; | |
270 | } /* if */ | |
271 | else | |
272 | return false; | |
273 | } | |
274 | virtual bool RowsReordered(unsigned int* new_order) | |
275 | { | |
276 | DataBrowserPropertyID propertyId; | |
277 | ||
278 | ||
279 | if ((new_order != NULL) && (this->m_dataViewControlPtr->GetSortProperty(&propertyId) == noErr) && (propertyId >= kMinPropertyID)) | |
280 | { | |
281 | DataBrowserSortOrder sortOrder; | |
282 | unsigned long column; | |
283 | ||
284 | if ((this->m_dataViewControlPtr->GetSortOrder(&sortOrder) == noErr) && (this->m_dataViewControlPtr->GetPropertyColumn(propertyId,&column) == noErr)) | |
285 | { | |
286 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
287 | ||
288 | if (dataViewCtrlPtr->GetColumn(column)->IsSortOrderAscending()) | |
289 | this->m_dataViewControlPtr->RenumberItemIDRowIndices(new_order); | |
290 | else // the sort order of the control is descending but the passed sort order is always ordered top - down | |
291 | { | |
292 | ItemCount itemCount; | |
293 | ||
294 | if (this->m_dataViewControlPtr->GetItemCount(&itemCount) != noErr) | |
295 | return false; | |
296 | unsigned int* reversedOrder(new unsigned int[itemCount]); | |
297 | ||
298 | for (ItemCount i=0; i<itemCount; ++i) | |
299 | reversedOrder[i] = itemCount-new_order[i]; | |
300 | this->m_dataViewControlPtr->RenumberItemIDRowIndices(reversedOrder); | |
301 | delete[] reversedOrder; | |
302 | } /* if */ | |
303 | if (this->m_dataViewControlPtr->UpdateItems()) | |
304 | { | |
305 | // sent the equivalent wxWidget event: | |
306 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED,dataViewCtrlPtr->GetId()); // variable defintion | |
307 | ||
308 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
309 | // sent the equivalent wxWidget event: | |
310 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
311 | // done | |
312 | return true; | |
313 | } /* if */ | |
314 | else | |
315 | return false; | |
316 | } /* if */ | |
317 | else | |
318 | return false; | |
319 | } /* if */ | |
320 | else | |
321 | return false; | |
322 | } | |
323 | virtual bool Cleared(void) | |
324 | { | |
325 | this->m_dataViewControlPtr->ClearItemIDRowPairs(); | |
326 | if (this->m_dataViewControlPtr->RemoveItems() == noErr) | |
327 | { | |
328 | wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer())); | |
329 | ||
330 | // sent the equivalent wxWidget event: | |
331 | wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED,dataViewCtrlPtr->GetId()); // variable defintion | |
332 | ||
333 | dataViewEvent.SetEventObject(dataViewCtrlPtr); | |
334 | // sent the equivalent wxWidget event: | |
335 | dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); | |
336 | // done | |
337 | return true; | |
338 | } /* if */ | |
339 | else | |
340 | return false; | |
341 | } | |
342 | ||
343 | protected: | |
344 | private: | |
345 | // | |
346 | // variables | |
347 | // | |
348 | wxMacDataViewDataBrowserListViewControl* m_dataViewControlPtr; | |
349 | }; | |
350 | ||
351 | // --------------------------------------------------------- | |
352 | // wxDataViewRenderer | |
353 | // --------------------------------------------------------- | |
354 | #pragma mark - | |
355 | wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) | |
356 | :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode) | |
357 | { | |
358 | } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */ | |
359 | ||
360 | void wxDataViewRenderer::SetMode(wxDataViewCellMode mode) | |
361 | { | |
362 | wxDataViewColumn* dataViewColumnPtr; | |
363 | ||
364 | ||
365 | this->m_mode = mode; | |
366 | dataViewColumnPtr = this->GetOwner(); | |
367 | if (dataViewColumnPtr != NULL) | |
368 | { | |
369 | // variable definition and initialization: | |
370 | wxDataViewCtrl* dataViewCtrlPtr(dataViewColumnPtr->GetOwner()); | |
371 | ||
372 | if (dataViewCtrlPtr != NULL) | |
373 | { | |
374 | // variable definition and initialization: | |
375 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
376 | ||
377 | if (macDataViewListCtrlPtr != NULL) | |
378 | { | |
379 | // variable definition and initialization: | |
380 | DataBrowserPropertyFlags flags; | |
381 | ||
382 | verify_noerr(macDataViewListCtrlPtr->GetPropertyFlags(dataViewColumnPtr->GetPropertyID(),&flags)); | |
383 | if (mode == wxDATAVIEW_CELL_EDITABLE) | |
384 | flags |= kDataBrowserPropertyIsEditable; | |
385 | else | |
386 | flags &= ~kDataBrowserPropertyIsEditable; | |
387 | verify_noerr(macDataViewListCtrlPtr->SetPropertyFlags(dataViewColumnPtr->GetPropertyID(),flags)); | |
388 | } /* if */ | |
389 | } /* if */ | |
390 | } /* if */ | |
391 | } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */ | |
392 | ||
393 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase) | |
394 | ||
395 | // --------------------------------------------------------- | |
396 | // wxDataViewCustomRenderer | |
397 | // --------------------------------------------------------- | |
398 | #pragma mark - | |
399 | wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) | |
400 | :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL) | |
401 | { | |
402 | } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */ | |
403 | ||
404 | wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) | |
405 | { | |
406 | if (this->m_DCPtr != NULL) | |
407 | delete this->m_DCPtr; | |
408 | } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */ | |
409 | ||
410 | wxDC* wxDataViewCustomRenderer::GetDC(void) | |
411 | { | |
412 | if (this->m_DCPtr == NULL) | |
413 | { | |
414 | if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL)) | |
415 | return NULL; | |
416 | this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner()); | |
417 | } /* if */ | |
418 | return this->m_DCPtr; | |
419 | } /* wxDataViewCustomRenderer::GetDC(void) */ | |
420 | ||
421 | bool wxDataViewCustomRenderer::Render(void) | |
422 | { | |
423 | return false; | |
424 | } /* wxDataViewCustomRenderer::Render(void) */ | |
425 | ||
426 | void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr) | |
427 | { | |
428 | delete this->m_DCPtr; | |
429 | this->m_DCPtr = newDCPtr; | |
430 | } /* wxDataViewCustomRenderer::SetDC(wxDC*) */ | |
431 | ||
432 | ||
433 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) | |
434 | ||
435 | // --------------------------------------------------------- | |
436 | // wxDataViewTextRenderer | |
437 | // --------------------------------------------------------- | |
438 | #pragma mark - | |
439 | wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) | |
440 | :wxDataViewRenderer(varianttype,mode,align) | |
441 | { | |
442 | } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */ | |
443 | ||
444 | bool wxDataViewTextRenderer::Render(void) | |
445 | { | |
446 | if (this->GetValue().GetType() == this->GetVariantType()) | |
447 | { | |
448 | // variable definition: | |
449 | wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding())); | |
450 | ||
451 | return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr); | |
452 | } /* if */ | |
453 | else | |
454 | return false; | |
455 | } /* wxDataViewTextRenderer::Render(void) */ | |
456 | ||
457 | IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer) | |
458 | ||
459 | // --------------------------------------------------------- | |
460 | // wxDataViewBitmapRenderer | |
461 | // --------------------------------------------------------- | |
462 | #pragma mark - | |
463 | wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) | |
464 | :wxDataViewRenderer(varianttype,mode,align) | |
465 | { | |
466 | } | |
467 | ||
468 | bool wxDataViewBitmapRenderer::Render(void) | |
469 | { | |
470 | if (this->GetValue().GetType() == this->GetVariantType()) | |
471 | { | |
472 | wxBitmap bitmap; | |
473 | ||
474 | bitmap << this->GetValue(); | |
475 | if (bitmap.Ok()) | |
476 | return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr); | |
477 | else | |
478 | return false; | |
479 | } /* if */ | |
480 | else | |
481 | return false; | |
482 | } /* wxDataViewBitmapRenderer::Render(void) */ | |
483 | ||
484 | IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer) | |
485 | ||
486 | // --------------------------------------------------------- | |
487 | // wxDataViewToggleRenderer | |
488 | // --------------------------------------------------------- | |
489 | #pragma mark - | |
490 | wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) | |
491 | :wxDataViewRenderer(varianttype,mode) | |
492 | { | |
493 | } | |
494 | ||
495 | bool wxDataViewToggleRenderer::Render(void) | |
496 | { | |
497 | if (this->GetValue().GetType() == this->GetVariantType()) | |
498 | return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr); | |
499 | else | |
500 | return false; | |
501 | } /* wxDataViewToggleRenderer::Render(void) */ | |
502 | ||
503 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer) | |
504 | ||
505 | // --------------------------------------------------------- | |
506 | // wxDataViewProgressRenderer | |
507 | // --------------------------------------------------------- | |
508 | #pragma mark - | |
509 | wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align) | |
510 | :wxDataViewRenderer(varianttype,mode,align) | |
511 | { | |
512 | } | |
513 | ||
514 | bool wxDataViewProgressRenderer::Render(void) | |
515 | { | |
516 | if (this->GetValue().GetType() == this->GetVariantType()) | |
517 | return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) && | |
518 | (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) && | |
519 | (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr)); | |
520 | else | |
521 | return false; | |
522 | } /* wxDataViewProgressRenderer::Render(void) */ | |
523 | ||
524 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer) | |
525 | ||
526 | // --------------------------------------------------------- | |
527 | // wxDataViewDateRenderer | |
528 | // --------------------------------------------------------- | |
529 | #pragma mark - | |
530 | wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) | |
531 | :wxDataViewRenderer(varianttype,mode,align) | |
532 | { | |
533 | } | |
534 | ||
535 | bool wxDataViewDateRenderer::Render(void) | |
536 | { | |
537 | if (this->GetValue().GetType() == this->GetVariantType()) | |
538 | return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr); | |
539 | else | |
540 | return false; | |
541 | } /* wxDataViewDateRenderer::Render(void) */ | |
542 | ||
543 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer) | |
544 | ||
545 | // --------------------------------------------------------- | |
546 | // wxDataViewColumn | |
547 | // --------------------------------------------------------- | |
548 | #pragma mark - | |
549 | wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags) | |
550 | :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_alignment(align), m_ascending(true), | |
551 | m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_minWidth(0), m_maxWidth(std::numeric_limits<int>::max()), m_width(width), m_title(title) | |
552 | { | |
553 | } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */ | |
554 | ||
555 | wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags) | |
556 | :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true), m_alignment(align), | |
557 | m_flags(flags & (wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_minWidth(0), m_maxWidth(std::numeric_limits<int>::max()), m_width(width) | |
558 | { | |
559 | } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */ | |
560 | ||
561 | void wxDataViewColumn::SetAlignment(wxAlignment align) | |
562 | { | |
563 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
564 | ||
565 | ||
566 | this->m_alignment = align; | |
567 | if (dataViewCtrlPtr != NULL) | |
568 | { | |
569 | // variable definition and initialization: | |
570 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
571 | ||
572 | if (macDataViewListCtrlPtr != NULL) | |
573 | { | |
574 | // variable definition and initialization: | |
575 | DataBrowserListViewHeaderDesc headerDescription; | |
576 | ||
577 | wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description.")); | |
578 | switch (align) | |
579 | { | |
580 | case wxALIGN_CENTER: | |
581 | case wxALIGN_CENTER_HORIZONTAL: | |
582 | headerDescription.btnFontStyle.just = teCenter; | |
583 | break; | |
584 | case wxALIGN_LEFT: | |
585 | headerDescription.btnFontStyle.just = teFlushLeft; | |
586 | break; | |
587 | case wxALIGN_RIGHT: | |
588 | headerDescription.btnFontStyle.just = teFlushRight; | |
589 | break; | |
590 | default: | |
591 | headerDescription.btnFontStyle.just = teFlushDefault; | |
592 | } /* switch */ | |
593 | wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment.")); | |
594 | } /* if */ | |
595 | } /* if */ | |
596 | } /* wxDataViewColumn::SetAlignment(wxAlignment) */ | |
597 | ||
598 | void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap) | |
599 | { | |
600 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
601 | ||
602 | ||
603 | wxDataViewColumnBase::SetBitmap(bitmap); | |
604 | if (dataViewCtrlPtr != NULL) | |
605 | { | |
606 | // variable definition and initialization: | |
607 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
608 | ||
609 | if (macDataViewListCtrlPtr != NULL) | |
610 | { | |
611 | // variable definition and initialization: | |
612 | DataBrowserListViewHeaderDesc headerDescription; | |
613 | ||
614 | wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description.")); | |
615 | if (this->GetBitmap().Ok()) | |
616 | headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef(); | |
617 | else | |
618 | headerDescription.btnContentInfo.u.iconRef = NULL; | |
619 | wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon.")); | |
620 | } /* if */ | |
621 | } /* if */ | |
622 | } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */ | |
623 | ||
624 | void wxDataViewColumn::SetFlags(int flags) | |
625 | { | |
626 | this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0); | |
627 | this->SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); | |
628 | this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0); | |
629 | } /* wxDataViewColumn::SetFlags(int) */ | |
630 | ||
631 | void wxDataViewColumn::SetMaxWidth(int maxWidth) | |
632 | { | |
633 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
634 | ||
635 | ||
636 | this->m_maxWidth = maxWidth; | |
637 | if (dataViewCtrlPtr != NULL) | |
638 | { | |
639 | // variable definition and initialization: | |
640 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
641 | ||
642 | if (macDataViewListCtrlPtr != NULL) | |
643 | { | |
644 | // variable definition and initialization: | |
645 | DataBrowserListViewHeaderDesc headerDescription; | |
646 | ||
647 | wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description.")); | |
648 | headerDescription.maximumWidth = static_cast<UInt16>(maxWidth); | |
649 | wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width.")); | |
650 | } /* if */ | |
651 | } /* if */ | |
652 | } /* wxDataViewColumn::SetMaxWidth(int) */ | |
653 | ||
654 | void wxDataViewColumn::SetMinWidth(int minWidth) | |
655 | { | |
656 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
657 | ||
658 | ||
659 | this->m_minWidth = minWidth; | |
660 | if (dataViewCtrlPtr != NULL) | |
661 | { | |
662 | // variable definition and initialization: | |
663 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
664 | ||
665 | if (macDataViewListCtrlPtr != NULL) | |
666 | { | |
667 | // variable definition and initialization: | |
668 | DataBrowserListViewHeaderDesc headerDescription; | |
669 | ||
670 | wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description.")); | |
671 | headerDescription.minimumWidth = static_cast<UInt16>(minWidth); | |
672 | wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width.")); | |
673 | } /* if */ | |
674 | } /* if */ | |
675 | } /* wxDataViewColumn::SetMaxWidth(int) */ | |
676 | ||
677 | void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable)) | |
678 | { | |
679 | } /* wxDataViewColumn::SetResizeable(bool) */ | |
680 | ||
681 | void wxDataViewColumn::SetSortable(bool sortable) | |
682 | { | |
683 | // variable definition and initialization: | |
684 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
685 | ||
686 | if (dataViewCtrlPtr != NULL) | |
687 | { | |
688 | // variable definition and initialization: | |
689 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
690 | ||
691 | if (macDataViewListCtrlPtr != NULL) | |
692 | { | |
693 | // variable definition and initialization: | |
694 | DataBrowserPropertyFlags flags; | |
695 | ||
696 | wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags.")); | |
697 | if (sortable) | |
698 | { | |
699 | this->m_flags |= wxDATAVIEW_COL_SORTABLE; | |
700 | flags |= kDataBrowserListViewSortableColumn; | |
701 | } /* if */ | |
702 | else | |
703 | { | |
704 | this->m_flags &= ~wxDATAVIEW_COL_SORTABLE; | |
705 | flags &= ~kDataBrowserPropertyIsEditable; | |
706 | } /* if */ | |
707 | wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags.")); | |
708 | } /* if */ | |
709 | } /* if */ | |
710 | } /* wxDataViewColumn::SetSortable(bool) */ | |
711 | ||
712 | void wxDataViewColumn::SetSortOrder(bool ascending) | |
713 | { | |
714 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
715 | ||
716 | ||
717 | this->m_ascending = ascending; | |
718 | if (dataViewCtrlPtr != NULL) | |
719 | { | |
720 | // variable definition and initialization: | |
721 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
722 | ||
723 | if (macDataViewListCtrlPtr != NULL) | |
724 | { | |
725 | // variable definition and initialization: | |
726 | DataBrowserListViewHeaderDesc headerDescription; | |
727 | ||
728 | verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription)); | |
729 | if (ascending) | |
730 | headerDescription.initialOrder = kDataBrowserOrderIncreasing; | |
731 | else | |
732 | headerDescription.initialOrder = kDataBrowserOrderDecreasing; | |
733 | verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription)); | |
734 | } /* if */ | |
735 | } /* if */ | |
736 | } /* wxDataViewColumn::SetSortOrder(bool) */ | |
737 | ||
738 | void wxDataViewColumn::SetTitle(wxString const& title) | |
739 | { | |
740 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
741 | ||
742 | ||
743 | this->m_title = title; | |
744 | if (dataViewCtrlPtr != NULL) | |
745 | { | |
746 | // variable definition and initialization: | |
747 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
748 | ||
749 | if (macDataViewListCtrlPtr != NULL) | |
750 | { | |
751 | // variable definition and initialization: | |
752 | DataBrowserListViewHeaderDesc headerDescription; | |
753 | wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding())); | |
754 | ||
755 | wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description.")); | |
756 | headerDescription.titleString = cfTitle; | |
757 | wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description.")); | |
758 | } /* if */ | |
759 | } /* if */ | |
760 | } /* wxDataViewColumn::SetTitle(wxString const&) */ | |
761 | ||
762 | void wxDataViewColumn::SetWidth(int width) | |
763 | { | |
764 | wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); | |
765 | ||
766 | ||
767 | if ((width >= this->m_minWidth) && (width <= this->m_maxWidth)) | |
768 | { | |
769 | this->m_width = width; | |
770 | if (dataViewCtrlPtr != NULL) | |
771 | { | |
772 | // variable definition and initialization: | |
773 | wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer())); | |
774 | ||
775 | if (macDataViewListCtrlPtr != NULL) | |
776 | wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width.")); | |
777 | } /* if */ | |
778 | } /* if */ | |
779 | } /* wxDataViewColumn::SetWidth(int) */ | |
780 | ||
781 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase) | |
782 | ||
783 | //----------------------------------------------------------------------------- | |
784 | // wxDataViewCtrl | |
785 | //----------------------------------------------------------------------------- | |
786 | #pragma mark - | |
787 | void wxDataViewCtrl::Init(void) | |
788 | { | |
789 | this->m_macIsUserPane = false; | |
790 | this->m_NotifierPtr = NULL; | |
791 | this->m_cgContext = NULL; | |
792 | } /* wxDataViewCtrl::Init(void) */ | |
793 | ||
794 | bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) | |
795 | { | |
796 | if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator))) | |
797 | return false; | |
798 | ||
799 | #ifdef __WXMAC__ | |
800 | MacSetClipChildren(true) ; | |
801 | #endif | |
802 | ||
803 | this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style); | |
804 | this->MacPostControlCreate(pos,size); | |
805 | ||
806 | InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL); | |
807 | ||
808 | return true; | |
809 | } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */ | |
810 | ||
811 | void wxDataViewCtrl::OnSize(wxSizeEvent& event) | |
812 | { | |
813 | unsigned int const NoOfColumns = this->GetColumnCount(); | |
814 | ||
815 | ||
816 | for (unsigned int i=0; i<NoOfColumns; ++i) | |
817 | { | |
818 | // variable definition and initialization: | |
819 | wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i)); | |
820 | ||
821 | if (dataViewColumnPtr != NULL) | |
822 | { | |
823 | // variable definition and initialization: | |
824 | wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer())); | |
825 | ||
826 | if (dataViewCustomRendererPtr != NULL) | |
827 | dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed | |
828 | } /* if */ | |
829 | } /* for */ | |
830 | event.Skip(); | |
831 | } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */ | |
832 | ||
833 | bool wxDataViewCtrl::AssociateModel(wxDataViewListModel *model) | |
834 | { | |
835 | if (!wxDataViewCtrlBase::AssociateModel(model)) | |
836 | return false; | |
837 | ||
838 | this->m_NotifierPtr = new wxMacDataViewListModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer)); | |
839 | model->AddNotifier(this->m_NotifierPtr); | |
840 | ||
841 | return true; | |
842 | } | |
843 | ||
844 | bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr) | |
845 | { | |
846 | wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL.")); | |
847 | wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,false,_("Column does not have a renderer.")); | |
848 | if (this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr)) | |
849 | { | |
850 | // variable definition: | |
851 | DataBrowserPropertyID FreeID; | |
852 | DataBrowserListViewColumnDesc columnDescription; | |
853 | wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding())); | |
854 | wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
855 | ||
856 | // initialize column description: | |
857 | wxCHECK_MSG (MacDataViewListCtrlPtr != NULL,false,_("m_peer is not or incorrectly initialized")); | |
858 | verify_noerr(MacDataViewListCtrlPtr->GetFreePropertyID(&FreeID)); | |
859 | dataViewColumnPtr->SetPropertyID(FreeID); | |
860 | columnDescription.propertyDesc.propertyID = FreeID; | |
861 | columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType(); | |
862 | columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; | |
863 | if (dataViewColumnPtr->IsSortable()) | |
864 | columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn; | |
865 | if (dataViewColumnPtr->IsResizeable()) | |
866 | columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn; | |
867 | if (dataViewColumnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE) | |
868 | columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable; | |
869 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
870 | if ((columnDescription.propertyDesc.propertyType == kDataBrowserTextType) || | |
871 | (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) || | |
872 | (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType)) | |
873 | columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
874 | #endif | |
875 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 | |
876 | columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; | |
877 | #endif | |
878 | columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
879 | columnDescription.headerBtnDesc.minimumWidth = 0; | |
880 | columnDescription.headerBtnDesc.maximumWidth = 30000; | |
881 | columnDescription.headerBtnDesc.titleOffset = 0; | |
882 | columnDescription.headerBtnDesc.titleString = cfTitle; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released | |
883 | // having called 'AddColumn' where the title (CFStringRef) is going to be used | |
884 | columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing; | |
885 | columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask; | |
886 | switch (dataViewColumnPtr->GetAlignment()) | |
887 | { | |
888 | case wxALIGN_CENTER: | |
889 | case wxALIGN_CENTER_HORIZONTAL: | |
890 | columnDescription.headerBtnDesc.btnFontStyle.just = teCenter; | |
891 | break; | |
892 | case wxALIGN_LEFT: | |
893 | columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft; | |
894 | break; | |
895 | case wxALIGN_RIGHT: | |
896 | columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight; | |
897 | break; | |
898 | default: | |
899 | columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault; | |
900 | } /* switch */ | |
901 | columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
902 | columnDescription.headerBtnDesc.btnFontStyle.style = normal; | |
903 | columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef; | |
904 | if (dataViewColumnPtr->GetBitmap().Ok()) | |
905 | columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef(); | |
906 | // add column: | |
907 | verify_noerr(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn)); | |
908 | // final adjustments for the layout: | |
909 | if (dataViewColumnPtr->GetWidth() <= 0) | |
910 | { | |
911 | // variable definition: | |
912 | UInt16 defaultColumnWidth; | |
913 | ||
914 | MacDataViewListCtrlPtr->GetDefaultColumnWidth(&defaultColumnWidth); | |
915 | dataViewColumnPtr->SetWidth(defaultColumnWidth); | |
916 | } /* if */ | |
917 | verify_noerr(MacDataViewListCtrlPtr->SetColumnWidth(dataViewColumnPtr->GetPropertyID(),dataViewColumnPtr->GetWidth())); | |
918 | if (dataViewColumnPtr->IsSortable()) // if the current column is sortable and there is no active sortable column yet, the new column will become active | |
919 | { | |
920 | // variable definition: | |
921 | DataBrowserPropertyID sortedProperty; | |
922 | ||
923 | if ((MacDataViewListCtrlPtr->GetSortProperty(&sortedProperty) == noErr) && (sortedProperty < kMinPropertyID)) | |
924 | MacDataViewListCtrlPtr->SetSortProperty(dataViewColumnPtr->GetPropertyID()); | |
925 | } /* if */ | |
926 | ||
927 | // now, make sure that data is shown in the newly appended column: | |
928 | if ((this->GetModel() != NULL) && (this->m_NotifierPtr != NULL) && (dataViewColumnPtr->GetModelColumn() >= 0) && (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount())) | |
929 | if (this->GetColumnCount() == 1) // the newly appended column is the only one and this means that no data has been inserted yet, so do it now: | |
930 | { | |
931 | // variable definition: | |
932 | DataBrowserItemID newID; | |
933 | ||
934 | for (size_t i=0; i<this->GetModel()->GetRowCount(); ++i) | |
935 | if (!((MacDataViewListCtrlPtr->GetFreeItemID(&newID) == noErr) && MacDataViewListCtrlPtr->InsertItemIDRowPair(newID,i) && (MacDataViewListCtrlPtr->AddItem(kDataBrowserNoItem,&newID) == noErr))) | |
936 | return false; | |
937 | } /* if */ | |
938 | else | |
939 | for (size_t i=0; i<this->GetModel()->GetRowCount(); ++i) | |
940 | (void) this->m_NotifierPtr->ValueChanged(dataViewColumnPtr->GetModelColumn(),i); | |
941 | // done: | |
942 | return true; | |
943 | } /* if */ | |
944 | else | |
945 | return false; | |
946 | } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */ | |
947 | ||
948 | int wxDataViewCtrl::GetSelection(void) const | |
949 | { | |
950 | wxArrayInt selectedRows; | |
951 | ||
952 | ||
953 | if (this->GetSelections(selectedRows) > 0) | |
954 | return selectedRows[0]; | |
955 | else | |
956 | return wxNOT_FOUND; | |
957 | } /* wxDataViewCtrl::GetSelection(void) const */ | |
958 | ||
959 | int wxDataViewCtrl::GetSelections(wxArrayInt& selectedRows) const | |
960 | { | |
961 | size_t NoOfSelections; | |
962 | ||
963 | wxArrayDataBrowserItemID itemIDs; | |
964 | ||
965 | wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
966 | ||
967 | ||
968 | if (dataViewListCtrlPtr == NULL) | |
969 | NoOfSelections = 0; | |
970 | else | |
971 | NoOfSelections = dataViewListCtrlPtr->GetSelectedItemIDs(itemIDs); | |
972 | selectedRows.Empty(); | |
973 | selectedRows.Alloc(NoOfSelections); | |
974 | for (size_t i=0; i<NoOfSelections; ++i) | |
975 | { | |
976 | // variable definition: | |
977 | DataBrowserTableViewRowIndex rowIndex; | |
978 | ||
979 | wxCHECK_MSG(dataViewListCtrlPtr->GetRowIndex(rowIndex,itemIDs[i]),0,_("Could not determine row index.")); | |
980 | selectedRows[i] = static_cast<int>(rowIndex); | |
981 | } /* for */ | |
982 | return static_cast<int>(NoOfSelections); | |
983 | } /* wxDataViewCtrl::GetSelections(wxArrayInt&) const */ | |
984 | ||
985 | bool wxDataViewCtrl::IsSelected(unsigned int row) const | |
986 | { | |
987 | DataBrowserItemID itemID; | |
988 | ||
989 | wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
990 | ||
991 | ||
992 | return ((dataViewListCtrlPtr != NULL) && (dataViewListCtrlPtr->GetItemID(row,&itemID) == noErr) && dataViewListCtrlPtr->IsItemSelected(itemID)); | |
993 | } /* wxDataViewCtrl::IsSelected(unsigned int row) const */ | |
994 | ||
995 | void wxDataViewCtrl::SetSelection(int row) | |
996 | { | |
997 | wxArrayDataBrowserItemID selectedItemIDs; | |
998 | ||
999 | size_t NoOfSelections; | |
1000 | ||
1001 | wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
1002 | ||
1003 | ||
1004 | wxCHECK_RET(dataViewListCtrlPtr != NULL,_("Peer pointer not initialized.")); | |
1005 | if (row == -1) // unselect all selected items | |
1006 | { | |
1007 | NoOfSelections = dataViewListCtrlPtr->GetSelectedItemIDs(selectedItemIDs); | |
1008 | for (size_t i=0; i<NoOfSelections; ++i) | |
1009 | (void) dataViewListCtrlPtr->SetSelectedItems(1,&(selectedItemIDs[i]),kDataBrowserItemsRemove); | |
1010 | } /* if */ | |
1011 | else if (row >= 0) // select specified item | |
1012 | { | |
1013 | // variable definition: | |
1014 | DataBrowserItemID itemID; | |
1015 | ||
1016 | verify_noerr(dataViewListCtrlPtr->GetItemID(row,&itemID)); | |
1017 | verify_noerr(dataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd)); // should also deselect automatically all other items | |
1018 | } /* if */ | |
1019 | } /* wxDataViewCtrl::SetSelection(int) */ | |
1020 | ||
1021 | void wxDataViewCtrl::SetSelectionRange(unsigned int from, unsigned int to) | |
1022 | { | |
1023 | wxCHECK_RET(from <= to,_("Invalid specified range ('from' has to be smaller or equal to 'to').")); | |
1024 | ||
1025 | // variable definition: | |
1026 | wxArrayInt selectedRows; | |
1027 | ||
1028 | selectedRows.Alloc(to-from+1); | |
1029 | for (unsigned int i=from; i<=to; ++i) | |
1030 | selectedRows.Add(i); | |
1031 | this->SetSelections(selectedRows); | |
1032 | } /* wxDataViewCtrl::SetSelectionRange(unsigned int, unsigned int) */ | |
1033 | ||
1034 | void wxDataViewCtrl::SetSelections(wxArrayInt const& selectedRows) | |
1035 | { | |
1036 | wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
1037 | ||
1038 | ||
1039 | wxCHECK_RET(dataViewListCtrlPtr != NULL,_("Peer pointer not initialized.")); | |
1040 | // unselect all selected items: | |
1041 | this->SetSelection(-1); | |
1042 | for (size_t i=0; i<selectedRows.GetCount(); ++i) | |
1043 | { | |
1044 | // variable definition: | |
1045 | DataBrowserItemID itemID; | |
1046 | ||
1047 | verify_noerr(dataViewListCtrlPtr->GetItemID(selectedRows[i],&itemID)); | |
1048 | verify_noerr(dataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAssign)); | |
1049 | } /* if */ | |
1050 | } /* wxDataViewCtrl::SetSelections(wxArrayInt const&) */ | |
1051 | ||
1052 | void wxDataViewCtrl::Unselect(unsigned int row) | |
1053 | { | |
1054 | DataBrowserItemID itemID; | |
1055 | ||
1056 | wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
1057 | ||
1058 | ||
1059 | wxCHECK_RET( dataViewListCtrlPtr != NULL, _("Peer pointer not initialized.")); | |
1060 | wxCHECK_RET((dataViewListCtrlPtr->GetItemID(row,&itemID) == noErr) && (dataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove) == noErr),_("Unselection impossible.")); | |
1061 | } /* wxDataViewCtrl::Unselect(unsigned int) */ | |
1062 | ||
1063 | void wxDataViewCtrl::ReverseSorting(DataBrowserPropertyID columnID) | |
1064 | { | |
1065 | ||
1066 | if (columnID >= kMinPropertyID) | |
1067 | { | |
1068 | // variable definition and initialization: | |
1069 | DataBrowserPropertyID sortPropertyID; | |
1070 | wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)); | |
1071 | ||
1072 | wxCHECK_RET(dataViewListCtrlPtr != NULL,_("Peer pointer not initialized.")); | |
1073 | wxCHECK_RET(dataViewListCtrlPtr->GetSortProperty(&sortPropertyID) == noErr,_("Determination of sort property impossible.")); | |
1074 | if (sortPropertyID == columnID) | |
1075 | { | |
1076 | // variable defintion: | |
1077 | DataBrowserSortOrder sortOrderCtrl; | |
1078 | DataBrowserTableViewColumnID columnIndex; | |
1079 | wxDataViewColumn* dataViewColumnPtr; | |
1080 | ||
1081 | wxCHECK_RET(dataViewListCtrlPtr->GetPropertyColumn(columnID,&columnIndex) == noErr,_("Determination of column index impossible")); | |
1082 | wxCHECK_RET(dataViewListCtrlPtr->GetSortOrder(&sortOrderCtrl) == noErr,_("Determination of sort order impossible")); | |
1083 | dataViewColumnPtr = this->GetColumn(columnIndex); | |
1084 | wxCHECK_RET(dataViewColumnPtr != NULL,_("Column could not be obtained.")); | |
1085 | if ((sortOrderCtrl == kDataBrowserOrderIncreasing) && !(dataViewColumnPtr->IsSortOrderAscending()) || | |
1086 | (sortOrderCtrl == kDataBrowserOrderDecreasing) && dataViewColumnPtr->IsSortOrderAscending()) | |
1087 | dataViewListCtrlPtr->ReverseRowIndexNumbering(); | |
1088 | } /* if */ | |
1089 | } /* if */ | |
1090 | } /* wxDataViewCtrl::ReverseSorting(DataBrowserPropertyID columnID) */ | |
1091 | ||
1092 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase) | |
1093 | ||
1094 | BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase) | |
1095 | EVT_SIZE(wxDataViewCtrl::OnSize) | |
1096 | END_EVENT_TABLE() | |
1097 | ||
1098 | #endif | |
1099 | // !wxUSE_GENERICDATAVIEWCTRL | |
1100 | ||
1101 | #endif | |
1102 | // wxUSE_DATAVIEWCTRL | |
1103 |