The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

818 lines
29KB

  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. //==============================================================================
  21. static int numAlwaysOnTopPeers = 0;
  22. bool juce_areThereAnyAlwaysOnTopWindows() { return numAlwaysOnTopPeers > 0; }
  23. //==============================================================================
  24. class LinuxComponentPeer : public ComponentPeer,
  25. private XWindowSystemUtilities::XSettings::Listener
  26. {
  27. public:
  28. LinuxComponentPeer (Component& comp, int windowStyleFlags, ::Window parentToAddTo)
  29. : ComponentPeer (comp, windowStyleFlags),
  30. isAlwaysOnTop (comp.isAlwaysOnTop())
  31. {
  32. // it's dangerous to create a window on a thread other than the message thread.
  33. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  34. const auto* instance = XWindowSystem::getInstance();
  35. if (! instance->isX11Available())
  36. return;
  37. if (isAlwaysOnTop)
  38. ++numAlwaysOnTopPeers;
  39. repainter = std::make_unique<LinuxRepaintManager> (*this);
  40. windowH = instance->createWindow (parentToAddTo, this);
  41. parentWindow = parentToAddTo;
  42. setTitle (component.getName());
  43. if (auto* xSettings = instance->getXSettings())
  44. xSettings->addListener (this);
  45. getNativeRealtimeModifiers = []() -> ModifierKeys { return XWindowSystem::getInstance()->getNativeRealtimeModifiers(); };
  46. }
  47. ~LinuxComponentPeer() override
  48. {
  49. // it's dangerous to delete a window on a thread other than the message thread.
  50. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  51. auto* instance = XWindowSystem::getInstance();
  52. repainter = nullptr;
  53. instance->destroyWindow (windowH);
  54. if (auto* xSettings = instance->getXSettings())
  55. xSettings->removeListener (this);
  56. if (isAlwaysOnTop)
  57. --numAlwaysOnTopPeers;
  58. }
  59. ::Window getWindowHandle() const noexcept
  60. {
  61. return windowH;
  62. }
  63. //==============================================================================
  64. void* getNativeHandle() const override
  65. {
  66. return reinterpret_cast<void*> (getWindowHandle());
  67. }
  68. //==============================================================================
  69. void setBounds (const Rectangle<int>& newBounds, bool isNowFullScreen) override
  70. {
  71. const auto correctedNewBounds = newBounds.withSize (jmax (1, newBounds.getWidth()),
  72. jmax (1, newBounds.getHeight()));
  73. if (bounds == correctedNewBounds && fullScreen == isNowFullScreen)
  74. return;
  75. bounds = correctedNewBounds;
  76. updateScaleFactorFromNewBounds (bounds, false);
  77. auto physicalBounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (bounds)
  78. : bounds * currentScaleFactor;
  79. WeakReference<Component> deletionChecker (&component);
  80. XWindowSystem::getInstance()->setBounds (windowH, physicalBounds, isNowFullScreen);
  81. fullScreen = isNowFullScreen;
  82. if (deletionChecker != nullptr)
  83. {
  84. updateBorderSize();
  85. handleMovedOrResized();
  86. }
  87. }
  88. Point<int> getScreenPosition (bool physical) const
  89. {
  90. auto physicalParentPosition = XWindowSystem::getInstance()->getPhysicalParentScreenPosition();
  91. auto parentPosition = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalParentPosition)
  92. : physicalParentPosition / currentScaleFactor;
  93. auto screenBounds = parentWindow == 0 ? bounds
  94. : bounds.translated (parentPosition.x, parentPosition.y);
  95. if (physical)
  96. return parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (screenBounds.getTopLeft())
  97. : screenBounds.getTopLeft() * currentScaleFactor;
  98. return screenBounds.getTopLeft();
  99. }
  100. Rectangle<int> getBounds() const override
  101. {
  102. return bounds;
  103. }
  104. BorderSize<int> getFrameSize() const override
  105. {
  106. return windowBorder;
  107. }
  108. Point<float> localToGlobal (Point<float> relativePosition) override
  109. {
  110. return relativePosition + getScreenPosition (false).toFloat();
  111. }
  112. Point<float> globalToLocal (Point<float> screenPosition) override
  113. {
  114. return screenPosition - getScreenPosition (false).toFloat();
  115. }
  116. using ComponentPeer::localToGlobal;
  117. using ComponentPeer::globalToLocal;
  118. //==============================================================================
  119. StringArray getAvailableRenderingEngines() override
  120. {
  121. return { "Software Renderer" };
  122. }
  123. void setVisible (bool shouldBeVisible) override
  124. {
  125. XWindowSystem::getInstance()->setVisible (windowH, shouldBeVisible);
  126. }
  127. void setTitle (const String& title) override
  128. {
  129. XWindowSystem::getInstance()->setTitle (windowH, title);
  130. }
  131. void setMinimised (bool shouldBeMinimised) override
  132. {
  133. if (shouldBeMinimised)
  134. XWindowSystem::getInstance()->setMinimised (windowH, shouldBeMinimised);
  135. else
  136. setVisible (true);
  137. }
  138. bool isMinimised() const override
  139. {
  140. return XWindowSystem::getInstance()->isMinimised (windowH);
  141. }
  142. void setFullScreen (bool shouldBeFullScreen) override
  143. {
  144. auto r = lastNonFullscreenBounds; // (get a copy of this before de-minimising)
  145. setMinimised (false);
  146. if (fullScreen != shouldBeFullScreen)
  147. {
  148. const auto usingNativeTitleBar = ((styleFlags & windowHasTitleBar) != 0);
  149. if (usingNativeTitleBar)
  150. XWindowSystem::getInstance()->setMaximised (windowH, shouldBeFullScreen);
  151. if (shouldBeFullScreen)
  152. r = usingNativeTitleBar ? XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow)
  153. : Desktop::getInstance().getDisplays().getDisplayForRect (bounds)->userArea;
  154. if (! r.isEmpty())
  155. setBounds (ScalingHelpers::scaledScreenPosToUnscaled (component, r), shouldBeFullScreen);
  156. component.repaint();
  157. }
  158. }
  159. bool isFullScreen() const override
  160. {
  161. return fullScreen;
  162. }
  163. bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
  164. {
  165. if (! bounds.withZeroOrigin().contains (localPos))
  166. return false;
  167. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  168. {
  169. auto* c = Desktop::getInstance().getComponent (i);
  170. if (c == &component)
  171. break;
  172. if (! c->isVisible())
  173. continue;
  174. if (auto* peer = c->getPeer())
  175. if (peer->contains (localPos + bounds.getPosition() - peer->getBounds().getPosition(), true))
  176. return false;
  177. }
  178. if (trueIfInAChildWindow)
  179. return true;
  180. return XWindowSystem::getInstance()->contains (windowH, localPos * currentScaleFactor);
  181. }
  182. void toFront (bool makeActive) override
  183. {
  184. if (makeActive)
  185. {
  186. setVisible (true);
  187. grabFocus();
  188. }
  189. XWindowSystem::getInstance()->toFront (windowH, makeActive);
  190. handleBroughtToFront();
  191. }
  192. void toBehind (ComponentPeer* other) override
  193. {
  194. if (auto* otherPeer = dynamic_cast<LinuxComponentPeer*> (other))
  195. {
  196. if (otherPeer->styleFlags & windowIsTemporary)
  197. return;
  198. setMinimised (false);
  199. XWindowSystem::getInstance()->toBehind (windowH, otherPeer->windowH);
  200. }
  201. else
  202. {
  203. jassertfalse; // wrong type of window?
  204. }
  205. }
  206. bool isFocused() const override
  207. {
  208. return XWindowSystem::getInstance()->isFocused (windowH);
  209. }
  210. void grabFocus() override
  211. {
  212. if (XWindowSystem::getInstance()->grabFocus (windowH))
  213. isActiveApplication = true;
  214. }
  215. //==============================================================================
  216. void repaint (const Rectangle<int>& area) override
  217. {
  218. if (repainter != nullptr)
  219. repainter->repaint (area.getIntersection (bounds.withZeroOrigin()));
  220. }
  221. void performAnyPendingRepaintsNow() override
  222. {
  223. if (repainter != nullptr)
  224. repainter->performAnyPendingRepaintsNow();
  225. }
  226. void setIcon (const Image& newIcon) override
  227. {
  228. XWindowSystem::getInstance()->setIcon (windowH, newIcon);
  229. }
  230. double getPlatformScaleFactor() const noexcept override
  231. {
  232. return currentScaleFactor;
  233. }
  234. void setAlpha (float) override {}
  235. bool setAlwaysOnTop (bool) override { return false; }
  236. void textInputRequired (Point<int>, TextInputTarget&) override {}
  237. //==============================================================================
  238. void addOpenGLRepaintListener (Component* dummy)
  239. {
  240. if (dummy != nullptr)
  241. glRepaintListeners.addIfNotAlreadyThere (dummy);
  242. }
  243. void removeOpenGLRepaintListener (Component* dummy)
  244. {
  245. if (dummy != nullptr)
  246. glRepaintListeners.removeAllInstancesOf (dummy);
  247. }
  248. void repaintOpenGLContexts()
  249. {
  250. for (auto* c : glRepaintListeners)
  251. c->handleCommandMessage (0);
  252. }
  253. //==============================================================================
  254. ::Window getParentWindow() { return parentWindow; }
  255. void setParentWindow (::Window newParent) { parentWindow = newParent; }
  256. //==============================================================================
  257. void updateWindowBounds()
  258. {
  259. jassert (windowH != 0);
  260. if (windowH != 0)
  261. {
  262. auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow);
  263. updateScaleFactorFromNewBounds (physicalBounds, true);
  264. bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
  265. : physicalBounds / currentScaleFactor;
  266. }
  267. }
  268. void updateBorderSize()
  269. {
  270. if ((styleFlags & windowHasTitleBar) == 0)
  271. windowBorder = {};
  272. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  273. windowBorder = XWindowSystem::getInstance()->getBorderSize (windowH);
  274. }
  275. //==============================================================================
  276. static bool isActiveApplication;
  277. bool focused = false;
  278. private:
  279. //==============================================================================
  280. class LinuxRepaintManager : public Timer
  281. {
  282. public:
  283. LinuxRepaintManager (LinuxComponentPeer& p)
  284. : peer (p),
  285. isSemiTransparentWindow ((peer.getStyleFlags() & ComponentPeer::windowIsSemiTransparent) != 0)
  286. {
  287. }
  288. void timerCallback() override
  289. {
  290. XWindowSystem::getInstance()->processPendingPaintsForWindow (peer.windowH);
  291. if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
  292. return;
  293. if (! regionsNeedingRepaint.isEmpty())
  294. {
  295. stopTimer();
  296. performAnyPendingRepaintsNow();
  297. }
  298. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  299. {
  300. stopTimer();
  301. image = Image();
  302. }
  303. }
  304. void repaint (Rectangle<int> area)
  305. {
  306. if (! isTimerRunning())
  307. startTimer (repaintTimerPeriod);
  308. regionsNeedingRepaint.add (area * peer.currentScaleFactor);
  309. }
  310. void performAnyPendingRepaintsNow()
  311. {
  312. if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
  313. {
  314. startTimer (repaintTimerPeriod);
  315. return;
  316. }
  317. auto originalRepaintRegion = regionsNeedingRepaint;
  318. regionsNeedingRepaint.clear();
  319. auto totalArea = originalRepaintRegion.getBounds();
  320. if (! totalArea.isEmpty())
  321. {
  322. if (image.isNull() || image.getWidth() < totalArea.getWidth()
  323. || image.getHeight() < totalArea.getHeight())
  324. {
  325. image = XWindowSystem::getInstance()->createImage (isSemiTransparentWindow,
  326. totalArea.getWidth(), totalArea.getHeight(),
  327. useARGBImagesForRendering);
  328. }
  329. startTimer (repaintTimerPeriod);
  330. RectangleList<int> adjustedList (originalRepaintRegion);
  331. adjustedList.offsetAll (-totalArea.getX(), -totalArea.getY());
  332. if (XWindowSystem::getInstance()->canUseARGBImages())
  333. for (auto& i : originalRepaintRegion)
  334. image.clear (i - totalArea.getPosition());
  335. {
  336. auto context = peer.getComponent().getLookAndFeel()
  337. .createGraphicsContext (image, -totalArea.getPosition(), adjustedList);
  338. context->addTransform (AffineTransform::scale ((float) peer.currentScaleFactor));
  339. peer.handlePaint (*context);
  340. }
  341. for (auto& i : originalRepaintRegion)
  342. XWindowSystem::getInstance()->blitToWindow (peer.windowH, image, i, totalArea);
  343. }
  344. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  345. startTimer (repaintTimerPeriod);
  346. }
  347. private:
  348. enum { repaintTimerPeriod = 1000 / 100 };
  349. LinuxComponentPeer& peer;
  350. const bool isSemiTransparentWindow;
  351. Image image;
  352. uint32 lastTimeImageUsed = 0;
  353. RectangleList<int> regionsNeedingRepaint;
  354. bool useARGBImagesForRendering = XWindowSystem::getInstance()->canUseARGBImages();
  355. JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager)
  356. };
  357. //==============================================================================
  358. void settingChanged (const XWindowSystemUtilities::XSetting& settingThatHasChanged) override
  359. {
  360. if (settingThatHasChanged.name == XWindowSystem::getWindowScalingFactorSettingName())
  361. forceDisplayUpdate();
  362. }
  363. void updateScaleFactorFromNewBounds (const Rectangle<int>& newBounds, bool isPhysical)
  364. {
  365. Point<int> translation = (parentWindow != 0 ? getScreenPosition (isPhysical) : Point<int>());
  366. const auto& desktop = Desktop::getInstance();
  367. if (auto* display = desktop.getDisplays().getDisplayForRect (newBounds.translated (translation.x, translation.y),
  368. isPhysical))
  369. {
  370. auto newScaleFactor = display->scale / desktop.getGlobalScaleFactor();
  371. if (! approximatelyEqual (newScaleFactor, currentScaleFactor))
  372. {
  373. currentScaleFactor = newScaleFactor;
  374. scaleFactorListeners.call ([&] (ScaleFactorListener& l) { l.nativeScaleFactorChanged (currentScaleFactor); });
  375. }
  376. }
  377. }
  378. //==============================================================================
  379. std::unique_ptr<LinuxRepaintManager> repainter;
  380. ::Window windowH = {}, parentWindow = {};
  381. Rectangle<int> bounds;
  382. BorderSize<int> windowBorder;
  383. bool fullScreen = false, isAlwaysOnTop = false;
  384. double currentScaleFactor = 1.0;
  385. Array<Component*> glRepaintListeners;
  386. //==============================================================================
  387. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LinuxComponentPeer)
  388. };
  389. bool LinuxComponentPeer::isActiveApplication = false;
  390. //==============================================================================
  391. ComponentPeer* Component::createNewPeer (int styleFlags, void* nativeWindowToAttachTo)
  392. {
  393. return new LinuxComponentPeer (*this, styleFlags, (::Window) nativeWindowToAttachTo);
  394. }
  395. //==============================================================================
  396. JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { return LinuxComponentPeer::isActiveApplication; }
  397. JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() {}
  398. JUCE_API void JUCE_CALLTYPE Process::hide() {}
  399. //==============================================================================
  400. void Desktop::setKioskComponent (Component* comp, bool enableOrDisable, bool)
  401. {
  402. if (enableOrDisable)
  403. comp->setBounds (getDisplays().getDisplayForRect (comp->getScreenBounds())->totalArea);
  404. }
  405. void Displays::findDisplays (float masterScale)
  406. {
  407. if (XWindowSystem::getInstance()->getDisplay() != nullptr)
  408. {
  409. displays = XWindowSystem::getInstance()->findDisplays (masterScale);
  410. if (! displays.isEmpty())
  411. updateToLogical();
  412. }
  413. }
  414. bool Desktop::canUseSemiTransparentWindows() noexcept
  415. {
  416. return XWindowSystem::getInstance()->canUseSemiTransparentWindows();
  417. }
  418. static bool screenSaverAllowed = true;
  419. void Desktop::setScreenSaverEnabled (bool isEnabled)
  420. {
  421. if (screenSaverAllowed != isEnabled)
  422. {
  423. screenSaverAllowed = isEnabled;
  424. XWindowSystem::getInstance()->setScreenSaverEnabled (screenSaverAllowed);
  425. }
  426. }
  427. bool Desktop::isScreenSaverEnabled()
  428. {
  429. return screenSaverAllowed;
  430. }
  431. double Desktop::getDefaultMasterScale() { return 1.0; }
  432. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const { return upright; }
  433. void Desktop::allowedOrientationsChanged() {}
  434. //==============================================================================
  435. bool MouseInputSource::SourceList::addSource()
  436. {
  437. if (sources.isEmpty())
  438. {
  439. addSource (0, MouseInputSource::InputSourceType::mouse);
  440. return true;
  441. }
  442. return false;
  443. }
  444. bool MouseInputSource::SourceList::canUseTouch()
  445. {
  446. return false;
  447. }
  448. Point<float> MouseInputSource::getCurrentRawMousePosition()
  449. {
  450. return Desktop::getInstance().getDisplays().physicalToLogical (XWindowSystem::getInstance()->getCurrentMousePosition());
  451. }
  452. void MouseInputSource::setRawMousePosition (Point<float> newPosition)
  453. {
  454. XWindowSystem::getInstance()->setMousePosition (Desktop::getInstance().getDisplays().logicalToPhysical (newPosition));
  455. }
  456. //==============================================================================
  457. void* CustomMouseCursorInfo::create() const
  458. {
  459. return XWindowSystem::getInstance()->createCustomMouseCursorInfo (image, hotspot);
  460. }
  461. void MouseCursor::deleteMouseCursor (void* cursorHandle, bool)
  462. {
  463. if (cursorHandle != nullptr)
  464. XWindowSystem::getInstance()->deleteMouseCursor (cursorHandle);
  465. }
  466. void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type)
  467. {
  468. return XWindowSystem::getInstance()->createStandardMouseCursor (type);
  469. }
  470. void MouseCursor::showInWindow (ComponentPeer* peer) const
  471. {
  472. if (peer != nullptr)
  473. XWindowSystem::getInstance()->showCursor ((::Window) peer->getNativeHandle(), getHandle());
  474. }
  475. //==============================================================================
  476. static LinuxComponentPeer* getPeerForDragEvent (Component* sourceComp)
  477. {
  478. if (sourceComp == nullptr)
  479. if (auto* draggingSource = Desktop::getInstance().getDraggingMouseSource (0))
  480. sourceComp = draggingSource->getComponentUnderMouse();
  481. if (sourceComp != nullptr)
  482. if (auto* lp = dynamic_cast<LinuxComponentPeer*> (sourceComp->getPeer()))
  483. return lp;
  484. jassertfalse; // This method must be called in response to a component's mouseDown or mouseDrag event!
  485. return nullptr;
  486. }
  487. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, bool canMoveFiles,
  488. Component* sourceComp, std::function<void()> callback)
  489. {
  490. if (files.isEmpty())
  491. return false;
  492. if (auto* peer = getPeerForDragEvent (sourceComp))
  493. return XWindowSystem::getInstance()->externalDragFileInit (peer, files, canMoveFiles, std::move (callback));
  494. // This method must be called in response to a component's mouseDown or mouseDrag event!
  495. jassertfalse;
  496. return false;
  497. }
  498. bool DragAndDropContainer::performExternalDragDropOfText (const String& text, Component* sourceComp,
  499. std::function<void()> callback)
  500. {
  501. if (text.isEmpty())
  502. return false;
  503. if (auto* peer = getPeerForDragEvent (sourceComp))
  504. return XWindowSystem::getInstance()->externalDragTextInit (peer, text, std::move (callback));
  505. // This method must be called in response to a component's mouseDown or mouseDrag event!
  506. jassertfalse;
  507. return false;
  508. }
  509. //==============================================================================
  510. void SystemClipboard::copyTextToClipboard (const String& clipText)
  511. {
  512. XWindowSystem::getInstance()->copyTextToClipboard (clipText);
  513. }
  514. String SystemClipboard::getTextFromClipboard()
  515. {
  516. return XWindowSystem::getInstance()->getTextFromClipboard();
  517. }
  518. //==============================================================================
  519. bool KeyPress::isKeyCurrentlyDown (int keyCode)
  520. {
  521. return XWindowSystem::getInstance()->isKeyCurrentlyDown (keyCode);
  522. }
  523. void LookAndFeel::playAlertSound()
  524. {
  525. std::cout << "\a" << std::flush;
  526. }
  527. //==============================================================================
  528. static int showDialog (const MessageBoxOptions& options,
  529. ModalComponentManager::Callback* callback,
  530. Async async)
  531. {
  532. const auto dummyCallback = [] (int) {};
  533. switch (options.getNumButtons())
  534. {
  535. case 2:
  536. {
  537. if (async == Async::yes && callback == nullptr)
  538. callback = ModalCallbackFunction::create (dummyCallback);
  539. return AlertWindow::showOkCancelBox (options.getIconType(),
  540. options.getTitle(),
  541. options.getMessage(),
  542. options.getButtonText (0),
  543. options.getButtonText (1),
  544. options.getAssociatedComponent(),
  545. callback) ? 1 : 0;
  546. }
  547. case 3:
  548. {
  549. if (async == Async::yes && callback == nullptr)
  550. callback = ModalCallbackFunction::create (dummyCallback);
  551. return AlertWindow::showYesNoCancelBox (options.getIconType(),
  552. options.getTitle(),
  553. options.getMessage(),
  554. options.getButtonText (0),
  555. options.getButtonText (1),
  556. options.getButtonText (2),
  557. options.getAssociatedComponent(),
  558. callback);
  559. }
  560. case 1:
  561. default:
  562. break;
  563. }
  564. #if JUCE_MODAL_LOOPS_PERMITTED
  565. if (async == Async::no)
  566. {
  567. AlertWindow::showMessageBox (options.getIconType(),
  568. options.getTitle(),
  569. options.getMessage(),
  570. options.getButtonText (0),
  571. options.getAssociatedComponent());
  572. }
  573. else
  574. #endif
  575. {
  576. AlertWindow::showMessageBoxAsync (options.getIconType(),
  577. options.getTitle(),
  578. options.getMessage(),
  579. options.getButtonText (0),
  580. options.getAssociatedComponent(),
  581. callback);
  582. }
  583. return 0;
  584. }
  585. #if JUCE_MODAL_LOOPS_PERMITTED
  586. void JUCE_CALLTYPE NativeMessageBox::showMessageBox (MessageBoxIconType iconType,
  587. const String& title, const String& message,
  588. Component* /*associatedComponent*/)
  589. {
  590. AlertWindow::showMessageBox (iconType, title, message);
  591. }
  592. int JUCE_CALLTYPE NativeMessageBox::show (const MessageBoxOptions& options)
  593. {
  594. return showDialog (options, nullptr, Async::no);
  595. }
  596. #endif
  597. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (MessageBoxIconType iconType,
  598. const String& title, const String& message,
  599. Component* associatedComponent,
  600. ModalComponentManager::Callback* callback)
  601. {
  602. AlertWindow::showMessageBoxAsync (iconType, title, message, {}, associatedComponent, callback);
  603. }
  604. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (MessageBoxIconType iconType,
  605. const String& title, const String& message,
  606. Component* associatedComponent,
  607. ModalComponentManager::Callback* callback)
  608. {
  609. return AlertWindow::showOkCancelBox (iconType, title, message, {}, {}, associatedComponent, callback);
  610. }
  611. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (MessageBoxIconType iconType,
  612. const String& title, const String& message,
  613. Component* associatedComponent,
  614. ModalComponentManager::Callback* callback)
  615. {
  616. return AlertWindow::showYesNoCancelBox (iconType, title, message, {}, {}, {},
  617. associatedComponent, callback);
  618. }
  619. int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (MessageBoxIconType iconType,
  620. const String& title, const String& message,
  621. Component* associatedComponent,
  622. ModalComponentManager::Callback* callback)
  623. {
  624. return AlertWindow::showOkCancelBox (iconType, title, message, TRANS("Yes"), TRANS("No"),
  625. associatedComponent, callback);
  626. }
  627. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  628. ModalComponentManager::Callback* callback)
  629. {
  630. showDialog (options, callback, Async::yes);
  631. }
  632. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  633. std::function<void (int)> callback)
  634. {
  635. showAsync (options, ModalCallbackFunction::create (callback));
  636. }
  637. //==============================================================================
  638. Image juce_createIconForFile (const File&)
  639. {
  640. return {};
  641. }
  642. void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component* dummy)
  643. {
  644. if (auto* linuxPeer = dynamic_cast<LinuxComponentPeer*> (peer))
  645. linuxPeer->addOpenGLRepaintListener (dummy);
  646. }
  647. void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component* dummy)
  648. {
  649. if (auto* linuxPeer = dynamic_cast<LinuxComponentPeer*> (peer))
  650. linuxPeer->removeOpenGLRepaintListener (dummy);
  651. }
  652. } // namespace juce