From 24f3b5230cc1ea7e6fb084294f04df10ede17e2f Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 13 Sep 2015 23:49:08 +0200 Subject: Linux/MacOSX: Mask/unmask PIM value in GUI the same way as the password --- src/Main/Forms/Forms.cpp | 15 ++++- src/Main/Forms/Forms.h | 2 + src/Main/Forms/TrueCrypt.fbp | 103 ++++++++++++++++++++++++++++++++- src/Main/Forms/VolumePasswordPanel.cpp | 39 +++++++++---- src/Main/Forms/VolumePasswordPanel.h | 1 + src/Main/Forms/VolumePimWizardPage.cpp | 46 +++++++++++++-- src/Main/Forms/VolumePimWizardPage.h | 2 + 7 files changed, 188 insertions(+), 20 deletions(-) (limited to 'src/Main/Forms') diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp index f6c20cec..3c0db6a7 100644 --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -3209,7 +3209,7 @@ VolumePasswordPanelBase::VolumePasswordPanelBase( wxWindow* parent, wxWindowID i VolumePimStaticText->Wrap( -1 ); GridBagSizer->Add( VolumePimStaticText, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxBOTTOM|wxRIGHT, 5 ); - VolumePimTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + VolumePimTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD ); VolumePimTextCtrl->SetMaxLength( 10 ); GridBagSizer->Add( VolumePimTextCtrl, wxGBPosition( 3, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxEXPAND, 5 ); @@ -3350,7 +3350,7 @@ VolumePimWizardPageBase::VolumePimWizardPageBase( wxWindow* parent, wxWindowID i VolumePimStaticText->Wrap( -1 ); PimSizer->Add( VolumePimStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - VolumePimTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + VolumePimTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD ); VolumePimTextCtrl->SetMaxLength( 10 ); PimSizer->Add( VolumePimTextCtrl, 0, wxALL, 5 ); @@ -3361,6 +3361,15 @@ VolumePimWizardPageBase::VolumePimWizardPageBase( wxWindow* parent, wxWindowID i PimPanelSizer->Add( PimSizer, 1, wxEXPAND, 5 ); + wxBoxSizer* bSizer166; + bSizer166 = new wxBoxSizer( wxHORIZONTAL ); + + DisplayPimCheckBox = new wxCheckBox( this, wxID_ANY, _("&Display PIM"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer166->Add( DisplayPimCheckBox, 1, wxALL|wxEXPAND, 5 ); + + + PimPanelSizer->Add( bSizer166, 1, wxEXPAND, 5 ); + bSizer102->Add( PimPanelSizer, 0, wxEXPAND, 5 ); @@ -3378,12 +3387,14 @@ VolumePimWizardPageBase::VolumePimWizardPageBase( wxWindow* parent, wxWindowID i // Connect Events VolumePimTextCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePimWizardPageBase::OnPimChanged ), NULL, this ); + DisplayPimCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePimWizardPageBase::OnDisplayPimCheckBoxClick ), NULL, this ); } VolumePimWizardPageBase::~VolumePimWizardPageBase() { // Disconnect Events VolumePimTextCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePimWizardPageBase::OnPimChanged ), NULL, this ); + DisplayPimCheckBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePimWizardPageBase::OnDisplayPimCheckBoxClick ), NULL, this ); } diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h index e950ac2e..629519ae 100644 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -1026,10 +1026,12 @@ namespace VeraCrypt wxStaticText* VolumePimStaticText; wxTextCtrl* VolumePimTextCtrl; wxStaticText* VolumePimHelpStaticText; + wxCheckBox* DisplayPimCheckBox; wxStaticText* InfoStaticText; // Virtual event handlers, overide them in your derived class virtual void OnPimChanged( wxCommandEvent& event ) { event.Skip(); } + virtual void OnDisplayPimCheckBoxClick( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp index 25dfe831..5f5735ab 100644 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -25972,7 +25972,7 @@ Resizable 1 - + wxTE_PASSWORD 0 @@ -27412,7 +27412,7 @@ Resizable 1 - + wxTE_PASSWORD 0 @@ -27538,6 +27538,105 @@ + + 5 + wxEXPAND + 1 + + + bSizer166 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + &Display PIM + + 0 + + + 0 + + 1 + DisplayPimCheckBox + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnDisplayPimCheckBoxClick + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 8d4639bf..03134535 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -66,10 +66,7 @@ namespace VeraCrypt VolumePimTextCtrl->Show (false); VolumePimHelpStaticText->Show (false); - wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. - const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; - validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); - VolumePimTextCtrl->SetValidator (validator); + SetPimValidator (); ConfirmPasswordStaticText->Show (enableConfirmation); ConfirmPasswordTextCtrl->Show (enableConfirmation); @@ -186,17 +183,27 @@ namespace VeraCrypt UseKeyfilesCheckBox->SetValue (true); } + void VolumePasswordPanel::SetPimValidator () + { + wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. + const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; + validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + VolumePimTextCtrl->SetValidator (validator); + } + void VolumePasswordPanel::DisplayPassword (bool display, wxTextCtrl **textCtrl, int row) { FreezeScope freeze (this); + bool isPim = (*textCtrl == VolumePimTextCtrl); + int colspan = isPim? 1 : 2; wxTextCtrl *newTextCtrl = new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, display ? 0 : wxTE_PASSWORD); - newTextCtrl->SetMaxLength (VolumePassword::MaxSize); + newTextCtrl->SetMaxLength (isPim? 10 : VolumePassword::MaxSize); newTextCtrl->SetValue ((*textCtrl)->GetValue()); newTextCtrl->SetMinSize ((*textCtrl)->GetSize()); GridBagSizer->Detach ((*textCtrl)); - GridBagSizer->Add (newTextCtrl, wxGBPosition (row, 1), wxGBSpan (1, 2), wxEXPAND|wxBOTTOM|wxALIGN_CENTER_VERTICAL, 5); + GridBagSizer->Add (newTextCtrl, wxGBPosition (row, 1), wxGBSpan (1, colspan), wxEXPAND|wxBOTTOM|wxALIGN_CENTER_VERTICAL, 5); (*textCtrl)->Show (false); WipeTextCtrl (*textCtrl); @@ -204,8 +211,11 @@ namespace VeraCrypt Layout(); newTextCtrl->SetMinSize ((*textCtrl)->GetMinSize()); - newTextCtrl->Connect (wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (VolumePasswordPanel::OnTextChanged), nullptr, this); + newTextCtrl->Connect (wxEVT_COMMAND_TEXT_UPDATED, isPim? wxCommandEventHandler (VolumePasswordPanel::OnPimChanged): wxCommandEventHandler (VolumePasswordPanel::OnTextChanged), nullptr, this); + delete *textCtrl; *textCtrl = newTextCtrl; + if (isPim) + SetPimValidator (); } shared_ptr VolumePasswordPanel::GetPassword () const @@ -369,6 +379,9 @@ namespace VeraCrypt if (ConfirmPasswordTextCtrl->IsShown()) DisplayPassword (event.IsChecked(), &ConfirmPasswordTextCtrl, 2); + + if (VolumePimTextCtrl->IsShown()) + DisplayPassword (event.IsChecked(), &VolumePimTextCtrl, 3); OnUpdate(); } @@ -449,9 +462,15 @@ namespace VeraCrypt VolumePimStaticText->Show (true); VolumePimTextCtrl->Show (true); VolumePimHelpStaticText->Show (true); - - Layout(); - Fit(); + + if (DisplayPasswordCheckBox->IsChecked ()) + DisplayPassword (true, &VolumePimTextCtrl, 3); + else + { + Layout(); + Fit(); + } + GetParent()->Layout(); GetParent()->Fit(); } diff --git a/src/Main/Forms/VolumePasswordPanel.h b/src/Main/Forms/VolumePasswordPanel.h index 520c36f6..de2475e9 100644 --- a/src/Main/Forms/VolumePasswordPanel.h +++ b/src/Main/Forms/VolumePasswordPanel.h @@ -45,6 +45,7 @@ namespace VeraCrypt Event UpdateEvent; protected: + void SetPimValidator (); void DisplayPassword (bool display, wxTextCtrl **textCtrl, int row); shared_ptr GetPassword (wxTextCtrl *textCtrl) const; void OnAddKeyfileDirMenuItemSelected (wxCommandEvent& event); diff --git a/src/Main/Forms/VolumePimWizardPage.cpp b/src/Main/Forms/VolumePimWizardPage.cpp index 36dc4c7f..8f98cb54 100644 --- a/src/Main/Forms/VolumePimWizardPage.cpp +++ b/src/Main/Forms/VolumePimWizardPage.cpp @@ -23,10 +23,7 @@ namespace VeraCrypt VolumePimWizardPage::VolumePimWizardPage (wxPanel* parent) : VolumePimWizardPageBase (parent) { - wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. - const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; - validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); - VolumePimTextCtrl->SetValidator (validator); + SetPimValidator (); } VolumePimWizardPage::~VolumePimWizardPage () @@ -85,6 +82,43 @@ namespace VeraCrypt { VolumePimHelpStaticText->SetForegroundColour(*wxBLACK); VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]); - } + } + Fit(); + Layout(); + } + + void VolumePimWizardPage::SetPimValidator () + { + wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. + const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; + validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + VolumePimTextCtrl->SetValidator (validator); + } + + void VolumePimWizardPage::OnDisplayPimCheckBoxClick( wxCommandEvent& event ) + { + FreezeScope freeze (this); + + bool display = event.IsChecked (); + + wxTextCtrl *newTextCtrl = new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, display ? 0 : wxTE_PASSWORD); + newTextCtrl->SetMaxLength (10); + newTextCtrl->SetValue (VolumePimTextCtrl->GetValue()); + newTextCtrl->SetMinSize (VolumePimTextCtrl->GetSize()); + + PimSizer->Replace (VolumePimTextCtrl, newTextCtrl); + VolumePimTextCtrl->Show (false); + VolumePimTextCtrl->SetValue (wxString (L'X', VolumePimTextCtrl->GetLineLength(0))); + GetVolumePim (); + + Fit(); + Layout(); + newTextCtrl->SetMinSize (VolumePimTextCtrl->GetMinSize()); + + newTextCtrl->Connect (wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (VolumePimWizardPage::OnPimChanged), nullptr, this); + delete VolumePimTextCtrl; + VolumePimTextCtrl = newTextCtrl; + SetPimValidator (); + OnPimChanged (GetVolumePim ()); } -} +} \ No newline at end of file diff --git a/src/Main/Forms/VolumePimWizardPage.h b/src/Main/Forms/VolumePimWizardPage.h index ae097004..af757359 100644 --- a/src/Main/Forms/VolumePimWizardPage.h +++ b/src/Main/Forms/VolumePimWizardPage.h @@ -32,8 +32,10 @@ namespace VeraCrypt bool IsValid (); void SetMaxStaticTextWidth (int width) { InfoStaticText->Wrap (width); } void SetPageText (const wxString &text) { InfoStaticText->SetLabel (text); } + void OnDisplayPimCheckBoxClick( wxCommandEvent& event ); protected: + void SetPimValidator (); void OnPimChanged (wxCommandEvent& event); void OnPimChanged (int pim); }; -- cgit v1.2.3