2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
30 Adds a focus outline to a component.
32 This object creates and manages a component that sits on top of a target
33 component. It will track the position of the target component and will be
34 brought to the front with the tracked component.
36 Use the Component::setHasFocusOutline() method to indicate that a component
37 should have a focus outline drawn around it, and when it receives keyboard
38 focus one of these objects will be created using the
39 LookAndFeel::createFocusOutlineForComponent() method. You can override this
40 method in your own LookAndFeel classes to draw a custom outline if required.
44 class JUCE_API FocusOutline
: private ComponentListener
47 //==============================================================================
48 /** Defines the focus outline window properties.
50 Pass an instance of one of these to the FocusOutline constructor to control
51 the bounds for the outline window and how it is drawn.
53 struct JUCE_API OutlineWindowProperties
55 virtual ~OutlineWindowProperties() = default;
57 /** Return the bounds for the outline window in screen coordinates. */
58 virtual Rectangle
<int> getOutlineBounds (Component
& focusedComponent
) = 0;
60 /** This method will be called to draw the focus outline. */
61 virtual void drawOutline (Graphics
&, int width
, int height
) = 0;
64 //==============================================================================
65 /** Creates a FocusOutline.
67 Call setOwner to attach it to a component.
69 FocusOutline (std::unique_ptr
<OutlineWindowProperties
> props
);
72 ~FocusOutline() override
;
74 /** Attaches the outline to a component. */
75 void setOwner (Component
* componentToFollow
);
78 //==============================================================================
79 void componentMovedOrResized (Component
&, bool, bool) override
;
80 void componentBroughtToFront (Component
&) override
;
81 void componentParentHierarchyChanged (Component
&) override
;
82 void componentVisibilityChanged (Component
&) override
;
84 void updateOutlineWindow();
87 //==============================================================================
88 std::unique_ptr
<OutlineWindowProperties
> properties
;
90 WeakReference
<Component
> owner
;
91 std::unique_ptr
<Component
> outlineWindow
;
92 WeakReference
<Component
> lastParentComp
;
94 bool reentrant
= false;
96 //==============================================================================
97 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FocusOutline
)