mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 17:00:30 +02:00
gtk, gtk2: subtract scroll offset when we report mouse event to LCL (bug #0013744)
git-svn-id: trunk@20180 -
This commit is contained in:
parent
b8d1a1adec
commit
9eaaa681d2
@ -1132,6 +1132,7 @@ begin
|
|||||||
MappedXY := TranslateGdkPointToClientArea(Event^.Window,
|
MappedXY := TranslateGdkPointToClientArea(Event^.Window,
|
||||||
Point(TruncToInt(Event^.X), TruncToInt(Event^.Y)),
|
Point(TruncToInt(Event^.X), TruncToInt(Event^.Y)),
|
||||||
PGtkWidget(AWinControl.Handle));
|
PGtkWidget(AWinControl.Handle));
|
||||||
|
MappedXY := SubtractScoll(PGtkWidget(AWinControl.Handle), MappedXY);
|
||||||
|
|
||||||
ShiftState := GTKEventStateToShiftState(Event^.State);
|
ShiftState := GTKEventStateToShiftState(Event^.State);
|
||||||
with Msg do
|
with Msg do
|
||||||
@ -1410,28 +1411,29 @@ var
|
|||||||
|
|
||||||
//DebugLn('DeliverMouseDownMessage ',DbgSName(AWinControl),' Mapped=',dbgs(MappedXY.X),',',dbgs(MappedXY.Y),' Event=',dbgs(EventXY.X),',',dbgs(EventXY.Y),' ',dbgs(LastMouse.ClickCount));
|
//DebugLn('DeliverMouseDownMessage ',DbgSName(AWinControl),' Mapped=',dbgs(MappedXY.X),',',dbgs(MappedXY.Y),' Event=',dbgs(EventXY.X),',',dbgs(EventXY.Y),' ',dbgs(LastMouse.ClickCount));
|
||||||
case LastMouse.ClickCount of
|
case LastMouse.ClickCount of
|
||||||
1: MessI.Msg := MsgNormal;
|
1: MessI.Msg := MsgNormal;
|
||||||
2: MessI.Msg := MsgDouble;
|
2: MessI.Msg := MsgDouble;
|
||||||
3: MessI.Msg := MsgTriple;
|
3: MessI.Msg := MsgTriple;
|
||||||
4: MessI.Msg := MsgQuad;
|
4: MessI.Msg := MsgQuad;
|
||||||
else
|
else
|
||||||
MessI.Msg := LM_NULL;
|
MessI.Msg := LM_NULL;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if (Widget=nil) then ;
|
MousePositionValid := False;
|
||||||
MousePositionValid:=false;
|
|
||||||
|
|
||||||
EventXY:=Point(TruncToInt(Event^.X),TruncToInt(Event^.Y));
|
EventXY := Point(TruncToInt(Event^.X), TruncToInt(Event^.Y));
|
||||||
ShiftState := GTKEventStateToShiftState(Event^.State);
|
ShiftState := GTKEventStateToShiftState(Event^.State);
|
||||||
MappedXY:=TranslateGdkPointToClientArea(Event^.Window,EventXY,
|
MappedXY := TranslateGdkPointToClientArea(Event^.Window, EventXY,
|
||||||
PGtkWidget(AWinControl.Handle));
|
PGtkWidget(AWinControl.Handle));
|
||||||
|
MappedXY := SubtractScoll(PGtkWidget(AWinControl.Handle), MappedXY);
|
||||||
//DebugLn('DeliverMouseDownMessage ',DbgSName(AWinControl),' Mapped=',dbgs(MappedXY.X),',',dbgs(MappedXY.Y),' Event=',dbgs(EventXY.X),',',dbgs(EventXY.Y));
|
//DebugLn('DeliverMouseDownMessage ',DbgSName(AWinControl),' Mapped=',dbgs(MappedXY.X),',',dbgs(MappedXY.Y),' Event=',dbgs(EventXY.X),',',dbgs(EventXY.Y));
|
||||||
|
|
||||||
if event^.Button in [4,5] then begin
|
if event^.Button in [4, 5] then
|
||||||
|
begin
|
||||||
// this is a mouse wheel event
|
// this is a mouse wheel event
|
||||||
MessE.Msg := LM_MOUSEWHEEL;
|
MessE.Msg := LM_MOUSEWHEEL;
|
||||||
MessE.WheelDelta := WHEEL_DELTA[event^.Button = 4];
|
MessE.WheelDelta := WHEEL_DELTA[event^.Button = 4];
|
||||||
@ -1445,31 +1447,25 @@ begin
|
|||||||
NotifyApplicationUserInput(MessE.Msg);
|
NotifyApplicationUserInput(MessE.Msg);
|
||||||
DeliverMessage(AWinControl, MessE);
|
DeliverMessage(AWinControl, MessE);
|
||||||
end
|
end
|
||||||
else begin
|
else
|
||||||
|
begin
|
||||||
// a normal mouse button is pressed
|
// a normal mouse button is pressed
|
||||||
MessI.Keys := 0;
|
MessI.Keys := 0;
|
||||||
case event^.Button of
|
case event^.Button of
|
||||||
|
1: if not CheckMouseButtonDown(LastLeft,
|
||||||
1: if not CheckMouseButtonDown(LastLeft,
|
MK_LBUTTON, LM_LBUTTONDOWN,
|
||||||
MK_LBUTTON, LM_LBUTTONDOWN,
|
LM_LBUTTONDBLCLK, LM_LBUTTONTRIPLECLK, LM_LBUTTONQUADCLK) then Exit;
|
||||||
LM_LBUTTONDBLCLK, LM_LBUTTONTRIPLECLK, LM_LBUTTONQUADCLK)
|
2: if not CheckMouseButtonDown(LastMiddle,
|
||||||
then exit;
|
MK_MBUTTON, LM_MBUTTONDOWN,
|
||||||
|
LM_MBUTTONDBLCLK, LM_MBUTTONTRIPLECLK, LM_MBUTTONQUADCLK) then Exit;
|
||||||
2: if not CheckMouseButtonDown(LastMiddle,
|
3: if not CheckMouseButtonDown(LastRight,
|
||||||
MK_MBUTTON, LM_MBUTTONDOWN,
|
MK_RBUTTON, LM_RBUTTONDOWN,
|
||||||
LM_MBUTTONDBLCLK, LM_MBUTTONTRIPLECLK, LM_MBUTTONQUADCLK)
|
LM_RBUTTONDBLCLK, LM_RBUTTONTRIPLECLK, LM_RBUTTONQUADCLK) then Exit;
|
||||||
then exit;
|
else
|
||||||
|
begin
|
||||||
3: if not CheckMouseButtonDown(LastRight,
|
MessI.Msg := LM_NULL;
|
||||||
MK_RBUTTON, LM_RBUTTONDOWN,
|
exit;
|
||||||
LM_RBUTTONDBLCLK, LM_RBUTTONTRIPLECLK, LM_RBUTTONQUADCLK)
|
end;
|
||||||
then exit;
|
|
||||||
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
MessI.Msg := LM_NULL;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end; // case
|
end; // case
|
||||||
|
|
||||||
MessI.XPos := MappedXY.X;
|
MessI.XPos := MappedXY.X;
|
||||||
@ -1686,6 +1682,7 @@ begin
|
|||||||
MappedXY := TranslateGdkPointToClientArea(Event^.Window,
|
MappedXY := TranslateGdkPointToClientArea(Event^.Window,
|
||||||
Point(TruncToInt(Event^.X), TruncToInt(Event^.Y)),
|
Point(TruncToInt(Event^.X), TruncToInt(Event^.Y)),
|
||||||
PGtkWidget(AWinControl.Handle));
|
PGtkWidget(AWinControl.Handle));
|
||||||
|
MappedXY := SubtractScoll(PGtkWidget(AWinControl.Handle), MappedXY);
|
||||||
//DebugLn(['DeliverMouseUpMessage ',GetWidgetDebugReport(Widget),' ',dbgsName(AWinControl),' ',dbgs(MappedXY)]);
|
//DebugLn(['DeliverMouseUpMessage ',GetWidgetDebugReport(Widget),' ',dbgsName(AWinControl),' ',dbgs(MappedXY)]);
|
||||||
|
|
||||||
case event^.Button of
|
case event^.Button of
|
||||||
|
@ -4496,16 +4496,18 @@ var
|
|||||||
ClientWindow: PGdkWindow;
|
ClientWindow: PGdkWindow;
|
||||||
begin
|
begin
|
||||||
ClientWidget:=GetFixedWidget(TheWidget);
|
ClientWidget:=GetFixedWidget(TheWidget);
|
||||||
if ClientWidget<>TheWidget then begin
|
if ClientWidget <> TheWidget then
|
||||||
ClientWindow:=GetControlWindow(ClientWidget);
|
begin
|
||||||
if ClientWindow<>nil then begin
|
ClientWindow := GetControlWindow(ClientWidget);
|
||||||
|
if ClientWindow <> nil then
|
||||||
|
begin
|
||||||
{$IFDEF DebugGDK}
|
{$IFDEF DebugGDK}
|
||||||
BeginGDKErrorTrap;
|
BeginGDKErrorTrap;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
gdk_window_get_origin(ClientWindow,@Result.X,@Result.Y);
|
gdk_window_get_origin(ClientWindow, @Result.X, @Result.Y);
|
||||||
{$Ifdef GTK2}
|
{$Ifdef GTK2}
|
||||||
if GTK_WIDGET_NO_WINDOW(ClientWidget)
|
if GTK_WIDGET_NO_WINDOW(ClientWidget) then
|
||||||
then begin
|
begin
|
||||||
Inc(Result.X, ClientWidget^.Allocation.X);
|
Inc(Result.X, ClientWidget^.Allocation.X);
|
||||||
Inc(Result.Y, ClientWidget^.Allocation.Y);
|
Inc(Result.Y, ClientWidget^.Allocation.Y);
|
||||||
end;
|
end;
|
||||||
@ -4516,12 +4518,15 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{$IFDEF Gtk2}
|
{$IFDEF Gtk2}
|
||||||
end else if GtkWidgetIsA(TheWidget,GTK_TYPE_NOTEBOOK) then begin
|
end
|
||||||
|
else
|
||||||
|
if GtkWidgetIsA(TheWidget,GTK_TYPE_NOTEBOOK) then
|
||||||
|
begin
|
||||||
GetNoteBookClientOrigin(PGtkNoteBook(TheWidget));
|
GetNoteBookClientOrigin(PGtkNoteBook(TheWidget));
|
||||||
exit;
|
Exit;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
Result:=GetWidgetOrigin(TheWidget);
|
Result := GetWidgetOrigin(TheWidget);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{-------------------------------------------------------------------------------
|
{-------------------------------------------------------------------------------
|
||||||
@ -4531,25 +4536,38 @@ end;
|
|||||||
client area of the LCL WinControl.
|
client area of the LCL WinControl.
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
function TranslateGdkPointToClientArea(SourceWindow: PGdkWindow;
|
function TranslateGdkPointToClientArea(SourceWindow: PGdkWindow;
|
||||||
SourcePos: TPoint; DestinationWidget: PGtkWidget): TPoint;
|
SourcePos: TPoint; DestinationWidget: PGtkWidget): TPoint;
|
||||||
var
|
var
|
||||||
SrcWindowOrigin: TPoint;
|
SrcWindowOrigin: TPoint;
|
||||||
ClientAreaWindowOrigin: TPoint;
|
ClientAreaWindowOrigin: TPoint;
|
||||||
Src2ClientAreaVector: TPoint;
|
Src2ClientAreaVector: TPoint;
|
||||||
begin
|
begin
|
||||||
if SourceWindow=nil then begin
|
if SourceWindow = nil then
|
||||||
|
begin
|
||||||
{$IFDEF RaiseExceptionOnNilPointers}
|
{$IFDEF RaiseExceptionOnNilPointers}
|
||||||
RaiseException('TranslateGdkPointToClientArea Window=nil');
|
RaiseException('TranslateGdkPointToClientArea Window=nil');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
DebugLn('WARNING: TranslateGdkPointToClientArea SourceWindow=nil');
|
DebugLn('WARNING: TranslateGdkPointToClientArea SourceWindow=nil');
|
||||||
end;
|
end;
|
||||||
gdk_window_get_origin(SourceWindow,@SrcWindowOrigin.X,@SrcWindowOrigin.Y);
|
gdk_window_get_origin(SourceWindow, @SrcWindowOrigin.X, @SrcWindowOrigin.Y);
|
||||||
|
|
||||||
ClientAreaWindowOrigin:=GetWidgetClientOrigin(DestinationWidget);
|
ClientAreaWindowOrigin := GetWidgetClientOrigin(DestinationWidget);
|
||||||
Src2ClientAreaVector.X:=ClientAreaWindowOrigin.X-SrcWindowOrigin.X;
|
Src2ClientAreaVector.X := ClientAreaWindowOrigin.X - SrcWindowOrigin.X;
|
||||||
Src2ClientAreaVector.Y:=ClientAreaWindowOrigin.Y-SrcWindowOrigin.Y;
|
Src2ClientAreaVector.Y := ClientAreaWindowOrigin.Y - SrcWindowOrigin.Y;
|
||||||
Result.X:=SourcePos.X-Src2ClientAreaVector.X;
|
Result.X := SourcePos.X - Src2ClientAreaVector.X;
|
||||||
Result.Y:=SourcePos.Y-Src2ClientAreaVector.Y;
|
Result.Y := SourcePos.Y - Src2ClientAreaVector.Y;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function SubtractScoll(AWidget: PGtkWidget; APosition: TPoint): TPoint;
|
||||||
|
begin
|
||||||
|
Result := APosition;
|
||||||
|
if not GTK_IS_SCROLLED_WINDOW(AWidget) then
|
||||||
|
AWidget := gtk_object_get_data(PGTKObject(AWidget), odnScrollArea);
|
||||||
|
if GTK_IS_SCROLLED_WINDOW(AWidget) then
|
||||||
|
begin
|
||||||
|
dec(Result.x, Round(gtk_scrolled_window_get_hadjustment(PGtkScrolledWindow(AWidget))^.value));
|
||||||
|
dec(Result.y, Round(gtk_scrolled_window_get_vadjustment(PGtkScrolledWindow(AWidget))^.value));
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user