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.

184 lines
8.2KB

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