"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/SingleChoiceWizardPage.h" (10 Oct 2018, 3534 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 "SingleChoiceWizardPage.h" 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 #ifndef TC_HEADER_Main_Forms_SingleChoiceWizardPage
   14 #define TC_HEADER_Main_Forms_SingleChoiceWizardPage
   15 
   16 #include "Forms.h"
   17 
   18 namespace VeraCrypt
   19 {
   20     template <class ChoiceType>
   21     class SingleChoiceWizardPage : public SingleChoiceWizardPageBase
   22     {
   23     public:
   24         SingleChoiceWizardPage (wxPanel* parent, const wxString &groupBoxText = wxEmptyString, bool choiceTextBold = false)
   25             : SingleChoiceWizardPageBase (parent),
   26             ChoiceTextBold (choiceTextBold)
   27         {
   28             if (!groupBoxText.empty())
   29             {
   30                 OuterChoicesSizer->Remove (ChoicesSizer);
   31                 ChoicesSizer = new wxStaticBoxSizer (wxVERTICAL, this, groupBoxText);
   32                 OuterChoicesSizer->Add (ChoicesSizer, 0, wxEXPAND, 5);
   33             }
   34         }
   35 
   36         void AddChoice (ChoiceType choice, const wxString &choiceText, const wxString &infoText = wxEmptyString, const wchar_t *infoLinkId = nullptr, const wxString &infoLinkText = wxEmptyString)
   37         {
   38             assert (RadioButtonMap.find (choice) == RadioButtonMap.end());
   39 
   40             wxRadioButton *radioButton = new wxRadioButton (this, wxID_ANY, choiceText);
   41             if (RadioButtonMap.empty())
   42                 radioButton->SetValue (true);
   43 
   44             RadioButtonMap[choice] = radioButton;
   45 
   46             if (ChoiceTextBold)
   47             {
   48                 wxFont buttonFont = radioButton->GetFont();
   49                 buttonFont.SetWeight (wxFONTWEIGHT_BOLD);
   50                 radioButton->SetFont (buttonFont);
   51             }
   52 
   53             ChoicesSizer->Add (radioButton, 0, wxALL, 5);
   54 
   55             wxBoxSizer *infoSizer = new wxBoxSizer (wxVERTICAL);
   56 
   57             wxStaticText *infoStaticText = new wxStaticText (this, wxID_ANY, infoText, wxDefaultPosition, wxDefaultSize, 0);
   58             ChoiceInfoTexts.push_back (infoStaticText);
   59 
   60             infoSizer->Add (infoStaticText, 0, wxALL, 5);
   61             ChoicesSizer->Add (infoSizer, 0, wxEXPAND | wxLEFT, Gui->GetCharWidth (this) * 3);
   62 
   63             if (infoLinkId)
   64             {
   65                 wxHyperlinkCtrl *hyperlink = Gui->CreateHyperlink (this, infoLinkId, infoLinkText);
   66                 infoSizer->Add (hyperlink, 0, wxALL, 5);
   67                 hyperlink->Connect (wxEVT_COMMAND_HYPERLINK, wxHyperlinkEventHandler (SingleChoiceWizardPage::OnChoiceHyperlinkClick), nullptr, this);
   68             }
   69 
   70             ChoicesSizer->Add (1, Gui->GetCharHeight (this) * 1, 0, wxEXPAND, 5);
   71         }
   72 
   73         ChoiceType GetSelection () const
   74         {
   75             typedef pair <ChoiceType, wxRadioButton*> MapPair;
   76             foreach (MapPair p, RadioButtonMap)
   77             {
   78                 if (p.second->GetValue())
   79                     return p.first;
   80             }
   81 
   82             throw NoItemSelected (SRC_POS);
   83         }
   84 
   85         bool IsValid ()
   86         {
   87             return true;
   88         }
   89 
   90         void SetMaxStaticTextWidth (int width)
   91         {
   92             InfoStaticText->Wrap (width);
   93 
   94             foreach (wxStaticText *infoText, ChoiceInfoTexts)
   95                 infoText->Wrap (width - Gui->GetCharWidth (this) * 3);
   96         }
   97 
   98         void SetPageText (const wxString &text)
   99         {
  100             InfoStaticText->SetLabel (text);
  101         }
  102 
  103         void SetSelection (ChoiceType choice)
  104         {
  105             RadioButtonMap[choice]->SetValue (true);
  106         }
  107 
  108     protected:
  109         void OnChoiceHyperlinkClick (wxHyperlinkEvent &event)
  110         {
  111             Gui->OpenHomepageLink (this, event.GetURL());
  112         }
  113 
  114         bool ChoiceTextBold;
  115         list <wxStaticText*> ChoiceInfoTexts;
  116         map <ChoiceType, wxRadioButton*> RadioButtonMap;
  117     };
  118 }
  119 
  120 #endif // TC_HEADER_Main_Forms_SingleChoiceWizardPage