Audio plugin host https://kx.studio/carla
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.

182 lines
8.6KB

  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 JUCE_DRAGANDDROPCONTAINER_H_INCLUDED
  18. #define JUCE_DRAGANDDROPCONTAINER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Enables drag-and-drop behaviour for a component and all its sub-components.
  22. For a component to be able to make or receive drag-and-drop events, one of its parent
  23. components must derive from this class. It's probably best for the top-level
  24. component to implement it.
  25. Then to start a drag operation, any sub-component can just call the startDragging()
  26. method, and this object will take over, tracking the mouse and sending appropriate
  27. callbacks to any child components derived from DragAndDropTarget which the mouse
  28. moves over.
  29. Note: If all that you need to do is to respond to files being drag-and-dropped from
  30. the operating system onto your component, you don't need any of these classes: you can do this
  31. simply by overriding Component::filesDropped().
  32. @see DragAndDropTarget
  33. */
  34. class JUCE_API DragAndDropContainer
  35. {
  36. public:
  37. //==============================================================================
  38. /** Creates a DragAndDropContainer.
  39. The object that derives from this class must also be a Component.
  40. */
  41. DragAndDropContainer();
  42. /** Destructor. */
  43. virtual ~DragAndDropContainer();
  44. //==============================================================================
  45. /** Begins a drag-and-drop operation.
  46. This starts a drag-and-drop operation - call it when the user drags the
  47. mouse in your drag-source component, and this object will track mouse
  48. movements until the user lets go of the mouse button, and will send
  49. appropriate messages to DragAndDropTarget objects that the mouse moves
  50. over.
  51. findParentDragContainerFor() is a handy method to call to find the
  52. drag container to use for a component.
  53. @param sourceDescription a string or value to use as the description of the thing being dragged -
  54. this will be passed to the objects that might be dropped-onto so they can
  55. decide whether they want to handle it
  56. @param sourceComponent the component that is being dragged
  57. @param dragImage the image to drag around underneath the mouse. If this is a null image,
  58. a snapshot of the sourceComponent will be used instead.
  59. @param allowDraggingToOtherJuceWindows if true, the dragged component will appear as a desktop
  60. window, and can be dragged to DragAndDropTargets that are the
  61. children of components other than this one.
  62. @param imageOffsetFromMouse if an image has been passed-in, this specifies the offset
  63. at which the image should be drawn from the mouse. If it isn't
  64. specified, then the image will be centred around the mouse. If
  65. an image hasn't been passed-in, this will be ignored.
  66. */
  67. void startDragging (const var& sourceDescription,
  68. Component* sourceComponent,
  69. Image dragImage = Image::null,
  70. bool allowDraggingToOtherJuceWindows = false,
  71. const Point<int>* imageOffsetFromMouse = nullptr);
  72. /** Returns true if something is currently being dragged. */
  73. bool isDragAndDropActive() const;
  74. /** Returns the description of the thing that's currently being dragged.
  75. If nothing's being dragged, this will return a null var, otherwise it'll return
  76. the var that was passed into startDragging().
  77. @see startDragging
  78. */
  79. var getCurrentDragDescription() const;
  80. /** Utility to find the DragAndDropContainer for a given Component.
  81. This will search up this component's parent hierarchy looking for the first
  82. parent component which is a DragAndDropContainer.
  83. It's useful when a component wants to call startDragging but doesn't know
  84. the DragAndDropContainer it should to use.
  85. Obviously this may return nullptr if it doesn't find a suitable component.
  86. */
  87. static DragAndDropContainer* findParentDragContainerFor (Component* childComponent);
  88. //==============================================================================
  89. /** This performs a synchronous drag-and-drop of a set of files to some external
  90. application.
  91. You can call this function in response to a mouseDrag callback, and it will
  92. block, running its own internal message loop and tracking the mouse, while it
  93. uses a native operating system drag-and-drop operation to move or copy some
  94. files to another application.
  95. @param files a list of filenames to drag
  96. @param canMoveFiles if true, the app that receives the files is allowed to move the files to a new location
  97. (if this is appropriate). If false, the receiver is expected to make a copy of them.
  98. @returns true if the files were successfully dropped somewhere, or false if it
  99. was interrupted
  100. @see performExternalDragDropOfText
  101. */
  102. static bool performExternalDragDropOfFiles (const StringArray& files, bool canMoveFiles);
  103. /** This performs a synchronous drag-and-drop of a block of text to some external
  104. application.
  105. You can call this function in response to a mouseDrag callback, and it will
  106. block, running its own internal message loop and tracking the mouse, while it
  107. uses a native operating system drag-and-drop operation to move or copy some
  108. text to another application.
  109. @param text the text to copy
  110. @returns true if the text was successfully dropped somewhere, or false if it
  111. was interrupted
  112. @see performExternalDragDropOfFiles
  113. */
  114. static bool performExternalDragDropOfText (const String& text);
  115. protected:
  116. /** Override this if you want to be able to perform an external drag a set of files
  117. when the user drags outside of this container component.
  118. This method will be called when a drag operation moves outside the Juce-based window,
  119. and if you want it to then perform a file drag-and-drop, add the filenames you want
  120. to the array passed in, and return true.
  121. @param sourceDetails information about the source of the drag operation
  122. @param files on return, the filenames you want to drag
  123. @param canMoveFiles on return, true if it's ok for the receiver to move the files; false if
  124. it must make a copy of them (see the performExternalDragDropOfFiles() method)
  125. @see performExternalDragDropOfFiles
  126. */
  127. virtual bool shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails,
  128. StringArray& files, bool& canMoveFiles);
  129. private:
  130. //==============================================================================
  131. class DragImageComponent;
  132. friend class DragImageComponent;
  133. friend struct ContainerDeletePolicy<DragImageComponent>;
  134. ScopedPointer<DragImageComponent> dragImageComponent;
  135. JUCE_DEPRECATED (virtual bool shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)) { return false; }
  136. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DragAndDropContainer)
  137. };
  138. #endif // JUCE_DRAGANDDROPCONTAINER_H_INCLUDED