another attempt to improve combobox behaviour

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1920 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-03-12 21:36:27 +00:00
parent 8a85884a0f
commit 7cf8cb48f8
2 changed files with 82 additions and 34 deletions

View File

@@ -314,14 +314,13 @@ int wxComboBox::FindString( const wxString &item )
{ {
GtkBin *bin = GTK_BIN( child->data ); GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child ); GtkLabel *label = GTK_LABEL( bin->child );
if (item == label->label) return count; if (item == label->label)
return count;
count++; count++;
child = child->next; child = child->next;
} }
wxFAIL_MSG( "wxComboBox: string not found" ); return wxNOT_FOUND;
return -1;
} }
int wxComboBox::GetSelection() const int wxComboBox::GetSelection() const
@@ -354,17 +353,20 @@ wxString wxComboBox::GetString( int n ) const
GtkWidget *list = GTK_COMBO(m_widget)->list; GtkWidget *list = GTK_COMBO(m_widget)->list;
wxString str;
GList *child = g_list_nth( GTK_LIST(list)->children, n ); GList *child = g_list_nth( GTK_LIST(list)->children, n );
if (child) if (child)
{ {
GtkBin *bin = GTK_BIN( child->data ); GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child ); GtkLabel *label = GTK_LABEL( bin->child );
return label->label; str = label->label;
}
else
{
wxFAIL_MSG( "wxComboBox: wrong index" );
} }
wxFAIL_MSG( "wxComboBox: wrong index" ); return str;
return "";
} }
wxString wxComboBox::GetStringSelection() const wxString wxComboBox::GetStringSelection() const
@@ -529,18 +531,40 @@ void wxComboBox::SetEditable( bool editable )
void wxComboBox::OnChar( wxKeyEvent &event ) void wxComboBox::OnChar( wxKeyEvent &event )
{ {
// make Enter generate "selected" event if there is only one item in the if ( event.KeyCode() == WXK_RETURN )
// combobox - without it, it's impossible to select it at all!
if ( (event.KeyCode() == WXK_RETURN) && (Number() == 0) )
{ {
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() ); wxString value = GetValue();
event.SetInt( 0 );
event.SetString( copystring(GetValue()) );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
delete [] event.GetString(); if ( Number() == 0 )
{
// make Enter generate "selected" event if there is only one item
// in the combobox - without it, it's impossible to select it at
// all!
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( 0 );
event.SetString( (char *)value.c_str() );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
else
{
// add the item to the list if it's not there yet
if ( FindString(value) == wxNOT_FOUND )
{
Append(value);
// and generate the selected event for it
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( Number() - 1 );
event.SetString( (char *)value.c_str() );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
//else: do nothing, this will open the listbox
}
} }
event.Skip();
} }
void wxComboBox::OnSize( wxSizeEvent &event ) void wxComboBox::OnSize( wxSizeEvent &event )

View File

@@ -314,14 +314,13 @@ int wxComboBox::FindString( const wxString &item )
{ {
GtkBin *bin = GTK_BIN( child->data ); GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child ); GtkLabel *label = GTK_LABEL( bin->child );
if (item == label->label) return count; if (item == label->label)
return count;
count++; count++;
child = child->next; child = child->next;
} }
wxFAIL_MSG( "wxComboBox: string not found" ); return wxNOT_FOUND;
return -1;
} }
int wxComboBox::GetSelection() const int wxComboBox::GetSelection() const
@@ -354,17 +353,20 @@ wxString wxComboBox::GetString( int n ) const
GtkWidget *list = GTK_COMBO(m_widget)->list; GtkWidget *list = GTK_COMBO(m_widget)->list;
wxString str;
GList *child = g_list_nth( GTK_LIST(list)->children, n ); GList *child = g_list_nth( GTK_LIST(list)->children, n );
if (child) if (child)
{ {
GtkBin *bin = GTK_BIN( child->data ); GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child ); GtkLabel *label = GTK_LABEL( bin->child );
return label->label; str = label->label;
}
else
{
wxFAIL_MSG( "wxComboBox: wrong index" );
} }
wxFAIL_MSG( "wxComboBox: wrong index" ); return str;
return "";
} }
wxString wxComboBox::GetStringSelection() const wxString wxComboBox::GetStringSelection() const
@@ -529,18 +531,40 @@ void wxComboBox::SetEditable( bool editable )
void wxComboBox::OnChar( wxKeyEvent &event ) void wxComboBox::OnChar( wxKeyEvent &event )
{ {
// make Enter generate "selected" event if there is only one item in the if ( event.KeyCode() == WXK_RETURN )
// combobox - without it, it's impossible to select it at all!
if ( (event.KeyCode() == WXK_RETURN) && (Number() == 0) )
{ {
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() ); wxString value = GetValue();
event.SetInt( 0 );
event.SetString( copystring(GetValue()) );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
delete [] event.GetString(); if ( Number() == 0 )
{
// make Enter generate "selected" event if there is only one item
// in the combobox - without it, it's impossible to select it at
// all!
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( 0 );
event.SetString( (char *)value.c_str() );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
else
{
// add the item to the list if it's not there yet
if ( FindString(value) == wxNOT_FOUND )
{
Append(value);
// and generate the selected event for it
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( Number() - 1 );
event.SetString( (char *)value.c_str() );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
//else: do nothing, this will open the listbox
}
} }
event.Skip();
} }
void wxComboBox::OnSize( wxSizeEvent &event ) void wxComboBox::OnSize( wxSizeEvent &event )