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.

1459 lines
53KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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. #include "../jucedemo_headers.h"
  19. //==============================================================================
  20. class BouncingBallComponent : public Component,
  21. public Timer
  22. {
  23. Colour colour;
  24. float x, y, dx, dy;
  25. public:
  26. BouncingBallComponent()
  27. {
  28. x = Random::getSystemRandom().nextFloat() * 100.0f;
  29. y = Random::getSystemRandom().nextFloat() * 100.0f;
  30. dx = Random::getSystemRandom().nextFloat() * 8.0f - 4.0f;
  31. dy = Random::getSystemRandom().nextFloat() * 8.0f - 4.0f;
  32. colour = Colour (Random::getSystemRandom().nextInt())
  33. .withAlpha (0.5f)
  34. .withBrightness (0.7f);
  35. int size = 10 + Random::getSystemRandom().nextInt (30);
  36. setSize (size, size);
  37. startTimer (60);
  38. }
  39. ~BouncingBallComponent()
  40. {
  41. }
  42. void paint (Graphics& g)
  43. {
  44. g.setColour (colour);
  45. g.fillEllipse (x - getX(), y - getY(), getWidth() - 2.0f, getHeight() - 2.0f);
  46. }
  47. void timerCallback()
  48. {
  49. x += dx;
  50. y += dy;
  51. if (x < 0)
  52. dx = fabsf (dx);
  53. if (x > getParentWidth())
  54. dx = -fabsf (dx);
  55. if (y < 0)
  56. dy = fabsf (dy);
  57. if (y > getParentHeight())
  58. dy = -fabsf (dy);
  59. setTopLeftPosition ((int) x, (int) y);
  60. }
  61. bool hitTest (int x, int y)
  62. {
  63. return false;
  64. }
  65. };
  66. //==============================================================================
  67. class DragOntoDesktopDemoComp : public Component
  68. {
  69. Component* parent;
  70. ComponentDragger dragger;
  71. public:
  72. DragOntoDesktopDemoComp (Component* p)
  73. : parent (p)
  74. {
  75. // show off semi-transparency if it's supported by the current OS.
  76. setOpaque (! Desktop::canUseSemiTransparentWindows());
  77. for (int i = 3; --i >= 0;)
  78. addAndMakeVisible (new BouncingBallComponent());
  79. }
  80. ~DragOntoDesktopDemoComp()
  81. {
  82. deleteAllChildren();
  83. }
  84. void mouseDown (const MouseEvent& e)
  85. {
  86. dragger.startDraggingComponent (this, 0);
  87. }
  88. void mouseDrag (const MouseEvent& e)
  89. {
  90. if (! parent->isValidComponent())
  91. {
  92. delete this;
  93. }
  94. else
  95. {
  96. MouseEvent e2 (e.getEventRelativeTo (parent));
  97. // if the mouse is inside the parent component, we'll make that the
  98. // parent - otherwise, we'll put this comp on the desktop.
  99. if (e2.x >= 0 && e2.y >= 0 && e2.x < parent->getWidth() && e2.y < parent->getHeight())
  100. {
  101. // re-add this component to a parent component, which will
  102. // remove it from the desktop..
  103. parent->addChildComponent (this);
  104. }
  105. else
  106. {
  107. // add the component to the desktop, which will remove it
  108. // from its current parent component..
  109. addToDesktop (ComponentPeer::windowIsTemporary);
  110. }
  111. dragger.dragComponent (this, e);
  112. }
  113. }
  114. void paint (Graphics& g)
  115. {
  116. if (isOpaque())
  117. g.fillAll (Colours::white);
  118. else
  119. g.fillAll (Colours::blue.withAlpha (0.2f));
  120. String desc ("drag this box onto the desktop to show how the same component can move from being lightweight to being a separate window");
  121. g.setFont (15.0f);
  122. g.setColour (Colours::black);
  123. g.drawFittedText (desc, 4, 0, getWidth() - 8, getHeight(), Justification::horizontallyJustified, 5);
  124. g.drawRect (0, 0, getWidth(), getHeight());
  125. }
  126. };
  127. //==============================================================================
  128. class CustomMenuComponent : public PopupMenuCustomComponent,
  129. public Timer
  130. {
  131. int blobX, blobY;
  132. public:
  133. CustomMenuComponent()
  134. : blobX (0),
  135. blobY (0)
  136. {
  137. // set off a timer to move a blob around on this component every
  138. // 300 milliseconds - see the timerCallback() method.
  139. startTimer (300);
  140. }
  141. ~CustomMenuComponent()
  142. {
  143. }
  144. void getIdealSize (int& idealWidth,
  145. int& idealHeight)
  146. {
  147. // tells the menu how big we'd like to be..
  148. idealWidth = 200;
  149. idealHeight = 60;
  150. }
  151. void paint (Graphics& g)
  152. {
  153. g.fillAll (Colours::yellow.withAlpha (0.3f));
  154. g.setColour (Colours::pink);
  155. g.fillEllipse ((float) blobX, (float) blobY, 30.0f, 40.0f);
  156. g.setFont (14.0f, Font::italic);
  157. g.setColour (Colours::black);
  158. g.drawFittedText ("this is a customised menu item (also demonstrating the Timer class)...",
  159. 4, 0, getWidth() - 8, getHeight(),
  160. Justification::centred, 3);
  161. }
  162. void timerCallback()
  163. {
  164. blobX = Random::getSystemRandom().nextInt (getWidth());
  165. blobY = Random::getSystemRandom().nextInt (getHeight());
  166. repaint();
  167. }
  168. };
  169. //==============================================================================
  170. /** To demonstrate how sliders can have custom snapping applied to their values,
  171. this simple class snaps the value to 50 if it comes near.
  172. */
  173. class SnappingSlider : public Slider
  174. {
  175. public:
  176. SnappingSlider (const String& name)
  177. : Slider (name)
  178. {
  179. }
  180. double snapValue (double attemptedValue, bool userIsDragging)
  181. {
  182. if (! userIsDragging)
  183. return attemptedValue; // if they're entering the value in the text-box, don't mess with it.
  184. if (attemptedValue > 40 && attemptedValue < 60)
  185. return 50.0;
  186. else
  187. return attemptedValue;
  188. }
  189. };
  190. /** A TextButton that pops up a colour chooser to change its colours. */
  191. class ColourChangeButton : public TextButton,
  192. public ChangeListener
  193. {
  194. public:
  195. ColourChangeButton()
  196. : TextButton ("click to change colour...")
  197. {
  198. setSize (10, 24);
  199. changeWidthToFitText();
  200. }
  201. ~ColourChangeButton()
  202. {
  203. }
  204. void clicked()
  205. {
  206. // create two colour selector components for our background and
  207. // text colour..
  208. ColourSelector colourSelector1;
  209. colourSelector1.setName ("background");
  210. colourSelector1.setCurrentColour (findColour (TextButton::buttonColourId));
  211. colourSelector1.addChangeListener (this);
  212. ColourSelector colourSelector2;
  213. colourSelector2.setName ("text");
  214. colourSelector2.setCurrentColour (findColour (TextButton::textColourOffId));
  215. colourSelector2.addChangeListener (this);
  216. // and add the selectors as custom menu items to a PopupMenu, putting
  217. // them in two different sub-menus..
  218. PopupMenu m, sub1, sub2;
  219. sub1.addCustomItem (1234, &colourSelector1, 300, 300, false);
  220. m.addSubMenu ("background colour", sub1);
  221. sub2.addCustomItem (1234, &colourSelector2, 300, 300, false);
  222. m.addSubMenu ("text colour", sub2);
  223. // and show the menu (modally)..
  224. m.showAt (this);
  225. }
  226. void changeListenerCallback (void* source)
  227. {
  228. ColourSelector* cs = (ColourSelector*) source;
  229. if (cs->getName() == "text")
  230. setColour (TextButton::textColourOffId, cs->getCurrentColour());
  231. else
  232. setColour (TextButton::buttonColourId, cs->getCurrentColour());
  233. }
  234. };
  235. //==============================================================================
  236. // just a component that deletes all its children, to use for the tabbed pages to avoid
  237. // memory leaks when they're deleted
  238. class DemoPageComp : public Component
  239. {
  240. public:
  241. DemoPageComp()
  242. {
  243. }
  244. ~DemoPageComp()
  245. {
  246. deleteAllChildren();
  247. }
  248. };
  249. //==============================================================================
  250. static Component* createSlidersPage()
  251. {
  252. DemoPageComp* page = new DemoPageComp();
  253. const int numSliders = 11;
  254. Slider* sliders [numSliders];
  255. int i;
  256. for (i = 0; i < numSliders; ++i)
  257. {
  258. if (i == 2)
  259. page->addAndMakeVisible (sliders[i] = new SnappingSlider ("slider"));
  260. else
  261. page->addAndMakeVisible (sliders[i] = new Slider ("slider"));
  262. sliders[i]->setRange (0.0, 100.0, 0.1);
  263. sliders[i]->setPopupMenuEnabled (true);
  264. sliders[i]->setValue (Random::getSystemRandom().nextDouble() * 100.0, false, false);
  265. }
  266. sliders[0]->setSliderStyle (Slider::LinearVertical);
  267. sliders[0]->setTextBoxStyle (Slider::TextBoxBelow, false, 100, 20);
  268. sliders[0]->setBounds (10, 25, 70, 200);
  269. sliders[0]->setDoubleClickReturnValue (true, 50.0); // double-clicking this slider will set it to 50.0
  270. sliders[0]->setTextValueSuffix (" units");
  271. sliders[1]->setSliderStyle (Slider::LinearVertical);
  272. sliders[1]->setVelocityBasedMode (true);
  273. sliders[1]->setSkewFactor (0.5);
  274. sliders[1]->setTextBoxStyle (Slider::TextBoxAbove, true, 100, 20);
  275. sliders[1]->setBounds (85, 25, 70, 200);
  276. sliders[1]->setTextValueSuffix (" rels");
  277. sliders[2]->setSliderStyle (Slider::LinearHorizontal);
  278. sliders[2]->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
  279. sliders[2]->setBounds (180, 35, 150, 20);
  280. sliders[3]->setSliderStyle (Slider::LinearHorizontal);
  281. sliders[3]->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  282. sliders[3]->setBounds (180, 65, 150, 20);
  283. sliders[3]->setPopupDisplayEnabled (true, page);
  284. sliders[3]->setTextValueSuffix (" nuns required to change a lightbulb");
  285. sliders[4]->setSliderStyle (Slider::IncDecButtons);
  286. sliders[4]->setTextBoxStyle (Slider::TextBoxLeft, false, 50, 20);
  287. sliders[4]->setBounds (180, 105, 100, 20);
  288. sliders[4]->setIncDecButtonsMode (Slider::incDecButtonsDraggable_Vertical);
  289. sliders[5]->setSliderStyle (Slider::Rotary);
  290. sliders[5]->setRotaryParameters (float_Pi * 1.2f, float_Pi * 2.8f, false);
  291. sliders[5]->setTextBoxStyle (Slider::TextBoxRight, false, 70, 20);
  292. sliders[5]->setBounds (190, 145, 120, 40);
  293. sliders[5]->setTextValueSuffix (" mm");
  294. sliders[6]->setSliderStyle (Slider::LinearBar);
  295. sliders[6]->setBounds (180, 195, 100, 30);
  296. sliders[6]->setTextValueSuffix (" gallons");
  297. sliders[7]->setSliderStyle (Slider::TwoValueHorizontal);
  298. sliders[7]->setBounds (360, 20, 160, 40);
  299. sliders[8]->setSliderStyle (Slider::TwoValueVertical);
  300. sliders[8]->setBounds (360, 110, 40, 160);
  301. sliders[9]->setSliderStyle (Slider::ThreeValueHorizontal);
  302. sliders[9]->setBounds (360, 70, 160, 40);
  303. sliders[10]->setSliderStyle (Slider::ThreeValueVertical);
  304. sliders[10]->setBounds (440, 110, 40, 160);
  305. for (i = 7; i <= 10; ++i)
  306. {
  307. sliders[i]->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  308. sliders[i]->setPopupDisplayEnabled (true, page);
  309. }
  310. /* Here, we'll create a Value object, and tell a bunch of our sliders to use it as their
  311. value source. By telling them all to share the same Value, they'll stay in sync with
  312. each other.
  313. We could also optionally keep a copy of this Value elsewhere, and by changing it,
  314. cause all the sliders to automatically update.
  315. */
  316. Value sharedValue;
  317. sharedValue = Random::getSystemRandom().nextDouble() * 100;
  318. for (i = 0; i < 7; ++i)
  319. sliders[i]->getValueObject().referTo (sharedValue);
  320. // ..and now we'll do the same for all our min/max slider values..
  321. Value sharedValueMin, sharedValueMax;
  322. sharedValueMin = Random::getSystemRandom().nextDouble() * 40.0;
  323. sharedValueMax = Random::getSystemRandom().nextDouble() * 40.0 + 60.0;
  324. for (i = 7; i <= 10; ++i)
  325. {
  326. sliders[i]->getMaxValueObject().referTo (sharedValueMax);
  327. sliders[i]->getMinValueObject().referTo (sharedValueMin);
  328. }
  329. // Create a description label...
  330. Label* label = new Label ("hint", "Try right-clicking on a slider for an options menu. \n\nAlso, holding down CTRL while dragging will turn on a slider's velocity-sensitive mode");
  331. label->setBounds (20, 245, 350, 150);
  332. page->addAndMakeVisible (label);
  333. return page;
  334. }
  335. //==============================================================================
  336. static Component* createRadioButtonPage()
  337. {
  338. DemoPageComp* page = new DemoPageComp();
  339. GroupComponent* group = new GroupComponent ("group", "radio buttons");
  340. group->setBounds (20, 20, 220, 140);
  341. page->addAndMakeVisible (group);
  342. int i;
  343. for (i = 0; i < 4; ++i)
  344. {
  345. ToggleButton* tb = new ToggleButton ("radio button #" + String (i + 1));
  346. page->addAndMakeVisible (tb);
  347. tb->setRadioGroupId (1234);
  348. tb->setBounds (45, 46 + i * 22, 180, 22);
  349. tb->setTooltip ("a set of mutually-exclusive radio buttons");
  350. if (i == 0)
  351. tb->setToggleState (true, false);
  352. }
  353. for (i = 0; i < 4; ++i)
  354. {
  355. DrawablePath normal, over;
  356. Path p;
  357. p.addStar (0.0f, 0.0f, i + 5, 20.0f, 50.0f, -0.2f);
  358. normal.setPath (p);
  359. normal.setFill (Colours::lightblue);
  360. normal.setStrokeFill (Colours::black);
  361. normal.setStrokeThickness (4.0f);
  362. over.setPath (p);
  363. over.setFill (Colours::blue);
  364. over.setStrokeFill (Colours::black);
  365. over.setStrokeThickness (4.0f);
  366. DrawableButton* db = new DrawableButton (String (i + 5) + " points", DrawableButton::ImageAboveTextLabel);
  367. db->setImages (&normal, &over, 0);
  368. page->addAndMakeVisible (db);
  369. db->setClickingTogglesState (true);
  370. db->setRadioGroupId (23456);
  371. const int buttonSize = 50;
  372. db->setBounds (25 + i * buttonSize, 180, buttonSize, buttonSize);
  373. if (i == 0)
  374. db->setToggleState (true, false);
  375. }
  376. for (i = 0; i < 4; ++i)
  377. {
  378. TextButton* tb = new TextButton ("button " + String (i + 1));
  379. page->addAndMakeVisible (tb);
  380. tb->setClickingTogglesState (true);
  381. tb->setRadioGroupId (34567);
  382. tb->setColour (TextButton::buttonColourId, Colours::white);
  383. tb->setColour (TextButton::buttonOnColourId, Colours::blueviolet.brighter());
  384. tb->setBounds (20 + i * 55, 260, 55, 24);
  385. tb->setConnectedEdges (((i != 0) ? Button::ConnectedOnLeft : 0)
  386. | ((i != 3) ? Button::ConnectedOnRight : 0));
  387. if (i == 0)
  388. tb->setToggleState (true, false);
  389. }
  390. return page;
  391. }
  392. //==============================================================================
  393. class ButtonsPage : public Component,
  394. public ButtonListener
  395. {
  396. public:
  397. ButtonsPage (ButtonListener* buttonListener)
  398. {
  399. //==============================================================================
  400. // create some drawables to use for our drawable buttons...
  401. DrawablePath normal, over;
  402. Path p;
  403. p.addStar (0.0f, 0.0f, 5, 20.0f, 50.0f, 0.2f);
  404. normal.setPath (p);
  405. normal.setFill (Colours::red);
  406. p.clear();
  407. p.addStar (0.0f, 0.0f, 7, 30.0f, 50.0f, 0.0f);
  408. over.setPath (p);
  409. over.setFill (Colours::pink);
  410. over.setStrokeFill (Colours::black);
  411. over.setStrokeThickness (5.0f);
  412. DrawableImage down;
  413. down.setImage (ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize), true);
  414. down.setOverlayColour (Colours::black.withAlpha (0.3f));
  415. //==============================================================================
  416. // create an image-above-text button from these drawables..
  417. DrawableButton* db = new DrawableButton ("Button 1", DrawableButton::ImageAboveTextLabel);
  418. db->setImages (&normal, &over, &down);
  419. addAndMakeVisible (db);
  420. db->setBounds (10, 30, 80, 80);
  421. db->setTooltip ("this is a DrawableButton with a label");
  422. //==============================================================================
  423. // create an image-only button from these drawables..
  424. db = new DrawableButton (T("Button 2"), DrawableButton::ImageFitted);
  425. db->setImages (&normal, &over, &down);
  426. db->setClickingTogglesState (true);
  427. addAndMakeVisible (db);
  428. db->setBounds (90, 30, 80, 80);
  429. db->setTooltip ("this is an image-only DrawableButton");
  430. db->addButtonListener (buttonListener);
  431. //==============================================================================
  432. // create an image-on-button-shape button from the same drawables..
  433. db = new DrawableButton (T("Button 3"), DrawableButton::ImageOnButtonBackground);
  434. db->setImages (&normal, 0, 0);
  435. addAndMakeVisible (db);
  436. db->setBounds (200, 30, 110, 25);
  437. db->setTooltip ("this is a DrawableButton on a standard button background");
  438. //==============================================================================
  439. db = new DrawableButton (T("Button 4"), DrawableButton::ImageOnButtonBackground);
  440. db->setImages (&normal, &over, &down);
  441. db->setClickingTogglesState (true);
  442. db->setBackgroundColours (Colours::white, Colours::yellow);
  443. addAndMakeVisible (db);
  444. db->setBounds (200, 70, 50, 50);
  445. db->setTooltip ("this is a DrawableButton on a standard button background");
  446. db->addButtonListener (buttonListener);
  447. //==============================================================================
  448. HyperlinkButton* hyperlink
  449. = new HyperlinkButton ("this is a HyperlinkButton",
  450. URL ("http://www.rawmaterialsoftware.com/juce"));
  451. hyperlink->setBounds (10, 130, 200, 24);
  452. addAndMakeVisible (hyperlink);
  453. //==============================================================================
  454. ImageButton* imageButton = new ImageButton ("imagebutton");
  455. addAndMakeVisible (imageButton);
  456. Image* juceImage = ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize);
  457. ImageCache::incReferenceCount (juceImage);
  458. ImageCache::incReferenceCount (juceImage);
  459. imageButton->setImages (true, true, true,
  460. juceImage, 0.7f, Colours::transparentBlack,
  461. juceImage, 1.0f, Colours::transparentBlack,
  462. juceImage, 1.0f, Colours::pink.withAlpha (0.8f),
  463. 0.5f);
  464. imageButton->setTopLeftPosition (10, 160);
  465. imageButton->setTooltip ("image button - showing alpha-channel hit-testing and colour overlay when clicked");
  466. //==============================================================================
  467. ColourChangeButton* colourChangeButton = new ColourChangeButton();
  468. addAndMakeVisible (colourChangeButton);
  469. colourChangeButton->setTopLeftPosition (350, 30);
  470. //==============================================================================
  471. animateButton = new TextButton ("click to animate...");
  472. addAndMakeVisible (animateButton);
  473. animateButton->changeWidthToFitText (24);
  474. animateButton->setTopLeftPosition (350, 70);
  475. animateButton->addButtonListener (this);
  476. }
  477. ~ButtonsPage()
  478. {
  479. deleteAllChildren();
  480. }
  481. void buttonClicked (Button*)
  482. {
  483. for (int i = getNumChildComponents(); --i >= 0;)
  484. {
  485. if (getChildComponent (i) != animateButton)
  486. {
  487. animator.animateComponent (getChildComponent (i),
  488. Rectangle<int> (Random::getSystemRandom().nextInt (getWidth() / 2),
  489. Random::getSystemRandom().nextInt (getHeight() / 2),
  490. 60 + Random::getSystemRandom().nextInt (getWidth() / 3),
  491. 16 + Random::getSystemRandom().nextInt (getHeight() / 6)),
  492. 500 + Random::getSystemRandom().nextInt (2000),
  493. Random::getSystemRandom().nextDouble(),
  494. Random::getSystemRandom().nextDouble());
  495. }
  496. }
  497. }
  498. private:
  499. TextButton* animateButton;
  500. ComponentAnimator animator;
  501. };
  502. //==============================================================================
  503. static Component* createMiscPage()
  504. {
  505. DemoPageComp* page = new DemoPageComp();
  506. TextEditor* textEditor1 = new TextEditor();
  507. page->addAndMakeVisible (textEditor1);
  508. textEditor1->setBounds (10, 25, 200, 24);
  509. textEditor1->setText ("single-line text box");
  510. TextEditor* textEditor2 = new TextEditor ("password", (tchar) 0x2022);
  511. page->addAndMakeVisible (textEditor2);
  512. textEditor2->setBounds (10, 55, 200, 24);
  513. textEditor2->setText ("password");
  514. //==============================================================================
  515. ComboBox* comboBox = new ComboBox ("combo");
  516. page->addAndMakeVisible (comboBox);
  517. comboBox->setBounds (300, 25, 200, 24);
  518. comboBox->setEditableText (true);
  519. comboBox->setJustificationType (Justification::centred);
  520. int i;
  521. for (i = 1; i < 100; ++i)
  522. comboBox->addItem ("combo box item " + String (i), i);
  523. comboBox->setSelectedId (1);
  524. DragOntoDesktopDemoComp* d = new DragOntoDesktopDemoComp (page);
  525. page->addAndMakeVisible (d);
  526. d->setBounds (20, 100, 200, 80);
  527. return page;
  528. }
  529. //==============================================================================
  530. class ToolbarDemoComp : public Component,
  531. public SliderListener,
  532. public ButtonListener
  533. {
  534. public:
  535. ToolbarDemoComp (ApplicationCommandManager* commandManager)
  536. {
  537. // Create and add the toolbar...
  538. addAndMakeVisible (toolbar = new Toolbar());
  539. // And use our item factory to add a set of default icons to it...
  540. toolbar->addDefaultItems (factory);
  541. // Now we'll just create the other sliders and buttons on the demo page, which adjust
  542. // the toolbar's properties...
  543. Label* info = new Label (String::empty,
  544. "As well as showing off toolbars, this demo illustrates how to store "
  545. "a set of SVG files in a Zip file, embed that in your application, and read "
  546. "them back in at runtime.\n\nThe icon images here are taken from the open-source "
  547. "Tango icon project.");
  548. addAndMakeVisible (info);
  549. info->setJustificationType (Justification::topLeft);
  550. info->setBounds (80, 80, 450, 100);
  551. info->setInterceptsMouseClicks (false, false);
  552. addAndMakeVisible (depthSlider = new Slider ("toolbar depth:"));
  553. depthSlider->setRange (10.0, 200.0, 1.0);
  554. depthSlider->setValue (50, false);
  555. depthSlider->setSliderStyle (Slider::LinearHorizontal);
  556. depthSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
  557. depthSlider->addListener (this);
  558. depthSlider->setBounds (80, 210, 300, 22);
  559. (new Label (depthSlider->getName(), depthSlider->getName()))->attachToComponent (depthSlider, false);
  560. addAndMakeVisible (orientationButton = new TextButton ("vertical/horizontal"));
  561. orientationButton->addButtonListener (this);
  562. orientationButton->changeWidthToFitText (22);
  563. orientationButton->setTopLeftPosition (depthSlider->getX(), depthSlider->getBottom() + 20);
  564. addAndMakeVisible (customiseButton = new TextButton ("customise..."));
  565. customiseButton->addButtonListener (this);
  566. customiseButton->changeWidthToFitText (22);
  567. customiseButton->setTopLeftPosition (orientationButton->getRight() + 20, orientationButton->getY());
  568. }
  569. ~ToolbarDemoComp()
  570. {
  571. deleteAllChildren();
  572. }
  573. void resized()
  574. {
  575. if (toolbar->isVertical())
  576. toolbar->setBounds (0, 0, (int) depthSlider->getValue(), getHeight());
  577. else
  578. toolbar->setBounds (0, 0, getWidth(), (int) depthSlider->getValue());
  579. }
  580. void sliderValueChanged (Slider* slider)
  581. {
  582. resized();
  583. }
  584. void buttonClicked (Button* button)
  585. {
  586. if (button == orientationButton)
  587. {
  588. toolbar->setVertical (! toolbar->isVertical());
  589. resized();
  590. }
  591. else if (button == customiseButton)
  592. {
  593. toolbar->showCustomisationDialog (factory);
  594. }
  595. }
  596. private:
  597. Toolbar* toolbar;
  598. Slider* depthSlider;
  599. TextButton* orientationButton;
  600. TextButton* customiseButton;
  601. //==============================================================================
  602. class DemoToolbarItemFactory : public ToolbarItemFactory
  603. {
  604. public:
  605. DemoToolbarItemFactory() {}
  606. ~DemoToolbarItemFactory() {}
  607. //==============================================================================
  608. // Each type of item a toolbar can contain must be given a unique ID. These
  609. // are the ones we'll use in this demo.
  610. enum DemoToolbarItemIds
  611. {
  612. doc_new = 1,
  613. doc_open = 2,
  614. doc_save = 3,
  615. doc_saveAs = 4,
  616. edit_copy = 5,
  617. edit_cut = 6,
  618. edit_paste = 7,
  619. juceLogoButton = 8,
  620. customComboBox = 9
  621. };
  622. void getAllToolbarItemIds (Array <int>& ids)
  623. {
  624. // This returns the complete list of all item IDs that are allowed to
  625. // go in our toolbar. Any items you might want to add must be listed here. The
  626. // order in which they are listed will be used by the toolbar customisation panel.
  627. ids.add (doc_new);
  628. ids.add (doc_open);
  629. ids.add (doc_save);
  630. ids.add (doc_saveAs);
  631. ids.add (edit_copy);
  632. ids.add (edit_cut);
  633. ids.add (edit_paste);
  634. ids.add (juceLogoButton);
  635. ids.add (customComboBox);
  636. // If you're going to use separators, then they must also be added explicitly
  637. // to the list.
  638. ids.add (separatorBarId);
  639. ids.add (spacerId);
  640. ids.add (flexibleSpacerId);
  641. }
  642. void getDefaultItemSet (Array <int>& ids)
  643. {
  644. // This returns an ordered list of the set of items that make up a
  645. // toolbar's default set. Not all items need to be on this list, and
  646. // items can appear multiple times (e.g. the separators used here).
  647. ids.add (doc_new);
  648. ids.add (doc_open);
  649. ids.add (doc_save);
  650. ids.add (doc_saveAs);
  651. ids.add (spacerId);
  652. ids.add (separatorBarId);
  653. ids.add (edit_copy);
  654. ids.add (edit_cut);
  655. ids.add (edit_paste);
  656. ids.add (separatorBarId);
  657. ids.add (flexibleSpacerId);
  658. ids.add (customComboBox);
  659. ids.add (flexibleSpacerId);
  660. ids.add (separatorBarId);
  661. ids.add (juceLogoButton);
  662. }
  663. ToolbarItemComponent* createItem (int itemId)
  664. {
  665. switch (itemId)
  666. {
  667. case doc_new:
  668. return createButtonFromZipFileSVG (itemId, "new", "document-new.svg");
  669. case doc_open:
  670. return createButtonFromZipFileSVG (itemId, "open", "document-open.svg");
  671. case doc_save:
  672. return createButtonFromZipFileSVG (itemId, "save", "document-save.svg");
  673. case doc_saveAs:
  674. return createButtonFromZipFileSVG (itemId, "save as", "document-save-as.svg");
  675. case edit_copy:
  676. return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg");
  677. case edit_cut:
  678. return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg");
  679. case edit_paste:
  680. return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg");
  681. case juceLogoButton:
  682. return new ToolbarButton (itemId, "juce!", Drawable::createFromImageData (BinaryData::juce_png, BinaryData::juce_pngSize), 0);
  683. case customComboBox:
  684. return new CustomToolbarComboBox (itemId);
  685. default:
  686. break;
  687. }
  688. return 0;
  689. }
  690. private:
  691. StringArray iconNames;
  692. OwnedArray <Drawable> iconsFromZipFile;
  693. // This is a little utility to create a button with one of the SVG images in
  694. // our embedded ZIP file "icons.zip"
  695. ToolbarButton* createButtonFromZipFileSVG (const int itemId, const String& text, const String& filename)
  696. {
  697. if (iconsFromZipFile.size() == 0)
  698. {
  699. // If we've not already done so, load all the images from the zip file..
  700. MemoryInputStream iconsFileStream (BinaryData::icons_zip, BinaryData::icons_zipSize, false);
  701. ZipFile icons (&iconsFileStream, false);
  702. for (int i = 0; i < icons.getNumEntries(); ++i)
  703. {
  704. InputStream* svgFileStream = icons.createStreamForEntry (i);
  705. if (svgFileStream != 0)
  706. {
  707. iconNames.add (icons.getEntry(i)->filename);
  708. iconsFromZipFile.add (Drawable::createFromImageDataStream (*svgFileStream));
  709. delete svgFileStream;
  710. }
  711. }
  712. }
  713. Drawable* image = iconsFromZipFile [iconNames.indexOf (filename)]->createCopy();
  714. return new ToolbarButton (itemId, text, image, 0);
  715. return 0;
  716. }
  717. // Demonstrates how to put a custom component into a toolbar - this one contains
  718. // a ComboBox.
  719. class CustomToolbarComboBox : public ToolbarItemComponent
  720. {
  721. public:
  722. CustomToolbarComboBox (const int toolbarItemId)
  723. : ToolbarItemComponent (toolbarItemId, "Custom Toolbar Item", false)
  724. {
  725. addAndMakeVisible (comboBox = new ComboBox ("demo toolbar combo box"));
  726. for (int i = 1; i < 20; ++i)
  727. comboBox->addItem ("Toolbar ComboBox item " + String (i), i);
  728. comboBox->setSelectedId (1);
  729. comboBox->setEditableText (true);
  730. }
  731. ~CustomToolbarComboBox()
  732. {
  733. delete comboBox;
  734. }
  735. bool getToolbarItemSizes (int toolbarDepth,
  736. bool isToolbarVertical,
  737. int& preferredSize, int& minSize, int& maxSize)
  738. {
  739. if (isToolbarVertical)
  740. return false;
  741. preferredSize = 250;
  742. minSize = 80;
  743. maxSize = 300;
  744. return true;
  745. }
  746. void paintButtonArea (Graphics&, int, int, bool, bool)
  747. {
  748. }
  749. void contentAreaChanged (const Rectangle<int>& contentArea)
  750. {
  751. comboBox->setSize (contentArea.getWidth() - 2,
  752. jmin (contentArea.getHeight() - 2, 22));
  753. comboBox->setCentrePosition (contentArea.getCentreX(), contentArea.getCentreY());
  754. }
  755. private:
  756. ComboBox* comboBox;
  757. };
  758. };
  759. DemoToolbarItemFactory factory;
  760. };
  761. //==============================================================================
  762. class DemoTabbedComponent : public TabbedComponent,
  763. public ButtonListener
  764. {
  765. public:
  766. DemoTabbedComponent (ApplicationCommandManager* commandManager)
  767. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  768. {
  769. addTab ("sliders", getRandomBrightColour(), createSlidersPage(), true);
  770. addTab ("toolbars", getRandomBrightColour(), new ToolbarDemoComp (commandManager), true);
  771. addTab ("buttons", getRandomBrightColour(), new ButtonsPage (this), true);
  772. addTab ("radio buttons", getRandomBrightColour(), createRadioButtonPage(), true);
  773. addTab ("misc widgets", getRandomBrightColour(), createMiscPage(), true);
  774. }
  775. ~DemoTabbedComponent()
  776. {
  777. }
  778. void buttonClicked (Button* button)
  779. {
  780. BubbleMessageComponent* bmc = new BubbleMessageComponent();
  781. if (Desktop::canUseSemiTransparentWindows())
  782. {
  783. bmc->setAlwaysOnTop (true);
  784. bmc->addToDesktop (0);
  785. }
  786. else
  787. {
  788. addChildComponent (bmc);
  789. }
  790. bmc->showAt (button, "This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing at a component or somewhere on the screen.\n\nThe message bubbles will disappear after a timeout period, or when the mouse is clicked.",
  791. 2000, true, true);
  792. }
  793. static const Colour getRandomBrightColour()
  794. {
  795. return Colour (Random::getSystemRandom().nextFloat(), 0.1f, 0.97f, 1.0f);
  796. }
  797. };
  798. //==============================================================================
  799. class DemoBackgroundThread : public ThreadWithProgressWindow
  800. {
  801. public:
  802. DemoBackgroundThread()
  803. : ThreadWithProgressWindow ("busy doing some important things...",
  804. true,
  805. true)
  806. {
  807. setStatusMessage ("Getting ready...");
  808. }
  809. ~DemoBackgroundThread()
  810. {
  811. }
  812. void run()
  813. {
  814. setProgress (-1.0); // setting a value beyond the range 0 -> 1 will show a spinning bar..
  815. setStatusMessage ("Preparing to do some stuff...");
  816. wait (2000);
  817. const int thingsToDo = 10;
  818. for (int i = 0; i < thingsToDo; ++i)
  819. {
  820. // must check this as often as possible, because this is
  821. // how we know if the user's pressed 'cancel'
  822. if (threadShouldExit())
  823. return;
  824. // this will update the progress bar on the dialog box
  825. setProgress (i / (double) thingsToDo);
  826. setStatusMessage (String (thingsToDo - i) + " things left to do...");
  827. wait (500);
  828. }
  829. setProgress (-1.0); // setting a value beyond the range 0 -> 1 will show a spinning bar..
  830. setStatusMessage ("Finishing off the last few bits and pieces!");
  831. wait (2000);
  832. }
  833. };
  834. //==============================================================================
  835. /** A DialogWindow containing a ColourSelector component */
  836. class ColourSelectorDialogWindow : public DialogWindow
  837. {
  838. public:
  839. ColourSelectorDialogWindow()
  840. : DialogWindow ("Colour selector demo",
  841. Colours::lightgrey,
  842. true)
  843. {
  844. setContentComponent (new ColourSelector());
  845. centreWithSize (400, 400);
  846. setResizable (true, true);
  847. }
  848. ~ColourSelectorDialogWindow()
  849. {
  850. }
  851. void closeButtonPressed()
  852. {
  853. // we expect this component to be run within a modal loop, so when the close
  854. // button is clicked, we can make it invisible to cause the loop to exit and the
  855. // calling code will delete this object.
  856. setVisible (false);
  857. }
  858. };
  859. #if JUCE_MAC
  860. //==============================================================================
  861. /** This pops open a dialog box and waits for you to press keys on your Apple Remote,
  862. which it describes in the box.
  863. */
  864. class AppleRemoteTestWindow : public AlertWindow,
  865. public AppleRemoteDevice
  866. {
  867. public:
  868. AppleRemoteTestWindow()
  869. : AlertWindow ("Apple Remote Control Test!",
  870. "If you've got an Apple Remote, press some buttons now...",
  871. AlertWindow::NoIcon)
  872. {
  873. addButton ("done", 0);
  874. // (To open the device in non-exclusive mode, pass 'false' in here)..
  875. if (! start (true))
  876. setMessage ("Couldn't open the remote control device!");
  877. }
  878. ~AppleRemoteTestWindow()
  879. {
  880. stop();
  881. }
  882. void buttonPressed (const ButtonType buttonId, const bool isDown)
  883. {
  884. String desc;
  885. switch (buttonId)
  886. {
  887. case menuButton:
  888. desc = "menu button (short)";
  889. break;
  890. case playButton:
  891. desc = "play button";
  892. break;
  893. case plusButton:
  894. desc = "plus button";
  895. break;
  896. case minusButton:
  897. desc = "minus button";
  898. break;
  899. case rightButton:
  900. desc = "right button (short)";
  901. break;
  902. case leftButton:
  903. desc = "left button (short)";
  904. break;
  905. case rightButton_Long:
  906. desc = "right button (long)";
  907. break;
  908. case leftButton_Long:
  909. desc = "left button (long)";
  910. break;
  911. case menuButton_Long:
  912. desc = "menu button (long)";
  913. break;
  914. case playButtonSleepMode:
  915. desc = "play (sleep mode)";
  916. break;
  917. case switched:
  918. desc = "remote switched";
  919. break;
  920. }
  921. if (isDown)
  922. desc << " -- [down]";
  923. else
  924. desc << " -- [up]";
  925. setMessage (desc);
  926. }
  927. };
  928. #endif
  929. //==============================================================================
  930. const int numGroups = 4;
  931. class WidgetsDemo : public Component,
  932. public ButtonListener
  933. {
  934. TextButton* menuButton;
  935. ToggleButton* enableButton;
  936. DemoTabbedComponent* tabs;
  937. public:
  938. //==============================================================================
  939. WidgetsDemo (ApplicationCommandManager* commandManager)
  940. {
  941. setName ("Widgets");
  942. addAndMakeVisible (tabs = new DemoTabbedComponent (commandManager));
  943. //==============================================================================
  944. menuButton = new TextButton ("click for a popup menu..",
  945. "click for a demo of the different types of item you can put into a popup menu...");
  946. addAndMakeVisible (menuButton);
  947. menuButton->setBounds (10, 10, 200, 24);
  948. menuButton->addButtonListener (this);
  949. menuButton->setTriggeredOnMouseDown (true); // because this button pops up a menu, this lets us
  950. // hold down the button and drag straight onto the menu
  951. //==============================================================================
  952. enableButton = new ToggleButton ("enable/disable components");
  953. addAndMakeVisible (enableButton);
  954. enableButton->setBounds (230, 10, 180, 24);
  955. enableButton->setTooltip (T("toggle button"));
  956. enableButton->setToggleState (true, false);
  957. enableButton->addButtonListener (this);
  958. }
  959. ~WidgetsDemo()
  960. {
  961. deleteAllChildren();
  962. }
  963. void resized()
  964. {
  965. tabs->setBounds (10, 40, getWidth() - 20, getHeight() - 50);
  966. }
  967. //==============================================================================
  968. void buttonClicked (Button* button)
  969. {
  970. if (button == enableButton)
  971. {
  972. const bool enabled = enableButton->getToggleState();
  973. menuButton->setEnabled (enabled);
  974. tabs->setEnabled (enabled);
  975. }
  976. else if (button == menuButton)
  977. {
  978. PopupMenu m;
  979. m.addItem (1, "Normal item");
  980. m.addItem (2, "Disabled item", false);
  981. m.addItem (3, "Ticked item", true, true);
  982. m.addColouredItem (4, "Coloured item", Colours::green);
  983. m.addSeparator();
  984. m.addCustomItem (5, new CustomMenuComponent());
  985. m.addSeparator();
  986. PopupMenu tabsMenu;
  987. tabsMenu.addItem (1001, "Show tabs at the top", true, tabs->getOrientation() == TabbedButtonBar::TabsAtTop);
  988. tabsMenu.addItem (1002, "Show tabs at the bottom", true, tabs->getOrientation() == TabbedButtonBar::TabsAtBottom);
  989. tabsMenu.addItem (1003, "Show tabs at the left", true, tabs->getOrientation() == TabbedButtonBar::TabsAtLeft);
  990. tabsMenu.addItem (1004, "Show tabs at the right", true, tabs->getOrientation() == TabbedButtonBar::TabsAtRight);
  991. m.addSubMenu ("Tab position", tabsMenu);
  992. m.addSeparator();
  993. PopupMenu dialogMenu;
  994. dialogMenu.addItem (100, "Show a plain alert-window...");
  995. dialogMenu.addItem (101, "Show an alert-window with a 'warning' icon...");
  996. dialogMenu.addItem (102, "Show an alert-window with an 'info' icon...");
  997. dialogMenu.addItem (103, "Show an alert-window with a 'question' icon...");
  998. dialogMenu.addSeparator();
  999. dialogMenu.addItem (110, "Show an ok/cancel alert-window...");
  1000. dialogMenu.addSeparator();
  1001. dialogMenu.addItem (111, "Show an alert-window with some extra components...");
  1002. dialogMenu.addSeparator();
  1003. dialogMenu.addItem (112, "Show a ThreadWithProgressWindow demo...");
  1004. m.addSubMenu ("AlertWindow demonstrations", dialogMenu);
  1005. m.addSeparator();
  1006. m.addItem (120, "Show a colour selector demo...");
  1007. m.addSeparator();
  1008. #if JUCE_MAC
  1009. m.addItem (140, "Run the Apple Remote Control test...");
  1010. m.addSeparator();
  1011. #endif
  1012. PopupMenu nativeFileChoosers;
  1013. nativeFileChoosers.addItem (121, "'Load' file browser...");
  1014. nativeFileChoosers.addItem (124, "'Load' file browser with an image file preview...");
  1015. nativeFileChoosers.addItem (122, "'Save' file browser...");
  1016. nativeFileChoosers.addItem (123, "'Choose directory' file browser...");
  1017. PopupMenu juceFileChoosers;
  1018. juceFileChoosers.addItem (131, "'Load' file browser...");
  1019. juceFileChoosers.addItem (134, "'Load' file browser with an image file preview...");
  1020. juceFileChoosers.addItem (132, "'Save' file browser...");
  1021. juceFileChoosers.addItem (133, "'Choose directory' file browser...");
  1022. PopupMenu fileChoosers;
  1023. fileChoosers.addSubMenu ("Operating system dialogs", nativeFileChoosers);
  1024. fileChoosers.addSubMenu ("Juce dialogs", juceFileChoosers);
  1025. m.addSubMenu ("File chooser dialogs", fileChoosers);
  1026. int result = m.showAt (menuButton);
  1027. if (result != 0)
  1028. {
  1029. // user chose something from the menu..
  1030. if (result >= 100 && result < 105)
  1031. {
  1032. AlertWindow::AlertIconType icon = AlertWindow::NoIcon;
  1033. if (result == 101)
  1034. icon = AlertWindow::WarningIcon;
  1035. else if (result == 102)
  1036. icon = AlertWindow::InfoIcon;
  1037. else if (result == 103)
  1038. icon = AlertWindow::QuestionIcon;
  1039. AlertWindow::showMessageBox (icon,
  1040. "This is an AlertWindow",
  1041. "And this is the AlertWindow's message. Blah blah blah blah blah blah blah blah blah blah blah blah blah.",
  1042. "ok");
  1043. }
  1044. else if (result == 110)
  1045. {
  1046. bool userPickedOk
  1047. = AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  1048. "This is an ok/cancel AlertWindow",
  1049. "And this is the AlertWindow's message. Blah blah blah blah blah blah blah blah blah blah blah blah blah.");
  1050. (void) userPickedOk; // (just avoids a compiler warning about unused variables)
  1051. }
  1052. else if (result == 111)
  1053. {
  1054. AlertWindow w ("AlertWindow demo..",
  1055. "This AlertWindow has a couple of extra components added to show how to add drop-down lists and text entry boxes.",
  1056. AlertWindow::QuestionIcon);
  1057. w.addTextEditor ("text", "enter some text here", "text field:");
  1058. StringArray options;
  1059. options.add ("option 1");
  1060. options.add ("option 2");
  1061. options.add ("option 3");
  1062. options.add ("option 4");
  1063. w.addComboBox ("option", options, "some options");
  1064. w.addButton ("ok", 1, KeyPress (KeyPress::returnKey, 0, 0));
  1065. w.addButton ("cancel", 0, KeyPress (KeyPress::escapeKey, 0, 0));
  1066. if (w.runModalLoop() != 0) // is they picked 'ok'
  1067. {
  1068. // this is the item they chose in the drop-down list..
  1069. const int optionIndexChosen = w.getComboBoxComponent ("option")->getSelectedItemIndex();
  1070. (void) optionIndexChosen; // (just avoids a compiler warning about unused variables)
  1071. // this is the text they entered..
  1072. String text = w.getTextEditorContents ("text");
  1073. }
  1074. }
  1075. else if (result == 112)
  1076. {
  1077. DemoBackgroundThread demoThread;
  1078. if (demoThread.runThread())
  1079. {
  1080. // thread finished normally..
  1081. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  1082. "Progress window",
  1083. "Thread finished ok!");
  1084. }
  1085. else
  1086. {
  1087. // user pressed the cancel button..
  1088. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  1089. "Progress window",
  1090. "You pressed cancel!");
  1091. }
  1092. }
  1093. else if (result == 120)
  1094. {
  1095. ColourSelectorDialogWindow colourDialog;
  1096. // this will run an event loop until the dialog's closeButtonPressed()
  1097. // method causes the loop to exit.
  1098. colourDialog.runModalLoop();
  1099. }
  1100. else if (result == 140)
  1101. {
  1102. #if JUCE_MAC
  1103. AppleRemoteTestWindow test;
  1104. test.runModalLoop();
  1105. #endif
  1106. }
  1107. else if (result >= 121 && result < 139)
  1108. {
  1109. const bool useNativeVersion = result < 130;
  1110. if (result > 130)
  1111. result -= 10;
  1112. if (result == 121)
  1113. {
  1114. FileChooser fc ("Choose a file to open...",
  1115. File::getCurrentWorkingDirectory(),
  1116. "*",
  1117. useNativeVersion);
  1118. if (fc.browseForFileToOpen())
  1119. {
  1120. File chosenFile = fc.getResult();
  1121. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  1122. "File Chooser...",
  1123. "You picked: " + chosenFile.getFullPathName());
  1124. }
  1125. }
  1126. else if (result == 124)
  1127. {
  1128. ImagePreviewComponent imagePreview;
  1129. imagePreview.setSize (200, 200);
  1130. FileChooser fc ("Choose an image to open...",
  1131. File::getCurrentWorkingDirectory(),
  1132. "*.jpg;*.jpeg;*.png;*.gif",
  1133. useNativeVersion);
  1134. if (fc.browseForFileToOpen (&imagePreview))
  1135. {
  1136. File chosenFile = fc.getResult();
  1137. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  1138. "File Chooser...",
  1139. "You picked: " + chosenFile.getFullPathName());
  1140. }
  1141. }
  1142. else if (result == 122)
  1143. {
  1144. FileChooser fc ("Choose a file to save...",
  1145. File::getCurrentWorkingDirectory(),
  1146. "*",
  1147. useNativeVersion);
  1148. if (fc.browseForFileToSave (true))
  1149. {
  1150. File chosenFile = fc.getResult();
  1151. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  1152. "File Chooser...",
  1153. "You picked: " + chosenFile.getFullPathName());
  1154. }
  1155. }
  1156. else if (result == 123)
  1157. {
  1158. FileChooser fc ("Choose a directory...",
  1159. File::getCurrentWorkingDirectory(),
  1160. "*",
  1161. useNativeVersion);
  1162. if (fc.browseForDirectory())
  1163. {
  1164. File chosenDirectory = fc.getResult();
  1165. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  1166. "File Chooser...",
  1167. "You picked: " + chosenDirectory.getFullPathName());
  1168. }
  1169. }
  1170. }
  1171. else if (result == 1001)
  1172. {
  1173. tabs->setOrientation (TabbedButtonBar::TabsAtTop);
  1174. }
  1175. else if (result == 1002)
  1176. {
  1177. tabs->setOrientation (TabbedButtonBar::TabsAtBottom);
  1178. }
  1179. else if (result == 1003)
  1180. {
  1181. tabs->setOrientation (TabbedButtonBar::TabsAtLeft);
  1182. }
  1183. else if (result == 1004)
  1184. {
  1185. tabs->setOrientation (TabbedButtonBar::TabsAtRight);
  1186. }
  1187. }
  1188. }
  1189. }
  1190. };
  1191. //==============================================================================
  1192. Component* createWidgetsDemo (ApplicationCommandManager* commandManager)
  1193. {
  1194. return new WidgetsDemo (commandManager);
  1195. }