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.

juce_DragAndDropTarget.h 6.4KB

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