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.

189 lines
7.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. An instance of this class is used to specify initialisation and shutdown
  21. code for the application.
  22. Any application that wants to run an event loop must declare a subclass of
  23. JUCEApplicationBase or JUCEApplication, and implement its various pure virtual
  24. methods.
  25. It then needs to use the START_JUCE_APPLICATION macro somewhere in a CPP file
  26. to declare an instance of this class and generate suitable platform-specific
  27. boilerplate code to launch the app.
  28. Note that this class is derived from JUCEApplicationBase, which contains most
  29. of the useful methods and functionality. This derived class is here simply as
  30. a convenient way to also inherit from an ApplicationCommandTarget, and to implement
  31. default versions of some of the pure virtual base class methods. But you can derive
  32. your app object directly from JUCEApplicationBase if you want to, and by doing so
  33. can avoid having a dependency on the juce_gui_basics module.
  34. e.g. @code
  35. class MyJUCEApp : public JUCEApplication
  36. {
  37. public:
  38. MyJUCEApp() {}
  39. ~MyJUCEApp() {}
  40. void initialise (const String& commandLine) override
  41. {
  42. myMainWindow = new MyApplicationWindow();
  43. myMainWindow->setBounds (100, 100, 400, 500);
  44. myMainWindow->setVisible (true);
  45. }
  46. void shutdown() override
  47. {
  48. myMainWindow = nullptr;
  49. }
  50. const String getApplicationName() override
  51. {
  52. return "Super JUCE-o-matic";
  53. }
  54. const String getApplicationVersion() override
  55. {
  56. return "1.0";
  57. }
  58. private:
  59. ScopedPointer<MyApplicationWindow> myMainWindow;
  60. };
  61. // this generates boilerplate code to launch our app class:
  62. START_JUCE_APPLICATION (MyJUCEApp)
  63. @endcode
  64. @see JUCEApplicationBase, START_JUCE_APPLICATION
  65. */
  66. class JUCE_API JUCEApplication : public JUCEApplicationBase,
  67. public ApplicationCommandTarget
  68. {
  69. public:
  70. //==============================================================================
  71. /** Constructs a JUCE app object.
  72. If subclasses implement a constructor or destructor, they shouldn't call any
  73. JUCE code in there - put your startup/shutdown code in initialise() and
  74. shutdown() instead.
  75. */
  76. JUCEApplication();
  77. /** Destructor.
  78. If subclasses implement a constructor or destructor, they shouldn't call any
  79. JUCE code in there - put your startup/shutdown code in initialise() and
  80. shutdown() instead.
  81. */
  82. ~JUCEApplication();
  83. //==============================================================================
  84. /** Returns the global instance of the application object being run. */
  85. static JUCEApplication* JUCE_CALLTYPE getInstance() noexcept;
  86. //==============================================================================
  87. #if DOXYGEN
  88. /** Returns the application's name. */
  89. virtual const String getApplicationName() = 0;
  90. /** Returns the application's version number. */
  91. virtual const String getApplicationVersion() = 0;
  92. #endif
  93. /** Checks whether multiple instances of the app are allowed.
  94. If you application class returns true for this, more than one instance is
  95. permitted to run (except on OSX where the OS automatically stops you launching
  96. a second instance of an app without explicitly starting it from the command-line).
  97. If it's false, the second instance won't start, but it you will still get a
  98. callback to anotherInstanceStarted() to tell you about this - which
  99. gives you a chance to react to what the user was trying to do.
  100. */
  101. bool moreThanOneInstanceAllowed() override;
  102. /** Indicates that the user has tried to start up another instance of the app.
  103. This will get called even if moreThanOneInstanceAllowed() is false.
  104. */
  105. void anotherInstanceStarted (const String& commandLine) override;
  106. /** Called when the operating system is trying to close the application.
  107. The default implementation of this method is to call quit(), but it may
  108. be overloaded to ignore the request or do some other special behaviour
  109. instead. For example, you might want to offer the user the chance to save
  110. their changes before quitting, and give them the chance to cancel.
  111. If you want to send a quit signal to your app, this is the correct method
  112. to call, because it means that requests that come from the system get handled
  113. in the same way as those from your own application code. So e.g. you'd
  114. call this method from a "quit" item on a menu bar.
  115. */
  116. void systemRequestedQuit() override;
  117. /** This method is called when the application is being put into background mode
  118. by the operating system.
  119. */
  120. void suspended() override;
  121. /** This method is called when the application is being woken from background mode
  122. by the operating system.
  123. */
  124. void resumed() override;
  125. /** If any unhandled exceptions make it through to the message dispatch loop, this
  126. callback will be triggered, in case you want to log them or do some other
  127. type of error-handling.
  128. If the type of exception is derived from the std::exception class, the pointer
  129. passed-in will be valid. If the exception is of unknown type, this pointer
  130. will be null.
  131. */
  132. void unhandledException (const std::exception* e,
  133. const String& sourceFilename,
  134. int lineNumber) override;
  135. //==============================================================================
  136. /** @internal */
  137. ApplicationCommandTarget* getNextCommandTarget() override;
  138. /** @internal */
  139. void getCommandInfo (CommandID, ApplicationCommandInfo&) override;
  140. /** @internal */
  141. void getAllCommands (Array<CommandID>&) override;
  142. /** @internal */
  143. bool perform (const InvocationInfo&) override;
  144. private:
  145. bool initialiseApp() override;
  146. JUCE_DECLARE_NON_COPYABLE (JUCEApplication)
  147. };