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.

764 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. #if JUCE_MSVC
  135. bool showDialog (IFileDialog& dialog, bool async) const
  136. {
  137. FILEOPENDIALOGOPTIONS flags = {};
  138. if (FAILED (dialog.GetOptions (&flags)))
  139. return false;
  140. const auto setBit = [] (FILEOPENDIALOGOPTIONS& field, bool value, FILEOPENDIALOGOPTIONS option)
  141. {
  142. if (value)
  143. field |= option;
  144. else
  145. field &= ~option;
  146. };
  147. setBit (flags, selectsDirectories, FOS_PICKFOLDERS);
  148. setBit (flags, warnAboutOverwrite, FOS_OVERWRITEPROMPT);
  149. setBit (flags, selectMultiple, FOS_ALLOWMULTISELECT);
  150. setBit (flags, customComponent != nullptr, FOS_FORCEPREVIEWPANEON);
  151. if (FAILED (dialog.SetOptions (flags)) || FAILED (dialog.SetTitle (title.toUTF16())))
  152. return false;
  153. PIDLIST_ABSOLUTE pidl = {};
  154. if (FAILED (SHParseDisplayName (initialPath.toWideCharPointer(), nullptr, &pidl, SFGAO_FOLDER, nullptr)))
  155. return false;
  156. const auto item = [&]
  157. {
  158. ComSmartPtr<IShellItem> ptr;
  159. SHCreateShellItem (nullptr, nullptr, pidl, ptr.resetAndGetPointerAddress());
  160. return ptr;
  161. }();
  162. if (item == nullptr || FAILED (dialog.SetFolder (item)))
  163. return false;
  164. String filename (files.getData());
  165. if (FAILED (dialog.SetFileName (filename.toWideCharPointer())))
  166. return false;
  167. auto extension = getDefaultFileExtension (filename);
  168. if (extension.isNotEmpty() && FAILED (dialog.SetDefaultExtension (extension.toWideCharPointer())))
  169. return false;
  170. const COMDLG_FILTERSPEC spec[] { { filtersString.toWideCharPointer(), filtersString.toWideCharPointer() } };
  171. if (! selectsDirectories && FAILED (dialog.SetFileTypes (numElementsInArray (spec), spec)))
  172. return false;
  173. return dialog.Show (static_cast<HWND> (async ? nullptr : owner->getWindowHandle())) == S_OK;
  174. }
  175. //==============================================================================
  176. Array<URL> openDialogVistaAndUp (bool async)
  177. {
  178. const auto getUrl = [] (IShellItem& item)
  179. {
  180. struct Free
  181. {
  182. void operator() (LPWSTR ptr) const noexcept { CoTaskMemFree (ptr); }
  183. };
  184. LPWSTR ptr = nullptr;
  185. item.GetDisplayName (SIGDN_URL, &ptr);
  186. return std::unique_ptr<WCHAR, Free> { ptr };
  187. };
  188. if (isSave)
  189. {
  190. const auto dialog = [&]
  191. {
  192. ComSmartPtr<IFileDialog> ptr;
  193. ptr.CoCreateInstance (CLSID_FileSaveDialog, CLSCTX_INPROC_SERVER);
  194. return ptr;
  195. }();
  196. if (dialog == nullptr)
  197. return {};
  198. showDialog (*dialog, async);
  199. const auto item = [&]
  200. {
  201. ComSmartPtr<IShellItem> ptr;
  202. dialog->GetResult (ptr.resetAndGetPointerAddress());
  203. return ptr;
  204. }();
  205. if (item == nullptr)
  206. return {};
  207. return { URL (String (getUrl (*item).get())) };
  208. }
  209. const auto dialog = [&]
  210. {
  211. ComSmartPtr<IFileOpenDialog> ptr;
  212. ptr.CoCreateInstance (CLSID_FileOpenDialog, CLSCTX_INPROC_SERVER);
  213. return ptr;
  214. }();
  215. if (dialog == nullptr)
  216. return {};
  217. showDialog (*dialog, async);
  218. const auto items = [&]
  219. {
  220. ComSmartPtr<IShellItemArray> ptr;
  221. dialog->GetResults (ptr.resetAndGetPointerAddress());
  222. return ptr;
  223. }();
  224. if (items == nullptr)
  225. return {};
  226. Array<URL> result;
  227. DWORD numItems = 0;
  228. items->GetCount (&numItems);
  229. for (DWORD i = 0; i < numItems; ++i)
  230. {
  231. ComSmartPtr<IShellItem> scope;
  232. items->GetItemAt (i, scope.resetAndGetPointerAddress());
  233. if (scope != nullptr)
  234. result.add (String (getUrl (*scope).get()));
  235. }
  236. return result;
  237. }
  238. #endif
  239. Array<URL> openDialogPreVista (bool async)
  240. {
  241. Array<URL> selections;
  242. if (selectsDirectories)
  243. {
  244. BROWSEINFO bi = {};
  245. bi.hwndOwner = (HWND) (async ? nullptr : owner->getWindowHandle());
  246. bi.pszDisplayName = files;
  247. bi.lpszTitle = title.toWideCharPointer();
  248. bi.lParam = (LPARAM) this;
  249. bi.lpfn = browseCallbackProc;
  250. #ifdef BIF_USENEWUI
  251. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  252. #else
  253. bi.ulFlags = 0x50;
  254. #endif
  255. LPITEMIDLIST list = SHBrowseForFolder (&bi);
  256. if (! SHGetPathFromIDListW (list, files))
  257. {
  258. files[0] = 0;
  259. returnedString.clear();
  260. }
  261. LPMALLOC al;
  262. if (list != nullptr && SUCCEEDED (SHGetMalloc (&al)))
  263. al->Free (list);
  264. if (files[0] != 0)
  265. {
  266. File result (String (files.get()));
  267. if (returnedString.isNotEmpty())
  268. result = result.getSiblingFile (returnedString);
  269. selections.add (URL (result));
  270. }
  271. }
  272. else
  273. {
  274. OPENFILENAMEW of = {};
  275. #ifdef OPENFILENAME_SIZE_VERSION_400W
  276. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  277. #else
  278. of.lStructSize = sizeof (of);
  279. #endif
  280. of.hwndOwner = (HWND) (async ? nullptr : owner->getWindowHandle());
  281. of.lpstrFilter = filters.getData();
  282. of.nFilterIndex = 1;
  283. of.lpstrFile = files;
  284. of.nMaxFile = (DWORD) charsAvailableForResult;
  285. of.lpstrInitialDir = initialPath.toWideCharPointer();
  286. of.lpstrTitle = title.toWideCharPointer();
  287. of.Flags = getOpenFilenameFlags (async);
  288. of.lCustData = (LPARAM) this;
  289. of.lpfnHook = &openCallback;
  290. if (isSave)
  291. {
  292. auto extension = getDefaultFileExtension (files.getData());
  293. if (extension.isNotEmpty())
  294. of.lpstrDefExt = extension.toWideCharPointer();
  295. if (! GetSaveFileName (&of))
  296. return {};
  297. }
  298. else
  299. {
  300. if (! GetOpenFileName (&of))
  301. return {};
  302. }
  303. if (selectMultiple && of.nFileOffset > 0 && files[of.nFileOffset - 1] == 0)
  304. {
  305. const WCHAR* filename = files + of.nFileOffset;
  306. while (*filename != 0)
  307. {
  308. selections.add (URL (File (String (files.get())).getChildFile (String (filename))));
  309. filename += wcslen (filename) + 1;
  310. }
  311. }
  312. else if (files[0] != 0)
  313. {
  314. selections.add (URL (File (String (files.get()))));
  315. }
  316. }
  317. return selections;
  318. }
  319. Array<URL> openDialog (bool async)
  320. {
  321. struct Remover
  322. {
  323. explicit Remover (Win32NativeFileChooser& chooser) : item (chooser) {}
  324. ~Remover() { getNativeDialogList().removeValue (&item); }
  325. Win32NativeFileChooser& item;
  326. };
  327. const Remover remover (*this);
  328. #if JUCE_MSVC
  329. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  330. return openDialogVistaAndUp (async);
  331. #endif
  332. return openDialogPreVista (async);
  333. }
  334. void run() override
  335. {
  336. // as long as the thread is running, don't delete this class
  337. Ptr safeThis (this);
  338. threadHasReference.signal();
  339. auto r = openDialog (true);
  340. MessageManager::callAsync ([safeThis, r]
  341. {
  342. safeThis->results = r;
  343. if (safeThis->owner != nullptr)
  344. safeThis->owner->exitModalState (r.size() > 0 ? 1 : 0);
  345. });
  346. }
  347. static HashMap<HWND, Win32NativeFileChooser*>& getNativeDialogList()
  348. {
  349. static HashMap<HWND, Win32NativeFileChooser*> dialogs;
  350. return dialogs;
  351. }
  352. static Win32NativeFileChooser* getNativePointerForDialog (HWND hWnd)
  353. {
  354. return getNativeDialogList()[hWnd];
  355. }
  356. //==============================================================================
  357. void setupFilters()
  358. {
  359. const size_t filterSpaceNumChars = 2048;
  360. filters.calloc (filterSpaceNumChars);
  361. const size_t bytesWritten = filtersString.copyToUTF16 (filters.getData(), filterSpaceNumChars * sizeof (WCHAR));
  362. filtersString.copyToUTF16 (filters + (bytesWritten / sizeof (WCHAR)),
  363. ((filterSpaceNumChars - 1) * sizeof (WCHAR) - bytesWritten));
  364. for (size_t i = 0; i < filterSpaceNumChars; ++i)
  365. if (filters[i] == '|')
  366. filters[i] = 0;
  367. }
  368. DWORD getOpenFilenameFlags (bool async)
  369. {
  370. DWORD ofFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_ENABLESIZING;
  371. if (warnAboutOverwrite)
  372. ofFlags |= OFN_OVERWRITEPROMPT;
  373. if (selectMultiple)
  374. ofFlags |= OFN_ALLOWMULTISELECT;
  375. if (async || customComponent != nullptr)
  376. ofFlags |= OFN_ENABLEHOOK;
  377. return ofFlags;
  378. }
  379. String getDefaultFileExtension (const String& filename) const
  380. {
  381. auto extension = filename.fromLastOccurrenceOf (".", false, false);
  382. if (extension.isEmpty())
  383. {
  384. auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'");
  385. tokens.trim();
  386. tokens.removeEmptyStrings();
  387. if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
  388. extension = tokens[0].fromFirstOccurrenceOf (".", false, false);
  389. }
  390. return extension;
  391. }
  392. //==============================================================================
  393. void initialised (HWND hWnd)
  394. {
  395. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) initialPath.toWideCharPointer());
  396. initDialog (hWnd);
  397. }
  398. void validateFailed (const String& path)
  399. {
  400. returnedString = path;
  401. }
  402. void initDialog (HWND hdlg)
  403. {
  404. ScopedLock lock (deletingDialog);
  405. getNativeDialogList().set (hdlg, this);
  406. if (shouldCancel.get() != 0)
  407. {
  408. EndDialog (hdlg, 0);
  409. }
  410. else
  411. {
  412. nativeDialogRef.set (hdlg);
  413. if (customComponent != nullptr)
  414. {
  415. Component::SafePointer<Component> safeCustomComponent (customComponent.get());
  416. RECT dialogScreenRect, dialogClientRect;
  417. GetWindowRect (hdlg, &dialogScreenRect);
  418. GetClientRect (hdlg, &dialogClientRect);
  419. auto screenRectangle = Rectangle<int>::leftTopRightBottom (dialogScreenRect.left, dialogScreenRect.top,
  420. dialogScreenRect.right, dialogScreenRect.bottom);
  421. auto scale = Desktop::getInstance().getDisplays().findDisplayForRect (screenRectangle, true).scale;
  422. auto physicalComponentWidth = roundToInt (safeCustomComponent->getWidth() * scale);
  423. SetWindowPos (hdlg, nullptr, screenRectangle.getX(), screenRectangle.getY(),
  424. physicalComponentWidth + jmax (150, screenRectangle.getWidth()),
  425. jmax (150, screenRectangle.getHeight()),
  426. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  427. auto appendCustomComponent = [safeCustomComponent, dialogClientRect, scale, hdlg]() mutable
  428. {
  429. if (safeCustomComponent != nullptr)
  430. {
  431. auto scaledClientRectangle = Rectangle<int>::leftTopRightBottom (dialogClientRect.left, dialogClientRect.top,
  432. dialogClientRect.right, dialogClientRect.bottom) / scale;
  433. safeCustomComponent->setBounds (scaledClientRectangle.getRight(), scaledClientRectangle.getY(),
  434. safeCustomComponent->getWidth(), scaledClientRectangle.getHeight());
  435. safeCustomComponent->addToDesktop (0, hdlg);
  436. }
  437. };
  438. if (MessageManager::getInstance()->isThisTheMessageThread())
  439. appendCustomComponent();
  440. else
  441. MessageManager::callAsync (appendCustomComponent);
  442. }
  443. }
  444. }
  445. void destroyDialog (HWND hdlg)
  446. {
  447. ScopedLock exiting (deletingDialog);
  448. getNativeDialogList().remove (hdlg);
  449. nativeDialogRef.set (nullptr);
  450. if (MessageManager::getInstance()->isThisTheMessageThread())
  451. customComponent = nullptr;
  452. else
  453. MessageManager::callAsync ([this] { customComponent = nullptr; });
  454. }
  455. void selectionChanged (HWND hdlg)
  456. {
  457. ScopedLock lock (deletingDialog);
  458. if (customComponent != nullptr && shouldCancel.get() == 0)
  459. {
  460. if (FilePreviewComponent* comp = dynamic_cast<FilePreviewComponent*> (customComponent->getChildComponent (0)))
  461. {
  462. WCHAR path [MAX_PATH * 2] = { 0 };
  463. CommDlg_OpenSave_GetFilePath (hdlg, (LPARAM) &path, MAX_PATH);
  464. if (MessageManager::getInstance()->isThisTheMessageThread())
  465. {
  466. comp->selectedFileChanged (File (path));
  467. }
  468. else
  469. {
  470. Component::SafePointer<FilePreviewComponent> safeComp (comp);
  471. File selectedFile (path);
  472. MessageManager::callAsync ([safeComp, selectedFile]() mutable
  473. {
  474. safeComp->selectedFileChanged (selectedFile);
  475. });
  476. }
  477. }
  478. }
  479. }
  480. //==============================================================================
  481. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM lpData)
  482. {
  483. auto* self = reinterpret_cast<Win32NativeFileChooser*> (lpData);
  484. switch (msg)
  485. {
  486. case BFFM_INITIALIZED: self->initialised (hWnd); break;
  487. case BFFM_VALIDATEFAILEDW: self->validateFailed (String ((LPCWSTR) lParam)); break;
  488. case BFFM_VALIDATEFAILEDA: self->validateFailed (String ((const char*) lParam)); break;
  489. default: break;
  490. }
  491. return 0;
  492. }
  493. static UINT_PTR CALLBACK openCallback (HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  494. {
  495. auto hdlg = getDialogFromHWND (hwnd);
  496. switch (uiMsg)
  497. {
  498. case WM_INITDIALOG:
  499. {
  500. if (auto* self = reinterpret_cast<Win32NativeFileChooser*> (((OPENFILENAMEW*) lParam)->lCustData))
  501. self->initDialog (hdlg);
  502. break;
  503. }
  504. case WM_DESTROY:
  505. {
  506. if (auto* self = getNativeDialogList()[hdlg])
  507. self->destroyDialog (hdlg);
  508. break;
  509. }
  510. case WM_NOTIFY:
  511. {
  512. auto ofn = reinterpret_cast<LPOFNOTIFY> (lParam);
  513. if (ofn->hdr.code == CDN_SELCHANGE)
  514. if (auto* self = reinterpret_cast<Win32NativeFileChooser*> (ofn->lpOFN->lCustData))
  515. self->selectionChanged (hdlg);
  516. break;
  517. }
  518. default:
  519. break;
  520. }
  521. return 0;
  522. }
  523. static HWND getDialogFromHWND (HWND hwnd)
  524. {
  525. if (hwnd == nullptr)
  526. return nullptr;
  527. HWND dialogH = GetParent (hwnd);
  528. if (dialogH == nullptr)
  529. dialogH = hwnd;
  530. return dialogH;
  531. }
  532. //==============================================================================
  533. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Win32NativeFileChooser)
  534. };
  535. class FileChooser::Native : public Component,
  536. public FileChooser::Pimpl
  537. {
  538. public:
  539. Native (FileChooser& fileChooser, int flags, FilePreviewComponent* previewComp)
  540. : owner (fileChooser),
  541. nativeFileChooser (new Win32NativeFileChooser (this, flags, previewComp, fileChooser.startingFile,
  542. fileChooser.title, fileChooser.filters))
  543. {
  544. auto mainMon = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
  545. setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  546. mainMon.getY() + mainMon.getHeight() / 4,
  547. 0, 0);
  548. setOpaque (true);
  549. setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
  550. addToDesktop (0);
  551. }
  552. ~Native() override
  553. {
  554. exitModalState (0);
  555. nativeFileChooser->cancel();
  556. nativeFileChooser = nullptr;
  557. }
  558. void launch() override
  559. {
  560. SafePointer<Native> safeThis (this);
  561. enterModalState (true, ModalCallbackFunction::create (
  562. [safeThis] (int)
  563. {
  564. if (safeThis != nullptr)
  565. safeThis->owner.finished (safeThis->nativeFileChooser->results);
  566. }));
  567. nativeFileChooser->open (true);
  568. }
  569. void runModally() override
  570. {
  571. enterModalState (true);
  572. nativeFileChooser->open (false);
  573. exitModalState (nativeFileChooser->results.size() > 0 ? 1 : 0);
  574. nativeFileChooser->cancel();
  575. owner.finished (nativeFileChooser->results);
  576. }
  577. bool canModalEventBeSentToComponent (const Component* targetComponent) override
  578. {
  579. if (targetComponent == nullptr)
  580. return false;
  581. if (targetComponent == nativeFileChooser->getCustomComponent())
  582. return true;
  583. return targetComponent->findParentComponentOfClass<FilePreviewComponent>() != nullptr;
  584. }
  585. private:
  586. FileChooser& owner;
  587. Win32NativeFileChooser::Ptr nativeFileChooser;
  588. };
  589. //==============================================================================
  590. bool FileChooser::isPlatformDialogAvailable()
  591. {
  592. #if JUCE_DISABLE_NATIVE_FILECHOOSERS
  593. return false;
  594. #else
  595. return true;
  596. #endif
  597. }
  598. FileChooser::Pimpl* FileChooser::showPlatformDialog (FileChooser& owner, int flags,
  599. FilePreviewComponent* preview)
  600. {
  601. return new FileChooser::Native (owner, flags, preview);
  602. }
  603. } // namespace juce