1
0
Эх сурвалжийг харах

Bug fix: When minimizing command-line operation, task bar button was hidden

Source commit: fb140c2372095e81c41b4f055a93fde198458bdc
Martin Prikryl 7 жил өмнө
parent
commit
6f2e21efc9

+ 40 - 19
source/windows/WinInterface.cpp

@@ -1370,36 +1370,57 @@ void __fastcall CallGlobalMinimizeHandler(TObject * Sender)
 //---------------------------------------------------------------------------
 static void __fastcall DoApplicationMinimizeRestore(bool Minimize)
 {
-  // WORKAROUND
-  // When main window is hidden (command-line operation),
-  // we do not want it to be shown by TApplication.Restore,
-  // so we temporarily detach it from an application.
-  // Probably not really necessary for minimizing phase,
-  // but we do it for consistency anyway.
   TForm * MainForm = Application->MainForm;
-  bool RestoreMainForm = false;
-  if (DebugAlwaysTrue(MainForm != NULL) &&
-      !MainForm->Visible)
-  {
-    SetAppMainForm(NULL);
-    RestoreMainForm = true;
-  }
-  try
+  TForm * MainLikeForm = GetMainForm();
+  if ((MainLikeForm != MainForm) && !WinConfiguration->MinimizeToTray)
   {
+    TWindowState PreviousWindowState;
     if (Minimize)
     {
-      Application->Minimize();
+      PreviousWindowState = MainLikeForm->WindowState;
+      MainLikeForm->WindowState = wsMinimized;
     }
     else
     {
-      Application->Restore();
+      MainLikeForm->WindowState = PreviousWindowState;
     }
   }
-  __finally
+  else
   {
-    if (RestoreMainForm)
+    // What is described below should not ever happen, except when minimizing to tray,
+    // as we capture command-line operation above.
+    // Had we called TApplication::Minimize, it would hide all non-MainForm windows, including MainLineForm,
+    // so it actually also hides taskbar button, what we do not want.
+    // WORKAROUND
+    // When main window is hidden (command-line operation),
+    // we do not want it to be shown by TApplication.Restore,
+    // so we temporarily detach it from an application.
+    // Probably not really necessary for minimizing phase,
+    // but we do it for consistency anyway.
+    bool RestoreMainForm = false;
+    if (DebugAlwaysTrue(MainForm != NULL) &&
+        !MainForm->Visible)
+    {
+      SetAppMainForm(NULL);
+      RestoreMainForm = true;
+    }
+    try
+    {
+      if (Minimize)
+      {
+        Application->Minimize();
+      }
+      else
+      {
+        Application->Restore();
+      }
+    }
+    __finally
     {
-      SetAppMainForm(MainForm);
+      if (RestoreMainForm)
+      {
+        SetAppMainForm(MainForm);
+      }
     }
   }
 }