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.9KB

9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_COMPONENTMOVEMENTWATCHER_H_INCLUDED
  18. #define JUCE_COMPONENTMOVEMENTWATCHER_H_INCLUDED
  19. //==============================================================================
  20. /** An object that watches for any movement of a component or any of its parent components.
  21. This makes it easy to check when a component is moved relative to its top-level
  22. peer window. The normal Component::moved() method is only called when a component
  23. moves relative to its immediate parent, and sometimes you want to know if any of
  24. components higher up the tree have moved (which of course will affect the overall
  25. position of all their sub-components).
  26. It also includes a callback that lets you know when the top-level peer is changed.
  27. This class is used by specialised components like WebBrowserComponent or QuickTimeComponent
  28. because they need to keep their custom windows in the right place and respond to
  29. changes in the peer.
  30. */
  31. class JUCE_API ComponentMovementWatcher : public ComponentListener
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a ComponentMovementWatcher to watch a given target component. */
  36. ComponentMovementWatcher (Component* component);
  37. /** Destructor. */
  38. ~ComponentMovementWatcher();
  39. //==============================================================================
  40. /** This callback happens when the component that is being watched is moved
  41. relative to its top-level peer window, or when it is resized. */
  42. virtual void componentMovedOrResized (bool wasMoved, bool wasResized) = 0;
  43. /** This callback happens when the component's top-level peer is changed. */
  44. virtual void componentPeerChanged() = 0;
  45. /** This callback happens when the component's visibility state changes, possibly due to
  46. one of its parents being made visible or invisible.
  47. */
  48. virtual void componentVisibilityChanged() = 0;
  49. /** Returns the component that's being watched. */
  50. Component* getComponent() const noexcept { return component; }
  51. //==============================================================================
  52. /** @internal */
  53. void componentParentHierarchyChanged (Component&) override;
  54. /** @internal */
  55. void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
  56. /** @internal */
  57. void componentBeingDeleted (Component&) override;
  58. /** @internal */
  59. void componentVisibilityChanged (Component&) override;
  60. private:
  61. //==============================================================================
  62. WeakReference<Component> component;
  63. uint32 lastPeerID;
  64. Array <Component*> registeredParentComps;
  65. bool reentrant, wasShowing;
  66. Rectangle<int> lastBounds;
  67. void unregister();
  68. void registerWithParentComps();
  69. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentMovementWatcher)
  70. };
  71. #endif // JUCE_COMPONENTMOVEMENTWATCHER_H_INCLUDED