mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 04:19:09 +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,
|
||||
Point(TruncToInt(Event^.X), TruncToInt(Event^.Y)),
|
||||
PGtkWidget(AWinControl.Handle));
|
||||
MappedXY := SubtractScoll(PGtkWidget(AWinControl.Handle), MappedXY);
|
||||
|
||||
ShiftState := GTKEventStateToShiftState(Event^.State);
|
||||
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));
|
||||
case LastMouse.ClickCount of
|
||||
1: MessI.Msg := MsgNormal;
|
||||
2: MessI.Msg := MsgDouble;
|
||||
3: MessI.Msg := MsgTriple;
|
||||
4: MessI.Msg := MsgQuad;
|
||||
else
|
||||
MessI.Msg := LM_NULL;
|
||||
1: MessI.Msg := MsgNormal;
|
||||
2: MessI.Msg := MsgDouble;
|
||||
3: MessI.Msg := MsgTriple;
|
||||
4: MessI.Msg := MsgQuad;
|
||||
else
|
||||
MessI.Msg := LM_NULL;
|
||||
end;
|
||||
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
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);
|
||||
MappedXY:=TranslateGdkPointToClientArea(Event^.Window,EventXY,
|
||||
PGtkWidget(AWinControl.Handle));
|
||||
MappedXY := TranslateGdkPointToClientArea(Event^.Window, EventXY,
|
||||
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));
|
||||
|
||||
if event^.Button in [4,5] then begin
|
||||
if event^.Button in [4, 5] then
|
||||
begin
|
||||
// this is a mouse wheel event
|
||||
MessE.Msg := LM_MOUSEWHEEL;
|
||||
MessE.WheelDelta := WHEEL_DELTA[event^.Button = 4];
|
||||
@ -1445,31 +1447,25 @@ begin
|
||||
NotifyApplicationUserInput(MessE.Msg);
|
||||
DeliverMessage(AWinControl, MessE);
|
||||
end
|
||||
else begin
|
||||
else
|
||||
begin
|
||||
// a normal mouse button is pressed
|
||||
MessI.Keys := 0;
|
||||
case event^.Button of
|
||||
|
||||
1: if not CheckMouseButtonDown(LastLeft,
|
||||
MK_LBUTTON, LM_LBUTTONDOWN,
|
||||
LM_LBUTTONDBLCLK, LM_LBUTTONTRIPLECLK, LM_LBUTTONQUADCLK)
|
||||
then exit;
|
||||
|
||||
2: if not CheckMouseButtonDown(LastMiddle,
|
||||
MK_MBUTTON, LM_MBUTTONDOWN,
|
||||
LM_MBUTTONDBLCLK, LM_MBUTTONTRIPLECLK, LM_MBUTTONQUADCLK)
|
||||
then exit;
|
||||
|
||||
3: if not CheckMouseButtonDown(LastRight,
|
||||
MK_RBUTTON, LM_RBUTTONDOWN,
|
||||
LM_RBUTTONDBLCLK, LM_RBUTTONTRIPLECLK, LM_RBUTTONQUADCLK)
|
||||
then exit;
|
||||
|
||||
else
|
||||
begin
|
||||
MessI.Msg := LM_NULL;
|
||||
exit;
|
||||
end;
|
||||
1: if not CheckMouseButtonDown(LastLeft,
|
||||
MK_LBUTTON, LM_LBUTTONDOWN,
|
||||
LM_LBUTTONDBLCLK, LM_LBUTTONTRIPLECLK, LM_LBUTTONQUADCLK) then Exit;
|
||||
2: if not CheckMouseButtonDown(LastMiddle,
|
||||
MK_MBUTTON, LM_MBUTTONDOWN,
|
||||
LM_MBUTTONDBLCLK, LM_MBUTTONTRIPLECLK, LM_MBUTTONQUADCLK) then Exit;
|
||||
3: if not CheckMouseButtonDown(LastRight,
|
||||
MK_RBUTTON, LM_RBUTTONDOWN,
|
||||
LM_RBUTTONDBLCLK, LM_RBUTTONTRIPLECLK, LM_RBUTTONQUADCLK) then Exit;
|
||||
else
|
||||
begin
|
||||
MessI.Msg := LM_NULL;
|
||||
exit;
|
||||
end;
|
||||
end; // case
|
||||
|
||||
MessI.XPos := MappedXY.X;
|
||||
@ -1686,6 +1682,7 @@ begin
|
||||
MappedXY := TranslateGdkPointToClientArea(Event^.Window,
|
||||
Point(TruncToInt(Event^.X), TruncToInt(Event^.Y)),
|
||||
PGtkWidget(AWinControl.Handle));
|
||||
MappedXY := SubtractScoll(PGtkWidget(AWinControl.Handle), MappedXY);
|
||||
//DebugLn(['DeliverMouseUpMessage ',GetWidgetDebugReport(Widget),' ',dbgsName(AWinControl),' ',dbgs(MappedXY)]);
|
||||
|
||||
case event^.Button of
|
||||
|
@ -4496,16 +4496,18 @@ var
|
||||
ClientWindow: PGdkWindow;
|
||||
begin
|
||||
ClientWidget:=GetFixedWidget(TheWidget);
|
||||
if ClientWidget<>TheWidget then begin
|
||||
ClientWindow:=GetControlWindow(ClientWidget);
|
||||
if ClientWindow<>nil then begin
|
||||
if ClientWidget <> TheWidget then
|
||||
begin
|
||||
ClientWindow := GetControlWindow(ClientWidget);
|
||||
if ClientWindow <> nil then
|
||||
begin
|
||||
{$IFDEF DebugGDK}
|
||||
BeginGDKErrorTrap;
|
||||
{$ENDIF}
|
||||
gdk_window_get_origin(ClientWindow,@Result.X,@Result.Y);
|
||||
gdk_window_get_origin(ClientWindow, @Result.X, @Result.Y);
|
||||
{$Ifdef GTK2}
|
||||
if GTK_WIDGET_NO_WINDOW(ClientWidget)
|
||||
then begin
|
||||
if GTK_WIDGET_NO_WINDOW(ClientWidget) then
|
||||
begin
|
||||
Inc(Result.X, ClientWidget^.Allocation.X);
|
||||
Inc(Result.Y, ClientWidget^.Allocation.Y);
|
||||
end;
|
||||
@ -4516,12 +4518,15 @@ begin
|
||||
exit;
|
||||
end;
|
||||
{$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));
|
||||
exit;
|
||||
Exit;
|
||||
{$ENDIF}
|
||||
end;
|
||||
Result:=GetWidgetOrigin(TheWidget);
|
||||
Result := GetWidgetOrigin(TheWidget);
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
@ -4531,25 +4536,38 @@ end;
|
||||
client area of the LCL WinControl.
|
||||
-------------------------------------------------------------------------------}
|
||||
function TranslateGdkPointToClientArea(SourceWindow: PGdkWindow;
|
||||
SourcePos: TPoint; DestinationWidget: PGtkWidget): TPoint;
|
||||
SourcePos: TPoint; DestinationWidget: PGtkWidget): TPoint;
|
||||
var
|
||||
SrcWindowOrigin: TPoint;
|
||||
ClientAreaWindowOrigin: TPoint;
|
||||
Src2ClientAreaVector: TPoint;
|
||||
begin
|
||||
if SourceWindow=nil then begin
|
||||
if SourceWindow = nil then
|
||||
begin
|
||||
{$IFDEF RaiseExceptionOnNilPointers}
|
||||
RaiseException('TranslateGdkPointToClientArea Window=nil');
|
||||
{$ENDIF}
|
||||
DebugLn('WARNING: TranslateGdkPointToClientArea SourceWindow=nil');
|
||||
end;
|
||||
gdk_window_get_origin(SourceWindow,@SrcWindowOrigin.X,@SrcWindowOrigin.Y);
|
||||
gdk_window_get_origin(SourceWindow, @SrcWindowOrigin.X, @SrcWindowOrigin.Y);
|
||||
|
||||
ClientAreaWindowOrigin:=GetWidgetClientOrigin(DestinationWidget);
|
||||
Src2ClientAreaVector.X:=ClientAreaWindowOrigin.X-SrcWindowOrigin.X;
|
||||
Src2ClientAreaVector.Y:=ClientAreaWindowOrigin.Y-SrcWindowOrigin.Y;
|
||||
Result.X:=SourcePos.X-Src2ClientAreaVector.X;
|
||||
Result.Y:=SourcePos.Y-Src2ClientAreaVector.Y;
|
||||
ClientAreaWindowOrigin := GetWidgetClientOrigin(DestinationWidget);
|
||||
Src2ClientAreaVector.X := ClientAreaWindowOrigin.X - SrcWindowOrigin.X;
|
||||
Src2ClientAreaVector.Y := ClientAreaWindowOrigin.Y - SrcWindowOrigin.Y;
|
||||
Result.X := SourcePos.X - Src2ClientAreaVector.X;
|
||||
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;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user