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.

207 lines
9.7KB

  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 __JUCER_COMPONENTDOCUMENT_JUCEHEADER__
  19. #define __JUCER_COMPONENTDOCUMENT_JUCEHEADER__
  20. #include "../../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. #include "../../utility/jucer_MarkerListBase.h"
  23. #include "jucer_CodeGenerator.h"
  24. //==============================================================================
  25. class ComponentDocument : public ValueTree::Listener,
  26. public RelativeCoordinate::NamedCoordinateFinder
  27. {
  28. public:
  29. //==============================================================================
  30. ComponentDocument (Project* project, const File& cppFile);
  31. ComponentDocument (const ComponentDocument& other);
  32. ~ComponentDocument();
  33. static bool isComponentFile (const File& file);
  34. bool save();
  35. bool reload();
  36. bool hasChangedSinceLastSave();
  37. void changed();
  38. Project* getProject() const { return project; }
  39. const File getCppFile() const { return cppFile; }
  40. void cppFileHasMoved (const File& newFile) { cppFile = newFile; }
  41. //==============================================================================
  42. const String getUniqueId() const { return root [idProperty]; }
  43. Value getClassName() const { return getRootValueNonUndoable (Ids::className); }
  44. Value getClassDescription() const { return getRootValueNonUndoable (Ids::classDesc); }
  45. void setUsingTemporaryCanvasSize (bool b);
  46. Value getCanvasWidth() const;
  47. Value getCanvasHeight() const;
  48. Value getBackgroundColour() const;
  49. void createClassProperties (Array <PropertyComponent*>& props);
  50. const String getNonexistentMemberName (String suggestedName);
  51. //==============================================================================
  52. int getNumComponents() const;
  53. const ValueTree getComponent (int index) const;
  54. const ValueTree getComponentWithMemberName (const String& name) const;
  55. const ValueTree getComponentWithID (const String& uid) const;
  56. Component* createComponent (int index);
  57. void updateComponent (Component* comp);
  58. bool containsComponent (Component* comp) const;
  59. const ValueTree getComponentState (Component* comp) const;
  60. bool isStateForComponent (const ValueTree& storedState, Component* comp) const;
  61. void removeComponent (const ValueTree& state);
  62. const RelativeRectangle getCoordsFor (const ValueTree& componentState) const;
  63. void setCoordsFor (ValueTree& componentState, const RelativeRectangle& newSize);
  64. void renameAnchor (const String& oldName, const String& newName);
  65. // for RelativeCoordinate::Resolver:
  66. const RelativeCoordinate findNamedCoordinate (const String& objectName, const String& edge) const;
  67. void addComponentMarkerMenuItems (const ValueTree& componentState, const String& coordName,
  68. RelativeCoordinate& coord, PopupMenu& menu, bool isAnchor1, bool isHorizontal);
  69. const String getChosenMarkerMenuItem (const ValueTree& componentState, RelativeCoordinate& coord, int itemId, bool isHorizontal) const;
  70. void addNewComponentMenuItems (PopupMenu& menu) const;
  71. const ValueTree performNewComponentMenuItem (int menuResultCode);
  72. void componentDoubleClicked (const MouseEvent& e, const ValueTree& state);
  73. void updateComponentsIn (Component* compHolder);
  74. Component* findComponentForState (Component* parentComp, const ValueTree& state);
  75. //==============================================================================
  76. class MarkerList : public MarkerListBase
  77. {
  78. public:
  79. MarkerList (ComponentDocument& document, bool isX);
  80. const RelativeCoordinate findNamedCoordinate (const String& objectName, const String& edge) const;
  81. bool createProperties (Array <PropertyComponent*>& props, const String& itemId);
  82. void addMarkerMenuItems (const ValueTree& markerState, const RelativeCoordinate& coord, PopupMenu& menu, bool isAnchor1);
  83. const String getChosenMarkerMenuItem (const RelativeCoordinate& coord, int itemId) const;
  84. UndoManager* getUndoManager() const;
  85. void renameAnchor (const String& oldName, const String& newName);
  86. const String getNonexistentMarkerName (const String& name);
  87. const String getId (const ValueTree& markerState) { return markerState [Ids::id_]; }
  88. int size() const { return group.getNumChildren(); }
  89. ValueTree getMarker (int index) const { return group.getChild (index); }
  90. ValueTree getMarkerNamed (const String& name) const { return group.getChildWithProperty (getMarkerNameProperty(), name); }
  91. bool contains (const ValueTree& markerState) const { return markerState.isAChildOf (group); }
  92. void createMarker (const String& name, double position);
  93. void deleteMarker (ValueTree& markerState);
  94. ComponentDocument& getDocument() throw() { return document; }
  95. ValueTree& getGroup() { return group; }
  96. private:
  97. ComponentDocument& document;
  98. ValueTree group;
  99. MarkerList (const MarkerList&);
  100. MarkerList& operator= (const MarkerList&);
  101. };
  102. MarkerList& getMarkerListX() const { return *markersX; }
  103. MarkerList& getMarkerListY() const { return *markersY; }
  104. MarkerList& getMarkerList (bool isX) const { return isX ? *markersX : *markersY; }
  105. //==============================================================================
  106. void createItemProperties (Array <PropertyComponent*>& props, const StringArray& selectedItemIds);
  107. //==============================================================================
  108. void beginDrag (const Array<Component*>& items, const MouseEvent& e,
  109. Component* parentForOverlays, const ResizableBorderComponent::Zone& zone);
  110. void continueDrag (const MouseEvent& e);
  111. void endDrag (const MouseEvent& e);
  112. //==============================================================================
  113. CodeGenerator::CustomCodeList& getCustomCodeList() throw() { return customCode; }
  114. const String getCppTemplate() const;
  115. const String getHeaderTemplate() const;
  116. const String getCppContent();
  117. const String getHeaderContent();
  118. //==============================================================================
  119. ValueTree& getRoot() { return root; }
  120. ValueTree getComponentGroup() const;
  121. UndoManager* getUndoManager() const;
  122. void beginNewTransaction();
  123. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const Identifier& property);
  124. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged);
  125. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged);
  126. static const Identifier idProperty;
  127. static const Identifier compBoundsProperty;
  128. static const Identifier memberNameProperty;
  129. static const Identifier compNameProperty;
  130. static const Identifier compTooltipProperty;
  131. static const Identifier compFocusOrderProperty;
  132. static const Identifier jucerIDProperty;
  133. static const String getJucerIDFor (Component* c);
  134. //==============================================================================
  135. juce_UseDebuggingNewOperator
  136. private:
  137. //==============================================================================
  138. Project* project;
  139. File cppFile;
  140. ValueTree root;
  141. ScopedPointer<MarkerList> markersX, markersY;
  142. CodeGenerator::CustomCodeList customCode;
  143. mutable UndoManager undoManager;
  144. bool changedSinceSaved, usingTemporaryCanvasSize;
  145. Value tempCanvasWidth, tempCanvasHeight;
  146. void checkRootObject();
  147. void createSubTreeIfNotThere (const Identifier& name);
  148. void addMarkerMenuItem (int i, const RelativeCoordinate& coord, const String& objectName, const String& edge,
  149. PopupMenu& menu, bool isAnchor1, const String& fullCoordName);
  150. Value getRootValueUndoable (const Identifier& name) const { return root.getPropertyAsValue (name, getUndoManager()); }
  151. Value getRootValueNonUndoable (const Identifier& name) const { return root.getPropertyAsValue (name, 0); }
  152. void writeCode (OutputStream& cpp, OutputStream& header);
  153. void writeMetadata (OutputStream& out);
  154. bool createItemProperties (Array <PropertyComponent*>& props, const String& itemId);
  155. };
  156. #endif // __JUCER_COMPONENTDOCUMENT_JUCEHEADER__