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.

153 lines
6.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_DRAGANDDROPTARGET_H_INCLUDED
  18. #define JUCE_DRAGANDDROPTARGET_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Components derived from this class can have things dropped onto them by a DragAndDropContainer.
  22. To create a component that can receive things drag-and-dropped by a DragAndDropContainer,
  23. derive your component from this class, and make sure that it is somewhere inside a
  24. DragAndDropContainer component.
  25. Note: If all that you need to do is to respond to files being drag-and-dropped from
  26. the operating system onto your component, you don't need any of these classes: instead
  27. see the FileDragAndDropTarget class.
  28. @see DragAndDropContainer, FileDragAndDropTarget
  29. */
  30. class JUCE_API DragAndDropTarget
  31. {
  32. public:
  33. /** Destructor. */
  34. virtual ~DragAndDropTarget() {}
  35. //==============================================================================
  36. /** Contains details about the source of a drag-and-drop operation.
  37. The contents of this
  38. */
  39. class JUCE_API SourceDetails
  40. {
  41. public:
  42. /** Creates a SourceDetails object from its various settings. */
  43. SourceDetails (const var& description,
  44. Component* sourceComponent,
  45. Point<int> localPosition) noexcept;
  46. /** A descriptor for the drag - this is set DragAndDropContainer::startDragging(). */
  47. var description;
  48. /** The component from the drag operation was started. */
  49. WeakReference<Component> sourceComponent;
  50. /** The local position of the mouse, relative to the target component.
  51. Note that for calls such as isInterestedInDragSource(), this may be a null position.
  52. */
  53. Point<int> localPosition;
  54. };
  55. //==============================================================================
  56. /** Callback to check whether this target is interested in the type of object being
  57. dragged.
  58. @param dragSourceDetails contains information about the source of the drag operation.
  59. @returns true if this component wants to receive the other callbacks regarging this
  60. type of object; if it returns false, no other callbacks will be made.
  61. */
  62. virtual bool isInterestedInDragSource (const SourceDetails& dragSourceDetails) = 0;
  63. /** Callback to indicate that something is being dragged over this component.
  64. This gets called when the user moves the mouse into this component while dragging
  65. something.
  66. Use this callback as a trigger to make your component repaint itself to give the
  67. user feedback about whether the item can be dropped here or not.
  68. @param dragSourceDetails contains information about the source of the drag operation.
  69. @see itemDragExit
  70. */
  71. virtual void itemDragEnter (const SourceDetails& dragSourceDetails);
  72. /** Callback to indicate that the user is dragging something over this component.
  73. This gets called when the user moves the mouse over this component while dragging
  74. something. Normally overriding itemDragEnter() and itemDragExit() are enough, but
  75. this lets you know what happens in-between.
  76. @param dragSourceDetails contains information about the source of the drag operation.
  77. */
  78. virtual void itemDragMove (const SourceDetails& dragSourceDetails);
  79. /** Callback to indicate that something has been dragged off the edge of this component.
  80. This gets called when the user moves the mouse out of this component while dragging
  81. something.
  82. If you've used itemDragEnter() to repaint your component and give feedback, use this
  83. as a signal to repaint it in its normal state.
  84. @param dragSourceDetails contains information about the source of the drag operation.
  85. @see itemDragEnter
  86. */
  87. virtual void itemDragExit (const SourceDetails& dragSourceDetails);
  88. /** Callback to indicate that the user has dropped something onto this component.
  89. When the user drops an item this get called, and you can use the description to
  90. work out whether your object wants to deal with it or not.
  91. Note that after this is called, the itemDragExit method may not be called, so you should
  92. clean up in here if there's anything you need to do when the drag finishes.
  93. @param dragSourceDetails contains information about the source of the drag operation.
  94. */
  95. virtual void itemDropped (const SourceDetails& dragSourceDetails) = 0;
  96. /** Overriding this allows the target to tell the drag container whether to
  97. draw the drag image while the cursor is over it.
  98. By default it returns true, but if you return false, then the normal drag
  99. image will not be shown when the cursor is over this target.
  100. */
  101. virtual bool shouldDrawDragImageWhenOver();
  102. //==============================================================================
  103. private:
  104. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  105. // The parameters for these methods have changed - please update your code!
  106. virtual void isInterestedInDragSource (const String&, Component*) {}
  107. virtual int itemDragEnter (const String&, Component*, int, int) { return 0; }
  108. virtual int itemDragMove (const String&, Component*, int, int) { return 0; }
  109. virtual int itemDragExit (const String&, Component*) { return 0; }
  110. virtual int itemDropped (const String&, Component*, int, int) { return 0; }
  111. #endif
  112. };
  113. #endif // JUCE_DRAGANDDROPTARGET_H_INCLUDED