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.

180 lines
7.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_JUCERDOCUMENT_JUCEHEADER__
  18. #define __JUCER_JUCERDOCUMENT_JUCEHEADER__
  19. #include "../Application/jucer_OpenDocumentManager.h"
  20. #include "../Code Editor/jucer_SourceCodeEditor.h"
  21. #include "components/jucer_ComponentTypeHandler.h"
  22. #include "jucer_PaintRoutine.h"
  23. #include "jucer_ComponentLayout.h"
  24. #include "jucer_BinaryResources.h"
  25. //==============================================================================
  26. class JucerDocument : public ChangeBroadcaster,
  27. private Timer,
  28. private CodeDocument::Listener,
  29. private OpenDocumentManager::DocumentCloseListener
  30. {
  31. public:
  32. JucerDocument (SourceCodeDocument* cpp);
  33. ~JucerDocument();
  34. static bool isValidJucerCppFile (const File&);
  35. static XmlElement* pullMetaDataFromCppFile (const String& cpp);
  36. static JucerDocument* createForCppFile (Project* project, const File&);
  37. void changed();
  38. void beginTransaction();
  39. void beginTransaction (const String& name);
  40. virtual JucerDocument* createCopy() = 0;
  41. virtual String getTypeName() const = 0;
  42. SourceCodeDocument& getCppDocument() const { return *cpp; }
  43. File getCppFile() const { return cpp->getFile(); }
  44. File getHeaderFile() const { return getCppFile().withFileExtension (".h"); }
  45. bool flushChangesToDocuments();
  46. bool reloadFromDocument();
  47. //==============================================================================
  48. UndoManager& getUndoManager() noexcept { return undoManager; }
  49. bool perform (UndoableAction* const action, const String& actionName);
  50. void refreshAllPropertyComps();
  51. //==============================================================================
  52. const String& getClassName() const noexcept { return className; }
  53. void setClassName (const String& newName);
  54. const String& getComponentName() const noexcept { return componentName; }
  55. void setComponentName (const String& newName);
  56. String getParentClassString() const { return parentClasses; }
  57. void setParentClasses (const String& classes);
  58. String getConstructorParams() const { return constructorParams; }
  59. void setConstructorParams (const String& newParams);
  60. String getVariableInitialisers() const { return variableInitialisers; }
  61. void setVariableInitialisers (const String& newInitlialisers);
  62. void setFixedSize (const bool isFixed);
  63. bool isFixedSize() const noexcept { return fixedSize; }
  64. void setInitialSize (int w, int h);
  65. int getInitialWidth() const noexcept { return initialWidth; }
  66. int getInitialHeight() const noexcept { return initialHeight; }
  67. //==============================================================================
  68. virtual int getNumPaintRoutines() const = 0;
  69. virtual StringArray getPaintRoutineNames() const = 0;
  70. virtual PaintRoutine* getPaintRoutine (const int index) const = 0;
  71. virtual ComponentLayout* getComponentLayout() const = 0;
  72. virtual Component* createTestComponent (const bool alwaysFillBackground) = 0;
  73. virtual void addExtraClassProperties (PropertyPanel&);
  74. //==============================================================================
  75. virtual void getOptionalMethods (StringArray& baseClasses,
  76. StringArray& returnValues,
  77. StringArray& methods,
  78. StringArray& initialContents) const;
  79. void setOptionalMethodEnabled (const String& methodSignature, const bool enable);
  80. bool isOptionalMethodEnabled (const String& methodSignature) const noexcept;
  81. //==============================================================================
  82. BinaryResources& getResources() noexcept { return resources; }
  83. //==============================================================================
  84. void setSnappingGrid (const int numPixels, const bool active, const bool shown);
  85. int getSnappingGridSize() const noexcept { return snapGridPixels; }
  86. bool isSnapActive (const bool disableIfCtrlKeyDown) const noexcept;
  87. bool isSnapShown() const noexcept { return snapShown; }
  88. int snapPosition (int pos) const noexcept;
  89. //==============================================================================
  90. void setComponentOverlayOpacity (const float alpha);
  91. float getComponentOverlayOpacity() const noexcept { return componentOverlayOpacity; }
  92. //==============================================================================
  93. static const char* const jucerCompXmlTag;
  94. bool findTemplateFiles (String& templateH, String& templateCpp) const;
  95. String getTemplateFile() const { return templateFile; }
  96. void setTemplateFile (const String&);
  97. static bool shouldUseTransMacro() noexcept { return true; }
  98. protected:
  99. SourceCodeDocument* cpp;
  100. String className, componentName, templateFile;
  101. String parentClasses, constructorParams, variableInitialisers;
  102. bool fixedSize;
  103. int initialWidth, initialHeight;
  104. BinaryResources resources;
  105. virtual XmlElement* createXml() const;
  106. virtual bool loadFromXml (const XmlElement&);
  107. virtual void fillInGeneratedCode (GeneratedCode&) const;
  108. virtual void fillInPaintCode (GeneratedCode&) const;
  109. static void addMethod (const String& base, const String& returnVal,
  110. const String& method, const String& initialContent,
  111. StringArray& baseClasses, StringArray& returnValues,
  112. StringArray& methods, StringArray& initialContents);
  113. private:
  114. UndoManager undoManager;
  115. int snapGridPixels;
  116. bool snapActive, snapShown;
  117. float componentOverlayOpacity;
  118. StringArray activeExtraMethods;
  119. ScopedPointer<XmlElement> currentXML;
  120. ScopedPointer<Timer> userDocChangeTimer;
  121. void timerCallback() override;
  122. void codeDocumentTextInserted (const String& newText, int insertIndex) override;
  123. void codeDocumentTextDeleted (int startIndex, int endIndex) override;
  124. void userEditedCpp();
  125. bool documentAboutToClose (OpenDocumentManager::Document*) override;
  126. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument);
  127. };
  128. #endif // __JUCER_JUCERDOCUMENT_JUCEHEADER__