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.

176 lines
7.3KB

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