summaryrefslogtreecommitdiff
path: root/shared/file_drop.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:56 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:56 +0200
commit98ecf620f7de377dc8ae9ad7fbd1e3b24477e138 (patch)
treefaadc6d8822c20cd3bc6f50b2a98e6c580585949 /shared/file_drop.h
parent3.16 (diff)
downloadFreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.tar.gz
FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.tar.bz2
FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.zip
3.17
Diffstat (limited to 'shared/file_drop.h')
-rw-r--r--shared/file_drop.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/shared/file_drop.h b/shared/file_drop.h
new file mode 100644
index 00000000..c85d4cbb
--- /dev/null
+++ b/shared/file_drop.h
@@ -0,0 +1,113 @@
+// **************************************************************************
+// * 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) *
+// **************************************************************************
+//
+#ifndef FILE_DROP_H_INCLUDED
+#define FILE_DROP_H_INCLUDED
+
+#include <wx/event.h>
+#include <wx/dnd.h>
+
+namespace zen
+{
+//register simple file drop event (without issue of freezing dialogs and without wxFileDropTarget overdesign)
+
+//1. have a window emit FFS_DROP_FILE_EVENT
+void setupFileDrop(wxWindow& wnd);
+
+//2. register events:
+//wnd.Connect (FFS_DROP_FILE_EVENT, FFSFileDropEventHandler(MyDlg::OnFilesDropped), NULL, this);
+//wnd.Disconnect(FFS_DROP_FILE_EVENT, FFSFileDropEventHandler(MyDlg::OnFilesDropped), NULL, this);
+
+//3. do something:
+//void MyDlg::OnFilesDropped(FFSFileDropEvent& event);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+inline
+wxEventType createNewEventType()
+{
+ //inline functions have external linkage by default => this static is also extern, i.e. program wide unique! but defined in a header... ;)
+ static wxEventType dummy = wxNewEventType();
+ return dummy;
+}
+
+//define new event type
+const wxEventType FFS_DROP_FILE_EVENT = createNewEventType();
+
+class FFSFileDropEvent : public wxCommandEvent
+{
+public:
+ FFSFileDropEvent(const std::vector<wxString>& filesDropped, const wxWindow& dropWindow, wxPoint dropPos) :
+ wxCommandEvent(FFS_DROP_FILE_EVENT),
+ filesDropped_(filesDropped),
+ dropWindow_(dropWindow),
+ dropPos_(dropPos) {}
+
+ virtual wxEvent* Clone() const
+ {
+ return new FFSFileDropEvent(filesDropped_, dropWindow_, dropPos_);
+ }
+
+ const std::vector<wxString>& getFiles() const { return filesDropped_; }
+ const wxWindow& getDropWindow() const { return dropWindow_; }
+ wxPoint getDropPosition() const { return dropPos_; } //position relative to drop window
+
+private:
+ const std::vector<wxString> filesDropped_;
+ const wxWindow& dropWindow_;
+ wxPoint dropPos_;
+};
+
+typedef void (wxEvtHandler::*FFSFileDropEventFunction)(FFSFileDropEvent&);
+
+#define FFSFileDropEventHandler(func) \
+ (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(FFSFileDropEventFunction, &func)
+
+
+class WindowDropTarget : public wxFileDropTarget
+{
+public:
+ WindowDropTarget(wxWindow& dropWindow) : dropWindow_(dropWindow) {}
+
+ virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& fileArray)
+ {
+ std::vector<wxString> filenames(fileArray.begin(), fileArray.end());
+ if (!filenames.empty())
+ {
+ //create a custom event on drop window: execute event after file dropping is completed! (after mouse is released)
+ FFSFileDropEvent evt(filenames, dropWindow_, wxPoint(x, y));
+ dropWindow_.GetEventHandler()->AddPendingEvent(evt);
+ }
+ return true;
+ }
+
+private:
+ wxWindow& dropWindow_;
+};
+
+
+inline
+void setupFileDrop(wxWindow& wnd)
+{
+ wnd.SetDropTarget(new WindowDropTarget(wnd)); //takes ownership
+}
+}
+
+#endif // FILE_DROP_H_INCLUDED
bgstack15