diff --git a/lcl/interfaces/gtk2/gtk2proc.inc b/lcl/interfaces/gtk2/gtk2proc.inc index 2408407568..8ef6d84620 100644 --- a/lcl/interfaces/gtk2/gtk2proc.inc +++ b/lcl/interfaces/gtk2/gtk2proc.inc @@ -2149,6 +2149,28 @@ var // the gtk2 gtkentry handles the return key and emits an activate signal // The LCL does not use that and needs the return key event // => emulate it + + // emulate VK_RETURN on GtkButton. issue #21483 + if GtkWidgetIsA(TargetWidget, gtk_type_button) then + begin + if (gdk_event_get_type(AEvent) = GDK_KEY_RELEASE) and + (VKey = VK_RETURN) then + begin + FillChar(Msg, SizeOf(Msg), 0); + Msg.CharCode := VKey; + if SysKey then + Msg.msg := LM_SYSKEYUP + else + Msg.msg := LM_KEYUP; + Msg.KeyData := CommonKeyData or (Flags shl 16) or $0001 {TODO: repeatcount}; + // do not send next LM_CLICKED. issue #21483 + g_object_set_data(PGObject(TargetWidget),'lcl-button-stop-clicked', TargetWidget); + NotifyApplicationUserInput(TControl(TargetObj), Msg.Msg); + DeliverKeyMessage(TargetObj, Msg); + end; + + end else + if ( GtkWidgetIsA(TargetWidget, gtk_type_entry) or GtkWidgetIsA(TargetWidget, gtk_type_text_view) diff --git a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp index 27fc2a09f2..eac314185a 100644 --- a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp +++ b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp @@ -2280,10 +2280,25 @@ var begin Result := CallBackDefaultReturn; if AInfo^.ChangeLock > 0 then Exit; + + // do not send LM_CLICKED. issue #21483 + if g_object_get_data(PGObject(AWidget),'lcl-button-stop-clicked') = AWidget then + begin + g_object_set_data(PGObject(AWidget),'lcl-button-stop-clicked', nil); + exit; + end; Msg.Msg := LM_CLICKED; Result := DeliverMessage(AInfo^.LCLObject, Msg) = 0; end; +function Gtk2WSButtonPressedEvent(widget: PGtkWidget; event: pgdkEventButton; data: gPointer): GBoolean; cdecl; +begin + Result := CallBackDefaultReturn; + // set to nil data if we pressed return before, + // otherwise LM_CLICKED won't trigger. issue #21483 + g_object_set_data(PGObject(Widget),'lcl-button-stop-clicked', nil); +end; + procedure Gtk2WSButton_SizeAllocate(widget: PGtkWidget; allocation: PGtkAllocation; user_data: gpointer); cdecl; var xthickness, ythickness: gint; @@ -2339,6 +2354,7 @@ class procedure TGtk2WSButton.SetCallbacks(const AGtkWidget: PGtkWidget; begin TGtk2WSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject)); SignalConnect(AWidgetInfo^.CoreWidget, 'clicked', @Gtk2WSButton_Clicked, AWidgetInfo); + SignalConnect(AWidgetInfo^.CoreWidget, 'button-press-event', @Gtk2WSButtonPressedEvent, AWidgetInfo); SignalConnect(AWidgetInfo^.CoreWidget, 'size-allocate', @Gtk2WSButton_SizeAllocate, AWidgetInfo); end;