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.

90 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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. /** An object that watches for any movement of a component or any of its parent components.
  17. This makes it easy to check when a component is moved relative to its top-level
  18. peer window. The normal Component::moved() method is only called when a component
  19. moves relative to its immediate parent, and sometimes you want to know if any of
  20. components higher up the tree have moved (which of course will affect the overall
  21. position of all their sub-components).
  22. It also includes a callback that lets you know when the top-level peer is changed.
  23. This class is used by specialised components like WebBrowserComponent
  24. because they need to keep their custom windows in the right place and respond to
  25. changes in the peer.
  26. @tags{GUI}
  27. */
  28. class JUCE_API ComponentMovementWatcher : public ComponentListener
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a ComponentMovementWatcher to watch a given target component. */
  33. ComponentMovementWatcher (Component* componentToWatch);
  34. /** Destructor. */
  35. ~ComponentMovementWatcher() override;
  36. //==============================================================================
  37. /** This callback happens when the component that is being watched is moved
  38. relative to its top-level peer window, or when it is resized. */
  39. virtual void componentMovedOrResized (bool wasMoved, bool wasResized) = 0;
  40. /** This callback happens when the component's top-level peer is changed. */
  41. virtual void componentPeerChanged() = 0;
  42. /** This callback happens when the component's visibility state changes, possibly due to
  43. one of its parents being made visible or invisible.
  44. */
  45. virtual void componentVisibilityChanged() = 0;
  46. /** Returns the component that's being watched. */
  47. Component* getComponent() const noexcept { return component.get(); }
  48. //==============================================================================
  49. /** @internal */
  50. void componentParentHierarchyChanged (Component&) override;
  51. /** @internal */
  52. void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
  53. /** @internal */
  54. void componentBeingDeleted (Component&) override;
  55. /** @internal */
  56. void componentVisibilityChanged (Component&) override;
  57. private:
  58. //==============================================================================
  59. WeakReference<Component> component;
  60. uint32 lastPeerID = 0;
  61. Array<Component*> registeredParentComps;
  62. bool reentrant = false, wasShowing;
  63. Rectangle<int> lastBounds;
  64. void unregister();
  65. void registerWithParentComps();
  66. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentMovementWatcher)
  67. };
  68. } // namespace juce