29bool juce_performDragDropFiles (
const StringArray&,
const bool copyFiles,
bool& shouldStop);
30bool juce_performDragDropText (
const String&,
bool& shouldStop);
44 : sourceDetails (desc, sourceComponent,
Point<int>()),
48 imageOffset (transformOffsetCoordinates (sourceComponent, offset)),
54 if (mouseDragSource ==
nullptr)
55 mouseDragSource = sourceComponent;
57 mouseDragSource->addMouseListener (
this,
false);
68 owner.dragImageComponents.remove (owner.dragImageComponents.indexOf (
this),
false);
70 if (mouseDragSource !=
nullptr)
72 mouseDragSource->removeMouseListener (
this);
74 if (
auto* current = getCurrentlyOver())
75 if (current->isInterestedInDragSource (sourceDetails))
76 current->itemDragExit (sourceDetails);
95 if (mouseDragSource !=
nullptr)
96 mouseDragSource->removeMouseListener (
this);
106 details.localPosition = localPosition;
112 parent->removeChildComponent (
this);
116 currentlyOverComp =
nullptr;
137 details.localPosition = localPosition;
141 maintainKeyboardFocusWhenPossible();
162 if (getCurrentlyOver() !=
nullptr)
163 lastTimeOverTarget = now;
168 forceMouseCursorUpdate();
171 void updateImage (
const ScaledImage&
newImage)
180 forceMouseCursorUpdate();
190 if (isOriginalInputSource (s) && ! s.isDragging())
192 if (mouseDragSource !=
nullptr)
193 mouseDragSource->removeMouseListener (
this);
210 dismissWithAnimation (
true);
221 return targetComponent == mouseDragSource;
234 bool hasCheckedForExternalDrag =
false;
235 Time lastTimeOverTarget;
236 int originalInputSourceIndex;
238 bool canHaveKeyboardFocus =
false;
240 void maintainKeyboardFocusWhenPossible()
245 if (canHaveKeyboardFocus)
251 const auto bounds = image.getScaledBounds().toNearestInt();
252 setSize (bounds.getWidth(), bounds.getHeight());
255 void forceMouseCursorUpdate()
260 DragAndDropTarget* getCurrentlyOver()
const noexcept
262 return dynamic_cast<DragAndDropTarget*
> (currentlyOverComp.
get());
269 for (
auto i =
desktop.getNumComponents(); --i >= 0;)
286 Point<int> transformOffsetCoordinates (
const Component*
const sourceComponent, Point<int>
offsetInSource)
const
304 while (
hit !=
nullptr)
306 if (
auto*
ddt =
dynamic_cast<DragAndDropTarget*
> (
hit))
310 hit =
hit->getParentComponent();
316 void setNewScreenPos (Point<int>
screenPos)
326 void sendDragMove (DragAndDropTarget::SourceDetails&
details)
const
328 if (
auto* target = getCurrentlyOver())
329 if (target->isInterestedInDragSource (
details))
330 target->itemDragMove (
details);
333 void checkForExternalDrag (DragAndDropTarget::SourceDetails&
details, Point<int>
screenPos)
335 if (! hasCheckedForExternalDrag)
339 hasCheckedForExternalDrag =
true;
381 animator.animateComponent (
this,
388 animator.fadeOut (
this, 120);
392 bool isOriginalInputSource (
const MouseInputSource&
sourceToCheck)
414 if (isAlreadyDragging (sourceComponent))
437 :
dragImage.getScaledBounds().getCentre() };
439 const auto scaleFactor = 2.0;
442 image.multiplyAllAlphas (0.6f);
445 const auto clipped = (image.getBounds().toDouble() / scaleFactor).getConstrainedPoint (
relPos);
453 gradient.point2 = gradient.point1 +
Point<float> (0.0f, scaleFactor * 400.0f);
454 gradient.
addColour (0.0, Colours::white);
455 gradient.
addColour (0.375, Colours::white);
456 gradient.
addColour (1.0, Colours::transparentWhite);
501 peer->performAnyPendingRepaintsNow();
509 return dragImageComponents.size() > 0;
514 return dragImageComponents.size();
521 jassert (dragImageComponents.size() < 2);
523 return dragImageComponents.size() != 0 ? dragImageComponents[0]->sourceDetails.description
532 return dragImageComponents.getUnchecked (index)->sourceDetails.description;
539 jassert (dragImageComponents.size() < 2);
541 dragImageComponents[0]->updateImage (
newImage);
547 dragImageComponents.getUnchecked (index)->updateImage (
newImage);
581 if (
auto*
ms =
desktop.getDraggingMouseSource (i))
583 auto distance =
ms->getScreenPosition().getDistanceSquaredFrom (
centrePoint);
600bool DragAndDropContainer::isAlreadyDragging (Component* component)
const noexcept
604 if (
dragImageComp->sourceDetails.sourceComponent == component)
613 : description (desc),
614 sourceComponent (comp),
Describes the layout and colours that should be used to paint a colour gradient.
bool isRadial
If true, the gradient should be filled circularly, centred around point1, with point2 defining a poin...
int addColour(double proportionAlongGradient, Colour colour)
Adds a colour at a point along the length of the gradient.
static ModifierKeys getCurrentModifiersRealtime() noexcept
On desktop platforms this method will check all the mouse and key states and return a ModifierKeys ob...
@ windowIsTemporary
Indicates that the window is a temporary popup, like a menu, tooltip, etc.
@ windowIgnoresMouseClicks
Indicates that the window should let mouse clicks pass through it (may not be possible on some platfo...
The base class for all JUCE user-interface objects.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
bool isVisible() const noexcept
Tests whether the component is visible or not.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
Image createComponentSnapshot(Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f)
Generates a snapshot of part of this component.
bool isOpaque() const noexcept
Returns true if no parts of this component are transparent.
void grabKeyboardFocus()
Tries to give keyboard focus to this component.
Point< int > getLocalPoint(const Component *sourceComponent, Point< int > pointRelativeToSourceComponent) const
Converts a point to be relative to this component's coordinate space.
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
Component() noexcept
Creates a component.
Rectangle< int > getScreenBounds() const
Returns the bounds of this component, relative to the screen's top-left.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
TargetClass * findParentComponentOfClass() const
Searches the parent components for a component of a specified class.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
Point< int > localPointToGlobal(Point< int > localPoint) const
Converts a point relative to this component's top-left into a screen coordinate.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
void setTopLeftPosition(int x, int y)
Moves the component to a new position.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
MouseInputSource getMainMouseSource() const noexcept
Returns the main mouse input device that the system is using.
ComponentAnimator & getAnimator() noexcept
The Desktop object has a ComponentAnimator instance which can be used for performing your animations.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
const Array< MouseInputSource > & getMouseSources() const noexcept
Provides access to the array of mouse sources, for iteration.
static bool canUseSemiTransparentWindows() noexcept
True if the OS supports semitransparent windows.
void mouseDrag(const MouseEvent &e) override
Called when the mouse is moved while a button is held down.
void paint(Graphics &g) override
Components can override this method to draw their content.
bool canModalEventBeSentToComponent(const Component *targetComponent) override
When a component is modal, this callback allows it to choose which other components can still receive...
void timerCallback() override
The user-defined callback routine that actually gets called periodically.
void inputAttemptWhenModal() override
Called when the user tries to click on a component that is blocked by another modal component.
bool keyPressed(const KeyPress &key) override
Called when a key is pressed.
void mouseUp(const MouseEvent &e) override
Called when a mouse button is released.
Enables drag-and-drop behaviour for a component and all its sub-components.
DragAndDropContainer()
Creates a DragAndDropContainer.
var getCurrentDragDescription() const
Returns the description of the thing that's currently being dragged.
void startDragging(const var &sourceDescription, Component *sourceComponent, const ScaledImage &dragImage=ScaledImage(), bool allowDraggingToOtherJuceWindows=false, const Point< int > *imageOffsetFromMouse=nullptr, const MouseInputSource *inputSourceCausingDrag=nullptr)
Begins a drag-and-drop operation.
var getDragDescriptionForIndex(int index) const
Same as the getCurrentDragDescription() method but takes a touch index parameter.
bool isDragAndDropActive() const
Returns true if something is currently being dragged.
virtual ~DragAndDropContainer()
Destructor.
virtual void dragOperationStarted(const DragAndDropTarget::SourceDetails &)
Subclasses can override this to be told when a drag starts.
static bool performExternalDragDropOfText(const String &text, Component *sourceComponent=nullptr, std::function< void()> callback=nullptr)
This performs an asynchronous drag-and-drop of a block of text to some external application.
virtual bool shouldDropTextWhenDraggedExternally(const DragAndDropTarget::SourceDetails &sourceDetails, String &text)
Override this if you want to be able to perform an external drag of text when the user drags outside ...
virtual void dragOperationEnded(const DragAndDropTarget::SourceDetails &)
Subclasses can override this to be told when a drag finishes.
virtual bool shouldDropFilesWhenDraggedExternally(const DragAndDropTarget::SourceDetails &sourceDetails, StringArray &files, bool &canMoveFiles)
Override this if you want to be able to perform an external drag of a set of files when the user drag...
int getNumCurrentDrags() const
Returns the number of things currently being dragged.
static DragAndDropContainer * findParentDragContainerFor(Component *childComponent)
Utility to find the DragAndDropContainer for a given Component.
static bool performExternalDragDropOfFiles(const StringArray &files, bool canMoveFiles, Component *sourceComponent=nullptr, std::function< void()> callback=nullptr)
This performs an asynchronous drag-and-drop of a set of files to some external application.
void setDragImageForIndex(int index, const ScaledImage &newImage)
Same as the setCurrentDragImage() method but takes a touch index parameter.
void setCurrentDragImage(const ScaledImage &newImage)
If a drag is in progress, this allows the image being shown to be dynamically updated.
Contains details about the source of a drag-and-drop operation.
WeakReference< Component > sourceComponent
The component from the drag operation was started.
SourceDetails(const var &description, Component *sourceComponent, Point< int > localPosition) noexcept
Creates a SourceDetails object from its various settings.
virtual void itemDragEnter(const SourceDetails &dragSourceDetails)
Callback to indicate that something is being dragged over this component.
virtual void itemDragExit(const SourceDetails &dragSourceDetails)
Callback to indicate that something has been dragged off the edge of this component.
virtual void itemDragMove(const SourceDetails &dragSourceDetails)
Callback to indicate that the user is dragging something over this component.
virtual bool shouldDrawDragImageWhenOver()
Overriding this allows the target to tell the drag container whether to draw the drag image while the...
virtual void fileDragEnter(const StringArray &files, int x, int y)
Callback to indicate that some files are being dragged over this component.
virtual void fileDragExit(const StringArray &files)
Callback to indicate that the mouse has moved away from this component.
virtual void fileDragMove(const StringArray &files, int x, int y)
Callback to indicate that the user is dragging some files over this component.
A graphics context, used for drawing a component or image.
void drawImage(const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool fillAlphaChannelWithCurrentBrush=false) const
Draws part of an image, rescaling it to fit in a given target region.
void setOpacity(float newOpacity)
Changes the opacity to use with the current colour.
void fillAll() const
Fills the context's entire clip region with the current colour or brush.
Holds a fixed-size bitmap.
Image convertedToFormat(PixelFormat newFormat) const
Returns a version of this image with a different image format.
@ SingleChannel
< each pixel is a 1-byte alpha channel value.
@ ARGB
< each pixel is a 4-byte ARGB premultiplied colour value.
Represents a key press, including any modifier keys that are needed.
static const int escapeKey
key-code for the escape key
static bool callAsync(std::function< void()> functionToCall)
Asynchronously invokes a function or C++11 lambda on the message thread.
Contains position and status information about a mouse event.
MouseInputSource source
The source device that generated this event.
Point< int > getScreenPosition() const
Returns the mouse position of this event, in global screen coordinates.
Component *const originalComponent
The component that the event first occurred on.
A pair of (x, y) coordinates.
constexpr Point< float > toFloat() const noexcept
Casts this point to a Point<float> object.
constexpr Point< double > toDouble() const noexcept
Casts this point to a Point<double> object.
Point< ValueType > getCentre() const noexcept
Returns the centre point of the rectangle.
static RelativeTime milliseconds(int milliseconds) noexcept
Creates a new RelativeTime object representing a number of milliseconds.
An image that will be resampled before it is drawn.
Image getImage() const
Returns the image at its original dimensions.
A special array for holding a list of strings.
virtual void textDragEnter(const String &text, int x, int y)
Callback to indicate that some text is being dragged over this component.
virtual void textDragMove(const String &text, int x, int y)
Callback to indicate that the user is dragging some text over this component.
virtual void textDragExit(const String &text)
Callback to indicate that the mouse has moved away from this component.
Holds an absolute date and time.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
Makes repeated callbacks to a virtual method at a specified time interval.
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
This class acts as a pointer which will automatically become null if the object to which it points is...
ObjectType * get() const noexcept
Returns the object that this pointer refers to, or null if the object no longer exists.
A variant class, that can be used to hold a range of primitive values.
void ignoreUnused(Types &&...) noexcept
Handy function for avoiding unused variables warning.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.