ui/winui/dnd.cpp

changeset 18
af411868ab9b
parent 0
2483f517c562
equal deleted inserted replaced
17:7cfd36aa005b 18:af411868ab9b
29 #include "pch.h" 29 #include "pch.h"
30 30
31 #include "dnd.h" 31 #include "dnd.h"
32 #include "util.h" 32 #include "util.h"
33 33
34 #include <thread>
35
36 using namespace winrt;
37 using namespace Windows::ApplicationModel::DataTransfer;
38 using namespace Windows::Storage;
39 using namespace Windows::Storage::Streams;
40
34 UIEXPORT void ui_selection_settext(UiDnD* dnd, char* str, int len) { 41 UIEXPORT void ui_selection_settext(UiDnD* dnd, char* str, int len) {
35 if (dnd->data) { 42 if (dnd->data) {
36 if (len < 0) { 43 if (len < 0) {
37 len = strlen(str); 44 len = strlen(str);
38 } 45 }
52 59
53 UIEXPORT char* ui_selection_gettext(UiDnD* dnd) { 60 UIEXPORT char* ui_selection_gettext(UiDnD* dnd) {
54 return nullptr; 61 return nullptr;
55 } 62 }
56 63
57 UIEXPORT char** ui_selection_geturis(UiDnD* dnd, size_t* nelm) { 64
58 return nullptr; 65 UIEXPORT UiFileList ui_selection_geturis(UiDnD *dnd) {
66 UiFileList flist;
67 flist.files = nullptr;
68 flist.nfiles = 0;
69
70 if (dnd->dataview.Contains(StandardDataFormats::StorageItems())) {
71 UiFileList *flist_ptr = &flist;
72
73 // we need to execute this in a different thread
74 // this could block the main gui thread, but shouldn't happen with a simple uri list
75 std::thread getDataThread([dnd, flist_ptr]() {
76 auto items = dnd->dataview.GetStorageItemsAsync().get();
77
78 char **uris = (char**)calloc(items.Size(), sizeof(char*));
79 flist_ptr->files = uris;
80 flist_ptr->nfiles = items.Size();
81
82 int i = 0;
83 for (IStorageItem const& item : items) {
84 winrt::hstring path = item.Path();
85 uris[i++] = wchar2utf8(path.c_str(), path.size());
86 }
87 });
88 getDataThread.join();
89 }
90 return flist;
59 } 91 }

mercurial