From 7ffce028d04a6b13ef762e2b89c34b688e8ca59d Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 31 May 2014 18:44:53 +0200 Subject: Add TrueCrypt 7.1a MacOSX/Linux specific source files. --- src/Main/Forms/FavoriteVolumesDialog.cpp | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/Main/Forms/FavoriteVolumesDialog.cpp (limited to 'src/Main/Forms/FavoriteVolumesDialog.cpp') diff --git a/src/Main/Forms/FavoriteVolumesDialog.cpp b/src/Main/Forms/FavoriteVolumesDialog.cpp new file mode 100644 index 00000000..7592b3c9 --- /dev/null +++ b/src/Main/Forms/FavoriteVolumesDialog.cpp @@ -0,0 +1,118 @@ +/* + Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved. + + Governed by the TrueCrypt License 3.0 the full text of which is contained in + the file License.txt included in TrueCrypt binary and source code distribution + packages. +*/ + +#include "System.h" +#include "Main/GraphicUserInterface.h" +#include "FavoriteVolumesDialog.h" + +namespace TrueCrypt +{ + FavoriteVolumesDialog::FavoriteVolumesDialog (wxWindow* parent, const FavoriteVolumeList &favorites, size_t newItemCount) + : FavoriteVolumesDialogBase (parent), Favorites (favorites) + { + list colPermilles; + FavoritesListCtrl->InsertColumn (ColumnVolumePath, LangString["VOLUME"], wxLIST_FORMAT_LEFT, 1); + colPermilles.push_back (500); + FavoritesListCtrl->InsertColumn (ColumnMountPoint, LangString["MOUNT_POINT"], wxLIST_FORMAT_LEFT, 1); + colPermilles.push_back (500); + + FavoritesListCtrl->SetMinSize (wxSize (400, -1)); + Gui->SetListCtrlHeight (FavoritesListCtrl, 15); + Gui->SetListCtrlColumnWidths (FavoritesListCtrl, colPermilles); + + Layout(); + Fit(); + Center(); + +#ifdef TC_MACOSX + // wxMac cannot insert items to wxListCtrl due to a bug + MoveUpButton->Show (false); + MoveDownButton->Show (false); +#endif + + vector fields (FavoritesListCtrl->GetColumnCount()); + size_t itemCount = 0; + foreach (shared_ptr favorite, Favorites) + { + fields[ColumnVolumePath] = favorite->Path; + fields[ColumnMountPoint] = favorite->MountPoint; + Gui->AppendToListCtrl (FavoritesListCtrl, fields, -1, favorite.get()); + + if (++itemCount > Favorites.size() - newItemCount) + { + FavoritesListCtrl->SetItemState (itemCount - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + FavoritesListCtrl->EnsureVisible (itemCount - 1); + } + } + + UpdateButtons(); + FavoritesListCtrl->SetFocus(); + } + + void FavoriteVolumesDialog::OnMoveDownButtonClick (wxCommandEvent& event) + { + FreezeScope freeze (this); + foreach_reverse (long itemIndex, Gui->GetListCtrlSelectedItems (FavoritesListCtrl)) + { + if (itemIndex >= FavoritesListCtrl->GetItemCount() - 1) + break; + Gui->MoveListCtrlItem (FavoritesListCtrl, itemIndex, itemIndex + 1); + } + UpdateButtons(); + } + + void FavoriteVolumesDialog::OnMoveUpButtonClick (wxCommandEvent& event) + { + FreezeScope freeze (this); + foreach (long itemIndex, Gui->GetListCtrlSelectedItems (FavoritesListCtrl)) + { + if (itemIndex == 0) + break; + + Gui->MoveListCtrlItem (FavoritesListCtrl, itemIndex, itemIndex - 1); + } + UpdateButtons(); + } + + void FavoriteVolumesDialog::OnOKButtonClick (wxCommandEvent& event) + { + FavoriteVolumeList newFavorites; + + for (long i = 0; i < FavoritesListCtrl->GetItemCount(); i++) + { + newFavorites.push_back (make_shared ( + *reinterpret_cast (FavoritesListCtrl->GetItemData (i)))); + } + + Favorites = newFavorites; + EndModal (wxID_OK); + } + + void FavoriteVolumesDialog::OnRemoveAllButtonClick (wxCommandEvent& event) + { + FavoritesListCtrl->DeleteAllItems(); + UpdateButtons(); + } + + void FavoriteVolumesDialog::OnRemoveButtonClick (wxCommandEvent& event) + { + long offset = 0; + foreach (long item, Gui->GetListCtrlSelectedItems (FavoritesListCtrl)) + FavoritesListCtrl->DeleteItem (item - offset++); + } + + void FavoriteVolumesDialog::UpdateButtons () + { + bool selected = FavoritesListCtrl->GetSelectedItemCount() > 0; + + MoveDownButton->Enable (selected); + MoveUpButton->Enable (selected); + RemoveAllButton->Enable (FavoritesListCtrl->GetItemCount() > 0); + RemoveButton->Enable (selected); + } +} -- cgit v1.2.3