1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/listbox.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/listbox.h"
19 #include "wx/dynarray.h"
24 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/arrstr.h"
27 #include "wx/toplevel.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
32 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
35 #include "wx/mac/uma.h"
36 #include "wx/dynarray.h"
38 // ============================================================================
39 // list box control implementation
40 // ============================================================================
42 wxListBox::wxListBox()
46 bool wxListBox::Create(
51 const wxArrayString
& choices
,
53 const wxValidator
& validator
,
54 const wxString
& name
)
56 wxCArrayString
chs(choices
);
59 parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
60 style
, validator
, name
);
63 wxMacListControl
* wxListBox::GetPeer() const
65 return dynamic_cast<wxMacListControl
*>(m_peer
);
68 bool wxListBox::Create(
74 const wxString choices
[],
76 const wxValidator
& validator
,
77 const wxString
& name
)
79 m_macIsUserPane
= false;
81 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
82 wxT("only a single listbox selection mode can be specified") );
84 if ( !wxListBoxBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
87 wxMacDataBrowserListControl
* control
= new wxMacDataBrowserListControl( this, pos
, size
, style
);
88 control
->SetClientDataType( m_clientDataItemsType
);
91 MacPostControlCreate( pos
, size
);
93 InsertItems( n
, choices
, 0 );
95 // Needed because it is a wxControlWithItems
101 wxListBox::~wxListBox()
104 m_peer
->SetReference( 0 );
107 void wxListBox::FreeData()
109 GetPeer()->MacClear();
112 void wxListBox::DoSetFirstItem(int n
)
114 GetPeer()->MacScrollTo( n
);
117 void wxListBox::EnsureVisible(int n
)
119 GetPeer()->MacScrollTo( n
);
122 void wxListBox::Delete(unsigned int n
)
124 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::Delete") );
126 GetPeer()->MacDelete( n
);
129 int wxListBox::DoAppend(const wxString
& item
)
131 InvalidateBestSize();
133 return GetPeer()->MacAppend( item
);
136 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
140 unsigned int n
= choices
.GetCount();
142 for ( size_t i
= 0; i
< n
; ++i
)
146 Append( choices
[i
], clientData
[i
] );
149 Append( choices
[i
] );
154 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
156 for ( size_t i
= 0; i
< GetCount(); ++ i
)
158 if (s
.IsSameAs( GetString( i
), bCase
) )
165 void wxListBox::Clear()
170 void wxListBox::DoSetSelection(int n
, bool select
)
172 wxCHECK_RET( n
== wxNOT_FOUND
|| IsValid(n
),
173 wxT("invalid index in wxListBox::SetSelection") );
175 if ( n
== wxNOT_FOUND
)
176 GetPeer()->MacDeselectAll();
178 GetPeer()->MacSetSelection( n
, select
);
181 bool wxListBox::IsSelected(int n
) const
183 wxCHECK_MSG( IsValid(n
), false, wxT("invalid index in wxListBox::Selected") );
185 return GetPeer()->MacIsSelected( n
);
188 void *wxListBox::DoGetItemClientData(unsigned int n
) const
190 wxCHECK_MSG( IsValid(n
), NULL
, wxT("invalid index in wxListBox::GetClientData"));
191 return GetPeer()->MacGetClientData( n
);
194 wxClientData
*wxListBox::DoGetItemClientObject(unsigned int n
) const
196 return (wxClientData
*)DoGetItemClientData( n
);
199 void wxListBox::DoSetItemClientData(unsigned int n
, void *clientData
)
201 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetClientData") );
202 GetPeer()->MacSetClientData( n
, clientData
);
205 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
207 DoSetItemClientData(n
, clientData
);
210 // Return number of selections and an array of selected integers
211 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
213 return GetPeer()->MacGetSelections( aSelections
);
216 // Get single selection, for single choice list items
217 int wxListBox::GetSelection() const
219 return GetPeer()->MacGetSelection();
222 // Find string for position
223 wxString
wxListBox::GetString(unsigned int n
) const
225 wxCHECK_MSG( IsValid(n
), wxEmptyString
, wxT("invalid index in wxListBox::GetString") );
226 return GetPeer()->MacGetString(n
);
229 void wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
)
231 wxCHECK_RET( IsValidInsert(pos
), wxT("invalid index in wxListBox::InsertItems") );
233 InvalidateBestSize();
235 GetPeer()->MacInsert( pos
, items
);
238 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
240 GetPeer()->MacSetString( n
, s
);
243 wxSize
wxListBox::DoGetBestSize() const
245 int lbWidth
= 100; // some defaults
250 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
)MacGetTopLevelWindowRef() ) );
252 // TODO: clean this up
255 ::TextFont( m_font
.MacGetFontNum() );
256 ::TextSize( m_font
.MacGetFontSize() );
257 ::TextFace( m_font
.MacGetFontStyle() );
261 ::TextFont( kFontIDMonaco
);
266 // Find the widest line
267 for (unsigned int i
= 0; i
< GetCount(); i
++)
269 wxString
str( GetString( i
) );
272 Point bounds
= {0, 0};
275 // NB: what if m_font.Ok() == false ???
276 ::GetThemeTextDimensions(
277 wxMacCFStringHolder( str
, m_font
.GetEncoding() ),
278 kThemeCurrentPortFont
,
285 wLine
= ::TextWidth( str
.c_str(), 0, str
.length() );
288 lbWidth
= wxMax( lbWidth
, wLine
);
291 // Add room for the scrollbar
292 lbWidth
+= wxSystemSettings::GetMetric( wxSYS_VSCROLL_X
);
294 // And just a bit more
296 int cx
= ::TextWidth( "X", 0, 1 );
299 // don't make the listbox too tall (limit height to around 10 items)
300 // but don't make it too small neither
301 lbHeight
= wxMax( (cy
+ 4) * wxMin( wxMax( GetCount(), 3 ), 10 ), 70 );
304 return wxSize( lbWidth
, lbHeight
);
307 unsigned int wxListBox::GetCount() const
309 return GetPeer()->MacGetCount();
312 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
314 wxControl::Refresh( eraseBack
, rect
);
317 // Some custom controls depend on this
318 /* static */ wxVisualAttributes
319 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
321 wxVisualAttributes attr
;
323 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
324 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
325 attr
.font
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
330 int wxListBox::DoListHitTest(const wxPoint
& inpoint
) const
334 // There are few reasons why this is complicated:
335 // 1) There is no native HitTest function for Mac
336 // 2) GetDataBrowserItemPartBounds only works on visible items
337 // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight
338 // because what it returns is basically inaccurate in the context
339 // of the coordinates we want here, but we use this as a guess
340 // for where the first visible item lies
342 wxPoint point
= inpoint
;
344 // interestingly enough 10.2 (and below?) have GetDataBrowserItemPartBounds
345 // giving root window coordinates but 10.3 and above give client coordinates
346 // so we only compare using root window coordinates on 10.3 and up
347 if ( UMAGetSystemVersion() < 0x1030 )
348 MacClientToRootWindow(&point
.x
, &point
.y
);
350 // get column property ID (req. for call to itempartbounds)
351 DataBrowserTableViewColumnID colId
= 0;
352 err
= GetDataBrowserTableViewColumnProperty(m_peer
->GetControlRef(), 0, &colId
);
353 wxCHECK_MSG(err
== noErr
, wxNOT_FOUND
, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
355 // OK, first we need to find the first visible item we have -
356 // this will be the "low" for our binary search. There is no real
357 // easy way around this, as we will need to do a SLOW linear search
358 // until we find a visible item, but we can do a cheap calculation
359 // via the row height to speed things up a bit
360 UInt32 scrollx
, scrolly
;
361 err
= GetDataBrowserScrollPosition(m_peer
->GetControlRef(), &scrollx
, &scrolly
);
362 wxCHECK_MSG(err
== noErr
, wxNOT_FOUND
, wxT("Unexpected error from GetDataBrowserScrollPosition"));
365 err
= GetDataBrowserTableViewRowHeight(m_peer
->GetControlRef(), &height
);
366 wxCHECK_MSG(err
== noErr
, wxNOT_FOUND
, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
368 // these indices are 0-based, as usual, so we need to add 1 to them when
369 // passing them to data browser functions which use 1-based indices
370 int low
= scrolly
/ height
,
371 high
= GetCount() - 1;
373 // search for the first visible item (note that the scroll guess above
374 // is the low bounds of where the item might lie so we only use that as a
375 // starting point - we should reach it within 1 or 2 iterations of the loop)
376 while ( low
<= high
)
379 err
= GetDataBrowserItemPartBounds(
380 m_peer
->GetControlRef(), low
+ 1, colId
,
381 kDataBrowserPropertyEnclosingPart
,
382 &bounds
); // note +1 to translate to Mac ID
386 // errDataBrowserItemNotFound is expected as it simply means that the
387 // item is not currently visible -- but other errors are not
388 wxCHECK_MSG( err
== errDataBrowserItemNotFound
, wxNOT_FOUND
,
389 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
394 // NOW do a binary search for where the item lies, searching low again if
395 // we hit an item that isn't visible
396 while ( low
<= high
)
398 int mid
= (low
+ high
) / 2;
401 err
= GetDataBrowserItemPartBounds(
402 m_peer
->GetControlRef(), mid
+ 1, colId
,
403 kDataBrowserPropertyEnclosingPart
,
404 &bounds
); //note +1 to trans to mac id
405 wxCHECK_MSG( err
== noErr
|| err
== errDataBrowserItemNotFound
,
407 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
409 if ( err
== errDataBrowserItemNotFound
)
411 // item not visible, attempt to find a visible one
415 else // visible item, do actual hitttest
417 // if point is within the bounds, return this item (since we assume
418 // all x coords of items are equal we only test the x coord in
420 if ((point
.x
>= bounds
.left
&& point
.x
<= bounds
.right
) &&
421 (point
.y
>= bounds
.top
&& point
.y
<= bounds
.bottom
) )
427 if ( point
.y
< bounds
.top
)
428 // index(bounds) greater then key(point)
431 // index(bounds) less then key(point)
439 // ============================================================================
440 // data browser based implementation
441 // ============================================================================
443 const short kTextColumnId
= 1024;
444 const short kNumericOrderColumnId
= 1025;
446 wxMacListBoxItem::wxMacListBoxItem()
452 wxMacListBoxItem::~wxMacListBoxItem()
456 void wxMacListBoxItem::SetOrder( SInt32 order
)
461 SInt32
wxMacListBoxItem::GetOrder() const
466 void wxMacListBoxItem::SetData( void* data
)
471 void* wxMacListBoxItem::GetData() const
476 void wxMacListBoxItem::SetLabel( const wxString
& str
)
479 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
482 const wxString
& wxMacListBoxItem::GetLabel() const
487 bool wxMacListBoxItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
488 const wxMacDataItem
* rhs
,
489 DataBrowserPropertyID sortProperty
) const
491 const wxMacListBoxItem
* otherItem
= dynamic_cast<const wxMacListBoxItem
*>(rhs
);
493 switch (sortProperty
)
496 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
499 case kNumericOrderColumnId
:
500 retval
= m_order
< otherItem
->m_order
;
510 OSStatus
wxMacListBoxItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
511 DataBrowserPropertyID property
,
512 DataBrowserItemDataRef itemData
,
515 OSStatus err
= errDataBrowserPropertyNotSupported
;
516 wxListBox
*list
= wxDynamicCast( owner
->GetPeer() , wxListBox
);
517 wxCHECK_MSG( list
!= NULL
, errDataBrowserPropertyNotSupported
, wxT("Listbox expected"));
524 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
528 case kNumericOrderColumnId
:
529 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
541 // no editable props here
550 void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl
*owner
,
551 DataBrowserItemNotification message
,
552 DataBrowserItemDataRef itemData
) const
554 wxMacDataBrowserListControl
*lb
= dynamic_cast<wxMacDataBrowserListControl
*>(owner
);
556 // we want to depend on as little as possible to make sure tear-down of controls is safe
558 if ( message
== kDataBrowserItemRemoved
)
560 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
562 delete (wxClientData
*) (m_data
);
569 wxListBox
*list
= wxDynamicCast( owner
->GetPeer() , wxListBox
);
570 wxCHECK_RET( list
!= NULL
, wxT("Listbox expected"));
572 bool trigger
= false;
573 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_SELECTED
, list
->GetId() );
576 case kDataBrowserItemDeselected
:
577 if ( list
->HasMultipleSelection() )
578 trigger
= !lb
->IsSelectionSuppressed();
581 case kDataBrowserItemSelected
:
582 trigger
= !lb
->IsSelectionSuppressed();
585 case kDataBrowserItemDoubleClicked
:
586 event
.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
);
596 event
.SetEventObject( list
);
597 if ( list
->HasClientObjectData() )
598 event
.SetClientObject( (wxClientData
*) m_data
);
599 else if ( list
->HasClientUntypedData() )
600 event
.SetClientData( m_data
);
601 event
.SetString( m_label
);
602 event
.SetInt( owner
->GetLineFromItem( this ) );
603 event
.SetExtraLong( list
->HasMultipleSelection() ? message
== kDataBrowserItemSelected
: true );
604 wxPostEvent( list
->GetEventHandler(), event
);
606 // direct notification is not always having the listbox GetSelection() having in synch with event
607 // list->GetEventHandler()->ProcessEvent(event);
611 wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
612 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
614 OSStatus err
= noErr
;
615 m_clientDataItemsType
= wxClientData_None
;
616 m_stringSorted
= style
& wxLB_SORT
;
618 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
619 if ( style
& wxLB_MULTIPLE
)
621 options
|= kDataBrowserAlwaysExtendSelection
| kDataBrowserCmdTogglesSelection
;
623 else if ( style
& wxLB_EXTENDED
)
629 options
|= kDataBrowserSelectOnlyOne
;
631 err
= SetSelectionFlags( options
);
634 DataBrowserListViewColumnDesc columnDesc
;
635 columnDesc
.headerBtnDesc
.titleOffset
= 0;
636 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
638 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
639 kControlUseFontMask
| kControlUseJustMask
;
641 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
642 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
643 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
644 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
645 columnDesc
.headerBtnDesc
.titleString
= NULL
;
647 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
648 columnDesc
.headerBtnDesc
.maximumWidth
= 10000;
650 columnDesc
.propertyDesc
.propertyID
= kTextColumnId
;
651 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
;
652 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserTableViewSelectionColumn
;
653 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
654 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
657 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
659 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
660 columnDesc
.headerBtnDesc
.maximumWidth
= 0;
661 columnDesc
.propertyDesc
.propertyID
= kNumericOrderColumnId
;
662 columnDesc
.propertyDesc
.propertyType
= kDataBrowserPropertyRelevanceRankPart
;
663 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserTableViewSelectionColumn
;
664 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
665 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
668 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
670 SetDataBrowserSortProperty( m_controlRef
, kTextColumnId
);
671 if ( m_stringSorted
)
673 SetDataBrowserSortProperty( m_controlRef
, kTextColumnId
);
674 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
678 SetDataBrowserSortProperty( m_controlRef
, kNumericOrderColumnId
);
679 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
682 verify_noerr( AutoSizeColumns() );
683 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
684 verify_noerr( SetHeaderButtonHeight( 0 ) );
685 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
687 // shouldn't be necessary anymore under 10.2
688 m_peer
->SetData( kControlNoPart
, kControlDataBrowserIncludesFrameAndFocusTag
, (Boolean
)false );
689 m_peer
->SetNeedsFocusRect( true );
693 wxMacDataBrowserListControl::~wxMacDataBrowserListControl()
698 wxMacListBoxItem
* wxMacDataBrowserListControl::CreateItem()
700 return new wxMacListBoxItem();
703 wxListBox
* wxMacDataBrowserListControl::GetPeer() const
705 return wxDynamicCast( wxMacControl::GetPeer() , wxListBox
);
708 wxClientDataType
wxMacDataBrowserListControl::GetClientDataType() const
710 return m_clientDataItemsType
;
712 void wxMacDataBrowserListControl::SetClientDataType(wxClientDataType clientDataItemsType
)
714 m_clientDataItemsType
= clientDataItemsType
;
717 unsigned int wxMacDataBrowserListControl::MacGetCount() const
719 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
722 void wxMacDataBrowserListControl::MacDelete( unsigned int n
)
724 wxMacListBoxItem
* item
= (wxMacListBoxItem
*)GetItemFromLine( n
);
725 RemoveItem( wxMacDataBrowserRootContainer
, item
);
728 void wxMacDataBrowserListControl::MacInsert( unsigned int n
, const wxString
& text
)
730 wxMacListBoxItem
* newItem
= CreateItem();
731 newItem
->SetLabel( text
);
733 if ( !m_stringSorted
)
735 // increase the order of the lines to be shifted
736 unsigned int lines
= MacGetCount();
737 for ( unsigned int i
= n
; i
< lines
; ++i
)
739 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(i
);
740 iter
->SetOrder( iter
->GetOrder() + 1 );
743 SInt32 frontLineOrder
= 0;
746 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(n
-1);
747 frontLineOrder
= iter
->GetOrder();
749 newItem
->SetOrder( frontLineOrder
+ 1 );
752 AddItem( wxMacDataBrowserRootContainer
, newItem
);
755 void wxMacDataBrowserListControl::MacInsert( unsigned int n
, const wxArrayString
& items
)
757 size_t itemsCount
= items
.GetCount();
758 if ( itemsCount
== 0 )
761 SInt32 frontLineOrder
= 0;
763 if ( !m_stringSorted
)
765 // increase the order of the lines to be shifted
766 unsigned int lines
= MacGetCount();
767 for ( unsigned int i
= n
; i
< lines
; ++i
)
769 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(i
);
770 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
774 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(n
-1);
775 frontLineOrder
= iter
->GetOrder();
779 wxArrayMacDataItemPtr ids
;
780 ids
.SetCount( itemsCount
);
782 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
784 wxMacListBoxItem
* item
= CreateItem();
785 item
->SetLabel( items
[i
]);
786 if ( !m_stringSorted
)
787 item
->SetOrder( frontLineOrder
+ 1 + i
);
792 AddItems( wxMacDataBrowserRootContainer
, ids
);
795 int wxMacDataBrowserListControl::MacAppend( const wxString
& text
)
797 wxMacListBoxItem
* item
= CreateItem();
798 item
->SetLabel( text
);
799 if ( !m_stringSorted
)
801 unsigned int lines
= MacGetCount();
806 wxMacListBoxItem
* frontItem
= (wxMacListBoxItem
*) GetItemFromLine(lines
-1);
807 item
->SetOrder( frontItem
->GetOrder() + 1 );
810 AddItem( wxMacDataBrowserRootContainer
, item
);
812 return GetLineFromItem(item
);
815 void wxMacDataBrowserListControl::MacClear()
817 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
818 RemoveAllItems(wxMacDataBrowserRootContainer
);
821 void wxMacDataBrowserListControl::MacDeselectAll()
823 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
824 SetSelectedAllItems( kDataBrowserItemsRemove
);
827 void wxMacDataBrowserListControl::MacSetSelection( unsigned int n
, bool select
)
829 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine(n
);
830 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
832 if ( IsItemSelected( item
) != select
)
835 SetSelectedItem( item
, GetPeer()->HasMultipleSelection() ? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
837 SetSelectedItem( item
, kDataBrowserItemsRemove
);
843 bool wxMacDataBrowserListControl::MacIsSelected( unsigned int n
) const
845 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine(n
);
846 return IsItemSelected( item
);
849 int wxMacDataBrowserListControl::MacGetSelection() const
851 wxMacDataItemPtr first
, last
;
852 GetSelectionAnchor( &first
, &last
);
856 return GetLineFromItem( first
);
862 int wxMacDataBrowserListControl::MacGetSelections( wxArrayInt
& aSelections
) const
865 wxArrayMacDataItemPtr selectedItems
;
866 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
868 int count
= selectedItems
.GetCount();
870 for ( int i
= 0; i
< count
; ++i
)
872 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
878 void wxMacDataBrowserListControl::MacSetString( unsigned int n
, const wxString
& text
)
880 // as we don't store the strings we only have to issue a redraw
881 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
882 item
->SetLabel( text
);
883 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
886 wxString
wxMacDataBrowserListControl::MacGetString( unsigned int n
) const
888 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
889 return item
->GetLabel();
892 void wxMacDataBrowserListControl::MacSetClientData( unsigned int n
, void * data
)
894 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
895 item
->SetData( data
);
896 // not displayed, therefore no Update infos to DataBrowser
899 void * wxMacDataBrowserListControl::MacGetClientData( unsigned int n
) const
901 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
902 return item
->GetData();
905 void wxMacDataBrowserListControl::MacScrollTo( unsigned int n
)
907 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
912 // in case we need that one day
914 // ============================================================================
915 // HIView owner-draw-based implementation
916 // ============================================================================
918 static pascal void ListBoxDrawProc(
919 ControlRef browser
, DataBrowserItemID item
, DataBrowserPropertyID property
,
920 DataBrowserItemState itemState
, const Rect
*itemRect
, SInt16 depth
, Boolean isColorDevice
)
922 CFStringRef cfString
;
923 ThemeDrawingState themeState
;
926 GetThemeDrawingState( &themeState
);
927 cfString
= CFStringCreateWithFormat( NULL
, NULL
, CFSTR("Row %d"), item
);
929 // In this sample we handle the "selected" state; all others fall through to our "active" state
930 if ( itemState
== kDataBrowserItemIsSelected
)
932 ThemeBrush colorBrushID
;
934 // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor
935 // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor
936 // for inactive browser highlighting
937 Gestalt( gestaltSystemVersion
, &systemVersion
);
938 if ( (systemVersion
>= 0x00001030) && !IsControlActive( browser
) )
939 colorBrushID
= kThemeBrushSecondaryHighlightColor
;
941 colorBrushID
= kThemeBrushPrimaryHighlightColor
;
943 // First paint the hilite rect, then the text on top
944 SetThemePen( colorBrushID
, 32, true );
945 PaintRect( itemRect
);
946 SetThemeDrawingState( themeState
, false );
949 DrawThemeTextBox( cfString
, kThemeApplicationFont
, kThemeStateActive
, true, itemRect
, teFlushDefault
, NULL
);
950 SetThemeDrawingState( themeState
, true );
952 if ( cfString
!= NULL
)
953 CFRelease( cfString
);
959 #endif // wxUSE_LISTBOX