38 button.repeatTimerCallback();
43 return button.keyStateChangedCallback();
55 return button.isShortcutPressed();
62 button.flashButtonState();
67 button.applicationCommandListChangeCallback();
88 if (commandManagerToUse !=
nullptr)
92 callbackHelper.reset();
108 generateTooltip =
false;
113 if (generateTooltip && commandManagerToUse !=
nullptr)
118 for (
auto&
kp : commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID))
120 auto key =
kp.getTextDescription();
124 if (key.length() == 1)
125 tt <<
TRANS (
"shortcut") <<
": '" << key <<
"']";
227 jassert (commandManagerToUse ==
nullptr || ! clickTogglesState);
248 if (radioGroupId != 0)
256 if (
auto b =
dynamic_cast<Button*
> (c))
258 if (b->getRadioGroupId() == radioGroupId)
290 if ((
down && (
over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
307 if (buttonState == buttonDown)
325 return now > buttonPressTime ? now - buttonPressTime : 0;
335 return triggerOnMouseDown;
348enum { clickMessageId = 0x2f3f4f99 };
357 if (clickTogglesState)
359 const bool shouldBeOn = (radioGroupId != 0 || ! lastToggleState);
371void Button::flashButtonState()
375 needsToRelease =
true;
377 callbackHelper->startTimer (100);
405 if (commandManagerToUse !=
nullptr && commandID != 0)
409 info.originatingComponent =
this;
411 commandManagerToUse->
invoke (info,
true);
419 buttonListeners.callChecked (
checker, [
this] (Listener&
l) {
l.buttonClicked (
this); });
424 NullCheckedInvocation::invoke (
onClick);
427void Button::sendStateMessage()
429 Component::BailOutChecker
checker (
this);
436 buttonListeners.callChecked (
checker, [
this] (
Listener&
l) {
l.buttonStateChanged (
this); });
449 needsToRelease =
false;
450 needsRepainting =
true;
454 lastStatePainted = buttonState;
463 updateState (
true,
true);
467 if (autoRepeatDelay >= 0)
468 callbackHelper->startTimer (autoRepeatDelay);
470 if (triggerOnMouseDown)
471 internalClickCallback (e.
mods);
479 updateState (isMouseSourceOver (e),
false);
483 if (lastStatePainted != buttonDown)
488 internalClickCallback (e.
mods);
491 updateState (isMouseSourceOver (e),
false);
498 updateState (isMouseSourceOver (e),
true);
501 callbackHelper->startTimer (autoRepeatSpeed);
504bool Button::isMouseSourceOver (
const MouseEvent& e)
526 needsToRelease =
false;
536 if (keySource !=
nullptr)
537 keySource->removeKeyListener (callbackHelper.get());
541 if (keySource !=
nullptr)
542 keySource->addKeyListener (callbackHelper.get());
555 if (commandManagerToUse !=
nullptr)
560 if (commandManagerToUse !=
nullptr)
561 commandManagerToUse->
addListener (callbackHelper.get());
567 jassert (commandManagerToUse ==
nullptr || ! clickTogglesState);
570 if (commandManagerToUse !=
nullptr)
571 applicationCommandListChangeCallback();
576void Button::applicationCommandListChangeCallback()
578 if (commandManagerToUse !=
nullptr)
584 updateAutomaticTooltip (info);
613bool Button::isShortcutPressed()
const
616 for (
auto& s : shortcuts)
617 if (s.isCurrentlyDown())
625 for (
auto& s : shortcuts)
632bool Button::keyStateChangedCallback()
637 const bool wasDown = isKeyDown;
638 isKeyDown = isShortcutPressed();
640 if (autoRepeatDelay >= 0 && (isKeyDown && !
wasDown))
641 callbackHelper->startTimer (autoRepeatDelay);
670 int minimumDelayInMillisecs)
noexcept
674 autoRepeatMinimumDelay =
jmin (autoRepeatSpeed, minimumDelayInMillisecs);
677void Button::repeatTimerCallback()
681 callbackHelper->stopTimer();
683 needsRepainting =
false;
685 else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState() == buttonDown)))
689 if (autoRepeatMinimumDelay >= 0)
702 if (lastRepeatTime != 0 && (
int) (now - lastRepeatTime) >
repeatSpeed * 2)
705 lastRepeatTime = now;
710 else if (! needsToRelease)
712 callbackHelper->stopTimer();
718 return std::make_unique<detail::ButtonAccessibilityHandler> (*
this, AccessibilityRole::button);
A listener that receives callbacks from an ApplicationCommandManager when commands are invoked or the...
One of these objects holds a list of all the commands your app can perform, and despatches these comm...
void addListener(ApplicationCommandManagerListener *listener)
Registers a listener that will be called when various events occur.
ApplicationCommandTarget * getTargetForCommand(CommandID commandID, ApplicationCommandInfo &upToDateInfo)
Tries to find the best target to use to perform a given command.
bool invoke(const ApplicationCommandTarget::InvocationInfo &invocationInfo, bool asynchronously)
Sends a command to the default target.
void removeListener(ApplicationCommandManagerListener *listener)
Deregisters a previously-added listener.
A class to keep an eye on a component and check for it being deleted.
The base class for all JUCE user-interface objects.
bool isMouseButtonDown(bool includeChildren=false) const
Returns true if the mouse button is currently held down in this component.
Component * getTopLevelComponent() const noexcept
Returns the highest-level component which contains this one or its parents.
bool isVisible() const noexcept
Tests whether the component is visible or not.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
bool isShowing() const
Tests whether this component and all its parents are visible.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
bool isCurrentlyBlockedByAnotherModalComponent() const
Checks whether there's a modal component somewhere that's stopping this one from receiving messages.
AccessibilityHandler * getAccessibilityHandler()
Returns the accessibility handler for this component, or nullptr if this component is not accessible.
void postCommandMessage(int commandId)
Dispatches a numbered message to this component.
void setEnabled(bool shouldBeEnabled)
Enables or disables this component.
void repaint()
Marks the whole component as needing to be redrawn.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
bool isMouseOver(bool includeChildren=false) const
Returns true if the mouse is currently over this component.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
const Array< Component * > & getChildren() const noexcept
Provides access to the underlying array of child components.
void invalidateAccessibilityHandler()
Invalidates the AccessibilityHandler that is currently being used for this component.
virtual void handleCommandMessage(int commandId)
Called to handle a command that was sent by postCommandMessage().
A graphics context, used for drawing a component or image.
Receives callbacks when keys are pressed.
Represents a key press, including any modifier keys that are needed.
bool isKeyCode(int keyCodeToCompare) const noexcept
Checks whether the KeyPress's key is the same as the one provided, without checking the modifiers.
bool isValid() const noexcept
Returns true if this is a valid KeyPress.
static const int returnKey
key-code for the return key
Represents the state of the mouse buttons and modifier keys.
static ModifierKeys currentModifiers
This object represents the last-known state of the keyboard and mouse buttons.
Contains position and status information about a mouse event.
const ModifierKeys mods
The key modifiers associated with the event.
MouseInputSource source
The source device that generated this event.
const Point< float > position
The position of the mouse when the event occurred.
Rectangle< float > toFloat() const noexcept
Casts this rectangle to a Rectangle<float>.
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Returns true if this coordinate is inside the rectangle.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
static uint32 getApproximateMillisecondCounter() noexcept
Less-accurate but faster version of getMillisecondCounter().
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
Makes repeated callbacks to a virtual method at a specified time interval.
Receives callbacks when a Value object changes.
Represents a shared variant value.
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
void removeListener(Listener *listener)
Removes a listener that was previously added with addListener().
bool refersToSameSourceAs(const Value &other) const
Returns true if this object and the other one use the same underlying ValueSource object.
var getValue() const
Returns the current value.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
@ valueChanged
Indicates that the UI element's value has changed.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
@ sendNotificationAsync
Requests an asynchronous notification.
@ sendNotification
Requests a notification message, either synchronous or not.
@ dontSendNotification
No notification message should be sent.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
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.
String description
A longer description of the command.
@ isTicked
Indicates that the command should have a tick next to it on a menu.
@ dontTriggerVisualFeedback
If this flag is present and the command is invoked from a keypress, then any buttons or menus that ar...
@ isDisabled
Indicates that the command can't currently be performed.
String shortName
A short name to describe the command.
Contains contextual details about the invocation of a command.
@ fromButton
The command is being invoked by a button click.
int commandFlags
The command's flags.
CommandID commandID
The UID of the command that should be performed.