]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/listbox.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / carbon / listbox.cpp
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* parent,
35 wxWindowID id,
36 const wxPoint& pos,
37 const wxSize& size,
38 long style,
39 long 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 wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, list->GetId() );
254 event.SetEventObject( list );
255 if ( list->HasClientObjectData() )
256 event.SetClientObject( list->GetClientObject(n) );
257 else if ( list->HasClientUntypedData() )
258 event.SetClientData( list->GetClientData(n) );
259 event.SetString( list->GetString(n) );
260 event.SetInt( n );
261 event.SetExtraLong( 1 );
262 list->HandleWindowEvent(event);
263 return;
264 }
265 }
266
267 IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl )
268
269 wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
270 : wxMacDataItemBrowserControl( peer, pos, size, style )
271 {
272 m_nextColumnId = 0 ;
273
274 OSStatus err = noErr;
275 m_clientDataItemsType = wxClientData_None;
276 if ( style & wxLB_SORT )
277 m_sortOrder = SortOrder_Text_Ascending;
278
279 DataBrowserSelectionFlags options = kDataBrowserDragSelect;
280 if ( style & wxLB_MULTIPLE )
281 {
282 options |= kDataBrowserAlwaysExtendSelection | kDataBrowserCmdTogglesSelection;
283 }
284 else if ( style & wxLB_EXTENDED )
285 {
286 options |= kDataBrowserCmdTogglesSelection;
287 }
288 else
289 {
290 options |= kDataBrowserSelectOnlyOne;
291 }
292 err = SetSelectionFlags( options );
293 verify_noerr( err );
294
295 DataBrowserListViewColumnDesc columnDesc;
296 columnDesc.headerBtnDesc.titleOffset = 0;
297 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
298
299 columnDesc.headerBtnDesc.btnFontStyle.flags =
300 kControlUseFontMask | kControlUseJustMask;
301
302 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
303 columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
304 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
305 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
306 columnDesc.headerBtnDesc.titleString = NULL;
307 /*
308 columnDesc.headerBtnDesc.minimumWidth = 0;
309 columnDesc.headerBtnDesc.maximumWidth = 10000;
310
311 columnDesc.propertyDesc.propertyID = kTextColumnId;
312 columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
313 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
314 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
315
316 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
317 */
318 columnDesc.headerBtnDesc.minimumWidth = 0;
319 columnDesc.headerBtnDesc.maximumWidth = 0;
320 columnDesc.propertyDesc.propertyID = kNumericOrderColumnId;
321 columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart;
322 columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn;
323 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
324
325 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
326
327 /*
328 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
329 if ( m_sortOrder == SortOrder_Text_Ascending )
330 {
331 SetDataBrowserSortProperty( m_controlRef , kTextColumnId);
332 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
333 }
334 else
335 */
336 {
337 SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId);
338 SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing);
339 }
340
341 verify_noerr( AutoSizeColumns() );
342 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
343 verify_noerr( SetHeaderButtonHeight( 0 ) );
344 err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true );
345 #if 0
346 // shouldn't be necessary anymore under 10.2
347 m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false );
348 m_peer->SetNeedsFocusRect( true );
349 #endif
350 }
351
352 wxMacDataBrowserListControl::~wxMacDataBrowserListControl()
353 {
354 }
355
356 void wxMacDataBrowserListControl::ItemNotification(
357 const wxMacDataItem* itemID,
358 DataBrowserItemNotification message,
359 DataBrowserItemDataRef itemData)
360 {
361 wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox );
362 wxCHECK_RET( list != NULL , wxT("Listbox expected"));
363
364 if (list->HasMultipleSelection() && (message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents()))
365 {
366 list->CalcAndSendEvent();
367 return;
368 }
369
370 if ((message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents()))
371 {
372 wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
373
374 int sel = list->GetSelection();
375 if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
376 return;
377 event.SetEventObject( list );
378 if ( list->HasClientObjectData() )
379 event.SetClientObject( list->GetClientObject( sel ) );
380 else if ( list->HasClientUntypedData() )
381 event.SetClientData( list->GetClientData( sel ) );
382 event.SetString( list->GetString( sel ) );
383 event.SetInt( sel );
384 event.SetExtraLong( 1 );
385 list->HandleWindowEvent(event);
386 return;
387 }
388
389 // call super for item level(wxMacDataItem->Notification) callback processing
390 wxMacDataItemBrowserControl::ItemNotification( itemID, message, itemData);
391 }
392
393
394 /*
395 wxWindow * wxMacDataBrowserListControl::GetPeer() const
396 {
397 return wxDynamicCast( wxMacControl::GetWX() , wxWindow );
398 }
399 */
400
401 //
402 // List Methods
403 //
404
405 wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned int pos, DataBrowserPropertyID property,
406 const wxString& title, bool editable,
407 DataBrowserPropertyType colType, SInt16 just, int width )
408 {
409 DataBrowserListViewColumnDesc columnDesc;
410 columnDesc.headerBtnDesc.titleOffset = 0;
411 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
412
413 columnDesc.headerBtnDesc.btnFontStyle.flags =
414 kControlUseFontMask | kControlUseJustMask;
415
416 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
417 columnDesc.headerBtnDesc.btnFontStyle.just = just;
418 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
419 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
420
421 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
422 // defined for other modes?
423 wxFontEncoding enc;
424 if ( m_font.Ok() )
425 enc = m_font.GetEncoding();
426 else
427 enc = wxLocale::GetSystemEncoding();
428 wxCFStringRef cfTitle( title, enc );
429 columnDesc.headerBtnDesc.titleString = cfTitle;
430
431 columnDesc.headerBtnDesc.minimumWidth = 0;
432 columnDesc.headerBtnDesc.maximumWidth = 30000;
433
434 columnDesc.propertyDesc.propertyID = property;
435 columnDesc.propertyDesc.propertyType = colType;
436 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
437 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
438 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
439
440 if ( editable )
441 columnDesc.propertyDesc.propertyFlags |= kDataBrowserPropertyIsMutable;
442
443 verify_noerr( AddColumn( &columnDesc, pos ) );
444
445 if (width > 0)
446 {
447 wxMacDataBrowserControl::SetColumnWidth(property, width);
448 }
449
450 wxMacDataBrowserColumn *col = new wxMacDataBrowserColumn( property, colType, editable );
451
452 m_columns.Insert( col, pos );
453
454 return col;
455 }
456
457 wxListWidgetColumn* wxMacDataBrowserListControl::InsertTextColumn( unsigned pos, const wxString& title, bool editable,
458 wxAlignment just, int defaultWidth)
459 {
460 DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++;
461
462 SInt16 j = teFlushLeft;
463 if ( just & wxALIGN_RIGHT )
464 j = teFlushRight;
465 else if ( just & wxALIGN_CENTER_HORIZONTAL )
466 j = teCenter;
467
468 return DoInsertColumn( pos, property, title, editable, kDataBrowserTextType, just, defaultWidth );
469 }
470
471 wxListWidgetColumn* wxMacDataBrowserListControl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable,
472 wxAlignment just, int defaultWidth )
473 {
474 DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++;
475
476 SInt16 j = teFlushLeft;
477 if ( just & wxALIGN_RIGHT )
478 j = teFlushRight;
479 else if ( just & wxALIGN_CENTER_HORIZONTAL )
480 j = teCenter;
481
482 return DoInsertColumn( pos, property, title, editable, kDataBrowserCheckboxType, just, defaultWidth );
483 }
484
485 wxMacDataBrowserColumn* wxMacDataBrowserListControl::GetColumnFromProperty( DataBrowserPropertyID property)
486 {
487 for ( unsigned int i = 0; i < m_columns.size() ; ++ i )
488 if ( m_columns[i]->GetProperty() == property )
489 return m_columns[i];
490
491 return NULL;
492 }
493
494 /*
495 wxMacDataItem* wxMacDataBrowserListControl::ListGetLineItem( unsigned int n )
496 {
497 return (wxMacDataItem*) GetItemFromLine(n);
498 }
499 */
500
501 unsigned int wxMacDataBrowserListControl::ListGetCount() const
502 {
503 return MacGetCount();
504 }
505
506 void wxMacDataBrowserListControl::ListDelete( unsigned int n )
507 {
508 MacDelete( n );
509 }
510
511 void wxMacDataBrowserListControl::ListInsert( unsigned int n )
512 {
513 MacInsert( n , new wxMacListBoxItem() );
514 }
515
516 void wxMacDataBrowserListControl::ListClear()
517 {
518 MacClear();
519 }
520
521 void wxMacDataBrowserListControl::ListDeselectAll()
522 {
523 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
524 SetSelectedAllItems( kDataBrowserItemsRemove );
525 }
526
527 void wxMacDataBrowserListControl::ListSetSelection( unsigned int n, bool select, bool multi )
528 {
529 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
530 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
531
532 if ( IsItemSelected( item ) != select )
533 {
534 if ( select )
535 SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign );
536 else
537 SetSelectedItem( item, kDataBrowserItemsRemove );
538 }
539
540 ListScrollTo( n );
541 }
542
543 bool wxMacDataBrowserListControl::ListIsSelected( unsigned int n ) const
544 {
545 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
546 return IsItemSelected( item );
547 }
548
549 int wxMacDataBrowserListControl::ListGetSelection() const
550 {
551 wxMacDataItemPtr first, last;
552 GetSelectionAnchor( &first, &last );
553
554 if ( first != NULL )
555 {
556 return GetLineFromItem( first );
557 }
558
559 return -1;
560 }
561
562 int wxMacDataBrowserListControl::ListGetSelections( wxArrayInt& aSelections ) const
563 {
564 aSelections.Empty();
565 wxArrayMacDataItemPtr selectedItems;
566 GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems);
567
568 int count = selectedItems.GetCount();
569
570 for ( int i = 0; i < count; ++i)
571 {
572 aSelections.Add(GetLineFromItem(selectedItems[i]));
573 }
574
575 return count;
576 }
577
578 void wxMacDataBrowserListControl::ListScrollTo( unsigned int n )
579 {
580 UInt32 top , left ;
581 GetScrollPosition( &top , &left ) ;
582 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
583
584 // there is a bug in RevealItem that leads to situations
585 // in large lists, where the item does not get scrolled
586 // into sight, so we do a pre-scroll if necessary
587 UInt16 height ;
588 GetRowHeight( (DataBrowserItemID) item , &height ) ;
589 UInt32 linetop = n * ((UInt32) height );
590 UInt32 linebottom = linetop + height;
591 Rect rect ;
592 GetControlBounds( m_controlRef, &rect );
593
594 if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) )
595 SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ;
596
597 RevealItem( item , kDataBrowserRevealWithoutSelecting );
598 }
599
600 void wxMacDataBrowserListControl::UpdateLine( unsigned int n, wxListWidgetColumn* col )
601 {
602 wxMacDataBrowserColumn* dbcol = dynamic_cast<wxMacDataBrowserColumn*> (col);
603 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
604 UpdateItem(wxMacDataBrowserRootContainer, item, dbcol ? dbcol->GetProperty() : kDataBrowserNoItem );
605 }
606
607 void wxMacDataBrowserListControl::UpdateLineToEnd( unsigned int n)
608 {
609 // with databrowser inserting does not need updating the entire model, it's done by databrowser itself
610 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
611 UpdateItem(wxMacDataBrowserRootContainer, item, kDataBrowserNoItem );
612 }
613
614 // value setters
615
616 void wxMacDataBrowserCellValue::Set( CFStringRef value )
617 {
618 SetDataBrowserItemDataText( m_data, value );
619 }
620
621 void wxMacDataBrowserCellValue::Set( const wxString& value )
622 {
623 wxCFStringRef cf(value);
624 SetDataBrowserItemDataText( m_data, (CFStringRef) cf);
625 }
626
627 void wxMacDataBrowserCellValue::Set( int value )
628 {
629 SetDataBrowserItemDataValue( m_data, value );
630 // SetDataBrowserItemDataButtonValue( m_data, value ? kThemeButtonOn : kThemeButtonOff);
631 }
632
633 int wxMacDataBrowserCellValue::GetIntValue() const
634 {
635 SInt32 value;
636 GetDataBrowserItemDataValue( m_data, &value );
637 return value;
638 }
639
640 wxString wxMacDataBrowserCellValue::GetStringValue() const
641 {
642 CFStringRef value;
643 GetDataBrowserItemDataText ( m_data, &value );
644 wxCFStringRef cf(value);
645 return cf.AsString();
646 }
647
648 #if 0
649
650 // in case we need that one day
651
652 // ============================================================================
653 // HIView owner-draw-based implementation
654 // ============================================================================
655
656 static pascal void ListBoxDrawProc(
657 ControlRef browser, DataBrowserItemID item, DataBrowserPropertyID property,
658 DataBrowserItemState itemState, const Rect *itemRect, SInt16 depth, Boolean isColorDevice )
659 {
660 CFStringRef cfString;
661 ThemeDrawingState themeState;
662 long systemVersion;
663
664 GetThemeDrawingState( &themeState );
665 cfString = CFStringCreateWithFormat( NULL, NULL, CFSTR("Row %d"), item );
666
667 // In this sample we handle the "selected" state; all others fall through to our "active" state
668 if ( itemState == kDataBrowserItemIsSelected )
669 {
670 ThemeBrush colorBrushID;
671
672 // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor
673 // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor
674 // for inactive browser highlighting
675 if ( !IsControlActive( browser ) )
676 colorBrushID = kThemeBrushSecondaryHighlightColor;
677 else
678 colorBrushID = kThemeBrushPrimaryHighlightColor;
679
680 // First paint the hilite rect, then the text on top
681 SetThemePen( colorBrushID, 32, true );
682 PaintRect( itemRect );
683 SetThemeDrawingState( themeState, false );
684 }
685
686 DrawThemeTextBox( cfString, kThemeApplicationFont, kThemeStateActive, true, itemRect, teFlushDefault, NULL );
687 SetThemeDrawingState( themeState, true );
688
689 if ( cfString != NULL )
690 CFRelease( cfString );
691 }
692
693 #endif
694
695
696 #endif // wxUSE_LISTBOX