1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Got rid of the nasty general-purpose ints and void*s that were in the Message class. Instead of using a plain old Message class, just create a subclass which contains whatever data you need in a more meaningful format.

This commit is contained in:
Julian Storer 2011-09-22 15:34:10 +01:00
parent 6e82a92d07
commit 5224a3d9b8
10 changed files with 106 additions and 152 deletions

View file

@ -25,6 +25,41 @@
BEGIN_JUCE_NAMESPACE
//==============================================================================
class ApplicationCommandTarget::MessageTarget : public MessageListener
{
public:
MessageTarget (ApplicationCommandTarget& owner_)
: owner (owner_)
{
}
void handleMessage (const Message& message)
{
jassert (dynamic_cast <const InvokedMessage*> (&message) != nullptr);
owner.tryToInvoke (dynamic_cast <const InvokedMessage&> (message).info, false);
}
struct InvokedMessage : public Message
{
InvokedMessage (const InvocationInfo& info_)
: info (info_)
{}
const InvocationInfo info;
private:
JUCE_DECLARE_NON_COPYABLE (InvokedMessage);
};
private:
ApplicationCommandTarget& owner;
JUCE_DECLARE_NON_COPYABLE (MessageTarget);
};
//==============================================================================
ApplicationCommandTarget::ApplicationCommandTarget()
{
@ -43,9 +78,9 @@ bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bo
if (async)
{
if (messageInvoker == nullptr)
messageInvoker = new CommandTargetMessageInvoker (this);
messageInvoker = new MessageTarget (*this);
messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
messageInvoker->postMessage (new MessageTarget::InvokedMessage (info));
return true;
}
else
@ -174,21 +209,5 @@ ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID comman
{
}
//==============================================================================
ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
: owner (owner_)
{
}
ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
{
}
void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
{
const ScopedPointer <InvocationInfo> info (static_cast <InvocationInfo*> (message.pointerParameter));
owner->tryToInvoke (*info, false);
}
END_JUCE_NAMESPACE

View file

@ -234,24 +234,11 @@ public:
private:
//==============================================================================
// (for async invocation of commands)
class CommandTargetMessageInvoker : public MessageListener
{
public:
CommandTargetMessageInvoker (ApplicationCommandTarget* owner);
~CommandTargetMessageInvoker();
class MessageTarget;
friend class MessageTarget;
friend class ScopedPointer<MessageTarget>;
ScopedPointer<MessageTarget> messageInvoker;
void handleMessage (const Message& message);
private:
ApplicationCommandTarget* const owner;
JUCE_DECLARE_NON_COPYABLE (CommandTargetMessageInvoker);
};
ScopedPointer <CommandTargetMessageInvoker> messageInvoker;
friend class CommandTargetMessageInvoker;
bool tryToInvoke (const InvocationInfo& info, bool async);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationCommandTarget);