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.

192 lines
8.5KB

  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 "jucer_Project.h"
  22. #include "jucer_Coordinate.h"
  23. #include "jucer_CodeGenerator.h"
  24. //==============================================================================
  25. class ComponentDocument : public ValueTree::Listener,
  26. public Coordinate::MarkerResolver
  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. const File getCppFile() const { return cppFile; }
  39. //==============================================================================
  40. Value getClassName() const { return getRootValueNonUndoable ("className"); }
  41. Value getClassDescription() const { return getRootValueNonUndoable ("classDesc"); }
  42. Value getCanvasWidth() const { return getRootValueNonUndoable ("width"); }
  43. Value getCanvasHeight() const { return getRootValueNonUndoable ("height"); }
  44. void createClassProperties (Array <PropertyComponent*>& props);
  45. const String getNonExistentMemberName (String suggestedName);
  46. //==============================================================================
  47. int getNumComponents() const;
  48. const ValueTree getComponent (int index) const;
  49. const ValueTree getComponentWithMemberName (const String& name) const;
  50. const ValueTree getComponentWithID (const String& uid) const;
  51. Component* createComponent (int index);
  52. void updateComponent (Component* comp);
  53. bool containsComponent (Component* comp) const;
  54. const ValueTree getComponentState (Component* comp) const;
  55. bool isStateForComponent (const ValueTree& storedState, Component* comp) const;
  56. void removeComponent (const ValueTree& state);
  57. const RectangleCoordinates getCoordsFor (const ValueTree& componentState) const;
  58. bool setCoordsFor (ValueTree& componentState, const RectangleCoordinates& newSize);
  59. // for Coordinate::MarkerResolver:
  60. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  61. void addComponentMarkerMenuItems (const ValueTree& componentState, const String& coordName,
  62. Coordinate& coord, PopupMenu& menu, bool isAnchor1);
  63. const String getChosenMarkerMenuItem (const ValueTree& componentState, Coordinate& coord, int itemId) const;
  64. void addNewComponentMenuItems (PopupMenu& menu) const;
  65. void performNewComponentMenuItem (int menuResultCode);
  66. //==============================================================================
  67. class MarkerList : public Coordinate::MarkerResolver
  68. {
  69. public:
  70. MarkerList (ComponentDocument& document, bool isX);
  71. ValueTree& getGroup();
  72. int size() const;
  73. ValueTree getMarker (int index) const;
  74. ValueTree getMarkerNamed (const String& name) const;
  75. bool contains (const ValueTree& markerState) const;
  76. const Coordinate getCoordinate (const ValueTree& markerState) const;
  77. const String getName (const ValueTree& markerState) const;
  78. Value getNameAsValue (const ValueTree& markerState) const;
  79. void setCoordinate (ValueTree& markerState, const Coordinate& newCoord);
  80. void createMarker (const String& name, int position);
  81. void deleteMarker (ValueTree& markerState);
  82. // for Coordinate::MarkerResolver:
  83. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  84. bool createProperties (Array <PropertyComponent*>& props, const String& itemId);
  85. void createMarkerProperties (Array <PropertyComponent*>& props, ValueTree& marker);
  86. void addMarkerMenuItems (const ValueTree& markerState, const Coordinate& coord, PopupMenu& menu, bool isAnchor1);
  87. const String getChosenMarkerMenuItem (const Coordinate& coord, int itemId) const;
  88. private:
  89. ComponentDocument& document;
  90. ValueTree group;
  91. const bool isX;
  92. MarkerList (const MarkerList&);
  93. MarkerList& operator= (const MarkerList&);
  94. };
  95. MarkerList& getMarkerListX() const { return *markersX; }
  96. MarkerList& getMarkerListY() const { return *markersY; }
  97. MarkerList& getMarkerList (bool isX) const { return isX ? *markersX : *markersY; }
  98. const String getNonexistentMarkerName (const String& name);
  99. //==============================================================================
  100. void createItemProperties (Array <PropertyComponent*>& props, const StringArray& selectedItemIds);
  101. //==============================================================================
  102. void beginDrag (const Array<Component*>& items, const MouseEvent& e,
  103. Component* parentForOverlays, const ResizableBorderComponent::Zone& zone);
  104. void continueDrag (const MouseEvent& e);
  105. void endDrag (const MouseEvent& e);
  106. //==============================================================================
  107. CodeGenerator::CustomCodeList& getCustomCodeList() throw() { return customCode; }
  108. const String getCppTemplate() const;
  109. const String getHeaderTemplate() const;
  110. //==============================================================================
  111. ValueTree& getRoot() { return root; }
  112. ValueTree getComponentGroup() const;
  113. UndoManager* getUndoManager() const;
  114. void beginNewTransaction();
  115. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& property);
  116. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged);
  117. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged);
  118. static const char* const idProperty;
  119. static const char* const compBoundsProperty;
  120. static const char* const memberNameProperty;
  121. static const char* const compNameProperty;
  122. static const char* const markerNameProperty;
  123. static const char* const markerPosProperty;
  124. static const char* const jucerIDProperty;
  125. static const String getJucerIDFor (Component* c);
  126. private:
  127. Project* project;
  128. File cppFile;
  129. ValueTree root;
  130. ScopedPointer<MarkerList> markersX, markersY;
  131. CodeGenerator::CustomCodeList customCode;
  132. mutable UndoManager undoManager;
  133. bool changedSinceSaved;
  134. void checkRootObject();
  135. void createSubTreeIfNotThere (const String& name);
  136. void addMarkerMenuItem (int i, const Coordinate& coord, const String& name, PopupMenu& menu,
  137. bool isAnchor1, const String& fullCoordName);
  138. Value getRootValueUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, getUndoManager()); }
  139. Value getRootValueNonUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, 0); }
  140. void writeCode (OutputStream& cpp, OutputStream& header);
  141. void writeMetadata (OutputStream& out);
  142. bool createItemProperties (Array <PropertyComponent*>& props, const String& itemId);
  143. };
  144. #endif // __JUCER_COMPONENTDOCUMENT_JUCEHEADER__