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.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. 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 (UndoableAction* action, const String& actionName);
  89. private:
  90. JucerDocument* document;
  91. OwnedArray <Component> components;
  92. SelectedItemSet <Component*> selected;
  93. int nextCompUID;
  94. String getUnusedMemberName (String nameRoot, Component* comp) const;
  95. friend class FrontBackCompAction;
  96. friend class DeleteCompAction;
  97. void moveComponentZOrder (int oldIndex, int newIndex);
  98. };
  99. void positionToCode (const RelativePositionedRectangle& position,
  100. const ComponentLayout* layout,
  101. String& x, String& y, String& w, String& h);