LCL: GTK2: TTabControl: Cannot use keyboard to switch tab. Issue #31986

git-svn-id: trunk@56131 -
This commit is contained in:
michl 2017-10-18 19:45:04 +00:00
parent 9abb167fde
commit 18f99936c4

View File

@ -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 }