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.

819 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_";
  22. //==============================================================================
  23. class Toolbar::Spacer : public ToolbarItemComponent
  24. {
  25. public:
  26. Spacer (const int itemId_, const float fixedSize_, const bool drawBar_)
  27. : ToolbarItemComponent (itemId_, String(), false),
  28. fixedSize (fixedSize_),
  29. drawBar (drawBar_)
  30. {
  31. setWantsKeyboardFocus (false);
  32. }
  33. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  34. int& preferredSize, int& minSize, int& maxSize) override
  35. {
  36. if (fixedSize <= 0)
  37. {
  38. preferredSize = toolbarThickness * 2;
  39. minSize = 4;
  40. maxSize = 32768;
  41. }
  42. else
  43. {
  44. maxSize = roundToInt (toolbarThickness * fixedSize);
  45. minSize = drawBar ? maxSize : jmin (4, maxSize);
  46. preferredSize = maxSize;
  47. if (getEditingMode() == editableOnPalette)
  48. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  49. }
  50. return true;
  51. }
  52. void paintButtonArea (Graphics&, int, int, bool, bool) override
  53. {
  54. }
  55. void contentAreaChanged (const Rectangle<int>&) override
  56. {
  57. }
  58. int getResizeOrder() const noexcept
  59. {
  60. return fixedSize <= 0 ? 0 : 1;
  61. }
  62. void paint (Graphics& g) override
  63. {
  64. const int w = getWidth();
  65. const int h = getHeight();
  66. if (drawBar)
  67. {
  68. g.setColour (findColour (Toolbar::separatorColourId, true));
  69. const float thickness = 0.2f;
  70. if (isToolbarVertical())
  71. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  72. else
  73. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  74. }
  75. if (getEditingMode() != normalMode && ! drawBar)
  76. {
  77. g.setColour (findColour (Toolbar::separatorColourId, true));
  78. const int indentX = jmin (2, (w - 3) / 2);
  79. const int indentY = jmin (2, (h - 3) / 2);
  80. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  81. if (fixedSize <= 0)
  82. {
  83. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  84. if (isToolbarVertical())
  85. {
  86. x1 = w * 0.5f;
  87. y1 = h * 0.4f;
  88. x2 = x1;
  89. y2 = indentX * 2.0f;
  90. x3 = x1;
  91. y3 = h * 0.6f;
  92. x4 = x1;
  93. y4 = h - y2;
  94. hw = w * 0.15f;
  95. hl = w * 0.2f;
  96. }
  97. else
  98. {
  99. x1 = w * 0.4f;
  100. y1 = h * 0.5f;
  101. x2 = indentX * 2.0f;
  102. y2 = y1;
  103. x3 = w * 0.6f;
  104. y3 = y1;
  105. x4 = w - x2;
  106. y4 = y1;
  107. hw = h * 0.15f;
  108. hl = h * 0.2f;
  109. }
  110. Path p;
  111. p.addArrow (Line<float> (x1, y1, x2, y2), 1.5f, hw, hl);
  112. p.addArrow (Line<float> (x3, y3, x4, y4), 1.5f, hw, hl);
  113. g.fillPath (p);
  114. }
  115. }
  116. }
  117. private:
  118. const float fixedSize;
  119. const bool drawBar;
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Spacer)
  121. };
  122. //==============================================================================
  123. class Toolbar::MissingItemsComponent : public PopupMenu::CustomComponent
  124. {
  125. public:
  126. MissingItemsComponent (Toolbar& bar, const int h)
  127. : PopupMenu::CustomComponent (true),
  128. owner (&bar),
  129. height (h)
  130. {
  131. for (int i = bar.items.size(); --i >= 0;)
  132. {
  133. ToolbarItemComponent* const tc = bar.items.getUnchecked(i);
  134. if (dynamic_cast<Spacer*> (tc) == nullptr && ! tc->isVisible())
  135. {
  136. oldIndexes.insert (0, i);
  137. addAndMakeVisible (tc, 0);
  138. }
  139. }
  140. layout (400);
  141. }
  142. ~MissingItemsComponent()
  143. {
  144. if (owner != nullptr)
  145. {
  146. for (int i = 0; i < getNumChildComponents(); ++i)
  147. {
  148. if (auto* tc = dynamic_cast<ToolbarItemComponent*> (getChildComponent (i)))
  149. {
  150. tc->setVisible (false);
  151. const int index = oldIndexes.removeAndReturn (i);
  152. owner->addChildComponent (tc, index);
  153. --i;
  154. }
  155. }
  156. owner->resized();
  157. }
  158. }
  159. void layout (const int preferredWidth)
  160. {
  161. const int indent = 8;
  162. int x = indent;
  163. int y = indent;
  164. int maxX = 0;
  165. for (auto* c : getChildren())
  166. {
  167. if (auto* tc = dynamic_cast<ToolbarItemComponent*> (c))
  168. {
  169. int preferredSize = 1, minSize = 1, maxSize = 1;
  170. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  171. {
  172. if (x + preferredSize > preferredWidth && x > indent)
  173. {
  174. x = indent;
  175. y += height;
  176. }
  177. tc->setBounds (x, y, preferredSize, height);
  178. x += preferredSize;
  179. maxX = jmax (maxX, x);
  180. }
  181. }
  182. }
  183. setSize (maxX + 8, y + height + 8);
  184. }
  185. void getIdealSize (int& idealWidth, int& idealHeight) override
  186. {
  187. idealWidth = getWidth();
  188. idealHeight = getHeight();
  189. }
  190. private:
  191. Component::SafePointer<Toolbar> owner;
  192. const int height;
  193. Array<int> oldIndexes;
  194. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MissingItemsComponent)
  195. };
  196. //==============================================================================
  197. Toolbar::Toolbar()
  198. : vertical (false),
  199. isEditingActive (false),
  200. toolbarStyle (Toolbar::iconsOnly)
  201. {
  202. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  203. missingItemsButton->setAlwaysOnTop (true);
  204. missingItemsButton->addListener (this);
  205. }
  206. Toolbar::~Toolbar()
  207. {
  208. items.clear();
  209. }
  210. void Toolbar::setVertical (const bool shouldBeVertical)
  211. {
  212. if (vertical != shouldBeVertical)
  213. {
  214. vertical = shouldBeVertical;
  215. resized();
  216. }
  217. }
  218. void Toolbar::clear()
  219. {
  220. items.clear();
  221. resized();
  222. }
  223. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  224. {
  225. if (itemId == ToolbarItemFactory::separatorBarId) return new Spacer (itemId, 0.1f, true);
  226. if (itemId == ToolbarItemFactory::spacerId) return new Spacer (itemId, 0.5f, false);
  227. if (itemId == ToolbarItemFactory::flexibleSpacerId) return new Spacer (itemId, 0.0f, false);
  228. return factory.createItem (itemId);
  229. }
  230. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  231. const int itemId,
  232. const int insertIndex)
  233. {
  234. // An ID can't be zero - this might indicate a mistake somewhere?
  235. jassert (itemId != 0);
  236. if (ToolbarItemComponent* const tc = createItem (factory, itemId))
  237. {
  238. #if JUCE_DEBUG
  239. Array<int> allowedIds;
  240. factory.getAllToolbarItemIds (allowedIds);
  241. // If your factory can create an item for a given ID, it must also return
  242. // that ID from its getAllToolbarItemIds() method!
  243. jassert (allowedIds.contains (itemId));
  244. #endif
  245. items.insert (insertIndex, tc);
  246. addAndMakeVisible (tc, insertIndex);
  247. }
  248. }
  249. void Toolbar::addItem (ToolbarItemFactory& factory,
  250. const int itemId,
  251. const int insertIndex)
  252. {
  253. addItemInternal (factory, itemId, insertIndex);
  254. resized();
  255. }
  256. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  257. {
  258. Array<int> ids;
  259. factoryToUse.getDefaultItemSet (ids);
  260. clear();
  261. for (int i = 0; i < ids.size(); ++i)
  262. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  263. resized();
  264. }
  265. void Toolbar::removeToolbarItem (const int itemIndex)
  266. {
  267. items.remove (itemIndex);
  268. resized();
  269. }
  270. ToolbarItemComponent* Toolbar::removeAndReturnItem (const int itemIndex)
  271. {
  272. if (ToolbarItemComponent* const tc = items.removeAndReturn (itemIndex))
  273. {
  274. removeChildComponent (tc);
  275. resized();
  276. return tc;
  277. }
  278. return nullptr;
  279. }
  280. int Toolbar::getNumItems() const noexcept
  281. {
  282. return items.size();
  283. }
  284. int Toolbar::getItemId (const int itemIndex) const noexcept
  285. {
  286. if (ToolbarItemComponent* const tc = getItemComponent (itemIndex))
  287. return tc->getItemId();
  288. return 0;
  289. }
  290. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const noexcept
  291. {
  292. return items [itemIndex];
  293. }
  294. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  295. {
  296. for (;;)
  297. {
  298. index += delta;
  299. if (ToolbarItemComponent* const tc = getItemComponent (index))
  300. {
  301. if (tc->isActive)
  302. return tc;
  303. }
  304. else
  305. {
  306. return nullptr;
  307. }
  308. }
  309. }
  310. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  311. {
  312. if (toolbarStyle != newStyle)
  313. {
  314. toolbarStyle = newStyle;
  315. updateAllItemPositions (false);
  316. }
  317. }
  318. String Toolbar::toString() const
  319. {
  320. String s ("TB:");
  321. for (int i = 0; i < getNumItems(); ++i)
  322. s << getItemId(i) << ' ';
  323. return s.trimEnd();
  324. }
  325. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  326. const String& savedVersion)
  327. {
  328. if (! savedVersion.startsWith ("TB:"))
  329. return false;
  330. StringArray tokens;
  331. tokens.addTokens (savedVersion.substring (3), false);
  332. clear();
  333. for (int i = 0; i < tokens.size(); ++i)
  334. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  335. resized();
  336. return true;
  337. }
  338. void Toolbar::paint (Graphics& g)
  339. {
  340. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  341. }
  342. int Toolbar::getThickness() const noexcept
  343. {
  344. return vertical ? getWidth() : getHeight();
  345. }
  346. int Toolbar::getLength() const noexcept
  347. {
  348. return vertical ? getHeight() : getWidth();
  349. }
  350. void Toolbar::setEditingActive (const bool active)
  351. {
  352. if (isEditingActive != active)
  353. {
  354. isEditingActive = active;
  355. updateAllItemPositions (false);
  356. }
  357. }
  358. //==============================================================================
  359. void Toolbar::resized()
  360. {
  361. updateAllItemPositions (false);
  362. }
  363. void Toolbar::updateAllItemPositions (const bool animate)
  364. {
  365. if (getWidth() > 0 && getHeight() > 0)
  366. {
  367. StretchableObjectResizer resizer;
  368. for (int i = 0; i < items.size(); ++i)
  369. {
  370. ToolbarItemComponent* const tc = items.getUnchecked(i);
  371. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  372. : ToolbarItemComponent::normalMode);
  373. tc->setStyle (toolbarStyle);
  374. Spacer* const spacer = dynamic_cast<Spacer*> (tc);
  375. int preferredSize = 1, minSize = 1, maxSize = 1;
  376. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  377. preferredSize, minSize, maxSize))
  378. {
  379. tc->isActive = true;
  380. resizer.addItem (preferredSize, minSize, maxSize,
  381. spacer != nullptr ? spacer->getResizeOrder() : 2);
  382. }
  383. else
  384. {
  385. tc->isActive = false;
  386. tc->setVisible (false);
  387. }
  388. }
  389. resizer.resizeToFit (getLength());
  390. int totalLength = 0;
  391. for (int i = 0; i < resizer.getNumItems(); ++i)
  392. totalLength += (int) resizer.getItemSize (i);
  393. const bool itemsOffTheEnd = totalLength > getLength();
  394. const int extrasButtonSize = getThickness() / 2;
  395. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  396. missingItemsButton->setVisible (itemsOffTheEnd);
  397. missingItemsButton->setEnabled (! isEditingActive);
  398. if (vertical)
  399. missingItemsButton->setCentrePosition (getWidth() / 2,
  400. getHeight() - 4 - extrasButtonSize / 2);
  401. else
  402. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  403. getHeight() / 2);
  404. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  405. : missingItemsButton->getX()) - 4
  406. : getLength();
  407. int pos = 0, activeIndex = 0;
  408. for (int i = 0; i < items.size(); ++i)
  409. {
  410. ToolbarItemComponent* const tc = items.getUnchecked(i);
  411. if (tc->isActive)
  412. {
  413. const int size = (int) resizer.getItemSize (activeIndex++);
  414. Rectangle<int> newBounds;
  415. if (vertical)
  416. newBounds.setBounds (0, pos, getWidth(), size);
  417. else
  418. newBounds.setBounds (pos, 0, size, getHeight());
  419. ComponentAnimator& animator = Desktop::getInstance().getAnimator();
  420. if (animate)
  421. {
  422. animator.animateComponent (tc, newBounds, 1.0f, 200, false, 3.0, 0.0);
  423. }
  424. else
  425. {
  426. animator.cancelAnimation (tc, false);
  427. tc->setBounds (newBounds);
  428. }
  429. pos += size;
  430. tc->setVisible (pos <= maxLength
  431. && ((! tc->isBeingDragged)
  432. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  433. }
  434. }
  435. }
  436. }
  437. //==============================================================================
  438. void Toolbar::buttonClicked (Button*)
  439. {
  440. jassert (missingItemsButton->isShowing());
  441. if (missingItemsButton->isShowing())
  442. {
  443. PopupMenu m;
  444. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  445. m.showMenuAsync (PopupMenu::Options().withTargetComponent (missingItemsButton), nullptr);
  446. }
  447. }
  448. //==============================================================================
  449. bool Toolbar::isInterestedInDragSource (const SourceDetails& dragSourceDetails)
  450. {
  451. return dragSourceDetails.description == toolbarDragDescriptor && isEditingActive;
  452. }
  453. void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails)
  454. {
  455. if (ToolbarItemComponent* const tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get()))
  456. {
  457. if (! items.contains (tc))
  458. {
  459. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  460. {
  461. if (ToolbarItemPalette* const palette = tc->findParentComponentOfClass<ToolbarItemPalette>())
  462. palette->replaceComponent (*tc);
  463. }
  464. else
  465. {
  466. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  467. }
  468. items.add (tc);
  469. addChildComponent (tc);
  470. updateAllItemPositions (true);
  471. }
  472. ComponentAnimator& animator = Desktop::getInstance().getAnimator();
  473. for (int i = getNumItems(); --i >= 0;)
  474. {
  475. const int currentIndex = items.indexOf (tc);
  476. int newIndex = currentIndex;
  477. const int dragObjectLeft = vertical ? (dragSourceDetails.localPosition.getY() - tc->dragOffsetY)
  478. : (dragSourceDetails.localPosition.getX() - tc->dragOffsetX);
  479. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  480. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  481. if (ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1))
  482. {
  483. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  484. if (std::abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX()))
  485. < std::abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight())))
  486. {
  487. newIndex = getIndexOfChildComponent (prev);
  488. }
  489. }
  490. if (ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1))
  491. {
  492. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  493. if (std::abs (dragObjectLeft - (vertical ? current.getY() : current.getX()))
  494. > std::abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight())))
  495. {
  496. newIndex = getIndexOfChildComponent (next) + 1;
  497. }
  498. }
  499. if (newIndex == currentIndex)
  500. break;
  501. items.removeObject (tc, false);
  502. removeChildComponent (tc);
  503. addChildComponent (tc, newIndex);
  504. items.insert (newIndex, tc);
  505. updateAllItemPositions (true);
  506. }
  507. }
  508. }
  509. void Toolbar::itemDragExit (const SourceDetails& dragSourceDetails)
  510. {
  511. if (ToolbarItemComponent* const tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get()))
  512. {
  513. if (isParentOf (tc))
  514. {
  515. items.removeObject (tc, false);
  516. removeChildComponent (tc);
  517. updateAllItemPositions (true);
  518. }
  519. }
  520. }
  521. void Toolbar::itemDropped (const SourceDetails& dragSourceDetails)
  522. {
  523. if (ToolbarItemComponent* const tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get()))
  524. tc->setState (Button::buttonNormal);
  525. }
  526. void Toolbar::mouseDown (const MouseEvent&) {}
  527. //==============================================================================
  528. class Toolbar::CustomisationDialog : public DialogWindow
  529. {
  530. public:
  531. CustomisationDialog (ToolbarItemFactory& factory, Toolbar& bar, int optionFlags)
  532. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  533. toolbar (bar)
  534. {
  535. setContentOwned (new CustomiserPanel (factory, toolbar, optionFlags), true);
  536. setResizable (true, true);
  537. setResizeLimits (400, 300, 1500, 1000);
  538. positionNearBar();
  539. }
  540. ~CustomisationDialog()
  541. {
  542. toolbar.setEditingActive (false);
  543. }
  544. void closeButtonPressed() override
  545. {
  546. setVisible (false);
  547. }
  548. bool canModalEventBeSentToComponent (const Component* comp) override
  549. {
  550. return toolbar.isParentOf (comp)
  551. || dynamic_cast<const ToolbarItemComponent::ItemDragAndDropOverlayComponent*> (comp) != nullptr;
  552. }
  553. void positionNearBar()
  554. {
  555. const Rectangle<int> screenSize (toolbar.getParentMonitorArea());
  556. Point<int> pos (toolbar.getScreenPosition());
  557. const int gap = 8;
  558. if (toolbar.isVertical())
  559. {
  560. if (pos.x > screenSize.getCentreX())
  561. pos.x -= getWidth() - gap;
  562. else
  563. pos.x += toolbar.getWidth() + gap;
  564. }
  565. else
  566. {
  567. pos.x += (toolbar.getWidth() - getWidth()) / 2;
  568. if (pos.y > screenSize.getCentreY())
  569. pos.y -= getHeight() - gap;
  570. else
  571. pos.y += toolbar.getHeight() + gap;
  572. }
  573. setTopLeftPosition (pos);
  574. }
  575. private:
  576. Toolbar& toolbar;
  577. class CustomiserPanel : public Component,
  578. private ComboBox::Listener,
  579. private Button::Listener
  580. {
  581. public:
  582. CustomiserPanel (ToolbarItemFactory& tbf, Toolbar& bar, int optionFlags)
  583. : factory (tbf), toolbar (bar), palette (tbf, bar),
  584. instructions (String(), TRANS ("You can drag the items above and drop them onto a toolbar to add them.")
  585. + "\n\n"
  586. + TRANS ("Items on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")),
  587. defaultButton (TRANS ("Restore to default set of items"))
  588. {
  589. addAndMakeVisible (palette);
  590. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  591. | Toolbar::allowIconsWithTextChoice
  592. | Toolbar::allowTextOnlyChoice)) != 0)
  593. {
  594. addAndMakeVisible (styleBox);
  595. styleBox.setEditableText (false);
  596. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0) styleBox.addItem (TRANS("Show icons only"), 1);
  597. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0) styleBox.addItem (TRANS("Show icons and descriptions"), 2);
  598. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0) styleBox.addItem (TRANS("Show descriptions only"), 3);
  599. int selectedStyle = 0;
  600. switch (bar.getStyle())
  601. {
  602. case Toolbar::iconsOnly: selectedStyle = 1; break;
  603. case Toolbar::iconsWithText: selectedStyle = 2; break;
  604. case Toolbar::textOnly: selectedStyle = 3; break;
  605. }
  606. styleBox.setSelectedId (selectedStyle);
  607. styleBox.addListener (this);
  608. }
  609. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  610. {
  611. addAndMakeVisible (defaultButton);
  612. defaultButton.addListener (this);
  613. }
  614. addAndMakeVisible (instructions);
  615. instructions.setFont (Font (13.0f));
  616. setSize (500, 300);
  617. }
  618. void comboBoxChanged (ComboBox*) override
  619. {
  620. switch (styleBox.getSelectedId())
  621. {
  622. case 1: toolbar.setStyle (Toolbar::iconsOnly); break;
  623. case 2: toolbar.setStyle (Toolbar::iconsWithText); break;
  624. case 3: toolbar.setStyle (Toolbar::textOnly); break;
  625. }
  626. palette.resized(); // to make it update the styles
  627. }
  628. void buttonClicked (Button*) override
  629. {
  630. toolbar.addDefaultItems (factory);
  631. }
  632. void paint (Graphics& g) override
  633. {
  634. Colour background;
  635. if (DialogWindow* const dw = findParentComponentOfClass<DialogWindow>())
  636. background = dw->getBackgroundColour();
  637. g.setColour (background.contrasting().withAlpha (0.3f));
  638. g.fillRect (palette.getX(), palette.getBottom() - 1, palette.getWidth(), 1);
  639. }
  640. void resized() override
  641. {
  642. palette.setBounds (0, 0, getWidth(), getHeight() - 120);
  643. styleBox.setBounds (10, getHeight() - 110, 200, 22);
  644. defaultButton.changeWidthToFitText (22);
  645. defaultButton.setTopLeftPosition (240, getHeight() - 110);
  646. instructions.setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  647. }
  648. private:
  649. ToolbarItemFactory& factory;
  650. Toolbar& toolbar;
  651. ToolbarItemPalette palette;
  652. Label instructions;
  653. ComboBox styleBox;
  654. TextButton defaultButton;
  655. };
  656. };
  657. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  658. {
  659. setEditingActive (true);
  660. (new CustomisationDialog (factory, *this, optionFlags))
  661. ->enterModalState (true, nullptr, true);
  662. }
  663. } // namespace juce