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.

177 lines
7.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_JUCERDOCUMENT_JUCEHEADER__
  19. #define __JUCER_JUCERDOCUMENT_JUCEHEADER__
  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. {
  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. 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();
  121. void codeDocumentTextInserted (const String& newText, int insertIndex);
  122. void codeDocumentTextDeleted (int startIndex, int endIndex);
  123. void userEditedCpp();
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument);
  125. };
  126. #endif // __JUCER_JUCERDOCUMENT_JUCEHEADER__