"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/VolumePimWizardPage.cpp" (10 Oct 2018, 3464 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "VolumePimWizardPage.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.18_Source_vs_1.19_Source.

    1 /*
    2  Copyright (c) 2015-2016 Mounir IDRASSI for the VeraCrypt project.
    3 
    4  Licensed under the Apache License, Version 2.0 (the "License");
    5  you may not use this file except in compliance with the License.
    6  You may obtain a copy of the License at
    7 
    8  http://www.apache.org/licenses/LICENSE-2.0
    9 
   10  Unless required by applicable law or agreed to in writing, software
   11  distributed under the License is distributed on an "AS IS" BASIS,
   12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  See the License for the specific language governing permissions and
   14  limitations under the License.
   15 */
   16 
   17 #include "System.h"
   18 #include "Main/GraphicUserInterface.h"
   19 #include "VolumePimWizardPage.h"
   20 
   21 namespace VeraCrypt
   22 {
   23     VolumePimWizardPage::VolumePimWizardPage (wxPanel* parent)
   24         : VolumePimWizardPageBase (parent)
   25     {
   26         SetPimValidator ();
   27     }
   28 
   29     VolumePimWizardPage::~VolumePimWizardPage ()
   30     {
   31     }
   32 
   33     int VolumePimWizardPage::GetVolumePim () const
   34     {
   35         if (VolumePimTextCtrl->IsEnabled ())
   36         {
   37             wxString pimStr (VolumePimTextCtrl->GetValue());
   38             long pim = 0;
   39             if (pimStr.IsEmpty())
   40                 return 0;
   41             if (((size_t) wxNOT_FOUND == pimStr.find_first_not_of (wxT("0123456789")))
   42                 && pimStr.ToLong (&pim)
   43                 && pim <= MAX_PIM_VALUE)
   44                 return (int) pim;
   45             else
   46                 return -1;
   47         }
   48         else
   49             return 0;
   50     }
   51 
   52     void VolumePimWizardPage::SetVolumePim (int pim)
   53     {
   54         if (pim > 0)
   55         {
   56             VolumePimTextCtrl->SetValue (StringConverter::FromNumber (pim));
   57         }
   58         else
   59         {
   60             VolumePimTextCtrl->SetValue (wxT(""));
   61         }
   62 
   63         OnPimValueChanged (pim);
   64     }
   65 
   66     bool VolumePimWizardPage::IsValid ()
   67     {
   68         return true;
   69     }
   70 
   71     void VolumePimWizardPage::OnPimChanged  (wxCommandEvent& event)
   72     {
   73         OnPimValueChanged (GetVolumePim ());
   74     }
   75 
   76     void VolumePimWizardPage::OnPimValueChanged  (int pim)
   77     {
   78         if (pim > 0)
   79         {
   80             VolumePimHelpStaticText->SetForegroundColour(*wxRED);
   81             VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]);
   82         }
   83         else
   84         {
   85             VolumePimHelpStaticText->SetForegroundColour(*wxBLACK);
   86             VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]);
   87         }
   88         Fit();
   89         Layout();
   90     }
   91 
   92     void VolumePimWizardPage::SetPimValidator ()
   93     {
   94         wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);  // wxFILTER_NUMERIC does not exclude - . , etc.
   95         const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" };
   96         validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr));
   97         VolumePimTextCtrl->SetValidator (validator);
   98     }
   99 
  100     void VolumePimWizardPage::OnDisplayPimCheckBoxClick( wxCommandEvent& event )
  101     {
  102         FreezeScope freeze (this);
  103 
  104         bool display = event.IsChecked ();
  105 
  106         wxTextCtrl *newTextCtrl = new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, display ? 0 : wxTE_PASSWORD);
  107         newTextCtrl->SetMaxLength (MAX_PIM_DIGITS);
  108         newTextCtrl->SetValue (VolumePimTextCtrl->GetValue());
  109         newTextCtrl->SetMinSize (VolumePimTextCtrl->GetSize());
  110 
  111         PimSizer->Replace (VolumePimTextCtrl, newTextCtrl);
  112         VolumePimTextCtrl->Show (false);
  113         VolumePimTextCtrl->SetValue (wxString (L'X', VolumePimTextCtrl->GetLineLength(0)));
  114         GetVolumePim ();
  115 
  116         Fit();
  117         Layout();
  118         newTextCtrl->SetMinSize (VolumePimTextCtrl->GetMinSize());
  119 
  120         newTextCtrl->Connect (wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (VolumePimWizardPage::OnPimChanged), nullptr, this);
  121         delete VolumePimTextCtrl;
  122         VolumePimTextCtrl = newTextCtrl;
  123         SetPimValidator ();
  124         OnPimValueChanged (GetVolumePim ());
  125     }
  126 }