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.

181 lines
7.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. #include "../CodeEditor/jucer_OpenDocumentManager.h"
  20. #include "../CodeEditor/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. {
  30. public:
  31. JucerDocument (SourceCodeDocument* cpp);
  32. ~JucerDocument() override;
  33. static bool isValidJucerCppFile (const File&);
  34. static std::unique_ptr<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*, bool);
  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 (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 (int index) const = 0;
  70. virtual ComponentLayout* getComponentLayout() const = 0;
  71. virtual Component* createTestComponent (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, bool enable);
  79. bool isOptionalMethodEnabled (const String& methodSignature) const noexcept;
  80. //==============================================================================
  81. BinaryResources& getResources() noexcept { return resources; }
  82. //==============================================================================
  83. void setSnappingGrid (int numPixels, bool active, const bool shown);
  84. int getSnappingGridSize() const noexcept { return snapGridPixels; }
  85. bool isSnapActive (bool disableIfCtrlKeyDown) const noexcept;
  86. bool isSnapShown() const noexcept { return snapShown; }
  87. int snapPosition (int pos) const noexcept;
  88. //==============================================================================
  89. void setComponentOverlayOpacity (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. //==============================================================================
  98. void refreshCustomCodeFromDocument();
  99. protected:
  100. SourceCodeDocument* cpp;
  101. String className, componentName, templateFile;
  102. String parentClasses, constructorParams, variableInitialisers;
  103. bool fixedSize = false;
  104. int initialWidth = 600, initialHeight = 400;
  105. BinaryResources resources;
  106. virtual std::unique_ptr<XmlElement> createXml() const;
  107. virtual bool loadFromXml (const XmlElement&);
  108. virtual void fillInGeneratedCode (GeneratedCode&) const;
  109. virtual void fillInPaintCode (GeneratedCode&) const;
  110. virtual void applyCustomPaintSnippets (StringArray&) {}
  111. static void addMethod (const String& base, const String& returnVal,
  112. const String& method, const String& initialContent,
  113. StringArray& baseClasses, StringArray& returnValues,
  114. StringArray& methods, StringArray& initialContents);
  115. private:
  116. UndoManager undoManager;
  117. int snapGridPixels = 8;
  118. bool snapActive = true, snapShown = true;
  119. float componentOverlayOpacity = 0.33f;
  120. StringArray activeExtraMethods;
  121. std::unique_ptr<XmlElement> currentXML;
  122. std::unique_ptr<Timer> userDocChangeTimer;
  123. void timerCallback() override;
  124. void codeDocumentTextInserted (const String& newText, int insertIndex) override;
  125. void codeDocumentTextDeleted (int startIndex, int endIndex) override;
  126. void userEditedCpp();
  127. void extractCustomPaintSnippetsFromCppFile (const String& cpp);
  128. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument)
  129. };