-// ============================================================================
-// list box control implementation
-// ============================================================================
-
-void wxListBox::MacDelete( int n )
-{
- wxArrayInt selectionBefore ;
- MacGetSelections( selectionBefore ) ;
-
- UInt32 id = m_noItems + 1 ;
-
- verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
- for ( unsigned int i = 0 ; i < selectionBefore.GetCount() ; ++i )
- {
- int current = selectionBefore[i] ;
- if ( current == n )
- {
- // selection was deleted
- MacSetSelection( current , false ) ;
- }
- else if ( current > n )
- {
- // something behind the deleted item was selected -> move up
- MacSetSelection( current - 1 , true ) ;
- MacSetSelection( current , false ) ;
- }
- }
-
- // refresh all
- verify_noerr(
- m_peer->UpdateItems(
- kDataBrowserNoItem, 1, (UInt32*)kDataBrowserNoItem,
- kDataBrowserItemNoProperty, kDataBrowserItemNoProperty ) ) ;
-}
-
-void wxListBox::MacInsert( int n , const wxString& text )
-{
- wxArrayInt selectionBefore ;
- MacGetSelections( selectionBefore ) ;
-
- // this has already been increased
- UInt32 id = m_noItems ;
- verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
-
- for ( int i = selectionBefore.GetCount()-1 ; i >= 0 ; --i )
- {
- int current = selectionBefore[i] ;
- if ( current >= n )
- {
- MacSetSelection( current + 1 , true ) ;
- MacSetSelection( current , false ) ;
- }
- }
-
- // refresh all
- verify_noerr(
- m_peer->UpdateItems(
- kDataBrowserNoItem, 1, (UInt32*)kDataBrowserNoItem,
- kDataBrowserItemNoProperty, kDataBrowserItemNoProperty ) ) ;
-}
-
-void wxListBox::MacAppend( const wxString& text )
-{
- UInt32 id = m_noItems ; // this has already been increased
- verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
- // no need to deal with selections nor refreshed, as we have appended
-}
-
-void wxListBox::MacClear()
-{
- verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ;
-}
-
-void wxListBox::MacDeselectAll()
-{
- bool former = MacSuppressSelection( true ) ;
- verify_noerr(m_peer->SetSelectedItems( 0 , NULL , kDataBrowserItemsRemove ) ) ;
- MacSuppressSelection( former ) ;
-}
-
-void wxListBox::MacSetSelection( int n , bool select )
-{
- bool former = MacSuppressSelection( true ) ;
- UInt32 id = n + 1 ;
-
- if ( m_peer->IsItemSelected( id ) != select )
- {
- if ( select )
- verify_noerr( m_peer->SetSelectedItems( 1 , & id , HasMultipleSelection() ? kDataBrowserItemsAdd : kDataBrowserItemsAssign ) ) ;
- else
- verify_noerr( m_peer->SetSelectedItems( 1 , & id , kDataBrowserItemsRemove ) ) ;
- }
-
- MacScrollTo( n ) ;
- MacSuppressSelection( former ) ;
-}
-
-bool wxListBox::MacSuppressSelection( bool suppress )
-{
- bool former = m_suppressSelection ;
- m_suppressSelection = suppress ;
- return former ;
-}
-
-bool wxListBox::MacIsSelected( int n ) const
-{
- return m_peer->IsItemSelected( n + 1 ) ;
-}
-
-int wxListBox::MacGetSelection() const
-{
- for ( unsigned int i = 0 ; i < GetCount() ; ++i )
- {
- if ( m_peer->IsItemSelected( i + 1 ) )
- return i ;
- }
-
- return -1 ;
-}
-
-int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
-{
- int no_sel = 0 ;
-
- aSelections.Empty();
-
- UInt32 first , last ;
- m_peer->GetSelectionAnchor( &first , &last ) ;
- if ( first != kDataBrowserNoItem )
- {
- for ( size_t i = first ; i <= last ; ++i )
- {
- if ( m_peer->IsItemSelected( i ) )
- {
- aSelections.Add( i - 1 ) ;
- no_sel++ ;
- }
- }
- }
-
- return no_sel ;
-}
-
-void wxListBox::MacSet( int n , const wxString& text )
-{
- // as we don't store the strings we only have to issue a redraw
- UInt32 id = n + 1 ;
- verify_noerr( m_peer->UpdateItems( kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ;
-}
-
-void wxListBox::MacScrollTo( int n )
-{
- UInt32 id = n + 1 ;
- verify_noerr( m_peer->RevealItem( id , kTextColumnId , kDataBrowserRevealWithoutSelecting ) ) ;
-}
-