Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / JuceDemo / Source / MainDemoWindow.cpp
bloba2bad8e515d6b792bce36d44473ab1c824176ad6
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-9 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "jucedemo_headers.h"
27 #include "MainDemoWindow.h"
30 //==============================================================================
31 class ContentComp : public Component,
32 public MenuBarModel,
33 public ApplicationCommandTarget
35 public:
36 //==============================================================================
37 ContentComp (MainDemoWindow* mainWindow_)
38 : mainWindow (mainWindow_),
39 currentDemoId (0)
41 invokeDirectly (showRendering, true);
44 ~ContentComp()
48 //==============================================================================
49 void resized()
51 if (currentDemo != 0)
52 currentDemo->setBounds (0, 0, getWidth(), getHeight());
55 //==============================================================================
56 void showDemo (Component* demoComp)
58 currentDemo = demoComp;
59 addAndMakeVisible (currentDemo);
60 resized();
63 //==============================================================================
64 const StringArray getMenuBarNames()
66 const char* const names[] = { "Demo", "Look-and-feel", 0 };
68 return StringArray (names);
71 const PopupMenu getMenuForIndex (int menuIndex, const String& /*menuName*/)
73 ApplicationCommandManager* commandManager = &(mainWindow->commandManager);
75 PopupMenu menu;
77 if (menuIndex == 0)
79 menu.addCommandItem (commandManager, showRendering);
80 menu.addCommandItem (commandManager, showFontsAndText);
81 menu.addCommandItem (commandManager, showWidgets);
82 menu.addCommandItem (commandManager, showThreading);
83 menu.addCommandItem (commandManager, showTreeView);
84 menu.addCommandItem (commandManager, showTable);
85 menu.addCommandItem (commandManager, showAudio);
86 menu.addCommandItem (commandManager, showDragAndDrop);
87 menu.addCommandItem (commandManager, showOpenGL);
88 menu.addCommandItem (commandManager, showQuicktime);
89 menu.addCommandItem (commandManager, showDirectShow);
90 menu.addCommandItem (commandManager, showInterprocessComms);
91 menu.addCommandItem (commandManager, showCamera);
92 menu.addCommandItem (commandManager, showWebBrowser);
93 menu.addCommandItem (commandManager, showCodeEditor);
95 menu.addSeparator();
96 menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
98 else if (menuIndex == 1)
100 menu.addCommandItem (commandManager, setDefaultLookAndFeel);
101 menu.addCommandItem (commandManager, setOldSchoolLookAndFeel);
102 menu.addSeparator();
103 menu.addCommandItem (commandManager, useNativeTitleBar);
105 #if JUCE_MAC
106 menu.addCommandItem (commandManager, useNativeMenus);
107 #endif
109 #if ! JUCE_LINUX
110 menu.addCommandItem (commandManager, goToKioskMode);
111 #endif
113 StringArray renderingEngines (getPeer()->getAvailableRenderingEngines());
114 if (renderingEngines.size() > 1)
116 menu.addSeparator();
118 for (int i = 0; i < renderingEngines.size(); ++i)
119 menu.addItem (5001 + i, "Use " + renderingEngines[i], true,
120 i == getPeer()->getCurrentRenderingEngine());
124 return menu;
127 void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/)
129 // most of our menu items are invoked automatically as commands, but we can handle the
130 // other special cases here..
132 if (menuItemID >= 5001 && menuItemID < 5010)
133 getPeer()->setCurrentRenderingEngine (menuItemID - 5001);
136 //==============================================================================
137 // The following methods implement the ApplicationCommandTarget interface, allowing
138 // this window to publish a set of actions it can perform, and which can be mapped
139 // onto menus, keypresses, etc.
141 ApplicationCommandTarget* getNextCommandTarget()
143 // this will return the next parent component that is an ApplicationCommandTarget (in this
144 // case, there probably isn't one, but it's best to use this method in your own apps).
145 return findFirstTargetParentComponent();
148 void getAllCommands (Array <CommandID>& commands)
150 // this returns the set of all commands that this target can perform..
151 const CommandID ids[] = { showRendering,
152 showFontsAndText,
153 showWidgets,
154 showThreading,
155 showTreeView,
156 showTable,
157 showAudio,
158 showDragAndDrop,
159 showOpenGL,
160 showQuicktime,
161 showDirectShow,
162 showCamera,
163 showWebBrowser,
164 showCodeEditor,
165 showInterprocessComms,
166 setDefaultLookAndFeel,
167 setOldSchoolLookAndFeel,
168 useNativeTitleBar
169 #if JUCE_MAC
170 , useNativeMenus
171 #endif
173 #if ! JUCE_LINUX
174 , goToKioskMode
175 #endif
178 commands.addArray (ids, numElementsInArray (ids));
181 // This method is used when something needs to find out the details about one of the commands
182 // that this object can perform..
183 void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
185 const String generalCategory ("General");
186 const String demosCategory ("Demos");
188 switch (commandID)
190 case showRendering:
191 result.setInfo ("Graphics Rendering", "Shows the graphics demo", demosCategory, 0);
192 result.setTicked (currentDemoId == showRendering);
193 result.addDefaultKeypress ('1', ModifierKeys::commandModifier);
194 break;
196 case showFontsAndText:
197 result.setInfo ("Fonts and Text", "Shows the fonts & text demo", demosCategory, 0);
198 result.setTicked (currentDemoId == showFontsAndText);
199 result.addDefaultKeypress ('2', ModifierKeys::commandModifier);
200 break;
202 case showWidgets:
203 result.setInfo ("Widgets", "Shows the widgets demo", demosCategory, 0);
204 result.setTicked (currentDemoId == showWidgets);
205 result.addDefaultKeypress ('3', ModifierKeys::commandModifier);
206 break;
208 case showThreading:
209 result.setInfo ("Multithreading", "Shows the threading demo", demosCategory, 0);
210 result.setTicked (currentDemoId == showThreading);
211 result.addDefaultKeypress ('4', ModifierKeys::commandModifier);
212 break;
214 case showTreeView:
215 result.setInfo ("Treeviews", "Shows the treeviews demo", demosCategory, 0);
216 result.setTicked (currentDemoId == showTreeView);
217 result.addDefaultKeypress ('5', ModifierKeys::commandModifier);
218 break;
220 case showTable:
221 result.setInfo ("Table Components", "Shows the table component demo", demosCategory, 0);
222 result.setTicked (currentDemoId == showTable);
223 result.addDefaultKeypress ('6', ModifierKeys::commandModifier);
224 break;
226 case showAudio:
227 result.setInfo ("Audio", "Shows the audio demo", demosCategory, 0);
228 result.setTicked (currentDemoId == showAudio);
229 result.addDefaultKeypress ('7', ModifierKeys::commandModifier);
230 break;
232 case showDragAndDrop:
233 result.setInfo ("Drag-and-drop", "Shows the drag & drop demo", demosCategory, 0);
234 result.setTicked (currentDemoId == showDragAndDrop);
235 result.addDefaultKeypress ('8', ModifierKeys::commandModifier);
236 break;
238 case showOpenGL:
239 result.setInfo ("OpenGL", "Shows the OpenGL demo", demosCategory, 0);
240 result.addDefaultKeypress ('9', ModifierKeys::commandModifier);
241 result.setTicked (currentDemoId == showOpenGL);
242 #if ! JUCE_OPENGL
243 result.setActive (false);
244 #endif
245 break;
247 case showQuicktime:
248 result.setInfo ("Quicktime", "Shows the Quicktime demo", demosCategory, 0);
249 result.addDefaultKeypress ('b', ModifierKeys::commandModifier);
250 result.setTicked (currentDemoId == showQuicktime);
251 #if ! (JUCE_QUICKTIME && ! JUCE_LINUX)
252 result.setActive (false);
253 #endif
254 break;
256 case showDirectShow:
257 result.setInfo ("DirectShow", "Shows the DirectShow demo", demosCategory, 0);
258 result.addDefaultKeypress ('b', ModifierKeys::commandModifier);
259 result.setTicked (currentDemoId == showDirectShow);
260 #if ! JUCE_DIRECTSHOW
261 result.setActive (false);
262 #endif
263 break;
265 case showCamera:
266 result.setInfo ("Camera Capture", "Shows the camera demo", demosCategory, 0);
267 result.addDefaultKeypress ('c', ModifierKeys::commandModifier);
268 result.setTicked (currentDemoId == showCamera);
269 #if ! JUCE_USE_CAMERA
270 result.setActive (false);
271 #endif
272 break;
274 case showWebBrowser:
275 result.setInfo ("Web Browser", "Shows the web browser demo", demosCategory, 0);
276 result.addDefaultKeypress ('i', ModifierKeys::commandModifier);
277 result.setTicked (currentDemoId == showWebBrowser);
278 #if (! JUCE_WEB_BROWSER) || JUCE_LINUX
279 result.setActive (false);
280 #endif
281 break;
283 case showCodeEditor:
284 result.setInfo ("Code Editor", "Shows the code editor demo", demosCategory, 0);
285 result.addDefaultKeypress ('e', ModifierKeys::commandModifier);
286 result.setTicked (currentDemoId == showCodeEditor);
287 break;
289 case showInterprocessComms:
290 result.setInfo ("Interprocess Comms", "Shows the interprocess communications demo", demosCategory, 0);
291 result.addDefaultKeypress ('0', ModifierKeys::commandModifier);
292 result.setTicked (currentDemoId == showInterprocessComms);
293 break;
295 case setDefaultLookAndFeel:
296 result.setInfo ("Use default look-and-feel", String::empty, generalCategory, 0);
297 result.setTicked (dynamic_cast <OldSchoolLookAndFeel*> (&getLookAndFeel()) == 0);
298 break;
300 case setOldSchoolLookAndFeel:
301 result.setInfo ("Use the old, original juce look-and-feel", String::empty, generalCategory, 0);
302 result.setTicked (dynamic_cast <OldSchoolLookAndFeel*> (&getLookAndFeel()) != 0);
303 break;
305 case useNativeTitleBar:
306 result.setInfo ("Use native window title bar", String::empty, generalCategory, 0);
307 result.setTicked (mainWindow->isUsingNativeTitleBar());
308 break;
310 #if JUCE_MAC
311 case useNativeMenus:
312 result.setInfo ("Use the native OSX menu bar", String::empty, generalCategory, 0);
313 result.setTicked (MenuBarModel::getMacMainMenu() != 0);
314 break;
315 #endif
317 #if ! JUCE_LINUX
318 case goToKioskMode:
319 result.setInfo ("Show full-screen kiosk mode", String::empty, generalCategory, 0);
320 result.setTicked (Desktop::getInstance().getKioskModeComponent() != 0);
321 break;
322 #endif
324 default:
325 break;
329 // this is the ApplicationCommandTarget method that is used to actually perform one of our commands..
330 bool perform (const InvocationInfo& info)
332 switch (info.commandID)
334 case showRendering:
335 showDemo (createRenderingDemo());
336 currentDemoId = showRendering;
337 break;
339 case showFontsAndText:
340 showDemo (createFontsAndTextDemo());
341 currentDemoId = showFontsAndText;
342 break;
344 case showWidgets:
345 showDemo (createWidgetsDemo());
346 currentDemoId = showWidgets;
347 break;
349 case showThreading:
350 showDemo (createThreadingDemo());
351 currentDemoId = showThreading;
352 break;
354 case showTreeView:
355 showDemo (createTreeViewDemo());
356 currentDemoId = showTreeView;
357 break;
359 case showTable:
360 showDemo (createTableDemo());
361 currentDemoId = showTable;
362 break;
364 case showAudio:
365 showDemo (createAudioDemo());
366 currentDemoId = showAudio;
367 break;
369 case showDragAndDrop:
370 showDemo (createDragAndDropDemo());
371 currentDemoId = showDragAndDrop;
372 break;
374 case showOpenGL:
375 #if JUCE_OPENGL
376 showDemo (createOpenGLDemo());
377 currentDemoId = showOpenGL;
378 #endif
379 break;
381 case showQuicktime:
382 #if JUCE_QUICKTIME && ! JUCE_LINUX
383 showDemo (createQuickTimeDemo());
384 currentDemoId = showQuicktime;
385 #endif
386 break;
388 case showDirectShow:
389 #if JUCE_DIRECTSHOW
390 showDemo (createDirectShowDemo());
391 currentDemoId = showDirectShow;
392 #endif
393 break;
395 case showCamera:
396 #if JUCE_USE_CAMERA
397 showDemo (createCameraDemo());
398 currentDemoId = showCamera;
399 #endif
400 break;
402 case showWebBrowser:
403 #if JUCE_WEB_BROWSER
404 showDemo (createWebBrowserDemo());
405 currentDemoId = showWebBrowser;
406 #endif
407 break;
409 case showCodeEditor:
410 showDemo (createCodeEditorDemo());
411 currentDemoId = showCodeEditor;
412 break;
414 case showInterprocessComms:
415 showDemo (createInterprocessCommsDemo());
416 currentDemoId = showInterprocessComms;
417 break;
419 case setDefaultLookAndFeel:
420 LookAndFeel::setDefaultLookAndFeel (nullptr);
421 break;
423 case setOldSchoolLookAndFeel:
424 LookAndFeel::setDefaultLookAndFeel (&oldLookAndFeel);
425 break;
427 case useNativeTitleBar:
428 mainWindow->setUsingNativeTitleBar (! mainWindow->isUsingNativeTitleBar());
429 break;
431 #if JUCE_MAC
432 case useNativeMenus:
433 if (MenuBarModel::getMacMainMenu() != 0)
435 MenuBarModel::setMacMainMenu (0);
436 mainWindow->setMenuBar ((ContentComp*) mainWindow->getContentComponent());
438 else
440 MenuBarModel::setMacMainMenu ((ContentComp*) mainWindow->getContentComponent());
441 mainWindow->setMenuBar (0);
444 break;
445 #endif
447 #if ! JUCE_LINUX
448 case goToKioskMode:
449 if (Desktop::getInstance().getKioskModeComponent() == 0)
451 Desktop::getInstance().setKioskModeComponent (getTopLevelComponent());
453 else
455 Desktop::getInstance().setKioskModeComponent (0);
458 break;
459 #endif
461 default:
462 return false;
465 return true;
468 private:
469 //==============================================================================
470 MainDemoWindow* mainWindow;
471 OldSchoolLookAndFeel oldLookAndFeel;
472 ScopedPointer<Component> currentDemo;
473 int currentDemoId;
475 TooltipWindow tooltipWindow; // to add tooltips to an application, you
476 // just need to create one of these and leave it
477 // there to do its work..
479 enum CommandIDs
481 showRendering = 0x2000,
482 showFontsAndText = 0x2001,
483 showWidgets = 0x2002,
484 showThreading = 0x2003,
485 showTreeView = 0x2004,
486 showAudio = 0x2005,
487 showDragAndDrop = 0x2006,
488 showOpenGL = 0x2007,
489 showQuicktime = 0x2008,
490 showInterprocessComms = 0x2009,
491 showTable = 0x2010,
492 showCamera = 0x2011,
493 showWebBrowser = 0x2012,
494 showCodeEditor = 0x2013,
495 showDirectShow = 0x2014,
497 setDefaultLookAndFeel = 0x200b,
498 setOldSchoolLookAndFeel = 0x200c,
499 useNativeTitleBar = 0x200d,
500 useNativeMenus = 0x200e,
501 goToKioskMode = 0x200f
504 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentComp);
507 //==============================================================================
508 #if JUCE_WINDOWS || JUCE_LINUX
510 // Just add a simple icon to the Window system tray area..
511 class DemoTaskbarComponent : public SystemTrayIconComponent
513 public:
514 DemoTaskbarComponent()
516 // Create an icon which is just a square with a "j" in it..
517 Image icon (Image::RGB, 32, 32, true);
518 Graphics g (icon);
519 g.fillAll (Colours::lightblue);
520 g.setColour (Colours::black);
521 g.setFont ((float) icon.getHeight(), Font::bold);
522 g.drawText ("j", 0, 0, icon.getWidth(), icon.getHeight(), Justification::centred, false);
524 setIconImage (icon);
526 setIconTooltip ("Juce Demo App!");
529 ~DemoTaskbarComponent()
533 void mouseDown (const MouseEvent&)
535 PopupMenu m;
536 m.addItem (1, "Quit the Juce demo");
538 const int result = m.show();
540 if (result == 1)
541 JUCEApplication::getInstance()->systemRequestedQuit();
545 #endif
547 //==============================================================================
548 MainDemoWindow::MainDemoWindow()
549 : DocumentWindow ("JUCE Demo!",
550 Colours::azure,
551 DocumentWindow::allButtons,
552 true)
554 setResizable (true, false); // resizability is a property of ResizableWindow
555 setResizeLimits (400, 300, 8192, 8192);
557 ContentComp* contentComp = new ContentComp (this);
559 commandManager.registerAllCommandsForTarget (contentComp);
560 commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance());
562 // this lets the command manager use keypresses that arrive in our window to send
563 // out commands
564 addKeyListener (commandManager.getKeyMappings());
566 // sets the main content component for the window to be this tabbed
567 // panel. This will be deleted when the window is deleted.
568 setContentOwned (contentComp, false);
570 // this tells the DocumentWindow to automatically create and manage a MenuBarComponent
571 // which uses our contentComp as its MenuBarModel
572 setMenuBar (contentComp);
574 // tells our menu bar model that it should watch this command manager for
575 // changes, and send change messages accordingly.
576 contentComp->setApplicationCommandManagerToWatch (&commandManager);
578 setVisible (true);
580 #if JUCE_WINDOWS || JUCE_LINUX
581 taskbarIcon = new DemoTaskbarComponent();
582 #endif
585 MainDemoWindow::~MainDemoWindow()
587 // because we've set the content comp to be used as our menu bar model, we
588 // have to switch this off before deleting the content comp..
589 setMenuBar (0);
591 #if JUCE_MAC // ..and also the main bar if we're using that on a Mac...
592 MenuBarModel::setMacMainMenu (0);
593 #endif
595 // clearing the content component will delete the current one, and
596 // that will in turn delete all its child components. You don't always
597 // have to do this explicitly, because the base class's destructor will
598 // also delete the content component, but in this case we need to
599 // make sure our content comp has gone away before deleting our command
600 // manager.
601 clearContentComponent();
604 void MainDemoWindow::closeButtonPressed()
606 // The correct thing to do when you want the app to quit is to call the
607 // JUCEApplication::systemRequestedQuit() method.
609 // That means that requests to quit that come from your own UI, or from other
610 // OS-specific sources (e.g. the dock menu on the mac) all get handled in the
611 // same way.
613 JUCEApplication::getInstance()->systemRequestedQuit();