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.

94 lines
3.3KB

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