Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_FocusOutline.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /**
  21. Adds a focus outline to a component.
  22. This object creates and manages a component that sits on top of a target
  23. component. It will track the position of the target component and will be
  24. brought to the front with the tracked component.
  25. Use the Component::setHasFocusOutline() method to indicate that a component
  26. should have a focus outline drawn around it, and when it receives keyboard
  27. focus one of these objects will be created using the
  28. LookAndFeel::createFocusOutlineForComponent() method. You can override this
  29. method in your own LookAndFeel classes to draw a custom outline if required.
  30. @tags{GUI}
  31. */
  32. class JUCE_API FocusOutline : private ComponentListener
  33. {
  34. public:
  35. //==============================================================================
  36. /** Defines the focus outline window properties.
  37. Pass an instance of one of these to the FocusOutline constructor to control
  38. the bounds for the outline window and how it is drawn.
  39. */
  40. struct JUCE_API OutlineWindowProperties
  41. {
  42. virtual ~OutlineWindowProperties() = default;
  43. /** Return the bounds for the outline window in screen coordinates. */
  44. virtual Rectangle<int> getOutlineBounds (Component& focusedComponent) = 0;
  45. /** This method will be called to draw the focus outline. */
  46. virtual void drawOutline (Graphics&, int width, int height) = 0;
  47. };
  48. //==============================================================================
  49. /** Creates a FocusOutline.
  50. Call setOwner to attach it to a component.
  51. */
  52. FocusOutline (std::unique_ptr<OutlineWindowProperties> props);
  53. /** Destructor. */
  54. ~FocusOutline() override;
  55. /** Attaches the outline to a component. */
  56. void setOwner (Component* componentToFollow);
  57. private:
  58. //==============================================================================
  59. void componentMovedOrResized (Component&, bool, bool) override;
  60. void componentBroughtToFront (Component&) override;
  61. void componentParentHierarchyChanged (Component&) override;
  62. void componentVisibilityChanged (Component&) override;
  63. void updateOutlineWindow();
  64. void updateParent();
  65. //==============================================================================
  66. std::unique_ptr<OutlineWindowProperties> properties;
  67. WeakReference<Component> owner;
  68. std::unique_ptr<Component> outlineWindow;
  69. WeakReference<Component> lastParentComp;
  70. bool reentrant = false;
  71. //==============================================================================
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FocusOutline)
  73. };
  74. } // namespace juce