JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ApplicationCommandTarget.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
31public:
33 : owner (target), info (inf)
34 {
35 }
36
37 void messageCallback() override
38 {
39 if (ApplicationCommandTarget* const target = owner)
40 target->tryToInvoke (info, false);
41 }
42
43private:
45 const InvocationInfo info;
46
48};
49
50//==============================================================================
53
54//==============================================================================
55bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
56{
57 if (isCommandActive (info.commandID))
58 {
59 if (async)
60 {
61 (new CommandMessage (this, info))->post();
62 return true;
63 }
64
65 if (perform (info))
66 return true;
67
68 // Hmm.. your target claimed that it could perform this command, but failed to do so.
69 // If it can't do it at the moment for some reason, it should clear the 'isActive' flag
70 // when it returns the command's info.
72 }
73
74 return false;
75}
76
78{
79 if (Component* const c = dynamic_cast<Component*> (this))
80 return c->findParentComponentOfClass<ApplicationCommandTarget>();
81
82 return nullptr;
83}
84
86{
87 ApplicationCommandTarget* target = this;
88 int depth = 0;
89
90 while (target != nullptr)
91 {
93 target->getAllCommands (commandIDs);
94
95 if (commandIDs.contains (commandID))
96 return target;
97
98 target = target->getNextCommandTarget();
99
100 ++depth;
101 jassert (depth < 100); // could be a recursive command chain??
102 jassert (target != this); // definitely a recursive command chain!
103
104 if (depth > 100 || target == this)
105 break;
106 }
107
108 if (target == nullptr)
109 {
111
112 if (target != nullptr)
113 {
115 target->getAllCommands (commandIDs);
116
117 if (commandIDs.contains (commandID))
118 return target;
119 }
120 }
121
122 return nullptr;
123}
124
126{
127 ApplicationCommandInfo info (commandID);
129
130 getCommandInfo (commandID, info);
131
132 return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
133}
134
135//==============================================================================
136bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
137{
138 ApplicationCommandTarget* target = this;
139 int depth = 0;
140
141 while (target != nullptr)
142 {
143 if (target->tryToInvoke (info, async))
144 return true;
145
146 target = target->getNextCommandTarget();
147
148 ++depth;
149 jassert (depth < 100); // could be a recursive command chain??
150 jassert (target != this); // definitely a recursive command chain!
151
152 if (depth > 100 || target == this)
153 break;
154 }
155
156 if (target == nullptr)
157 {
159
160 if (target != nullptr)
161 return target->tryToInvoke (info, async);
162 }
163
164 return false;
165}
166
174
175//==============================================================================
176ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID command)
177 : commandID (command),
178 commandFlags (0),
179 invocationMethod (direct),
180 originatingComponent (nullptr),
181 isKeyDown (false),
182 millisecsSinceKeyPressed (0)
183{
184}
185
186} // namespace juce
A command target publishes a list of command IDs that it can perform.
ApplicationCommandTarget * getTargetForCommand(CommandID commandID)
Searches this target and all subsequent ones for the first one that can handle the specified command.
ApplicationCommandTarget()
Creates a command target.
bool isCommandActive(CommandID commandID)
Checks whether this command can currently be performed by this target.
virtual ApplicationCommandTarget * getNextCommandTarget()=0
This must return the next target to try after this one.
virtual void getCommandInfo(CommandID commandID, ApplicationCommandInfo &result)=0
This must provide details about one of the commands that this target can perform.
virtual void getAllCommands(Array< CommandID > &commands)=0
This must return a complete list of commands that this target can handle.
bool invokeDirectly(CommandID commandID, bool asynchronously)
Invokes a given command directly on this target.
virtual bool perform(const InvocationInfo &info)=0
This must actually perform the specified command.
ApplicationCommandTarget * findFirstTargetParentComponent()
If this object is a Component, this method will search upwards in its current UI hierarchy for the ne...
bool invoke(const InvocationInfo &invocationInfo, bool asynchronously)
Makes this target invoke a command.
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
The base class for all JUCE user-interface objects.
static JUCEApplication *JUCE_CALLTYPE getInstance() noexcept
Returns the global instance of the application object being run.
Internal class used as the base class for all message objects.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
int CommandID
A type used to hold the unique ID for an application command.
Holds information describing an application command.
int flags
A bitwise-OR of the values specified in the CommandFlags enum.
@ isDisabled
Indicates that the command can't currently be performed.
Contains contextual details about the invocation of a command.
InvocationMethod invocationMethod
The type of event that triggered this command.
@ direct
The command is being invoked directly by a piece of code.