juce_Application.h 7.4 KB

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