// ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * // * Copyright (C) ZenJu (zenju AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "mouse_move_dlg.h" #include #include //includes "windows.h" #include #include #include #include #include #include #include #include #include using namespace zen; namespace { template inline void forEachChild(wxWindow& parent, Fun f) { wxWindowList& wl = parent.GetChildren(); for (auto iter = wl.begin(); iter != wl.end(); ++iter) //yet another wxWidgets bug keeps us from using std::for_each { wxWindow& wnd = **iter; f(wnd); forEachChild(wnd, f); } } } MouseMoveWindow::MouseMoveWindow(wxWindow& parent, bool includeParent) : wxWindow(&parent, wxID_ANY) { wxObjectEventFunction memFunMouseDown = wxMouseEventHandler(MouseMoveWindow::LeftButtonDown); //wxWidgets macros are obviously not C++11 ready auto connect = [&](wxWindow& wnd) { if (dynamic_cast (&wnd) || //redirect clicks on these "dead" controls to move dialog instead dynamic_cast (&wnd) || dynamic_cast(&wnd) || dynamic_cast (&wnd) || dynamic_cast (&wnd) || dynamic_cast (&wnd) || dynamic_cast (&wnd) || dynamic_cast (&wnd) || dynamic_cast (&wnd)) wnd.Connect(wxEVT_LEFT_DOWN, memFunMouseDown, nullptr, this); }; if (includeParent) connect(parent); forEachChild(parent, connect); Hide(); //this is just a dummy window so that its parent can have ownership Disable(); } void MouseMoveWindow::LeftButtonDown(wxMouseEvent& event) { if (GetParent() && allowMove(event)) { ::ReleaseCapture(); //::SendMessage(GetHwndOf(dialogToMove_), WM_NCLBUTTONDOWN, HTCAPTION, 0); ::SendMessage(static_cast(GetParent()->GetHWND()), WM_NCLBUTTONDOWN, HTCAPTION, 0); return; //event.Skip(); -> swallow event, to avoid other windows losing focus } event.Skip(); }