Browse Source

Bug 1539: Failure when opening Synchronization checklist window

https://winscp.net/tracker/1539

Source commit: a65104fe862bc6295928338b7f9a429df66fe6bb
Martin Prikryl 8 years ago
parent
commit
359b54232e

+ 18 - 6
source/forms/SynchronizeChecklist.cpp

@@ -163,8 +163,21 @@ void __fastcall TSynchronizeChecklistDialog::UpdateControls()
   SelectAllAction->Enabled = (ListView->SelCount < ListView->Items->Count);
 }
 //---------------------------------------------------------------------------
+bool __fastcall TSynchronizeChecklistDialog::GetWindowParams(UnicodeString & WindowParams)
+{
+  WindowParams = CustomWinConfiguration->SynchronizeChecklist.WindowParams;
+  bool CustomPos = (StrToIntDef(CutToChar(WindowParams, L';', true), 0) != 0);
+  return CustomPos || (Application->MainForm == NULL);
+}
+//---------------------------------------------------------------------------
 void __fastcall TSynchronizeChecklistDialog::CreateParams(TCreateParams & Params)
 {
+  UnicodeString WindowParams;
+  if (GetWindowParams(WindowParams))
+  {
+    // This is only to set correct TForm::Position. Actual bounds are set later after DPI scaling
+    RestoreForm(WindowParams, this, true);
+  }
   TForm::CreateParams(Params);
 }
 //---------------------------------------------------------------------------
@@ -393,19 +406,18 @@ void __fastcall TSynchronizeChecklistDialog::FormShow(TObject * /*Sender*/)
   // Moved here form CreateParams (see also TEditorForm::CreateParams), because there it breaks per-monitor DPI.
   // For example BoundsRect is matched to the main form too soon, so it gets rescaled later.
   // Also it happens before constructor, what causes UseDesktopFont-flagged controls to rescale twice.
+  // But Position is already set in the CreateParams, as it cannot be set here anymore.
   if (!FFormRestored)
   {
     FFormRestored = True;
-    UnicodeString WindowParams = CustomWinConfiguration->SynchronizeChecklist.WindowParams;
-    bool CustomPos = (StrToIntDef(CutToChar(WindowParams, L';', true), 0) != 0);
-
-    if (!CustomPos && (Application->MainForm != NULL))
+    UnicodeString WindowParams;
+    if (GetWindowParams(WindowParams))
     {
-      BoundsRect = Application->MainForm->BoundsRect;
+      RestoreForm(WindowParams, this);
     }
     else
     {
-      RestoreForm(WindowParams, this);
+      BoundsRect = Application->MainForm->BoundsRect;
     }
   }
 

+ 1 - 0
source/forms/SynchronizeChecklist.h

@@ -136,6 +136,7 @@ protected:
   virtual void __fastcall Dispatch(void * Message);
   void __fastcall UpdateImages();
   void __fastcall CMDpiChanged(TMessage & Message);
+  bool __fastcall GetWindowParams(UnicodeString & WindowParams);
   static int __fastcall CompareNumber(__int64 Value1, __int64 Value2);
 };
 //----------------------------------------------------------------------------

+ 17 - 8
source/windows/Tools.cpp

@@ -167,7 +167,7 @@ void __fastcall LoadListViewStr(TListView * ListView, UnicodeString ALayoutStr)
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall RestoreForm(UnicodeString Data, TForm * Form)
+void __fastcall RestoreForm(UnicodeString Data, TForm * Form, bool PositionOnly)
 {
   DebugAssert(Form);
   if (!Data.IsEmpty())
@@ -237,25 +237,34 @@ void __fastcall RestoreForm(UnicodeString Data, TForm * Form)
         {
           // when positioning on non-primary monitor, we need
           // to handle that ourselves, so place window to center
-          Form->SetBounds(Monitor->Left + ((Monitor->Width - Bounds.Width()) / 2),
-            Monitor->Top + ((Monitor->Height - Bounds.Height()) / 2),
-            Bounds.Width(), Bounds.Height());
+          if (!PositionOnly)
+          {
+            Form->SetBounds(Monitor->Left + ((Monitor->Width - Bounds.Width()) / 2),
+              Monitor->Top + ((Monitor->Height - Bounds.Height()) / 2),
+              Bounds.Width(), Bounds.Height());
+          }
           Form->Position = poDesigned;
         }
       }
       else
       {
         Form->Position = poDesigned;
-        Form->BoundsRect = Bounds;
+        if (!PositionOnly)
+        {
+          Form->BoundsRect = Bounds;
+        }
       }
     }
     else if (State == wsMaximized)
     {
       Form->Position = poDesigned;
 
-      Bounds = Form->BoundsRect;
-      OffsetRect(Bounds, Monitor->Left, Monitor->Top);
-      Form->BoundsRect = Bounds;
+      if (!PositionOnly)
+      {
+        Bounds = Form->BoundsRect;
+        OffsetRect(Bounds, Monitor->Left, Monitor->Top);
+        Form->BoundsRect = Bounds;
+      }
     }
   }
   else if (Form->Position == poDesigned)

+ 1 - 1
source/windows/Tools.h

@@ -27,7 +27,7 @@ IShellLink * __fastcall CreateDesktopSessionShortCut(
   int SpecialFolder = -1, int IconIndex = SITE_ICON, bool Return = false);
 UnicodeString __fastcall GetListViewStr(TListView * ListView);
 void __fastcall LoadListViewStr(TListView * ListView, UnicodeString LayoutStr);
-void __fastcall RestoreForm(UnicodeString Data, TForm * Form);
+void __fastcall RestoreForm(UnicodeString Data, TForm * Form, bool PositionOnly = false);
 UnicodeString __fastcall StoreForm(TCustomForm * Form);
 void __fastcall RestoreFormSize(UnicodeString Data, TForm * Form);
 UnicodeString __fastcall StoreFormSize(TForm * Form);