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.

178 lines
7.5KB

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