Annotation of truecrypt/main/forms/wizardframe.cpp, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.