The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

96 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
  19. #define __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
  20. #include "../juce_Component.h"
  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 OpenGLComponent or QuickTimeComponent
  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. //==============================================================================
  52. /** @internal */
  53. void componentParentHierarchyChanged (Component& component);
  54. /** @internal */
  55. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  56. /** @internal */
  57. void componentBeingDeleted (Component& component);
  58. /** @internal */
  59. void componentVisibilityChanged (Component& component);
  60. private:
  61. //==============================================================================
  62. WeakReference<Component> component;
  63. ComponentPeer* lastPeer;
  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_JUCEHEADER__