Browse Source

TPasswordEdit is not needed as VCL supports ES_PASSWORD style with TEdit

... and did already in XE6.
Getting rid of TPasswordEdit will also make it easier to subclass edits by reducing number of classes in use.

Source commit: 0f32c7a6cdb1bab0c966215770ea923cfdae5c58
Martin Prikryl 5 months ago
parent
commit
27a9163e0b

+ 0 - 3
source/My.cbproj

@@ -131,9 +131,6 @@
         <DelphiCompile Include="packages\my\OperationWithTimeout.pas">
             <BuildOrder>22</BuildOrder>
         </DelphiCompile>
-        <DelphiCompile Include="packages\my\PasswordEdit.pas">
-            <BuildOrder>15</BuildOrder>
-        </DelphiCompile>
         <DelphiCompile Include="packages\my\PasTools.pas">
             <BuildOrder>16</BuildOrder>
         </DelphiCompile>

+ 2 - 3
source/forms/Authenticate.cpp

@@ -16,7 +16,6 @@
 #include <Tools.h>
 //---------------------------------------------------------------------------
 #pragma package(smart_init)
-#pragma link "PasswordEdit"
 #pragma resource "*.dfm"
 //---------------------------------------------------------------------------
 __fastcall TAuthenticateForm::TAuthenticateForm(TComponent * Owner)
@@ -230,8 +229,8 @@ TLabel * __fastcall TAuthenticateForm::GenerateLabel(int Current, UnicodeString
 //---------------------------------------------------------------------------
 TCustomEdit * __fastcall TAuthenticateForm::GenerateEdit(int Current, bool Echo)
 {
-  TCustomEdit * Result = (Echo ? static_cast<TCustomEdit *>(new TEdit(this)) :
-    static_cast<TCustomEdit *>(new TPasswordEdit(this)));
+  TEdit * Result = new TEdit(this);
+  SetEditPasswordMode(Result, !Echo);
   Result->Parent = FPromptParent;
 
   Result->Anchors = TAnchors() << akLeft << akTop << akRight;

+ 4 - 2
source/forms/Authenticate.dfm

@@ -123,22 +123,24 @@ object AuthenticateForm: TAuthenticateForm
         FocusControl = PromptEdit2
         WordWrap = True
       end
-      object PromptEdit1: TPasswordEdit
+      object PromptEdit1: TEdit
         Left = 8
         Top = 74
         Width = 400
         Height = 23
         Anchors = [akLeft, akTop, akRight]
         MaxLength = 250
+        PasswordChar = '*'
         TabOrder = 0
       end
-      object PromptEdit2: TPasswordEdit
+      object PromptEdit2: TEdit
         Left = 8
         Top = 121
         Width = 400
         Height = 23
         Anchors = [akLeft, akTop, akRight]
         MaxLength = 250
+        PasswordChar = '*'
         TabOrder = 1
       end
     end

+ 2 - 3
source/forms/Authenticate.h

@@ -8,7 +8,6 @@
 #include <Forms.hpp>
 #include <ComCtrls.hpp>
 #include <ExtCtrls.hpp>
-#include "PasswordEdit.hpp"
 #include "WinInterface.h"
 #include "GUITools.h"
 #include <System.Actions.hpp>
@@ -23,7 +22,7 @@ __published:
   TPanel *PasswordPanel;
   TPanel *PromptEditPanel;
   TLabel *PromptLabel1;
-  TPasswordEdit *PromptEdit1;
+  TEdit *PromptEdit1;
   TPanel *BannerPanel;
   TMemo *BannerMemo;
   TCheckBox *NeverShowAgainCheck;
@@ -37,7 +36,7 @@ __published:
   TButton *PasswordHelpButton;
   TLabel *InstructionsLabel;
   TLabel *PromptLabel2;
-  TPasswordEdit *PromptEdit2;
+  TEdit *PromptEdit2;
   TPanel *SessionRememberPasswordPanel;
   TCheckBox *SessionRememberPasswordCheck;
   TPanel *TopPanel;

+ 0 - 1
source/forms/Custom.cpp

@@ -22,7 +22,6 @@
 
 #include "Custom.h"
 //---------------------------------------------------------------------
-#pragma link "PasswordEdit"
 #pragma resource "*.dfm"
 //---------------------------------------------------------------------
 const int GroupBoxBorderWidth = 1;

+ 3 - 10
source/forms/InputDlg.cpp

@@ -8,7 +8,6 @@
 #include <Consts.hpp>
 #include <HistoryComboBox.hpp>
 #include <PasTools.hpp>
-#include <PasswordEdit.hpp>
 #include <Custom.h>
 //---------------------------------------------------------------------------
 #pragma package(smart_init)
@@ -29,7 +28,7 @@ private:
   bool FPathInput;
   TInputDialogInitialize FOnInitialize;
   TStrings * FHistory;
-  TCustomEdit * Edit;
+  TEdit * Edit;
   THistoryComboBox * HistoryCombo;
 };
 //---------------------------------------------------------------------------
@@ -49,14 +48,8 @@ __fastcall TInputDialog::TInputDialog(
   int MaxLength = FPathInput ? 0 : 255;
   if (History == NULL)
   {
-    if (Echo)
-    {
-      Edit = new TEdit(this);
-    }
-    else
-    {
-      Edit = new TPasswordEdit(this);
-    }
+    Edit = new TEdit(this);
+    SetEditPasswordMode(Edit, !Echo);
     HistoryCombo = NULL;
     AddEditLikeControl(Edit, Label);
     reinterpret_cast<TEdit *>(Edit)->MaxLength = MaxLength;

+ 0 - 1
source/forms/Login.cpp

@@ -23,7 +23,6 @@
 #include "S3FileSystem.h"
 //---------------------------------------------------------------------
 #pragma link "ComboEdit"
-#pragma link "PasswordEdit"
 #pragma link "UpDownEdit"
 #pragma resource "*.dfm"
 //---------------------------------------------------------------------------

+ 2 - 1
source/forms/Login.dfm

@@ -230,13 +230,14 @@ object LoginDialog: TLoginDialog
           Text = 'UserNameEdit'
           OnChange = DataChange
         end
-        object PasswordEdit: TPasswordEdit
+        object PasswordEdit: TEdit
           Left = 198
           Top = 134
           Width = 184
           Height = 23
           Anchors = [akLeft, akTop, akRight]
           MaxLength = 100
+          PasswordChar = '*'
           TabOrder = 8
           Text = 'PasswordEdit'
           OnChange = DataChange

+ 1 - 2
source/forms/Login.h

@@ -3,7 +3,6 @@
 #define LoginH
 //----------------------------------------------------------------------------
 #include "ComboEdit.hpp"
-#include "PasswordEdit.hpp"
 #include "UpDownEdit.hpp"
 #include "PngImageList.hpp"
 #include <System.Classes.hpp>
@@ -90,7 +89,7 @@ __published:
   TLabel *WebDavsLabel;
   TEdit *HostNameEdit;
   TEdit *UserNameEdit;
-  TPasswordEdit *PasswordEdit;
+  TEdit *PasswordEdit;
   TUpDownEdit *PortNumberEdit;
   TComboBox *TransferProtocolCombo;
   TComboBox *FtpsCombo;

+ 0 - 1
source/forms/SiteAdvanced.cpp

@@ -23,7 +23,6 @@
 #include "Authenticate.h"
 //---------------------------------------------------------------------
 #pragma link "ComboEdit"
-#pragma link "PasswordEdit"
 #pragma link "UpDownEdit"
 #pragma resource "*.dfm"
 //---------------------------------------------------------------------------

+ 6 - 3
source/forms/SiteAdvanced.dfm

@@ -522,13 +522,14 @@ object SiteAdvancedDialog: TSiteAdvancedDialog
             OnChange = DataChange
             OnExit = EncryptKeyEditExit
           end
-          object EncryptKeyPasswordEdit: TPasswordEdit
+          object EncryptKeyPasswordEdit: TEdit
             Left = 9
             Top = 40
             Width = 420
             Height = 23
             Anchors = [akLeft, akTop, akRight]
             MaxLength = 64
+            PasswordChar = '*'
             TabOrder = 0
             Text = 'EncryptKeyPasswordEdit'
             OnChange = DataChange
@@ -1575,13 +1576,14 @@ object SiteAdvancedDialog: TSiteAdvancedDialog
             Text = 'ProxyUsernameEdit'
             OnChange = DataChange
           end
-          object ProxyPasswordEdit: TPasswordEdit
+          object ProxyPasswordEdit: TEdit
             Left = 222
             Top = 113
             Width = 207
             Height = 23
             Anchors = [akLeft, akTop, akRight]
             MaxLength = 100
+            PasswordChar = '*'
             TabOrder = 6
             Text = 'ProxyPasswordEdit'
             OnChange = DataChange
@@ -1823,13 +1825,14 @@ object SiteAdvancedDialog: TSiteAdvancedDialog
             Text = 'TunnelUserNameEdit'
             OnChange = DataChange
           end
-          object TunnelPasswordEdit: TPasswordEdit
+          object TunnelPasswordEdit: TEdit
             Left = 222
             Top = 87
             Width = 207
             Height = 23
             Anchors = [akLeft, akTop, akRight]
             MaxLength = 100
+            PasswordChar = '*'
             TabOrder = 3
             Text = 'TunnelPasswordEdit'
             OnChange = DataChange

+ 3 - 4
source/forms/SiteAdvanced.h

@@ -3,7 +3,6 @@
 #define SiteAdvancedH
 //----------------------------------------------------------------------------
 #include "ComboEdit.hpp"
-#include "PasswordEdit.hpp"
 #include "UpDownEdit.hpp"
 #include <System.Classes.hpp>
 #include <Vcl.ActnList.hpp>
@@ -56,7 +55,7 @@ __published:
   TEdit *ProxyUsernameEdit;
   TLabel *ProxyUsernameLabel;
   TLabel *ProxyPasswordLabel;
-  TPasswordEdit *ProxyPasswordEdit;
+  TEdit *ProxyPasswordEdit;
   TGroupBox *ProxySettingsGroup;
   TLabel *ProxyTelnetCommandLabel;
   TEdit *ProxyTelnetCommandEdit;
@@ -143,7 +142,7 @@ __published:
   TLabel *Label18;
   TEdit *TunnelHostNameEdit;
   TEdit *TunnelUserNameEdit;
-  TPasswordEdit *TunnelPasswordEdit;
+  TEdit *TunnelPasswordEdit;
   TUpDownEdit *TunnelPortNumberEdit;
   TFilenameEdit *TunnelPrivateKeyEdit3;
   TLabel *Label19;
@@ -257,7 +256,7 @@ __published:
   TCheckBox *EncryptFilesCheck;
   TGroupBox *EncryptFilesGroup;
   TLabel *Label13;
-  TPasswordEdit *EncryptKeyPasswordEdit;
+  TEdit *EncryptKeyPasswordEdit;
   TCheckBox *ShowEncryptionKeyCheck;
   TButton *GenerateKeyButton;
   TEdit *EncryptKeyVisibleEdit;

+ 0 - 114
source/packages/my/PasswordEdit.pas

@@ -1,114 +0,0 @@
-unit PasswordEdit;
-
-interface
-
-uses
-  StdCtrls, Classes, Controls;
-
-type
-  TPasswordEdit = class(TCustomEdit)
-  protected
-    FPassword: Boolean;
-
-    procedure CreateParams(var Params: TCreateParams); override;
-    procedure SetPassword(Value: Boolean);
-
-  public
-    constructor Create(AOwner: TComponent); override;
-
-  published
-    property Password: Boolean read FPassword write SetPassword default True;
-
-    property Anchors;
-    property AutoSelect;
-    property AutoSize;
-    property BevelEdges;
-    property BevelInner;
-    property BevelKind default bkNone;
-    property BevelOuter;
-    property BiDiMode;
-    property BorderStyle;
-    property CharCase;
-    property Color;
-    property Constraints;
-    property Ctl3D;
-    property DragCursor;
-    property DragKind;
-    property DragMode;
-    property Enabled;
-    property Font;
-    property HideSelection;
-    property ImeMode;
-    property ImeName;
-    property MaxLength;
-    property OEMConvert;
-    property ParentBiDiMode;
-    property ParentColor;
-    property ParentCtl3D;
-    property ParentFont;
-    property ParentShowHint;
-    //property PasswordChar;
-    property PopupMenu;
-    property ReadOnly;
-    property ShowHint;
-    property TabOrder;
-    property TabStop;
-    property Text;
-    property Visible;
-    property OnChange;
-    property OnClick;
-    property OnContextPopup;
-    property OnDblClick;
-    property OnDragDrop;
-    property OnDragOver;
-    property OnEndDock;
-    property OnEndDrag;
-    property OnEnter;
-    property OnExit;
-    property OnKeyDown;
-    property OnKeyPress;
-    property OnKeyUp;
-    property OnMouseDown;
-    property OnMouseMove;
-    property OnMouseUp;
-    property OnStartDock;
-    property OnStartDrag;
-  end;
-
-procedure Register;
-
-implementation
-
-uses Windows, SysUtils;
-
-procedure Register;
-begin
-  RegisterComponents('Martin', [TPasswordEdit]);
-end;
-
-constructor TPasswordEdit.Create(AOwner: TComponent);
-begin
-  inherited Create(AOwner);
-  FPassword := True;
-end;
-
-procedure TPasswordEdit.SetPassword(Value: Boolean);
-begin
-  if Password <> Value then
-  begin
-    FPassword := Value;
-    RecreateWnd;
-  end;
-end;
-
-procedure TPasswordEdit.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  if FPassword then
-  begin
-    Params.Style := Params.Style or ES_PASSWORD;
-  end;
-end;
-
-initialization
-end.

+ 17 - 13
source/windows/UserInterface.cpp

@@ -15,7 +15,6 @@
 #include "TerminalManager.h"
 #include "TextsWin.h"
 #include "WinInterface.h"
-#include "PasswordEdit.hpp"
 #include "ProgParams.h"
 #include "Tools.h"
 #include "Custom.h"
@@ -1284,9 +1283,11 @@ protected:
   virtual void __fastcall DoChange(bool & CanSubmit);
 
 private:
-  TPasswordEdit * CurrentEdit;
-  TPasswordEdit * NewEdit;
-  TPasswordEdit * ConfirmEdit;
+  TEdit * CurrentEdit;
+  TEdit * NewEdit;
+  TEdit * ConfirmEdit;
+
+  TEdit * CreatePasswordEdit(int Label);
 };
 //---------------------------------------------------------------------------
 // Need to have an Owner argument for SafeFormCreate
@@ -1295,30 +1296,33 @@ __fastcall TMasterPasswordDialog::TMasterPasswordDialog(TComponent *) :
 {
 }
 //---------------------------------------------------------------------------
+TEdit * TMasterPasswordDialog::CreatePasswordEdit(int Label)
+{
+  TEdit * Result = new TEdit(this);
+  SetEditPasswordMode(Result);
+  AddEdit(Result, CreateLabel(LoadStr(Label)));
+  Result->MaxLength = PasswordMaxLength();
+  return Result;
+}
+//---------------------------------------------------------------------------
 void TMasterPasswordDialog::Init(bool Current)
 {
   HelpKeyword = Current ? HELP_MASTER_PASSWORD_CURRENT : HELP_MASTER_PASSWORD_CHANGE;
   Caption = LoadStr(MASTER_PASSWORD_CAPTION);
 
-  CurrentEdit = new TPasswordEdit(this);
-  AddEdit(CurrentEdit, CreateLabel(LoadStr(MASTER_PASSWORD_CURRENT)));
+  CurrentEdit = CreatePasswordEdit(MASTER_PASSWORD_CURRENT);
   EnableControl(CurrentEdit, Current || WinConfiguration->UseMasterPassword);
-  CurrentEdit->MaxLength = PasswordMaxLength();
 
   if (!Current)
   {
-    NewEdit = new TPasswordEdit(this);
-    AddEdit(NewEdit, CreateLabel(LoadStr(MASTER_PASSWORD_NEW)));
-    NewEdit->MaxLength = CurrentEdit->MaxLength;
+    NewEdit = CreatePasswordEdit(MASTER_PASSWORD_NEW);
 
     if (!WinConfiguration->UseMasterPassword)
     {
       ActiveControl = NewEdit;
     }
 
-    ConfirmEdit = new TPasswordEdit(this);
-    AddEdit(ConfirmEdit, CreateLabel(LoadStr(MASTER_PASSWORD_CONFIRM)));
-    ConfirmEdit->MaxLength = CurrentEdit->MaxLength;
+    ConfirmEdit = CreatePasswordEdit(MASTER_PASSWORD_CONFIRM);
   }
   else
   {

+ 6 - 2
source/windows/VCLCommon.cpp

@@ -14,7 +14,6 @@
 #include <CoreMain.h>
 
 #include <Vcl.StdActns.hpp>
-#include <PasswordEdit.hpp>
 #include <FileCtrl.hpp>
 #include <PathLabel.hpp>
 #include <PasTools.hpp>
@@ -387,7 +386,7 @@ void __fastcall DoReadOnlyControl(TControl * Control, bool ReadOnly, bool Color)
         Memo->WantReturns = false;
       }
 
-      if ((Edit->PopupMenu == NULL) && (dynamic_cast<TPasswordEdit *>(Control) == NULL))
+      if ((Edit->PopupMenu == NULL) && (Edit->PasswordChar == L'\0'))
       {
         std::unique_ptr<TPopupMenu> PopupMenu(new TPopupMenu(Edit));
 
@@ -438,6 +437,11 @@ void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly)
   DoReadOnlyControl(Control, ReadOnly, true);
 }
 //---------------------------------------------------------------------------
+void SetEditPasswordMode(TEdit * Edit, bool Password)
+{
+  Edit->PasswordChar = (Password ? L'*' : L'\0');
+}
+//---------------------------------------------------------------------------
 int CalculateCheckBoxWidth(TControl * Control, const UnicodeString & Caption)
 {
   return

+ 1 - 0
source/windows/VCLCommon.h

@@ -16,6 +16,7 @@ bool UseDarkModeForControl(TControl * Control);
 void __fastcall EnableControl(TControl* Control, bool Enable);
 void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly = true);
 void __fastcall ReadOnlyAndEnabledControl(TControl * Control, bool ReadOnly, bool Enabled);
+void SetEditPasswordMode(TEdit * Edit, bool Password = true);
 int CalculateCheckBoxWidth(TControl * Control, const UnicodeString & Caption);
 void AutoSizeCheckBox(TCheckBox * CheckBox);
 void __fastcall InitializeSystemSettings();