Browse Source

ComponentPeer: Deprecate getFrameSize()

v6.1.6
attila 3 years ago
parent
commit
6575d24a81
8 changed files with 67 additions and 10 deletions
  1. +24
    -0
      BREAKING-CHANGES.txt
  2. +2
    -1
      extras/Projucer/Source/Application/jucer_MainWindow.cpp
  3. +2
    -1
      modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h
  4. +2
    -1
      modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp
  5. +10
    -1
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
  6. +15
    -2
      modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
  7. +3
    -0
      modules/juce_gui_basics/windows/juce_ComponentPeer.h
  8. +9
    -4
      modules/juce_gui_basics/windows/juce_ResizableWindow.cpp

+ 24
- 0
BREAKING-CHANGES.txt View File

@@ -4,6 +4,30 @@ JUCE breaking changes
develop
=======

Change
------
The ComponentPeer::getFrameSize() function has been deprecated on Linux.

Possible Issues
---------------
Deprecation warnings will be seen when compiling code which uses this function
and eventually builds will fail when it is later removed from the API.

Workaround
----------
Use the ComponentPeer::getFrameSizeIfPresent() function. The new function returns
an OptionalBorderSize object. Use operator bool() to determine if the border size
is valid, then access the value using operator*() only if it is.

Rationale
---------
The XWindow system cannot return a valid border size immediately after window
creation. ComponentPeer::getFrameSize() returns a default constructed
BorderSize<int> instance in such cases that corresponds to a frame size of
zero. That however can be a valid value, and needs to be treated differently
from the situation when the frame size is not yet available.


Change
------
The return type of XWindowSystem::getBorderSize() was changed to


+ 2
- 1
extras/Projucer/Source/Application/jucer_MainWindow.cpp View File

@@ -1012,7 +1012,8 @@ void MainWindowList::checkWindowBounds (MainWindow& windowToCheck)
auto screenLimits = Desktop::getInstance().getDisplays().getDisplayForRect (windowBounds)->userArea;
if (auto* peer = windowToCheck.getPeer())
peer->getFrameSize().subtractFrom (screenLimits);
if (const auto frameSize = peer->getFrameSizeIfPresent())
frameSize->subtractFrom (screenLimits);
auto constrainedX = jlimit (screenLimits.getX(), jmax (screenLimits.getX(), screenLimits.getRight() - windowBounds.getWidth()), windowBounds.getX());
auto constrainedY = jlimit (screenLimits.getY(), jmax (screenLimits.getY(), screenLimits.getBottom() - windowBounds.getHeight()), windowBounds.getY());


+ 2
- 1
modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h View File

@@ -983,7 +983,8 @@ private:
const auto windowBorders = [&]() -> BorderSize<int>
{
if (auto* peer = owner.getPeer())
return peer->getFrameSize();
if (const auto frameSize = peer->getFrameSizeIfPresent())
return *frameSize;
return {};
}();


+ 2
- 1
modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp View File

@@ -114,7 +114,8 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* component,
else
{
if (auto* peer = component->getPeer())
border = peer->getFrameSize();
if (const auto frameSize = peer->getFrameSizeIfPresent())
border = *frameSize;
auto screenBounds = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre())->userArea;


+ 10
- 1
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -2390,7 +2390,16 @@ private:
{
if (auto* constrainer = owner->getConstrainer())
{
const auto originalBounds = owner->getFrameSize().addedTo (owner->getComponent().getScreenBounds()).toFloat();
const auto originalBounds = [&]() -> Rectangle<float>
{
const auto screenBounds = owner->getComponent().getScreenBounds();
if (const auto frameSize = owner->getFrameSizeIfPresent())
return frameSize->addedTo (screenBounds).toFloat();
return screenBounds.toFloat();
}();
const auto expanded = originalBounds.withWidth ((float) constrainer->getMaximumWidth())
.withHeight ((float) constrainer->getMaximumHeight());
const auto constrained = expanded.constrainedWithin (convertToRectFloat (flippedScreenRect (r)));


+ 15
- 2
modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp View File

@@ -1744,7 +1744,13 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle<int> newBounds, bool
X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints.get());
}
auto windowBorder = peer->getFrameSize();
const auto windowBorder = [&]() -> BorderSize<int>
{
if (const auto& frameSize = peer->getFrameSizeIfPresent())
return *frameSize;
return {};
}();
X11Symbols::getInstance()->xMoveResizeWindow (display, windowH,
newBounds.getX() - windowBorder.getLeft(),
@@ -1774,7 +1780,14 @@ void XWindowSystem::updateConstraints (::Window windowH, ComponentPeer& peer) co
}
else if (auto* c = peer.getConstrainer())
{
const auto windowBorder = peer.getFrameSize();
const auto windowBorder = [&]() -> BorderSize<int>
{
if (const auto& frameSize = peer.getFrameSizeIfPresent())
return *frameSize;
return {};
}();
const auto factor = peer.getPlatformScaleFactor();
const auto leftAndRight = windowBorder.getLeftAndRight();
const auto topAndBottom = windowBorder.getTopAndBottom();


+ 3
- 0
modules/juce_gui_basics/windows/juce_ComponentPeer.h View File

@@ -260,6 +260,9 @@ public:
Whether or not the window has a normal window frame depends on the flags
that were set when the window was created by Component::addToDesktop()
*/
#if JUCE_LINUX || JUCE_BSD
[[deprecated ("Use getFrameSizeIfPresent instead.")]]
#endif
virtual BorderSize<int> getFrameSize() const = 0;
/** This is called when the window's bounds change.


+ 9
- 4
modules/juce_gui_basics/windows/juce_ResizableWindow.cpp View File

@@ -532,9 +532,12 @@ String ResizableWindow::getWindowStateAsString()
#if JUCE_LINUX
if (auto* peer = isOnDesktop() ? getPeer() : nullptr)
{
const auto frameSize = peer->getFrameSize();
stateString << " frame " << frameSize.getTop() << ' ' << frameSize.getLeft()
<< ' ' << frameSize.getBottom() << ' ' << frameSize.getRight();
if (const auto optionalFrameSize = peer->getFrameSizeIfPresent())
{
const auto& frameSize = *optionalFrameSize;
stateString << " frame " << frameSize.getTop() << ' ' << frameSize.getLeft()
<< ' ' << frameSize.getBottom() << ' ' << frameSize.getRight();
}
}
#endif
@@ -610,7 +613,9 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s)
if (peer != nullptr)
{
peer->getFrameSize().subtractFrom (newPos);
if (const auto frameSize = peer->getFrameSizeIfPresent())
frameSize->subtractFrom (newPos);
peer->setNonFullScreenBounds (newPos);
}


Loading…
Cancel
Save