29ResizableWindow::ResizableWindow (
const String& name,
bool shouldAddToDesktop)
32 initialise (shouldAddToDesktop);
35ResizableWindow::ResizableWindow (
const String& name,
Colour bkgnd,
bool shouldAddToDesktop)
39 initialise (shouldAddToDesktop);
44 splashScreen.deleteAndZero();
52 resizableCorner.reset();
53 resizableBorder.reset();
61void ResizableWindow::initialise (
const bool shouldAddToDesktop)
78 #if ! JucePlugin_Build_Standalone
86 lastNonFullScreenPos.
setBounds (50, 50, 256, 256);
88 if (shouldAddToDesktop)
92int ResizableWindow::getDesktopWindowStyleFlags()
const
94 int styleFlags = TopLevelWindow::getDesktopWindowStyleFlags();
105 if (ownsContentComponent)
107 contentComponent.deleteAndZero();
112 contentComponent =
nullptr;
116void ResizableWindow::setContent (
Component* newContentComponent,
118 bool resizeToFitWhenContentChangesSize)
120 if (newContentComponent != contentComponent)
124 contentComponent = newContentComponent;
128 ownsContentComponent = takeOwnership;
129 resizeToFitContent = resizeToFitWhenContentChangesSize;
131 if (resizeToFitWhenContentChangesSize)
139 setContent (newContentComponent,
true, resizeToFitWhenContentChangesSize);
144 setContent (newContentComponent,
false, resizeToFitWhenContentChangesSize);
147void ResizableWindow::setContentComponent (
Component*
const newContentComponent,
148 const bool deleteOldOne,
149 const bool resizeToFitWhenContentChangesSize)
151 if (newContentComponent != contentComponent)
155 contentComponent.deleteAndZero();
160 contentComponent =
nullptr;
164 setContent (newContentComponent,
true, resizeToFitWhenContentChangesSize);
169 jassert (width > 0 && height > 0);
173 setSize (width + border.getLeftAndRight(),
174 height + border.getTopAndBottom());
192 updateLastPosIfShowing();
198 updateLastPosIfShowing();
205 if (resizableBorder !=
nullptr)
207 resizableBorder->setVisible (! resizerHidden);
210 resizableBorder->toBack();
213 if (resizableCorner !=
nullptr)
215 resizableCorner->setVisible (! resizerHidden);
217 const int resizerSize = 18;
218 resizableCorner->setBounds (
getWidth() - resizerSize,
220 resizerSize, resizerSize);
223 if (contentComponent !=
nullptr)
227 jassert (! contentComponent->isTransformed());
232 updateLastPosIfShowing();
235 hasBeenResized =
true;
241 if ((child == contentComponent) && (child !=
nullptr) && resizeToFitContent)
250 child->
getHeight() + borders.getTopAndBottom());
261 repaint (area.removeFromTop (border.getTop()));
262 repaint (area.removeFromLeft (border.getLeft()));
263 repaint (area.removeFromRight (border.getRight()));
264 repaint (area.removeFromBottom (border.getBottom()));
269 const bool useBottomRightCornerResizer)
271 if (shouldBeResizable)
273 if (useBottomRightCornerResizer)
275 resizableBorder.reset();
277 if (resizableCorner ==
nullptr)
281 resizableCorner->setAlwaysOnTop (
true);
286 resizableCorner.reset();
288 if (resizableBorder ==
nullptr)
297 resizableCorner.reset();
298 resizableBorder.reset();
302 recreateDesktopWindow();
310 return resizableCorner !=
nullptr
311 || resizableBorder !=
nullptr;
315 int newMinimumHeight,
317 int newMaximumHeight)
noexcept
320 jassert (constrainer == &defaultConstrainer || constrainer ==
nullptr);
322 if (constrainer ==
nullptr)
323 setConstrainer (&defaultConstrainer);
325 defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
326 newMaximumWidth, newMaximumHeight);
328 setBoundsConstrained (getBounds());
333 canDrag = shouldBeDraggable;
338 if (constrainer != newConstrainer)
340 constrainer = newConstrainer;
342 bool useBottomRightCornerResizer = resizableCorner !=
nullptr;
343 bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder !=
nullptr;
345 resizableCorner.reset();
346 resizableBorder.reset();
348 setResizable (shouldBeResizable, useBottomRightCornerResizer);
349 updatePeerConstrainer();
355 if (constrainer !=
nullptr)
396 updatePeerConstrainer();
407 auto backgroundColour = newColour;
410 backgroundColour = newColour.
withAlpha (1.0f);
423 return peer !=
nullptr && peer->isFullScreen();
433 updateLastPosIfShowing();
434 fullscreen = shouldBeFullScreen;
441 auto lastPos = lastNonFullScreenPos;
443 peer->setFullScreen (shouldBeFullScreen);
445 if ((! shouldBeFullScreen) && ! lastPos.isEmpty())
455 if (shouldBeFullScreen)
468 return peer->isMinimised();
479 updateLastPosIfShowing();
480 peer->setMinimised (shouldMinimise);
493 return peer->isKioskMode();
498void ResizableWindow::updateLastPosIfShowing()
502 updateLastPosIfNotFullScreen();
503 updatePeerConstrainer();
507void ResizableWindow::updateLastPosIfNotFullScreen()
513void ResizableWindow::updatePeerConstrainer()
517 peer->setConstrainer (constrainer);
529 updateLastPosIfShowing();
535 if (
const auto optionalFrameSize = peer->getFrameSizeIfPresent())
537 const auto& frameSize = *optionalFrameSize;
538 stateString <<
" frame " << frameSize.getTop() <<
' ' << frameSize.getLeft()
539 <<
' ' << frameSize.getBottom() <<
' ' << frameSize.getRight();
554 const bool fs = tokens[0].startsWithIgnoreCase (
"fs");
555 const int firstCoord = fs ? 1 : 0;
557 if (tokens.
size() < firstCoord + 4)
561 tokens[firstCoord + 1].getIntValue(),
562 tokens[firstCoord + 2].getIntValue(),
563 tokens[firstCoord + 3].getIntValue());
572 if (
const auto frameSize = peer->getFrameSizeIfPresent())
573 frameSize->addTo (newPos);
577 if (peer ==
nullptr || ! peer->getFrameSizeIfPresent())
581 if (tokens[firstCoord + 4] ==
"frame" && tokens.
size() == firstCoord + 9)
584 tokens[firstCoord + 6].getIntValue(),
585 tokens[firstCoord + 7].getIntValue(),
586 tokens[firstCoord + 8].getIntValue() };
588 newPos.
setX (newPos.
getX() - frame.getLeft());
589 newPos.
setY (newPos.
getY() - frame.getTop());
598 auto allMonitors = desktop.getDisplays().getRectangleList (
true);
599 allMonitors.clipTo (newPos);
600 auto onScreenArea = allMonitors.getBounds();
602 if (onScreenArea.getWidth() * onScreenArea.getHeight() < 32 * 32)
604 auto screen = desktop.getDisplays().getDisplayForRect (newPos)->userArea;
616 if (
const auto frameSize = peer->getFrameSizeIfPresent())
617 frameSize->subtractFrom (newPos);
619 peer->setNonFullScreenBounds (newPos);
622 updateLastPosIfNotFullScreen();
Specifies a set of gaps to be left around the sides of a rectangle.
Represents a colour, also including a transparency value.
Colour withAlpha(uint8 newAlpha) const noexcept
Returns a colour that's the same colour as this one, but with a new alpha value.
A class that imposes restrictions on a Component's size or position.
void setMinimumOnscreenAmounts(int minimumWhenOffTheTop, int minimumWhenOffTheLeft, int minimumWhenOffTheBottom, int minimumWhenOffTheRight) noexcept
Sets the amount by which the component is allowed to go off-screen.
void setBoundsForComponent(Component *component, Rectangle< int > bounds, bool isStretchingTop, bool isStretchingLeft, bool isStretchingBottom, bool isStretchingRight)
Checks the given bounds, and then sets the component to the corrected size.
void dragComponent(Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)
Call this from your mouseDrag() callback to move the component.
void startDraggingComponent(Component *componentToDrag, const MouseEvent &e)
Call this from your component's mouseDown() method, to prepare for dragging.
@ windowIsResizable
Indicates that the window should have a resizable border.
@ windowHasTitleBar
Indicates that the window should have a normal OS-specific title bar and frame.
The base class for all JUCE user-interface objects.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
int getNumChildComponents() const noexcept
Returns the number of child components that this component contains.
int getIndexOfChildComponent(const Component *child) const noexcept
Returns the index of this component in the list of child components.
int getHeight() const noexcept
Returns the component's height in pixels.
bool isShowing() const
Tests whether this component and all its parents are visible.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void setOpaque(bool shouldBeOpaque)
Indicates whether any parts of the component might be transparent.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
bool isOnDesktop() const noexcept
Returns true if this component is currently showing on the desktop.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
virtual void addToDesktop(int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
Makes this component appear as a window on the desktop.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
void setColour(int colourID, Colour newColour)
Registers a colour to be used for a particular purpose.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
int getWidth() const noexcept
Returns the component's width in pixels.
ComponentPeer * getPeer() const
Returns the heavyweight window that contains this component.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
int getParentWidth() const noexcept
Returns the width of the component's parent.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
int getParentHeight() const noexcept
Returns the height of the component's parent.
Component * getKioskModeComponent() const noexcept
Returns the component that is currently being used in kiosk-mode.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
static bool canUseSemiTransparentWindows() noexcept
True if the OS supports semitransparent windows.
A graphics context, used for drawing a component or image.
The standard JUCE splash screen component.
Contains position and status information about a mouse event.
Manages a rectangle and allows geometric operations to be performed on it.
String toString() const
Creates a string describing this rectangle.
void setY(ValueType newY) noexcept
Changes the rectangle's Y coordinate.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
void setSize(ValueType newWidth, ValueType newHeight) noexcept
Changes the rectangle's size, leaving the position of its top-left corner unchanged.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
void setPosition(Point< ValueType > newPos) noexcept
Changes the position of the rectangle's top-left corner (leaving its size unchanged).
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
bool isEmpty() const noexcept
Returns true if the rectangle's width or height are zero or less.
void setX(ValueType newX) noexcept
Changes the rectangle's X coordinate.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Changes all the rectangle's coordinates.
A component that resizes its parent component when dragged.
A component that resizes a parent component when dragged.
void setResizable(bool shouldBeResizable, bool useBottomRightCornerResizer)
Make the window resizable or fixed.
void setBoundsConstrained(const Rectangle< int > &newBounds)
Calls the window's setBounds method, after first checking these bounds with the current constrainer.
void setFullScreen(bool shouldBeFullScreen)
Puts the window into full-screen mode, or restores it to its normal size.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
String getWindowStateAsString()
Returns a string which encodes the window's current size and position.
void setDraggable(bool shouldBeDraggable) noexcept
Can be used to enable or disable user-dragging of the window.
void resized() override
(if overriding this, make sure you call ResizableWindow::resized() in your subclass)
bool isResizable() const noexcept
Returns true if resizing is enabled.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
void setResizeLimits(int newMinimumWidth, int newMinimumHeight, int newMaximumWidth, int newMaximumHeight) noexcept
This sets the maximum and minimum sizes for the window.
bool isMinimised() const
Returns true if the window is currently minimised.
bool isKioskMode() const
Returns true if the window has been placed in kiosk-mode.
void setContentOwned(Component *newContentComponent, bool resizeToFitWhenContentChangesSize)
Changes the current content component.
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
void clearContentComponent()
Removes the current content component.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
@ backgroundColourId
A colour to use to fill the window's background.
void setBackgroundColour(Colour newColour)
Changes the colour currently being used for the window's background.
void visibilityChanged() override
Called when this component's visibility changes.
virtual BorderSize< int > getContentComponentBorder()
Returns the insets to use when positioning the content component.
void paint(Graphics &) override
Components can override this method to draw their content.
virtual BorderSize< int > getBorderThickness()
Returns the width of the frame to use around the window.
bool isFullScreen() const
Returns true if the window is currently in full-screen mode.
void activeWindowStatusChanged() override
This callback happens when this window becomes active or inactive.
void parentSizeChanged() override
Called when this component's immediate parent has been resized.
Colour getBackgroundColour() const noexcept
Returns the colour currently being used for the window's background.
void setConstrainer(ComponentBoundsConstrainer *newConstrainer)
Sets the bounds-constrainer object to use for resizing and dragging this window.
void moved() override
(if overriding this, make sure you call ResizableWindow::moved() in your subclass)
bool restoreWindowStateFromString(const String &previousState)
Restores the window to a previously-saved size and position.
void setContentNonOwned(Component *newContentComponent, bool resizeToFitWhenContentChangesSize)
Changes the current content component.
~ResizableWindow() override
Destructor.
void setContentComponentSize(int width, int height)
Changes the window so that the content component ends up with the specified size.
void childBoundsChanged(Component *) override
Called when one of this component's children is moved or resized.
void setMinimised(bool shouldMinimise)
Minimises the window, or restores it to its previous position and size.
void addToDesktop()
Adds the window to the desktop using the default flags.
A special array for holding a list of strings.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
int size() const noexcept
Returns the number of strings in the array.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
A base class for top-level windows.
void visibilityChanged() override
Called when this component's visibility changes.
bool isUsingNativeTitleBar() const noexcept
Returns true if the window is currently using an OS-native title bar.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.