juce_RelativeCoordinatePositioner.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_RELATIVECOORDINATEPOSITIONER_H_INCLUDED
  18. #define JUCE_RELATIVECOORDINATEPOSITIONER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Base class for Component::Positioners that are based upon relative coordinates.
  22. */
  23. class JUCE_API RelativeCoordinatePositionerBase : public Component::Positioner,
  24. public ComponentListener,
  25. public MarkerList::Listener
  26. {
  27. public:
  28. RelativeCoordinatePositionerBase (Component& component);
  29. ~RelativeCoordinatePositionerBase();
  30. void componentMovedOrResized (Component&, bool, bool);
  31. void componentParentHierarchyChanged (Component&);
  32. void componentChildrenChanged (Component& component);
  33. void componentBeingDeleted (Component& component);
  34. void markersChanged (MarkerList*);
  35. void markerListBeingDeleted (MarkerList* markerList);
  36. void apply();
  37. bool addCoordinate (const RelativeCoordinate& coord);
  38. bool addPoint (const RelativePoint& point);
  39. //==============================================================================
  40. /** Used for resolving a RelativeCoordinate expression in the context of a component. */
  41. class ComponentScope : public Expression::Scope
  42. {
  43. public:
  44. ComponentScope (Component& component);
  45. Expression getSymbolValue (const String& symbol) const;
  46. void visitRelativeScope (const String& scopeName, Visitor& visitor) const;
  47. String getScopeUID() const;
  48. protected:
  49. Component& component;
  50. Component* findSiblingComponent (const String& componentID) const;
  51. private:
  52. JUCE_DECLARE_NON_COPYABLE (ComponentScope)
  53. };
  54. protected:
  55. virtual bool registerCoordinates() = 0;
  56. virtual void applyToComponentBounds() = 0;
  57. private:
  58. class DependencyFinderScope;
  59. friend class DependencyFinderScope;
  60. Array <Component*> sourceComponents;
  61. Array <MarkerList*> sourceMarkerLists;
  62. bool registeredOk;
  63. void registerComponentListener (Component& comp);
  64. void registerMarkerListListener (MarkerList* const list);
  65. void unregisterListeners();
  66. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RelativeCoordinatePositionerBase)
  67. };
  68. #endif // JUCE_RELATIVECOORDINATEPOSITIONER_H_INCLUDED