Gtk3: fixed invalid size from TGtk3WidgetSet.GetClientRect. issue #41343

This commit is contained in:
zeljan1 2025-01-22 13:17:27 +01:00
parent 7f92b9f77a
commit 54e4530082
2 changed files with 28 additions and 15 deletions

View File

@ -77,6 +77,7 @@ type
FFocusableByMouse: Boolean; {shell we call SetFocus on mouse down. Default = False} FFocusableByMouse: Boolean; {shell we call SetFocus on mouse down. Default = False}
FOwner: PGtkWidget; FOwner: PGtkWidget;
FProps: TStringList; FProps: TStringList;
FWidgetMapped: boolean;
FWidgetRGBA: array [0{GTK_STATE_NORMAL}..4{GTK_STATE_INSENSITIVE}] of TDefaultRGBA; FWidgetRGBA: array [0{GTK_STATE_NORMAL}..4{GTK_STATE_INSENSITIVE}] of TDefaultRGBA;
function CanSendLCLMessage: Boolean; function CanSendLCLMessage: Boolean;
function GetCairoContext: Pcairo_t; function GetCairoContext: Pcairo_t;
@ -90,7 +91,7 @@ type
procedure SetStyleContext({%H-}AValue: PGtkStyleContext); procedure SetStyleContext({%H-}AValue: PGtkStyleContext);
class procedure DestroyWidgetEvent({%H-}w: PGtkWidget;{%H-}data:gpointer); cdecl; static; class procedure DestroyWidgetEvent({%H-}w: PGtkWidget;{%H-}data:gpointer); cdecl; static;
class function DrawWidget(AWidget: PGtkWidget; AContext: Pcairo_t; Data: gpointer): gboolean; cdecl; static; class function DrawWidget(AWidget: PGtkWidget; AContext: Pcairo_t; Data: gpointer): gboolean; cdecl; static;
class procedure MapWidget(AWidget: PGtkWidget; Data: gPointer); cdecl; static; class procedure MapWidget(AWidget: PGtkWidget; Data: gPointer); cdecl; static; {GtkWindow never sends this signal !}
class function ResizeEvent(AWidget: PGtkWidget; AEvent: PGdkEvent; Data: gpointer): gboolean; cdecl; static; class function ResizeEvent(AWidget: PGtkWidget; AEvent: PGdkEvent; Data: gpointer): gboolean; cdecl; static;
class function ScrollEvent(AWidget: PGtkWidget; AEvent: PGdkEvent; AData: GPointer): GBoolean; cdecl; static; class function ScrollEvent(AWidget: PGtkWidget; AEvent: PGdkEvent; AData: GPointer): GBoolean; cdecl; static;
class procedure SizeAllocate(AWidget: PGtkWidget; AGdkRect: PGdkRectangle; Data: gpointer); cdecl; static; class procedure SizeAllocate(AWidget: PGtkWidget; AGdkRect: PGdkRectangle; Data: gpointer); cdecl; static;
@ -209,6 +210,7 @@ type
property Text: String read getText write setText; property Text: String read getText write setText;
property Visible: Boolean read GetVisible write SetVisible; property Visible: Boolean read GetVisible write SetVisible;
property Widget: PGtkWidget read GetWidget; property Widget: PGtkWidget read GetWidget;
property WidgetMapped: boolean read FWidgetMapped write FWidgetMapped; {very important. Gtk3 does not give us reliable informations about this state get_mapped returns true, but actually map event isn't arrived yet.}
property WidgetType: TGtk3WidgetTypes read FWidgetType; property WidgetType: TGtk3WidgetTypes read FWidgetType;
end; end;
@ -1293,7 +1295,12 @@ begin
end; end;
GDK_MAP: GDK_MAP:
begin begin
// DebugLn('****** GDK_MAP FOR ',dbgsName(TGtk3Widget(Data).LCLObject)); //issue #41343
if [wtWindow, wtHintWindow] * TGtk3Widget(Data).WidgetType <> [] then
begin
TGtk3Window(Data).WidgetMapped := True;
// DebugLn('****** GDK_MAP FOR ',dbgsName(TGtk3Widget(Data).LCLObject));
end;
end; end;
GDK_UNMAP: GDK_UNMAP:
begin begin
@ -1369,6 +1376,7 @@ begin
with Allocation do with Allocation do
DebugLn(' Allocation ',Format('x %d y %d w %d h %d',[x,y,width,height])); DebugLn(' Allocation ',Format('x %d y %d w %d h %d',[x,y,width,height]));
{$ENDIF} {$ENDIF}
TGtk3Widget(Data).WidgetMapped := True;
ARect := TGtk3Widget(Data).LCLObject.BoundsRect; ARect := TGtk3Widget(Data).LCLObject.BoundsRect;
{$IFDEF GTK3DEBUGCORE} {$IFDEF GTK3DEBUGCORE}
with ARect do with ARect do
@ -2667,6 +2675,7 @@ begin
LCLWidth := 0; LCLWidth := 0;
LCLHeight := 0; LCLHeight := 0;
FContext := 0; FContext := 0;
FWidgetMapped := False;
FHasPaint := False; FHasPaint := False;
FWidget := nil; FWidget := nil;
FOwner := nil; FOwner := nil;
@ -2687,6 +2696,7 @@ constructor TGtk3Widget.CreateFrom(const AWinControl: TWinControl;
begin begin
inherited Create; inherited Create;
FContext := 0; FContext := 0;
FWidgetMapped := False;
FHasPaint := False; FHasPaint := False;
FWidget := nil; FWidget := nil;
FOwner := nil; FOwner := nil;
@ -8317,7 +8327,8 @@ begin
{%H-}PGtkWindow(FWidget)^.set_title(PGChar(AValue)); {%H-}PGtkWindow(FWidget)^.set_title(PGChar(AValue));
end; end;
class function TGtk3Window.WindowStateSignal(AWidget: PGtkWidget; AEvent: PGdkEvent; AData: gPointer): GBoolean; cdecl; class function TGtk3Window.WindowStateSignal(AWidget: PGtkWidget;
AEvent: PGdkEvent; AData: gPointer): gboolean; cdecl;
var var
Msg: TLMSize; Msg: TLMSize;
AState: TGdkWindowState; AState: TGdkWindowState;
@ -8703,6 +8714,7 @@ begin
if Gtk3IsGtkWindow(fWidget) then if Gtk3IsGtkWindow(fWidget) then
begin begin
//PGtkWindow(Widget)^.set_default_size(AWidth, AHeight);
PGtkWindow(Widget)^.set_resizable(true); PGtkWindow(Widget)^.set_resizable(true);
PGtkWindow(Widget)^.resize(AWidth, AHeight); PGtkWindow(Widget)^.resize(AWidth, AHeight);
PGtkWindow(Widget)^.move(ALeft, ATop); PGtkWindow(Widget)^.move(ALeft, ATop);

View File

@ -2941,24 +2941,25 @@ end;
function TGtk3WidgetSet.GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; function TGtk3WidgetSet.GetWindowRect(Handle: hwnd; var ARect: TRect): Integer;
var var
AWindow: PGdkWindow; AWindow: PGtkWindow;
x, y: gint; x, y, aWidth, aHeight: gint;
//w, h: gint;
GRect: TGdkRectangle;
Allocation: TGtkAllocation; Allocation: TGtkAllocation;
begin begin
Result := 0; Result := 0;
if Handle <> 0 then if IsValidHandle(Handle) then
begin begin
AWindow := TGtk3Widget(Handle).GetWindow; if [wtWindow, wtHintWindow] * TGtk3Widget(Handle).WidgetType <> [] then
begin
AWindow := PGtkWindow(TGtk3Widget(Handle).Widget);
if not TGtk3Window(Handle).WidgetMapped then
AWindow := nil;
end else
AWindow := nil;
if AWindow <> nil then if AWindow <> nil then
begin begin
AWindow^.get_origin(@x, @y); AWindow^.get_position(@x, @y);
//w := AWindow^.get_width; AWindow^.get_size(@aWidth, @aHeight);
//h := AWindow^.get_height; ARect := Bounds(x, Y, AWidth, AHeight);
AWindow^.get_frame_extents(@GRect);
// R := RectFromGdkRect(GRect);
ARect := Bounds(x, Y, GRect.width, GRect.Height);
Result := 1; Result := 1;
end else end else
begin begin