浏览代码

Bug 1702: User name edit box on Login dialog in some cases does not include modification commands (like Paste)

https://winscp.net/tracker/1702

Source commit: 2cc51eff1e4839e3594ca5f319cbeb11bfb4c592
Martin Prikryl 7 年之前
父节点
当前提交
fda93b37c5
共有 1 个文件被更改,包括 23 次插入20 次删除
  1. 23 20
      source/windows/VCLCommon.cpp

+ 23 - 20
source/windows/VCLCommon.cpp

@@ -281,30 +281,22 @@ void __fastcall EnableControl(TControl * Control, bool Enable)
   }
 };
 //---------------------------------------------------------------------------
+void __fastcall DoReadOnlyControl(TControl * Control, bool ReadOnly, bool Color);
+//---------------------------------------------------------------------------
 void __fastcall ReadOnlyAndEnabledControl(TControl * Control, bool ReadOnly, bool Enabled)
 {
-  if (dynamic_cast<TCustomEdit *>(Control) != NULL)
+  // Change color only in only one of EnableControl and DoReadOnlyControl to prevent flicker
+  if (ReadOnly)
   {
     DebugAssert(dynamic_cast<TWinControl *>(Control)->ControlCount == 0);
-    DebugAssert(dynamic_cast<TMemo *>(Control) == NULL);
-
-    if (ReadOnly)
-    {
-      Control->Enabled = Enabled;
-      ReadOnlyControl(Control, true);
-    }
-    else
-    {
-      // ReadOnlyControl(..., false) would set color to clWindow,
-      // but we want to reflect the Enabled state and avoid flicker.
-      ((TEdit*)Control)->ReadOnly = false;
-
-      EnableControl(Control, Enabled);
-    }
+    // As EnableControl, but with no color change
+    Control->Enabled = Enabled;
+    DoReadOnlyControl(Control, ReadOnly, true);
   }
   else
   {
-    DebugFail();
+    DoReadOnlyControl(Control, ReadOnly, false);
+    EnableControl(Control, Enabled);
   }
 }
 //---------------------------------------------------------------------------
@@ -317,7 +309,7 @@ static void __fastcall ReadOnlyEditContextPopup(void * /*Data*/, TObject * Sende
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
+void __fastcall DoReadOnlyControl(TControl * Control, bool ReadOnly, bool Color)
 {
   if (dynamic_cast<TCustomEdit *>(Control) != NULL)
   {
@@ -326,7 +318,10 @@ void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
     TMemo * Memo = dynamic_cast<TMemo *>(Control);
     if (ReadOnly)
     {
-      SetParentColor(Control);
+      if (Color)
+      {
+        SetParentColor(Control);
+      }
       if (Memo != NULL)
       {
         // Is true by default and makes the control swallow not only
@@ -357,7 +352,10 @@ void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
     }
     else
     {
-      Edit->Color = clWindow;
+      if (Color)
+      {
+        Edit->Color = clWindow;
+      }
       // not supported atm, we need to persist previous value of WantReturns
       DebugAssert(Memo == NULL);
 
@@ -378,6 +376,11 @@ void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
+{
+  DoReadOnlyControl(Control, ReadOnly, true);
+}
+//---------------------------------------------------------------------------
 // Some of MainFormLike code can now be obsolete, thanks to Application->OnGetMainFormHandle.
 static TForm * MainLikeForm = NULL;
 //---------------------------------------------------------------------------