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.

199 lines
8.9KB

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