"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/FavoriteVolumesDialog.cpp" (10 Oct 2018, 3771 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 "FavoriteVolumesDialog.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 "FavoriteVolumesDialog.h"
   16 
   17 namespace VeraCrypt
   18 {
   19     FavoriteVolumesDialog::FavoriteVolumesDialog (wxWindow* parent, const FavoriteVolumeList &favorites, size_t newItemCount)
   20         : FavoriteVolumesDialogBase (parent), Favorites (favorites)
   21     {
   22         list <int> colPermilles;
   23         FavoritesListCtrl->InsertColumn (ColumnVolumePath, LangString["VOLUME"], wxLIST_FORMAT_LEFT, 1);
   24         colPermilles.push_back (500);
   25         FavoritesListCtrl->InsertColumn (ColumnMountPoint, LangString["MOUNT_POINT"], wxLIST_FORMAT_LEFT, 1);
   26         colPermilles.push_back (500);
   27 
   28         FavoritesListCtrl->SetMinSize (wxSize (400, -1));
   29         Gui->SetListCtrlHeight (FavoritesListCtrl, 15);
   30         Gui->SetListCtrlColumnWidths (FavoritesListCtrl, colPermilles);
   31 
   32         Layout();
   33         Fit();
   34         Center();
   35 
   36 #ifdef TC_MACOSX
   37         // wxMac cannot insert items to wxListCtrl due to a bug
   38         MoveUpButton->Show (false);
   39         MoveDownButton->Show (false);
   40 #endif
   41 
   42         vector <wstring> fields (FavoritesListCtrl->GetColumnCount());
   43         size_t itemCount = 0;
   44         foreach (shared_ptr <FavoriteVolume> favorite, Favorites)
   45         {
   46             fields[ColumnVolumePath] = favorite->Path;
   47             fields[ColumnMountPoint] = favorite->MountPoint;
   48             Gui->AppendToListCtrl (FavoritesListCtrl, fields, -1, favorite.get());
   49 
   50             if (++itemCount > Favorites.size() - newItemCount)
   51             {
   52                 FavoritesListCtrl->SetItemState (itemCount - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
   53                 FavoritesListCtrl->EnsureVisible (itemCount - 1);
   54             }
   55         }
   56 
   57         UpdateButtons();
   58         FavoritesListCtrl->SetFocus();
   59     }
   60 
   61     void FavoriteVolumesDialog::OnMoveDownButtonClick (wxCommandEvent& event)
   62     {
   63         FreezeScope freeze (this);
   64         foreach_reverse (long itemIndex, Gui->GetListCtrlSelectedItems (FavoritesListCtrl))
   65         {
   66             if (itemIndex >= FavoritesListCtrl->GetItemCount() - 1)
   67                 break;
   68             Gui->MoveListCtrlItem (FavoritesListCtrl, itemIndex, itemIndex + 1);
   69         }
   70         UpdateButtons();
   71     }
   72 
   73     void FavoriteVolumesDialog::OnMoveUpButtonClick (wxCommandEvent& event)
   74     {
   75         FreezeScope freeze (this);
   76         foreach (long itemIndex, Gui->GetListCtrlSelectedItems (FavoritesListCtrl))
   77         {
   78             if (itemIndex == 0)
   79                 break;
   80 
   81             Gui->MoveListCtrlItem (FavoritesListCtrl, itemIndex, itemIndex - 1);
   82         }
   83         UpdateButtons();
   84     }
   85 
   86     void FavoriteVolumesDialog::OnOKButtonClick (wxCommandEvent& event)
   87     {
   88         FavoriteVolumeList newFavorites;
   89 
   90         for (long i = 0; i < FavoritesListCtrl->GetItemCount(); i++)
   91         {
   92             newFavorites.push_back (make_shared <FavoriteVolume> (
   93                 *reinterpret_cast <FavoriteVolume *> (FavoritesListCtrl->GetItemData (i))));
   94         }
   95 
   96         Favorites = newFavorites;
   97         EndModal (wxID_OK);
   98     }
   99 
  100     void FavoriteVolumesDialog::OnRemoveAllButtonClick (wxCommandEvent& event)
  101     {
  102         FavoritesListCtrl->DeleteAllItems();
  103         UpdateButtons();
  104     }
  105 
  106     void FavoriteVolumesDialog::OnRemoveButtonClick (wxCommandEvent& event)
  107     {
  108         long offset = 0;
  109         foreach (long item, Gui->GetListCtrlSelectedItems (FavoritesListCtrl))
  110             FavoritesListCtrl->DeleteItem (item - offset++);
  111     }
  112 
  113     void FavoriteVolumesDialog::UpdateButtons ()
  114     {
  115         bool selected = FavoritesListCtrl->GetSelectedItemCount() > 0;
  116 
  117         MoveDownButton->Enable (selected);
  118         MoveUpButton->Enable (selected);
  119         RemoveAllButton->Enable (FavoritesListCtrl->GetItemCount() > 0);
  120         RemoveButton->Enable (selected);
  121     }
  122 }