29static uint32 lastUniquePeerID = 1;
35 uniqueID (lastUniquePeerID += 2)
39 desktop.addFocusChangeListener (
this);
45 desktop.removeFocusChangeListener (
this);
46 desktop.peers.removeFirstMatchingValue (
this);
64 if (&(peer->getComponent()) == component)
96 MouseInputSource (*mouse).handleWheel (*
this, pos, time,
wheel);
102 MouseInputSource (*mouse).handleMagnifyGesture (*
this, pos, time, scaleFactor);
124 #if JUCE_ENABLE_REPAINT_DEBUGGING
125 #ifdef JUCE_IS_REPAINT_DEBUGGING_ACTIVE
139 #if JUCE_ENABLE_REPAINT_DEBUGGING
140 #ifdef JUCE_IS_REPAINT_DEBUGGING_ACTIVE
164Component* ComponentPeer::getTargetForKeyPress()
171 if (c->isCurrentlyBlockedByAnotherModalComponent())
189 for (
auto* target = getTargetForKeyPress(); target !=
nullptr; target = target->
getParentComponent())
228 for (
auto* target = getTargetForKeyPress(); target !=
nullptr; target = target->
getParentComponent())
232 keyWasUsed = target->keyStateChanged (isKeyDown);
258 if (target ==
nullptr)
261 if (target ==
nullptr)
264 target->internalModifierKeysChanged();
274 if (textInputTarget ==
nullptr)
275 dismissPendingTextInput();
277 textInputRequired (
globalToLocal (c->getScreenPosition()), *textInputTarget);
284 if (c == &component || component.
isParentOf (c))
286 if (
ti->isTextInputActive())
294void ComponentPeer::dismissPendingTextInput()
302 component.internalBroughtToFront();
314 if (component.flags.hasHeavyweightPeerFlag && !
nowMinimised)
318 auto newBounds = detail::ComponentHelpers::rawPeerPositionToLocal (component,
getBounds());
326 component.boundsRelativeToParent =
newBounds;
342 component.sendVisibilityChangeMessage();
348 lastNonFullscreenBounds = component.
getBounds();
353 if (component.
isParentOf (lastFocusedComponent)
354 && lastFocusedComponent->isShowing()
355 && lastFocusedComponent->getWantsKeyboardFocus())
357 Component::currentlyFocusedComponent = lastFocusedComponent;
366 ModalComponentManager::getInstance()->bringModalComponentsToFront();
374 lastFocusedComponent = Component::currentlyFocusedComponent;
376 if (lastFocusedComponent !=
nullptr)
378 Component::currentlyFocusedComponent =
nullptr;
385Component* ComponentPeer::getLastFocusedSubcomponent()
const noexcept
387 return (component.
isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
388 ?
static_cast<Component*
> (lastFocusedComponent)
405 return lastNonFullscreenBounds;
433 return detail::ScalingHelpers::scaledScreenPosToUnscaled
445 static bool isSuitableTarget (
const ComponentPeer::DragInfo& info, Component* target)
447 return isFileDrag (info) ?
dynamic_cast<FileDragAndDropTarget*
> (target) !=
nullptr
451 static bool isInterested (
const ComponentPeer::DragInfo& info, Component* target)
453 return isFileDrag (info) ?
dynamic_cast<FileDragAndDropTarget*
> (target)->isInterestedInFileDrag (info.files)
454 :
dynamic_cast<TextDragAndDropTarget*
> (target)->isInterestedInTextDrag (info.text);
457 static Component* findDragAndDropTarget (Component* c,
const ComponentPeer::DragInfo& info, Component*
lastOne)
459 for (; c !=
nullptr; c = c->getParentComponent())
460 if (isSuitableTarget (info, c) && (c ==
lastOne || isInterested (info, c)))
467bool ComponentPeer::handleDragMove (
const ComponentPeer::DragInfo& info)
470 auto*
lastTarget = dragAndDropTargetComponent.get();
482 if (DragHelpers::isFileDrag (info))
483 dynamic_cast<FileDragAndDropTarget*
> (
lastTarget)->fileDragExit (info.files);
485 dynamic_cast<TextDragAndDropTarget*
> (
lastTarget)->textDragExit (info.text);
488 dragAndDropTargetComponent =
nullptr;
490 if (DragHelpers::isSuitableTarget (info,
newTarget))
493 auto pos =
newTarget->getLocalPoint (&component, info.position);
495 if (DragHelpers::isFileDrag (info))
496 dynamic_cast<FileDragAndDropTarget*
> (
newTarget)->fileDragEnter (info.files, pos.x, pos.y);
498 dynamic_cast<TextDragAndDropTarget*
> (
newTarget)->textDragEnter (info.text, pos.x, pos.y);
507 if (! DragHelpers::isSuitableTarget (info,
newTarget))
510 auto pos =
newTarget->getLocalPoint (&component, info.position);
512 if (DragHelpers::isFileDrag (info))
513 dynamic_cast<FileDragAndDropTarget*
> (
newTarget)->fileDragMove (info.files, pos.x, pos.y);
515 dynamic_cast<TextDragAndDropTarget*
> (
newTarget)->textDragMove (info.text, pos.x, pos.y);
520bool ComponentPeer::handleDragExit (
const ComponentPeer::DragInfo& info)
522 DragInfo
info2 (info);
523 info2.position.setXY (-1, -1);
524 const bool used = handleDragMove (
info2);
526 jassert (dragAndDropTargetComponent ==
nullptr);
527 lastDragAndDropCompUnderMouse =
nullptr;
531bool ComponentPeer::handleDragDrop (
const ComponentPeer::DragInfo& info)
533 handleDragMove (info);
537 dragAndDropTargetComponent =
nullptr;
538 lastDragAndDropCompUnderMouse =
nullptr;
540 if (DragHelpers::isSuitableTarget (info, targetComp))
542 if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
544 targetComp->internalModalInputAttempt();
546 if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
550 ComponentPeer::DragInfo
infoCopy (info);
551 infoCopy.position = targetComp->getLocalPoint (&component, info.position);
557 if (
auto* c = targetComp.get())
559 if (DragHelpers::isFileDrag (info))
560 dynamic_cast<FileDragAndDropTarget*> (c)->filesDropped (infoCopy.files, infoCopy.position.x, infoCopy.position.y);
562 dynamic_cast<TextDragAndDropTarget*> (c)->textDropped (infoCopy.text, infoCopy.position.x, infoCopy.position.y);
574void ComponentPeer::handleUserClosingWindow()
589int ComponentPeer::getCurrentRenderingEngine()
const {
return 0; }
590void ComponentPeer::setCurrentRenderingEngine ([[
maybe_unused]]
int index) {
jassert (index == 0); }
593std::function<ModifierKeys()> ComponentPeer::getNativeRealtimeModifiers =
nullptr;
597 if (getNativeRealtimeModifiers !=
nullptr)
598 return getNativeRealtimeModifiers();
604void ComponentPeer::forceDisplayUpdate()
609void ComponentPeer::globalFocusChanged ([[
maybe_unused]] Component* comp)
Represents a colour, also including a transparency value.
A class that imposes restrictions on a Component's size or position.
The Component class uses a ComponentPeer internally to create and manage a real operating-system wind...
virtual bool setDocumentEditedStatus(bool edited)
If this type of window is capable of indicating that the document in it has been edited,...
static ModifierKeys getCurrentModifiersRealtime() noexcept
On desktop platforms this method will check all the mouse and key states and return a ModifierKeys ob...
void handleModifierKeysChange()
Called whenever a modifier key is pressed or released.
~ComponentPeer() override
Destructor.
virtual void handleScreenSizeChange()
This is called if the screen resolution changes.
virtual bool isKioskMode() const
True if the window is in kiosk-mode.
void handleFocusGain()
Called when the window gains keyboard focus.
bool handleKeyPress(int keyCode, juce_wchar textCharacter)
Called when a key is pressed.
virtual void closeInputMethodContext()
If there's a currently active input-method context - i.e.
virtual Rectangle< int > getBounds() const =0
Returns the current position and size of the window.
ComponentPeer(Component &component, int styleFlags)
Creates a peer.
void handleMovedOrResized()
This is called when the window's bounds change.
static int getNumPeers() noexcept
Returns the number of currently-active peers.
virtual void setBounds(const Rectangle< int > &newBounds, bool isNowFullScreen)=0
Moves and resizes the window.
void handlePaint(LowLevelGraphicsContext &contextToPaintTo)
This is called to repaint the component into the given context.
void setNonFullScreenBounds(const Rectangle< int > &newBounds) noexcept
Sets the size to restore to if fullscreen mode is turned off.
TextInputTarget * findCurrentTextInputTarget()
Returns the currently focused TextInputTarget, or null if none is found.
bool handleKeyUpOrDown(bool isKeyDown)
Called whenever a key is pressed or released.
const Rectangle< int > & getNonFullScreenBounds() const noexcept
Returns the size to restore to if fullscreen mode is turned off.
virtual Point< float > localToGlobal(Point< float > relativePosition)=0
Converts a position relative to the top-left of this component to screen coordinates.
static ComponentPeer * getPeerFor(const Component *) noexcept
Returns the peer that's attached to the given component, or nullptr if there isn't one.
void handleBroughtToFront()
Called when the window is brought to the front, either by the OS or by a call to toFront().
void handleFocusLoss()
Called when the window loses keyboard focus.
static bool isValidPeer(const ComponentPeer *peer) noexcept
Checks if this peer object is valid.
void setConstrainer(ComponentBoundsConstrainer *newConstrainer) noexcept
Sets a constrainer to use if the peer can resize itself.
virtual void setRepresentedFile(const File &)
If this type of window is capable of indicating that it represents a file, then this lets you set the...
void updateBounds()
Updates the peer's bounds to match its component.
Rectangle< int > getAreaCoveredBy(const Component &subComponent) const
Returns the area in peer coordinates that is covered by the given sub-comp (which may be at any depth...
virtual bool isFullScreen() const =0
True if the window is currently full-screen.
static ComponentPeer * getPeer(int index) noexcept
Returns one of the currently-active peers.
void refreshTextInputTarget()
Alerts the peer that the current text input target has changed somehow.
virtual Point< float > globalToLocal(Point< float > screenPosition)=0
Converts a screen coordinate to a position relative to the top-left of this component.
virtual bool isMinimised() const =0
True if the window is currently minimised.
The base class for all JUCE user-interface objects.
void paintEntireComponent(Graphics &context, bool ignoreAlphaLevel)
Draws this component and all its subcomponents onto the specified graphics context.
Rectangle< int > getBoundsInParent() const noexcept
Returns the area of this component's parent which this component covers.
AffineTransform getTransform() const
Returns the transform that is currently being applied to this component.
static Component *JUCE_CALLTYPE getCurrentlyModalComponent(int index=0) noexcept
Returns one of the components that are currently modal.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
virtual void minimisationStateChanged(bool isNowMinimised)
Called for a desktop component which has just been minimised or un-minimised.
void grabKeyboardFocus()
Tries to give keyboard focus to this component.
Rectangle< int > getLocalArea(const Component *sourceComponent, Rectangle< int > areaRelativeToSourceComponent) const
Converts a rectangle to be relative to this component's coordinate space.
bool isTransformed() const noexcept
Returns true if a non-identity transform is being applied to this component.
virtual void userTriedToCloseWindow()
For components on the desktop, this is called if the system wants to close the window.
static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent() noexcept
Returns the component that currently has the keyboard focus.
@ focusChangedDirectly
Means that the focus was changed by a call to grabKeyboardFocus().
@ focusChangedByMouseClick
Means that the user clicked the mouse to change focus.
bool hasKeyboardFocus(bool trueIfChildIsFocused) const
Returns true if this component currently has the keyboard focus.
bool isCurrentlyBlockedByAnotherModalComponent() const
Checks whether there's a modal component somewhere that's stopping this one from receiving messages.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
bool isParentOf(const Component *possibleChild) const noexcept
Checks whether a component is anywhere inside this component or its children.
virtual void parentSizeChanged()
Called when this component's immediate parent has been resized.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
Component * getComponentAt(int x, int y)
Returns the component at a certain point within this one.
Component * getKioskModeComponent() const noexcept
Returns the component that is currently being used in kiosk-mode.
MouseInputSource getMainMouseSource() const noexcept
Returns the main mouse input device that the system is using.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
Represents a local file or directory.
A graphics context, used for drawing a component or image.
void saveState()
Saves the current graphics state on an internal stack.
void restoreState()
Restores a graphics state that was previously saved with saveState().
void addTransform(const AffineTransform &transform)
Adds a transformation which will be performed on all the graphics operations that the context subsequ...
void fillAll() const
Fills the context's entire clip region with the current colour or brush.
Represents a key press, including any modifier keys that are needed.
static const int tabKey
key-code for the tab key
Interface class for graphics context objects, used internally by the Graphics class.
static bool callAsync(std::function< void()> functionToCall)
Asynchronously invokes a function or C++11 lambda on the message thread.
Represents the state of the mouse buttons and modifier keys.
static ModifierKeys currentModifiers
This object represents the last-known state of the keyboard and mouse buttons.
A pair of (x, y) coordinates.
constexpr Point< float > toFloat() const noexcept
Casts this point to a Point<float> object.
constexpr Point< int > roundToInt() const noexcept
Casts this point to a Point<int> object using roundToInt() to convert the values.
A random number generator.
Manages a rectangle and allows geometric operations to be performed on it.
Rectangle transformedBy(const AffineTransform &transform) const noexcept
Returns the smallest rectangle that can contain the shape created by applying a transform to this rec...
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
An abstract base class which can be implemented by components that function as text editors.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define JUCE_TRY
The JUCE_TRY/JUCE_CATCH_EXCEPTION wrappers can be used to pass any uncaught exceptions to the JUCEApp...
#define JUCE_CATCH_EXCEPTION
The JUCE_TRY/JUCE_CATCH_EXCEPTION wrappers can be used to pass any uncaught exceptions to the JUCEApp...
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
long long int64
A platform-independent 64-bit integer type.
Contains status information about a pen event.
Structure to describe drag and drop information.