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.

132 lines
5.6KB

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