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.

182 lines
7.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "../CodeEditor/jucer_OpenDocumentManager.h"
  21. #include "../CodeEditor/jucer_SourceCodeEditor.h"
  22. #include "Components/jucer_ComponentTypeHandler.h"
  23. #include "jucer_PaintRoutine.h"
  24. #include "jucer_ComponentLayout.h"
  25. #include "jucer_BinaryResources.h"
  26. //==============================================================================
  27. class JucerDocument : public ChangeBroadcaster,
  28. private Timer,
  29. private CodeDocument::Listener
  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*, 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 (Project*);
  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. //==============================================================================
  99. void refreshCustomCodeFromDocument();
  100. protected:
  101. SourceCodeDocument* cpp;
  102. String className, componentName, templateFile;
  103. String parentClasses, constructorParams, variableInitialisers;
  104. bool fixedSize = false;
  105. int initialWidth = 600, initialHeight = 400;
  106. BinaryResources resources;
  107. virtual XmlElement* createXml() const;
  108. virtual bool loadFromXml (const XmlElement&);
  109. virtual void fillInGeneratedCode (GeneratedCode&) const;
  110. virtual void fillInPaintCode (GeneratedCode&) const;
  111. virtual void applyCustomPaintSnippets (StringArray&) {}
  112. static void addMethod (const String& base, const String& returnVal,
  113. const String& method, const String& initialContent,
  114. StringArray& baseClasses, StringArray& returnValues,
  115. StringArray& methods, StringArray& initialContents);
  116. private:
  117. UndoManager undoManager;
  118. int snapGridPixels = 8;
  119. bool snapActive = true, snapShown = true;
  120. float componentOverlayOpacity = 0.33f;
  121. StringArray activeExtraMethods;
  122. ScopedPointer<XmlElement> currentXML;
  123. ScopedPointer<Timer> userDocChangeTimer;
  124. void timerCallback() override;
  125. void codeDocumentTextInserted (const String& newText, int insertIndex) override;
  126. void codeDocumentTextDeleted (int startIndex, int endIndex) override;
  127. void userEditedCpp();
  128. void extractCustomPaintSnippetsFromCppFile (const String& cpp);
  129. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument)
  130. };