Bläddra i källkod

Issue 2305 – Open window maximized when closed while minimized from maximized state

https://winscp.net/tracker/2305

Source commit: b35bb6aad0947c521784208ed8d51c8857bbc771
Martin Prikryl 1 år sedan
förälder
incheckning
ecf8d35436

+ 3 - 0
source/forms/CustomScpExplorer.cpp

@@ -299,6 +299,7 @@ __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
 //---------------------------------------------------------------------------
 __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
 {
+  AppLog(L"Destroying main window");
   FInvalid = true;
   ReleaseHiContrastTheme();
   if (FClipboardTerminal != NULL)
@@ -350,6 +351,7 @@ __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
     // particularly window site is not restored correctly (BoundsRect value set
     // in RestoreForm gets lost during handle allocation), so we do not want
     // it to be stored
+    AppLog(L"Storing main window configuration");
     StoreParams();
   }
   ManagedSession = NULL;
@@ -390,6 +392,7 @@ __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
     DestroyWindow(FHiddenWindow);
     FHiddenWindow = NULL;
   }
+  AppLog(L"Main window destroyed");
 
 }
 //---------------------------------------------------------------------------

+ 2 - 4
source/windows/Tools.cpp

@@ -325,7 +325,7 @@ void __fastcall RestoreForm(UnicodeString Data, TForm * Form, bool PositionOnly)
   }
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall StoreForm(TCustomForm * Form)
+UnicodeString __fastcall StoreForm(TForm * Form)
 {
   DebugAssert(Form);
   TRect Bounds = Form->BoundsRect;
@@ -334,9 +334,7 @@ UnicodeString __fastcall StoreForm(TCustomForm * Form)
     FORMAT(L"%d;%d;%d;%d;%d;%s", (SaveDimension(Bounds.Left), SaveDimension(Bounds.Top),
       SaveDimension(Bounds.Right), SaveDimension(Bounds.Bottom),
       // we do not want WinSCP to start minimized next time (we cannot handle that anyway).
-      // note that WindowState is wsNormal when window in minimized for some reason.
-      // actually it is wsMinimized only when minimized by MSVDM
-      (int)(Form->WindowState == wsMinimized ? wsNormal : Form->WindowState),
+      (int)(Form->WindowState == wsMinimized ? GetWindowStateBeforeMimimize(Form) : Form->WindowState),
       SavePixelsPerInch(Form)));
   return Result;
 }

+ 1 - 1
source/windows/Tools.h

@@ -30,7 +30,7 @@ IShellLink * __fastcall CreateDesktopSessionShortCut(
 UnicodeString __fastcall GetListViewStr(TListView * ListView);
 void __fastcall LoadListViewStr(TListView * ListView, UnicodeString LayoutStr);
 void __fastcall RestoreForm(UnicodeString Data, TForm * Form, bool PositionOnly = false);
-UnicodeString __fastcall StoreForm(TCustomForm * Form);
+UnicodeString __fastcall StoreForm(TForm * Form);
 void __fastcall RestoreFormSize(UnicodeString Data, TForm * Form);
 UnicodeString __fastcall StoreFormSize(TForm * Form);
 TFontStyles __fastcall IntToFontStyles(int value);

+ 44 - 26
source/windows/VCLCommon.cpp

@@ -615,58 +615,60 @@ static void __fastcall ChangeControlScale(TControl * Control, int M, int D)
 typedef std::pair<int, int> TRatio;
 typedef std::map<TRatio, TRatio > TRatioMap;
 //---------------------------------------------------------------------------
-class TFormRescaleComponent : public TComponent
+class TFormCustomizationComponent : public TComponent
 {
 public:
-  __fastcall TFormRescaleComponent() :
+  __fastcall TFormCustomizationComponent() :
     TComponent(NULL)
   {
     ImplicitRescaleAdded = false;
     Rescaling = false;
+    WindowStateBeforeMimimize = wsNormal;
   }
 
   bool Rescaling;
   bool ImplicitRescaleAdded;
   TRatioMap RatioMap;
+  TWindowState WindowStateBeforeMimimize;
 };
 //---------------------------------------------------------------------------
-static TFormRescaleComponent * GetFormRescaleComponent(TForm * Form)
+static TFormCustomizationComponent * GetFormCustomizationComponent(TForm * Form)
 {
-  TFormRescaleComponent * FormRescaleComponent =
-    dynamic_cast<TFormRescaleComponent *>(Form->FindComponent(TFormRescaleComponent::QualifiedClassName()));
-  if (FormRescaleComponent == NULL)
+  TFormCustomizationComponent * FormCustomizationComponent =
+    dynamic_cast<TFormCustomizationComponent *>(Form->FindComponent(TFormCustomizationComponent::QualifiedClassName()));
+  if (FormCustomizationComponent == NULL)
   {
-    FormRescaleComponent = new TFormRescaleComponent();
-    FormRescaleComponent->Name = TFormRescaleComponent::QualifiedClassName();
-    Form->InsertComponent(FormRescaleComponent);
+    FormCustomizationComponent = new TFormCustomizationComponent();
+    FormCustomizationComponent->Name = TFormCustomizationComponent::QualifiedClassName();
+    Form->InsertComponent(FormCustomizationComponent);
   }
-  return FormRescaleComponent;
+  return FormCustomizationComponent;
 }
 //---------------------------------------------------------------------------
 void __fastcall RecordFormImplicitRescale(TForm * Form)
 {
   if (Form->Scaled)
   {
-    TFormRescaleComponent * FormRescaleComponent = GetFormRescaleComponent(Form);
-    if (!FormRescaleComponent->ImplicitRescaleAdded)
+    TFormCustomizationComponent * FormCustomizationComponent = GetFormCustomizationComponent(Form);
+    if (!FormCustomizationComponent->ImplicitRescaleAdded)
     {
       TRatio Ratio;
       GetFormScaleRatio(Form, Ratio.first, Ratio.second);
       TRatio RescaleKeyRatio(Form->PixelsPerInch, USER_DEFAULT_SCREEN_DPI);
-      FormRescaleComponent->RatioMap[RescaleKeyRatio] = Ratio;
-      FormRescaleComponent->ImplicitRescaleAdded = true;
+      FormCustomizationComponent->RatioMap[RescaleKeyRatio] = Ratio;
+      FormCustomizationComponent->ImplicitRescaleAdded = true;
     }
   }
 }
 //---------------------------------------------------------------------------
 static void GetFormRescaleRatio(TForm * Form, int PixelsPerInch, int & M, int & D)
 {
-  TFormRescaleComponent * FormRescaleComponent = GetFormRescaleComponent(Form);
+  TFormCustomizationComponent * FormCustomizationComponent = GetFormCustomizationComponent(Form);
   TRatio ReverseRescaleKeyRatio(Form->PixelsPerInch, PixelsPerInch);
-  if (FormRescaleComponent->RatioMap.count(ReverseRescaleKeyRatio) > 0)
+  if (FormCustomizationComponent->RatioMap.count(ReverseRescaleKeyRatio) > 0)
   {
-    M = FormRescaleComponent->RatioMap[ReverseRescaleKeyRatio].second;
-    D = FormRescaleComponent->RatioMap[ReverseRescaleKeyRatio].first;
+    M = FormCustomizationComponent->RatioMap[ReverseRescaleKeyRatio].second;
+    D = FormCustomizationComponent->RatioMap[ReverseRescaleKeyRatio].first;
   }
   else
   {
@@ -676,20 +678,20 @@ static void GetFormRescaleRatio(TForm * Form, int PixelsPerInch, int & M, int &
 
 
   TRatio RescaleKeyRatio(PixelsPerInch, Form->PixelsPerInch);
-  FormRescaleComponent->RatioMap[RescaleKeyRatio] = TRatio(M, D);
+  FormCustomizationComponent->RatioMap[RescaleKeyRatio] = TRatio(M, D);
 }
 //---------------------------------------------------------------------------
 static void __fastcall ChangeFormPixelsPerInch(TForm * Form, int PixelsPerInch)
 {
   RecordFormImplicitRescale(Form);
 
-  TFormRescaleComponent * FormRescaleComponent = GetFormRescaleComponent(Form);
+  TFormCustomizationComponent * FormCustomizationComponent = GetFormCustomizationComponent(Form);
 
   if ((Form->PixelsPerInch != PixelsPerInch) && // optimization
-      !FormRescaleComponent->Rescaling)
+      !FormCustomizationComponent->Rescaling)
   {
     AppLogFmt(L"Scaling window %s", (Form->Caption));
-    TAutoFlag RescalingFlag(FormRescaleComponent->Rescaling);
+    TAutoFlag RescalingFlag(FormCustomizationComponent->Rescaling);
 
     int M, D;
     GetFormRescaleRatio(Form, PixelsPerInch, M, D);
@@ -886,6 +888,11 @@ static void __fastcall FormShowingChanged(TForm * Form, TWndMethod WndProc, TMes
   }
 }
 //---------------------------------------------------------------------------
+TWindowState GetWindowStateBeforeMimimize(TForm * Form)
+{
+  return GetFormCustomizationComponent(Form)->WindowStateBeforeMimimize;
+}
+//---------------------------------------------------------------------------
 static TCustomForm * WindowPrintForm = NULL;
 static DWORD WindowPrintPrevClick = 0;
 static unsigned int WindowPrintClickCount = 0;
@@ -964,11 +971,22 @@ inline void __fastcall DoFormWindowProc(TCustomForm * Form, TWndMethod WndProc,
 {
   TForm * AForm = dynamic_cast<TForm *>(Form);
   DebugAssert(AForm != NULL);
-  if ((Message.Msg == WM_SYSCOMMAND) &&
-      (Message.WParam == SC_CONTEXTHELP))
+  if (Message.Msg == WM_SYSCOMMAND)
   {
-    FormHelp(Form);
-    Message.Result = 1;
+    if (Message.WParam == SC_CONTEXTHELP)
+    {
+      FormHelp(Form);
+      Message.Result = 1;
+    }
+    else if (Message.WParam == SC_MINIMIZE)
+    {
+      GetFormCustomizationComponent(AForm)->WindowStateBeforeMimimize = Form->WindowState;
+      WndProc(Message);
+    }
+    else
+    {
+      WndProc(Message);
+    }
   }
   else if (Message.Msg == CM_SHOWINGCHANGED)
   {

+ 1 - 0
source/windows/VCLCommon.h

@@ -90,6 +90,7 @@ typedef void __fastcall (*TRescaleEvent)(TComponent * Sender, TObject * Token);
 void __fastcall SetRescaleFunction(
   TComponent * Component, TRescaleEvent OnRescale, TObject * Token = NULL, bool OwnsToken = false);
 void __fastcall RecordFormImplicitRescale(TForm * Form);
+TWindowState GetWindowStateBeforeMimimize(TForm * Form);
 void __fastcall CountClicksForWindowPrint(TForm * Form);
 bool IsButtonBeingClicked(TButtonControl * Button);
 bool IsCancelButtonBeingClicked(TControl * Control);