From 159b66c02a8f1c724d1af3c768ad5d90f4c8a0e2 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 6 Aug 2001 21:06:13 +0000 Subject: [PATCH] Applied patch for wxComboBox and wxListBox to prevent "hanging" in single selection mode. Also removed call to AddPendingEvent and changed wxLB_EXTENDED mode so that no changes to the listbox go unnoticed. I do wonder what the difference between multiple and extended list boxes actually are. Not suer what I changed in the other files. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11310 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/combobox.h | 1 + include/wx/gtk/listbox.h | 1 + include/wx/gtk1/combobox.h | 1 + include/wx/gtk1/listbox.h | 1 + samples/dialogs/dialogs.cpp | 5 +++++ src/common/appcmn.cpp | 3 +++ src/gtk/combobox.cpp | 17 ++++++++++++++++- src/gtk/listbox.cpp | 31 +++++++++++++++++++++++++------ src/gtk1/combobox.cpp | 17 ++++++++++++++++- src/gtk1/listbox.cpp | 31 +++++++++++++++++++++++++------ 10 files changed, 94 insertions(+), 14 deletions(-) diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index 8e2b81b6b1..e7be38f91b 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -114,6 +114,7 @@ public: bool m_alreadySent; wxList m_clientDataList; wxList m_clientObjectList; + int m_prevSelection; void DisableEvents(); void EnableEvents(); diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 20eb87cac5..da536fe9c2 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -96,6 +96,7 @@ public: bool m_hasCheckBoxes; #endif // wxUSE_CHECKLISTBOX + int m_prevSelection; protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk1/combobox.h b/include/wx/gtk1/combobox.h index 8e2b81b6b1..e7be38f91b 100644 --- a/include/wx/gtk1/combobox.h +++ b/include/wx/gtk1/combobox.h @@ -114,6 +114,7 @@ public: bool m_alreadySent; wxList m_clientDataList; wxList m_clientObjectList; + int m_prevSelection; void DisableEvents(); void EnableEvents(); diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index 20eb87cac5..da536fe9c2 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -96,6 +96,7 @@ public: bool m_hasCheckBoxes; #endif // wxUSE_CHECKLISTBOX + int m_prevSelection; protected: virtual wxSize DoGetBestSize() const; diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 08d8abd3c7..84ea95b342 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -399,6 +399,8 @@ void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) { +// wxFAIL_MSG( "Test assert" ); + wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0); if (dialog.ShowModal() == wxID_OK) @@ -420,6 +422,9 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) // one will use it by default void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) { + wxOnAssert( "Test assert.txt", 20, "Test" ); + return; + static wxString s_extDef; wxString path = wxFileSelector( _T("Select the file to load"), diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 49dfb98eed..86a63a1090 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -395,6 +395,9 @@ void ShowAssertDialog(const wxChar *szFile, int nLine, const wxChar *szMsg) // this function is called when an assert fails void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg) { + wxMessageBox( "ttest", "test", wxOK ); + return; + if ( !wxTheApp ) { // by default, show the assert dialog box - we can't customize this diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 492a1d6a02..26e78469de 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -57,8 +57,18 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) combo->m_alreadySent = TRUE; + int curSelection = combo->GetSelection(); + + if (combo->m_prevSelection != curSelection) + { + GtkWidget *list = GTK_COMBO(combo->m_widget)->list; + gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); + } + + combo->m_prevSelection = curSelection; + wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); - event.SetInt( combo->GetSelection() ); + event.SetInt( curSelection ); event.SetString( combo->GetStringSelection() ); event.SetEventObject( combo ); @@ -102,6 +112,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, m_alreadySent = FALSE; m_needParent = TRUE; m_acceptsFocus = TRUE; + m_prevSelection = 0; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) @@ -121,6 +132,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, GtkWidget *list = GTK_COMBO(m_widget)->list; + gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE ); + for (int i = 0; i < n; i++) { /* don't send first event, which GTK sends aways when @@ -433,7 +446,9 @@ void wxComboBox::SetSelection( int n ) DisableEvents(); GtkWidget *list = GTK_COMBO(m_widget)->list; + gtk_list_unselect_item( GTK_LIST(list), m_prevSelection ); gtk_list_select_item( GTK_LIST(list), n ); + m_prevSelection = n; EnableEvents(); } diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index aade5967cf..fa4b4bcdc7 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -261,7 +261,7 @@ static void gtk_listitem_deselect_callback( GtkWidget *widget, wxListBox *listbo gtk_listitem_select_cb( widget, listbox, FALSE ); } -static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *listbox, bool is_selection ) +static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool is_selection ) { if (g_isIdle) wxapp_install_idle_handler(); @@ -270,7 +270,19 @@ static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *list wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); - event.SetExtraLong( (long) is_selection ); +// MSW doesn't do that either +// event.SetExtraLong( (long) is_selection ); + + + if ((listbox->GetWindowStyleFlag() & wxLB_SINGLE) != 0) + { + int sel = listbox->GtkGetIndex( widget ); + + if (listbox->m_prevSelection != sel) + gtk_list_unselect_item( listbox->m_list, listbox->m_prevSelection ); + + listbox->m_prevSelection = sel; + } wxArrayInt aSelections; int n, count = listbox->GetSelections(aSelections); @@ -290,8 +302,9 @@ static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *list event.m_commandInt = n; - listbox->GetEventHandler()->AddPendingEvent( event ); -// listbox->GetEventHandler()->ProcessEvent( event ); +// No longer required with new code in wxLB_SINGLE +// listbox->GetEventHandler()->AddPendingEvent( event ); + listbox->GetEventHandler()->ProcessEvent( event ); } //----------------------------------------------------------------------------- @@ -320,6 +333,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, { m_needParent = TRUE; m_acceptsFocus = TRUE; + m_prevSelection = 0; // or -1 ?? if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) @@ -355,7 +369,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, { // if style was 0 set single mode m_windowStyle |= wxLB_SINGLE; - mode = GTK_SELECTION_BROWSE; + mode = GTK_SELECTION_MULTIPLE; } gtk_list_set_selection_mode( GTK_LIST(m_list), mode ); @@ -535,7 +549,7 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - if (HasFlag(wxLB_MULTIPLE)) + if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) gtk_signal_connect( GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this ); @@ -844,7 +858,12 @@ void wxListBox::SetSelection( int n, bool select ) GtkDisableEvents(); if (select) + { + if ((m_windowStyle & wxLB_SINGLE) != 0) + gtk_list_unselect_item( m_list, m_prevSelection ); gtk_list_select_item( m_list, n ); + m_prevSelection = n; + } else gtk_list_unselect_item( m_list, n ); diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 492a1d6a02..26e78469de 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -57,8 +57,18 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) combo->m_alreadySent = TRUE; + int curSelection = combo->GetSelection(); + + if (combo->m_prevSelection != curSelection) + { + GtkWidget *list = GTK_COMBO(combo->m_widget)->list; + gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); + } + + combo->m_prevSelection = curSelection; + wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); - event.SetInt( combo->GetSelection() ); + event.SetInt( curSelection ); event.SetString( combo->GetStringSelection() ); event.SetEventObject( combo ); @@ -102,6 +112,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, m_alreadySent = FALSE; m_needParent = TRUE; m_acceptsFocus = TRUE; + m_prevSelection = 0; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) @@ -121,6 +132,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, GtkWidget *list = GTK_COMBO(m_widget)->list; + gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE ); + for (int i = 0; i < n; i++) { /* don't send first event, which GTK sends aways when @@ -433,7 +446,9 @@ void wxComboBox::SetSelection( int n ) DisableEvents(); GtkWidget *list = GTK_COMBO(m_widget)->list; + gtk_list_unselect_item( GTK_LIST(list), m_prevSelection ); gtk_list_select_item( GTK_LIST(list), n ); + m_prevSelection = n; EnableEvents(); } diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index aade5967cf..fa4b4bcdc7 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -261,7 +261,7 @@ static void gtk_listitem_deselect_callback( GtkWidget *widget, wxListBox *listbo gtk_listitem_select_cb( widget, listbox, FALSE ); } -static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *listbox, bool is_selection ) +static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool is_selection ) { if (g_isIdle) wxapp_install_idle_handler(); @@ -270,7 +270,19 @@ static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *list wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); - event.SetExtraLong( (long) is_selection ); +// MSW doesn't do that either +// event.SetExtraLong( (long) is_selection ); + + + if ((listbox->GetWindowStyleFlag() & wxLB_SINGLE) != 0) + { + int sel = listbox->GtkGetIndex( widget ); + + if (listbox->m_prevSelection != sel) + gtk_list_unselect_item( listbox->m_list, listbox->m_prevSelection ); + + listbox->m_prevSelection = sel; + } wxArrayInt aSelections; int n, count = listbox->GetSelections(aSelections); @@ -290,8 +302,9 @@ static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *list event.m_commandInt = n; - listbox->GetEventHandler()->AddPendingEvent( event ); -// listbox->GetEventHandler()->ProcessEvent( event ); +// No longer required with new code in wxLB_SINGLE +// listbox->GetEventHandler()->AddPendingEvent( event ); + listbox->GetEventHandler()->ProcessEvent( event ); } //----------------------------------------------------------------------------- @@ -320,6 +333,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, { m_needParent = TRUE; m_acceptsFocus = TRUE; + m_prevSelection = 0; // or -1 ?? if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) @@ -355,7 +369,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, { // if style was 0 set single mode m_windowStyle |= wxLB_SINGLE; - mode = GTK_SELECTION_BROWSE; + mode = GTK_SELECTION_MULTIPLE; } gtk_list_set_selection_mode( GTK_LIST(m_list), mode ); @@ -535,7 +549,7 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - if (HasFlag(wxLB_MULTIPLE)) + if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) gtk_signal_connect( GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this ); @@ -844,7 +858,12 @@ void wxListBox::SetSelection( int n, bool select ) GtkDisableEvents(); if (select) + { + if ((m_windowStyle & wxLB_SINGLE) != 0) + gtk_list_unselect_item( m_list, m_prevSelection ); gtk_list_select_item( m_list, n ); + m_prevSelection = n; + } else gtk_list_unselect_item( m_list, n ); -- 2.45.2