ui/winui/dnd.cpp

branch
newapi
changeset 243
9f66c31a27ed
parent 224
88bc21b19213
--- a/ui/winui/dnd.cpp	Wed Jan 31 19:15:41 2024 +0100
+++ b/ui/winui/dnd.cpp	Thu Feb 01 19:45:17 2024 +0100
@@ -31,6 +31,13 @@
 #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) {
@@ -54,6 +61,31 @@
 	return nullptr;
 }
 
-UIEXPORT char** ui_selection_geturis(UiDnD* dnd, size_t* nelm) {
-	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;
+
+		// we need to execute this in a different thread
+		// this could block the main gui thread, but shouldn't happen with a simple uri list
+		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;
 }

mercurial