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.

212 lines
9.1KB

  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::MarkerResolver
  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 ("className"); }
  45. Value getClassDescription() const { return getRootValueNonUndoable ("classDesc"); }
  46. void setUsingTemporaryCanvasSize (bool b);
  47. Value getCanvasWidth() const;
  48. Value getCanvasHeight() 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 RectangleCoordinates getCoordsFor (const ValueTree& componentState) const;
  63. bool setCoordsFor (ValueTree& componentState, const RectangleCoordinates& newSize);
  64. void renameAnchor (const String& oldName, const String& newName);
  65. // for Coordinate::MarkerResolver:
  66. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  67. void addComponentMarkerMenuItems (const ValueTree& componentState, const String& coordName,
  68. Coordinate& coord, PopupMenu& menu, bool isAnchor1);
  69. const String getChosenMarkerMenuItem (const ValueTree& componentState, Coordinate& coord, int itemId) const;
  70. void addNewComponentMenuItems (PopupMenu& menu) const;
  71. const ValueTree performNewComponentMenuItem (int menuResultCode);
  72. void updateComponentsIn (Component* compHolder);
  73. //==============================================================================
  74. class MarkerList : public MarkerListBase
  75. {
  76. public:
  77. MarkerList (ComponentDocument& document, bool isX);
  78. const Coordinate findMarker (const String& name, bool isHorizontal) const;
  79. bool createProperties (Array <PropertyComponent*>& props, const String& itemId);
  80. void addMarkerMenuItems (const ValueTree& markerState, const Coordinate& coord, PopupMenu& menu, bool isAnchor1);
  81. const String getChosenMarkerMenuItem (const Coordinate& coord, int itemId) const;
  82. UndoManager* getUndoManager() const;
  83. void renameAnchor (const String& oldName, const String& newName);
  84. const String getNonexistentMarkerName (const String& name);
  85. ComponentDocument& getDocument() throw() { return document; }
  86. private:
  87. ComponentDocument& document;
  88. MarkerList (const MarkerList&);
  89. MarkerList& operator= (const MarkerList&);
  90. };
  91. MarkerList& getMarkerListX() const { return *markersX; }
  92. MarkerList& getMarkerListY() const { return *markersY; }
  93. MarkerList& getMarkerList (bool isX) const { return isX ? *markersX : *markersY; }
  94. //==============================================================================
  95. void createItemProperties (Array <PropertyComponent*>& props, const StringArray& selectedItemIds);
  96. //==============================================================================
  97. void beginDrag (const Array<Component*>& items, const MouseEvent& e,
  98. Component* parentForOverlays, const ResizableBorderComponent::Zone& zone);
  99. void continueDrag (const MouseEvent& e);
  100. void endDrag (const MouseEvent& e);
  101. //==============================================================================
  102. CodeGenerator::CustomCodeList& getCustomCodeList() throw() { return customCode; }
  103. const String getCppTemplate() const;
  104. const String getHeaderTemplate() const;
  105. const String getCppContent();
  106. const String getHeaderContent();
  107. //==============================================================================
  108. ValueTree& getRoot() { return root; }
  109. ValueTree getComponentGroup() const;
  110. UndoManager* getUndoManager() const;
  111. void beginNewTransaction();
  112. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& property);
  113. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged);
  114. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged);
  115. static const char* const idProperty;
  116. static const char* const compBoundsProperty;
  117. static const char* const memberNameProperty;
  118. static const char* const compNameProperty;
  119. static const char* const compTooltipProperty;
  120. static const char* const compFocusOrderProperty;
  121. static const char* const jucerIDProperty;
  122. static const String getJucerIDFor (Component* c);
  123. //==============================================================================
  124. class TestComponent : public Component
  125. {
  126. public:
  127. TestComponent (ComponentDocument& document_);
  128. TestComponent (Project* project, const File& cppFile);
  129. ~TestComponent();
  130. void resized();
  131. void paint (Graphics& g);
  132. private:
  133. ScopedPointer<ComponentDocument> document;
  134. void setupDocument();
  135. };
  136. juce_UseDebuggingNewOperator
  137. private:
  138. //==============================================================================
  139. Project* project;
  140. File cppFile;
  141. ValueTree root;
  142. ScopedPointer<MarkerList> markersX, markersY;
  143. CodeGenerator::CustomCodeList customCode;
  144. mutable UndoManager undoManager;
  145. bool changedSinceSaved, usingTemporaryCanvasSize;
  146. Value tempCanvasWidth, tempCanvasHeight;
  147. void checkRootObject();
  148. void createSubTreeIfNotThere (const String& name);
  149. void addMarkerMenuItem (int i, const Coordinate& coord, const String& name, PopupMenu& menu,
  150. bool isAnchor1, const String& fullCoordName);
  151. Value getRootValueUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, getUndoManager()); }
  152. Value getRootValueNonUndoable (const var::identifier& name) const { return root.getPropertyAsValue (name, 0); }
  153. void writeCode (OutputStream& cpp, OutputStream& header);
  154. void writeMetadata (OutputStream& out);
  155. bool createItemProperties (Array <PropertyComponent*>& props, const String& itemId);
  156. Component* findComponentForState (Component* compHolder, const ValueTree& state);
  157. };
  158. #endif // __JUCER_COMPONENTDOCUMENT_JUCEHEADER__