View Issue Details

IDProjectCategoryView StatusLast Update
0028036LazarusLCLpublic2020-04-05 18:04
ReporterOndrej Pokorny Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status confirmedResolutionopen 
PlatformGtk2OSLinux 
Product Version1.5 (SVN) 
Summary0028036: Form ClientHeight ignores main menu height
DescriptionWhen you have a form with a main menu and you set ClientHeight, the main menu height is ignored and thus the resulting form height is too small.

In Win32, the main menu height is considered for ClientHeight. All widgetsets should behave the same way in this respect.
Steps To ReproduceSee the attached project. If you compile and run it under Win32, you will see the whole panel. If you compile and run under Gtk2, the panel is partly hidden because the form height is not big enough (the hidden height is exactly the main menu height).
Additional InformationI came across this issue when working on auto-sized Lazarus IDE main window: http://bugs.freepascal.org/view.php?id=27940
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

related to 0028034 resolvedZeljan Rikalo Lazarus GetSystemMetrics(SM_CYMENU) delivers wrong result 
related to 0027940 closedJuha Manninen Patches Lazarus IDE has an unnecessary MaxHeight-constraint 
related to 0031621 new Lazarus Alignment error in inherited forms 
related to 0034377 feedback Lazarus Size range overflow in MainIDE.SendMoveSizeMessages 

Activities

Ondrej Pokorny

2015-05-06 10:44

developer  

Zeljan Rikalo

2017-05-20 17:39

developer  

gtk2_formclientrect.diff (1,054 bytes)   
Index: lcl/interfaces/gtk2/gtk2winapi.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2winapi.inc	(revision 55021)
+++ lcl/interfaces/gtk2/gtk2winapi.inc	(working copy)
@@ -4370,10 +4370,21 @@
   child controls are visible.
  ------------------------------------------------------------------------------}
 function TGtk2WidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
+var
+  AInfo: PWidgetInfo;
 begin
   Result := false;
   if Handle = 0 then Exit;
   ARect := GetWidgetClientRect({%H-}PGtkWidget(Handle));
+  AInfo := GetWidgetInfo({%H-}PGtkWidget(Handle));
+  if Assigned(AInfo) and (AInfo^.LCLObject is TCustomForm) and
+    Assigned(TCustomForm(AInfo^.LCLObject).Menu) and
+      TCustomForm(AInfo^.LCLObject).Menu.HandleAllocated then
+  begin
+    if GTK_WIDGET_VISIBLE({%H-}PGtkWidget(TCustomForm(AInfo^.LCLObject).Menu.Handle)) then
+      dec(ARect.Bottom, TCustomForm(AInfo^.LCLObject).Menu.Height - Max(FCachedBorderSize * 2, 0));
+  end;
+
   Result := True;
 end;
 
gtk2_formclientrect.diff (1,054 bytes)   

Zeljan Rikalo

2017-05-20 17:39

developer   ~0100543

Please test with attached patch and give some feedback. Note that probably adding TStatusBar to the gtk2 form may result in same problem.

Zeljan Rikalo

2020-04-05 15:57

developer   ~0121942

Attached another patch which works ok, but in that case Main IDE window does not look good.

Zeljan Rikalo

2020-04-05 15:57

developer  

gtk2clientrect.diff (2,249 bytes)   
Index: gtk2proc.inc
===================================================================
--- gtk2proc.inc	(revision 62888)
+++ gtk2proc.inc	(working copy)
@@ -6830,6 +6830,7 @@
   ParentWidget: PGtkWidget;
   ParentFixed: PGtkWidget;
   WinWidgetInfo: PWidgetInfo;
+  AParentForm: TCustomForm;
   {$IFDEF VerboseSizeMsg}
   LCLObject: TObject;
   {$ENDIF}
@@ -6875,6 +6876,17 @@
     if GtkWidgetIsA(ParentFixed,GTK_FIXED_GET_TYPE) or
        GtkWidgetIsA(ParentFixed,GTK_LAYOUT_GET_TYPE) then
     begin
+      {issue #28036}
+      if (LCLControl is TStatusBar) and LCLControl.Visible then
+      begin
+        if Assigned(LCLControl.Parent) and (LCLControl.Parent is TCustomForm) then
+        begin
+          AParentForm := TCustomForm(LCLControl.Parent);
+          if Assigned(AParentForm.Menu) and AParentForm.Menu.HandleAllocated and
+            GTK_WIDGET_VISIBLE({%H-}PGtkWidget(AParentForm.Menu.Handle)) then
+            inc(LCLTop, AParentForm.Menu.Height);
+        end;
+      end;
       //DebugLn(['SetWidgetSizeAndPosition ',DbgSName(LCLControl),' Widget=[',GetWidgetDebugReport(Widget),'] ParentFixed=[',GetWidgetDebugReport(ParentFixed),']']);
       FixedMoveControl(ParentFixed, Widget, LCLLeft, LCLTop);
     end
Index: gtk2winapi.inc
===================================================================
--- gtk2winapi.inc	(revision 62889)
+++ gtk2winapi.inc	(working copy)
@@ -4404,10 +4403,25 @@
   child controls are visible.
  ------------------------------------------------------------------------------}
 function TGtk2WidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
+var
+  AInfo: PWidgetInfo;
 begin
   Result := false;
   if Handle = 0 then Exit;
   ARect := GetWidgetClientRect({%H-}PGtkWidget(Handle));
+
+  {issue #28036}
+  AInfo := GetWidgetInfo({%H-}PGtkWidget(Handle));
+  if Assigned(AInfo) and (AInfo^.LCLObject is TCustomForm) then
+  begin
+    if Assigned(TCustomForm(AInfo^.LCLObject).Menu) and
+      TCustomForm(AInfo^.LCLObject).Menu.HandleAllocated then
+    begin
+      if GTK_WIDGET_VISIBLE({%H-}PGtkWidget(TCustomForm(AInfo^.LCLObject).Menu.Handle)) then
+        dec(ARect.Bottom, TCustomForm(AInfo^.LCLObject).Menu.Height);
+    end;
+  end;
+
   Result := True;
 end;
 
gtk2clientrect.diff (2,249 bytes)   

Zeljan Rikalo

2020-04-05 16:31

developer   ~0121945

Forgot about last patch. Move ClientHeight := Panel.Top + Panel.Height into FormActivate and it'll work.
Something else is problem in gtk2ws

Zeljan Rikalo

2020-04-05 18:04

developer   ~0121947

I've unassigned myself from this issue. An Application.QueueAsyncCall() from FormShow , and then set ClientHeight in async call event works fine.

Issue History

Date Modified Username Field Change
2015-05-06 10:44 Ondrej Pokorny New Issue
2015-05-06 10:44 Ondrej Pokorny File Added: FormClientHeight.lpi.zip
2015-05-06 23:06 Maxim Ganetsky Relationship added related to 0027940
2016-03-01 17:38 Zeljan Rikalo Assigned To => Zeljan Rikalo
2016-03-01 17:38 Zeljan Rikalo Status new => assigned
2016-03-02 09:30 Zeljan Rikalo LazTarget => -
2016-03-02 09:30 Zeljan Rikalo Status assigned => confirmed
2017-05-12 08:01 Ondrej Pokorny Relationship added related to 0031621
2017-05-20 17:39 Zeljan Rikalo File Added: gtk2_formclientrect.diff
2017-05-20 17:39 Zeljan Rikalo Note Added: 0100543
2020-04-05 11:27 Zeljan Rikalo Relationship added related to 0028034
2020-04-05 15:56 Zeljan Rikalo Relationship added related to 0034377
2020-04-05 15:57 Zeljan Rikalo Note Added: 0121942
2020-04-05 15:57 Zeljan Rikalo File Added: gtk2clientrect.diff
2020-04-05 16:31 Zeljan Rikalo Note Added: 0121945
2020-04-05 18:03 Zeljan Rikalo Assigned To Zeljan Rikalo =>
2020-04-05 18:04 Zeljan Rikalo Note Added: 0121947