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.

141 lines
6.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_DRAWABLEDOCUMENT_JUCEHEADER__
  19. #define __JUCER_DRAWABLEDOCUMENT_JUCEHEADER__
  20. #include "../../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. #include "../../utility/jucer_MarkerListBase.h"
  23. //==============================================================================
  24. class DrawableDocument : public ValueTree::Listener,
  25. public Drawable::ImageProvider
  26. {
  27. public:
  28. //==============================================================================
  29. DrawableDocument (Project* project);
  30. ~DrawableDocument();
  31. //==============================================================================
  32. void setName (const String& name);
  33. const String getName() const;
  34. bool reload (const File& drawableFile);
  35. bool save (const File& drawableFile);
  36. bool hasChangedSinceLastSave() const;
  37. void changed();
  38. Project* getProject() const throw() { return project; }
  39. const String getUniqueId() const;
  40. ValueTree& getRoot() { return root; }
  41. DrawableComposite::ValueTreeWrapper getRootDrawableNode() const;
  42. ValueTree findDrawableState (const String& objectId, bool recursive) const;
  43. const String createUniqueID (const String& suggestion, StringArray& recentlyUsedIdCache) const;
  44. void createItemProperties (Array <PropertyComponent*>& props, const StringArray& selectedItemIds);
  45. void addNewItemMenuItems (PopupMenu& menu) const;
  46. const ValueTree performNewItemMenuItem (int menuResultCode);
  47. const ValueTree insertSVG (const File& file, const Point<float>& position);
  48. //==============================================================================
  49. class MarkerList : public MarkerListBase
  50. {
  51. public:
  52. MarkerList (DrawableDocument& document, bool isX);
  53. ~MarkerList() {}
  54. const RelativeCoordinate findNamedCoordinate (const String& objectName, const String& edge) const;
  55. bool createProperties (Array <PropertyComponent*>& props, const String& itemId);
  56. void addMarkerMenuItems (const ValueTree& markerState, const RelativeCoordinate& coord, PopupMenu& menu, bool isAnchor1);
  57. const String getChosenMarkerMenuItem (const RelativeCoordinate& coord, int itemId) const;
  58. UndoManager* getUndoManager() const;
  59. const String getNonexistentMarkerName (const String& name);
  60. void renameAnchor (const String& oldName, const String& newName);
  61. const String getId (const ValueTree& markerState);
  62. int size() const;
  63. ValueTree getMarker (int index) const;
  64. ValueTree getMarkerNamed (const String& name) const;
  65. bool contains (const ValueTree& markerState) const;
  66. void createMarker (const String& name, double position);
  67. void deleteMarker (ValueTree& markerState);
  68. private:
  69. DrawableDocument& document;
  70. DrawableComposite::ValueTreeWrapper object;
  71. void addMarkerMenuItem (int i, const RelativeCoordinate& coord, const String& objectName, const String& edge,
  72. PopupMenu& menu, bool isAnchor1, const String& fullCoordName);
  73. MarkerList (const MarkerList&);
  74. MarkerList& operator= (const MarkerList&);
  75. };
  76. MarkerList& getMarkerListX() const { return *markersX; }
  77. MarkerList& getMarkerListY() const { return *markersY; }
  78. MarkerList& getMarkerList (bool isX) const { return isX ? *markersX : *markersY; }
  79. const String getNonexistentMarkerName (const String& name);
  80. void renameAnchor (const String& oldName, const String& newName);
  81. const Image getImageForIdentifier (const var& imageIdentifier);
  82. const var getIdentifierForImage (const Image& image);
  83. //==============================================================================
  84. void valueTreePropertyChanged (ValueTree& tree, const Identifier& name);
  85. void valueTreeChildrenChanged (ValueTree& tree);
  86. void valueTreeParentChanged (ValueTree& tree);
  87. //==============================================================================
  88. UndoManager* getUndoManager() const throw() { return &undoManager; }
  89. private:
  90. Project* project;
  91. ValueTree root;
  92. ScopedPointer<MarkerList> markersX, markersY;
  93. mutable UndoManager undoManager;
  94. bool saveAsXml, needsSaving;
  95. void checkRootObject();
  96. void recursivelyUpdateIDs (Drawable::ValueTreeWrapperBase& d, StringArray& recentlyUsedIdCache);
  97. Value getRootValueUndoable (const Identifier& name) const { return root.getPropertyAsValue (name, getUndoManager()); }
  98. Value getRootValueNonUndoable (const Identifier& name) const { return root.getPropertyAsValue (name, 0); }
  99. void save (OutputStream& output);
  100. bool load (InputStream& input);
  101. bool createItemProperties (Array <PropertyComponent*>& props, const String& itemId);
  102. const RelativeCoordinate findNamedCoordinate (const String& objectName, const String& edge) const;
  103. };
  104. #endif // __JUCER_DRAWABLEDOCUMENT_JUCEHEADER__