JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ComponentPeer.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
43class JUCE_API ComponentPeer : private FocusChangeListener
44{
45public:
46 //==============================================================================
49 {
50 windowAppearsOnTaskbar = (1 << 0),
52 windowIsTemporary = (1 << 1),
54 windowIgnoresMouseClicks = (1 << 2),
56 windowHasTitleBar = (1 << 3),
59 windowIsResizable = (1 << 4),
60 windowHasMinimiseButton = (1 << 5),
62 windowHasMaximiseButton = (1 << 6),
64 windowHasCloseButton = (1 << 7),
66 windowHasDropShadow = (1 << 8),
68 windowRepaintedExplictly = (1 << 9),
71 windowIgnoresKeyPresses = (1 << 10),
74 windowRequiresSynchronousCoreGraphicsRendering = (1 << 11),
78 windowIsSemiTransparent = (1 << 30)
80 };
81
90 class JUCE_API OptionalBorderSize final
91 {
92 public:
94 OptionalBorderSize() : valid (false) {}
95
97 explicit OptionalBorderSize (BorderSize<int> size) : valid (true), borderSize (std::move (size)) {}
98
100 explicit operator bool() const noexcept { return valid; }
101
107 const auto& operator*() const noexcept
108 {
109 jassert (valid);
110 return borderSize;
111 }
112
118 const auto* operator->() const noexcept
119 {
120 jassert (valid);
121 return &borderSize;
122 }
123
124 private:
125 bool valid;
126 BorderSize<int> borderSize;
127 };
128
129 //==============================================================================
135 ComponentPeer (Component& component, int styleFlags);
136
138 ~ComponentPeer() override;
139
140 //==============================================================================
142 Component& getComponent() noexcept { return component; }
143
147 int getStyleFlags() const noexcept { return styleFlags; }
148
152 uint32 getUniqueID() const noexcept { return uniqueID; }
153
154 //==============================================================================
160 virtual void* getNativeHandle() const = 0;
161
163 virtual void setVisible (bool shouldBeVisible) = 0;
164
166 virtual void setTitle (const String& title) = 0;
167
174 virtual bool setDocumentEditedStatus (bool edited);
175
181 virtual void setRepresentedFile (const File&);
182
183 //==============================================================================
191 virtual void setBounds (const Rectangle<int>& newBounds, bool isNowFullScreen) = 0;
192
194 void updateBounds();
195
201 virtual Rectangle<int> getBounds() const = 0;
202
204 virtual Point<float> localToGlobal (Point<float> relativePosition) = 0;
205
207 virtual Point<float> globalToLocal (Point<float> screenPosition) = 0;
208
210 Point<int> localToGlobal (Point<int> relativePosition);
211
213 Point<int> globalToLocal (Point<int> screenPosition);
214
216 virtual Rectangle<int> localToGlobal (const Rectangle<int>& relativePosition);
217
219 virtual Rectangle<int> globalToLocal (const Rectangle<int>& screenPosition);
220
222 Rectangle<float> localToGlobal (const Rectangle<float>& relativePosition);
223
225 Rectangle<float> globalToLocal (const Rectangle<float>& screenPosition);
226
230 Rectangle<int> getAreaCoveredBy (const Component& subComponent) const;
231
233 virtual void setMinimised (bool shouldBeMinimised) = 0;
234
236 virtual bool isMinimised() const = 0;
237
239 virtual void setFullScreen (bool shouldBeFullScreen) = 0;
240
242 virtual bool isFullScreen() const = 0;
243
245 virtual bool isKioskMode() const;
246
248 void setNonFullScreenBounds (const Rectangle<int>& newBounds) noexcept;
249
251 const Rectangle<int>& getNonFullScreenBounds() const noexcept;
252
254 virtual void setIcon (const Image& newIcon) = 0;
255
259 void setConstrainer (ComponentBoundsConstrainer* newConstrainer) noexcept;
260
268 virtual void startHostManagedResize ([[maybe_unused]] Point<int> mouseDownPosition,
269 [[maybe_unused]] ResizableBorderComponent::Zone zone) {}
270
272 ComponentBoundsConstrainer* getConstrainer() const noexcept { return constrainer; }
273
280 virtual bool contains (Point<int> localPos, bool trueIfInAChildWindow) const = 0;
281
293
298 #if JUCE_LINUX || JUCE_BSD
299 [[deprecated ("Use getFrameSizeIfPresent instead.")]]
300 #endif
301 virtual BorderSize<int> getFrameSize() const = 0;
302
307 void handleMovedOrResized();
308
313 virtual void handleScreenSizeChange();
314
315 //==============================================================================
317 void handlePaint (LowLevelGraphicsContext& contextToPaintTo);
318
319 //==============================================================================
323 virtual bool setAlwaysOnTop (bool alwaysOnTop) = 0;
324
326 virtual void toFront (bool takeKeyboardFocus) = 0;
327
329 virtual void toBehind (ComponentPeer* other) = 0;
330
334 void handleBroughtToFront();
335
336 //==============================================================================
338 virtual bool isFocused() const = 0;
339
341 virtual void grabFocus() = 0;
342
344 void handleFocusGain();
346 void handleFocusLoss();
347
348 Component* getLastFocusedSubcomponent() const noexcept;
349
354 bool handleKeyPress (int keyCode, juce_wchar textCharacter);
355
359 bool handleKeyPress (const KeyPress& key);
360
364 bool handleKeyUpOrDown (bool isKeyDown);
365
367 void handleModifierKeysChange();
368
373 virtual void closeInputMethodContext();
374
379 void refreshTextInputTarget();
380
381 //==============================================================================
383 TextInputTarget* findCurrentTextInputTarget();
384
385 //==============================================================================
387 virtual void repaint (const Rectangle<int>& area) = 0;
388
395 virtual void performAnyPendingRepaintsNow() = 0;
396
398 virtual void setAlpha (float newAlpha) = 0;
399
400 //==============================================================================
401 void handleMouseEvent (MouseInputSource::InputSourceType type, Point<float> positionWithinPeer, ModifierKeys newMods, float pressure,
402 float orientation, int64 time, PenDetails pen = {}, int touchIndex = 0);
403
404 void handleMouseWheel (MouseInputSource::InputSourceType type, Point<float> positionWithinPeer,
405 int64 time, const MouseWheelDetails&, int touchIndex = 0);
406
407 void handleMagnifyGesture (MouseInputSource::InputSourceType type, Point<float> positionWithinPeer,
408 int64 time, float scaleFactor, int touchIndex = 0);
409
410 void handleUserClosingWindow();
411
413 struct DragInfo
414 {
415 StringArray files;
416 String text;
417 Point<int> position;
418
419 bool isEmpty() const noexcept { return files.size() == 0 && text.isEmpty(); }
420 void clear() noexcept { files.clear(); text.clear(); }
421 };
422
423 bool handleDragMove (const DragInfo&);
424 bool handleDragExit (const DragInfo&);
425 bool handleDragDrop (const DragInfo&);
426
427 //==============================================================================
431 static int getNumPeers() noexcept;
432
436 static ComponentPeer* getPeer (int index) noexcept;
437
439 static ComponentPeer* getPeerFor (const Component*) noexcept;
440
444 static bool isValidPeer (const ComponentPeer* peer) noexcept;
445
446 //==============================================================================
447 virtual StringArray getAvailableRenderingEngines() = 0;
448 virtual int getCurrentRenderingEngine() const;
449 virtual void setCurrentRenderingEngine (int index);
450
451 //==============================================================================
462 static ModifierKeys getCurrentModifiersRealtime() noexcept;
463
464 //==============================================================================
471 struct JUCE_API ScaleFactorListener
472 {
474 virtual ~ScaleFactorListener() = default;
475
477 virtual void nativeScaleFactorChanged (double newScaleFactor) = 0;
478 };
479
481 void addScaleFactorListener (ScaleFactorListener* listenerToAdd) { scaleFactorListeners.add (listenerToAdd); }
482
484 void removeScaleFactorListener (ScaleFactorListener* listenerToRemove) { scaleFactorListeners.remove (listenerToRemove); }
485
486 //==============================================================================
499 struct JUCE_API VBlankListener
500 {
502 virtual ~VBlankListener() = default;
503
505 virtual void onVBlank() = 0;
506 };
507
509 void addVBlankListener (VBlankListener* listenerToAdd) { vBlankListeners.add (listenerToAdd); }
510
512 void removeVBlankListener (VBlankListener* listenerToRemove) { vBlankListeners.remove (listenerToRemove); }
513
514 //==============================================================================
520 virtual double getPlatformScaleFactor() const noexcept { return 1.0; }
521
525 virtual void setHasChangedSinceSaved (bool) {}
526
527
528 enum class Style
529 {
531 automatic,
532
534 light,
535
537 dark
538 };
539
547 {
548 if (std::exchange (style, s) != style)
549 appStyleChanged();
550 }
551
553 Style getAppStyle() const { return style; }
554
555protected:
556 //==============================================================================
557 static void forceDisplayUpdate();
558
559 Component& component;
560 const int styleFlags;
561 Rectangle<int> lastNonFullscreenBounds;
562 ComponentBoundsConstrainer* constrainer = nullptr;
563 static std::function<ModifierKeys()> getNativeRealtimeModifiers;
564 ListenerList<ScaleFactorListener> scaleFactorListeners;
565 ListenerList<VBlankListener> vBlankListeners;
566 Style style = Style::automatic;
567
568private:
569 //==============================================================================
570 virtual void appStyleChanged() {}
571
579 virtual void textInputRequired (Point<int>, TextInputTarget&) = 0;
580
588 virtual void dismissPendingTextInput();
589
590 void globalFocusChanged (Component*) override;
591 Component* getTargetForKeyPress();
592
593 WeakReference<Component> lastFocusedComponent, dragAndDropTargetComponent;
594 Component* lastDragAndDropCompUnderMouse = nullptr;
595 TextInputTarget* textInputTarget = nullptr;
596 const uint32 uniqueID;
597 bool isWindowMinimised = false;
598
599 //==============================================================================
601};
602
603} // namespace juce
Specifies a set of gaps to be left around the sides of a rectangle.
A class that imposes restrictions on a Component's size or position.
Represents the window borders around a window component.
const auto & operator*() const noexcept
Returns a reference to the value.
const auto * operator->() const noexcept
Returns a pointer to the value.
OptionalBorderSize(BorderSize< int > size)
Constructor.
The Component class uses a ComponentPeer internally to create and manage a real operating-system wind...
void removeVBlankListener(VBlankListener *listenerToRemove)
Removes a VBlankListener.
int getStyleFlags() const noexcept
Returns the set of style flags that were set when the window was created.
virtual void setFullScreen(bool shouldBeFullScreen)=0
Enable/disable fullscreen mode for the window.
virtual bool setAlwaysOnTop(bool alwaysOnTop)=0
Sets this window to either be always-on-top or normal.
virtual void setHasChangedSinceSaved(bool)
On platforms that support it, this will update the window's titlebar in some way to indicate that the...
virtual void toFront(bool takeKeyboardFocus)=0
Brings the window to the top, optionally also giving it keyboard focus.
virtual void grabFocus()=0
Tries to give the window keyboard focus.
void addVBlankListener(VBlankListener *listenerToAdd)
Adds a VBlankListener.
virtual void * getNativeHandle() const =0
Returns the raw handle to whatever kind of window is being used.
virtual Rectangle< int > getBounds() const =0
Returns the current position and size of the window.
virtual void setMinimised(bool shouldBeMinimised)=0
Minimises the window.
virtual void setBounds(const Rectangle< int > &newBounds, bool isNowFullScreen)=0
Moves and resizes the window.
virtual double getPlatformScaleFactor() const noexcept
On Windows and Linux this will return the OS scaling factor currently being applied to the native win...
StyleFlags
A combination of these flags is passed to the ComponentPeer constructor.
virtual void setVisible(bool shouldBeVisible)=0
Shows or hides the window.
virtual Point< float > localToGlobal(Point< float > relativePosition)=0
Converts a position relative to the top-left of this component to screen coordinates.
ComponentBoundsConstrainer * getConstrainer() const noexcept
Returns the current constrainer, if one has been set.
virtual bool isFocused() const =0
True if the window has the keyboard focus.
virtual bool contains(Point< int > localPos, bool trueIfInAChildWindow) const =0
Checks if a point is in the window.
virtual OptionalBorderSize getFrameSizeIfPresent() const =0
Returns the size of the window frame that's around this window.
void removeScaleFactorListener(ScaleFactorListener *listenerToRemove)
Removes a scale factor listener.
virtual void toBehind(ComponentPeer *other)=0
Moves the window to be just behind another one.
void setAppStyle(Style s)
On operating systems that support it, this will update the style of this peer as requested.
virtual BorderSize< int > getFrameSize() const =0
Returns the size of the window frame that's around this window.
virtual bool isFullScreen() const =0
True if the window is currently full-screen.
virtual void setTitle(const String &title)=0
Changes the title of the window.
uint32 getUniqueID() const noexcept
Returns a unique ID for this peer.
Style getAppStyle() const
Returns the style requested for this app.
virtual Point< float > globalToLocal(Point< float > screenPosition)=0
Converts a screen coordinate to a position relative to the top-left of this component.
Component & getComponent() noexcept
Returns the component being represented by this peer.
void addScaleFactorListener(ScaleFactorListener *listenerToAdd)
Adds a scale factor listener.
virtual bool isMinimised() const =0
True if the window is currently minimised.
The base class for all JUCE user-interface objects.
Represents a local file or directory.
Definition juce_File.h:45
Classes can implement this interface and register themselves with the Desktop class to receive callba...
Holds a fixed-size bitmap.
Definition juce_Image.h:58
Represents a key press, including any modifier keys that are needed.
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Interface class for graphics context objects, used internally by the Graphics class.
Represents the state of the mouse buttons and modifier keys.
Represents a linear source of mouse events from a mouse device or individual finger in a multi-touch ...
InputSourceType
Possible mouse input sources.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
A component that resizes its parent component when dragged.
A special array for holding a list of strings.
void clear()
Removes all elements from the array.
int size() const noexcept
Returns the number of strings in the array.
The JUCE String class!
Definition juce_String.h:53
bool isEmpty() const noexcept
Returns true if the string contains no characters.
void clear() noexcept
Resets this string to be empty.
An abstract base class which can be implemented by components that function as text editors.
T exchange(T... args)
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.
Contains status information about a mouse wheel event.
Contains status information about a pen event.
Structure to describe drag and drop information.
Used to receive callbacks when the OS scale factor of this ComponentPeer changes.
virtual ~ScaleFactorListener()=default
Destructor.
virtual void nativeScaleFactorChanged(double newScaleFactor)=0
Called when the scale factor changes.
Used to receive callbacks on every vertical blank event of the display that the peer currently belong...
virtual ~VBlankListener()=default
Destructor.
virtual void onVBlank()=0
Called on every vertical blank of the display to which the peer is associated.