#include "pch.h"
#include "dnd.h"
#include "util.h"
#include <thread>
using namespace winrt;
using namespace Windows::ApplicationModel::DataTransfer;
using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
UIEXPORT void ui_selection_settext(UiDnD* dnd,
char* str,
int len) {
if (dnd->data) {
if (len <
0) {
len = strlen(str);
}
wchar_t *wstr = str2wstr_len(str, len, nullptr);
dnd->data.SetText(wstr);
free(wstr);
}
}
UIEXPORT void ui_selection_seturis(UiDnD* dnd,
char** uris,
int nelm) {
}
UIEXPORT char* ui_selection_gettext(UiDnD* dnd) {
return nullptr;
}
UIEXPORT UiFileList ui_selection_geturis(UiDnD *dnd) {
UiFileList flist;
flist.files = nullptr;
flist.nfiles =
0;
if (dnd->dataview.Contains(StandardDataFormats::StorageItems())) {
UiFileList *flist_ptr = &flist;
std::thread getDataThread([dnd, flist_ptr]() {
auto items = dnd->dataview.GetStorageItemsAsync().get();
char **uris = (
char**)calloc(items.Size(),
sizeof(
char*));
flist_ptr->files = uris;
flist_ptr->nfiles = items.Size();
int i =
0;
for (IStorageItem
const& item : items) {
winrt::hstring path = item.Path();
uris[i++] = wchar2utf8(path.c_str(), path.size());
}
});
getDataThread.join();
}
return flist;
}