diff --git a/lcl/interfaces/gtk3/gtk3procs.pas b/lcl/interfaces/gtk3/gtk3procs.pas index 9b676a0d7b..632db94397 100644 --- a/lcl/interfaces/gtk3/gtk3procs.pas +++ b/lcl/interfaces/gtk3/gtk3procs.pas @@ -291,6 +291,7 @@ function GtkAllocationFromRect(R: TRect): TGtkAllocation; function GdkKeyToLCLKey(AValue: Word): Word; function GdkModifierStateToLCL(AState: TGdkModifierType; const AIsKeyEvent: Boolean): PtrInt; +function GdkModifierStateToShiftState(AState: TGdkModifierType): TShiftState; procedure SetWindowCursor(AWindow: PGdkWindow; ACursor: HCursor; ARecursive: Boolean; ASetDefault: Boolean); @@ -682,6 +683,34 @@ begin Result := Result or MK_CONTROL; end; +function GdkModifierStateToShiftState(AState: TGdkModifierType): TShiftState; +begin + Result := []; + if AState and GDK_BUTTON1_MASK <> 0 then + Include(Result, ssLeft); + + if AState and GDK_BUTTON2_MASK <> 0 then + Include(Result, ssRight); + + if AState and GDK_BUTTON3_MASK <> 0 then + Include(Result, ssMiddle); + + if AState and GDK_BUTTON4_MASK <> 0 then + Include(Result, ssExtra1); + + if AState and GDK_BUTTON5_MASK <> 0 then + Include(Result, ssExtra2); + + if AState and GDK_SHIFT_MASK <> 0 then + Include(Result, ssShift); + + if AState and GDK_CONTROL_MASK <> 0 then + Include(Result, ssCtrl); + + if AState and GDK_META_MASK <> 0 then + Include(Result, ssAlt); +end; + procedure AddCharsetEncoding(CharSet: Byte; CharSetReg, CharSetCod: CharSetStr; ToEnum:boolean=true; CrPart:boolean=false; CcPart:boolean=false); var diff --git a/lcl/interfaces/gtk3/gtk3widgets.pas b/lcl/interfaces/gtk3/gtk3widgets.pas index 4d672beb43..959ddefa44 100644 --- a/lcl/interfaces/gtk3/gtk3widgets.pas +++ b/lcl/interfaces/gtk3/gtk3widgets.pas @@ -1240,6 +1240,11 @@ begin // Result := TGtk3Widget(Data).GtkEventShowHide(Widget, Event); // DebugLn('****** GDK_VISIBILITY_NOTIFY FOR ' + dbgsName(TGtk3Widget(Data).LCLObject)); end; + 31: // GDK_SCROLL + begin + // DebugLn('****** GDK_SCROLL ' + dbgsName(TGtk3Widget(Data).LCLObject)); + Result := TGtk3Widget(Data).GtkEventMouseWheel(Widget, Event); + end; 32: // GDK_WINDOW_STATE begin // DebugLn('****** GDK_WINDOW_STATE FOR ' + dbgsName(TGtk3Widget(Data).LCLObject)); @@ -1790,10 +1795,37 @@ end; function TGtk3Widget.GtkEventMouseWheel(Sender: PGtkWidget; Event: PGdkEvent ): Boolean; cdecl; +var + Msg: TLMMouseEvent; + EventXY: TPoint; begin // gtk3 have ugly bug with scroll-event // https://bugzilla.gnome.org/show_bug.cgi?id=675959 Result := False; + EventXY := Point(TruncToInt(Event^.scroll.x), TruncToInt(Event^.scroll.y)); + FillChar(Msg{%H-},SizeOf(Msg),0); + Msg.Msg := LM_MOUSEWHEEL; + //DebugLn('Scroll ',Format('deltaX %2.2n deltaY %2.2n x %2.2n y %2.2n rootx %2.2n rooty %2.2n', + // [Event^.scroll.delta_x, Event^.scroll.delta_y, Event^.scroll.x, Event^.scroll.y, + // Event^.scroll.x_root, Event^.scroll.y_root])); + if Event^.scroll.direction = GDK_SCROLL_UP then + Msg.WheelDelta := 120 + else + if Event^.scroll.direction = GDK_SCROLL_DOWN then + Msg.WheelDelta := -120 + else + exit; + Msg.X := EventXY.X; + Msg.Y := EventXY.Y; + Msg.State := GdkModifierStateToShiftState(Event^.scroll.state); + Msg.UserData := LCLObject; + Msg.Button := 0; + + NotifyApplicationUserInput(LCLObject, Msg.Msg); + if Widget^.get_parent <> nil then + Event^.motion.send_event := NO_PROPAGATION_TO_PARENT; + if DeliverMessage(Msg, True) <> 0 then + Result := True; end; function TGtk3Widget.IsValidHandle: Boolean;