]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/osx/carbon/listbox.cpp | |
3 | // Purpose: wxListBox | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_LISTBOX | |
15 | ||
16 | #include "wx/listbox.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/log.h" | |
20 | #include "wx/intl.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/settings.h" | |
23 | #include "wx/arrstr.h" | |
24 | #include "wx/dcclient.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/osx/private.h" | |
28 | ||
29 | // ============================================================================ | |
30 | // list box control implementation | |
31 | // ============================================================================ | |
32 | ||
33 | wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, | |
34 | wxWindowMac* WXUNUSED(parent), | |
35 | wxWindowID WXUNUSED(id), | |
36 | const wxPoint& pos, | |
37 | const wxSize& size, | |
38 | long style, | |
39 | long WXUNUSED(extraStyle)) | |
40 | { | |
41 | wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( wxpeer, pos, size, style ); | |
42 | // TODO CHECK control->SetClientDataType( m_clientDataItemsType ); | |
43 | return control; | |
44 | } | |
45 | ||
46 | int wxListBox::DoListHitTest(const wxPoint& inpoint) const | |
47 | { | |
48 | OSStatus err; | |
49 | ||
50 | // There are few reasons why this is complicated: | |
51 | // 1) There is no native HitTest function for Mac | |
52 | // 2) GetDataBrowserItemPartBounds only works on visible items | |
53 | // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight | |
54 | // because what it returns is basically inaccurate in the context | |
55 | // of the coordinates we want here, but we use this as a guess | |
56 | // for where the first visible item lies | |
57 | ||
58 | wxPoint point = inpoint; | |
59 | ||
60 | // get column property ID (req. for call to itempartbounds) | |
61 | DataBrowserTableViewColumnID colId = 0; | |
62 | err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId); | |
63 | wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty")); | |
64 | ||
65 | // OK, first we need to find the first visible item we have - | |
66 | // this will be the "low" for our binary search. There is no real | |
67 | // easy way around this, as we will need to do a SLOW linear search | |
68 | // until we find a visible item, but we can do a cheap calculation | |
69 | // via the row height to speed things up a bit | |
70 | UInt32 scrollx, scrolly; | |
71 | err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly); | |
72 | wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition")); | |
73 | ||
74 | UInt16 height; | |
75 | err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height); | |
76 | wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight")); | |
77 | ||
78 | // these indices are 0-based, as usual, so we need to add 1 to them when | |
79 | // passing them to data browser functions which use 1-based indices | |
80 | int low = scrolly / height, | |
81 | high = GetCount() - 1; | |
82 | ||
83 | // search for the first visible item (note that the scroll guess above | |
84 | // is the low bounds of where the item might lie so we only use that as a | |
85 | // starting point - we should reach it within 1 or 2 iterations of the loop) | |
86 | while ( low <= high ) | |
87 | { | |
88 | Rect bounds; | |
89 | err = GetDataBrowserItemPartBounds( | |
90 | m_peer->GetControlRef(), low + 1, colId, | |
91 | kDataBrowserPropertyEnclosingPart, | |
92 | &bounds); // note +1 to translate to Mac ID | |
93 | if ( err == noErr ) | |
94 | break; | |
95 | ||
96 | // errDataBrowserItemNotFound is expected as it simply means that the | |
97 | // item is not currently visible -- but other errors are not | |
98 | wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND, | |
99 | wxT("Unexpected error from GetDataBrowserItemPartBounds") ); | |
100 | ||
101 | low++; | |
102 | } | |
103 | ||
104 | // NOW do a binary search for where the item lies, searching low again if | |
105 | // we hit an item that isn't visible | |
106 | while ( low <= high ) | |
107 | { | |
108 | int mid = (low + high) / 2; | |
109 | ||
110 | Rect bounds; | |
111 | err = GetDataBrowserItemPartBounds( | |
112 | m_peer->GetControlRef(), mid + 1, colId, | |
113 | kDataBrowserPropertyEnclosingPart, | |
114 | &bounds); //note +1 to trans to mac id | |
115 | wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound, | |
116 | wxNOT_FOUND, | |
117 | wxT("Unexpected error from GetDataBrowserItemPartBounds") ); | |
118 | ||
119 | if ( err == errDataBrowserItemNotFound ) | |
120 | { | |
121 | // item not visible, attempt to find a visible one | |
122 | // search lower | |
123 | high = mid - 1; | |
124 | } | |
125 | else // visible item, do actual hitttest | |
126 | { | |
127 | // if point is within the bounds, return this item (since we assume | |
128 | // all x coords of items are equal we only test the x coord in | |
129 | // equality) | |
130 | if ((point.x >= bounds.left && point.x <= bounds.right) && | |
131 | (point.y >= bounds.top && point.y <= bounds.bottom) ) | |
132 | { | |
133 | // found! | |
134 | return mid; | |
135 | } | |
136 | ||
137 | if ( point.y < bounds.top ) | |
138 | // index(bounds) greater then key(point) | |
139 | high = mid - 1; | |
140 | else | |
141 | // index(bounds) less then key(point) | |
142 | low = mid + 1; | |
143 | } | |
144 | } | |
145 | ||
146 | return wxNOT_FOUND; | |
147 | } | |
148 | ||
149 | // ============================================================================ | |
150 | // data browser based implementation | |
151 | // ============================================================================ | |
152 | ||
153 | wxMacListBoxItem::wxMacListBoxItem() | |
154 | :wxMacDataItem() | |
155 | { | |
156 | } | |
157 | ||
158 | wxMacListBoxItem::~wxMacListBoxItem() | |
159 | { | |
160 | } | |
161 | ||
162 | OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner , | |
163 | DataBrowserPropertyID property, | |
164 | DataBrowserItemDataRef itemData, | |
165 | bool changeValue ) | |
166 | { | |
167 | wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl); | |
168 | OSStatus err = errDataBrowserPropertyNotSupported; | |
169 | if ( !changeValue ) | |
170 | { | |
171 | if ( property >= kMinColumnId ) | |
172 | { | |
173 | wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( property ); | |
174 | unsigned int n = owner->GetLineFromItem( this ); | |
175 | wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox ); | |
176 | wxMacDataBrowserCellValue valueholder(itemData); | |
177 | list->GetValueCallback( n , col, valueholder ); | |
178 | ||
179 | err = noErr; | |
180 | } | |
181 | else | |
182 | { | |
183 | if ( property == kDataBrowserItemIsEditableProperty ) | |
184 | { | |
185 | DataBrowserPropertyID propertyToEdit ; | |
186 | GetDataBrowserItemDataProperty( itemData, &propertyToEdit ); | |
187 | wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( propertyToEdit ); | |
188 | ||
189 | verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, col->IsEditable() )); | |
190 | err = noErr; | |
191 | } | |
192 | ||
193 | } | |
194 | ||
195 | } | |
196 | else | |
197 | { | |
198 | if ( property >= kMinColumnId ) | |
199 | { | |
200 | wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( property ); | |
201 | ||
202 | unsigned int n = owner->GetLineFromItem( this ); | |
203 | wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox ); | |
204 | wxMacDataBrowserCellValue valueholder(itemData); | |
205 | list->SetValueCallback( n , col, valueholder ); | |
206 | ||
207 | /* | |
208 | // we have to change this behind the back, since Check() would be triggering another update round | |
209 | bool newVal = !m_isChecked; | |
210 | verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff )); | |
211 | m_isChecked = newVal; | |
212 | err = noErr; | |
213 | ||
214 | wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() ); | |
215 | event.SetInt( owner->GetLineFromItem( this ) ); | |
216 | event.SetEventObject( checklist ); | |
217 | checklist->HandleWindowEvent( event ); | |
218 | ||
219 | */ | |
220 | err = noErr; | |
221 | } | |
222 | } | |
223 | ||
224 | // call inherited if not ours | |
225 | if ( err == errDataBrowserPropertyNotSupported ) | |
226 | { | |
227 | err = wxMacDataItem::GetSetData(owner, property, itemData, changeValue); | |
228 | } | |
229 | ||
230 | return err; | |
231 | } | |
232 | ||
233 | void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner , | |
234 | DataBrowserItemNotification message, | |
235 | DataBrowserItemDataRef WXUNUSED(itemData) ) const | |
236 | { | |
237 | wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl); | |
238 | ||
239 | // we want to depend on as little as possible to make sure tear-down of controls is safe | |
240 | ||
241 | if ( message == kDataBrowserItemRemoved) | |
242 | { | |
243 | delete this; | |
244 | return; | |
245 | } | |
246 | ||
247 | wxListBox *list = wxDynamicCast( lb->GetWXPeer() , wxListBox ); | |
248 | wxCHECK_RET( list != NULL , wxT("Listbox expected")); | |
249 | ||
250 | if (message == kDataBrowserItemDoubleClicked) | |
251 | { | |
252 | unsigned int n = owner->GetLineFromItem( this ); | |
253 | list->HandleLineEvent( n, true ); | |
254 | return; | |
255 | } | |
256 | } | |
257 | ||
258 | IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl ) | |
259 | ||
260 | wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style) | |
261 | : wxMacDataItemBrowserControl( peer, pos, size, style ) | |
262 | { | |
263 | m_nextColumnId = 0 ; | |
264 | ||
265 | OSStatus err = noErr; | |
266 | m_clientDataItemsType = wxClientData_None; | |
267 | if ( style & wxLB_SORT ) | |
268 | m_sortOrder = SortOrder_Text_Ascending; | |
269 | ||
270 | DataBrowserSelectionFlags options = kDataBrowserDragSelect; | |
271 | if ( style & wxLB_MULTIPLE ) | |
272 | { | |
273 | options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection; | |
274 | } | |
275 | else if ( style & wxLB_EXTENDED ) | |
276 | { | |
277 | options |= kDataBrowserCmdTogglesSelection; | |
278 | } | |
279 | else | |
280 | { | |
281 | options |= kDataBrowserSelectOnlyOne; | |
282 | } | |
283 | err = SetSelectionFlags( options ); | |
284 | verify_noerr( err ); | |
285 | ||
286 | DataBrowserListViewColumnDesc columnDesc; | |
287 | columnDesc.headerBtnDesc.titleOffset = 0; | |
288 | columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
289 | ||
290 | columnDesc.headerBtnDesc.btnFontStyle.flags = | |
291 | kControlUseFontMask | kControlUseJustMask; | |
292 | ||
293 | columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; | |
294 | columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; | |
295 | columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
296 | columnDesc.headerBtnDesc.btnFontStyle.style = normal; | |
297 | columnDesc.headerBtnDesc.titleString = NULL; | |
298 | /* | |
299 | columnDesc.headerBtnDesc.minimumWidth = 0; | |
300 | columnDesc.headerBtnDesc.maximumWidth = 10000; | |
301 | ||
302 | columnDesc.propertyDesc.propertyID = kTextColumnId; | |
303 | columnDesc.propertyDesc.propertyType = kDataBrowserTextType; | |
304 | columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; | |
305 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
306 | ||
307 | verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); | |
308 | */ | |
309 | columnDesc.headerBtnDesc.minimumWidth = 0; | |
310 | columnDesc.headerBtnDesc.maximumWidth = 0; | |
311 | columnDesc.propertyDesc.propertyID = kNumericOrderColumnId; | |
312 | columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart; | |
313 | columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; | |
314 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
315 | ||
316 | verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); | |
317 | ||
318 | /* | |
319 | SetDataBrowserSortProperty( m_controlRef , kTextColumnId); | |
320 | if ( m_sortOrder == SortOrder_Text_Ascending ) | |
321 | { | |
322 | SetDataBrowserSortProperty( m_controlRef , kTextColumnId); | |
323 | SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); | |
324 | } | |
325 | else | |
326 | */ | |
327 | { | |
328 | SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId); | |
329 | SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); | |
330 | } | |
331 | ||
332 | verify_noerr( AutoSizeColumns() ); | |
333 | verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) ); | |
334 | verify_noerr( SetHeaderButtonHeight( 0 ) ); | |
335 | err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true ); | |
336 | #if 0 | |
337 | // shouldn't be necessary anymore under 10.2 | |
338 | m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false ); | |
339 | m_peer->SetNeedsFocusRect( true ); | |
340 | #endif | |
341 | } | |
342 | ||
343 | wxMacDataBrowserListControl::~wxMacDataBrowserListControl() | |
344 | { | |
345 | } | |
346 | ||
347 | void wxMacDataBrowserListControl::ItemNotification( | |
348 | DataBrowserItemID itemID, | |
349 | DataBrowserItemNotification message, | |
350 | DataBrowserItemDataRef itemData) | |
351 | { | |
352 | wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox ); | |
353 | wxCHECK_RET( list != NULL , wxT("Listbox expected")); | |
354 | ||
355 | if (list->HasMultipleSelection() && (message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents())) | |
356 | { | |
357 | list->CalcAndSendEvent(); | |
358 | return; | |
359 | } | |
360 | ||
361 | if ((message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents())) | |
362 | { | |
363 | wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() ); | |
364 | ||
365 | int sel = list->GetSelection(); | |
366 | if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?) | |
367 | return; | |
368 | list->HandleLineEvent( sel, false ); | |
369 | return; | |
370 | } | |
371 | ||
372 | // call super for item level(wxMacDataItem->Notification) callback processing | |
373 | wxMacDataItemBrowserControl::ItemNotification( itemID, message, itemData); | |
374 | } | |
375 | ||
376 | ||
377 | /* | |
378 | wxWindow * wxMacDataBrowserListControl::GetPeer() const | |
379 | { | |
380 | return wxDynamicCast( wxMacControl::GetWX() , wxWindow ); | |
381 | } | |
382 | */ | |
383 | ||
384 | // | |
385 | // List Methods | |
386 | // | |
387 | ||
388 | wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned int pos, DataBrowserPropertyID property, | |
389 | const wxString& title, bool editable, | |
390 | DataBrowserPropertyType colType, SInt16 just, int width ) | |
391 | { | |
392 | DataBrowserListViewColumnDesc columnDesc; | |
393 | columnDesc.headerBtnDesc.titleOffset = 0; | |
394 | columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
395 | ||
396 | columnDesc.headerBtnDesc.btnFontStyle.flags = | |
397 | kControlUseFontMask | kControlUseJustMask; | |
398 | ||
399 | columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly; | |
400 | columnDesc.headerBtnDesc.btnFontStyle.just = just; | |
401 | columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
402 | columnDesc.headerBtnDesc.btnFontStyle.style = normal; | |
403 | ||
404 | // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is | |
405 | // defined for other modes? | |
406 | wxFontEncoding enc; | |
407 | if ( m_font.Ok() ) | |
408 | enc = m_font.GetEncoding(); | |
409 | else | |
410 | enc = wxLocale::GetSystemEncoding(); | |
411 | wxCFStringRef cfTitle( title, enc ); | |
412 | columnDesc.headerBtnDesc.titleString = cfTitle; | |
413 | ||
414 | columnDesc.headerBtnDesc.minimumWidth = 0; | |
415 | columnDesc.headerBtnDesc.maximumWidth = 30000; | |
416 | ||
417 | columnDesc.propertyDesc.propertyID = property; | |
418 | columnDesc.propertyDesc.propertyType = colType; | |
419 | columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn; | |
420 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
421 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; | |
422 | ||
423 | if ( editable ) | |
424 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserPropertyIsMutable; | |
425 | ||
426 | verify_noerr( AddColumn( &columnDesc, pos ) ); | |
427 | ||
428 | if (width > 0) | |
429 | { | |
430 | wxMacDataBrowserControl::SetColumnWidth(property, width); | |
431 | } | |
432 | ||
433 | wxMacDataBrowserColumn *col = new wxMacDataBrowserColumn( property, colType, editable ); | |
434 | ||
435 | m_columns.Insert( col, pos ); | |
436 | ||
437 | return col; | |
438 | } | |
439 | ||
440 | wxListWidgetColumn* wxMacDataBrowserListControl::InsertTextColumn( unsigned pos, const wxString& title, bool editable, | |
441 | wxAlignment just, int defaultWidth) | |
442 | { | |
443 | DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++; | |
444 | ||
445 | SInt16 j = teFlushLeft; | |
446 | if ( just & wxALIGN_RIGHT ) | |
447 | j = teFlushRight; | |
448 | else if ( just & wxALIGN_CENTER_HORIZONTAL ) | |
449 | j = teCenter; | |
450 | ||
451 | return DoInsertColumn( pos, property, title, editable, kDataBrowserTextType, just, defaultWidth ); | |
452 | } | |
453 | ||
454 | wxListWidgetColumn* wxMacDataBrowserListControl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable, | |
455 | wxAlignment just, int defaultWidth ) | |
456 | { | |
457 | DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++; | |
458 | ||
459 | SInt16 j = teFlushLeft; | |
460 | if ( just & wxALIGN_RIGHT ) | |
461 | j = teFlushRight; | |
462 | else if ( just & wxALIGN_CENTER_HORIZONTAL ) | |
463 | j = teCenter; | |
464 | ||
465 | return DoInsertColumn( pos, property, title, editable, kDataBrowserCheckboxType, just, defaultWidth ); | |
466 | } | |
467 | ||
468 | wxMacDataBrowserColumn* wxMacDataBrowserListControl::GetColumnFromProperty( DataBrowserPropertyID property) | |
469 | { | |
470 | for ( unsigned int i = 0; i < m_columns.size() ; ++ i ) | |
471 | if ( m_columns[i]->GetProperty() == property ) | |
472 | return m_columns[i]; | |
473 | ||
474 | return NULL; | |
475 | } | |
476 | ||
477 | /* | |
478 | wxMacDataItem* wxMacDataBrowserListControl::ListGetLineItem( unsigned int n ) | |
479 | { | |
480 | return (wxMacDataItem*) GetItemFromLine(n); | |
481 | } | |
482 | */ | |
483 | ||
484 | unsigned int wxMacDataBrowserListControl::ListGetCount() const | |
485 | { | |
486 | return MacGetCount(); | |
487 | } | |
488 | ||
489 | void wxMacDataBrowserListControl::ListDelete( unsigned int n ) | |
490 | { | |
491 | MacDelete( n ); | |
492 | } | |
493 | ||
494 | void wxMacDataBrowserListControl::ListInsert( unsigned int n ) | |
495 | { | |
496 | MacInsert( n , new wxMacListBoxItem() ); | |
497 | } | |
498 | ||
499 | void wxMacDataBrowserListControl::ListClear() | |
500 | { | |
501 | MacClear(); | |
502 | } | |
503 | ||
504 | void wxMacDataBrowserListControl::ListDeselectAll() | |
505 | { | |
506 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
507 | SetSelectedAllItems( kDataBrowserItemsRemove ); | |
508 | } | |
509 | ||
510 | void wxMacDataBrowserListControl::ListSetSelection( unsigned int n, bool select, bool multi ) | |
511 | { | |
512 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); | |
513 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
514 | ||
515 | if ( IsItemSelected( item ) != select ) | |
516 | { | |
517 | if ( select ) | |
518 | SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign ); | |
519 | else | |
520 | SetSelectedItem( item, kDataBrowserItemsRemove ); | |
521 | } | |
522 | ||
523 | ListScrollTo( n ); | |
524 | } | |
525 | ||
526 | bool wxMacDataBrowserListControl::ListIsSelected( unsigned int n ) const | |
527 | { | |
528 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); | |
529 | return IsItemSelected( item ); | |
530 | } | |
531 | ||
532 | int wxMacDataBrowserListControl::ListGetSelection() const | |
533 | { | |
534 | wxMacDataItemPtr first, last; | |
535 | GetSelectionAnchor( &first, &last ); | |
536 | ||
537 | if ( first != NULL ) | |
538 | { | |
539 | return GetLineFromItem( first ); | |
540 | } | |
541 | ||
542 | return -1; | |
543 | } | |
544 | ||
545 | int wxMacDataBrowserListControl::ListGetSelections( wxArrayInt& aSelections ) const | |
546 | { | |
547 | aSelections.Empty(); | |
548 | wxArrayMacDataItemPtr selectedItems; | |
549 | GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems); | |
550 | ||
551 | int count = selectedItems.GetCount(); | |
552 | ||
553 | for ( int i = 0; i < count; ++i) | |
554 | { | |
555 | aSelections.Add(GetLineFromItem(selectedItems[i])); | |
556 | } | |
557 | ||
558 | return count; | |
559 | } | |
560 | ||
561 | void wxMacDataBrowserListControl::ListScrollTo( unsigned int n ) | |
562 | { | |
563 | UInt32 top , left ; | |
564 | GetScrollPosition( &top , &left ) ; | |
565 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
566 | ||
567 | // there is a bug in RevealItem that leads to situations | |
568 | // in large lists, where the item does not get scrolled | |
569 | // into sight, so we do a pre-scroll if necessary | |
570 | UInt16 height ; | |
571 | GetRowHeight( (DataBrowserItemID) item , &height ) ; | |
572 | UInt32 linetop = n * ((UInt32) height ); | |
573 | UInt32 linebottom = linetop + height; | |
574 | Rect rect ; | |
575 | GetControlBounds( m_controlRef, &rect ); | |
576 | ||
577 | if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) ) | |
578 | SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ; | |
579 | ||
580 | RevealItem( item , kDataBrowserRevealWithoutSelecting ); | |
581 | } | |
582 | ||
583 | void wxMacDataBrowserListControl::UpdateLine( unsigned int n, wxListWidgetColumn* col ) | |
584 | { | |
585 | wxMacDataBrowserColumn* dbcol = dynamic_cast<wxMacDataBrowserColumn*> (col); | |
586 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
587 | UpdateItem(wxMacDataBrowserRootContainer, item, dbcol ? dbcol->GetProperty() : kDataBrowserNoItem ); | |
588 | } | |
589 | ||
590 | void wxMacDataBrowserListControl::UpdateLineToEnd( unsigned int n) | |
591 | { | |
592 | // with databrowser inserting does not need updating the entire model, it's done by databrowser itself | |
593 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
594 | UpdateItem(wxMacDataBrowserRootContainer, item, kDataBrowserNoItem ); | |
595 | } | |
596 | ||
597 | // value setters | |
598 | ||
599 | void wxMacDataBrowserCellValue::Set( CFStringRef value ) | |
600 | { | |
601 | SetDataBrowserItemDataText( m_data, value ); | |
602 | } | |
603 | ||
604 | void wxMacDataBrowserCellValue::Set( const wxString& value ) | |
605 | { | |
606 | wxCFStringRef cf(value); | |
607 | SetDataBrowserItemDataText( m_data, (CFStringRef) cf); | |
608 | } | |
609 | ||
610 | void wxMacDataBrowserCellValue::Set( int value ) | |
611 | { | |
612 | SetDataBrowserItemDataValue( m_data, value ); | |
613 | // SetDataBrowserItemDataButtonValue( m_data, value ? kThemeButtonOn : kThemeButtonOff); | |
614 | } | |
615 | ||
616 | int wxMacDataBrowserCellValue::GetIntValue() const | |
617 | { | |
618 | SInt32 value; | |
619 | GetDataBrowserItemDataValue( m_data, &value ); | |
620 | return value; | |
621 | } | |
622 | ||
623 | wxString wxMacDataBrowserCellValue::GetStringValue() const | |
624 | { | |
625 | CFStringRef value; | |
626 | GetDataBrowserItemDataText ( m_data, &value ); | |
627 | wxCFStringRef cf(value); | |
628 | return cf.AsString(); | |
629 | } | |
630 | ||
631 | #if 0 | |
632 | ||
633 | // in case we need that one day | |
634 | ||
635 | // ============================================================================ | |
636 | // HIView owner-draw-based implementation | |
637 | // ============================================================================ | |
638 | ||
639 | static pascal void ListBoxDrawProc( | |
640 | ControlRef browser, DataBrowserItemID item, DataBrowserPropertyID property, | |
641 | DataBrowserItemState itemState, const Rect *itemRect, SInt16 depth, Boolean isColorDevice ) | |
642 | { | |
643 | CFStringRef cfString; | |
644 | ThemeDrawingState themeState; | |
645 | long systemVersion; | |
646 | ||
647 | GetThemeDrawingState( &themeState ); | |
648 | cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item ); | |
649 | ||
650 | // In this sample we handle the "selected" state; all others fall through to our "active" state | |
651 | if ( itemState == kDataBrowserItemIsSelected ) | |
652 | { | |
653 | ThemeBrush colorBrushID; | |
654 | ||
655 | // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor | |
656 | // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor | |
657 | // for inactive browser highlighting | |
658 | if ( !IsControlActive( browser ) ) | |
659 | colorBrushID = kThemeBrushSecondaryHighlightColor; | |
660 | else | |
661 | colorBrushID = kThemeBrushPrimaryHighlightColor; | |
662 | ||
663 | // First paint the hilite rect, then the text on top | |
664 | SetThemePen( colorBrushID, 32, true ); | |
665 | PaintRect( itemRect ); | |
666 | SetThemeDrawingState( themeState, false ); | |
667 | } | |
668 | ||
669 | DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL ); | |
670 | SetThemeDrawingState( themeState, true ); | |
671 | ||
672 | if ( cfString != NULL ) | |
673 | CFRelease( cfString ); | |
674 | } | |
675 | ||
676 | #endif | |
677 | ||
678 | ||
679 | #endif // wxUSE_LISTBOX |