Make wxComboBox spit out a bit fewer surplis
events when holding down the mouse button. Enable key based navigation through notebook tabs as in the native control with Left and right keys. Support for vetoing. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29668 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -54,18 +54,18 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi
|
|||||||
|
|
||||||
int curSelection = combo->GetSelection();
|
int curSelection = combo->GetSelection();
|
||||||
|
|
||||||
if (combo->m_prevSelection != curSelection)
|
if (combo->m_prevSelection == curSelection) return;
|
||||||
{
|
|
||||||
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
|
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
|
||||||
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
|
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
|
||||||
}
|
|
||||||
combo->m_prevSelection = curSelection;
|
combo->m_prevSelection = curSelection;
|
||||||
|
|
||||||
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
|
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
|
||||||
event.SetInt( curSelection );
|
event.SetInt( curSelection );
|
||||||
event.SetString( combo->GetStringSelection() );
|
event.SetString( combo->GetStringSelection() );
|
||||||
event.SetEventObject( combo );
|
event.SetEventObject( combo );
|
||||||
|
|
||||||
combo->GetEventHandler()->ProcessEvent( event );
|
combo->GetEventHandler()->ProcessEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -185,32 +185,60 @@ gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
|
|||||||
// "key_press_event"
|
// "key_press_event"
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *win )
|
static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook )
|
||||||
{
|
{
|
||||||
if (g_isIdle)
|
if (g_isIdle)
|
||||||
wxapp_install_idle_handler();
|
wxapp_install_idle_handler();
|
||||||
|
|
||||||
if (!win->m_hasVMT) return FALSE;
|
if (!notebook->m_hasVMT) return FALSE;
|
||||||
if (g_blockEventsOnDrag) return FALSE;
|
if (g_blockEventsOnDrag) return FALSE;
|
||||||
|
|
||||||
|
/* win is a control: tab can be propagated up */
|
||||||
|
if ((gdk_event->keyval == GDK_Left) || (gdk_event->keyval == GDK_Right))
|
||||||
|
{
|
||||||
|
int page;
|
||||||
|
int nMax = notebook->GetPageCount();
|
||||||
|
if ( nMax-- ) // decrement it to get the last valid index
|
||||||
|
{
|
||||||
|
int nSel = notebook->GetSelection();
|
||||||
|
|
||||||
|
// change selection wrapping if it becomes invalid
|
||||||
|
page = (gdk_event->keyval != GDK_Left) ? nSel == nMax ? 0
|
||||||
|
: nSel + 1
|
||||||
|
: nSel == 0 ? nMax
|
||||||
|
: nSel - 1;
|
||||||
|
}
|
||||||
|
else // notebook is empty, no next page
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// m_selection = page;
|
||||||
|
gtk_notebook_set_page( GTK_NOTEBOOK(widget), page );
|
||||||
|
|
||||||
|
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* win is a control: tab can be propagated up */
|
/* win is a control: tab can be propagated up */
|
||||||
if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
|
if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
|
||||||
{
|
{
|
||||||
int sel = win->GetSelection();
|
int sel = notebook->GetSelection();
|
||||||
if (sel == -1)
|
if (sel == -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
wxGtkNotebookPage *nb_page = win->GetNotebookPage(sel);
|
wxGtkNotebookPage *nb_page = notebook->GetNotebookPage(sel);
|
||||||
wxCHECK_MSG( nb_page, FALSE, _T("invalid selection in wxNotebook") );
|
wxCHECK_MSG( nb_page, FALSE, _T("invalid selection in wxNotebook") );
|
||||||
|
|
||||||
wxNavigationKeyEvent event;
|
wxNavigationKeyEvent event;
|
||||||
event.SetEventObject( win );
|
event.SetEventObject( notebook );
|
||||||
/* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
|
/* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
|
||||||
event.SetDirection( (gdk_event->keyval == GDK_Tab) );
|
event.SetDirection( (gdk_event->keyval == GDK_Tab) );
|
||||||
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
|
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
|
||||||
event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
|
event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ||
|
||||||
event.SetCurrentFocus( win );
|
(gdk_event->keyval == GDK_Left) || (gdk_event->keyval == GDK_Right) );
|
||||||
|
event.SetCurrentFocus( notebook );
|
||||||
|
|
||||||
wxNotebookPage *client = win->GetPage(sel);
|
wxNotebookPage *client = notebook->GetPage(sel);
|
||||||
if ( !client->GetEventHandler()->ProcessEvent( event ) )
|
if ( !client->GetEventHandler()->ProcessEvent( event ) )
|
||||||
{
|
{
|
||||||
client->SetFocus();
|
client->SetFocus();
|
||||||
|
@@ -54,18 +54,18 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi
|
|||||||
|
|
||||||
int curSelection = combo->GetSelection();
|
int curSelection = combo->GetSelection();
|
||||||
|
|
||||||
if (combo->m_prevSelection != curSelection)
|
if (combo->m_prevSelection == curSelection) return;
|
||||||
{
|
|
||||||
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
|
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
|
||||||
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
|
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
|
||||||
}
|
|
||||||
combo->m_prevSelection = curSelection;
|
combo->m_prevSelection = curSelection;
|
||||||
|
|
||||||
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
|
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
|
||||||
event.SetInt( curSelection );
|
event.SetInt( curSelection );
|
||||||
event.SetString( combo->GetStringSelection() );
|
event.SetString( combo->GetStringSelection() );
|
||||||
event.SetEventObject( combo );
|
event.SetEventObject( combo );
|
||||||
|
|
||||||
combo->GetEventHandler()->ProcessEvent( event );
|
combo->GetEventHandler()->ProcessEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -185,32 +185,60 @@ gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
|
|||||||
// "key_press_event"
|
// "key_press_event"
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *win )
|
static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook )
|
||||||
{
|
{
|
||||||
if (g_isIdle)
|
if (g_isIdle)
|
||||||
wxapp_install_idle_handler();
|
wxapp_install_idle_handler();
|
||||||
|
|
||||||
if (!win->m_hasVMT) return FALSE;
|
if (!notebook->m_hasVMT) return FALSE;
|
||||||
if (g_blockEventsOnDrag) return FALSE;
|
if (g_blockEventsOnDrag) return FALSE;
|
||||||
|
|
||||||
|
/* win is a control: tab can be propagated up */
|
||||||
|
if ((gdk_event->keyval == GDK_Left) || (gdk_event->keyval == GDK_Right))
|
||||||
|
{
|
||||||
|
int page;
|
||||||
|
int nMax = notebook->GetPageCount();
|
||||||
|
if ( nMax-- ) // decrement it to get the last valid index
|
||||||
|
{
|
||||||
|
int nSel = notebook->GetSelection();
|
||||||
|
|
||||||
|
// change selection wrapping if it becomes invalid
|
||||||
|
page = (gdk_event->keyval != GDK_Left) ? nSel == nMax ? 0
|
||||||
|
: nSel + 1
|
||||||
|
: nSel == 0 ? nMax
|
||||||
|
: nSel - 1;
|
||||||
|
}
|
||||||
|
else // notebook is empty, no next page
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// m_selection = page;
|
||||||
|
gtk_notebook_set_page( GTK_NOTEBOOK(widget), page );
|
||||||
|
|
||||||
|
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* win is a control: tab can be propagated up */
|
/* win is a control: tab can be propagated up */
|
||||||
if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
|
if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
|
||||||
{
|
{
|
||||||
int sel = win->GetSelection();
|
int sel = notebook->GetSelection();
|
||||||
if (sel == -1)
|
if (sel == -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
wxGtkNotebookPage *nb_page = win->GetNotebookPage(sel);
|
wxGtkNotebookPage *nb_page = notebook->GetNotebookPage(sel);
|
||||||
wxCHECK_MSG( nb_page, FALSE, _T("invalid selection in wxNotebook") );
|
wxCHECK_MSG( nb_page, FALSE, _T("invalid selection in wxNotebook") );
|
||||||
|
|
||||||
wxNavigationKeyEvent event;
|
wxNavigationKeyEvent event;
|
||||||
event.SetEventObject( win );
|
event.SetEventObject( notebook );
|
||||||
/* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
|
/* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
|
||||||
event.SetDirection( (gdk_event->keyval == GDK_Tab) );
|
event.SetDirection( (gdk_event->keyval == GDK_Tab) );
|
||||||
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
|
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
|
||||||
event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
|
event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ||
|
||||||
event.SetCurrentFocus( win );
|
(gdk_event->keyval == GDK_Left) || (gdk_event->keyval == GDK_Right) );
|
||||||
|
event.SetCurrentFocus( notebook );
|
||||||
|
|
||||||
wxNotebookPage *client = win->GetPage(sel);
|
wxNotebookPage *client = notebook->GetPage(sel);
|
||||||
if ( !client->GetEventHandler()->ProcessEvent( event ) )
|
if ( !client->GetEventHandler()->ProcessEvent( event ) )
|
||||||
{
|
{
|
||||||
client->SetFocus();
|
client->SetFocus();
|
||||||
|
Reference in New Issue
Block a user