1. sorted wxListBox and wxComboBox seem to work under wxGTK

2. to support this, new class wxControlWithItems added (ctrlsub.h/cpp) and the
   controls sample modified to test it


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4141 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-22 18:00:39 +00:00
parent 2ee3ee1bc8
commit 6c8a980fc4
28 changed files with 657 additions and 495 deletions

View File

@@ -46,9 +46,17 @@ static void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), wxChoice *
if (g_blockEventsOnDrag) return;
wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, choice->GetId() );
event.SetInt( choice->GetSelection() );
int n = choice->GetSelection();
event.SetInt( n );
event.SetString( choice->GetStringSelection() );
event.SetEventObject(choice);
if ( choice->HasClientObjectData() )
event.SetClientObject( choice->GetClientObject(n) );
else if ( choice->HasClientUntypedData() )
event.SetClientData( choice->GetClientData(n) );
choice->GetEventHandler()->ProcessEvent(event);
}
@@ -134,32 +142,32 @@ int wxChoice::DoAppend( const wxString &item )
return AppendHelper(menu, item);
}
void wxChoice::DoSetClientData( int n, void* clientData )
void wxChoice::DoSetItemClientData( int n, void* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetClientData") );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientData") );
node->SetData( (wxObject*) clientData );
}
void* wxChoice::DoGetClientData( int n ) const
void* wxChoice::DoGetItemClientData( int n ) const
{
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetClientData") );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetItemClientData") );
return node->Data();
}
void wxChoice::DoSetClientObject( int n, wxClientData* clientData )
void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetClientObject") );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientObject") );
wxClientData *cd = (wxClientData*) node->Data();
delete cd;
@@ -167,13 +175,13 @@ void wxChoice::DoSetClientObject( int n, wxClientData* clientData )
node->SetData( (wxObject*) clientData );
}
wxClientData* wxChoice::DoGetClientObject( int n ) const
wxClientData* wxChoice::DoGetItemClientObject( int n ) const
{
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_MSG( node, (wxClientData *)NULL,
wxT("invalid index in wxChoice::DoGetClientObject") );
wxT("invalid index in wxChoice::DoGetItemClientObject") );
return (wxClientData*) node->Data();
}
@@ -186,8 +194,18 @@ void wxChoice::Clear()
GtkWidget *menu = gtk_menu_new();
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
if ( m_clientDataItemsType == ClientData_Object )
m_clientList.DeleteContents(TRUE);
if ( HasClientObjectData() )
{
// destroy the data (due to Robert's idea of using wxList<wxObject>
// and not wxList<wxClientData> we can't just say
// m_clientList.DeleteContents(TRUE) - this would crash!
wxNode *node = m_clientList.First();
while ( node )
{
delete (wxClientData *)node->Data();
node = node->Next();
}
}
m_clientList.Clear();
if ( m_strings )
@@ -246,6 +264,13 @@ int wxChoice::GetSelection() const
return -1;
}
void wxChoice::SetString( int WXUNUSED(n), const wxString& WXUNUSED(string) )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
wxFAIL_MSG(wxT("not implemented"));
}
wxString wxChoice::GetString( int n ) const
{
wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid choice") );
@@ -372,8 +397,7 @@ size_t wxChoice::AppendHelper(GtkWidget *menu, const wxString& item)
}
else
{
// can't use Insert() :-(
m_clientList.Append( (wxObject*) NULL );
m_clientList.Insert( (wxObject*) NULL );
}
}
else

View File

@@ -102,25 +102,28 @@ gtk_listbox_button_release_callback( GtkWidget * WXUNUSED(widget),
if (!g_hasDoubleClicked) return FALSE;
wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() );
event.SetEventObject( listbox );
wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() );
event.SetEventObject( listbox );
wxArrayInt aSelections;
int count = listbox->GetSelections(aSelections);
if ( count > 0 )
{
event.m_commandInt = aSelections[0] ;
event.m_clientData = listbox->GetClientData( event.m_commandInt );
wxString str(listbox->GetString(event.m_commandInt));
if (!str.IsEmpty()) event.m_commandString = str;
}
else
{
event.m_commandInt = -1 ;
event.m_commandString.Empty();
}
wxArrayInt aSelections;
int n, count = listbox->GetSelections(aSelections);
if ( count > 0 )
{
n = aSelections[0];
if ( listbox->HasClientObjectData() )
event.SetClientObject( listbox->GetClientObject(n) );
else if ( listbox->HasClientUntypedData() )
event.SetClientData( listbox->GetClientData(n) );
event.SetString( listbox->GetString(n) );
}
else
{
n = -1;
}
listbox->GetEventHandler()->ProcessEvent( event );
event.m_commandInt = n;
listbox->GetEventHandler()->ProcessEvent( event );
return FALSE;
}
@@ -213,14 +216,18 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox
if (g_blockEventsOnDrag) return;
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
event.SetEventObject( listbox );
wxArrayInt aSelections;
int n, count = listbox->GetSelections(aSelections);
if ( count > 0 )
{
n = aSelections[0];
event.m_clientData = listbox->m_clientData.Item(n);
event.m_commandString = listbox->GetString(n);
if ( listbox->HasClientObjectData() )
event.SetClientObject( listbox->GetClientObject(n) );
else if ( listbox->HasClientUntypedData() )
event.SetClientData( listbox->GetClientData(n) );
event.SetString( listbox->GetString(n) );
}
else
{
@@ -229,8 +236,6 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox
event.m_commandInt = n;
event.SetEventObject( listbox );
listbox->GetEventHandler()->ProcessEvent( event );
}
@@ -317,8 +322,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
for (int i = 0; i < n; i++)
{
m_clientData.Append((wxObject *)NULL);
DoAppend(choices[i]);
#if 0
@@ -431,7 +434,6 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
// remove the old items
wxArrayString deletedLabels;
wxArrayPtrVoid deletedData;
#if wxUSE_CHECKLISTBOX
wxArrayInt deletedChecks;
#endif
@@ -446,9 +448,6 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
wxString str(GET_REAL_LABEL(label->label),*wxConvCurrent);
deletedLabels.Add(str);
// save data
deletedData.Add(m_clientData.Item(n));
#if wxUSE_CHECKLISTBOX
// save check state
if ( m_hasCheckBoxes )
@@ -458,33 +457,28 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
#endif // wxUSE_CHECKLISTBOX
}
// don't delete contents, the data will be reappended soon
m_clientData.Clear();
size_t nDeletedCount = n;
gtk_list_clear_items( m_list, pos, length );
// now append the new items
wxNode *node = m_clientData.Item(pos);
for ( n = 0; n < nItems; n++ )
{
AppendWithoutSorting(items[n]);
m_clientData.Append((wxObject *)NULL);
// make sure we have the correct number of items in this list
m_clientData.Insert(node, (wxObject *)NULL);
}
// and append the old items too
pos += nItems; // now the indices are shifter
pos += nItems; // now the indices are shifted
for ( n = 0; n < nDeletedCount; n++ )
{
AppendWithoutSorting(deletedLabels[n]);
m_clientData.Append((wxObject *)NULL);
if ( m_clientDataItemsType == ClientData_Object )
SetClientObject(n, (wxClientData *)deletedData[n]);
else if ( m_clientDataItemsType == ClientData_Void )
SetClientData(n, deletedData[n]);
// the data is already correct - the indices have been rearranged in
// such manner that we now correspond to the same node as before
#if wxUSE_CHECKLISTBOX
if ( m_hasCheckBoxes )
@@ -617,32 +611,32 @@ void wxListBox::DoSetItems( const wxArrayString& items,
// client data
// ----------------------------------------------------------------------------
void wxListBox::DoSetClientData( int n, void* clientData )
void wxListBox::DoSetItemClientData( int n, void* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
wxNode *node = m_clientData.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetClientData") );
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientData") );
node->SetData( (wxObject*) clientData );
}
void* wxListBox::DoGetClientData( int n ) const
void* wxListBox::DoGetItemClientData( int n ) const
{
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
wxNode *node = m_clientData.Nth( n );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetClientData") );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetItemClientData") );
return node->Data();
}
void wxListBox::DoSetClientObject( int n, wxClientData* clientData )
void wxListBox::DoSetItemClientObject( int n, wxClientData* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
wxNode *node = m_clientData.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetClientObject") );
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientObject") );
wxClientData *cd = (wxClientData*) node->Data();
delete cd;
@@ -650,13 +644,13 @@ void wxListBox::DoSetClientObject( int n, wxClientData* clientData )
node->SetData( (wxObject*) clientData );
}
wxClientData* wxListBox::DoGetClientObject( int n ) const
wxClientData* wxListBox::DoGetItemClientObject( int n ) const
{
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
wxNode *node = m_clientData.Nth( n );
wxCHECK_MSG( node, (wxClientData *)NULL,
wxT("invalid index in wxListBox::DoGetClientObject") );
wxT("invalid index in wxListBox::DoGetItemClientObject") );
return (wxClientData*) node->Data();
}
@@ -667,8 +661,18 @@ void wxListBox::Clear()
gtk_list_clear_items( m_list, 0, Number() );
if ( m_clientDataItemsType == ClientData_Object )
m_clientData.DeleteContents(TRUE);
if ( HasClientObjectData() )
{
// destroy the data (due to Robert's idea of using wxList<wxObject>
// and not wxList<wxClientData> we can't just say
// m_clientList.DeleteContents(TRUE) - this would crash!
wxNode *node = m_clientData.First();
while ( node )
{
delete (wxClientData *)node->Data();
node = node->Next();
}
}
m_clientData.Clear();
if ( m_strings )