|
|
|
@@ -27,12 +27,11 @@ |
|
|
|
namespace juce
|
|
|
|
{
|
|
|
|
|
|
|
|
class Button::CallbackHelper : public Timer,
|
|
|
|
public ApplicationCommandManagerListener,
|
|
|
|
public Value::Listener,
|
|
|
|
public KeyListener
|
|
|
|
struct Button::CallbackHelper : public Timer,
|
|
|
|
public ApplicationCommandManagerListener,
|
|
|
|
public Value::Listener,
|
|
|
|
public KeyListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CallbackHelper (Button& b) : button (b) {}
|
|
|
|
|
|
|
|
void timerCallback() override
|
|
|
|
@@ -48,7 +47,7 @@ public: |
|
|
|
void valueChanged (Value& value) override
|
|
|
|
{
|
|
|
|
if (value.refersToSameSourceAs (button.isOn))
|
|
|
|
button.setToggleState (button.isOn.getValue(), sendNotification);
|
|
|
|
button.setToggleState (button.isOn.getValue(), dontSendNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool keyPressed (const KeyPress&, Component*) override
|
|
|
|
@@ -69,7 +68,6 @@ public: |
|
|
|
button.applicationCommandListChangeCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Button& button;
|
|
|
|
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CallbackHelper)
|
|
|
|
@@ -78,7 +76,7 @@ private: |
|
|
|
//==============================================================================
|
|
|
|
Button::Button (const String& name) : Component (name), text (name)
|
|
|
|
{
|
|
|
|
callbackHelper = new CallbackHelper (*this);
|
|
|
|
callbackHelper.reset (new CallbackHelper (*this));
|
|
|
|
|
|
|
|
setWantsKeyboardFocus (true);
|
|
|
|
isOn.addListener (callbackHelper);
|
|
|
|
@@ -115,14 +113,12 @@ void Button::updateAutomaticTooltip (const ApplicationCommandInfo& info) |
|
|
|
{
|
|
|
|
if (generateTooltip && commandManagerToUse != nullptr)
|
|
|
|
{
|
|
|
|
String tt (info.description.isNotEmpty() ? info.description
|
|
|
|
: info.shortName);
|
|
|
|
auto tt = info.description.isNotEmpty() ? info.description
|
|
|
|
: info.shortName;
|
|
|
|
|
|
|
|
Array<KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
|
|
|
|
|
|
|
|
for (int i = 0; i < keyPresses.size(); ++i)
|
|
|
|
for (auto& kp : commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID))
|
|
|
|
{
|
|
|
|
const String key (keyPresses.getReference(i).getTextDescription());
|
|
|
|
auto key = kp.getTextDescription();
|
|
|
|
|
|
|
|
tt << " [";
|
|
|
|
|
|
|
|
@@ -303,7 +299,7 @@ void Button::buttonStateChanged() {} |
|
|
|
|
|
|
|
uint32 Button::getMillisecondsSinceButtonDown() const noexcept
|
|
|
|
{
|
|
|
|
const uint32 now = Time::getApproximateMillisecondCounter();
|
|
|
|
auto now = Time::getApproximateMillisecondCounter();
|
|
|
|
return now > buttonPressTime ? now - buttonPressTime : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -457,7 +453,7 @@ void Button::mouseUp (const MouseEvent& e) |
|
|
|
|
|
|
|
void Button::mouseDrag (const MouseEvent& e)
|
|
|
|
{
|
|
|
|
const ButtonState oldState = buttonState;
|
|
|
|
auto oldState = buttonState;
|
|
|
|
updateState (isMouseOrTouchOver (e), true);
|
|
|
|
|
|
|
|
if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
|
|
|
|
@@ -492,7 +488,7 @@ void Button::visibilityChanged() |
|
|
|
|
|
|
|
void Button::parentHierarchyChanged()
|
|
|
|
{
|
|
|
|
Component* const newKeySource = (shortcuts.size() == 0) ? nullptr : getTopLevelComponent();
|
|
|
|
auto* newKeySource = shortcuts.isEmpty() ? nullptr : getTopLevelComponent();
|
|
|
|
|
|
|
|
if (newKeySource != keySource.get())
|
|
|
|
{
|
|
|
|
@@ -576,8 +572,8 @@ void Button::clearShortcuts() |
|
|
|
bool Button::isShortcutPressed() const
|
|
|
|
{
|
|
|
|
if (isShowing() && ! isCurrentlyBlockedByAnotherModalComponent())
|
|
|
|
for (int i = shortcuts.size(); --i >= 0;)
|
|
|
|
if (shortcuts.getReference(i).isCurrentlyDown())
|
|
|
|
for (auto& s : shortcuts)
|
|
|
|
if (s.isCurrentlyDown())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
@@ -585,8 +581,8 @@ bool Button::isShortcutPressed() const |
|
|
|
|
|
|
|
bool Button::isRegisteredForShortcut (const KeyPress& key) const
|
|
|
|
{
|
|
|
|
for (int i = shortcuts.size(); --i >= 0;)
|
|
|
|
if (key == shortcuts.getReference(i))
|
|
|
|
for (auto& s : shortcuts)
|
|
|
|
if (key == s)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
@@ -647,11 +643,11 @@ void Button::repeatTimerCallback() |
|
|
|
}
|
|
|
|
else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState() == buttonDown)))
|
|
|
|
{
|
|
|
|
int repeatSpeed = autoRepeatSpeed;
|
|
|
|
auto repeatSpeed = autoRepeatSpeed;
|
|
|
|
|
|
|
|
if (autoRepeatMinimumDelay >= 0)
|
|
|
|
{
|
|
|
|
double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
|
|
|
|
auto timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
|
|
|
|
timeHeldDown *= timeHeldDown;
|
|
|
|
|
|
|
|
repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
|
|
|
|
@@ -659,7 +655,7 @@ void Button::repeatTimerCallback() |
|
|
|
|
|
|
|
repeatSpeed = jmax (1, repeatSpeed);
|
|
|
|
|
|
|
|
const uint32 now = Time::getMillisecondCounter();
|
|
|
|
auto now = Time::getMillisecondCounter();
|
|
|
|
|
|
|
|
// if we've been blocked from repeating often enough, speed up the repeat timer to compensate..
|
|
|
|
if (lastRepeatTime != 0 && (int) (now - lastRepeatTime) > repeatSpeed * 2)
|
|
|
|
|