summaryrefslogtreecommitdiff
path: root/shared/mouse_move_dlg.cpp
blob: 95074b55ed9c54ca5fe7cd37044d28aea3297f1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// **************************************************************************
// * 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) 2008-2011 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include "mouse_move_dlg.h"
#include <vector>
#include <wx/msw/wrapwin.h> //includes "windows.h"
#include <wx/stattext.h>
#include <wx/statbmp.h>
#include <wx/statline.h>
#include <wx/animate.h>
#include <wx/panel.h>
#include <wx/gauge.h>
#include <wx/statusbr.h>

using namespace zen;

namespace
{
void getAllChildren(wxWindow& parent, std::vector<wxWindow*>& out)
{
    wxWindowList& wl = parent.GetChildren();
    for (wxWindowList::iterator i = wl.begin(); i != wl.end(); ++i)
    {
        if (dynamic_cast<wxStaticText*>   (*i) || //redirect clicks on these "dead" controls to move dialog instead
            dynamic_cast<wxStaticBitmap*> (*i) ||
            dynamic_cast<wxAnimationCtrl*>(*i) ||
            dynamic_cast<wxGauge*>        (*i) ||
            dynamic_cast<wxStaticLine*>   (*i) ||
            dynamic_cast<wxStatusBar*>    (*i) ||
            dynamic_cast<wxPanel*>        (*i))
            out.push_back(*i);
        getAllChildren(**i, out);
    }
}
}

MouseMoveWindow::MouseMoveWindow(wxWindow& parent, bool includeParent) : wxWindow(&parent, wxID_ANY)
{
    std::vector<wxWindow*> windList;
    if (includeParent)
        windList.push_back(&parent);
    getAllChildren(parent, windList);

    for (std::vector<wxWindow*>::const_iterator i = windList.begin(); i != windList.end(); ++i)
        (*i)->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(MouseMoveWindow::LeftButtonDown), NULL, this);

    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<HWND>(GetParent()->GetHWND()), WM_NCLBUTTONDOWN, HTCAPTION, 0);

        return;
        //event.Skip(); -> swallow event, to avoid other windows losing focus
    }
    event.Skip();
}
bgstack15