Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

760 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. // Win32NativeFileChooser needs to be a reference counted object as there
  21. // is no way for the parent to know when the dialog HWND has actually been
  22. // created without pumping the message thread (which is forbidden when modal
  23. // loops are disabled). However, the HWND pointer is the only way to cancel
  24. // the dialog box. This means that the actual native FileChooser HWND may
  25. // not have been created yet when the user deletes JUCE's FileChooser class. If this
  26. // occurs the Win32NativeFileChooser will still have a reference count of 1 and will
  27. // simply delete itself immediately once the HWND will have been created a while later.
  28. class Win32NativeFileChooser : public ReferenceCountedObject,
  29. private Thread
  30. {
  31. public:
  32. using Ptr = ReferenceCountedObjectPtr<Win32NativeFileChooser>;
  33. enum { charsAvailableForResult = 32768 };
  34. Win32NativeFileChooser (Component* parent, int flags, FilePreviewComponent* previewComp,
  35. const File& startingFile, const String& titleToUse,
  36. const String& filtersToUse)
  37. : Thread ("Native Win32 FileChooser"),
  38. owner (parent), title (titleToUse), filtersString (filtersToUse),
  39. selectsDirectories ((flags & FileBrowserComponent::canSelectDirectories) != 0),
  40. isSave ((flags & FileBrowserComponent::saveMode) != 0),
  41. warnAboutOverwrite ((flags & FileBrowserComponent::warnAboutOverwriting) != 0),
  42. selectMultiple ((flags & FileBrowserComponent::canSelectMultipleItems) != 0),
  43. nativeDialogRef (nullptr), shouldCancel (0)
  44. {
  45. auto parentDirectory = startingFile.getParentDirectory();
  46. // Handle nonexistent root directories in the same way as existing ones
  47. files.calloc (static_cast<size_t> (charsAvailableForResult) + 1);
  48. if (startingFile.isDirectory() || startingFile.isRoot())
  49. {
  50. initialPath = startingFile.getFullPathName();
  51. }
  52. else
  53. {
  54. startingFile.getFileName().copyToUTF16 (files,
  55. static_cast<size_t> (charsAvailableForResult) * sizeof (WCHAR));
  56. initialPath = parentDirectory.getFullPathName();
  57. }
  58. if (! selectsDirectories)
  59. {
  60. if (previewComp != nullptr)
  61. customComponent.reset (new CustomComponentHolder (previewComp));
  62. setupFilters();
  63. }
  64. }
  65. ~Win32NativeFileChooser()
  66. {
  67. signalThreadShouldExit();
  68. waitForThreadToExit (-1);
  69. }
  70. void open (bool async)
  71. {
  72. results.clear();
  73. // the thread should not be running
  74. nativeDialogRef.set (nullptr);
  75. if (async)
  76. {
  77. jassert (! isThreadRunning());
  78. threadHasReference.reset();
  79. startThread();
  80. threadHasReference.wait (-1);
  81. }
  82. else
  83. {
  84. results = openDialog (false);
  85. owner->exitModalState (results.size() > 0 ? 1 : 0);
  86. }
  87. }
  88. void cancel()
  89. {
  90. ScopedLock lock (deletingDialog);
  91. customComponent = nullptr;
  92. shouldCancel.set (1);
  93. if (auto hwnd = nativeDialogRef.get())
  94. EndDialog (hwnd, 0);
  95. }
  96. Component* getCustomComponent() { return customComponent.get(); }
  97. Array<URL> results;
  98. private:
  99. //==============================================================================
  100. class CustomComponentHolder : public Component
  101. {
  102. public:
  103. CustomComponentHolder (Component* const customComp)
  104. {
  105. setVisible (true);
  106. setOpaque (true);
  107. addAndMakeVisible (customComp);
  108. setSize (jlimit (20, 800, customComp->getWidth()), customComp->getHeight());
  109. }
  110. void paint (Graphics& g) override
  111. {
  112. g.fillAll (Colours::lightgrey);
  113. }
  114. void resized() override
  115. {
  116. if (Component* const c = getChildComponent(0))
  117. c->setBounds (getLocalBounds());
  118. }
  119. private:
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomComponentHolder)
  121. };
  122. //==============================================================================
  123. Component::SafePointer<Component> owner;
  124. String title, filtersString;
  125. std::unique_ptr<CustomComponentHolder> customComponent;
  126. String initialPath, returnedString;
  127. WaitableEvent threadHasReference;
  128. CriticalSection deletingDialog;
  129. bool selectsDirectories, isSave, warnAboutOverwrite, selectMultiple;
  130. HeapBlock<WCHAR> files;
  131. HeapBlock<WCHAR> filters;
  132. Atomic<HWND> nativeDialogRef;
  133. Atomic<int> shouldCancel;
  134. bool showDialog (IFileDialog& dialog, bool async) const
  135. {
  136. FILEOPENDIALOGOPTIONS flags = {};
  137. if (FAILED (dialog.GetOptions (&flags)))
  138. return false;
  139. const auto setBit = [] (FILEOPENDIALOGOPTIONS& field, bool value, FILEOPENDIALOGOPTIONS option)
  140. {
  141. if (value)
  142. field |= option;
  143. else
  144. field &= ~option;
  145. };
  146. setBit (flags, selectsDirectories, FOS_PICKFOLDERS);
  147. setBit (flags, warnAboutOverwrite, FOS_OVERWRITEPROMPT);
  148. setBit (flags, selectMultiple, FOS_ALLOWMULTISELECT);
  149. setBit (flags, customComponent != nullptr, FOS_FORCEPREVIEWPANEON);
  150. if (FAILED (dialog.SetOptions (flags)) || FAILED (dialog.SetTitle (title.toUTF16())))
  151. return false;
  152. PIDLIST_ABSOLUTE pidl = {};
  153. if (FAILED (SHParseDisplayName (initialPath.toWideCharPointer(), nullptr, &pidl, SFGAO_FOLDER, nullptr)))
  154. return false;
  155. const auto item = [&]
  156. {
  157. ComSmartPtr<IShellItem> ptr;
  158. SHCreateShellItem (nullptr, nullptr, pidl, ptr.resetAndGetPointerAddress());
  159. return ptr;
  160. }();
  161. if (item == nullptr || FAILED (dialog.SetFolder (item)))
  162. return false;
  163. String filename (files.getData());
  164. if (FAILED (dialog.SetFileName (filename.toWideCharPointer())))
  165. return false;
  166. auto extension = getDefaultFileExtension (filename);
  167. if (extension.isNotEmpty() && FAILED (dialog.SetDefaultExtension (extension.toWideCharPointer())))
  168. return false;
  169. const COMDLG_FILTERSPEC spec[] { { filtersString.toWideCharPointer(), filtersString.toWideCharPointer() } };
  170. if (! selectsDirectories && FAILED (dialog.SetFileTypes (numElementsInArray (spec), spec)))
  171. return false;
  172. return dialog.Show (static_cast<HWND> (async ? nullptr : owner->getWindowHandle())) == S_OK;
  173. }
  174. //==============================================================================
  175. Array<URL> openDialogVistaAndUp (bool async)
  176. {
  177. const auto getUrl = [] (IShellItem& item)
  178. {
  179. struct Free
  180. {
  181. void operator() (LPWSTR ptr) const noexcept { CoTaskMemFree (ptr); }
  182. };
  183. LPWSTR ptr = nullptr;
  184. item.GetDisplayName (SIGDN_URL, &ptr);
  185. return std::unique_ptr<WCHAR, Free> { ptr };
  186. };
  187. if (isSave)
  188. {
  189. const auto dialog = [&]
  190. {
  191. ComSmartPtr<IFileDialog> ptr;
  192. ptr.CoCreateInstance (CLSID_FileSaveDialog, CLSCTX_INPROC_SERVER);
  193. return ptr;
  194. }();
  195. if (dialog == nullptr)
  196. return {};
  197. showDialog (*dialog, async);
  198. const auto item = [&]
  199. {
  200. ComSmartPtr<IShellItem> ptr;
  201. dialog->GetResult (ptr.resetAndGetPointerAddress());
  202. return ptr;
  203. }();
  204. if (item == nullptr)
  205. return {};
  206. return { URL (String (getUrl (*item).get())) };
  207. }
  208. const auto dialog = [&]
  209. {
  210. ComSmartPtr<IFileOpenDialog> ptr;
  211. ptr.CoCreateInstance (CLSID_FileOpenDialog, CLSCTX_INPROC_SERVER);
  212. return ptr;
  213. }();
  214. if (dialog == nullptr)
  215. return {};
  216. showDialog (*dialog, async);
  217. const auto items = [&]
  218. {
  219. ComSmartPtr<IShellItemArray> ptr;
  220. dialog->GetResults (ptr.resetAndGetPointerAddress());
  221. return ptr;
  222. }();
  223. if (items == nullptr)
  224. return {};
  225. Array<URL> result;
  226. DWORD numItems = 0;
  227. items->GetCount (&numItems);
  228. for (DWORD i = 0; i < numItems; ++i)
  229. {
  230. ComSmartPtr<IShellItem> scope;
  231. items->GetItemAt (i, scope.resetAndGetPointerAddress());
  232. if (scope != nullptr)
  233. result.add (String (getUrl (*scope).get()));
  234. }
  235. return result;
  236. }
  237. Array<URL> openDialogPreVista (bool async)
  238. {
  239. Array<URL> selections;
  240. if (selectsDirectories)
  241. {
  242. BROWSEINFO bi = {};
  243. bi.hwndOwner = (HWND) (async ? nullptr : owner->getWindowHandle());
  244. bi.pszDisplayName = files;
  245. bi.lpszTitle = title.toWideCharPointer();
  246. bi.lParam = (LPARAM) this;
  247. bi.lpfn = browseCallbackProc;
  248. #ifdef BIF_USENEWUI
  249. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  250. #else
  251. bi.ulFlags = 0x50;
  252. #endif
  253. LPITEMIDLIST list = SHBrowseForFolder (&bi);
  254. if (! SHGetPathFromIDListW (list, files))
  255. {
  256. files[0] = 0;
  257. returnedString.clear();
  258. }
  259. LPMALLOC al;
  260. if (list != nullptr && SUCCEEDED (SHGetMalloc (&al)))
  261. al->Free (list);
  262. if (files[0] != 0)
  263. {
  264. File result (String (files.get()));
  265. if (returnedString.isNotEmpty())
  266. result = result.getSiblingFile (returnedString);
  267. selections.add (URL (result));
  268. }
  269. }
  270. else
  271. {
  272. OPENFILENAMEW of = {};
  273. #ifdef OPENFILENAME_SIZE_VERSION_400W
  274. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  275. #else
  276. of.lStructSize = sizeof (of);
  277. #endif
  278. of.hwndOwner = (HWND) (async ? nullptr : owner->getWindowHandle());
  279. of.lpstrFilter = filters.getData();
  280. of.nFilterIndex = 1;
  281. of.lpstrFile = files;
  282. of.nMaxFile = (DWORD) charsAvailableForResult;
  283. of.lpstrInitialDir = initialPath.toWideCharPointer();
  284. of.lpstrTitle = title.toWideCharPointer();
  285. of.Flags = getOpenFilenameFlags (async);
  286. of.lCustData = (LPARAM) this;
  287. of.lpfnHook = &openCallback;
  288. if (isSave)
  289. {
  290. auto extension = getDefaultFileExtension (files.getData());
  291. if (extension.isNotEmpty())
  292. of.lpstrDefExt = extension.toWideCharPointer();
  293. if (! GetSaveFileName (&of))
  294. return {};
  295. }
  296. else
  297. {
  298. if (! GetOpenFileName (&of))
  299. return {};
  300. }
  301. if (selectMultiple && of.nFileOffset > 0 && files[of.nFileOffset - 1] == 0)
  302. {
  303. const WCHAR* filename = files + of.nFileOffset;
  304. while (*filename != 0)
  305. {
  306. selections.add (URL (File (String (files.get())).getChildFile (String (filename))));
  307. filename += wcslen (filename) + 1;
  308. }
  309. }
  310. else if (files[0] != 0)
  311. {
  312. selections.add (URL (File (String (files.get()))));
  313. }
  314. }
  315. return selections;
  316. }
  317. Array<URL> openDialog (bool async)
  318. {
  319. struct Remover
  320. {
  321. explicit Remover (Win32NativeFileChooser& chooser) : item (chooser) {}
  322. ~Remover() { getNativeDialogList().removeValue (&item); }
  323. Win32NativeFileChooser& item;
  324. };
  325. const Remover remover (*this);
  326. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  327. return openDialogVistaAndUp (async);
  328. return openDialogPreVista (async);
  329. }
  330. void run() override
  331. {
  332. // as long as the thread is running, don't delete this class
  333. Ptr safeThis (this);
  334. threadHasReference.signal();
  335. auto r = openDialog (true);
  336. MessageManager::callAsync ([safeThis, r]
  337. {
  338. safeThis->results = r;
  339. if (safeThis->owner != nullptr)
  340. safeThis->owner->exitModalState (r.size() > 0 ? 1 : 0);
  341. });
  342. }
  343. static HashMap<HWND, Win32NativeFileChooser*>& getNativeDialogList()
  344. {
  345. static HashMap<HWND, Win32NativeFileChooser*> dialogs;
  346. return dialogs;
  347. }
  348. static Win32NativeFileChooser* getNativePointerForDialog (HWND hWnd)
  349. {
  350. return getNativeDialogList()[hWnd];
  351. }
  352. //==============================================================================
  353. void setupFilters()
  354. {
  355. const size_t filterSpaceNumChars = 2048;
  356. filters.calloc (filterSpaceNumChars);
  357. const size_t bytesWritten = filtersString.copyToUTF16 (filters.getData(), filterSpaceNumChars * sizeof (WCHAR));
  358. filtersString.copyToUTF16 (filters + (bytesWritten / sizeof (WCHAR)),
  359. ((filterSpaceNumChars - 1) * sizeof (WCHAR) - bytesWritten));
  360. for (size_t i = 0; i < filterSpaceNumChars; ++i)
  361. if (filters[i] == '|')
  362. filters[i] = 0;
  363. }
  364. DWORD getOpenFilenameFlags (bool async)
  365. {
  366. DWORD ofFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_ENABLESIZING;
  367. if (warnAboutOverwrite)
  368. ofFlags |= OFN_OVERWRITEPROMPT;
  369. if (selectMultiple)
  370. ofFlags |= OFN_ALLOWMULTISELECT;
  371. if (async || customComponent != nullptr)
  372. ofFlags |= OFN_ENABLEHOOK;
  373. return ofFlags;
  374. }
  375. String getDefaultFileExtension (const String& filename) const
  376. {
  377. auto extension = filename.fromLastOccurrenceOf (".", false, false);
  378. if (extension.isEmpty())
  379. {
  380. auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'");
  381. tokens.trim();
  382. tokens.removeEmptyStrings();
  383. if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
  384. extension = tokens[0].fromFirstOccurrenceOf (".", false, false);
  385. }
  386. return extension;
  387. }
  388. //==============================================================================
  389. void initialised (HWND hWnd)
  390. {
  391. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) initialPath.toWideCharPointer());
  392. initDialog (hWnd);
  393. }
  394. void validateFailed (const String& path)
  395. {
  396. returnedString = path;
  397. }
  398. void initDialog (HWND hdlg)
  399. {
  400. ScopedLock lock (deletingDialog);
  401. getNativeDialogList().set (hdlg, this);
  402. if (shouldCancel.get() != 0)
  403. {
  404. EndDialog (hdlg, 0);
  405. }
  406. else
  407. {
  408. nativeDialogRef.set (hdlg);
  409. if (customComponent != nullptr)
  410. {
  411. Component::SafePointer<Component> safeCustomComponent (customComponent.get());
  412. RECT dialogScreenRect, dialogClientRect;
  413. GetWindowRect (hdlg, &dialogScreenRect);
  414. GetClientRect (hdlg, &dialogClientRect);
  415. auto screenRectangle = Rectangle<int>::leftTopRightBottom (dialogScreenRect.left, dialogScreenRect.top,
  416. dialogScreenRect.right, dialogScreenRect.bottom);
  417. auto scale = Desktop::getInstance().getDisplays().findDisplayForRect (screenRectangle, true).scale;
  418. auto physicalComponentWidth = roundToInt (safeCustomComponent->getWidth() * scale);
  419. SetWindowPos (hdlg, nullptr, screenRectangle.getX(), screenRectangle.getY(),
  420. physicalComponentWidth + jmax (150, screenRectangle.getWidth()),
  421. jmax (150, screenRectangle.getHeight()),
  422. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  423. auto appendCustomComponent = [safeCustomComponent, dialogClientRect, scale, hdlg]() mutable
  424. {
  425. if (safeCustomComponent != nullptr)
  426. {
  427. auto scaledClientRectangle = Rectangle<int>::leftTopRightBottom (dialogClientRect.left, dialogClientRect.top,
  428. dialogClientRect.right, dialogClientRect.bottom) / scale;
  429. safeCustomComponent->setBounds (scaledClientRectangle.getRight(), scaledClientRectangle.getY(),
  430. safeCustomComponent->getWidth(), scaledClientRectangle.getHeight());
  431. safeCustomComponent->addToDesktop (0, hdlg);
  432. }
  433. };
  434. if (MessageManager::getInstance()->isThisTheMessageThread())
  435. appendCustomComponent();
  436. else
  437. MessageManager::callAsync (appendCustomComponent);
  438. }
  439. }
  440. }
  441. void destroyDialog (HWND hdlg)
  442. {
  443. ScopedLock exiting (deletingDialog);
  444. getNativeDialogList().remove (hdlg);
  445. nativeDialogRef.set (nullptr);
  446. if (MessageManager::getInstance()->isThisTheMessageThread())
  447. customComponent = nullptr;
  448. else
  449. MessageManager::callAsync ([this] { customComponent = nullptr; });
  450. }
  451. void selectionChanged (HWND hdlg)
  452. {
  453. ScopedLock lock (deletingDialog);
  454. if (customComponent != nullptr && shouldCancel.get() == 0)
  455. {
  456. if (FilePreviewComponent* comp = dynamic_cast<FilePreviewComponent*> (customComponent->getChildComponent (0)))
  457. {
  458. WCHAR path [MAX_PATH * 2] = { 0 };
  459. CommDlg_OpenSave_GetFilePath (hdlg, (LPARAM) &path, MAX_PATH);
  460. if (MessageManager::getInstance()->isThisTheMessageThread())
  461. {
  462. comp->selectedFileChanged (File (path));
  463. }
  464. else
  465. {
  466. Component::SafePointer<FilePreviewComponent> safeComp (comp);
  467. File selectedFile (path);
  468. MessageManager::callAsync ([safeComp, selectedFile]() mutable
  469. {
  470. safeComp->selectedFileChanged (selectedFile);
  471. });
  472. }
  473. }
  474. }
  475. }
  476. //==============================================================================
  477. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM lpData)
  478. {
  479. auto* self = reinterpret_cast<Win32NativeFileChooser*> (lpData);
  480. switch (msg)
  481. {
  482. case BFFM_INITIALIZED: self->initialised (hWnd); break;
  483. case BFFM_VALIDATEFAILEDW: self->validateFailed (String ((LPCWSTR) lParam)); break;
  484. case BFFM_VALIDATEFAILEDA: self->validateFailed (String ((const char*) lParam)); break;
  485. default: break;
  486. }
  487. return 0;
  488. }
  489. static UINT_PTR CALLBACK openCallback (HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  490. {
  491. auto hdlg = getDialogFromHWND (hwnd);
  492. switch (uiMsg)
  493. {
  494. case WM_INITDIALOG:
  495. {
  496. if (auto* self = reinterpret_cast<Win32NativeFileChooser*> (((OPENFILENAMEW*) lParam)->lCustData))
  497. self->initDialog (hdlg);
  498. break;
  499. }
  500. case WM_DESTROY:
  501. {
  502. if (auto* self = getNativeDialogList()[hdlg])
  503. self->destroyDialog (hdlg);
  504. break;
  505. }
  506. case WM_NOTIFY:
  507. {
  508. auto ofn = reinterpret_cast<LPOFNOTIFY> (lParam);
  509. if (ofn->hdr.code == CDN_SELCHANGE)
  510. if (auto* self = reinterpret_cast<Win32NativeFileChooser*> (ofn->lpOFN->lCustData))
  511. self->selectionChanged (hdlg);
  512. break;
  513. }
  514. default:
  515. break;
  516. }
  517. return 0;
  518. }
  519. static HWND getDialogFromHWND (HWND hwnd)
  520. {
  521. if (hwnd == nullptr)
  522. return nullptr;
  523. HWND dialogH = GetParent (hwnd);
  524. if (dialogH == nullptr)
  525. dialogH = hwnd;
  526. return dialogH;
  527. }
  528. //==============================================================================
  529. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Win32NativeFileChooser)
  530. };
  531. class FileChooser::Native : public Component,
  532. public FileChooser::Pimpl
  533. {
  534. public:
  535. Native (FileChooser& fileChooser, int flags, FilePreviewComponent* previewComp)
  536. : owner (fileChooser),
  537. nativeFileChooser (new Win32NativeFileChooser (this, flags, previewComp, fileChooser.startingFile,
  538. fileChooser.title, fileChooser.filters))
  539. {
  540. auto mainMon = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
  541. setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  542. mainMon.getY() + mainMon.getHeight() / 4,
  543. 0, 0);
  544. setOpaque (true);
  545. setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
  546. addToDesktop (0);
  547. }
  548. ~Native() override
  549. {
  550. exitModalState (0);
  551. nativeFileChooser->cancel();
  552. nativeFileChooser = nullptr;
  553. }
  554. void launch() override
  555. {
  556. SafePointer<Native> safeThis (this);
  557. enterModalState (true, ModalCallbackFunction::create (
  558. [safeThis] (int)
  559. {
  560. if (safeThis != nullptr)
  561. safeThis->owner.finished (safeThis->nativeFileChooser->results);
  562. }));
  563. nativeFileChooser->open (true);
  564. }
  565. void runModally() override
  566. {
  567. enterModalState (true);
  568. nativeFileChooser->open (false);
  569. exitModalState (nativeFileChooser->results.size() > 0 ? 1 : 0);
  570. nativeFileChooser->cancel();
  571. owner.finished (nativeFileChooser->results);
  572. }
  573. bool canModalEventBeSentToComponent (const Component* targetComponent) override
  574. {
  575. if (targetComponent == nullptr)
  576. return false;
  577. if (targetComponent == nativeFileChooser->getCustomComponent())
  578. return true;
  579. return targetComponent->findParentComponentOfClass<FilePreviewComponent>() != nullptr;
  580. }
  581. private:
  582. FileChooser& owner;
  583. Win32NativeFileChooser::Ptr nativeFileChooser;
  584. };
  585. //==============================================================================
  586. bool FileChooser::isPlatformDialogAvailable()
  587. {
  588. #if JUCE_DISABLE_NATIVE_FILECHOOSERS
  589. return false;
  590. #else
  591. return true;
  592. #endif
  593. }
  594. FileChooser::Pimpl* FileChooser::showPlatformDialog (FileChooser& owner, int flags,
  595. FilePreviewComponent* preview)
  596. {
  597. return new FileChooser::Native (owner, flags, preview);
  598. }
  599. } // namespace juce