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.

133 lines
5.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 "components/jucer_ComponentTypeHandler.h"
  19. class JucerDocument;
  20. //==============================================================================
  21. /**
  22. Manages the set of sub-components for a JucerDocument.
  23. */
  24. class ComponentLayout
  25. {
  26. public:
  27. //==============================================================================
  28. ComponentLayout();
  29. ~ComponentLayout();
  30. //==============================================================================
  31. void changed();
  32. int getNumComponents() const noexcept { return components.size(); }
  33. Component* getComponent (const int index) const noexcept { return components [index]; }
  34. int indexOfComponent (Component* const comp) const noexcept { return components.indexOf (comp); }
  35. bool containsComponent (Component* const comp) const noexcept { return components.contains (comp); }
  36. //==============================================================================
  37. void clearComponents();
  38. void removeComponent (Component* comp, const bool undoable);
  39. Component* addNewComponent (ComponentTypeHandler* const type, int x, int y);
  40. Component* addComponentFromXml (const XmlElement& xml, const bool undoable);
  41. Component* findComponentWithId (const int64 componentId) const;
  42. //==============================================================================
  43. void componentToFront (Component* comp, const bool undoable);
  44. void componentToBack (Component* comp, const bool undoable);
  45. void setComponentPosition (Component* comp, const RelativePositionedRectangle& newPos, const bool undoable);
  46. void updateStoredComponentPosition (Component* comp, const bool undoable);
  47. //==============================================================================
  48. Component* getComponentRelativePosTarget (Component* comp, int whichDimension) const;
  49. void setComponentRelativeTarget (Component* comp, int whichDimension, Component* compToBeRelativeTo);
  50. // checks recursively whether the comp depends on the given comp for its position
  51. bool dependsOnComponentForRelativePos (Component* comp, Component* possibleDependee) const;
  52. PopupMenu getRelativeTargetMenu (Component* comp, int whichDimension) const;
  53. void processRelativeTargetMenuResult (Component* comp, int whichDimension, int menuResultID);
  54. //==============================================================================
  55. void setComponentMemberVariableName (Component* comp, const String& newName);
  56. String getComponentMemberVariableName (Component* comp) const;
  57. //==============================================================================
  58. void setComponentVirtualClassName (Component* comp, const String& newName);
  59. String getComponentVirtualClassName (Component* comp) const;
  60. //==============================================================================
  61. SelectedItemSet <Component*>& getSelectedSet() { return selected; }
  62. static const char* const clipboardXmlTag;
  63. void copySelectedToClipboard();
  64. void paste();
  65. void deleteSelected();
  66. void selectAll();
  67. void selectedToFront();
  68. void selectedToBack();
  69. void startDragging();
  70. void dragSelectedComps (int dxFromDragStart, int dyFromDragStart, const bool allowSnap = true);
  71. void endDragging();
  72. void moveSelectedComps (int dx, int dy, bool snap);
  73. void stretchSelectedComps (int dw, int dh, bool allowSnap);
  74. void bringLostItemsBackOnScreen (int width, int height);
  75. //==============================================================================
  76. void setDocument (JucerDocument* const doc) { document = doc; }
  77. JucerDocument* getDocument() const noexcept { return document; }
  78. //==============================================================================
  79. void addToXml (XmlElement& xml) const;
  80. void fillInGeneratedCode (GeneratedCode& code) const;
  81. void perform (UndoableAction* action, const String& actionName);
  82. private:
  83. JucerDocument* document;
  84. OwnedArray <Component> components;
  85. SelectedItemSet <Component*> selected;
  86. int nextCompUID;
  87. String getUnusedMemberName (String nameRoot, Component* comp) const;
  88. friend class FrontBackCompAction;
  89. friend class DeleteCompAction;
  90. void moveComponentZOrder (int oldIndex, int newIndex);
  91. };
  92. void positionToCode (const RelativePositionedRectangle& position,
  93. const ComponentLayout* layout,
  94. String& x, String& y, String& w, String& h);