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.

796 lines
26KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. static juce_wchar getDefaultPasswordChar() noexcept
  16. {
  17. #if JUCE_LINUX || JUCE_BSD
  18. return 0x2022;
  19. #else
  20. return 0x25cf;
  21. #endif
  22. }
  23. //==============================================================================
  24. AlertWindow::AlertWindow (const String& title,
  25. const String& message,
  26. MessageBoxIconType iconType,
  27. Component* comp)
  28. : TopLevelWindow (title, true),
  29. alertIconType (iconType),
  30. associatedComponent (comp),
  31. desktopScale (comp != nullptr ? Component::getApproximateScaleFactorForComponent (comp) : 1.0f)
  32. {
  33. setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
  34. accessibleMessageLabel.setColour (Label::textColourId, Colours::transparentBlack);
  35. accessibleMessageLabel.setColour (Label::backgroundColourId, Colours::transparentBlack);
  36. accessibleMessageLabel.setColour (Label::outlineColourId, Colours::transparentBlack);
  37. accessibleMessageLabel.setInterceptsMouseClicks (false, false);
  38. addAndMakeVisible (accessibleMessageLabel);
  39. if (message.isEmpty())
  40. text = " "; // to force an update if the message is empty
  41. setMessage (message);
  42. AlertWindow::lookAndFeelChanged();
  43. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  44. }
  45. AlertWindow::~AlertWindow()
  46. {
  47. // Ensure that the focus does not jump to another TextEditor while we
  48. // remove children.
  49. for (auto* t : textBoxes)
  50. t->setWantsKeyboardFocus (false);
  51. // Give away focus before removing the editors, so that any TextEditor
  52. // with focus has a chance to dismiss native keyboard if shown.
  53. giveAwayKeyboardFocus();
  54. removeAllChildren();
  55. }
  56. void AlertWindow::userTriedToCloseWindow()
  57. {
  58. if (escapeKeyCancels || buttons.size() > 0)
  59. exitModalState (0);
  60. }
  61. //==============================================================================
  62. void AlertWindow::setMessage (const String& message)
  63. {
  64. auto newMessage = message.substring (0, 2048);
  65. if (text != newMessage)
  66. {
  67. text = newMessage;
  68. auto accessibleText = getName() + ". " + text;
  69. accessibleMessageLabel.setText (accessibleText, NotificationType::dontSendNotification);
  70. setDescription (accessibleText);
  71. updateLayout (true);
  72. repaint();
  73. }
  74. }
  75. //==============================================================================
  76. void AlertWindow::exitAlert (Button* button)
  77. {
  78. if (auto* parent = button->getParentComponent())
  79. parent->exitModalState (button->getCommandID());
  80. }
  81. //==============================================================================
  82. void AlertWindow::addButton (const String& name,
  83. const int returnValue,
  84. const KeyPress& shortcutKey1,
  85. const KeyPress& shortcutKey2)
  86. {
  87. auto* b = new TextButton (name, {});
  88. buttons.add (b);
  89. b->setWantsKeyboardFocus (true);
  90. b->setExplicitFocusOrder (1);
  91. b->setMouseClickGrabsKeyboardFocus (false);
  92. b->setCommandToTrigger (nullptr, returnValue, false);
  93. b->addShortcut (shortcutKey1);
  94. b->addShortcut (shortcutKey2);
  95. b->onClick = [this, b] { exitAlert (b); };
  96. Array<TextButton*> buttonsArray (buttons.begin(), buttons.size());
  97. auto& lf = getLookAndFeel();
  98. auto buttonHeight = lf.getAlertWindowButtonHeight();
  99. auto buttonWidths = lf.getWidthsForTextButtons (*this, buttonsArray);
  100. jassert (buttonWidths.size() == buttons.size());
  101. int i = 0;
  102. for (auto* button : buttons)
  103. button->setSize (buttonWidths[i++], buttonHeight);
  104. addAndMakeVisible (b, 0);
  105. updateLayout (false);
  106. }
  107. int AlertWindow::getNumButtons() const
  108. {
  109. return buttons.size();
  110. }
  111. void AlertWindow::triggerButtonClick (const String& buttonName)
  112. {
  113. for (auto* b : buttons)
  114. {
  115. if (buttonName == b->getName())
  116. {
  117. b->triggerClick();
  118. break;
  119. }
  120. }
  121. }
  122. void AlertWindow::setEscapeKeyCancels (bool shouldEscapeKeyCancel)
  123. {
  124. escapeKeyCancels = shouldEscapeKeyCancel;
  125. }
  126. //==============================================================================
  127. void AlertWindow::addTextEditor (const String& name,
  128. const String& initialContents,
  129. const String& onScreenLabel,
  130. const bool isPasswordBox)
  131. {
  132. auto* ed = new TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0);
  133. ed->setSelectAllWhenFocused (true);
  134. ed->setEscapeAndReturnKeysConsumed (false);
  135. textBoxes.add (ed);
  136. allComps.add (ed);
  137. ed->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  138. ed->setFont (getLookAndFeel().getAlertWindowMessageFont());
  139. addAndMakeVisible (ed);
  140. ed->setText (initialContents);
  141. ed->setCaretPosition (initialContents.length());
  142. textboxNames.add (onScreenLabel);
  143. updateLayout (false);
  144. }
  145. TextEditor* AlertWindow::getTextEditor (const String& nameOfTextEditor) const
  146. {
  147. for (auto* tb : textBoxes)
  148. if (tb->getName() == nameOfTextEditor)
  149. return tb;
  150. return nullptr;
  151. }
  152. String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  153. {
  154. if (auto* t = getTextEditor (nameOfTextEditor))
  155. return t->getText();
  156. return {};
  157. }
  158. //==============================================================================
  159. void AlertWindow::addComboBox (const String& name,
  160. const StringArray& items,
  161. const String& onScreenLabel)
  162. {
  163. auto* cb = new ComboBox (name);
  164. comboBoxes.add (cb);
  165. allComps.add (cb);
  166. cb->addItemList (items, 1);
  167. addAndMakeVisible (cb);
  168. cb->setSelectedItemIndex (0);
  169. comboBoxNames.add (onScreenLabel);
  170. updateLayout (false);
  171. }
  172. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  173. {
  174. for (auto* cb : comboBoxes)
  175. if (cb->getName() == nameOfList)
  176. return cb;
  177. return nullptr;
  178. }
  179. //==============================================================================
  180. class AlertTextComp : public TextEditor
  181. {
  182. public:
  183. AlertTextComp (AlertWindow& owner, const String& message, const Font& font)
  184. {
  185. if (owner.isColourSpecified (AlertWindow::textColourId))
  186. setColour (TextEditor::textColourId, owner.findColour (AlertWindow::textColourId));
  187. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  188. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  189. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  190. setReadOnly (true);
  191. setMultiLine (true, true);
  192. setCaretVisible (false);
  193. setScrollbarsShown (true);
  194. lookAndFeelChanged();
  195. setWantsKeyboardFocus (false);
  196. setFont (font);
  197. setText (message, false);
  198. bestWidth = 2 * (int) std::sqrt (font.getHeight() * (float) font.getStringWidth (message));
  199. }
  200. void updateLayout (const int width)
  201. {
  202. AttributedString s;
  203. s.setJustification (Justification::topLeft);
  204. s.append (getText(), getFont());
  205. TextLayout text;
  206. text.createLayoutWithBalancedLineLengths (s, (float) width - 8.0f);
  207. setSize (width, jmin (width, (int) (text.getHeight() + getFont().getHeight())));
  208. }
  209. int bestWidth;
  210. JUCE_DECLARE_NON_COPYABLE (AlertTextComp)
  211. };
  212. void AlertWindow::addTextBlock (const String& textBlock)
  213. {
  214. auto* c = new AlertTextComp (*this, textBlock, getLookAndFeel().getAlertWindowMessageFont());
  215. textBlocks.add (c);
  216. allComps.add (c);
  217. addAndMakeVisible (c);
  218. updateLayout (false);
  219. }
  220. //==============================================================================
  221. void AlertWindow::addProgressBarComponent (double& progressValue)
  222. {
  223. auto* pb = new ProgressBar (progressValue);
  224. progressBars.add (pb);
  225. allComps.add (pb);
  226. addAndMakeVisible (pb);
  227. updateLayout (false);
  228. }
  229. //==============================================================================
  230. void AlertWindow::addCustomComponent (Component* const component)
  231. {
  232. customComps.add (component);
  233. allComps.add (component);
  234. addAndMakeVisible (component);
  235. updateLayout (false);
  236. }
  237. int AlertWindow::getNumCustomComponents() const { return customComps.size(); }
  238. Component* AlertWindow::getCustomComponent (int index) const { return customComps [index]; }
  239. Component* AlertWindow::removeCustomComponent (const int index)
  240. {
  241. auto* c = getCustomComponent (index);
  242. if (c != nullptr)
  243. {
  244. customComps.removeFirstMatchingValue (c);
  245. allComps.removeFirstMatchingValue (c);
  246. removeChildComponent (c);
  247. updateLayout (false);
  248. }
  249. return c;
  250. }
  251. //==============================================================================
  252. void AlertWindow::paint (Graphics& g)
  253. {
  254. auto& lf = getLookAndFeel();
  255. lf.drawAlertBox (g, *this, textArea, textLayout);
  256. g.setColour (findColour (textColourId));
  257. g.setFont (lf.getAlertWindowFont());
  258. for (int i = textBoxes.size(); --i >= 0;)
  259. {
  260. auto* te = textBoxes.getUnchecked(i);
  261. g.drawFittedText (textboxNames[i],
  262. te->getX(), te->getY() - 14,
  263. te->getWidth(), 14,
  264. Justification::centredLeft, 1);
  265. }
  266. for (int i = comboBoxNames.size(); --i >= 0;)
  267. {
  268. auto* cb = comboBoxes.getUnchecked(i);
  269. g.drawFittedText (comboBoxNames[i],
  270. cb->getX(), cb->getY() - 14,
  271. cb->getWidth(), 14,
  272. Justification::centredLeft, 1);
  273. }
  274. for (auto* c : customComps)
  275. g.drawFittedText (c->getName(),
  276. c->getX(), c->getY() - 14,
  277. c->getWidth(), 14,
  278. Justification::centredLeft, 1);
  279. }
  280. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  281. {
  282. const int titleH = 24;
  283. const int iconWidth = 80;
  284. auto& lf = getLookAndFeel();
  285. auto messageFont (lf.getAlertWindowMessageFont());
  286. auto wid = jmax (messageFont.getStringWidth (text),
  287. messageFont.getStringWidth (getName()));
  288. auto sw = (int) std::sqrt (messageFont.getHeight() * (float) wid);
  289. auto w = jmin (300 + sw * 2, (int) ((float) getParentWidth() * 0.7f));
  290. const int edgeGap = 10;
  291. const int labelHeight = 18;
  292. int iconSpace = 0;
  293. AttributedString attributedText;
  294. attributedText.append (getName(), lf.getAlertWindowTitleFont());
  295. if (text.isNotEmpty())
  296. attributedText.append ("\n\n" + text, messageFont);
  297. attributedText.setColour (findColour (textColourId));
  298. if (alertIconType == NoIcon)
  299. {
  300. attributedText.setJustification (Justification::centredTop);
  301. textLayout.createLayoutWithBalancedLineLengths (attributedText, (float) w);
  302. }
  303. else
  304. {
  305. attributedText.setJustification (Justification::topLeft);
  306. textLayout.createLayoutWithBalancedLineLengths (attributedText, (float) w);
  307. iconSpace = iconWidth;
  308. }
  309. w = jmax (350, (int) textLayout.getWidth() + iconSpace + edgeGap * 4);
  310. w = jmin (w, (int) ((float) getParentWidth() * 0.7f));
  311. auto textLayoutH = (int) textLayout.getHeight();
  312. auto textBottom = 16 + titleH + textLayoutH;
  313. int h = textBottom;
  314. int buttonW = 40;
  315. for (auto* b : buttons)
  316. buttonW += 16 + b->getWidth();
  317. w = jmax (buttonW, w);
  318. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  319. if (auto* b = buttons[0])
  320. h += 20 + b->getHeight();
  321. for (auto* c : customComps)
  322. {
  323. w = jmax (w, (c->getWidth() * 100) / 80);
  324. h += 10 + c->getHeight();
  325. if (c->getName().isNotEmpty())
  326. h += labelHeight;
  327. }
  328. for (auto* tb : textBlocks)
  329. w = jmax (w, static_cast<const AlertTextComp*> (tb)->bestWidth);
  330. w = jmin (w, (int) ((float) getParentWidth() * 0.7f));
  331. for (auto* tb : textBlocks)
  332. {
  333. auto* ac = static_cast<AlertTextComp*> (tb);
  334. ac->updateLayout ((int) ((float) w * 0.8f));
  335. h += ac->getHeight() + 10;
  336. }
  337. h = jmin (getParentHeight() - 50, h);
  338. if (onlyIncreaseSize)
  339. {
  340. w = jmax (w, getWidth());
  341. h = jmax (h, getHeight());
  342. }
  343. if (! isVisible())
  344. centreAroundComponent (associatedComponent, w, h);
  345. else
  346. setBounds (getBounds().withSizeKeepingCentre (w, h));
  347. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  348. accessibleMessageLabel.setBounds (textArea);
  349. const int spacer = 16;
  350. int totalWidth = -spacer;
  351. for (auto* b : buttons)
  352. totalWidth += b->getWidth() + spacer;
  353. auto x = (w - totalWidth) / 2;
  354. auto y = (int) ((float) getHeight() * 0.95f);
  355. for (auto* c : buttons)
  356. {
  357. int ny = proportionOfHeight (0.95f) - c->getHeight();
  358. c->setTopLeftPosition (x, ny);
  359. if (ny < y)
  360. y = ny;
  361. x += c->getWidth() + spacer;
  362. c->toFront (false);
  363. }
  364. y = textBottom;
  365. for (auto* c : allComps)
  366. {
  367. h = 22;
  368. const int comboIndex = comboBoxes.indexOf (dynamic_cast<ComboBox*> (c));
  369. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  370. y += labelHeight;
  371. const int tbIndex = textBoxes.indexOf (dynamic_cast<TextEditor*> (c));
  372. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  373. y += labelHeight;
  374. if (customComps.contains (c))
  375. {
  376. if (c->getName().isNotEmpty())
  377. y += labelHeight;
  378. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  379. h = c->getHeight();
  380. }
  381. else if (textBlocks.contains (c))
  382. {
  383. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  384. h = c->getHeight();
  385. }
  386. else
  387. {
  388. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  389. }
  390. y += h + 10;
  391. }
  392. setWantsKeyboardFocus (getNumChildComponents() == 0);
  393. }
  394. bool AlertWindow::containsAnyExtraComponents() const
  395. {
  396. return allComps.size() > 0;
  397. }
  398. //==============================================================================
  399. void AlertWindow::mouseDown (const MouseEvent& e)
  400. {
  401. dragger.startDraggingComponent (this, e);
  402. }
  403. void AlertWindow::mouseDrag (const MouseEvent& e)
  404. {
  405. dragger.dragComponent (this, e, &constrainer);
  406. }
  407. bool AlertWindow::keyPressed (const KeyPress& key)
  408. {
  409. for (auto* b : buttons)
  410. {
  411. if (b->isRegisteredForShortcut (key))
  412. {
  413. b->triggerClick();
  414. return true;
  415. }
  416. }
  417. if (key.isKeyCode (KeyPress::escapeKey) && escapeKeyCancels)
  418. {
  419. exitModalState (0);
  420. return true;
  421. }
  422. if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  423. {
  424. buttons.getUnchecked(0)->triggerClick();
  425. return true;
  426. }
  427. return false;
  428. }
  429. void AlertWindow::lookAndFeelChanged()
  430. {
  431. const int newFlags = getLookAndFeel().getAlertBoxWindowFlags();
  432. setUsingNativeTitleBar ((newFlags & ComponentPeer::windowHasTitleBar) != 0);
  433. setDropShadowEnabled (isOpaque() && (newFlags & ComponentPeer::windowHasDropShadow) != 0);
  434. updateLayout (false);
  435. }
  436. int AlertWindow::getDesktopWindowStyleFlags() const
  437. {
  438. return getLookAndFeel().getAlertBoxWindowFlags();
  439. }
  440. enum class Async { no, yes };
  441. //==============================================================================
  442. class AlertWindowInfo
  443. {
  444. public:
  445. AlertWindowInfo (const MessageBoxOptions& opts,
  446. std::unique_ptr<ModalComponentManager::Callback>&& cb,
  447. Async showAsync)
  448. : options (opts),
  449. callback (std::move (cb)),
  450. async (showAsync)
  451. {
  452. }
  453. int invoke() const
  454. {
  455. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  456. return returnValue;
  457. }
  458. private:
  459. static void* showCallback (void* userData)
  460. {
  461. static_cast<AlertWindowInfo*> (userData)->show();
  462. return nullptr;
  463. }
  464. void show()
  465. {
  466. auto* component = options.getAssociatedComponent();
  467. auto& lf = (component != nullptr ? component->getLookAndFeel()
  468. : LookAndFeel::getDefaultLookAndFeel());
  469. std::unique_ptr<AlertWindow> alertBox (lf.createAlertWindow (options.getTitle(), options.getMessage(),
  470. options.getButtonText (0), options.getButtonText (1), options.getButtonText (2),
  471. options.getIconType(), options.getNumButtons(), component));
  472. jassert (alertBox != nullptr); // you have to return one of these!
  473. alertBox->setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
  474. #if JUCE_MODAL_LOOPS_PERMITTED
  475. if (async == Async::no)
  476. returnValue = alertBox->runModalLoop();
  477. else
  478. #endif
  479. {
  480. ignoreUnused (async);
  481. alertBox->enterModalState (true, callback.release(), true);
  482. alertBox.release();
  483. }
  484. }
  485. MessageBoxOptions options;
  486. std::unique_ptr<ModalComponentManager::Callback> callback;
  487. const Async async;
  488. int returnValue = 0;
  489. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AlertWindowInfo)
  490. };
  491. namespace AlertWindowMappings
  492. {
  493. using MapFn = int (*) (int);
  494. static inline int noMapping (int buttonIndex) { return buttonIndex; }
  495. static inline int messageBox (int) { return 0; }
  496. static inline int okCancel (int buttonIndex) { return buttonIndex == 0 ? 1 : 0; }
  497. static inline int yesNoCancel (int buttonIndex) { return buttonIndex == 2 ? 0 : buttonIndex + 1; }
  498. static std::unique_ptr<ModalComponentManager::Callback> getWrappedCallback (ModalComponentManager::Callback* callbackIn,
  499. MapFn mapFn)
  500. {
  501. jassert (mapFn != nullptr);
  502. if (callbackIn == nullptr)
  503. return nullptr;
  504. auto wrappedCallback = [innerCallback = rawToUniquePtr (callbackIn), mapFn] (int buttonIndex)
  505. {
  506. innerCallback->modalStateFinished (mapFn (buttonIndex));
  507. };
  508. return rawToUniquePtr (ModalCallbackFunction::create (std::move (wrappedCallback)));
  509. }
  510. }
  511. #if JUCE_MODAL_LOOPS_PERMITTED
  512. void AlertWindow::showMessageBox (MessageBoxIconType iconType,
  513. const String& title,
  514. const String& message,
  515. const String& buttonText,
  516. Component* associatedComponent)
  517. {
  518. show (MessageBoxOptions()
  519. .withIconType (iconType)
  520. .withTitle (title)
  521. .withMessage (message)
  522. .withButton (buttonText.isEmpty() ? TRANS("OK") : buttonText)
  523. .withAssociatedComponent (associatedComponent));
  524. }
  525. int AlertWindow::show (const MessageBoxOptions& options)
  526. {
  527. if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
  528. return NativeMessageBox::show (options);
  529. AlertWindowInfo info (options, nullptr, Async::no);
  530. return info.invoke();
  531. }
  532. bool AlertWindow::showNativeDialogBox (const String& title,
  533. const String& bodyText,
  534. bool isOkCancel)
  535. {
  536. if (isOkCancel)
  537. return NativeMessageBox::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  538. NativeMessageBox::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  539. return true;
  540. }
  541. #endif
  542. void AlertWindow::showAsync (const MessageBoxOptions& options, ModalComponentManager::Callback* callback)
  543. {
  544. if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
  545. {
  546. NativeMessageBox::showAsync (options, callback);
  547. }
  548. else
  549. {
  550. AlertWindowInfo info (options, rawToUniquePtr (callback), Async::yes);
  551. info.invoke();
  552. }
  553. }
  554. void AlertWindow::showAsync (const MessageBoxOptions& options, std::function<void (int)> callback)
  555. {
  556. showAsync (options, ModalCallbackFunction::create (callback));
  557. }
  558. void AlertWindow::showMessageBoxAsync (MessageBoxIconType iconType,
  559. const String& title,
  560. const String& message,
  561. const String& buttonText,
  562. Component* associatedComponent,
  563. ModalComponentManager::Callback* callback)
  564. {
  565. showAsync (MessageBoxOptions()
  566. .withIconType (iconType)
  567. .withTitle (title)
  568. .withMessage (message)
  569. .withButton (buttonText.isEmpty() ? TRANS("OK") : buttonText)
  570. .withAssociatedComponent (associatedComponent),
  571. callback);
  572. }
  573. static int showMaybeAsync (const MessageBoxOptions& options,
  574. ModalComponentManager::Callback* callbackIn,
  575. AlertWindowMappings::MapFn mapFn)
  576. {
  577. const auto showAsync = (callbackIn != nullptr ? Async::yes
  578. : Async::no);
  579. auto callback = AlertWindowMappings::getWrappedCallback (callbackIn, mapFn);
  580. if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
  581. {
  582. #if JUCE_MODAL_LOOPS_PERMITTED
  583. if (showAsync == Async::no)
  584. return mapFn (NativeMessageBox::show (options));
  585. #endif
  586. NativeMessageBox::showAsync (options, callback.release());
  587. return false;
  588. }
  589. AlertWindowInfo info (options, std::move (callback), showAsync);
  590. return info.invoke();
  591. }
  592. bool AlertWindow::showOkCancelBox (MessageBoxIconType iconType,
  593. const String& title,
  594. const String& message,
  595. const String& button1Text,
  596. const String& button2Text,
  597. Component* associatedComponent,
  598. ModalComponentManager::Callback* callback)
  599. {
  600. return showMaybeAsync (MessageBoxOptions()
  601. .withIconType (iconType)
  602. .withTitle (title)
  603. .withMessage (message)
  604. .withButton (button1Text.isEmpty() ? TRANS("OK") : button1Text)
  605. .withButton (button2Text.isEmpty() ? TRANS("Cancel") : button2Text)
  606. .withAssociatedComponent (associatedComponent),
  607. callback,
  608. LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows()
  609. ? AlertWindowMappings::okCancel
  610. : AlertWindowMappings::noMapping) == 1;
  611. }
  612. int AlertWindow::showYesNoCancelBox (MessageBoxIconType iconType,
  613. const String& title,
  614. const String& message,
  615. const String& button1Text,
  616. const String& button2Text,
  617. const String& button3Text,
  618. Component* associatedComponent,
  619. ModalComponentManager::Callback* callback)
  620. {
  621. return showMaybeAsync (MessageBoxOptions()
  622. .withIconType (iconType)
  623. .withTitle (title)
  624. .withMessage (message)
  625. .withButton (button1Text.isEmpty() ? TRANS("Yes") : button1Text)
  626. .withButton (button2Text.isEmpty() ? TRANS("No") : button2Text)
  627. .withButton (button3Text.isEmpty() ? TRANS("Cancel") : button3Text)
  628. .withAssociatedComponent (associatedComponent),
  629. callback,
  630. LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows()
  631. ? AlertWindowMappings::yesNoCancel
  632. : AlertWindowMappings::noMapping);
  633. }
  634. //==============================================================================
  635. std::unique_ptr<AccessibilityHandler> AlertWindow::createAccessibilityHandler()
  636. {
  637. return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::dialogWindow);
  638. }
  639. } // namespace juce