Browse Source

Bug 1748: Failure when undocking toolbar on a system with multiple monitors with different DPI

https://winscp.net/tracker/1748
(cherry picked from commit 896a72c0d549a07f4f31ece9730138e9bc2c22ce)

Source commit: 6042b9da7af371d60484205ad98f5c14388373f1
Martin Prikryl 6 years ago
parent
commit
152555ade4
1 changed files with 15 additions and 2 deletions
  1. 15 2
      source/packages/tbx/TBX.pas

+ 15 - 2
source/packages/tbx/TBX.pas

@@ -2607,7 +2607,11 @@ procedure TTBXToolbar.SetParent(AParent: TWinControl);
 begin
   inherited;
   if AParent is TTBXFloatingWindowParent then
+  begin
     TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
+    // See the comment in TTBXToolbar.Rebuild
+    Rebuild;
+  end;
 end;
 
 procedure TTBXToolbar.SetSnapDistance(Value: Integer);
@@ -2640,8 +2644,17 @@ end;
 
 procedure TTBXToolbar.Rebuild;
 begin
-  if Floating then UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self))
-    else UpdateNCArea(Self, GetWinViewType(Self));
+  if Floating then
+  begin
+    // Is not set yet, when called from within SetParent > WMDpiChangedAfterParent while undocking on
+    // per-monitor-DPI system. We will call Rebuild again at the end of the SetParent
+    if Assigned(Parent) then
+      UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self));
+  end
+    else
+  begin
+    UpdateNCArea(Self, GetWinViewType(Self));
+  end;
   Invalidate;
   Arrange;
 end;