Browse Source

tags/2021-05-28
jules 18 years ago
parent
commit
e4304ef483
5 changed files with 58 additions and 54 deletions
  1. +12
    -22
      src/juce_appframework/application/juce_Application.cpp
  2. +7
    -3
      src/juce_appframework/application/juce_Application.h
  3. +14
    -13
      src/juce_appframework/gui/components/keyboard/juce_KeyPressMappingSet.cpp
  4. +11
    -11
      src/juce_appframework/gui/components/keyboard/juce_KeyPressMappingSet.h
  5. +14
    -5
      src/juce_core/threads/juce_Thread.cpp

+ 12
- 22
src/juce_appframework/application/juce_Application.cpp View File

@@ -68,12 +68,12 @@ JUCEApplication::~JUCEApplication()
{ {
} }
JUCEApplication* JUCEApplication::getInstance()
JUCEApplication* JUCEApplication::getInstance() throw()
{ {
return appInstance; return appInstance;
} }
bool JUCEApplication::isInitialising() const
bool JUCEApplication::isInitialising() const throw()
{ {
return stillInitialising; return stillInitialising;
} }
@@ -155,20 +155,6 @@ bool JUCEApplication::perform (const InvocationInfo& info)
} }
//============================================================================== //==============================================================================
// used as a listener object later on..
class NewAppListener : public ActionListener
{
public:
void actionListenerCallback (const String& message)
{
if (message.startsWith (appInstance->getApplicationName() + T("/")))
{
appInstance->anotherInstanceStarted (message.fromFirstOccurrenceOf (T("/"),
false, false));
}
}
};
int JUCEApplication::main (String& commandLine, JUCEApplication* const app) int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
{ {
jassert (appInstance == 0); jassert (appInstance == 0);
@@ -185,8 +171,7 @@ int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
if (! appLock->enter(0)) if (! appLock->enter(0))
{ {
MessageManager::broadcastMessage (app->getApplicationName()
+ T("/") + commandLine);
MessageManager::broadcastMessage (app->getApplicationName() + "/" + commandLine);
delete appInstance; delete appInstance;
appInstance = 0; appInstance = 0;
@@ -207,16 +192,14 @@ int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
commandLine = String::empty; commandLine = String::empty;
// register for broadcast new app messages // register for broadcast new app messages
NewAppListener* const newAppListener = new NewAppListener();
MessageManager::getInstance()->registerBroadcastListener (newAppListener);
MessageManager::getInstance()->registerBroadcastListener (app);
app->stillInitialising = false; app->stillInitialising = false;
// now loop until a quit message is received.. // now loop until a quit message is received..
useForce = MessageManager::getInstance()->runDispatchLoop(); useForce = MessageManager::getInstance()->runDispatchLoop();
delete newAppListener;
MessageManager::getInstance()->deregisterBroadcastListener (app);
if (appLock != 0) if (appLock != 0)
{ {
@@ -297,6 +280,13 @@ int JUCEApplication::main (int argc, char* argv[],
return JUCEApplication::main (cmd, newApp); return JUCEApplication::main (cmd, newApp);
} }
void JUCEApplication::actionListenerCallback (const String& message)
{
if (message.startsWith (getApplicationName() + "/"))
{
anotherInstanceStarted (message.fromFirstOccurrenceOf (T("/"), false, false));
}
}
//============================================================================== //==============================================================================
static bool juceInitialisedGUI = false; static bool juceInitialisedGUI = false;


+ 7
- 3
src/juce_appframework/application/juce_Application.h View File

@@ -33,6 +33,7 @@
#define __JUCE_APPLICATION_JUCEHEADER__ #define __JUCE_APPLICATION_JUCEHEADER__
#include "juce_ApplicationCommandTarget.h" #include "juce_ApplicationCommandTarget.h"
#include "../events/juce_ActionListener.h"
//============================================================================== //==============================================================================
@@ -103,7 +104,8 @@
@see MessageManager, DeletedAtShutdown @see MessageManager, DeletedAtShutdown
*/ */
class JUCE_API JUCEApplication : public ApplicationCommandTarget
class JUCE_API JUCEApplication : public ApplicationCommandTarget,
private ActionListener
{ {
protected: protected:
//============================================================================== //==============================================================================
@@ -126,7 +128,7 @@ public:
//============================================================================== //==============================================================================
/** Returns the global instance of the application object being run. */ /** Returns the global instance of the application object being run. */
static JUCEApplication* getInstance();
static JUCEApplication* getInstance() throw();
//============================================================================== //==============================================================================
/** Called when the application starts. /** Called when the application starts.
@@ -154,7 +156,7 @@ public:
This is handy for things like splash screens to know when the app's up-and-running This is handy for things like splash screens to know when the app's up-and-running
properly. properly.
*/ */
bool isInitialising() const;
bool isInitialising() const throw();
/* Called to allow the application to clear up before exiting. /* Called to allow the application to clear up before exiting.
@@ -269,6 +271,8 @@ public:
void getAllCommands (Array <CommandID>& commands); void getAllCommands (Array <CommandID>& commands);
/** @internal */ /** @internal */
bool perform (const InvocationInfo& info); bool perform (const InvocationInfo& info);
/** @internal */
void actionListenerCallback (const String& message);
private: private:
//============================================================================== //==============================================================================


+ 14
- 13
src/juce_appframework/gui/components/keyboard/juce_KeyPressMappingSet.cpp View File

@@ -39,7 +39,7 @@ BEGIN_JUCE_NAMESPACE
//============================================================================== //==============================================================================
KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_)
KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
: commandManager (commandManager_) : commandManager (commandManager_)
{ {
// A manager is needed to get the descriptions of commands, and will be called when // A manager is needed to get the descriptions of commands, and will be called when
@@ -49,7 +49,7 @@ KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const command
Desktop::getInstance().addFocusChangeListener (this); Desktop::getInstance().addFocusChangeListener (this);
} }
KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other)
KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
: commandManager (other.commandManager) : commandManager (other.commandManager)
{ {
Desktop::getInstance().addFocusChangeListener (this); Desktop::getInstance().addFocusChangeListener (this);
@@ -72,7 +72,7 @@ const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const
void KeyPressMappingSet::addKeyPress (const CommandID commandID, void KeyPressMappingSet::addKeyPress (const CommandID commandID,
const KeyPress& newKeyPress, const KeyPress& newKeyPress,
int insertIndex)
int insertIndex) throw()
{ {
if (findCommandForKeyPress (newKeyPress) != commandID) if (findCommandForKeyPress (newKeyPress) != commandID)
{ {
@@ -107,7 +107,7 @@ void KeyPressMappingSet::addKeyPress (const CommandID commandID,
} }
} }
void KeyPressMappingSet::resetToDefaultMappings()
void KeyPressMappingSet::resetToDefaultMappings() throw()
{ {
mappings.clear(); mappings.clear();
@@ -125,7 +125,7 @@ void KeyPressMappingSet::resetToDefaultMappings()
sendChangeMessage (this); sendChangeMessage (this);
} }
void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
{ {
clearAllKeyPresses (commandID); clearAllKeyPresses (commandID);
@@ -138,15 +138,16 @@ void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
} }
} }
void KeyPressMappingSet::clearAllKeyPresses()
void KeyPressMappingSet::clearAllKeyPresses() throw()
{ {
if (mappings.size() > 0) if (mappings.size() > 0)
{
sendChangeMessage (this); sendChangeMessage (this);
mappings.clear();
mappings.clear();
}
} }
void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
{ {
for (int i = mappings.size(); --i >= 0;) for (int i = mappings.size(); --i >= 0;)
{ {
@@ -158,7 +159,7 @@ void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
} }
} }
void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
{ {
if (keypress.isValid()) if (keypress.isValid())
{ {
@@ -179,7 +180,7 @@ void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
} }
void KeyPressMappingSet::removeKeyPress (const CommandID commandID, void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
const int keyPressIndex)
const int keyPressIndex) throw()
{ {
for (int i = mappings.size(); --i >= 0;) for (int i = mappings.size(); --i >= 0;)
{ {
@@ -193,7 +194,7 @@ void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
} }
//============================================================================== //==============================================================================
CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const
CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
{ {
for (int i = 0; i < mappings.size(); ++i) for (int i = 0; i < mappings.size(); ++i)
if (mappings.getUnchecked(i)->keypresses.contains (keyPress)) if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
@@ -203,7 +204,7 @@ CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress)
} }
bool KeyPressMappingSet::containsMapping (const CommandID commandID, bool KeyPressMappingSet::containsMapping (const CommandID commandID,
const KeyPress& keyPress) const
const KeyPress& keyPress) const throw()
{ {
for (int i = mappings.size(); --i >= 0;) for (int i = mappings.size(); --i >= 0;)
if (mappings.getUnchecked(i)->commandID == commandID) if (mappings.getUnchecked(i)->commandID == commandID)


+ 11
- 11
src/juce_appframework/gui/components/keyboard/juce_KeyPressMappingSet.h View File

@@ -113,10 +113,10 @@ public:
@see ApplicationCommandManager @see ApplicationCommandManager
*/ */
KeyPressMappingSet (ApplicationCommandManager* const commandManager);
KeyPressMappingSet (ApplicationCommandManager* const commandManager) throw();
/** Creates an copy of a KeyPressMappingSet. */ /** Creates an copy of a KeyPressMappingSet. */
KeyPressMappingSet (const KeyPressMappingSet& other);
KeyPressMappingSet (const KeyPressMappingSet& other) throw();
/** Destructor. */ /** Destructor. */
~KeyPressMappingSet(); ~KeyPressMappingSet();
@@ -146,25 +146,25 @@ public:
*/ */
void addKeyPress (const CommandID commandID, void addKeyPress (const CommandID commandID,
const KeyPress& newKeyPress, const KeyPress& newKeyPress,
int insertIndex = -1);
int insertIndex = -1) throw();
/** Reset all mappings to the defaults, as dictated by the ApplicationCommandManager. /** Reset all mappings to the defaults, as dictated by the ApplicationCommandManager.
@see resetToDefaultMapping @see resetToDefaultMapping
*/ */
void resetToDefaultMappings();
void resetToDefaultMappings() throw();
/** Resets all key-mappings to the defaults for a particular command. /** Resets all key-mappings to the defaults for a particular command.
@see resetToDefaultMappings @see resetToDefaultMappings
*/ */
void resetToDefaultMapping (const CommandID commandID);
void resetToDefaultMapping (const CommandID commandID) throw();
/** Removes all keypresses that are assigned to any commands. */ /** Removes all keypresses that are assigned to any commands. */
void clearAllKeyPresses();
void clearAllKeyPresses() throw();
/** Removes all keypresses that are assigned to a particular command. */ /** Removes all keypresses that are assigned to a particular command. */
void clearAllKeyPresses (const CommandID commandID);
void clearAllKeyPresses (const CommandID commandID) throw();
/** Removes one of the keypresses that are assigned to a command. /** Removes one of the keypresses that are assigned to a command.
@@ -172,22 +172,22 @@ public:
which the keyPressIndex refers. which the keyPressIndex refers.
*/ */
void removeKeyPress (const CommandID commandID, void removeKeyPress (const CommandID commandID,
const int keyPressIndex);
const int keyPressIndex) throw();
/** Removes a keypress from any command that it may be assigned to. /** Removes a keypress from any command that it may be assigned to.
*/ */
void removeKeyPress (const KeyPress& keypress);
void removeKeyPress (const KeyPress& keypress) throw();
/** Returns true if the given command is linked to this key. */ /** Returns true if the given command is linked to this key. */
bool containsMapping (const CommandID commandID, bool containsMapping (const CommandID commandID,
const KeyPress& keyPress) const;
const KeyPress& keyPress) const throw();
//============================================================================== //==============================================================================
/** Looks for a command that corresponds to a keypress. /** Looks for a command that corresponds to a keypress.
@returns the UID of the command or 0 if none was found @returns the UID of the command or 0 if none was found
*/ */
CommandID findCommandForKeyPress (const KeyPress& keyPress) const;
CommandID findCommandForKeyPress (const KeyPress& keyPress) const throw();
//============================================================================== //==============================================================================
/** Tries to recreate the mappings from a previously stored state. /** Tries to recreate the mappings from a previously stored state.


+ 14
- 5
src/juce_core/threads/juce_Thread.cpp View File

@@ -259,16 +259,25 @@ Thread* Thread::getCurrentThread() throw()
return result; return result;
} }
void Thread::stopAllThreads (const int timeoutInMillisecs) throw()
void Thread::stopAllThreads (const int timeOutMilliseconds) throw()
{ {
while (getNumRunningThreads() > 0)
runningThreadsLock.enter();
for (int i = runningThreads.size(); --i >= 0;)
((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
runningThreadsLock.exit();
for (;;)
{ {
runningThreadsLock.enter(); runningThreadsLock.enter();
Thread* const r = (Thread*) runningThreads[0];
Thread* const t = (Thread*) runningThreads[0];
runningThreadsLock.exit(); runningThreadsLock.exit();
if (r != 0)
r->stopThread (timeoutInMillisecs);
if (t == 0)
break;
t->stopThread (timeOutMilliseconds);
} }
} }


Loading…
Cancel
Save