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

unix.superglobalmegacorp.com

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