JUCE
Public Member Functions | Static Public Member Functions | List of all members
JUCEApplication Class Referenceabstract

An instance of this class is used to specify initialisation and shutdown code for the application. More...

+ Inheritance diagram for JUCEApplication:

Public Member Functions

 JUCEApplication ()
 Constructs a JUCE app object. More...
 
 ~JUCEApplication ()
 Destructor. More...
 
virtual const String getApplicationName ()=0
 Returns the application's name. More...
 
virtual const String getApplicationVersion ()=0
 Returns the application's version number. More...
 
bool moreThanOneInstanceAllowed () override
 Checks whether multiple instances of the app are allowed. More...
 
void anotherInstanceStarted (const String &commandLine) override
 Indicates that the user has tried to start up another instance of the app. More...
 
void systemRequestedQuit () override
 Called when the operating system is trying to close the application. More...
 
void suspended () override
 This method is called when the application is being put into background mode by the operating system. More...
 
void resumed () override
 This method is called when the application is being woken from background mode by the operating system. More...
 
void unhandledException (const std::exception *e, const String &sourceFilename, int lineNumber) override
 If any unhandled exceptions make it through to the message dispatch loop, this callback will be triggered, in case you want to log them or do some other type of error-handling. More...
 
ApplicationCommandTargetgetNextCommandTarget () override
 
void getCommandInfo (CommandID, ApplicationCommandInfo &) override
 
void getAllCommands (Array< CommandID > &) override
 
bool perform (const InvocationInfo &) override
 
- Public Member Functions inherited from JUCEApplicationBase
virtual ~JUCEApplicationBase ()
 Destructor. More...
 
virtual void initialise (const String &commandLineParameters)=0
 Called when the application starts. More...
 
virtual void shutdown ()=0
 
void setApplicationReturnValue (int newReturnValue) noexcept
 Sets the value that should be returned as the application's exit code when the app quits. More...
 
int getApplicationReturnValue () const noexcept
 Returns the value that has been set as the application's exit code. More...
 
bool isInitialising () const noexcept
 Returns true if the application hasn't yet completed its initialise() method and entered the main event loop. More...
 
- Public Member Functions inherited from ApplicationCommandTarget
 ApplicationCommandTarget ()
 Creates a command target. More...
 
virtual ~ApplicationCommandTarget ()
 Destructor. More...
 
bool invoke (const InvocationInfo &invocationInfo, const bool asynchronously)
 Makes this target invoke a command. More...
 
bool invokeDirectly (const CommandID commandID, const bool asynchronously)
 Invokes a given command directly on this target. More...
 
ApplicationCommandTargetgetTargetForCommand (const CommandID commandID)
 Searches this target and all subsequent ones for the first one that can handle the specified command. More...
 
bool isCommandActive (const CommandID commandID)
 Checks whether this command can currently be performed by this target. More...
 
ApplicationCommandTargetfindFirstTargetParentComponent ()
 If this object is a Component, this method will search upwards in its current UI hierarchy for the next parent component that implements the ApplicationCommandTarget class. More...
 

Static Public Member Functions

static JUCEApplication *JUCE_CALLTYPE getInstance () noexcept
 Returns the global instance of the application object being run. More...
 
- Static Public Member Functions inherited from JUCEApplicationBase
static JUCEApplicationBasegetInstance () noexcept
 Returns the global instance of the application object that's running. More...
 
static void quit ()
 Signals that the main message loop should stop and the application should terminate. More...
 
static StringArray JUCE_CALLTYPE getCommandLineParameterArray ()
 Returns the application's command line parameters as a set of strings. More...
 
static String JUCE_CALLTYPE getCommandLineParameters ()
 Returns the application's command line parameters as a single string. More...
 
static bool isStandaloneApp () noexcept
 Returns true if this executable is running as an app (as opposed to being a plugin or other kind of shared library. More...
 

Additional Inherited Members

- Protected Member Functions inherited from JUCEApplicationBase
 JUCEApplicationBase ()
 

Detailed Description

An instance of this class is used to specify initialisation and shutdown code for the application.

Any application that wants to run an event loop must declare a subclass of JUCEApplicationBase or JUCEApplication, and implement its various pure virtual methods.

It then needs to use the START_JUCE_APPLICATION macro somewhere in a CPP file to declare an instance of this class and generate suitable platform-specific boilerplate code to launch the app.

Note that this class is derived from JUCEApplicationBase, which contains most of the useful methods and functionality. This derived class is here simply as a convenient way to also inherit from an ApplicationCommandTarget, and to implement default versions of some of the pure virtual base class methods. But you can derive your app object directly from JUCEApplicationBase if you want to, and by doing so can avoid having a dependency on the juce_gui_basics module.

e.g.

class MyJUCEApp : public JUCEApplication
{
public:
MyJUCEApp() {}
~MyJUCEApp() {}
void initialise (const String& commandLine) override
{
myMainWindow = new MyApplicationWindow();
myMainWindow->setBounds (100, 100, 400, 500);
myMainWindow->setVisible (true);
}
void shutdown() override
{
myMainWindow = nullptr;
}
const String getApplicationName() override
{
return "Super JUCE-o-matic";
}
const String getApplicationVersion() override
{
return "1.0";
}
private:
};
// this generates boilerplate code to launch our app class:
See also
JUCEApplicationBase, START_JUCE_APPLICATION

Constructor & Destructor Documentation

JUCEApplication::JUCEApplication ( )

Constructs a JUCE app object.

If subclasses implement a constructor or destructor, they shouldn't call any JUCE code in there - put your startup/shutdown code in initialise() and shutdown() instead.

JUCEApplication::~JUCEApplication ( )

Destructor.

If subclasses implement a constructor or destructor, they shouldn't call any JUCE code in there - put your startup/shutdown code in initialise() and shutdown() instead.

Member Function Documentation

static JUCEApplication* JUCE_CALLTYPE JUCEApplication::getInstance ( )
staticnoexcept

Returns the global instance of the application object being run.

virtual const String JUCEApplication::getApplicationName ( )
pure virtual

Returns the application's name.

Implements JUCEApplicationBase.

virtual const String JUCEApplication::getApplicationVersion ( )
pure virtual

Returns the application's version number.

Implements JUCEApplicationBase.

bool JUCEApplication::moreThanOneInstanceAllowed ( )
overridevirtual

Checks whether multiple instances of the app are allowed.

If you application class returns true for this, more than one instance is permitted to run (except on OSX where the OS automatically stops you launching a second instance of an app without explicitly starting it from the command-line).

If it's false, the second instance won't start, but it you will still get a callback to anotherInstanceStarted() to tell you about this - which gives you a chance to react to what the user was trying to do.

Implements JUCEApplicationBase.

void JUCEApplication::anotherInstanceStarted ( const String commandLine)
overridevirtual

Indicates that the user has tried to start up another instance of the app.

This will get called even if moreThanOneInstanceAllowed() is false.

Implements JUCEApplicationBase.

void JUCEApplication::systemRequestedQuit ( )
overridevirtual

Called when the operating system is trying to close the application.

The default implementation of this method is to call quit(), but it may be overloaded to ignore the request or do some other special behaviour instead. For example, you might want to offer the user the chance to save their changes before quitting, and give them the chance to cancel.

If you want to send a quit signal to your app, this is the correct method to call, because it means that requests that come from the system get handled in the same way as those from your own application code. So e.g. you'd call this method from a "quit" item on a menu bar.

Implements JUCEApplicationBase.

void JUCEApplication::suspended ( )
overridevirtual

This method is called when the application is being put into background mode by the operating system.

Implements JUCEApplicationBase.

void JUCEApplication::resumed ( )
overridevirtual

This method is called when the application is being woken from background mode by the operating system.

Implements JUCEApplicationBase.

void JUCEApplication::unhandledException ( const std::exception *  e,
const String sourceFilename,
int  lineNumber 
)
overridevirtual

If any unhandled exceptions make it through to the message dispatch loop, this callback will be triggered, in case you want to log them or do some other type of error-handling.

If the type of exception is derived from the std::exception class, the pointer passed-in will be valid. If the exception is of unknown type, this pointer will be null.

Implements JUCEApplicationBase.

ApplicationCommandTarget* JUCEApplication::getNextCommandTarget ( )
overridevirtual
void JUCEApplication::getCommandInfo ( CommandID  ,
ApplicationCommandInfo  
)
overridevirtual
void JUCEApplication::getAllCommands ( Array< CommandID > &  )
overridevirtual
bool JUCEApplication::perform ( const InvocationInfo )
overridevirtual

The documentation for this class was generated from the following file: