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
This commit is contained in:
@@ -114,6 +114,7 @@ public:
|
|||||||
bool m_alreadySent;
|
bool m_alreadySent;
|
||||||
wxList m_clientDataList;
|
wxList m_clientDataList;
|
||||||
wxList m_clientObjectList;
|
wxList m_clientObjectList;
|
||||||
|
int m_prevSelection;
|
||||||
|
|
||||||
void DisableEvents();
|
void DisableEvents();
|
||||||
void EnableEvents();
|
void EnableEvents();
|
||||||
|
@@ -96,6 +96,7 @@ public:
|
|||||||
bool m_hasCheckBoxes;
|
bool m_hasCheckBoxes;
|
||||||
#endif // wxUSE_CHECKLISTBOX
|
#endif // wxUSE_CHECKLISTBOX
|
||||||
|
|
||||||
|
int m_prevSelection;
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
|
@@ -114,6 +114,7 @@ public:
|
|||||||
bool m_alreadySent;
|
bool m_alreadySent;
|
||||||
wxList m_clientDataList;
|
wxList m_clientDataList;
|
||||||
wxList m_clientObjectList;
|
wxList m_clientObjectList;
|
||||||
|
int m_prevSelection;
|
||||||
|
|
||||||
void DisableEvents();
|
void DisableEvents();
|
||||||
void EnableEvents();
|
void EnableEvents();
|
||||||
|
@@ -96,6 +96,7 @@ public:
|
|||||||
bool m_hasCheckBoxes;
|
bool m_hasCheckBoxes;
|
||||||
#endif // wxUSE_CHECKLISTBOX
|
#endif // wxUSE_CHECKLISTBOX
|
||||||
|
|
||||||
|
int m_prevSelection;
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
|
@@ -399,6 +399,8 @@ void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
|
|||||||
|
|
||||||
void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
|
// wxFAIL_MSG( "Test assert" );
|
||||||
|
|
||||||
wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
|
wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
|
||||||
|
|
||||||
if (dialog.ShowModal() == wxID_OK)
|
if (dialog.ShowModal() == wxID_OK)
|
||||||
@@ -420,6 +422,9 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
|||||||
// one will use it by default
|
// one will use it by default
|
||||||
void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
|
wxOnAssert( "Test assert.txt", 20, "Test" );
|
||||||
|
return;
|
||||||
|
|
||||||
static wxString s_extDef;
|
static wxString s_extDef;
|
||||||
wxString path = wxFileSelector(
|
wxString path = wxFileSelector(
|
||||||
_T("Select the file to load"),
|
_T("Select the file to load"),
|
||||||
|
@@ -395,6 +395,9 @@ void ShowAssertDialog(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
|||||||
// this function is called when an assert fails
|
// this function is called when an assert fails
|
||||||
void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg)
|
||||||
{
|
{
|
||||||
|
wxMessageBox( "ttest", "test", wxOK );
|
||||||
|
return;
|
||||||
|
|
||||||
if ( !wxTheApp )
|
if ( !wxTheApp )
|
||||||
{
|
{
|
||||||
// by default, show the assert dialog box - we can't customize this
|
// by default, show the assert dialog box - we can't customize this
|
||||||
|
@@ -57,8 +57,18 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
|
|||||||
|
|
||||||
combo->m_alreadySent = TRUE;
|
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() );
|
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
|
||||||
event.SetInt( combo->GetSelection() );
|
event.SetInt( curSelection );
|
||||||
event.SetString( combo->GetStringSelection() );
|
event.SetString( combo->GetStringSelection() );
|
||||||
event.SetEventObject( combo );
|
event.SetEventObject( combo );
|
||||||
|
|
||||||
@@ -102,6 +112,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
|
|||||||
m_alreadySent = FALSE;
|
m_alreadySent = FALSE;
|
||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_acceptsFocus = TRUE;
|
m_acceptsFocus = TRUE;
|
||||||
|
m_prevSelection = 0;
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
!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;
|
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++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
/* don't send first event, which GTK sends aways when
|
/* don't send first event, which GTK sends aways when
|
||||||
@@ -433,7 +446,9 @@ void wxComboBox::SetSelection( int n )
|
|||||||
DisableEvents();
|
DisableEvents();
|
||||||
|
|
||||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||||
|
gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
|
||||||
gtk_list_select_item( GTK_LIST(list), n );
|
gtk_list_select_item( GTK_LIST(list), n );
|
||||||
|
m_prevSelection = n;
|
||||||
|
|
||||||
EnableEvents();
|
EnableEvents();
|
||||||
}
|
}
|
||||||
|
@@ -261,7 +261,7 @@ static void gtk_listitem_deselect_callback( GtkWidget *widget, wxListBox *listbo
|
|||||||
gtk_listitem_select_cb( widget, listbox, FALSE );
|
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();
|
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() );
|
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
|
||||||
event.SetEventObject( listbox );
|
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;
|
wxArrayInt aSelections;
|
||||||
int n, count = listbox->GetSelections(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;
|
event.m_commandInt = n;
|
||||||
|
|
||||||
listbox->GetEventHandler()->AddPendingEvent( event );
|
// No longer required with new code in wxLB_SINGLE
|
||||||
// listbox->GetEventHandler()->ProcessEvent( event );
|
// listbox->GetEventHandler()->AddPendingEvent( event );
|
||||||
|
listbox->GetEventHandler()->ProcessEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -320,6 +333,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
|
|||||||
{
|
{
|
||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_acceptsFocus = TRUE;
|
m_acceptsFocus = TRUE;
|
||||||
|
m_prevSelection = 0; // or -1 ??
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
!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
|
// if style was 0 set single mode
|
||||||
m_windowStyle |= wxLB_SINGLE;
|
m_windowStyle |= wxLB_SINGLE;
|
||||||
mode = GTK_SELECTION_BROWSE;
|
mode = GTK_SELECTION_MULTIPLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_list_set_selection_mode( GTK_LIST(m_list), mode );
|
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_connect( GTK_OBJECT(list_item), "select",
|
||||||
GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
|
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_connect( GTK_OBJECT(list_item), "deselect",
|
||||||
GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this );
|
GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this );
|
||||||
|
|
||||||
@@ -844,7 +858,12 @@ void wxListBox::SetSelection( int n, bool select )
|
|||||||
GtkDisableEvents();
|
GtkDisableEvents();
|
||||||
|
|
||||||
if (select)
|
if (select)
|
||||||
|
{
|
||||||
|
if ((m_windowStyle & wxLB_SINGLE) != 0)
|
||||||
|
gtk_list_unselect_item( m_list, m_prevSelection );
|
||||||
gtk_list_select_item( m_list, n );
|
gtk_list_select_item( m_list, n );
|
||||||
|
m_prevSelection = n;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
gtk_list_unselect_item( m_list, n );
|
gtk_list_unselect_item( m_list, n );
|
||||||
|
|
||||||
|
@@ -57,8 +57,18 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
|
|||||||
|
|
||||||
combo->m_alreadySent = TRUE;
|
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() );
|
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
|
||||||
event.SetInt( combo->GetSelection() );
|
event.SetInt( curSelection );
|
||||||
event.SetString( combo->GetStringSelection() );
|
event.SetString( combo->GetStringSelection() );
|
||||||
event.SetEventObject( combo );
|
event.SetEventObject( combo );
|
||||||
|
|
||||||
@@ -102,6 +112,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
|
|||||||
m_alreadySent = FALSE;
|
m_alreadySent = FALSE;
|
||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_acceptsFocus = TRUE;
|
m_acceptsFocus = TRUE;
|
||||||
|
m_prevSelection = 0;
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
!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;
|
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++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
/* don't send first event, which GTK sends aways when
|
/* don't send first event, which GTK sends aways when
|
||||||
@@ -433,7 +446,9 @@ void wxComboBox::SetSelection( int n )
|
|||||||
DisableEvents();
|
DisableEvents();
|
||||||
|
|
||||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||||
|
gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
|
||||||
gtk_list_select_item( GTK_LIST(list), n );
|
gtk_list_select_item( GTK_LIST(list), n );
|
||||||
|
m_prevSelection = n;
|
||||||
|
|
||||||
EnableEvents();
|
EnableEvents();
|
||||||
}
|
}
|
||||||
|
@@ -261,7 +261,7 @@ static void gtk_listitem_deselect_callback( GtkWidget *widget, wxListBox *listbo
|
|||||||
gtk_listitem_select_cb( widget, listbox, FALSE );
|
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();
|
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() );
|
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
|
||||||
event.SetEventObject( listbox );
|
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;
|
wxArrayInt aSelections;
|
||||||
int n, count = listbox->GetSelections(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;
|
event.m_commandInt = n;
|
||||||
|
|
||||||
listbox->GetEventHandler()->AddPendingEvent( event );
|
// No longer required with new code in wxLB_SINGLE
|
||||||
// listbox->GetEventHandler()->ProcessEvent( event );
|
// listbox->GetEventHandler()->AddPendingEvent( event );
|
||||||
|
listbox->GetEventHandler()->ProcessEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -320,6 +333,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
|
|||||||
{
|
{
|
||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_acceptsFocus = TRUE;
|
m_acceptsFocus = TRUE;
|
||||||
|
m_prevSelection = 0; // or -1 ??
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
!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
|
// if style was 0 set single mode
|
||||||
m_windowStyle |= wxLB_SINGLE;
|
m_windowStyle |= wxLB_SINGLE;
|
||||||
mode = GTK_SELECTION_BROWSE;
|
mode = GTK_SELECTION_MULTIPLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_list_set_selection_mode( GTK_LIST(m_list), mode );
|
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_connect( GTK_OBJECT(list_item), "select",
|
||||||
GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
|
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_connect( GTK_OBJECT(list_item), "deselect",
|
||||||
GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this );
|
GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this );
|
||||||
|
|
||||||
@@ -844,7 +858,12 @@ void wxListBox::SetSelection( int n, bool select )
|
|||||||
GtkDisableEvents();
|
GtkDisableEvents();
|
||||||
|
|
||||||
if (select)
|
if (select)
|
||||||
|
{
|
||||||
|
if ((m_windowStyle & wxLB_SINGLE) != 0)
|
||||||
|
gtk_list_unselect_item( m_list, m_prevSelection );
|
||||||
gtk_list_select_item( m_list, n );
|
gtk_list_select_item( m_list, n );
|
||||||
|
m_prevSelection = n;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
gtk_list_unselect_item( m_list, n );
|
gtk_list_unselect_item( m_list, n );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user