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.

139 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. #include "Components/jucer_ComponentTypeHandler.h"
  20. class JucerDocument;
  21. //==============================================================================
  22. /**
  23. Manages the set of sub-components for a JucerDocument.
  24. */
  25. class ComponentLayout
  26. {
  27. public:
  28. //==============================================================================
  29. ComponentLayout();
  30. ~ComponentLayout();
  31. //==============================================================================
  32. void changed();
  33. int getNumComponents() const noexcept { return components.size(); }
  34. Component* getComponent (const int index) const noexcept { return components [index]; }
  35. int indexOfComponent (Component* const comp) const noexcept { return components.indexOf (comp); }
  36. bool containsComponent (Component* const comp) const noexcept { return components.contains (comp); }
  37. //==============================================================================
  38. void clearComponents();
  39. void removeComponent (Component* comp, bool undoable);
  40. Component* addNewComponent (ComponentTypeHandler* const type, int x, int y);
  41. Component* addComponentFromXml (const XmlElement& xml, bool undoable);
  42. Component* findComponentWithId (int64 componentId) const;
  43. //==============================================================================
  44. void componentToFront (Component* comp, bool undoable);
  45. void componentToBack (Component* comp, bool undoable);
  46. void setComponentPosition (Component* comp, const RelativePositionedRectangle& newPos, bool undoable);
  47. void setComponentBoundsAndProperties (Component* comp, const Rectangle<int>& newBounds, Component* referenceComponent, bool undoable);
  48. void updateStoredComponentPosition (Component* comp, bool undoable);
  49. //==============================================================================
  50. Component* getComponentRelativePosTarget (Component* comp, int whichDimension) const;
  51. void setComponentRelativeTarget (Component* comp, int whichDimension, Component* compToBeRelativeTo);
  52. // checks recursively whether the comp depends on the given comp for its position
  53. bool dependsOnComponentForRelativePos (Component* comp, Component* possibleDependee) const;
  54. bool isComponentPositionRelative (Component* comp) const;
  55. PopupMenu getRelativeTargetMenu (Component* comp, int whichDimension) const;
  56. void processRelativeTargetMenuResult (Component* comp, int whichDimension, int menuResultID);
  57. //==============================================================================
  58. void setComponentMemberVariableName (Component* comp, const String& newName);
  59. String getComponentMemberVariableName (Component* comp) const;
  60. //==============================================================================
  61. void setComponentVirtualClassName (Component* comp, const String& newName);
  62. String getComponentVirtualClassName (Component* comp) const;
  63. //==============================================================================
  64. SelectedItemSet <Component*>& getSelectedSet() { return selected; }
  65. static const char* const clipboardXmlTag;
  66. void copySelectedToClipboard();
  67. void paste();
  68. void deleteSelected();
  69. void selectAll();
  70. void selectedToFront();
  71. void selectedToBack();
  72. void alignTop();
  73. void alignRight();
  74. void alignBottom();
  75. void alignLeft();
  76. void startDragging();
  77. void dragSelectedComps (int dxFromDragStart, int dyFromDragStart, const bool allowSnap = true);
  78. void endDragging();
  79. void moveSelectedComps (int dx, int dy, bool snap);
  80. void stretchSelectedComps (int dw, int dh, bool allowSnap);
  81. void bringLostItemsBackOnScreen (int width, int height);
  82. //==============================================================================
  83. void setDocument (JucerDocument* const doc) { document = doc; }
  84. JucerDocument* getDocument() const noexcept { return document; }
  85. //==============================================================================
  86. void addToXml (XmlElement& xml) const;
  87. void fillInGeneratedCode (GeneratedCode& code) const;
  88. void perform (std::unique_ptr<UndoableAction> action, const String& actionName);
  89. void moveComponentZOrder (int oldIndex, int newIndex);
  90. private:
  91. JucerDocument* document;
  92. OwnedArray<Component> components;
  93. SelectedItemSet <Component*> selected;
  94. int nextCompUID;
  95. int addComponentIndexAdded = 0;
  96. String getUnusedMemberName (String nameRoot, Component* comp) const;
  97. };
  98. void positionToCode (const RelativePositionedRectangle& position,
  99. const ComponentLayout* layout,
  100. String& x, String& y, String& w, String& h);