insert was not correctly implemented
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29347 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -39,6 +39,10 @@ END_EVENT_TABLE()
|
|||||||
const short kTextColumnId = 1024 ;
|
const short kTextColumnId = 1024 ;
|
||||||
|
|
||||||
// new databrowserbased version
|
// new databrowserbased version
|
||||||
|
// because of the limited insert
|
||||||
|
// functionality of DataBrowser,
|
||||||
|
// we just introduce id s corresponding
|
||||||
|
// to the line number
|
||||||
|
|
||||||
// Listbox item
|
// Listbox item
|
||||||
wxListBox::wxListBox()
|
wxListBox::wxListBox()
|
||||||
@@ -74,44 +78,43 @@ static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrow
|
|||||||
if ( ref )
|
if ( ref )
|
||||||
{
|
{
|
||||||
wxListBox* list = wxDynamicCast( (wxObject*) ref , wxListBox ) ;
|
wxListBox* list = wxDynamicCast( (wxObject*) ref , wxListBox ) ;
|
||||||
for ( size_t i = 0 ; i < list->m_idArray.GetCount() ; ++i )
|
size_t i = itemID - 1 ;
|
||||||
if ( list->m_idArray[i] == (long) itemID )
|
if (i >= 0 && i < list->GetCount() )
|
||||||
|
{
|
||||||
|
bool trigger = false ;
|
||||||
|
wxCommandEvent event(
|
||||||
|
wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
|
||||||
|
switch( message )
|
||||||
{
|
{
|
||||||
bool trigger = false ;
|
case kDataBrowserItemDeselected :
|
||||||
wxCommandEvent event(
|
if ( list->HasMultipleSelection() )
|
||||||
wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
|
|
||||||
switch( message )
|
|
||||||
{
|
|
||||||
case kDataBrowserItemDeselected :
|
|
||||||
if ( list->HasMultipleSelection() )
|
|
||||||
trigger = true ;
|
|
||||||
break ;
|
|
||||||
case kDataBrowserItemSelected :
|
|
||||||
trigger = true ;
|
trigger = true ;
|
||||||
break ;
|
break ;
|
||||||
case kDataBrowserItemDoubleClicked :
|
case kDataBrowserItemSelected :
|
||||||
event.SetEventType(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) ;
|
trigger = true ;
|
||||||
trigger = true ;
|
break ;
|
||||||
break ;
|
case kDataBrowserItemDoubleClicked :
|
||||||
default :
|
event.SetEventType(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) ;
|
||||||
break ;
|
trigger = true ;
|
||||||
}
|
break ;
|
||||||
if ( trigger )
|
default :
|
||||||
{
|
break ;
|
||||||
event.SetEventObject( list );
|
|
||||||
if ( list->HasClientObjectData() )
|
|
||||||
event.SetClientObject( list->GetClientObject(i) );
|
|
||||||
else if ( list->HasClientUntypedData() )
|
|
||||||
event.SetClientData( list->GetClientData(i) );
|
|
||||||
event.SetString( list->GetString(i) );
|
|
||||||
event.SetInt(i) ;
|
|
||||||
event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : TRUE );
|
|
||||||
wxPostEvent( list->GetEventHandler() , event ) ;
|
|
||||||
// direct notification is not always having the listbox GetSelection() having in synch with event
|
|
||||||
// list->GetEventHandler()->ProcessEvent(event) ;
|
|
||||||
}
|
|
||||||
break ;
|
|
||||||
}
|
}
|
||||||
|
if ( trigger )
|
||||||
|
{
|
||||||
|
event.SetEventObject( list );
|
||||||
|
if ( list->HasClientObjectData() )
|
||||||
|
event.SetClientObject( list->GetClientObject(i) );
|
||||||
|
else if ( list->HasClientUntypedData() )
|
||||||
|
event.SetClientData( list->GetClientData(i) );
|
||||||
|
event.SetString( list->GetString(i) );
|
||||||
|
event.SetInt(i) ;
|
||||||
|
event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : TRUE );
|
||||||
|
wxPostEvent( list->GetEventHandler() , event ) ;
|
||||||
|
// direct notification is not always having the listbox GetSelection() having in synch with event
|
||||||
|
// list->GetEventHandler()->ProcessEvent(event) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,14 +136,13 @@ static pascal OSStatus ListBoxGetSetItemData(ControlRef browser,
|
|||||||
if ( ref )
|
if ( ref )
|
||||||
{
|
{
|
||||||
wxListBox* list = wxDynamicCast( (wxObject*) ref , wxListBox ) ;
|
wxListBox* list = wxDynamicCast( (wxObject*) ref , wxListBox ) ;
|
||||||
for ( size_t i = 0 ; i < list->m_idArray.GetCount() ; ++i )
|
size_t i = itemID - 1 ;
|
||||||
if ( list->m_idArray[i] == (long) itemID )
|
if (i >= 0 && i < list->GetCount() )
|
||||||
{
|
{
|
||||||
wxMacCFStringHolder cf( list->GetString(i) , list->GetFont().GetEncoding() ) ;
|
wxMacCFStringHolder cf( list->GetString(i) , list->GetFont().GetEncoding() ) ;
|
||||||
verify_noerr( ::SetDataBrowserItemDataText( itemData , cf ) ) ;
|
verify_noerr( ::SetDataBrowserItemDataText( itemData , cf ) ) ;
|
||||||
err = noErr ;
|
err = noErr ;
|
||||||
break ;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -171,8 +173,6 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
|
|||||||
|
|
||||||
m_noItems = 0 ; // this will be increased by our append command
|
m_noItems = 0 ; // this will be increased by our append command
|
||||||
m_selected = 0;
|
m_selected = 0;
|
||||||
m_nextId = 1 ;
|
|
||||||
|
|
||||||
|
|
||||||
Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
|
Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
|
||||||
|
|
||||||
@@ -242,6 +242,12 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
|
|||||||
#endif
|
#endif
|
||||||
m_peer->SetCallbacks( &callbacks);
|
m_peer->SetCallbacks( &callbacks);
|
||||||
|
|
||||||
|
#if TARGET_API_MAC_OSX
|
||||||
|
// there is a redraw bug in 10.2.X
|
||||||
|
if ( UMAGetSystemVersion() < 0x1030 )
|
||||||
|
m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean) false ) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
MacPostControlCreate(pos,size) ;
|
MacPostControlCreate(pos,size) ;
|
||||||
|
|
||||||
for ( int i = 0 ; i < n ; i++ )
|
for ( int i = 0 ; i < n ; i++ )
|
||||||
@@ -521,10 +527,9 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
|||||||
{
|
{
|
||||||
m_stringArray.Insert( items[i] , pos + i ) ;
|
m_stringArray.Insert( items[i] , pos + i ) ;
|
||||||
m_dataArray.Insert( NULL , pos + i ) ;
|
m_dataArray.Insert( NULL , pos + i ) ;
|
||||||
|
m_noItems++ ;
|
||||||
MacInsert( pos + i , items[i] ) ;
|
MacInsert( pos + i , items[i] ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_noItems += nItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::SetString(int N, const wxString& s)
|
void wxListBox::SetString(int N, const wxString& s)
|
||||||
@@ -640,40 +645,38 @@ wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
|||||||
|
|
||||||
void wxListBox::MacDelete( int N )
|
void wxListBox::MacDelete( int N )
|
||||||
{
|
{
|
||||||
UInt32 id = m_idArray[N] ;
|
UInt32 id = m_noItems+1 ;
|
||||||
verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
|
verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
|
||||||
m_idArray.RemoveAt( N ) ;
|
verify_noerr( m_peer->UpdateItems( kDataBrowserNoItem , 1 , (UInt32*) kDataBrowserNoItem , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::MacInsert( int n , const wxString& text)
|
void wxListBox::MacInsert( int n , const wxString& text)
|
||||||
{
|
{
|
||||||
verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ;
|
UInt32 id = m_noItems ; // this has already been increased
|
||||||
m_idArray.Insert( m_nextId , n ) ;
|
verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
|
||||||
++m_nextId ;
|
verify_noerr( m_peer->UpdateItems( kDataBrowserNoItem , 1 , (UInt32*) kDataBrowserNoItem , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::MacAppend( const wxString& text)
|
void wxListBox::MacAppend( const wxString& text)
|
||||||
{
|
{
|
||||||
verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ;
|
UInt32 id = m_noItems ; // this has already been increased
|
||||||
m_idArray.Add( m_nextId ) ;
|
verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ;
|
||||||
++m_nextId ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::MacClear()
|
void wxListBox::MacClear()
|
||||||
{
|
{
|
||||||
verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ;
|
verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ;
|
||||||
m_idArray.Empty() ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::MacSetSelection( int n , bool select )
|
void wxListBox::MacSetSelection( int n , bool select )
|
||||||
{
|
{
|
||||||
UInt32 id = m_idArray[n] ;
|
UInt32 id = n + 1 ;
|
||||||
if ( !(GetWindowStyle() & (wxLB_MULTIPLE|wxLB_EXTENDED) ) )
|
if ( !(GetWindowStyle() & (wxLB_MULTIPLE|wxLB_EXTENDED) ) )
|
||||||
{
|
{
|
||||||
int n = MacGetSelection() ;
|
int n = MacGetSelection() ;
|
||||||
if ( n >= 0 )
|
if ( n >= 0 )
|
||||||
{
|
{
|
||||||
UInt32 idOld = m_idArray[n] ;
|
UInt32 idOld = n + 1 ;
|
||||||
m_peer->SetSelectedItems( 1 , & idOld , kDataBrowserItemsRemove ) ;
|
m_peer->SetSelectedItems( 1 , & idOld , kDataBrowserItemsRemove ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -686,14 +689,14 @@ void wxListBox::MacSetSelection( int n , bool select )
|
|||||||
|
|
||||||
bool wxListBox::MacIsSelected( int n ) const
|
bool wxListBox::MacIsSelected( int n ) const
|
||||||
{
|
{
|
||||||
return m_peer->IsItemSelected( m_idArray[n] ) ;
|
return m_peer->IsItemSelected( n + 1 ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxListBox::MacGetSelection() const
|
int wxListBox::MacGetSelection() const
|
||||||
{
|
{
|
||||||
for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i )
|
for ( size_t i = 0 ; i < GetCount() ; ++i )
|
||||||
{
|
{
|
||||||
if ( m_peer->IsItemSelected( m_idArray[i] ) )
|
if ( m_peer->IsItemSelected( i + 1 ) )
|
||||||
{
|
{
|
||||||
return i ;
|
return i ;
|
||||||
}
|
}
|
||||||
@@ -706,9 +709,9 @@ int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
|
|||||||
int no_sel = 0 ;
|
int no_sel = 0 ;
|
||||||
|
|
||||||
aSelections.Empty();
|
aSelections.Empty();
|
||||||
for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i )
|
for ( size_t i = 0 ; i < GetCount() ; ++i )
|
||||||
{
|
{
|
||||||
if ( m_peer->IsItemSelected( m_idArray[i] ) )
|
if ( m_peer->IsItemSelected( i + 1 ) )
|
||||||
{
|
{
|
||||||
aSelections.Add( i ) ;
|
aSelections.Add( i ) ;
|
||||||
no_sel++ ;
|
no_sel++ ;
|
||||||
@@ -720,13 +723,13 @@ int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
|
|||||||
void wxListBox::MacSet( int n , const wxString& text )
|
void wxListBox::MacSet( int n , const wxString& text )
|
||||||
{
|
{
|
||||||
// as we don't store the strings we only have to issue a redraw
|
// as we don't store the strings we only have to issue a redraw
|
||||||
UInt32 id = m_idArray[n] ;
|
UInt32 id = n + 1 ;
|
||||||
verify_noerr( m_peer->UpdateItems( kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ;
|
verify_noerr( m_peer->UpdateItems( kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListBox::MacScrollTo( int n )
|
void wxListBox::MacScrollTo( int n )
|
||||||
{
|
{
|
||||||
UInt32 id = m_idArray[n] ;
|
UInt32 id = n + 1 ;
|
||||||
verify_noerr( m_peer->RevealItem( id , kTextColumnId , kDataBrowserRevealWithoutSelecting ) ) ;
|
verify_noerr( m_peer->RevealItem( id , kTextColumnId , kDataBrowserRevealWithoutSelecting ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user