Public Member Functions | Static Public Member Functions | Protected Member Functions

JUCEApplication Class Reference

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

Inherits ApplicationCommandTarget.

List of all members.

Public Member Functions

virtual ~JUCEApplication ()
 Destructor.
virtual void initialise (const String &commandLineParameters)=0
 Called when the application starts.
bool isInitialising () const noexcept
 Returns true if the application hasn't yet completed its initialise() method and entered the main event loop.
virtual void shutdown ()=0
virtual const String getApplicationName ()=0
 Returns the application's name.
virtual const String getApplicationVersion ()=0
 Returns the application's version number.
virtual bool moreThanOneInstanceAllowed ()
 Checks whether multiple instances of the app are allowed.
virtual void anotherInstanceStarted (const String &commandLine)
 Indicates that the user has tried to start up another instance of the app.
virtual void systemRequestedQuit ()
 Called when the operating system is trying to close the application.
virtual void unhandledException (const std::exception *e, const String &sourceFilename, int lineNumber)
 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.
void setApplicationReturnValue (int newReturnValue) noexcept
 Sets the value that should be returned as the application's exit code when the app quits.
int getApplicationReturnValue () const noexcept
 Returns the value that has been set as the application's exit code.
const StringgetCommandLineParameters () const noexcept
 Returns the application's command line parameters.
ApplicationCommandTargetgetNextCommandTarget ()
 This must return the next target to try after this one.
void getCommandInfo (CommandID commandID, ApplicationCommandInfo &result)
 This must provide details about one of the commands that this target can perform.
void getAllCommands (Array< CommandID > &commands)
 This must return a complete list of commands that this target can handle.
bool perform (const InvocationInfo &info)
 This must actually perform the specified command.

Static Public Member Functions

static JUCEApplicationgetInstance () noexcept
 Returns the global instance of the application object being run.
static void quit ()
 Signals that the main message loop should stop and the application should terminate.
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.

Protected Member Functions

 JUCEApplication ()
 Constructs a JUCE app object.

Detailed Description

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

An application that wants to run in the JUCE framework needs to declare a subclass of 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 a suitable platform-specific main() function.

e.g.

        class MyJUCEApp  : public JUCEApplication
        {
        public:
            MyJUCEApp()
            {
            }

            ~MyJUCEApp()
            {
            }

            void initialise (const String& commandLine)
            {
                myMainWindow = new MyApplicationWindow();
                myMainWindow->setBounds (100, 100, 400, 500);
                myMainWindow->setVisible (true);
            }

            void shutdown()
            {
                myMainWindow = 0;
            }

            const String getApplicationName()
            {
                return "Super JUCE-o-matic";
            }

            const String getApplicationVersion()
            {
                return "1.0";
            }

        private:
            ScopedPointer <MyApplicationWindow> myMainWindow;
        };

        // this creates wrapper code to actually launch the app properly.
        START_JUCE_APPLICATION (MyJUCEApp)
See also:
MessageManager

Constructor & Destructor Documentation

JUCEApplication::JUCEApplication (  ) [protected]

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.

virtual JUCEApplication::~JUCEApplication (  ) [virtual]

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* JUCEApplication::getInstance (  ) [static]

Returns the global instance of the application object being run.

virtual void JUCEApplication::initialise ( const String commandLineParameters ) [pure virtual]

Called when the application starts.

This will be called once to let the application do whatever initialisation it needs, create its windows, etc.

After the method returns, the normal event-dispatch loop will be run, until the quit() method is called, at which point the shutdown() method will be called to let the application clear up anything it needs to delete.

If during the initialise() method, the application decides not to start-up after all, it can just call the quit() method and the event loop won't be run.

Parameters:
commandLineParametersthe line passed in does not include the name of the executable, just the parameter list.
See also:
shutdown, quit
bool JUCEApplication::isInitialising (  ) const

Returns true if the application hasn't yet completed its initialise() method and entered the main event loop.

This is handy for things like splash screens to know when the app's up-and-running properly.

virtual void JUCEApplication::shutdown (  ) [pure virtual]
virtual const String JUCEApplication::getApplicationName (  ) [pure virtual]

Returns the application's name.

An application must implement this to name itself.

virtual const String JUCEApplication::getApplicationVersion (  ) [pure virtual]

Returns the application's version number.

virtual bool JUCEApplication::moreThanOneInstanceAllowed (  ) [virtual]

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 the Mac where this isn't possible).

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.

virtual void JUCEApplication::anotherInstanceStarted ( const String commandLine ) [virtual]

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

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

virtual void JUCEApplication::systemRequestedQuit (  ) [virtual]

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.

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

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.

static void JUCEApplication::quit (  ) [static]

Signals that the main message loop should stop and the application should terminate.

This isn't synchronous, it just posts a quit message to the main queue, and when this message arrives, the message loop will stop, the shutdown() method will be called, and the app will exit.

Note that this will cause an unconditional quit to happen, so if you need an extra level before this, e.g. to give the user the chance to save their work and maybe cancel the quit, you'll need to handle this in the systemRequestedQuit() method - see that method's help for more info.

See also:
MessageManager
void JUCEApplication::setApplicationReturnValue ( int  newReturnValue )

Sets the value that should be returned as the application's exit code when the app quits.

This is the value that's returned by the main() function. Normally you'd leave this as 0 unless you want to indicate an error code.

See also:
getApplicationReturnValue
int JUCEApplication::getApplicationReturnValue (  ) const

Returns the value that has been set as the application's exit code.

See also:
setApplicationReturnValue
const String& JUCEApplication::getCommandLineParameters (  ) const

Returns the application's command line parameters.

static bool JUCEApplication::isStandaloneApp (  ) [static]

Returns true if this executable is running as an app (as opposed to being a plugin or other kind of shared library.

ApplicationCommandTarget* JUCEApplication::getNextCommandTarget (  ) [virtual]

This must return the next target to try after this one.

When a command is being sent, and the first target can't handle that command, this method is used to determine the next target that should be tried.

It may return 0 if it doesn't know of another target.

If your target is a Component, you would usually use the findFirstTargetParentComponent() method to return a parent component that might want to handle it.

See also:
invoke

Implements ApplicationCommandTarget.

void JUCEApplication::getCommandInfo ( CommandID  commandID,
ApplicationCommandInfo result 
) [virtual]

This must provide details about one of the commands that this target can perform.

This will be called with one of the command IDs that the target provided in its getAllCommands() methods.

It should fill-in all appropriate fields of the ApplicationCommandInfo structure with suitable information about the command. (The commandID field will already have been filled-in by the caller).

The easiest way to set the info is using the ApplicationCommandInfo::setInfo() method to set all the fields at once.

If the command is currently inactive for some reason, this method must use ApplicationCommandInfo::setActive() to make that clear, (or it should set the isDisabled bit of the ApplicationCommandInfo::flags field).

Any default key-presses for the command should be appended to the ApplicationCommandInfo::defaultKeypresses field.

Note that if you change something that affects the status of the commands that would be returned by this method (e.g. something that makes some commands active or inactive), you should call ApplicationCommandManager::commandStatusChanged() to cause the manager to refresh its status.

Implements ApplicationCommandTarget.

void JUCEApplication::getAllCommands ( Array< CommandID > &  commands ) [virtual]

This must return a complete list of commands that this target can handle.

Your target should add all the command IDs that it handles to the array that is passed-in.

Implements ApplicationCommandTarget.

bool JUCEApplication::perform ( const InvocationInfo info ) [virtual]

This must actually perform the specified command.

If this target is able to perform the command specified by the commandID field of the InvocationInfo structure, then it should do so, and must return true.

If it can't handle this command, it should return false, which tells the caller to pass the command on to the next target in line.

See also:
invoke, ApplicationCommandManager::invoke

Implements ApplicationCommandTarget.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines