View Issue Details

IDProjectCategoryView StatusLast Update
0027771LazarusLCLpublic2016-03-24 14:20
ReporterAlexey Tor.Assigned ToOndrej Pokorny 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformwinOSw7 x64OS Version
Product Version1.5 (SVN)Product Build 
Target Version1.8Fixed in Version1.7 (SVN) 
Summary0027771: Position "screen center" don't give vert-center
DescriptionImg. Top indent 135; bottom 95. 1.4RC same.
TagsNo tags attached.
Fixed in Revision51111
LazTarget1.8
Widgetset
Attached Files
  • indent-incorr.png (13,339 bytes)
    indent-incorr.png (13,339 bytes)
  • customform.inc.patch (1,617 bytes)
    Index: customform.inc
    ===================================================================
    --- lcl/include/customform.inc	(revision 51106)
    +++ lcl/include/customform.inc	(working copy)
    @@ -1279,9 +1279,9 @@
       end;
     
     var
    -  X, Y: integer;
    +  X, Y, BorderW, BorderH: integer;
       p: TPosition;
    -  AForm: TCustomForm;
    +  AForm: TCustomForm; rcWindow, rcClient:TRect;
     begin
       if (Parent <> nil) or (ParentWindow <> 0) then exit;
     
    @@ -1291,6 +1291,12 @@
       X := Left;
       Y := Top;
     
    +  {$IFDEF Windows}
    +    rcClient:=GetClientRect; GetWindowRect(Handle, rcWindow);
    +    BorderW := (rcWindow.Right - rcWindow.Left) - rcClient.Right;
    +    BorderH := (rcWindow.Bottom - rcWindow.Top) - rcClient.Bottom;
    +  {$ENDIF}
    +
       p := Position;
       if (Position = poMainFormCenter) and (Application.Mainform=nil) then
         p := poScreenCenter;
    @@ -1297,13 +1303,13 @@
       case P of
         poDesktopCenter:
           begin
    -        X := Screen.DesktopLeft + (Screen.DesktopWidth - Width) div 2;
    -        Y := Screen.DesktopTop +(Screen.DesktopHeight - Height) div 2;
    +        X := Screen.DesktopLeft + (Screen.DesktopWidth - (Width{$IFDEF Windows}+BorderW{$ENDIF})) div 2;
    +        Y := Screen.DesktopTop +(Screen.DesktopHeight - (Height{$IFDEF Windows}+BorderH{$ENDIF})) div 2;
           end;
         poScreenCenter:
           begin
    -        X := (Screen.Width - Width) div 2;
    -        Y := (Screen.Height - Height) div 2;
    +        X := (Screen.Width - (Width{$IFDEF Windows}+BorderW{$ENDIF})) div 2;
    +        Y := (Screen.Height - (Height{$IFDEF Windows}+BorderH{$ENDIF})) div 2;
           end;
         poMainFormCenter,
         poOwnerFormCenter:
    
    customform.inc.patch (1,617 bytes)

Relationships

related to 0020952 assignedOndrej Pokorny Form ClientWidth 
related to 0029371 closedOndrej Pokorny Error location in the form Form.Position: = poScreenCenter; 
related to 0029887 closedOndrej Pokorny Form position "poMainFormCenter" don't work correctly 

Activities

Alexey Tor.

2015-04-02 06:06

reporter  

indent-incorr.png (13,339 bytes)
indent-incorr.png (13,339 bytes)

Alexey Tor.

2015-04-03 15:39

reporter   ~0082567

Details. test shows:
a) form Height is 603, while image has visible height
about 640.
b) form ClientHeight 603!! so issue exists: Height=ClientHeight while it's not ok for win32, do you agree? or is it done special? to not handle Win stuff, not calc wnd border?

Janusz Tomczak

2016-01-01 20:20

reporter  

customform.inc.patch (1,617 bytes)
Index: customform.inc
===================================================================
--- lcl/include/customform.inc	(revision 51106)
+++ lcl/include/customform.inc	(working copy)
@@ -1279,9 +1279,9 @@
   end;
 
 var
-  X, Y: integer;
+  X, Y, BorderW, BorderH: integer;
   p: TPosition;
-  AForm: TCustomForm;
+  AForm: TCustomForm; rcWindow, rcClient:TRect;
 begin
   if (Parent <> nil) or (ParentWindow <> 0) then exit;
 
@@ -1291,6 +1291,12 @@
   X := Left;
   Y := Top;
 
+  {$IFDEF Windows}
+    rcClient:=GetClientRect; GetWindowRect(Handle, rcWindow);
+    BorderW := (rcWindow.Right - rcWindow.Left) - rcClient.Right;
+    BorderH := (rcWindow.Bottom - rcWindow.Top) - rcClient.Bottom;
+  {$ENDIF}
+
   p := Position;
   if (Position = poMainFormCenter) and (Application.Mainform=nil) then
     p := poScreenCenter;
@@ -1297,13 +1303,13 @@
   case P of
     poDesktopCenter:
       begin
-        X := Screen.DesktopLeft + (Screen.DesktopWidth - Width) div 2;
-        Y := Screen.DesktopTop +(Screen.DesktopHeight - Height) div 2;
+        X := Screen.DesktopLeft + (Screen.DesktopWidth - (Width{$IFDEF Windows}+BorderW{$ENDIF})) div 2;
+        Y := Screen.DesktopTop +(Screen.DesktopHeight - (Height{$IFDEF Windows}+BorderH{$ENDIF})) div 2;
       end;
     poScreenCenter:
       begin
-        X := (Screen.Width - Width) div 2;
-        Y := (Screen.Height - Height) div 2;
+        X := (Screen.Width - (Width{$IFDEF Windows}+BorderW{$ENDIF})) div 2;
+        Y := (Screen.Height - (Height{$IFDEF Windows}+BorderH{$ENDIF})) div 2;
       end;
     poMainFormCenter,
     poOwnerFormCenter:
customform.inc.patch (1,617 bytes)

Janusz Tomczak

2016-01-01 20:26

reporter   ~0088507

My patch seems resolved the problem.

Alexey Tor.

2016-01-01 20:50

reporter   ~0088508

Last edited: 2016-01-01 20:50

View 2 revisions

Good that patch is only here (calc position).Not inside calc of Height/Width. So noone should break.

Bart Broersma

2016-01-01 23:28

developer   ~0088513

A cross-platform solution (no ifdef's)would be nice(er).

Janusz Tomczak

2016-01-02 01:47

reporter   ~0088517

Yes, I know... This is temporary workaround only for Windows, but it is better than nothing ;)

Ondrej Pokorny

2016-01-02 10:15

reporter   ~0088518

Fixed with a cross-platform solution.

Info: it works on Windows. It doesn't work on Linux/X11, but this is another problem (related to WM, see http://stackoverflow.com/questions/7408082/how-to-get-the-width-of-a-window-frame-before-creating-any-windows ). The real form bounds can be obtained from X11 only after the form has been shown.

Issue History

Date Modified Username Field Change
2015-04-02 06:06 Alexey Tor. New Issue
2015-04-02 06:06 Alexey Tor. File Added: indent-incorr.png
2015-04-03 15:39 Alexey Tor. Note Added: 0082567
2015-04-03 16:16 Bart Broersma Relationship added related to 0020952
2016-01-01 20:20 Janusz Tomczak File Added: customform.inc.patch
2016-01-01 20:26 Janusz Tomczak Note Added: 0088507
2016-01-01 20:50 Alexey Tor. Note Added: 0088508
2016-01-01 20:50 Alexey Tor. Note Edited: 0088508 View Revisions
2016-01-01 23:28 Bart Broersma Note Added: 0088513
2016-01-02 01:47 Janusz Tomczak Note Added: 0088517
2016-01-02 09:17 Ondrej Pokorny Assigned To => Ondrej Pokorny
2016-01-02 09:17 Ondrej Pokorny Status new => assigned
2016-01-02 10:15 Ondrej Pokorny Fixed in Revision => 51111
2016-01-02 10:15 Ondrej Pokorny LazTarget => 1.8
2016-01-02 10:15 Ondrej Pokorny Note Added: 0088518
2016-01-02 10:15 Ondrej Pokorny Status assigned => resolved
2016-01-02 10:15 Ondrej Pokorny Fixed in Version => 1.7 (SVN)
2016-01-02 10:15 Ondrej Pokorny Resolution open => fixed
2016-01-02 10:15 Ondrej Pokorny Target Version => 1.8
2016-01-11 13:45 Ondrej Pokorny Relationship added related to 0029371
2016-03-24 14:20 Ondrej Pokorny Relationship added related to 0029887