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.

166 lines
7.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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 __JUCER_COMPONENTDOCUMENT_JUCEHEADER__
  19. #define __JUCER_COMPONENTDOCUMENT_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. #include "jucer_Project.h"
  22. #include "jucer_Coordinate.h"
  23. //==============================================================================
  24. class ComponentDocument : public ValueTree::Listener,
  25. public Coordinate::MarkerResolver
  26. {
  27. public:
  28. //==============================================================================
  29. ComponentDocument (Project* project, const File& cppFile);
  30. ~ComponentDocument();
  31. static bool isComponentFile (const File& file);
  32. bool save();
  33. bool reload();
  34. bool hasChangedSinceLastSave();
  35. //==============================================================================
  36. Value getClassName() const { return getRootValueNonUndoable ("className"); }
  37. Value getClassDescription() const { return getRootValueNonUndoable ("classDesc"); }
  38. Value getCanvasWidth() const { return getRootValueNonUndoable ("width"); }
  39. Value getCanvasHeight() const { return getRootValueNonUndoable ("height"); }
  40. void createClassProperties (Array <PropertyComponent*>& props);
  41. const String getNonExistentMemberName (String suggestedName);
  42. //==============================================================================
  43. int getNumComponents() const;
  44. const ValueTree getComponent (int index) const;
  45. const ValueTree getComponentWithMemberName (const String& name) const;
  46. Component* createComponent (int index);
  47. void updateComponent (Component* comp);
  48. bool containsComponent (Component* comp) const;
  49. const ValueTree getComponentState (Component* comp) const;
  50. void getComponentProperties (Array <PropertyComponent*>& props, Component* comp);
  51. bool isStateForComponent (const ValueTree& storedState, Component* comp) const;
  52. void removeComponent (const ValueTree& state);
  53. const RectangleCoordinates getCoordsFor (const ValueTree& componentState) const;
  54. bool setCoordsFor (ValueTree& componentState, const RectangleCoordinates& newSize);
  55. // for Coordinate::MarkerResolver:
  56. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  57. void getComponentMarkerMenuItems (const ValueTree& componentState, const String& coordName,
  58. Coordinate& coord, PopupMenu& menu, bool isAnchor1);
  59. const String getChosenMarkerMenuItem (const ValueTree& componentState, Coordinate& coord, int itemId) const;
  60. void addNewComponentMenuItems (PopupMenu& menu) const;
  61. void performNewComponentMenuItem (int menuResultCode);
  62. //==============================================================================
  63. class MarkerList : public Coordinate::MarkerResolver
  64. {
  65. public:
  66. MarkerList (ComponentDocument& document, bool isX);
  67. ValueTree& getGroup();
  68. int size() const;
  69. ValueTree getMarker (int index) const;
  70. ValueTree getMarkerNamed (const String& name) const;
  71. bool contains (const ValueTree& markerState) const;
  72. const Coordinate getCoordinate (const ValueTree& markerState) const;
  73. const String getName (const ValueTree& markerState) const;
  74. Value getNameAsValue (const ValueTree& markerState) const;
  75. void setCoordinate (ValueTree& markerState, const Coordinate& newCoord);
  76. void createMarker (const String& name, int position);
  77. void deleteMarker (ValueTree& markerState);
  78. // for Coordinate::MarkerResolver:
  79. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  80. private:
  81. ComponentDocument& document;
  82. ValueTree group;
  83. const bool isX;
  84. MarkerList (const MarkerList&);
  85. MarkerList& operator= (const MarkerList&);
  86. };
  87. MarkerList& getMarkerListX() const { return *markersX; }
  88. MarkerList& getMarkerListY() const { return *markersY; }
  89. MarkerList& getMarkerList (bool isX) const { return isX ? *markersX : *markersY; }
  90. const String getNonexistentMarkerName (const String& name);
  91. //==============================================================================
  92. void beginDrag (const Array<Component*>& items, const MouseEvent& e,
  93. Component* parentForOverlays, const ResizableBorderComponent::Zone& zone);
  94. void continueDrag (const MouseEvent& e);
  95. void endDrag (const MouseEvent& e);
  96. //==============================================================================
  97. ValueTree& getRoot() { return root; }
  98. UndoManager* getUndoManager() const;
  99. void beginNewTransaction();
  100. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& property);
  101. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged);
  102. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged);
  103. static const char* const idProperty;
  104. static const char* const compBoundsProperty;
  105. static const char* const memberNameProperty;
  106. static const char* const compNameProperty;
  107. static const char* const markerNameProperty;
  108. static const char* const markerPosProperty;
  109. private:
  110. Project* project;
  111. File cppFile;
  112. ValueTree root;
  113. ScopedPointer<MarkerList> markersX, markersY;
  114. mutable UndoManager undoManager;
  115. bool changedSinceSaved;
  116. void checkRootObject();
  117. void createSubTreeIfNotThere (const String& name);
  118. ValueTree getComponentGroup() const;
  119. void addMarkerMenuItem (int i, Coordinate& coord, const String& name, PopupMenu& menu, bool isAnchor1,
  120. const ValueTree& componentState, const String& coordName);
  121. Value getRootValueUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, getUndoManager()); }
  122. Value getRootValueNonUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, 0); }
  123. void writeCode (OutputStream& cpp, OutputStream& header);
  124. void writeMetadata (OutputStream& out);
  125. };
  126. #endif // __JUCER_COMPONENTDOCUMENT_JUCEHEADER__