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.

826 lines
26KB

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