diff --git a/lcl/interfaces/gtk2/gtk2winapi.inc b/lcl/interfaces/gtk2/gtk2winapi.inc index 7f674ee348..6f071006e7 100644 --- a/lcl/interfaces/gtk2/gtk2winapi.inc +++ b/lcl/interfaces/gtk2/gtk2winapi.inc @@ -6144,23 +6144,24 @@ var P: TPoint; begin Result := 0; // error - if Handle <> 0 then + if Handle = 0 then + Exit; + + Widget := {%H-}PGtkWidget(Handle); + + if GTK_IS_WINDOW(Widget) and Assigned(Widget^.window) + and GTK_WIDGET_VISIBLE(Widget) // Gtk2 returns invalid origin/frame for invisible widgets + then + begin + gdk_window_get_origin(Widget^.window, @ARect.Left, @ARect.Top); + gdk_window_get_size(Widget^.window, @ARect.Right, @ARect.Bottom); + P := GetWidgetOrigin(Widget); + gdk_window_get_frame_extents(Widget^.window, @GRect); + ARect := Bounds(P.X,P.Y,GRect.width,GRect.height); + // writeln('Frame extents are: ',dbgs(R),' ARECT=',dbgs(AREct)); + Result := 1; // success + end else begin - Widget := {%H-}PGtkWidget(Handle); - - if GTK_IS_WINDOW(Widget) and Assigned(Widget^.window) - and GTK_WIDGET_VISIBLE(Widget) then - begin - gdk_window_get_origin(Widget^.window, @ARect.Left, @ARect.Top); - gdk_window_get_size(Widget^.window, @ARect.Right, @ARect.Bottom); - P := GetWidgetOrigin(Widget); - gdk_window_get_frame_extents(Widget^.window, @GRect); - ARect := Bounds(P.X,P.Y,GRect.width,GRect.height); - // writeln('Frame extents are: ',dbgs(R),' ARECT=',dbgs(AREct)); - Result := 1; // success - exit; - end; - ARect.TopLeft := GetWidgetOrigin(Widget); if (ARect.Top <> -1) or (ARect.Left <> -1) or (Widget^.allocation.width <> 1) or (Widget^.allocation.height <> 1) then