ui/winui/dnd.cpp

changeset 18
af411868ab9b
parent 0
2483f517c562
--- a/ui/winui/dnd.cpp	Wed Jan 31 12:55:11 2024 +0100
+++ b/ui/winui/dnd.cpp	Tue Feb 06 14:17:22 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