diff --git a/src/Main/Forms/KeyfileGeneratorDialog.cpp b/src/Main/Forms/KeyfileGeneratorDialog.cpp index 2ebd46fa..ab7976db 100644 --- a/src/Main/Forms/KeyfileGeneratorDialog.cpp +++ b/src/Main/Forms/KeyfileGeneratorDialog.cpp @@ -14,6 +14,7 @@ #include "Main/GraphicUserInterface.h" #include "Volume/Hash.h" #include "KeyfileGeneratorDialog.h" +#include "WindowEventHandlers.h" namespace VeraCrypt { @@ -44,8 +45,7 @@ namespace VeraCrypt MouseEventsCounter = 0; - foreach (wxWindow *c, this->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (KeyfileGeneratorDialog::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (this, wxEVT_MOTION, wxMouseEventHandler (KeyfileGeneratorDialog::OnMouseMotion), this); } KeyfileGeneratorDialog::~KeyfileGeneratorDialog () diff --git a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp index bed15550..b846a60e 100644 --- a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp +++ b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp @@ -14,6 +14,7 @@ #include "Main/GraphicUserInterface.h" #include "Volume/Hash.h" #include "RandomPoolEnrichmentDialog.h" +#include "WindowEventHandlers.h" namespace VeraCrypt { @@ -46,8 +47,7 @@ namespace VeraCrypt MouseEventsCounter = 0; - foreach (wxWindow *c, this->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (RandomPoolEnrichmentDialog::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (this, wxEVT_MOTION, wxMouseEventHandler (RandomPoolEnrichmentDialog::OnMouseMotion), this); } RandomPoolEnrichmentDialog::~RandomPoolEnrichmentDialog () diff --git a/src/Main/Forms/WindowEventHandlers.h b/src/Main/Forms/WindowEventHandlers.h new file mode 100644 index 00000000..087cedc7 --- /dev/null +++ b/src/Main/Forms/WindowEventHandlers.h @@ -0,0 +1,30 @@ +/* + Derived from source code of TrueCrypt 7.1a, which is + Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed + by the TrueCrypt License 3.0. + + Modifications and additions to the original source code (contained in this file) + and all other portions of this file are Copyright (c) 2013-2026 AM Crypto + and are governed by the Apache License 2.0 the full text of which is + contained in the file License.txt included in VeraCrypt binary and source + code distribution packages. +*/ + +#ifndef TC_HEADER_Main_Forms_WindowEventHandlers +#define TC_HEADER_Main_Forms_WindowEventHandlers + +#include "Main/Main.h" + +namespace VeraCrypt +{ + inline void ConnectEventToChildWindows (wxWindow *window, wxEventType eventType, wxObjectEventFunction handler, wxEvtHandler *eventSink) + { + foreach (wxWindow *child, window->GetChildren()) + { + child->Connect (eventType, handler, nullptr, eventSink); + ConnectEventToChildWindows (child, eventType, handler, eventSink); + } + } +} + +#endif // TC_HEADER_Main_Forms_WindowEventHandlers diff --git a/src/Main/Forms/WizardFrame.cpp b/src/Main/Forms/WizardFrame.cpp index 4717bcfc..503e6857 100644 --- a/src/Main/Forms/WizardFrame.cpp +++ b/src/Main/Forms/WizardFrame.cpp @@ -14,6 +14,7 @@ #include "Main/GraphicUserInterface.h" #include "Main/Resources.h" #include "WizardFrame.h" +#include "WindowEventHandlers.h" namespace VeraCrypt { @@ -40,8 +41,7 @@ namespace VeraCrypt this->SetDefaultItem (NextButton); NextButton->SetFocus(); - foreach (wxWindow *c, MainPanel->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (MainPanel, wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), this); } WizardFrame::~WizardFrame () @@ -145,8 +145,7 @@ namespace VeraCrypt CurrentPage->PageUpdatedEvent.Connect (EventConnector (this, &WizardFrame::OnPageUpdated)); CurrentPage->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this); - foreach (wxWindow *c, CurrentPage->GetChildren()) - c->Connect (wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), nullptr, this); + ConnectEventToChildWindows (CurrentPage, wxEVT_MOTION, wxMouseEventHandler (WizardFrame::OnMouseMotion), this); if (MaxStaticTextWidth > 0) CurrentPage->SetMaxStaticTextWidth (MaxStaticTextWidth);