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.

176 lines
7.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. #include "../Application/jucer_OpenDocumentManager.h"
  19. #include "../Code Editor/jucer_SourceCodeEditor.h"
  20. #include "components/jucer_ComponentTypeHandler.h"
  21. #include "jucer_PaintRoutine.h"
  22. #include "jucer_ComponentLayout.h"
  23. #include "jucer_BinaryResources.h"
  24. //==============================================================================
  25. class JucerDocument : public ChangeBroadcaster,
  26. private Timer,
  27. private CodeDocument::Listener,
  28. private OpenDocumentManager::DocumentCloseListener
  29. {
  30. public:
  31. JucerDocument (SourceCodeDocument* cpp);
  32. ~JucerDocument();
  33. static bool isValidJucerCppFile (const File&);
  34. static XmlElement* pullMetaDataFromCppFile (const String& cpp);
  35. static JucerDocument* createForCppFile (Project*, const File&);
  36. void changed();
  37. void beginTransaction();
  38. void beginTransaction (const String& name);
  39. virtual JucerDocument* createCopy() = 0;
  40. virtual String getTypeName() const = 0;
  41. SourceCodeDocument& getCppDocument() const { return *cpp; }
  42. File getCppFile() const { return cpp->getFile(); }
  43. File getHeaderFile() const { return getCppFile().withFileExtension (".h"); }
  44. bool flushChangesToDocuments (Project*);
  45. bool reloadFromDocument();
  46. //==============================================================================
  47. UndoManager& getUndoManager() noexcept { return undoManager; }
  48. bool perform (UndoableAction* const action, const String& actionName);
  49. void refreshAllPropertyComps();
  50. //==============================================================================
  51. const String& getClassName() const noexcept { return className; }
  52. void setClassName (const String& newName);
  53. const String& getComponentName() const noexcept { return componentName; }
  54. void setComponentName (const String& newName);
  55. String getParentClassString() const { return parentClasses; }
  56. void setParentClasses (const String& classes);
  57. String getConstructorParams() const { return constructorParams; }
  58. void setConstructorParams (const String& newParams);
  59. String getVariableInitialisers() const { return variableInitialisers; }
  60. void setVariableInitialisers (const String& newInitlialisers);
  61. void setFixedSize (const bool isFixed);
  62. bool isFixedSize() const noexcept { return fixedSize; }
  63. void setInitialSize (int w, int h);
  64. int getInitialWidth() const noexcept { return initialWidth; }
  65. int getInitialHeight() const noexcept { return initialHeight; }
  66. //==============================================================================
  67. virtual int getNumPaintRoutines() const = 0;
  68. virtual StringArray getPaintRoutineNames() const = 0;
  69. virtual PaintRoutine* getPaintRoutine (const int index) const = 0;
  70. virtual ComponentLayout* getComponentLayout() const = 0;
  71. virtual Component* createTestComponent (const bool alwaysFillBackground) = 0;
  72. virtual void addExtraClassProperties (PropertyPanel&);
  73. //==============================================================================
  74. virtual void getOptionalMethods (StringArray& baseClasses,
  75. StringArray& returnValues,
  76. StringArray& methods,
  77. StringArray& initialContents) const;
  78. void setOptionalMethodEnabled (const String& methodSignature, const bool enable);
  79. bool isOptionalMethodEnabled (const String& methodSignature) const noexcept;
  80. //==============================================================================
  81. BinaryResources& getResources() noexcept { return resources; }
  82. //==============================================================================
  83. void setSnappingGrid (const int numPixels, const bool active, const bool shown);
  84. int getSnappingGridSize() const noexcept { return snapGridPixels; }
  85. bool isSnapActive (const bool disableIfCtrlKeyDown) const noexcept;
  86. bool isSnapShown() const noexcept { return snapShown; }
  87. int snapPosition (int pos) const noexcept;
  88. //==============================================================================
  89. void setComponentOverlayOpacity (const float alpha);
  90. float getComponentOverlayOpacity() const noexcept { return componentOverlayOpacity; }
  91. //==============================================================================
  92. static const char* const jucerCompXmlTag;
  93. bool findTemplateFiles (String& templateH, String& templateCpp) const;
  94. String getTemplateFile() const { return templateFile; }
  95. void setTemplateFile (const String&);
  96. static bool shouldUseTransMacro() noexcept { return true; }
  97. protected:
  98. SourceCodeDocument* cpp;
  99. String className, componentName, templateFile;
  100. String parentClasses, constructorParams, variableInitialisers;
  101. bool fixedSize;
  102. int initialWidth, initialHeight;
  103. BinaryResources resources;
  104. virtual XmlElement* createXml() const;
  105. virtual bool loadFromXml (const XmlElement&);
  106. virtual void fillInGeneratedCode (GeneratedCode&) const;
  107. virtual void fillInPaintCode (GeneratedCode&) const;
  108. static void addMethod (const String& base, const String& returnVal,
  109. const String& method, const String& initialContent,
  110. StringArray& baseClasses, StringArray& returnValues,
  111. StringArray& methods, StringArray& initialContents);
  112. private:
  113. UndoManager undoManager;
  114. int snapGridPixels;
  115. bool snapActive, snapShown;
  116. float componentOverlayOpacity;
  117. StringArray activeExtraMethods;
  118. ScopedPointer<XmlElement> currentXML;
  119. ScopedPointer<Timer> userDocChangeTimer;
  120. void timerCallback() override;
  121. void codeDocumentTextInserted (const String& newText, int insertIndex) override;
  122. void codeDocumentTextDeleted (int startIndex, int endIndex) override;
  123. void userEditedCpp();
  124. bool documentAboutToClose (OpenDocumentManager::Document*) override;
  125. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument)
  126. };