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
,
33 public ApplicationCommandTarget
36 //==============================================================================
37 ContentComp (MainDemoWindow
* mainWindow_
)
38 : mainWindow (mainWindow_
),
41 invokeDirectly (showRendering
, true);
48 //==============================================================================
52 currentDemo
->setBounds (0, 0, getWidth(), getHeight());
55 //==============================================================================
56 void showDemo (Component
* demoComp
)
58 currentDemo
= demoComp
;
59 addAndMakeVisible (currentDemo
);
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
);
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
);
96 menu
.addCommandItem (commandManager
, StandardApplicationCommandIDs::quit
);
98 else if (menuIndex
== 1)
100 menu
.addCommandItem (commandManager
, setDefaultLookAndFeel
);
101 menu
.addCommandItem (commandManager
, setOldSchoolLookAndFeel
);
103 menu
.addCommandItem (commandManager
, useNativeTitleBar
);
106 menu
.addCommandItem (commandManager
, useNativeMenus
);
110 menu
.addCommandItem (commandManager
, goToKioskMode
);
113 StringArray
renderingEngines (getPeer()->getAvailableRenderingEngines());
114 if (renderingEngines
.size() > 1)
118 for (int i
= 0; i
< renderingEngines
.size(); ++i
)
119 menu
.addItem (5001 + i
, "Use " + renderingEngines
[i
], true,
120 i
== getPeer()->getCurrentRenderingEngine());
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
,
165 showInterprocessComms
,
166 setDefaultLookAndFeel
,
167 setOldSchoolLookAndFeel
,
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");
191 result
.setInfo ("Graphics Rendering", "Shows the graphics demo", demosCategory
, 0);
192 result
.setTicked (currentDemoId
== showRendering
);
193 result
.addDefaultKeypress ('1', ModifierKeys::commandModifier
);
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
);
203 result
.setInfo ("Widgets", "Shows the widgets demo", demosCategory
, 0);
204 result
.setTicked (currentDemoId
== showWidgets
);
205 result
.addDefaultKeypress ('3', ModifierKeys::commandModifier
);
209 result
.setInfo ("Multithreading", "Shows the threading demo", demosCategory
, 0);
210 result
.setTicked (currentDemoId
== showThreading
);
211 result
.addDefaultKeypress ('4', ModifierKeys::commandModifier
);
215 result
.setInfo ("Treeviews", "Shows the treeviews demo", demosCategory
, 0);
216 result
.setTicked (currentDemoId
== showTreeView
);
217 result
.addDefaultKeypress ('5', ModifierKeys::commandModifier
);
221 result
.setInfo ("Table Components", "Shows the table component demo", demosCategory
, 0);
222 result
.setTicked (currentDemoId
== showTable
);
223 result
.addDefaultKeypress ('6', ModifierKeys::commandModifier
);
227 result
.setInfo ("Audio", "Shows the audio demo", demosCategory
, 0);
228 result
.setTicked (currentDemoId
== showAudio
);
229 result
.addDefaultKeypress ('7', ModifierKeys::commandModifier
);
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
);
239 result
.setInfo ("OpenGL", "Shows the OpenGL demo", demosCategory
, 0);
240 result
.addDefaultKeypress ('9', ModifierKeys::commandModifier
);
241 result
.setTicked (currentDemoId
== showOpenGL
);
243 result
.setActive (false);
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);
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);
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);
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);
284 result
.setInfo ("Code Editor", "Shows the code editor demo", demosCategory
, 0);
285 result
.addDefaultKeypress ('e', ModifierKeys::commandModifier
);
286 result
.setTicked (currentDemoId
== showCodeEditor
);
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
);
295 case setDefaultLookAndFeel
:
296 result
.setInfo ("Use default look-and-feel", String::empty
, generalCategory
, 0);
297 result
.setTicked (dynamic_cast <OldSchoolLookAndFeel
*> (&getLookAndFeel()) == 0);
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);
305 case useNativeTitleBar
:
306 result
.setInfo ("Use native window title bar", String::empty
, generalCategory
, 0);
307 result
.setTicked (mainWindow
->isUsingNativeTitleBar());
312 result
.setInfo ("Use the native OSX menu bar", String::empty
, generalCategory
, 0);
313 result
.setTicked (MenuBarModel::getMacMainMenu() != 0);
319 result
.setInfo ("Show full-screen kiosk mode", String::empty
, generalCategory
, 0);
320 result
.setTicked (Desktop::getInstance().getKioskModeComponent() != 0);
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
)
335 showDemo (createRenderingDemo());
336 currentDemoId
= showRendering
;
339 case showFontsAndText
:
340 showDemo (createFontsAndTextDemo());
341 currentDemoId
= showFontsAndText
;
345 showDemo (createWidgetsDemo());
346 currentDemoId
= showWidgets
;
350 showDemo (createThreadingDemo());
351 currentDemoId
= showThreading
;
355 showDemo (createTreeViewDemo());
356 currentDemoId
= showTreeView
;
360 showDemo (createTableDemo());
361 currentDemoId
= showTable
;
365 showDemo (createAudioDemo());
366 currentDemoId
= showAudio
;
369 case showDragAndDrop
:
370 showDemo (createDragAndDropDemo());
371 currentDemoId
= showDragAndDrop
;
376 showDemo (createOpenGLDemo());
377 currentDemoId
= showOpenGL
;
382 #if JUCE_QUICKTIME && ! JUCE_LINUX
383 showDemo (createQuickTimeDemo());
384 currentDemoId
= showQuicktime
;
390 showDemo (createDirectShowDemo());
391 currentDemoId
= showDirectShow
;
397 showDemo (createCameraDemo());
398 currentDemoId
= showCamera
;
404 showDemo (createWebBrowserDemo());
405 currentDemoId
= showWebBrowser
;
410 showDemo (createCodeEditorDemo());
411 currentDemoId
= showCodeEditor
;
414 case showInterprocessComms
:
415 showDemo (createInterprocessCommsDemo());
416 currentDemoId
= showInterprocessComms
;
419 case setDefaultLookAndFeel
:
420 LookAndFeel::setDefaultLookAndFeel (nullptr);
423 case setOldSchoolLookAndFeel
:
424 LookAndFeel::setDefaultLookAndFeel (&oldLookAndFeel
);
427 case useNativeTitleBar
:
428 mainWindow
->setUsingNativeTitleBar (! mainWindow
->isUsingNativeTitleBar());
433 if (MenuBarModel::getMacMainMenu() != 0)
435 MenuBarModel::setMacMainMenu (0);
436 mainWindow
->setMenuBar ((ContentComp
*) mainWindow
->getContentComponent());
440 MenuBarModel::setMacMainMenu ((ContentComp
*) mainWindow
->getContentComponent());
441 mainWindow
->setMenuBar (0);
449 if (Desktop::getInstance().getKioskModeComponent() == 0)
451 Desktop::getInstance().setKioskModeComponent (getTopLevelComponent());
455 Desktop::getInstance().setKioskModeComponent (0);
469 //==============================================================================
470 MainDemoWindow
* mainWindow
;
471 OldSchoolLookAndFeel oldLookAndFeel
;
472 ScopedPointer
<Component
> currentDemo
;
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..
481 showRendering
= 0x2000,
482 showFontsAndText
= 0x2001,
483 showWidgets
= 0x2002,
484 showThreading
= 0x2003,
485 showTreeView
= 0x2004,
487 showDragAndDrop
= 0x2006,
489 showQuicktime
= 0x2008,
490 showInterprocessComms
= 0x2009,
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
514 DemoTaskbarComponent()
516 // Create an icon which is just a square with a "j" in it..
517 Image
icon (Image::RGB
, 32, 32, true);
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);
526 setIconTooltip ("Juce Demo App!");
529 ~DemoTaskbarComponent()
533 void mouseDown (const MouseEvent
&)
536 m
.addItem (1, "Quit the Juce demo");
538 const int result
= m
.show();
541 JUCEApplication::getInstance()->systemRequestedQuit();
547 //==============================================================================
548 MainDemoWindow::MainDemoWindow()
549 : DocumentWindow ("JUCE Demo!",
551 DocumentWindow::allButtons
,
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
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
);
580 #if JUCE_WINDOWS || JUCE_LINUX
581 taskbarIcon
= new DemoTaskbarComponent();
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..
591 #if JUCE_MAC // ..and also the main bar if we're using that on a Mac...
592 MenuBarModel::setMacMainMenu (0);
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
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
613 JUCEApplication::getInstance()->systemRequestedQuit();