浏览代码

Bug 1455: Move main window with Login dialog

https://winscp.net/tracker/1455

Source commit: b165f9f9a2246a03c448a1946dd26fa87548c058
Martin Prikryl 9 年之前
父节点
当前提交
47eac93da5

+ 2 - 2
source/forms/CustomScpExplorer.cpp

@@ -497,7 +497,7 @@ bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
       UnicodeString SessionName = Params.Param[1];
       UnicodeString SessionName = Params.Param[1];
       std::unique_ptr<TObjectList> DataList(new TObjectList());
       std::unique_ptr<TObjectList> DataList(new TObjectList());
       UnicodeString DownloadFile; // unused
       UnicodeString DownloadFile; // unused
-      GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true);
+      GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
       if (DataList->Count > 0)
       if (DataList->Count > 0)
       {
       {
         TTerminalManager * Manager = TTerminalManager::Instance();
         TTerminalManager * Manager = TTerminalManager::Instance();
@@ -5798,7 +5798,7 @@ void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
 {
 {
   try
   try
   {
   {
-    TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions);
+    TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
   }
   }
   __finally
   __finally
   {
   {

+ 23 - 3
source/forms/Login.cpp

@@ -34,14 +34,14 @@ const int WorkspaceImageIndex = 4;
 const int NewSiteImageIndex = 6;
 const int NewSiteImageIndex = 6;
 const int SiteColorMaskImageIndex = 8;
 const int SiteColorMaskImageIndex = 8;
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-bool __fastcall DoLoginDialog(TStoredSessionList *SessionList, TList * DataList)
+bool __fastcall DoLoginDialog(TStoredSessionList *SessionList, TList * DataList, TForm * LinkedForm)
 {
 {
   DebugAssert(DataList != NULL);
   DebugAssert(DataList != NULL);
   TLoginDialog * LoginDialog = SafeFormCreate<TLoginDialog>();
   TLoginDialog * LoginDialog = SafeFormCreate<TLoginDialog>();
   bool Result;
   bool Result;
   try
   try
   {
   {
-    LoginDialog->Init(SessionList);
+    LoginDialog->Init(SessionList, LinkedForm);
     Result = LoginDialog->Execute(DataList);
     Result = LoginDialog->Execute(DataList);
   }
   }
   __finally
   __finally
@@ -71,6 +71,7 @@ __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
   FLoading = false;
   FLoading = false;
   FSortEnablePending = false;
   FSortEnablePending = false;
   FSiteSearch = ssSiteName;
   FSiteSearch = ssSiteName;
+  FLinkedForm = NULL;
 
 
   // we need to make sure that window procedure is set asap
   // we need to make sure that window procedure is set asap
   // (so that CM_SHOWINGCHANGED handling is applied)
   // (so that CM_SHOWINGCHANGED handling is applied)
@@ -94,9 +95,10 @@ void __fastcall TLoginDialog::InvalidateSessionData()
   FSessionData = NULL;
   FSessionData = NULL;
 }
 }
 //---------------------------------------------------------------------
 //---------------------------------------------------------------------
-void __fastcall TLoginDialog::Init(TStoredSessionList *SessionList)
+void __fastcall TLoginDialog::Init(TStoredSessionList *SessionList, TForm * LinkedForm)
 {
 {
   FStoredSessions = SessionList;
   FStoredSessions = SessionList;
+  FLinkedForm = LinkedForm;
   LoadSessions();
   LoadSessions();
   UnicodeString Dummy;
   UnicodeString Dummy;
   RunPageantAction->Visible = FindTool(PageantTool, Dummy);
   RunPageantAction->Visible = FindTool(PageantTool, Dummy);
@@ -1517,6 +1519,20 @@ void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
   TForm::Dispatch(&Message);
   TForm::Dispatch(&Message);
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+void __fastcall TLoginDialog::WMMoving(TMessage & Message)
+{
+  TForm::Dispatch(&Message);
+
+  if (FLinkedForm != NULL)
+  {
+    RECT & Rect = *reinterpret_cast<RECT*>(Message.LParam);
+    FLinkedForm->SetBounds(
+      FLinkedForm->Left + (Rect.left - Left),
+      FLinkedForm->Top + (Rect.top - Top),
+      FLinkedForm->Width, FLinkedForm->Height);
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TLoginDialog::Dispatch(void * Message)
 void __fastcall TLoginDialog::Dispatch(void * Message)
 {
 {
   TMessage * M = reinterpret_cast<TMessage*>(Message);
   TMessage * M = reinterpret_cast<TMessage*>(Message);
@@ -1551,6 +1567,10 @@ void __fastcall TLoginDialog::Dispatch(void * Message)
       TForm::Dispatch(Message);
       TForm::Dispatch(Message);
     }
     }
   }
   }
+  else if (M->Msg == WM_MOVING)
+  {
+    WMMoving(*M);
+  }
   else
   else
   {
   {
     TForm::Dispatch(Message);
     TForm::Dispatch(Message);

+ 3 - 1
source/forms/Login.h

@@ -307,6 +307,7 @@ private:
   bool FSortEnablePending;
   bool FSortEnablePending;
   std::unique_ptr<TImageList> FButtonImageList;
   std::unique_ptr<TImageList> FButtonImageList;
   TSiteSearch FSiteSearch;
   TSiteSearch FSiteSearch;
+  TForm * FLinkedForm;
 
 
   void __fastcall LoadSession(TSessionData * SessionData);
   void __fastcall LoadSession(TSessionData * SessionData);
   void __fastcall LoadContents();
   void __fastcall LoadContents();
@@ -388,6 +389,7 @@ private:
   void __fastcall ResetNewSiteData();
   void __fastcall ResetNewSiteData();
   TModalResult __fastcall DefaultResult();
   TModalResult __fastcall DefaultResult();
   int __fastcall AddLoginButtonImage(bool Enabled);
   int __fastcall AddLoginButtonImage(bool Enabled);
+  void __fastcall WMMoving(TMessage & Message);
 
 
 protected:
 protected:
   void __fastcall Default();
   void __fastcall Default();
@@ -406,7 +408,7 @@ protected:
 public:
 public:
   virtual __fastcall TLoginDialog(TComponent* AOwner);
   virtual __fastcall TLoginDialog(TComponent* AOwner);
   __fastcall ~TLoginDialog();
   __fastcall ~TLoginDialog();
-  void __fastcall Init(TStoredSessionList *SessionList);
+  void __fastcall Init(TStoredSessionList *SessionList, TForm * LinkedForm);
   bool __fastcall Execute(TList * DataList);
   bool __fastcall Execute(TList * DataList);
 };
 };
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------

+ 2 - 2
source/windows/TerminalManager.cpp

@@ -1317,7 +1317,7 @@ void __fastcall TTerminalManager::OpenInPutty()
   }
   }
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-void __fastcall TTerminalManager::NewSession(bool /*FromSite*/, const UnicodeString & SessionUrl, bool ReloadSessions)
+void __fastcall TTerminalManager::NewSession(bool /*FromSite*/, const UnicodeString & SessionUrl, bool ReloadSessions, TForm * LinkedForm)
 {
 {
   if (ReloadSessions)
   if (ReloadSessions)
   {
   {
@@ -1327,7 +1327,7 @@ void __fastcall TTerminalManager::NewSession(bool /*FromSite*/, const UnicodeStr
   UnicodeString DownloadFile; // unused
   UnicodeString DownloadFile; // unused
   std::unique_ptr<TObjectList> DataList(new TObjectList());
   std::unique_ptr<TObjectList> DataList(new TObjectList());
 
 
-  GetLoginData(SessionUrl, NULL, DataList.get(), DownloadFile, true);
+  GetLoginData(SessionUrl, NULL, DataList.get(), DownloadFile, true, LinkedForm);
 
 
   if (DataList->Count > 0)
   if (DataList->Count > 0)
   {
   {

+ 1 - 1
source/windows/TerminalManager.h

@@ -53,7 +53,7 @@ public:
   void __fastcall UpdateAppTitle();
   void __fastcall UpdateAppTitle();
   bool __fastcall CanOpenInPutty();
   bool __fastcall CanOpenInPutty();
   void __fastcall OpenInPutty();
   void __fastcall OpenInPutty();
-  void __fastcall NewSession(bool FromSite, const UnicodeString & SessionUrl, bool ReloadSessions = true);
+  void __fastcall NewSession(bool FromSite, const UnicodeString & SessionUrl, bool ReloadSessions = true, TForm * LinkedForm = NULL);
   void __fastcall Idle();
   void __fastcall Idle();
   UnicodeString __fastcall TerminalTitle(TTerminal * Terminal);
   UnicodeString __fastcall TerminalTitle(TTerminal * Terminal);
   void __fastcall HandleException(Exception * E);
   void __fastcall HandleException(Exception * E);

+ 2 - 2
source/windows/WinInterface.h

@@ -141,7 +141,7 @@ bool __fastcall DoChangeMasterPasswordDialog(UnicodeString & NewPassword);
 // windows\WinMain.cpp
 // windows\WinMain.cpp
 int __fastcall Execute();
 int __fastcall Execute();
 void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
 void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
-  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession);
+  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm);
 
 
 // forms\InputDlg.cpp
 // forms\InputDlg.cpp
 struct TInputDialogData
 struct TInputDialogData
@@ -210,7 +210,7 @@ bool __fastcall DoImportSessionsDialog(TList * Imported);
 enum TLicense { lcNoLicense = -1, lcWinScp, lcExpat };
 enum TLicense { lcNoLicense = -1, lcWinScp, lcExpat };
 void __fastcall DoLicenseDialog(TLicense License);
 void __fastcall DoLicenseDialog(TLicense License);
 
 
-bool __fastcall DoLoginDialog(TStoredSessionList * SessionList, TList * DataList);
+bool __fastcall DoLoginDialog(TStoredSessionList * SessionList, TList * DataList, TForm * LinkedForm);
 
 
   // forms\SiteAdvanced.cpp
   // forms\SiteAdvanced.cpp
 bool __fastcall DoSiteAdvancedDialog(TSessionData * SessionData);
 bool __fastcall DoSiteAdvancedDialog(TSessionData * SessionData);

+ 3 - 3
source/windows/WinMain.cpp

@@ -24,7 +24,7 @@
 #pragma package(smart_init)
 #pragma package(smart_init)
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
 void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
-  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession)
+  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm)
 {
 {
   bool DefaultsOnly = false;
   bool DefaultsOnly = false;
 
 
@@ -85,7 +85,7 @@ void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
     // - the specified session does not contain enough information to login [= not even hostname]
     // - the specified session does not contain enough information to login [= not even hostname]
 
 
     DebugAssert(DataList->Count <= 1);
     DebugAssert(DataList->Count <= 1);
-    if (!DoLoginDialog(StoredSessions, DataList))
+    if (!DoLoginDialog(StoredSessions, DataList, LinkedForm))
     {
     {
       Abort();
       Abort();
     }
     }
@@ -979,7 +979,7 @@ int __fastcall Execute()
         TObjectList * DataList = new TObjectList();
         TObjectList * DataList = new TObjectList();
         try
         try
         {
         {
-          GetLoginData(AutoStartSession, Params, DataList, DownloadFile, NeedSession);
+          GetLoginData(AutoStartSession, Params, DataList, DownloadFile, NeedSession, NULL);
           // GetLoginData now Aborts when session is needed and none is selected
           // GetLoginData now Aborts when session is needed and none is selected
           if (DebugAlwaysTrue(!NeedSession || (DataList->Count > 0)))
           if (DebugAlwaysTrue(!NeedSession || (DataList->Count > 0)))
           {
           {