39 const String& getName()
const noexcept {
return name; }
49 AccessibilityRole::menuItem,
50 getAccessibilityActions (item)),
55 String getTitle()
const override {
return itemComponent.name; }
60 auto showMenu = [&item] { item.owner.
showMenu (item.owner.indexOfItemComponent (&item)); };
63 [&item] { item.owner.setItemUnderMouse (item.owner.indexOfItemComponent (&item)); })
64 .addAction (AccessibilityActionType::press,
showMenu)
71 return std::make_unique<ComponentHandler> (*
this);
102 if (model !=
nullptr)
107 if (model !=
nullptr)
122 if (model ==
nullptr)
125 for (
size_t i = 0; i < itemComponents.size(); ++i)
127 const auto& itemComponent = itemComponents[i];
128 const auto itemBounds = itemComponent->getBounds();
139 itemComponent->getName(),
140 (
int) i == itemUnderMouse,
141 (
int) i == currentPopupIndex,
151 for (
size_t i = 0; i < itemComponents.size(); ++i)
153 auto& itemComponent = itemComponents[i];
155 auto w =
getLookAndFeel().getMenuBarItemWidth (*
this, (
int) i, itemComponent->getName());
156 itemComponent->setBounds (x, 0, w,
getHeight());
163 for (
size_t i = 0; i < itemComponents.size(); ++i)
170void MenuBarComponent::repaintMenuItem (
int index)
183void MenuBarComponent::setItemUnderMouse (
int index)
185 if (itemUnderMouse == index)
188 repaintMenuItem (itemUnderMouse);
189 itemUnderMouse = index;
190 repaintMenuItem (itemUnderMouse);
194 handler->grabFocus();
197void MenuBarComponent::setOpenItem (
int index)
199 if (currentPopupIndex != index)
202 model->handleMenuBarActivate (
true);
203 else if (currentPopupIndex >= 0 && index < 0)
204 model->handleMenuBarActivate (
false);
206 repaintMenuItem (currentPopupIndex);
207 currentPopupIndex = index;
208 repaintMenuItem (currentPopupIndex);
213 desktop.addGlobalMouseListener (
this);
215 desktop.removeGlobalMouseListener (
this);
219void MenuBarComponent::updateItemUnderMouse (Point<int> p)
221 setItemUnderMouse (getItemAt (p));
226 if (index == currentPopupIndex)
238 setItemUnderMouse (index);
242 const auto& itemComponent = itemComponents[(
size_t) index];
243 auto m = model->
getMenuForIndex (itemUnderMouse, itemComponent->getName());
245 if (m.lookAndFeel ==
nullptr)
253 ref->menuDismissed (index, result);
263void MenuBarComponent::menuDismissed (
int topLevelIndex,
int itemId)
274 if (numActiveMenus == 0)
296 if (currentPopupIndex < 0)
300 currentPopupIndex = -2;
317 updateItemUnderMouse (
e2.getPosition());
330 if (lastMousePos !=
e2.getPosition())
332 if (currentPopupIndex >= 0)
334 const auto item = getItemAt (
e2.getPosition());
341 updateItemUnderMouse (
e2.getPosition());
344 lastMousePos =
e2.getPosition();
376 if (model !=
nullptr)
381 if ((
int) itemComponents.size() !=
newNames.size())
384 for (
size_t i = 0; i < itemComponents.size(); ++i)
402 itemComponents.clear();
406 itemComponents.push_back (std::make_unique<AccessibleItemComponent> (*
this, name));
411int MenuBarComponent::indexOfItemComponent (AccessibleItemComponent* itemComponent)
const
413 const auto iter =
std::find_if (itemComponents.cbegin(), itemComponents.cend(),
416 if (iter != itemComponents.cend())
428 for (
size_t i = 0; i < itemComponents.size(); ++i)
434 setItemUnderMouse ((
int) i);
441void MenuBarComponent::timerCallback()
452 explicit MenuBarComponentAccessibilityHandler (
MenuBarComponent& menuBarComponent)
460 return std::make_unique<MenuBarComponentAccessibilityHandler> (*
this);
A simple wrapper for building a collection of supported accessibility actions and corresponding callb...
AccessibilityActions & addAction(AccessibilityActionType type, std::function< void()> actionCallback)
Adds an action.
Base class for accessible Components.
Represents the state of an accessible UI element.
AccessibleState withIgnored() const noexcept
Sets the ignored flag and returns the new state.
The base class for all JUCE user-interface objects.
bool contains(Point< int > localPoint)
Returns true if a given point lies within this component or one of its children.
void setRepaintsOnMouseActivity(bool shouldRepaint) noexcept
Causes automatic repaints when the mouse enters or exits this component.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
bool reallyContains(Point< int > localPoint, bool returnTrueIfWithinAChild)
Returns true if a given point lies in this component, taking any overlapping siblings into account.
int getHeight() const noexcept
Returns the component's height in pixels.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
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.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
Point< int > getMouseXYRelative() const
Returns the mouse's current position, relative to this component.
Rectangle< int > localAreaToGlobal(Rectangle< int > localArea) const
Converts a rectangle from this component's coordinate space to a screen coordinate.
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.
void setMouseClickGrabsKeyboardFocus(bool shouldGrabFocus)
Chooses whether a click on this component automatically grabs the focus.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
String getName() const noexcept
Returns the name of this component.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
void removeGlobalMouseListener(MouseListener *listener)
Unregisters a MouseListener that was added with addGlobalMouseListener().
Uses RAII to save and restore the state of a graphics context.
A graphics context, used for drawing a component or image.
bool reduceClipRegion(int x, int y, int width, int height)
Intersects the current clipping region with another region.
void setOrigin(Point< int > newOrigin)
Moves the position of the context's origin.
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.
static const int rightKey
key-code for the cursor-right key
static const int leftKey
key-code for the cursor-left key
Contains position and status information about a mouse event.
Point< int > getPosition() const noexcept
The position of the mouse when the event occurred.
MouseEvent getEventRelativeTo(Component *newComponent) const noexcept
Creates a version of this event that is relative to a different component.
Component *const eventComponent
The component that this event applies to.
A pair of (x, y) coordinates.
A special array for holding a list of strings.
void stopTimer() noexcept
Stops the timer.
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
@ showMenu
Represents the user showing a contextual menu for a UI element.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
@ dontTriggerVisualFeedback
If this flag is present and the command is invoked from a keypress, then any buttons or menus that ar...
Contains contextual details about the invocation of a command.
int commandFlags
The command's flags.
CommandID commandID
The UID of the command that should be performed.