diff --git a/lcl/interfaces/gtk2/gtk2pagecontrol.inc b/lcl/interfaces/gtk2/gtk2pagecontrol.inc index 626f83666a..605dca82fc 100644 --- a/lcl/interfaces/gtk2/gtk2pagecontrol.inc +++ b/lcl/interfaces/gtk2/gtk2pagecontrol.inc @@ -21,10 +21,12 @@ const type - GtkNotebookPressEventProc = function (widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl; - + GtkNotebookButtonPressEventProc = function (widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl; + GtkNotebookKeyPressEventProc = function (widget:PGtkWidget; event:PGdkEventKey):gboolean; cdecl; + var - OldNoteBookButtonPress: GtkNotebookPressEventProc = nil; + OldNoteBookButtonPress: GtkNotebookButtonPressEventProc = nil; + OldNoteBookKeyPress: GtkNotebookKeyPressEventProc = nil; // this was created as a workaround of a tnotebook eating rightclick of custom controls function Notebook_Button_Press(widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl; @@ -35,14 +37,29 @@ begin Result := OldNoteBookButtonPress(widget, event); end; +// Allow switching tabs per key. Issue #31986 +function Notebook_Key_Press(widget:PGtkWidget; event:PGdkEventKey):gboolean; cdecl; +begin + Result := True; + if OldNoteBookKeyPress = nil then exit; + case event^.hardware_keycode of + 113: gtk_notebook_prev_page(PGtkNotebook(widget)); + 114: gtk_notebook_next_page(PGtkNotebook(widget)); + else + Result := OldNoteBookKeyPress(widget, event); + end; +end; + procedure HookNoteBookClass; var WidgetClass: PGtkWidgetClass; begin WidgetClass := GTK_WIDGET_CLASS(gtk_type_class(gtk_notebook_get_type)); - OldNoteBookButtonPress := GtkNotebookPressEventProc(WidgetClass^.button_press_event); + OldNoteBookButtonPress := GtkNotebookButtonPressEventProc(WidgetClass^.button_press_event); WidgetClass^.button_press_event := @Notebook_Button_Press; + OldNoteBookKeyPress := GtkNotebookKeyPressEventProc(WidgetClass^.key_press_event); + WidgetClass^.key_press_event := @Notebook_Key_Press; end; { TGtk2WSCustomTabControl }