"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/WizardFrame.cpp" (10 Oct 2018, 4616 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 "WizardFrame.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #include "System.h"
   14 #include "Main/GraphicUserInterface.h"
   15 #include "Main/Resources.h"
   16 #include "WizardFrame.h"
   17 
   18 namespace VeraCrypt
   19 {
   20     WizardFrame::WizardFrame (wxWindow* parent)
   21         : WizardFrameBase (parent),
   22         CurrentPage (nullptr),
   23         CurrentStep (-1),
   24         MaxStaticTextWidth (-1),
   25         WorkInProgress (false)
   26     {
   27         SetIcon (Resources::GetVeraCryptIcon());
   28 
   29         PageTitleStaticText->SetFont (wxFont (
   30 #ifdef TC_WINDOWS
   31             16
   32 #elif defined(TC_MACOSX)
   33             18
   34 #elif defined(__WXGTK__)
   35             14
   36 #endif
   37             * Gui->GetCharHeight (this) / 13, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, L"Times New Roman"));
   38 
   39         UpdateControls();
   40         this->SetDefaultItem (NextButton);
   41         NextButton->SetFocus();
   42 
   43         foreach (wxWindow *c, MainPanel->GetChildren())
   44             c->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this);
   45     }
   46 
   47     WizardFrame::~WizardFrame ()
   48     {
   49         if (CurrentPage)
   50             CurrentPage->Destroy();
   51     }
   52 
   53     void WizardFrame::ClearHistory ()
   54     {
   55         StepHistory.clear();
   56         UpdateControls();
   57     }
   58 
   59     void WizardFrame::OnActivate (wxActivateEvent& event)
   60     {
   61         Gui->SetActiveFrame (this);
   62         event.Skip();
   63     }
   64 
   65     void WizardFrame::OnClose (wxCloseEvent& event)
   66     {
   67         if (WorkInProgress)
   68             return;
   69 
   70         Gui->SetActiveFrame (nullptr);
   71         event.Skip();
   72     }
   73 
   74     void WizardFrame::OnHelpButtonClick (wxCommandEvent& event)
   75     {
   76         Gui->OpenUserGuide (this);
   77     }
   78 
   79     void WizardFrame::OnNextButtonClick (wxCommandEvent& event)
   80     {
   81         if (CurrentPage->IsValid())
   82         {
   83             WizardStep nextStep = ProcessPageChangeRequest (true);
   84             if (nextStep != CurrentStep)
   85                 SetStep (nextStep);
   86         }
   87     }
   88 
   89     void WizardFrame::OnPreviousButtonClick (wxCommandEvent& event)
   90     {
   91         ProcessPageChangeRequest (false);
   92 
   93         if (!StepHistory.empty())
   94         {
   95             WizardStep prevStep = *StepHistory.rbegin();
   96             StepHistory.pop_back();
   97             SetStep (prevStep, false);
   98         }
   99     }
  100 
  101     void WizardFrame::SetCancelButtonText (const wxString &text)
  102     {
  103         CancelButton->SetLabel (text.empty() ? wxString (_("Cancel")) : text);
  104     }
  105 
  106     void WizardFrame::SetImage (const wxBitmap &bitmap)
  107     {
  108         WizardBitmap->SetBitmap (bitmap);
  109     }
  110 
  111     void WizardFrame::SetMaxStaticTextWidth (size_t charCount)
  112     {
  113         MaxStaticTextWidth = Gui->GetCharWidth (this) * charCount;
  114     }
  115 
  116     void WizardFrame::SetStep (WizardStep newStep)
  117     {
  118         SetStep (newStep, true);
  119     }
  120 
  121     void WizardFrame::SetStep (WizardStep newStep, bool forward)
  122     {
  123         bool init = false;
  124         FreezeScope freeze (this);
  125 
  126 #ifdef TC_WINDOWS
  127         HelpButton->Disable(); // Prevent Help button from getting default focus
  128         NextButton->Enable();
  129 #endif
  130         if (CurrentPage)
  131         {
  132             if (forward)
  133                 StepHistory.push_back (CurrentStep);
  134 
  135             CurrentPage->OnPageChanging (forward);
  136             CurrentPage->Destroy();
  137             CurrentPage = nullptr;
  138         }
  139         else
  140             init = true;
  141 
  142         CurrentStep = newStep;
  143         CurrentPage = GetPage (newStep);
  144 
  145         CurrentPage->PageUpdatedEvent.Connect (EventConnector <WizardFrame> (this, &WizardFrame::OnPageUpdated));
  146 
  147         CurrentPage->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this);
  148         foreach (wxWindow *c, CurrentPage->GetChildren())
  149             c->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this);
  150 
  151         if (MaxStaticTextWidth > 0)
  152             CurrentPage->SetMaxStaticTextWidth (MaxStaticTextWidth);
  153 
  154         PageTitleStaticText->SetLabel (CurrentPage->GetPageTitle());
  155         PageSizer->Add (CurrentPage, 1, wxALL | wxEXPAND);
  156 
  157         if (init)
  158         {
  159             Fit();
  160             Layout();
  161             Center();
  162         }
  163         else
  164             MainPanel->Layout();
  165 
  166         CurrentPage->SetFocus();
  167 
  168         wxString nextButtonText = CurrentPage->GetNextButtonText();
  169         if (nextButtonText.empty())
  170             NextButton->SetLabel (_("&Next >"));
  171         else
  172             NextButton->SetLabel (nextButtonText);
  173 
  174 #ifdef TC_WINDOWS
  175         HelpButton->Enable();
  176 #endif
  177         UpdateControls();
  178     }
  179 
  180     void WizardFrame::SetWorkInProgress (bool state)
  181     {
  182         WorkInProgress = state;
  183         UpdateControls();
  184     }
  185 
  186     void WizardFrame::UpdateControls ()
  187     {
  188         CancelButton->Enable (!WorkInProgress);
  189         HelpButton->Enable (!WorkInProgress);
  190         NextButton->Enable (!WorkInProgress && CurrentPage != nullptr && CurrentPage->IsValid());
  191         PreviousButton->Enable (!WorkInProgress && !StepHistory.empty());
  192     }
  193 }