blob: 86db57c1a6d0c0c3010ebe6c8423b09da70c6def (
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
68
69
70
71
72
73
74
75
76
|
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
#include "file_drop.h"
#include <wx/dnd.h>
#include <zen/utf.h>
#include <zen/file_access.h>
using namespace zen;
namespace zen
{
wxDEFINE_EVENT(EVENT_DROP_FILE, FileDropEvent);
}
namespace
{
class WindowDropTarget : public wxFileDropTarget
{
public:
explicit WindowDropTarget(const wxWindow& dropWindow) : dropWindow_(dropWindow) {}
private:
wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def) override
{
//why the FUCK I is drag & drop still working while showing another modal dialog!???
//why the FUCK II is drag & drop working even when dropWindow is disabled!?? [Windows] => we can fix this
//why the FUCK III is dropWindow NOT disabled while showing another modal dialog!??? [macOS, Linux] => we CANNOT fix this: FUUUUUUUUUUUUUU...
if (!dropWindow_.IsEnabled())
return wxDragNone;
return wxFileDropTarget::OnDragOver(x, y, def);
}
//"bool wxDropTarget::GetData() [...] This method may only be called from within OnData()."
//=> FUUUUUUUUUUUUUU........ a.k.a. no support for DragDropValidator during mouse hover! >:(
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& fileArray) override
{
/*Linux, MTP: we get an empty file array
=> switching to wxTextDropTarget won't help (much): we'd get the format
mtp://[usb:001,002]/Telefonspeicher/Folder/file.txt
instead of
/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C002%5D/Telefonspeicher/Folder/file.txt */
if (!dropWindow_.IsEnabled())
return false;
//wxPoint clientDropPos(x, y)
std::vector<Zstring> filePaths;
for (const wxString& file : fileArray)
filePaths.push_back(utfTo<Zstring>(file));
//create a custom event on drop window: execute event after file dropping is completed! (after mouse is released)
if (wxEvtHandler* handler = dropWindow_.GetEventHandler())
handler->AddPendingEvent(FileDropEvent(filePaths));
return true;
}
const wxWindow& dropWindow_;
};
}
void zen::setupFileDrop(wxWindow& dropWindow)
{
dropWindow.SetDropTarget(new WindowDropTarget(dropWindow)); /*takes ownership*/
}
|