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.

132 lines
5.6KB

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