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_ComponentMovementWatcher.h 3.8KB

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