From e39f5fa5d6b1b09df16271cabb1dda5d42c0b980 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 29 Apr 2018 17:33:33 +0200 Subject: MacOSX: support pasting values to password fields using keyboard (CMD+V and CMD+A now working properly). This make using password managers with VeraCrypt easier. --- src/Main/GraphicUserInterface.cpp | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/Main/GraphicUserInterface.cpp') diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index 9ae735e4..ba283af4 100755 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -37,6 +37,11 @@ namespace VeraCrypt { +#ifdef TC_MACOSX + int GraphicUserInterface::g_customIdCmdV = 0; + int GraphicUserInterface::g_customIdCmdA = 0; +#endif + GraphicUserInterface::GraphicUserInterface () : ActiveFrame (nullptr), BackgroundMode (false), @@ -51,6 +56,8 @@ namespace VeraCrypt #endif #ifdef TC_MACOSX + g_customIdCmdV = wxNewId(); + g_customIdCmdA = wxNewId(); wxApp::s_macHelpMenuTitleName = _("&Help"); #endif } @@ -657,6 +664,41 @@ namespace VeraCrypt { SetBackgroundMode (false); } + + bool GraphicUserInterface::HandlePasswordEntryCustomEvent (wxEvent& event) + { + bool bHandled = false; + if ( (event.GetEventType() == wxEVT_MENU) + && ((event.GetId() == g_customIdCmdV) || (event.GetId() == g_customIdCmdA))) + { + wxWindow* focusedCtrl = wxWindow::FindFocus(); + if (focusedCtrl + && (focusedCtrl->IsKindOf(wxCLASSINFO(wxTextCtrl))) + && (focusedCtrl->GetWindowStyle() & wxTE_PASSWORD)) + { + wxTextCtrl* passwordCtrl = (wxTextCtrl*) focusedCtrl; + if (event.GetId() == g_customIdCmdV) + passwordCtrl->Paste (); + else if (event.GetId() == g_customIdCmdA) + passwordCtrl->SelectAll (); + bHandled = true; + } + } + + return bHandled; + } + + void GraphicUserInterface::InstallPasswordEntryCustomKeyboardShortcuts (wxWindow* window) + { + // we manually handle CMD+V and CMD+A on password fields in order to support + // pasting password values into them. By default, wxWidgets doesn't handle this + // for password entry fields. + wxAcceleratorEntry entries[2]; + entries[0].Set(wxACCEL_CMD, (int) 'V', g_customIdCmdV); + entries[1].Set(wxACCEL_CMD, (int) 'A', g_customIdCmdA); + wxAcceleratorTable accel(sizeof(entries) / sizeof(wxAcceleratorEntry), entries); + window->SetAcceleratorTable(accel); + } #endif void GraphicUserInterface::MoveListCtrlItem (wxListCtrl *listCtrl, long itemIndex, long newItemIndex) const -- cgit v1.2.3