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.

137 lines
5.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_COMPONENTLAYOUT_JUCEHEADER__
  19. #define __JUCER_COMPONENTLAYOUT_JUCEHEADER__
  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);
  97. #endif // __JUCER_COMPONENTLAYOUT_JUCEHEADER__