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.

136 lines
5.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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. //==============================================================================
  24. class ComponentDocument : public ValueTree::Listener
  25. {
  26. public:
  27. //==============================================================================
  28. ComponentDocument (Project* project, const File& cppFile);
  29. ~ComponentDocument();
  30. static bool isComponentFile (const File& file);
  31. bool save();
  32. bool reload();
  33. bool hasChangedSinceLastSave();
  34. typedef SelectedItemSet<uint32> SelectedItems;
  35. //==============================================================================
  36. Value getClassName() { return getRootValue ("className"); }
  37. Value getClassDescription() { return getRootValue ("classDesc"); }
  38. Value getCanvasWidth() { return root.getPropertyAsValue ("width", 0); } // (deliberately not undoable)
  39. Value getCanvasHeight() { return root.getPropertyAsValue ("height", 0); }
  40. const String getNonExistentMemberName (String suggestedName);
  41. //==============================================================================
  42. int getNumComponents() const;
  43. const ValueTree getComponent (int index) const;
  44. const ValueTree getComponentWithMemberName (const String& name) const;
  45. Component* createComponent (int index);
  46. void updateComponent (Component* comp);
  47. bool containsComponent (Component* comp) const;
  48. const ValueTree getComponentState (Component* comp) const;
  49. void getComponentProperties (Array <PropertyComponent*>& props, Component* comp);
  50. bool isStateForComponent (const ValueTree& storedState, Component* comp) const;
  51. Coordinate::MarkerResolver* createMarkerResolver (const ValueTree& state);
  52. const StringArray getComponentMarkers (bool horizontal) const;
  53. const RectangleCoordinates getCoordsFor (const ValueTree& componentState) const;
  54. bool setCoordsFor (ValueTree& componentState, const RectangleCoordinates& newSize);
  55. void addNewComponentMenuItems (PopupMenu& menu) const;
  56. void performNewComponentMenuItem (int menuResultCode);
  57. //==============================================================================
  58. void beginDrag (const Array<Component*>& items, const MouseEvent& e,
  59. Component* parentForOverlays, const ResizableBorderComponent::Zone& zone);
  60. void continueDrag (const MouseEvent& e);
  61. void endDrag (const MouseEvent& e);
  62. //==============================================================================
  63. ValueTree& getRoot() { return root; }
  64. UndoManager* getUndoManager();
  65. void beginNewTransaction();
  66. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& property);
  67. void valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged);
  68. void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged);
  69. private:
  70. Project* project;
  71. File cppFile;
  72. ValueTree root;
  73. UndoManager undoManager;
  74. bool changedSinceSaved;
  75. void checkRootObject();
  76. ValueTree getComponentGroup() const;
  77. Value getRootValue (const var::identifier& name) { return root.getPropertyAsValue (name, getUndoManager()); }
  78. void writeCode (OutputStream& cpp, OutputStream& header);
  79. void writeMetadata (OutputStream& out);
  80. };
  81. //==============================================================================
  82. class ComponentTypeHandler
  83. {
  84. public:
  85. //==============================================================================
  86. ComponentTypeHandler (const String& name_, const String& xmlTag_, const String& memberNameRoot_);
  87. virtual ~ComponentTypeHandler();
  88. const String& getName() const { return name; }
  89. const String& getXmlTag() const { return xmlTag; }
  90. const String& getMemberNameRoot() const { return memberNameRoot; }
  91. virtual Component* createComponent() = 0;
  92. virtual const Rectangle<int> getDefaultSize() = 0;
  93. virtual void updateComponent (ComponentDocument& document, Component* comp, const ValueTree& state);
  94. virtual void initialiseNewItem (ComponentDocument& document, ValueTree& state);
  95. virtual void createPropertyEditors (ComponentDocument& document, ValueTree& state, Array <PropertyComponent*>& props);
  96. Value getValue (const var::identifier& name, ValueTree& state, ComponentDocument& document) const;
  97. //==============================================================================
  98. protected:
  99. const String name, xmlTag, memberNameRoot;
  100. };
  101. #endif // __JUCER_COMPONENTDOCUMENT_JUCEHEADER__