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.

175 lines
7.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef __JUCE_APPLICATIONBASE_JUCEHEADER__
  18. #define __JUCE_APPLICATIONBASE_JUCEHEADER__
  19. //==============================================================================
  20. /**
  21. Abstract base class for application classes.
  22. This class shouldn't be used directly - you'll normally use JUCEApplication as
  23. the base for your app, and that inherits from this, adding some more functionality
  24. to it.
  25. @see JUCEApplication
  26. */
  27. class JUCE_API JUCEApplicationBase
  28. {
  29. protected:
  30. //==============================================================================
  31. JUCEApplicationBase();
  32. public:
  33. /** Destructor. */
  34. virtual ~JUCEApplicationBase();
  35. //==============================================================================
  36. /** Returns the global instance of the application object that's running. */
  37. static JUCEApplicationBase* getInstance() noexcept { return appInstance; }
  38. //==============================================================================
  39. /** Returns the application's name.
  40. An application must implement this to name itself.
  41. */
  42. virtual const String getApplicationName() = 0;
  43. /** Returns the application's version number.
  44. */
  45. virtual const String getApplicationVersion() = 0;
  46. /** Checks whether multiple instances of the app are allowed.
  47. If you application class returns true for this, more than one instance is
  48. permitted to run (except on the Mac where this isn't possible).
  49. If it's false, the second instance won't start, but it you will still get a
  50. callback to anotherInstanceStarted() to tell you about this - which
  51. gives you a chance to react to what the user was trying to do.
  52. */
  53. virtual bool moreThanOneInstanceAllowed() = 0;
  54. /** Called when the application starts.
  55. This will be called once to let the application do whatever initialisation
  56. it needs, create its windows, etc.
  57. After the method returns, the normal event-dispatch loop will be run,
  58. until the quit() method is called, at which point the shutdown()
  59. method will be called to let the application clear up anything it needs
  60. to delete.
  61. If during the initialise() method, the application decides not to start-up
  62. after all, it can just call the quit() method and the event loop won't be run.
  63. @param commandLineParameters the line passed in does not include the name of
  64. the executable, just the parameter list. To get the
  65. parameters as an array, you can call
  66. JUCEApplication::getCommandLineParameters()
  67. @see shutdown, quit
  68. */
  69. virtual void initialise (const String& commandLineParameters) = 0;
  70. /* Called to allow the application to clear up before exiting.
  71. After JUCEApplication::quit() has been called, the event-dispatch loop will
  72. terminate, and this method will get called to allow the app to sort itself
  73. out.
  74. Be careful that nothing happens in this method that might rely on messages
  75. being sent, or any kind of window activity, because the message loop is no
  76. longer running at this point.
  77. @see DeletedAtShutdown
  78. */
  79. virtual void shutdown() = 0;
  80. /** Indicates that the user has tried to start up another instance of the app.
  81. This will get called even if moreThanOneInstanceAllowed() is false.
  82. */
  83. virtual void anotherInstanceStarted (const String& commandLine) = 0;
  84. /** Called when the operating system is trying to close the application.
  85. The default implementation of this method is to call quit(), but it may
  86. be overloaded to ignore the request or do some other special behaviour
  87. instead. For example, you might want to offer the user the chance to save
  88. their changes before quitting, and give them the chance to cancel.
  89. If you want to send a quit signal to your app, this is the correct method
  90. to call, because it means that requests that come from the system get handled
  91. in the same way as those from your own application code. So e.g. you'd
  92. call this method from a "quit" item on a menu bar.
  93. */
  94. virtual void systemRequestedQuit() = 0;
  95. /** This method is called when the application is being put into background mode
  96. by the operating system.
  97. */
  98. virtual void suspended() = 0;
  99. /** This method is called when the application is being woken from background mode
  100. by the operating system.
  101. */
  102. virtual void resumed() = 0;
  103. /** If any unhandled exceptions make it through to the message dispatch loop, this
  104. callback will be triggered, in case you want to log them or do some other
  105. type of error-handling.
  106. If the type of exception is derived from the std::exception class, the pointer
  107. passed-in will be valid. If the exception is of unknown type, this pointer
  108. will be null.
  109. */
  110. virtual void unhandledException (const std::exception*,
  111. const String& sourceFilename,
  112. int lineNumber) = 0;
  113. //==============================================================================
  114. /** Returns true if this executable is running as an app (as opposed to being a plugin
  115. or other kind of shared library. */
  116. static inline bool isStandaloneApp() noexcept { return createInstance != nullptr; }
  117. //==============================================================================
  118. #ifndef DOXYGEN
  119. static void appWillTerminateByForce();
  120. typedef JUCEApplicationBase* (*CreateInstanceFunction)();
  121. static CreateInstanceFunction createInstance;
  122. protected:
  123. virtual int shutdownApp() = 0;
  124. #endif
  125. private:
  126. //==============================================================================
  127. static JUCEApplicationBase* appInstance;
  128. JUCE_DECLARE_NON_COPYABLE (JUCEApplicationBase)
  129. };
  130. #endif // __JUCE_APPLICATIONBASE_JUCEHEADER__