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.

140 lines
5.8KB

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