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.

135 lines
5.5KB

  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 updateStoredComponentPosition (Component* comp, const 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. PopupMenu getRelativeTargetMenu (Component* comp, int whichDimension) const;
  55. void processRelativeTargetMenuResult (Component* comp, int whichDimension, int menuResultID);
  56. //==============================================================================
  57. void setComponentMemberVariableName (Component* comp, const String& newName);
  58. String getComponentMemberVariableName (Component* comp) const;
  59. //==============================================================================
  60. void setComponentVirtualClassName (Component* comp, const String& newName);
  61. String getComponentVirtualClassName (Component* comp) const;
  62. //==============================================================================
  63. SelectedItemSet <Component*>& getSelectedSet() { return selected; }
  64. static const char* const clipboardXmlTag;
  65. void copySelectedToClipboard();
  66. void paste();
  67. void deleteSelected();
  68. void selectAll();
  69. void selectedToFront();
  70. void selectedToBack();
  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);