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.

136 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_COMPONENTLAYOUT_JUCEHEADER__
  18. #define __JUCER_COMPONENTLAYOUT_JUCEHEADER__
  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, const bool undoable);
  40. Component* addNewComponent (ComponentTypeHandler* const type, int x, int y);
  41. Component* addComponentFromXml (const XmlElement& xml, const bool undoable);
  42. Component* findComponentWithId (const int64 componentId) const;
  43. //==============================================================================
  44. void componentToFront (Component* comp, const bool undoable);
  45. void componentToBack (Component* comp, const bool undoable);
  46. void setComponentPosition (Component* comp, const RelativePositionedRectangle& newPos, const bool undoable);
  47. void updateStoredComponentPosition (Component* comp, const bool undoable);
  48. //==============================================================================
  49. Component* getComponentRelativePosTarget (Component* comp, int whichDimension) const;
  50. void setComponentRelativeTarget (Component* comp, int whichDimension, Component* compToBeRelativeTo);
  51. // checks recursively whether the comp depends on the given comp for its position
  52. bool dependsOnComponentForRelativePos (Component* comp, Component* possibleDependee) const;
  53. PopupMenu getRelativeTargetMenu (Component* comp, int whichDimension) const;
  54. void processRelativeTargetMenuResult (Component* comp, int whichDimension, int menuResultID);
  55. //==============================================================================
  56. void setComponentMemberVariableName (Component* comp, const String& newName);
  57. String getComponentMemberVariableName (Component* comp) const;
  58. //==============================================================================
  59. void setComponentVirtualClassName (Component* comp, const String& newName);
  60. String getComponentVirtualClassName (Component* comp) const;
  61. //==============================================================================
  62. SelectedItemSet <Component*>& getSelectedSet() { return selected; }
  63. static const char* const clipboardXmlTag;
  64. void copySelectedToClipboard();
  65. void paste();
  66. void deleteSelected();
  67. void selectAll();
  68. void selectedToFront();
  69. void selectedToBack();
  70. void startDragging();
  71. void dragSelectedComps (int dxFromDragStart, int dyFromDragStart, const bool allowSnap = true);
  72. void endDragging();
  73. void moveSelectedComps (int dx, int dy, bool snap);
  74. void stretchSelectedComps (int dw, int dh, bool allowSnap);
  75. void bringLostItemsBackOnScreen (int width, int height);
  76. //==============================================================================
  77. void setDocument (JucerDocument* const doc) { document = doc; }
  78. JucerDocument* getDocument() const noexcept { return document; }
  79. //==============================================================================
  80. void addToXml (XmlElement& xml) const;
  81. void fillInGeneratedCode (GeneratedCode& code) const;
  82. void perform (UndoableAction* action, const String& actionName);
  83. private:
  84. JucerDocument* document;
  85. OwnedArray <Component> components;
  86. SelectedItemSet <Component*> selected;
  87. int nextCompUID;
  88. String getUnusedMemberName (String nameRoot, Component* comp) const;
  89. friend class FrontBackCompAction;
  90. friend class DeleteCompAction;
  91. void moveComponentZOrder (int oldIndex, int newIndex);
  92. };
  93. void positionToCode (const RelativePositionedRectangle& position,
  94. const ComponentLayout* layout,
  95. String& x, String& y, String& w, String& h);
  96. #endif // __JUCER_COMPONENTLAYOUT_JUCEHEADER__