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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /** An object that watches for any movement of a component or any of its parent components.
  23. This makes it easy to check when a component is moved relative to its top-level
  24. peer window. The normal Component::moved() method is only called when a component
  25. moves relative to its immediate parent, and sometimes you want to know if any of
  26. components higher up the tree have moved (which of course will affect the overall
  27. position of all their sub-components).
  28. It also includes a callback that lets you know when the top-level peer is changed.
  29. This class is used by specialised components like WebBrowserComponent
  30. because they need to keep their custom windows in the right place and respond to
  31. changes in the peer.
  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* component);
  39. /** Destructor. */
  40. ~ComponentMovementWatcher();
  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; }
  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;
  66. Array <Component*> registeredParentComps;
  67. bool reentrant, wasShowing;
  68. Rectangle<int> lastBounds;
  69. void unregister();
  70. void registerWithParentComps();
  71. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentMovementWatcher)
  72. };
  73. } // namespace juce