44 #include <cx/mempool.h> |
44 #include <cx/mempool.h> |
45 |
45 |
46 #include "MainWindow.xaml.h" |
46 #include "MainWindow.xaml.h" |
47 |
47 |
48 |
48 |
|
49 #include <Windows.h> |
|
50 #include <shobjidl.h> |
|
51 #include <iostream> |
|
52 |
49 using namespace winrt; |
53 using namespace winrt; |
50 using namespace Microsoft::UI::Xaml; |
54 using namespace Microsoft::UI::Xaml; |
51 using namespace Microsoft::UI::Xaml::Controls; |
55 using namespace Microsoft::UI::Xaml::Controls; |
52 using namespace Microsoft::UI::Xaml::Controls::Primitives; |
56 using namespace Microsoft::UI::Xaml::Controls::Primitives; |
53 using namespace Microsoft::UI::Xaml::XamlTypeInfo; |
57 using namespace Microsoft::UI::Xaml::XamlTypeInfo; |
355 files.Append(file); |
359 files.Append(file); |
356 filedialog_callback(obj, file_selected_callback, cbdata, files.GetView()); |
360 filedialog_callback(obj, file_selected_callback, cbdata, files.GetView()); |
357 } |
361 } |
358 } |
362 } |
359 |
363 |
|
364 static Windows::Foundation::IAsyncAction save_filedialog_async(UiObject *obj, char *name, ui_callback file_selected_callback, void *cbdata) { |
|
365 IFileSaveDialog *saveFileDialog; |
|
366 |
|
367 HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_ALL, IID_IFileSaveDialog, reinterpret_cast<void**>(&saveFileDialog)); |
|
368 if (FAILED(hr)) |
|
369 { |
|
370 co_return; |
|
371 } |
|
372 |
|
373 if (name) { |
|
374 wchar_t *wname = str2wstr(name, NULL); |
|
375 saveFileDialog->SetFileName(wname); |
|
376 free(wname); |
|
377 free(name); |
|
378 } |
|
379 |
|
380 |
|
381 hr = saveFileDialog->Show(NULL); |
|
382 if (SUCCEEDED(hr)) { |
|
383 IShellItem *item; |
|
384 hr = saveFileDialog->GetResult(&item); |
|
385 if (SUCCEEDED(hr)) { |
|
386 PWSTR wpath; |
|
387 hr = item->GetDisplayName(SIGDN_FILESYSPATH, &wpath); |
|
388 |
|
389 if (SUCCEEDED(hr)) { |
|
390 char *path = wchar2utf8(wpath, lstrlen(wpath)); |
|
391 CoTaskMemFree(wpath); |
|
392 |
|
393 UiFileList flist; |
|
394 flist.nfiles = 1; |
|
395 flist.files = new char*[1]; |
|
396 flist.files[0] = path; |
|
397 |
|
398 UiEvent evt; |
|
399 evt.obj = obj; |
|
400 evt.document = obj->ctx->document; |
|
401 evt.window = obj->window; |
|
402 evt.eventdata = &flist; |
|
403 evt.intval = 0; |
|
404 file_selected_callback(&evt, cbdata); |
|
405 |
|
406 free(path); |
|
407 delete[] flist.files; |
|
408 } |
|
409 item->Release(); |
|
410 } |
|
411 } |
|
412 |
|
413 // cleanup |
|
414 saveFileDialog->Release(); |
|
415 } |
|
416 |
360 static Windows::Foundation::IAsyncAction folderdialog_async(UiObject *obj, ui_callback file_selected_callback, void *cbdata) { |
417 static Windows::Foundation::IAsyncAction folderdialog_async(UiObject *obj, ui_callback file_selected_callback, void *cbdata) { |
361 FolderPicker folderPicker = FolderPicker(); |
418 FolderPicker folderPicker = FolderPicker(); |
362 auto initializeWithWindow { folderPicker.as<::IInitializeWithWindow>() |
419 auto initializeWithWindow { folderPicker.as<::IInitializeWithWindow>() |
363 }; |
420 }; |
364 |
421 |
394 } else { |
451 } else { |
395 open_filedialog_async(obj, mode, file_selected_callback, cbdata); |
452 open_filedialog_async(obj, mode, file_selected_callback, cbdata); |
396 } |
453 } |
397 } |
454 } |
398 |
455 |
399 UIEXPORT void ui_savefiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) { |
456 UIEXPORT void ui_savefiledialog(UiObject *obj, const char *name, ui_callback file_selected_callback, void *cbdata) { |
400 |
457 char *n = name ? _strdup(name) : NULL; |
401 } |
458 save_filedialog_async(obj, n, file_selected_callback, cbdata); |
|
459 } |