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"
28 #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"
37 #include "wx/arrstr.h"
39 // ============================================================================
40 // list box control implementation
41 // ============================================================================
43 wxListBox::wxListBox()
47 bool wxListBox::Create(
52 const wxArrayString
& choices
,
54 const wxValidator
& validator
,
55 const wxString
& name
)
57 wxCArrayString
chs(choices
);
60 parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
61 style
, validator
, name
);
64 wxMacListControl
* wxListBox::GetPeer() const
66 return dynamic_cast<wxMacListControl
*>(m_peer
);
69 bool wxListBox::Create(
75 const wxString choices
[],
77 const wxValidator
& validator
,
78 const wxString
& name
)
80 m_macIsUserPane
= false;
82 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
83 wxT("only a single listbox selection mode can be specified") );
85 if ( !wxListBoxBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
88 wxMacDataBrowserListControl
* control
= new wxMacDataBrowserListControl( this, pos
, size
, style
);
89 control
->SetClientDataType( m_clientDataItemsType
);
92 MacPostControlCreate( pos
, size
);
94 InsertItems( n
, choices
, 0 );
96 // Needed because it is a wxControlWithItems
102 wxListBox::~wxListBox()
105 m_peer
->SetReference( 0 );
108 void wxListBox::FreeData()
110 GetPeer()->MacClear();
113 void wxListBox::DoSetFirstItem(int n
)
115 GetPeer()->MacScrollTo( n
);
118 void wxListBox::EnsureVisible(int n
)
120 GetPeer()->MacScrollTo( n
);
123 void wxListBox::Delete(unsigned int n
)
125 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::Delete") );
127 GetPeer()->MacDelete( n
);
130 int wxListBox::DoAppend(const wxString
& item
)
132 InvalidateBestSize();
134 return GetPeer()->MacAppend( item
);
137 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
141 unsigned int n
= choices
.GetCount();
143 for ( size_t i
= 0; i
< n
; ++i
)
147 Append( choices
[i
], clientData
[i
] );
150 Append( choices
[i
] );
155 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
157 for ( size_t i
= 0; i
< GetCount(); ++ i
)
159 if (s
.IsSameAs( GetString( i
), bCase
) )
166 void wxListBox::Clear()
171 void wxListBox::DoSetSelection(int n
, bool select
)
173 wxCHECK_RET( n
== wxNOT_FOUND
|| IsValid(n
),
174 wxT("invalid index in wxListBox::SetSelection") );
176 if ( n
== wxNOT_FOUND
)
177 GetPeer()->MacDeselectAll();
179 GetPeer()->MacSetSelection( n
, select
);
182 bool wxListBox::IsSelected(int n
) const
184 wxCHECK_MSG( IsValid(n
), false, wxT("invalid index in wxListBox::Selected") );
186 return GetPeer()->MacIsSelected( n
);
189 void *wxListBox::DoGetItemClientData(unsigned int n
) const
191 wxCHECK_MSG( IsValid(n
), NULL
, wxT("invalid index in wxListBox::GetClientData"));
192 return GetPeer()->MacGetClientData( n
);
195 wxClientData
*wxListBox::DoGetItemClientObject(unsigned int n
) const
197 return (wxClientData
*)DoGetItemClientData( n
);
200 void wxListBox::DoSetItemClientData(unsigned int n
, void *clientData
)
202 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetClientData") );
203 GetPeer()->MacSetClientData( n
, clientData
);
206 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
208 DoSetItemClientData(n
, clientData
);
211 // Return number of selections and an array of selected integers
212 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
214 return GetPeer()->MacGetSelections( aSelections
);
217 // Get single selection, for single choice list items
218 int wxListBox::GetSelection() const
220 return GetPeer()->MacGetSelection();
223 // Find string for position
224 wxString
wxListBox::GetString(unsigned int n
) const
226 wxCHECK_MSG( IsValid(n
), wxEmptyString
, wxT("invalid index in wxListBox::GetString") );
227 return GetPeer()->MacGetString(n
);
230 void wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
)
232 wxCHECK_RET( IsValidInsert(pos
), wxT("invalid index in wxListBox::InsertItems") );
234 InvalidateBestSize();
236 GetPeer()->MacInsert( pos
, items
);
239 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
241 GetPeer()->MacSetString( n
, s
);
244 wxSize
wxListBox::DoGetBestSize() const
246 int lbWidth
= 100; // some defaults
251 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
)MacGetTopLevelWindowRef() ) );
253 // TODO: clean this up
256 ::TextFont( m_font
.MacGetFontNum() );
257 ::TextSize( m_font
.MacGetFontSize() );
258 ::TextFace( m_font
.MacGetFontStyle() );
262 ::TextFont( kFontIDMonaco
);
267 // Find the widest line
268 for (unsigned int i
= 0; i
< GetCount(); i
++)
270 wxString
str( GetString( i
) );
273 Point bounds
= {0, 0};
276 // NB: what if m_font.Ok() == false ???
277 ::GetThemeTextDimensions(
278 wxMacCFStringHolder( str
, m_font
.GetEncoding() ),
279 kThemeCurrentPortFont
,
286 wLine
= ::TextWidth( str
.c_str(), 0, str
.length() );
289 lbWidth
= wxMax( lbWidth
, wLine
);
292 // Add room for the scrollbar
293 lbWidth
+= wxSystemSettings::GetMetric( wxSYS_VSCROLL_X
);
295 // And just a bit more
297 int cx
= ::TextWidth( "X", 0, 1 );
300 // don't make the listbox too tall (limit height to around 10 items)
301 // but don't make it too small neither
302 lbHeight
= wxMax( (cy
+ 4) * wxMin( wxMax( GetCount(), 3 ), 10 ), 70 );
305 return wxSize( lbWidth
, lbHeight
);
308 unsigned int wxListBox::GetCount() const
310 return GetPeer()->MacGetCount();
313 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
315 wxControl::Refresh( eraseBack
, rect
);
318 // Some custom controls depend on this
319 /* static */ wxVisualAttributes
320 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
322 wxVisualAttributes attr
;
324 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
325 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
326 attr
.font
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
331 int wxListBox::DoListHitTest(const wxPoint
& inpoint
) const
335 // There are few reasons why this is complicated:
336 // 1) There is no native HitTest function for Mac
337 // 2) GetDataBrowserItemPartBounds only works on visible items
338 // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight
339 // because what it returns is basically inaccurate in the context
340 // of the coordinates we want here, but we use this as a guess
341 // for where the first visible item lies
343 wxPoint point
= inpoint
;
345 // interestingly enough 10.2 (and below?) have GetDataBrowserItemPartBounds
346 // giving root window coordinates but 10.3 and above give client coordinates
347 // so we only compare using root window coordinates on 10.3 and up
348 if ( UMAGetSystemVersion() < 0x1030 )
349 MacClientToRootWindow(&point
.x
, &point
.y
);
351 // get column property ID (req. for call to itempartbounds)
352 DataBrowserTableViewColumnID colId
= 0;
353 err
= GetDataBrowserTableViewColumnProperty(m_peer
->GetControlRef(), 0, &colId
);
354 wxCHECK_MSG(err
== noErr
, wxNOT_FOUND
, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));
356 // OK, first we need to find the first visible item we have -
357 // this will be the "low" for our binary search. There is no real
358 // easy way around this, as we will need to do a SLOW linear search
359 // until we find a visible item, but we can do a cheap calculation
360 // via the row height to speed things up a bit
361 UInt32 scrollx
, scrolly
;
362 err
= GetDataBrowserScrollPosition(m_peer
->GetControlRef(), &scrollx
, &scrolly
);
363 wxCHECK_MSG(err
== noErr
, wxNOT_FOUND
, wxT("Unexpected error from GetDataBrowserScrollPosition"));
366 err
= GetDataBrowserTableViewRowHeight(m_peer
->GetControlRef(), &height
);
367 wxCHECK_MSG(err
== noErr
, wxNOT_FOUND
, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));
369 // these indices are 0-based, as usual, so we need to add 1 to them when
370 // passing them to data browser functions which use 1-based indices
371 int low
= scrolly
/ height
,
372 high
= GetCount() - 1;
374 // search for the first visible item (note that the scroll guess above
375 // is the low bounds of where the item might lie so we only use that as a
376 // starting point - we should reach it within 1 or 2 iterations of the loop)
377 while ( low
<= high
)
380 err
= GetDataBrowserItemPartBounds(
381 m_peer
->GetControlRef(), low
+ 1, colId
,
382 kDataBrowserPropertyEnclosingPart
,
383 &bounds
); // note +1 to translate to Mac ID
387 // errDataBrowserItemNotFound is expected as it simply means that the
388 // item is not currently visible -- but other errors are not
389 wxCHECK_MSG( err
== errDataBrowserItemNotFound
, wxNOT_FOUND
,
390 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
395 // NOW do a binary search for where the item lies, searching low again if
396 // we hit an item that isn't visible
397 while ( low
<= high
)
399 int mid
= (low
+ high
) / 2;
402 err
= GetDataBrowserItemPartBounds(
403 m_peer
->GetControlRef(), mid
+ 1, colId
,
404 kDataBrowserPropertyEnclosingPart
,
405 &bounds
); //note +1 to trans to mac id
406 wxCHECK_MSG( err
== noErr
|| err
== errDataBrowserItemNotFound
,
408 wxT("Unexpected error from GetDataBrowserItemPartBounds") );
410 if ( err
== errDataBrowserItemNotFound
)
412 // item not visible, attempt to find a visible one
416 else // visible item, do actual hitttest
418 // if point is within the bounds, return this item (since we assume
419 // all x coords of items are equal we only test the x coord in
421 if ((point
.x
>= bounds
.left
&& point
.x
<= bounds
.right
) &&
422 (point
.y
>= bounds
.top
&& point
.y
<= bounds
.bottom
) )
428 if ( point
.y
< bounds
.top
)
429 // index(bounds) greater then key(point)
432 // index(bounds) less then key(point)
440 // ============================================================================
441 // data browser based implementation
442 // ============================================================================
444 const short kTextColumnId
= 1024;
445 const short kNumericOrderColumnId
= 1025;
447 wxMacListBoxItem::wxMacListBoxItem()
453 wxMacListBoxItem::~wxMacListBoxItem()
457 void wxMacListBoxItem::SetOrder( SInt32 order
)
462 SInt32
wxMacListBoxItem::GetOrder() const
467 void wxMacListBoxItem::SetData( void* data
)
472 void* wxMacListBoxItem::GetData() const
477 void wxMacListBoxItem::SetLabel( const wxString
& str
)
480 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
483 const wxString
& wxMacListBoxItem::GetLabel() const
488 bool wxMacListBoxItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
489 const wxMacDataItem
* rhs
,
490 DataBrowserPropertyID sortProperty
) const
492 const wxMacListBoxItem
* otherItem
= dynamic_cast<const wxMacListBoxItem
*>(rhs
);
494 switch (sortProperty
)
497 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
500 case kNumericOrderColumnId
:
501 retval
= m_order
< otherItem
->m_order
;
511 OSStatus
wxMacListBoxItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
512 DataBrowserPropertyID property
,
513 DataBrowserItemDataRef itemData
,
516 OSStatus err
= errDataBrowserPropertyNotSupported
;
517 wxListBox
*list
= wxDynamicCast( owner
->GetPeer() , wxListBox
);
518 wxCHECK_MSG( list
!= NULL
, errDataBrowserPropertyNotSupported
, wxT("Listbox expected"));
525 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
529 case kNumericOrderColumnId
:
530 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
542 // no editable props here
551 void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl
*owner
,
552 DataBrowserItemNotification message
,
553 DataBrowserItemDataRef itemData
) const
555 wxMacDataBrowserListControl
*lb
= dynamic_cast<wxMacDataBrowserListControl
*>(owner
);
557 // we want to depend on as little as possible to make sure tear-down of controls is safe
559 if ( message
== kDataBrowserItemRemoved
)
561 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
563 delete (wxClientData
*) (m_data
);
570 wxListBox
*list
= wxDynamicCast( owner
->GetPeer() , wxListBox
);
571 wxCHECK_RET( list
!= NULL
, wxT("Listbox expected"));
573 bool trigger
= false;
574 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_SELECTED
, list
->GetId() );
577 case kDataBrowserItemDeselected
:
578 if ( list
->HasMultipleSelection() )
579 trigger
= !lb
->IsSelectionSuppressed();
582 case kDataBrowserItemSelected
:
583 trigger
= !lb
->IsSelectionSuppressed();
586 case kDataBrowserItemDoubleClicked
:
587 event
.SetEventType( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
);
597 event
.SetEventObject( list
);
598 if ( list
->HasClientObjectData() )
599 event
.SetClientObject( (wxClientData
*) m_data
);
600 else if ( list
->HasClientUntypedData() )
601 event
.SetClientData( m_data
);
602 event
.SetString( m_label
);
603 event
.SetInt( owner
->GetLineFromItem( this ) );
604 event
.SetExtraLong( list
->HasMultipleSelection() ? message
== kDataBrowserItemSelected
: true );
605 wxPostEvent( list
->GetEventHandler(), event
);
607 // direct notification is not always having the listbox GetSelection() having in synch with event
608 // list->GetEventHandler()->ProcessEvent(event);
612 wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
613 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
615 OSStatus err
= noErr
;
616 m_clientDataItemsType
= wxClientData_None
;
617 m_stringSorted
= style
& wxLB_SORT
;
619 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
620 if ( style
& wxLB_MULTIPLE
)
622 options
|= kDataBrowserAlwaysExtendSelection
| kDataBrowserCmdTogglesSelection
;
624 else if ( style
& wxLB_EXTENDED
)
630 options
|= kDataBrowserSelectOnlyOne
;
632 err
= SetSelectionFlags( options
);
635 DataBrowserListViewColumnDesc columnDesc
;
636 columnDesc
.headerBtnDesc
.titleOffset
= 0;
637 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
639 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
640 kControlUseFontMask
| kControlUseJustMask
;
642 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
643 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
644 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
645 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
646 columnDesc
.headerBtnDesc
.titleString
= NULL
;
648 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
649 columnDesc
.headerBtnDesc
.maximumWidth
= 10000;
651 columnDesc
.propertyDesc
.propertyID
= kTextColumnId
;
652 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
;
653 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserTableViewSelectionColumn
;
654 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
655 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
658 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
660 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
661 columnDesc
.headerBtnDesc
.maximumWidth
= 0;
662 columnDesc
.propertyDesc
.propertyID
= kNumericOrderColumnId
;
663 columnDesc
.propertyDesc
.propertyType
= kDataBrowserPropertyRelevanceRankPart
;
664 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserTableViewSelectionColumn
;
665 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
666 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
669 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
671 SetDataBrowserSortProperty( m_controlRef
, kTextColumnId
);
672 if ( m_stringSorted
)
674 SetDataBrowserSortProperty( m_controlRef
, kTextColumnId
);
675 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
679 SetDataBrowserSortProperty( m_controlRef
, kNumericOrderColumnId
);
680 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
683 verify_noerr( AutoSizeColumns() );
684 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
685 verify_noerr( SetHeaderButtonHeight( 0 ) );
686 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
688 // shouldn't be necessary anymore under 10.2
689 m_peer
->SetData( kControlNoPart
, kControlDataBrowserIncludesFrameAndFocusTag
, (Boolean
)false );
690 m_peer
->SetNeedsFocusRect( true );
694 wxMacDataBrowserListControl::~wxMacDataBrowserListControl()
699 wxMacListBoxItem
* wxMacDataBrowserListControl::CreateItem()
701 return new wxMacListBoxItem();
704 wxListBox
* wxMacDataBrowserListControl::GetPeer() const
706 return wxDynamicCast( wxMacControl::GetPeer() , wxListBox
);
709 wxClientDataType
wxMacDataBrowserListControl::GetClientDataType() const
711 return m_clientDataItemsType
;
713 void wxMacDataBrowserListControl::SetClientDataType(wxClientDataType clientDataItemsType
)
715 m_clientDataItemsType
= clientDataItemsType
;
718 unsigned int wxMacDataBrowserListControl::MacGetCount() const
720 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
723 void wxMacDataBrowserListControl::MacDelete( unsigned int n
)
725 wxMacListBoxItem
* item
= (wxMacListBoxItem
*)GetItemFromLine( n
);
726 RemoveItem( wxMacDataBrowserRootContainer
, item
);
729 void wxMacDataBrowserListControl::MacInsert( unsigned int n
, const wxString
& text
)
731 wxMacListBoxItem
* newItem
= CreateItem();
732 newItem
->SetLabel( text
);
734 if ( !m_stringSorted
)
736 // increase the order of the lines to be shifted
737 unsigned int lines
= MacGetCount();
738 for ( unsigned int i
= n
; i
< lines
; ++i
)
740 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(i
);
741 iter
->SetOrder( iter
->GetOrder() + 1 );
744 SInt32 frontLineOrder
= 0;
747 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(n
-1);
748 frontLineOrder
= iter
->GetOrder();
750 newItem
->SetOrder( frontLineOrder
+ 1 );
753 AddItem( wxMacDataBrowserRootContainer
, newItem
);
756 void wxMacDataBrowserListControl::MacInsert( unsigned int n
, const wxArrayString
& items
)
758 size_t itemsCount
= items
.GetCount();
759 if ( itemsCount
== 0 )
762 SInt32 frontLineOrder
= 0;
764 if ( !m_stringSorted
)
766 // increase the order of the lines to be shifted
767 unsigned int lines
= MacGetCount();
768 for ( unsigned int i
= n
; i
< lines
; ++i
)
770 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(i
);
771 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
775 wxMacListBoxItem
* iter
= (wxMacListBoxItem
*) GetItemFromLine(n
-1);
776 frontLineOrder
= iter
->GetOrder();
780 wxArrayMacDataItemPtr ids
;
781 ids
.SetCount( itemsCount
);
783 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
785 wxMacListBoxItem
* item
= CreateItem();
786 item
->SetLabel( items
[i
]);
787 if ( !m_stringSorted
)
788 item
->SetOrder( frontLineOrder
+ 1 + i
);
793 AddItems( wxMacDataBrowserRootContainer
, ids
);
796 int wxMacDataBrowserListControl::MacAppend( const wxString
& text
)
798 wxMacListBoxItem
* item
= CreateItem();
799 item
->SetLabel( text
);
800 if ( !m_stringSorted
)
802 unsigned int lines
= MacGetCount();
807 wxMacListBoxItem
* frontItem
= (wxMacListBoxItem
*) GetItemFromLine(lines
-1);
808 item
->SetOrder( frontItem
->GetOrder() + 1 );
811 AddItem( wxMacDataBrowserRootContainer
, item
);
813 return GetLineFromItem(item
);
816 void wxMacDataBrowserListControl::MacClear()
818 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
819 RemoveAllItems(wxMacDataBrowserRootContainer
);
822 void wxMacDataBrowserListControl::MacDeselectAll()
824 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
825 SetSelectedAllItems( kDataBrowserItemsRemove
);
828 void wxMacDataBrowserListControl::MacSetSelection( unsigned int n
, bool select
)
830 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine(n
);
831 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
833 if ( IsItemSelected( item
) != select
)
836 SetSelectedItem( item
, GetPeer()->HasMultipleSelection() ? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
838 SetSelectedItem( item
, kDataBrowserItemsRemove
);
844 bool wxMacDataBrowserListControl::MacIsSelected( unsigned int n
) const
846 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine(n
);
847 return IsItemSelected( item
);
850 int wxMacDataBrowserListControl::MacGetSelection() const
852 wxMacDataItemPtr first
, last
;
853 GetSelectionAnchor( &first
, &last
);
857 return GetLineFromItem( first
);
863 int wxMacDataBrowserListControl::MacGetSelections( wxArrayInt
& aSelections
) const
866 wxArrayMacDataItemPtr selectedItems
;
867 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
869 int count
= selectedItems
.GetCount();
871 for ( int i
= 0; i
< count
; ++i
)
873 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
879 void wxMacDataBrowserListControl::MacSetString( unsigned int n
, const wxString
& text
)
881 // as we don't store the strings we only have to issue a redraw
882 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
883 item
->SetLabel( text
);
884 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
887 wxString
wxMacDataBrowserListControl::MacGetString( unsigned int n
) const
889 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
890 return item
->GetLabel();
893 void wxMacDataBrowserListControl::MacSetClientData( unsigned int n
, void * data
)
895 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
896 item
->SetData( data
);
897 // not displayed, therefore no Update infos to DataBrowser
900 void * wxMacDataBrowserListControl::MacGetClientData( unsigned int n
) const
902 wxMacListBoxItem
* item
= (wxMacListBoxItem
*) GetItemFromLine( n
);
903 return item
->GetData();
906 void wxMacDataBrowserListControl::MacScrollTo( unsigned int n
)
908 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
913 // in case we need that one day
915 // ============================================================================
916 // HIView owner-draw-based implementation
917 // ============================================================================
919 static pascal void ListBoxDrawProc(
920 ControlRef browser
, DataBrowserItemID item
, DataBrowserPropertyID property
,
921 DataBrowserItemState itemState
, const Rect
*itemRect
, SInt16 depth
, Boolean isColorDevice
)
923 CFStringRef cfString
;
924 ThemeDrawingState themeState
;
927 GetThemeDrawingState( &themeState
);
928 cfString
= CFStringCreateWithFormat( NULL
, NULL
, CFSTR("Row %d"), item
);
930 // In this sample we handle the "selected" state; all others fall through to our "active" state
931 if ( itemState
== kDataBrowserItemIsSelected
)
933 ThemeBrush colorBrushID
;
935 // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor
936 // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor
937 // for inactive browser highlighting
938 Gestalt( gestaltSystemVersion
, &systemVersion
);
939 if ( (systemVersion
>= 0x00001030) && !IsControlActive( browser
) )
940 colorBrushID
= kThemeBrushSecondaryHighlightColor
;
942 colorBrushID
= kThemeBrushPrimaryHighlightColor
;
944 // First paint the hilite rect, then the text on top
945 SetThemePen( colorBrushID
, 32, true );
946 PaintRect( itemRect
);
947 SetThemeDrawingState( themeState
, false );
950 DrawThemeTextBox( cfString
, kThemeApplicationFont
, kThemeStateActive
, true, itemRect
, teFlushDefault
, NULL
);
951 SetThemeDrawingState( themeState
, true );
953 if ( cfString
!= NULL
)
954 CFRelease( cfString
);
960 #endif // wxUSE_LISTBOX