Browse Source

Some internal modernisation in windowing classes

tags/2021-05-28
jules 8 years ago
parent
commit
c42719c2eb
11 changed files with 173 additions and 227 deletions
  1. +59
    -89
      modules/juce_gui_basics/windows/juce_AlertWindow.cpp
  2. +2
    -2
      modules/juce_gui_basics/windows/juce_AlertWindow.h
  3. +26
    -25
      modules/juce_gui_basics/windows/juce_CallOutBox.cpp
  4. +4
    -4
      modules/juce_gui_basics/windows/juce_CallOutBox.h
  5. +3
    -11
      modules/juce_gui_basics/windows/juce_DialogWindow.cpp
  6. +6
    -6
      modules/juce_gui_basics/windows/juce_DialogWindow.h
  7. +27
    -33
      modules/juce_gui_basics/windows/juce_DocumentWindow.cpp
  8. +3
    -3
      modules/juce_gui_basics/windows/juce_DocumentWindow.h
  9. +25
    -27
      modules/juce_gui_basics/windows/juce_ResizableWindow.cpp
  10. +17
    -26
      modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp
  11. +1
    -1
      modules/juce_gui_basics/windows/juce_TopLevelWindow.h

+ 59
- 89
modules/juce_gui_basics/windows/juce_AlertWindow.cpp View File

@@ -43,8 +43,7 @@ AlertWindow::AlertWindow (const String& title,
Component* comp) Component* comp)
: TopLevelWindow (title, true), : TopLevelWindow (title, true),
alertIconType (iconType), alertIconType (iconType),
associatedComponent (comp),
escapeKeyCancels (true)
associatedComponent (comp)
{ {
setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows()); setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
@@ -71,7 +70,7 @@ void AlertWindow::userTriedToCloseWindow()
//============================================================================== //==============================================================================
void AlertWindow::setMessage (const String& message) void AlertWindow::setMessage (const String& message)
{ {
const String newMessage (message.substring (0, 2048));
auto newMessage = message.substring (0, 2048);
if (text != newMessage) if (text != newMessage)
{ {
@@ -84,7 +83,7 @@ void AlertWindow::setMessage (const String& message)
//============================================================================== //==============================================================================
void AlertWindow::buttonClicked (Button* button) void AlertWindow::buttonClicked (Button* button)
{ {
if (Component* parent = button->getParentComponent())
if (auto* parent = button->getParentComponent())
parent->exitModalState (button->getCommandID()); parent->exitModalState (button->getCommandID());
} }
@@ -94,7 +93,7 @@ void AlertWindow::addButton (const String& name,
const KeyPress& shortcutKey1, const KeyPress& shortcutKey1,
const KeyPress& shortcutKey2) const KeyPress& shortcutKey2)
{ {
TextButton* const b = new TextButton (name, String());
auto* b = new TextButton (name, {});
buttons.add (b); buttons.add (b);
b->setWantsKeyboardFocus (true); b->setWantsKeyboardFocus (true);
@@ -105,19 +104,18 @@ void AlertWindow::addButton (const String& name,
b->addListener (this); b->addListener (this);
Array<TextButton*> buttonsArray (buttons.begin(), buttons.size()); Array<TextButton*> buttonsArray (buttons.begin(), buttons.size());
auto& lf = getLookAndFeel();
const int buttonHeight = getLookAndFeel().getAlertWindowButtonHeight();
const Array<int> buttonWidths = getLookAndFeel().getWidthsForTextButtons (*this, buttonsArray);
auto buttonHeight = lf.getAlertWindowButtonHeight();
auto buttonWidths = lf.getWidthsForTextButtons (*this, buttonsArray);
jassert (buttonWidths.size() == buttons.size()); jassert (buttonWidths.size() == buttons.size());
int i = 0;
const int n = buttonWidths.size();
for (int i = 0; i < n; ++i)
buttons.getUnchecked (i)->setSize (buttonWidths.getReference (i), buttonHeight);
for (auto* button : buttons)
button->setSize (buttonWidths[i++], buttonHeight);
addAndMakeVisible (b, 0); addAndMakeVisible (b, 0);
updateLayout (false); updateLayout (false);
} }
@@ -128,10 +126,8 @@ int AlertWindow::getNumButtons() const
void AlertWindow::triggerButtonClick (const String& buttonName) void AlertWindow::triggerButtonClick (const String& buttonName)
{ {
for (int i = buttons.size(); --i >= 0;)
for (auto* b : buttons)
{ {
TextButton* const b = buttons.getUnchecked(i);
if (buttonName == b->getName()) if (buttonName == b->getName())
{ {
b->triggerClick(); b->triggerClick();
@@ -151,7 +147,7 @@ void AlertWindow::addTextEditor (const String& name,
const String& onScreenLabel, const String& onScreenLabel,
const bool isPasswordBox) const bool isPasswordBox)
{ {
TextEditor* ed = new TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0);
auto* ed = new TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0);
ed->setSelectAllWhenFocused (true); ed->setSelectAllWhenFocused (true);
ed->setEscapeAndReturnKeysConsumed (false); ed->setEscapeAndReturnKeysConsumed (false);
textBoxes.add (ed); textBoxes.add (ed);
@@ -169,9 +165,9 @@ void AlertWindow::addTextEditor (const String& name,
TextEditor* AlertWindow::getTextEditor (const String& nameOfTextEditor) const TextEditor* AlertWindow::getTextEditor (const String& nameOfTextEditor) const
{ {
for (int i = textBoxes.size(); --i >= 0;)
if (textBoxes.getUnchecked(i)->getName() == nameOfTextEditor)
return textBoxes.getUnchecked(i);
for (auto* tb : textBoxes)
if (tb->getName() == nameOfTextEditor)
return tb;
return nullptr; return nullptr;
} }
@@ -190,7 +186,7 @@ void AlertWindow::addComboBox (const String& name,
const StringArray& items, const StringArray& items,
const String& onScreenLabel) const String& onScreenLabel)
{ {
ComboBox* const cb = new ComboBox (name);
auto* cb = new ComboBox (name);
comboBoxes.add (cb); comboBoxes.add (cb);
allComps.add (cb); allComps.add (cb);
@@ -205,9 +201,9 @@ void AlertWindow::addComboBox (const String& name,
ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
{ {
for (int i = comboBoxes.size(); --i >= 0;)
if (comboBoxes.getUnchecked(i)->getName() == nameOfList)
return comboBoxes.getUnchecked(i);
for (auto* cb : comboBoxes)
if (cb->getName() == nameOfList)
return cb;
return nullptr; return nullptr;
} }
@@ -231,15 +227,12 @@ public:
setScrollbarsShown (true); setScrollbarsShown (true);
lookAndFeelChanged(); lookAndFeelChanged();
setWantsKeyboardFocus (false); setWantsKeyboardFocus (false);
setFont (font); setFont (font);
setText (message, false); setText (message, false);
bestWidth = 2 * (int) std::sqrt (font.getHeight() * font.getStringWidth (message)); bestWidth = 2 * (int) std::sqrt (font.getHeight() * font.getStringWidth (message));
} }
int getPreferredWidth() const noexcept { return bestWidth; }
void updateLayout (const int width) void updateLayout (const int width)
{ {
AttributedString s; AttributedString s;
@@ -251,7 +244,6 @@ public:
setSize (width, jmin (width, (int) (text.getHeight() + getFont().getHeight()))); setSize (width, jmin (width, (int) (text.getHeight() + getFont().getHeight())));
} }
private:
int bestWidth; int bestWidth;
JUCE_DECLARE_NON_COPYABLE (AlertTextComp) JUCE_DECLARE_NON_COPYABLE (AlertTextComp)
@@ -259,10 +251,9 @@ private:
void AlertWindow::addTextBlock (const String& textBlock) void AlertWindow::addTextBlock (const String& textBlock)
{ {
AlertTextComp* const c = new AlertTextComp (*this, textBlock, getLookAndFeel().getAlertWindowMessageFont());
auto* c = new AlertTextComp (*this, textBlock, getLookAndFeel().getAlertWindowMessageFont());
textBlocks.add (c); textBlocks.add (c);
allComps.add (c); allComps.add (c);
addAndMakeVisible (c); addAndMakeVisible (c);
updateLayout (false); updateLayout (false);
@@ -271,10 +262,9 @@ void AlertWindow::addTextBlock (const String& textBlock)
//============================================================================== //==============================================================================
void AlertWindow::addProgressBarComponent (double& progressValue) void AlertWindow::addProgressBarComponent (double& progressValue)
{ {
ProgressBar* const pb = new ProgressBar (progressValue);
auto* pb = new ProgressBar (progressValue);
progressBars.add (pb); progressBars.add (pb);
allComps.add (pb); allComps.add (pb);
addAndMakeVisible (pb); addAndMakeVisible (pb);
updateLayout (false); updateLayout (false);
@@ -285,25 +275,17 @@ void AlertWindow::addCustomComponent (Component* const component)
{ {
customComps.add (component); customComps.add (component);
allComps.add (component); allComps.add (component);
addAndMakeVisible (component); addAndMakeVisible (component);
updateLayout (false); updateLayout (false);
} }
int AlertWindow::getNumCustomComponents() const
{
return customComps.size();
}
Component* AlertWindow::getCustomComponent (const int index) const
{
return customComps [index];
}
int AlertWindow::getNumCustomComponents() const { return customComps.size(); }
Component* AlertWindow::getCustomComponent (int index) const { return customComps [index]; }
Component* AlertWindow::removeCustomComponent (const int index) Component* AlertWindow::removeCustomComponent (const int index)
{ {
Component* const c = getCustomComponent (index);
auto* c = getCustomComponent (index);
if (c != nullptr) if (c != nullptr)
{ {
@@ -320,14 +302,15 @@ Component* AlertWindow::removeCustomComponent (const int index)
//============================================================================== //==============================================================================
void AlertWindow::paint (Graphics& g) void AlertWindow::paint (Graphics& g)
{ {
getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
auto& lf = getLookAndFeel();
lf.drawAlertBox (g, *this, textArea, textLayout);
g.setColour (findColour (textColourId)); g.setColour (findColour (textColourId));
g.setFont (getLookAndFeel().getAlertWindowFont());
g.setFont (lf.getAlertWindowFont());
for (int i = textBoxes.size(); --i >= 0;) for (int i = textBoxes.size(); --i >= 0;)
{ {
const TextEditor* const te = textBoxes.getUnchecked(i);
auto* te = textBoxes.getUnchecked(i);
g.drawFittedText (textboxNames[i], g.drawFittedText (textboxNames[i],
te->getX(), te->getY() - 14, te->getX(), te->getY() - 14,
@@ -337,7 +320,7 @@ void AlertWindow::paint (Graphics& g)
for (int i = comboBoxNames.size(); --i >= 0;) for (int i = comboBoxNames.size(); --i >= 0;)
{ {
const ComboBox* const cb = comboBoxes.getUnchecked(i);
auto* cb = comboBoxes.getUnchecked(i);
g.drawFittedText (comboBoxNames[i], g.drawFittedText (comboBoxNames[i],
cb->getX(), cb->getY() - 14, cb->getX(), cb->getY() - 14,
@@ -345,15 +328,11 @@ void AlertWindow::paint (Graphics& g)
Justification::centredLeft, 1); Justification::centredLeft, 1);
} }
for (int i = customComps.size(); --i >= 0;)
{
const Component* const c = customComps.getUnchecked(i);
for (auto* c : customComps)
g.drawFittedText (c->getName(), g.drawFittedText (c->getName(),
c->getX(), c->getY() - 14, c->getX(), c->getY() - 14,
c->getWidth(), 14, c->getWidth(), 14,
Justification::centredLeft, 1); Justification::centredLeft, 1);
}
} }
void AlertWindow::updateLayout (const bool onlyIncreaseSize) void AlertWindow::updateLayout (const bool onlyIncreaseSize)
@@ -361,15 +340,14 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
const int titleH = 24; const int titleH = 24;
const int iconWidth = 80; const int iconWidth = 80;
LookAndFeel& lf = getLookAndFeel();
auto& lf = getLookAndFeel();
auto messageFont (lf.getAlertWindowMessageFont());
const Font messageFont (lf.getAlertWindowMessageFont());
auto wid = jmax (messageFont.getStringWidth (text),
messageFont.getStringWidth (getName()));
const int wid = jmax (messageFont.getStringWidth (text),
messageFont.getStringWidth (getName()));
const int sw = (int) std::sqrt (messageFont.getHeight() * wid);
int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
auto sw = (int) std::sqrt (messageFont.getHeight() * wid);
auto w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
const int edgeGap = 10; const int edgeGap = 10;
const int labelHeight = 18; const int labelHeight = 18;
int iconSpace = 0; int iconSpace = 0;
@@ -397,24 +375,24 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
w = jmax (350, (int) textLayout.getWidth() + iconSpace + edgeGap * 4); w = jmax (350, (int) textLayout.getWidth() + iconSpace + edgeGap * 4);
w = jmin (w, (int) (getParentWidth() * 0.7f)); w = jmin (w, (int) (getParentWidth() * 0.7f));
const int textLayoutH = (int) textLayout.getHeight();
const int textBottom = 16 + titleH + textLayoutH;
auto textLayoutH = (int) textLayout.getHeight();
auto textBottom = 16 + titleH + textLayoutH;
int h = textBottom; int h = textBottom;
int buttonW = 40; int buttonW = 40;
for (int i = 0; i < buttons.size(); ++i)
buttonW += 16 + buttons.getUnchecked (i)->getWidth();
for (auto* b : buttons)
buttonW += 16 + b->getWidth();
w = jmax (buttonW, w); w = jmax (buttonW, w);
h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50; h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
if (buttons.size() > 0)
h += 20 + buttons.getUnchecked (0)->getHeight();
if (auto* b = buttons[0])
h += 20 + b->getHeight();
for (int i = customComps.size(); --i >= 0;)
for (auto* c : customComps)
{ {
Component* c = customComps.getUnchecked (i);
w = jmax (w, (c->getWidth() * 100) / 80); w = jmax (w, (c->getWidth() * 100) / 80);
h += 10 + c->getHeight(); h += 10 + c->getHeight();
@@ -422,17 +400,14 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
h += labelHeight; h += labelHeight;
} }
for (int i = textBlocks.size(); --i >= 0;)
{
const AlertTextComp* const ac = static_cast<const AlertTextComp*> (textBlocks.getUnchecked(i));
w = jmax (w, ac->getPreferredWidth());
}
for (auto* tb : textBlocks)
w = jmax (w, static_cast<const AlertTextComp*> (tb)->bestWidth);
w = jmin (w, (int) (getParentWidth() * 0.7f)); w = jmin (w, (int) (getParentWidth() * 0.7f));
for (int i = textBlocks.size(); --i >= 0;)
for (auto* tb : textBlocks)
{ {
AlertTextComp* const ac = static_cast<AlertTextComp*> (textBlocks.getUnchecked(i));
auto* ac = static_cast<AlertTextComp*> (tb);
ac->updateLayout ((int) (w * 0.8f)); ac->updateLayout ((int) (w * 0.8f));
h += ac->getHeight() + 10; h += ac->getHeight() + 10;
} }
@@ -455,15 +430,14 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
const int spacer = 16; const int spacer = 16;
int totalWidth = -spacer; int totalWidth = -spacer;
for (int i = buttons.size(); --i >= 0;)
totalWidth += buttons.getUnchecked(i)->getWidth() + spacer;
for (auto* b : buttons)
totalWidth += b->getWidth() + spacer;
int x = (w - totalWidth) / 2;
int y = (int) (getHeight() * 0.95f);
auto x = (w - totalWidth) / 2;
auto y = (int) (getHeight() * 0.95f);
for (int i = 0; i < buttons.size(); ++i)
for (auto* c : buttons)
{ {
TextButton* const c = buttons.getUnchecked(i);
int ny = proportionOfHeight (0.95f) - c->getHeight(); int ny = proportionOfHeight (0.95f) - c->getHeight();
c->setTopLeftPosition (x, ny); c->setTopLeftPosition (x, ny);
if (ny < y) if (ny < y)
@@ -476,9 +450,8 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
y = textBottom; y = textBottom;
for (int i = 0; i < allComps.size(); ++i)
for (auto* c : allComps)
{ {
Component* const c = allComps.getUnchecked(i);
h = 22; h = 22;
const int comboIndex = comboBoxes.indexOf (dynamic_cast<ComboBox*> (c)); const int comboIndex = comboBoxes.indexOf (dynamic_cast<ComboBox*> (c));
@@ -531,10 +504,8 @@ void AlertWindow::mouseDrag (const MouseEvent& e)
bool AlertWindow::keyPressed (const KeyPress& key) bool AlertWindow::keyPressed (const KeyPress& key)
{ {
for (int i = buttons.size(); --i >= 0;)
for (auto* b : buttons)
{ {
TextButton* const b = buttons.getUnchecked(i);
if (b->isRegisteredForShortcut (key)) if (b->isRegisteredForShortcut (key))
{ {
b->triggerClick(); b->triggerClick();
@@ -579,8 +550,7 @@ public:
AlertWindow::AlertIconType icon, int numButts, AlertWindow::AlertIconType icon, int numButts,
ModalComponentManager::Callback* cb, bool runModally) ModalComponentManager::Callback* cb, bool runModally)
: title (t), message (m), iconType (icon), numButtons (numButts), : title (t), message (m), iconType (icon), numButtons (numButts),
returnValue (0), associatedComponent (component),
callback (cb), modal (runModally)
associatedComponent (component), callback (cb), modal (runModally)
{ {
} }
@@ -594,15 +564,15 @@ public:
private: private:
AlertWindow::AlertIconType iconType; AlertWindow::AlertIconType iconType;
int numButtons, returnValue;
int numButtons, returnValue = 0;
WeakReference<Component> associatedComponent; WeakReference<Component> associatedComponent;
ModalComponentManager::Callback* callback; ModalComponentManager::Callback* callback;
bool modal; bool modal;
void show() void show()
{ {
LookAndFeel& lf = associatedComponent != nullptr ? associatedComponent->getLookAndFeel()
: LookAndFeel::getDefaultLookAndFeel();
auto& lf = associatedComponent != nullptr ? associatedComponent->getLookAndFeel()
: LookAndFeel::getDefaultLookAndFeel();
ScopedPointer<Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3, ScopedPointer<Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
iconType, numButtons, associatedComponent)); iconType, numButtons, associatedComponent));


+ 2
- 2
modules/juce_gui_basics/windows/juce_AlertWindow.h View File

@@ -479,8 +479,8 @@ private:
OwnedArray<Component> textBlocks; OwnedArray<Component> textBlocks;
Array<Component*> allComps; Array<Component*> allComps;
StringArray textboxNames, comboBoxNames; StringArray textboxNames, comboBoxNames;
Component* associatedComponent;
bool escapeKeyCancels;
Component* const associatedComponent;
bool escapeKeyCancels = true;
void updateLayout (bool onlyIncreaseSize); void updateLayout (bool onlyIncreaseSize);


+ 26
- 25
modules/juce_gui_basics/windows/juce_CallOutBox.cpp View File

@@ -27,8 +27,8 @@
namespace juce namespace juce
{ {
CallOutBox::CallOutBox (Component& c, const Rectangle<int>& area, Component* const parent)
: arrowSize (16.0f), content (c), dismissalMouseClicksAreAlwaysConsumed (false)
CallOutBox::CallOutBox (Component& c, Rectangle<int> area, Component* const parent)
: content (c)
{ {
addAndMakeVisible (content); addAndMakeVisible (content);
@@ -84,7 +84,7 @@ public:
JUCE_DECLARE_NON_COPYABLE (CallOutBoxCallback) JUCE_DECLARE_NON_COPYABLE (CallOutBoxCallback)
}; };
CallOutBox& CallOutBox::launchAsynchronously (Component* content, const Rectangle<int>& area, Component* parent)
CallOutBox& CallOutBox::launchAsynchronously (Component* content, Rectangle<int> area, Component* parent)
{ {
jassert (content != nullptr); // must be a valid content component! jassert (content != nullptr); // must be a valid content component!
@@ -110,7 +110,7 @@ void CallOutBox::paint (Graphics& g)
void CallOutBox::resized() void CallOutBox::resized()
{ {
const int borderSpace = getBorderSize();
auto borderSpace = getBorderSize();
content.setTopLeftPosition (borderSpace, borderSpace); content.setTopLeftPosition (borderSpace, borderSpace);
refreshPath(); refreshPath();
} }
@@ -143,7 +143,8 @@ void CallOutBox::inputAttemptWhenModal()
// as Windows still sends touch events before the CallOutBox had a chance // as Windows still sends touch events before the CallOutBox had a chance
// to really open. // to really open.
RelativeTime elapsed = Time::getCurrentTime() - creationTime;
auto elapsed = Time::getCurrentTime() - creationTime;
if (elapsed.inMilliseconds() > 200) if (elapsed.inMilliseconds() > 200)
dismiss(); dismiss();
} }
@@ -193,29 +194,29 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
targetArea = newAreaToPointTo; targetArea = newAreaToPointTo;
availableArea = newAreaToFitIn; availableArea = newAreaToFitIn;
const int borderSpace = getBorderSize();
auto borderSpace = getBorderSize();
Rectangle<int> newBounds (content.getWidth() + borderSpace * 2, Rectangle<int> newBounds (content.getWidth() + borderSpace * 2,
content.getHeight() + borderSpace * 2); content.getHeight() + borderSpace * 2);
const int hw = newBounds.getWidth() / 2;
const int hh = newBounds.getHeight() / 2;
const float hwReduced = (float) (hw - borderSpace * 2);
const float hhReduced = (float) (hh - borderSpace * 2);
const float arrowIndent = borderSpace - arrowSize;
auto hw = newBounds.getWidth() / 2;
auto hh = newBounds.getHeight() / 2;
auto hwReduced = (float) (hw - borderSpace * 2);
auto hhReduced = (float) (hh - borderSpace * 2);
auto arrowIndent = borderSpace - arrowSize;
Point<float> targets[4] = { Point<float> ((float) targetArea.getCentreX(), (float) targetArea.getBottom()),
Point<float> ((float) targetArea.getRight(), (float) targetArea.getCentreY()),
Point<float> ((float) targetArea.getX(), (float) targetArea.getCentreY()),
Point<float> ((float) targetArea.getCentreX(), (float) targetArea.getY()) };
Point<float> targets[4] = { { (float) targetArea.getCentreX(), (float) targetArea.getBottom() },
{ (float) targetArea.getRight(), (float) targetArea.getCentreY() },
{ (float) targetArea.getX(), (float) targetArea.getCentreY() },
{ (float) targetArea.getCentreX(), (float) targetArea.getY() } };
Line<float> lines[4] = { Line<float> (targets[0].translated (-hwReduced, hh - arrowIndent), targets[0].translated (hwReduced, hh - arrowIndent)),
Line<float> (targets[1].translated (hw - arrowIndent, -hhReduced), targets[1].translated (hw - arrowIndent, hhReduced)),
Line<float> (targets[2].translated (-(hw - arrowIndent), -hhReduced), targets[2].translated (-(hw - arrowIndent), hhReduced)),
Line<float> (targets[3].translated (-hwReduced, -(hh - arrowIndent)), targets[3].translated (hwReduced, -(hh - arrowIndent))) };
Line<float> lines[4] = { { targets[0].translated (-hwReduced, hh - arrowIndent), targets[0].translated (hwReduced, hh - arrowIndent) },
{ targets[1].translated (hw - arrowIndent, -hhReduced), targets[1].translated (hw - arrowIndent, hhReduced) },
{ targets[2].translated (-(hw - arrowIndent), -hhReduced), targets[2].translated (-(hw - arrowIndent), hhReduced) },
{ targets[3].translated (-hwReduced, -(hh - arrowIndent)), targets[3].translated (hwReduced, -(hh - arrowIndent)) } };
const Rectangle<float> centrePointArea (newAreaToFitIn.reduced (hw, hh).toFloat());
const Point<float> targetCentre (targetArea.getCentre().toFloat());
auto centrePointArea = newAreaToFitIn.reduced (hw, hh).toFloat();
auto targetCentre = targetArea.getCentre().toFloat();
float nearest = 1.0e9f; float nearest = 1.0e9f;
@@ -224,8 +225,8 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
Line<float> constrainedLine (centrePointArea.getConstrainedPoint (lines[i].getStart()), Line<float> constrainedLine (centrePointArea.getConstrainedPoint (lines[i].getStart()),
centrePointArea.getConstrainedPoint (lines[i].getEnd())); centrePointArea.getConstrainedPoint (lines[i].getEnd()));
const Point<float> centre (constrainedLine.findNearestPointTo (targetCentre));
float distanceFromCentre = centre.getDistanceFrom (targets[i]);
auto centre = constrainedLine.findNearestPointTo (targetCentre);
auto distanceFromCentre = centre.getDistanceFrom (targets[i]);
if (! centrePointArea.intersects (lines[i])) if (! centrePointArea.intersects (lines[i]))
distanceFromCentre += 1000.0f; distanceFromCentre += 1000.0f;
@@ -233,8 +234,8 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
if (distanceFromCentre < nearest) if (distanceFromCentre < nearest)
{ {
nearest = distanceFromCentre; nearest = distanceFromCentre;
targetPoint = targets[i]; targetPoint = targets[i];
newBounds.setPosition ((int) (centre.x - hw), newBounds.setPosition ((int) (centre.x - hw),
(int) (centre.y - hh)); (int) (centre.y - hh));
} }
@@ -246,7 +247,7 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
void CallOutBox::refreshPath() void CallOutBox::refreshPath()
{ {
repaint(); repaint();
background = Image();
background = {};
outline.clear(); outline.clear();
const float gap = 4.5f; const float gap = 4.5f;


+ 4
- 4
modules/juce_gui_basics/windows/juce_CallOutBox.h View File

@@ -73,7 +73,7 @@ public:
If this is a nullptr, the call-out will be added to the desktop. If this is a nullptr, the call-out will be added to the desktop.
*/ */
CallOutBox (Component& contentComponent, CallOutBox (Component& contentComponent,
const Rectangle<int>& areaToPointTo,
Rectangle<int> areaToPointTo,
Component* parentComponent); Component* parentComponent);
/** Destructor. */ /** Destructor. */
@@ -117,7 +117,7 @@ public:
If this is a nullptr, the call-out will be added to the desktop. If this is a nullptr, the call-out will be added to the desktop.
*/ */
static CallOutBox& launchAsynchronously (Component* contentComponent, static CallOutBox& launchAsynchronously (Component* contentComponent,
const Rectangle<int>& areaToPointTo,
Rectangle<int> areaToPointTo,
Component* parentComponent); Component* parentComponent);
/** Posts a message which will dismiss the callout box asynchronously. /** Posts a message which will dismiss the callout box asynchronously.
@@ -167,13 +167,13 @@ public:
private: private:
//============================================================================== //==============================================================================
float arrowSize;
Component& content; Component& content;
Path outline; Path outline;
Point<float> targetPoint; Point<float> targetPoint;
Rectangle<int> availableArea, targetArea; Rectangle<int> availableArea, targetArea;
Image background; Image background;
bool dismissalMouseClicksAreAlwaysConsumed;
float arrowSize = 16.0f;
bool dismissalMouseClicksAreAlwaysConsumed = false;
Time creationTime; Time creationTime;


+ 3
- 11
modules/juce_gui_basics/windows/juce_DialogWindow.cpp View File

@@ -63,7 +63,7 @@ void DialogWindow::resized()
if (escapeKeyTriggersCloseButton) if (escapeKeyTriggersCloseButton)
{ {
if (Button* const close = getCloseButton())
if (auto* close = getCloseButton())
{ {
const KeyPress esc (KeyPress::escapeKey, 0, 0); const KeyPress esc (KeyPress::escapeKey, 0, 0);
@@ -102,15 +102,7 @@ private:
JUCE_DECLARE_NON_COPYABLE (DefaultDialogWindow) JUCE_DECLARE_NON_COPYABLE (DefaultDialogWindow)
}; };
DialogWindow::LaunchOptions::LaunchOptions() noexcept
: dialogBackgroundColour (Colours::lightgrey),
componentToCentreAround (nullptr),
escapeKeyTriggersCloseButton (true),
useNativeTitleBar (true),
resizable (true),
useBottomRightCornerResizer (false)
{
}
DialogWindow::LaunchOptions::LaunchOptions() noexcept {}
DialogWindow* DialogWindow::LaunchOptions::create() DialogWindow* DialogWindow::LaunchOptions::create()
{ {
@@ -121,7 +113,7 @@ DialogWindow* DialogWindow::LaunchOptions::create()
DialogWindow* DialogWindow::LaunchOptions::launchAsync() DialogWindow* DialogWindow::LaunchOptions::launchAsync()
{ {
DialogWindow* const d = create();
auto* d = create();
d->enterModalState (true, nullptr, true); d->enterModalState (true, nullptr, true);
return d; return d;
} }


+ 6
- 6
modules/juce_gui_basics/windows/juce_DialogWindow.h View File

@@ -87,7 +87,7 @@ public:
String dialogTitle; String dialogTitle;
/** The background colour for the window. */ /** The background colour for the window. */
Colour dialogBackgroundColour;
Colour dialogBackgroundColour = Colours::lightgrey;
/** The content component to show in the window. This must not be null! /** The content component to show in the window. This must not be null!
Using an OptionalScopedPointer to hold this pointer lets you indicate whether Using an OptionalScopedPointer to hold this pointer lets you indicate whether
@@ -100,16 +100,16 @@ public:
dialog box in front of. See the DocumentWindow::centreAroundComponent() method for dialog box in front of. See the DocumentWindow::centreAroundComponent() method for
more info about this parameter. more info about this parameter.
*/ */
Component* componentToCentreAround;
Component* componentToCentreAround = nullptr;
/** If true, then the escape key will trigger the dialog's close button. */ /** If true, then the escape key will trigger the dialog's close button. */
bool escapeKeyTriggersCloseButton;
bool escapeKeyTriggersCloseButton = true;
/** If true, the dialog will use a native title bar. See TopLevelWindow::setUsingNativeTitleBar() */ /** If true, the dialog will use a native title bar. See TopLevelWindow::setUsingNativeTitleBar() */
bool useNativeTitleBar;
bool useNativeTitleBar = true;
/** If true, the window will be resizable. See ResizableWindow::setResizable() */ /** If true, the window will be resizable. See ResizableWindow::setResizable() */
bool resizable;
bool resizable = true;
/** Indicates whether to use a border or corner resizer component. See ResizableWindow::setResizable() */ /** Indicates whether to use a border or corner resizer component. See ResizableWindow::setResizable() */
bool useBottomRightCornerResizer;
bool useBottomRightCornerResizer = false;
/** Launches a new modal dialog window. /** Launches a new modal dialog window.
This will create a dialog based on the settings in this structure, This will create a dialog based on the settings in this structure,


+ 27
- 33
modules/juce_gui_basics/windows/juce_DocumentWindow.cpp View File

@@ -51,16 +51,12 @@ DocumentWindow::DocumentWindow (const String& title,
int requiredButtons_, int requiredButtons_,
bool addToDesktop_) bool addToDesktop_)
: ResizableWindow (title, backgroundColour, addToDesktop_), : ResizableWindow (title, backgroundColour, addToDesktop_),
titleBarHeight (26),
menuBarHeight (24),
requiredButtons (requiredButtons_), requiredButtons (requiredButtons_),
#if JUCE_MAC #if JUCE_MAC
positionTitleBarButtonsOnLeft (true),
positionTitleBarButtonsOnLeft (true)
#else #else
positionTitleBarButtonsOnLeft (false),
positionTitleBarButtonsOnLeft (false)
#endif #endif
drawTitleTextCentred (true),
menuBarModel (nullptr)
{ {
setResizeLimits (128, 128, 32768, 32768); setResizeLimits (128, 128, 32768, 32768);
@@ -77,8 +73,8 @@ DocumentWindow::~DocumentWindow()
jassert (titleBarButtons[1] == nullptr || getIndexOfChildComponent (titleBarButtons[1]) >= 0); jassert (titleBarButtons[1] == nullptr || getIndexOfChildComponent (titleBarButtons[1]) >= 0);
jassert (titleBarButtons[2] == nullptr || getIndexOfChildComponent (titleBarButtons[2]) >= 0); jassert (titleBarButtons[2] == nullptr || getIndexOfChildComponent (titleBarButtons[2]) >= 0);
for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
titleBarButtons[i] = nullptr;
for (auto& b : titleBarButtons)
b = nullptr;
menuBar = nullptr; menuBar = nullptr;
} }
@@ -193,16 +189,16 @@ void DocumentWindow::paint (Graphics& g)
{ {
ResizableWindow::paint (g); ResizableWindow::paint (g);
const Rectangle<int> titleBarArea (getTitleBarArea());
auto titleBarArea = getTitleBarArea();
g.reduceClipRegion (titleBarArea); g.reduceClipRegion (titleBarArea);
g.setOrigin (titleBarArea.getPosition()); g.setOrigin (titleBarArea.getPosition());
int titleSpaceX1 = 6; int titleSpaceX1 = 6;
int titleSpaceX2 = titleBarArea.getWidth() - 6; int titleSpaceX2 = titleBarArea.getWidth() - 6;
for (int i = 0; i < 3; ++i)
for (auto& b : titleBarButtons)
{ {
if (Button* const b = titleBarButtons[i])
if (b != nullptr)
{ {
if (positionTitleBarButtonsOnLeft) if (positionTitleBarButtonsOnLeft)
titleSpaceX1 = jmax (titleSpaceX1, b->getRight() + (getWidth() - b->getRight()) / 8); titleSpaceX1 = jmax (titleSpaceX1, b->getRight() + (getWidth() - b->getRight()) / 8);
@@ -224,10 +220,10 @@ void DocumentWindow::resized()
{ {
ResizableWindow::resized(); ResizableWindow::resized();
if (Button* const b = getMaximiseButton())
if (auto* b = getMaximiseButton())
b->setToggleState (isFullScreen(), dontSendNotification); b->setToggleState (isFullScreen(), dontSendNotification);
const Rectangle<int> titleBarArea (getTitleBarArea());
auto titleBarArea = getTitleBarArea();
getLookAndFeel() getLookAndFeel()
.positionDocumentWindowButtons (*this, .positionDocumentWindowButtons (*this,
@@ -250,7 +246,7 @@ BorderSize<int> DocumentWindow::getBorderThickness()
BorderSize<int> DocumentWindow::getContentComponentBorder() BorderSize<int> DocumentWindow::getContentComponentBorder()
{ {
BorderSize<int> border (getBorderThickness());
auto border = getBorderThickness();
if (! isKioskMode()) if (! isKioskMode())
border.setTop (border.getTop() border.setTop (border.getTop()
@@ -267,13 +263,11 @@ int DocumentWindow::getTitleBarHeight() const
Rectangle<int> DocumentWindow::getTitleBarArea() Rectangle<int> DocumentWindow::getTitleBarArea()
{ {
const BorderSize<int> border (getBorderThickness());
if (isKioskMode()) if (isKioskMode())
return Rectangle<int>();
return {};
return Rectangle<int> (border.getLeft(), border.getTop(),
getWidth() - border.getLeftAndRight(), getTitleBarHeight());
auto border = getBorderThickness();
return { border.getLeft(), border.getTop(), getWidth() - border.getLeftAndRight(), getTitleBarHeight() };
} }
Button* DocumentWindow::getCloseButton() const noexcept { return titleBarButtons[2]; } Button* DocumentWindow::getCloseButton() const noexcept { return titleBarButtons[2]; }
@@ -282,7 +276,7 @@ Button* DocumentWindow::getMaximiseButton() const noexcept { return titleBarBut
int DocumentWindow::getDesktopWindowStyleFlags() const int DocumentWindow::getDesktopWindowStyleFlags() const
{ {
int styleFlags = ResizableWindow::getDesktopWindowStyleFlags();
auto styleFlags = ResizableWindow::getDesktopWindowStyleFlags();
if ((requiredButtons & minimiseButton) != 0) styleFlags |= ComponentPeer::windowHasMinimiseButton; if ((requiredButtons & minimiseButton) != 0) styleFlags |= ComponentPeer::windowHasMinimiseButton;
if ((requiredButtons & maximiseButton) != 0) styleFlags |= ComponentPeer::windowHasMaximiseButton; if ((requiredButtons & maximiseButton) != 0) styleFlags |= ComponentPeer::windowHasMaximiseButton;
@@ -293,8 +287,8 @@ int DocumentWindow::getDesktopWindowStyleFlags() const
void DocumentWindow::lookAndFeelChanged() void DocumentWindow::lookAndFeelChanged()
{ {
for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
titleBarButtons[i] = nullptr;
for (auto& b : titleBarButtons)
b = nullptr;
if (! isUsingNativeTitleBar()) if (! isUsingNativeTitleBar())
{ {
@@ -304,9 +298,9 @@ void DocumentWindow::lookAndFeelChanged()
if ((requiredButtons & maximiseButton) != 0) titleBarButtons[1] = lf.createDocumentWindowButton (maximiseButton); if ((requiredButtons & maximiseButton) != 0) titleBarButtons[1] = lf.createDocumentWindowButton (maximiseButton);
if ((requiredButtons & closeButton) != 0) titleBarButtons[2] = lf.createDocumentWindowButton (closeButton); if ((requiredButtons & closeButton) != 0) titleBarButtons[2] = lf.createDocumentWindowButton (closeButton);
for (int i = 0; i < 3; ++i)
for (auto& b : titleBarButtons)
{ {
if (Button* const b = titleBarButtons[i])
if (b != nullptr)
{ {
if (buttonListener == nullptr) if (buttonListener == nullptr)
buttonListener = new ButtonListenerProxy (*this); buttonListener = new ButtonListenerProxy (*this);
@@ -319,7 +313,7 @@ void DocumentWindow::lookAndFeelChanged()
} }
} }
if (Button* const b = getCloseButton())
if (auto* b = getCloseButton())
{ {
#if JUCE_MAC #if JUCE_MAC
b->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0)); b->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
@@ -342,21 +336,21 @@ void DocumentWindow::parentHierarchyChanged()
void DocumentWindow::activeWindowStatusChanged() void DocumentWindow::activeWindowStatusChanged()
{ {
ResizableWindow::activeWindowStatusChanged(); ResizableWindow::activeWindowStatusChanged();
bool isActive = isActiveWindow();
for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
if (Button* const b = titleBarButtons[i])
b->setEnabled (isActiveWindow());
for (auto& b : titleBarButtons)
if (b != nullptr)
b->setEnabled (isActive);
if (menuBar != nullptr) if (menuBar != nullptr)
menuBar->setEnabled (isActiveWindow());
menuBar->setEnabled (isActive);
} }
void DocumentWindow::mouseDoubleClick (const MouseEvent& e) void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
{ {
Button* const maximise = getMaximiseButton();
if (maximise != nullptr && getTitleBarArea().contains (e.x, e.y))
maximise->triggerClick();
if (getTitleBarArea().contains (e.x, e.y))
if (auto* maximise = getMaximiseButton())
maximise->triggerClick();
} }
void DocumentWindow::userTriedToCloseWindow() void DocumentWindow::userTriedToCloseWindow()


+ 3
- 3
modules/juce_gui_basics/windows/juce_DocumentWindow.h View File

@@ -276,12 +276,12 @@ public:
private: private:
//============================================================================== //==============================================================================
int titleBarHeight, menuBarHeight, requiredButtons;
bool positionTitleBarButtonsOnLeft, drawTitleTextCentred;
int titleBarHeight = 26, menuBarHeight = 24, requiredButtons;
bool positionTitleBarButtonsOnLeft, drawTitleTextCentred = true;
ScopedPointer<Button> titleBarButtons [3]; ScopedPointer<Button> titleBarButtons [3];
Image titleBarIcon; Image titleBarIcon;
ScopedPointer<Component> menuBar; ScopedPointer<Component> menuBar;
MenuBarModel* menuBarModel;
MenuBarModel* menuBarModel = nullptr;
class ButtonListenerProxy; class ButtonListenerProxy;
friend struct ContainerDeletePolicy<ButtonListenerProxy>; friend struct ContainerDeletePolicy<ButtonListenerProxy>;


+ 25
- 27
modules/juce_gui_basics/windows/juce_ResizableWindow.cpp View File

@@ -37,7 +37,6 @@ ResizableWindow::ResizableWindow (const String& name, Colour bkgnd, bool shouldA
: TopLevelWindow (name, shouldAddToDesktop) : TopLevelWindow (name, shouldAddToDesktop)
{ {
setBackgroundColour (bkgnd); setBackgroundColour (bkgnd);
initialise (shouldAddToDesktop); initialise (shouldAddToDesktop);
} }
@@ -168,7 +167,7 @@ void ResizableWindow::setContentComponentSize (int width, int height)
{ {
jassert (width > 0 && height > 0); // not a great idea to give it a zero size.. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
const BorderSize<int> border (getContentComponentBorder());
auto border = getContentComponentBorder();
setSize (width + border.getLeftAndRight(), setSize (width + border.getLeftAndRight(),
height + border.getTopAndBottom()); height + border.getTopAndBottom());
@@ -177,7 +176,7 @@ void ResizableWindow::setContentComponentSize (int width, int height)
BorderSize<int> ResizableWindow::getBorderThickness() BorderSize<int> ResizableWindow::getBorderThickness()
{ {
if (isUsingNativeTitleBar() || isKioskMode()) if (isUsingNativeTitleBar() || isKioskMode())
return BorderSize<int>();
return {};
return BorderSize<int> ((resizableBorder != nullptr && ! isFullScreen()) ? 4 : 1); return BorderSize<int> ((resizableBorder != nullptr && ! isFullScreen()) ? 4 : 1);
} }
@@ -195,7 +194,6 @@ void ResizableWindow::moved()
void ResizableWindow::visibilityChanged() void ResizableWindow::visibilityChanged()
{ {
TopLevelWindow::visibilityChanged(); TopLevelWindow::visibilityChanged();
updateLastPosIfShowing(); updateLastPosIfShowing();
} }
@@ -256,9 +254,9 @@ void ResizableWindow::childBoundsChanged (Component* child)
//============================================================================== //==============================================================================
void ResizableWindow::activeWindowStatusChanged() void ResizableWindow::activeWindowStatusChanged()
{ {
const BorderSize<int> border (getContentComponentBorder());
auto border = getContentComponentBorder();
auto area = getLocalBounds();
Rectangle<int> area (getLocalBounds());
repaint (area.removeFromTop (border.getTop())); repaint (area.removeFromTop (border.getTop()));
repaint (area.removeFromLeft (border.getLeft())); repaint (area.removeFromLeft (border.getLeft()));
repaint (area.removeFromRight (border.getRight())); repaint (area.removeFromRight (border.getRight()));
@@ -308,10 +306,10 @@ bool ResizableWindow::isResizable() const noexcept
|| resizableBorder != nullptr; || resizableBorder != nullptr;
} }
void ResizableWindow::setResizeLimits (const int newMinimumWidth,
const int newMinimumHeight,
const int newMaximumWidth,
const int newMaximumHeight) noexcept
void ResizableWindow::setResizeLimits (int newMinimumWidth,
int newMinimumHeight,
int newMaximumWidth,
int newMaximumHeight) noexcept
{ {
// if you've set up a custom constrainer then these settings won't have any effect.. // if you've set up a custom constrainer then these settings won't have any effect..
jassert (constrainer == &defaultConstrainer || constrainer == nullptr); jassert (constrainer == &defaultConstrainer || constrainer == nullptr);
@@ -336,8 +334,8 @@ void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer
{ {
constrainer = newConstrainer; constrainer = newConstrainer;
const bool useBottomRightCornerResizer = resizableCorner != nullptr;
const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != nullptr;
bool useBottomRightCornerResizer = resizableCorner != nullptr;
bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != nullptr;
resizableCorner = nullptr; resizableCorner = nullptr;
resizableBorder = nullptr; resizableBorder = nullptr;
@@ -358,7 +356,7 @@ void ResizableWindow::setBoundsConstrained (const Rectangle<int>& newBounds)
//============================================================================== //==============================================================================
void ResizableWindow::paint (Graphics& g) void ResizableWindow::paint (Graphics& g)
{ {
LookAndFeel& lf = getLookAndFeel();
auto& lf = getLookAndFeel();
lf.fillResizableWindowBackground (g, getWidth(), getHeight(), lf.fillResizableWindowBackground (g, getWidth(), getHeight(),
getBorderThickness(), *this); getBorderThickness(), *this);
@@ -401,13 +399,12 @@ Colour ResizableWindow::getBackgroundColour() const noexcept
void ResizableWindow::setBackgroundColour (Colour newColour) void ResizableWindow::setBackgroundColour (Colour newColour)
{ {
Colour backgroundColour (newColour);
auto backgroundColour = newColour;
if (! Desktop::canUseSemiTransparentWindows()) if (! Desktop::canUseSemiTransparentWindows())
backgroundColour = newColour.withAlpha (1.0f); backgroundColour = newColour.withAlpha (1.0f);
setColour (backgroundColourId, backgroundColour); setColour (backgroundColourId, backgroundColour);
setOpaque (backgroundColour.isOpaque()); setOpaque (backgroundColour.isOpaque());
repaint(); repaint();
} }
@@ -417,7 +414,7 @@ bool ResizableWindow::isFullScreen() const
{ {
if (isOnDesktop()) if (isOnDesktop())
{ {
ComponentPeer* const peer = getPeer();
auto* peer = getPeer();
return peer != nullptr && peer->isFullScreen(); return peer != nullptr && peer->isFullScreen();
} }
@@ -433,10 +430,10 @@ void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
if (isOnDesktop()) if (isOnDesktop())
{ {
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
{ {
// keep a copy of this intact in case the real one gets messed-up while we're un-maximising // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
const Rectangle<int> lastPos (lastNonFullScreenPos);
auto lastPos = lastNonFullScreenPos;
peer->setFullScreen (shouldBeFullScreen); peer->setFullScreen (shouldBeFullScreen);
@@ -462,7 +459,7 @@ void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
bool ResizableWindow::isMinimised() const bool ResizableWindow::isMinimised() const
{ {
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
return peer->isMinimised(); return peer->isMinimised();
return false; return false;
@@ -472,7 +469,7 @@ void ResizableWindow::setMinimised (const bool shouldMinimise)
{ {
if (shouldMinimise != isMinimised()) if (shouldMinimise != isMinimised())
{ {
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
{ {
updateLastPosIfShowing(); updateLastPosIfShowing();
peer->setMinimised (shouldMinimise); peer->setMinimised (shouldMinimise);
@@ -487,7 +484,7 @@ void ResizableWindow::setMinimised (const bool shouldMinimise)
bool ResizableWindow::isKioskMode() const bool ResizableWindow::isKioskMode() const
{ {
if (isOnDesktop()) if (isOnDesktop())
if (ComponentPeer* peer = getPeer())
if (auto* peer = getPeer())
return peer->isKioskMode(); return peer->isKioskMode();
return Desktop::getInstance().getKioskModeComponent() == this; return Desktop::getInstance().getKioskModeComponent() == this;
@@ -511,7 +508,7 @@ void ResizableWindow::updateLastPosIfNotFullScreen()
void ResizableWindow::updatePeerConstrainer() void ResizableWindow::updatePeerConstrainer()
{ {
if (isOnDesktop()) if (isOnDesktop())
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
peer->setConstrainer (constrainer); peer->setConstrainer (constrainer);
} }
@@ -549,19 +546,20 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s)
if (newPos.isEmpty()) if (newPos.isEmpty())
return false; return false;
ComponentPeer* const peer = isOnDesktop() ? getPeer() : nullptr;
auto* peer = isOnDesktop() ? getPeer() : nullptr;
if (peer != nullptr) if (peer != nullptr)
peer->getFrameSize().addTo (newPos); peer->getFrameSize().addTo (newPos);
{ {
Desktop& desktop = Desktop::getInstance();
RectangleList<int> allMonitors (desktop.getDisplays().getRectangleList (true));
auto& desktop = Desktop::getInstance();
auto allMonitors = desktop.getDisplays().getRectangleList (true);
allMonitors.clipTo (newPos); allMonitors.clipTo (newPos);
const Rectangle<int> onScreenArea (allMonitors.getBounds());
auto onScreenArea = allMonitors.getBounds();
if (onScreenArea.getWidth() * onScreenArea.getHeight() < 32 * 32) if (onScreenArea.getWidth() * onScreenArea.getHeight() < 32 * 32)
{ {
const Rectangle<int> screen (desktop.getDisplays().getDisplayContaining (newPos.getCentre()).userArea);
auto screen = desktop.getDisplays().getDisplayContaining (newPos.getCentre()).userArea;
newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()), newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
jmin (newPos.getHeight(), screen.getHeight())); jmin (newPos.getHeight(), screen.getHeight()));


+ 17
- 26
modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp View File

@@ -32,14 +32,8 @@ class TopLevelWindowManager : private Timer,
private DeletedAtShutdown private DeletedAtShutdown
{ {
public: public:
TopLevelWindowManager() : currentActive (nullptr)
{
}
~TopLevelWindowManager()
{
clearSingletonInstance();
}
TopLevelWindowManager() {}
~TopLevelWindowManager() { clearSingletonInstance(); }
juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager) juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
@@ -52,14 +46,14 @@ public:
{ {
startTimer (jmin (1731, getTimerInterval() * 2)); startTimer (jmin (1731, getTimerInterval() * 2));
TopLevelWindow* newActive = findCurrentlyActiveWindow();
auto* newActive = findCurrentlyActiveWindow();
if (newActive != currentActive) if (newActive != currentActive)
{ {
currentActive = newActive; currentActive = newActive;
for (int i = windows.size(); --i >= 0;) for (int i = windows.size(); --i >= 0;)
if (TopLevelWindow* tlw = windows[i])
if (auto* tlw = windows[i])
tlw->setWindowActive (isWindowActive (tlw)); tlw->setWindowActive (isWindowActive (tlw));
Desktop::getInstance().triggerFocusCallback(); Desktop::getInstance().triggerFocusCallback();
@@ -83,14 +77,14 @@ public:
windows.removeFirstMatchingValue (w); windows.removeFirstMatchingValue (w);
if (windows.size() == 0)
if (windows.isEmpty())
deleteInstance(); deleteInstance();
} }
Array<TopLevelWindow*> windows; Array<TopLevelWindow*> windows;
private: private:
TopLevelWindow* currentActive;
TopLevelWindow* currentActive = nullptr;
void timerCallback() override void timerCallback() override
{ {
@@ -109,8 +103,8 @@ private:
{ {
if (Process::isForegroundProcess()) if (Process::isForegroundProcess())
{ {
Component* const focusedComp = Component::getCurrentlyFocusedComponent();
TopLevelWindow* w = dynamic_cast<TopLevelWindow*> (focusedComp);
auto* focusedComp = Component::getCurrentlyFocusedComponent();
auto* w = dynamic_cast<TopLevelWindow*> (focusedComp);
if (w == nullptr && focusedComp != nullptr) if (w == nullptr && focusedComp != nullptr)
w = focusedComp->findParentComponentOfClass<TopLevelWindow>(); w = focusedComp->findParentComponentOfClass<TopLevelWindow>();
@@ -133,16 +127,13 @@ juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
void juce_checkCurrentlyFocusedTopLevelWindow(); void juce_checkCurrentlyFocusedTopLevelWindow();
void juce_checkCurrentlyFocusedTopLevelWindow() void juce_checkCurrentlyFocusedTopLevelWindow()
{ {
if (TopLevelWindowManager* const wm = TopLevelWindowManager::getInstanceWithoutCreating())
if (auto* wm = TopLevelWindowManager::getInstanceWithoutCreating())
wm->checkFocusAsync(); wm->checkFocusAsync();
} }
//============================================================================== //==============================================================================
TopLevelWindow::TopLevelWindow (const String& name, const bool shouldAddToDesktop) TopLevelWindow::TopLevelWindow (const String& name, const bool shouldAddToDesktop)
: Component (name),
useDropShadow (true),
useNativeTitleBar (false),
isCurrentlyActive (false)
: Component (name)
{ {
setOpaque (true); setOpaque (true);
@@ -165,7 +156,7 @@ TopLevelWindow::~TopLevelWindow()
//============================================================================== //==============================================================================
void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType) void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
{ {
TopLevelWindowManager* const wm = TopLevelWindowManager::getInstance();
auto* wm = TopLevelWindowManager::getInstance();
if (hasKeyboardFocus (true)) if (hasKeyboardFocus (true))
wm->checkFocus(); wm->checkFocus();
@@ -194,7 +185,7 @@ bool TopLevelWindow::isUsingNativeTitleBar() const noexcept
void TopLevelWindow::visibilityChanged() void TopLevelWindow::visibilityChanged()
{ {
if (isShowing()) if (isShowing())
if (ComponentPeer* p = getPeer())
if (auto* p = getPeer())
if ((p->getStyleFlags() & (ComponentPeer::windowIsTemporary if ((p->getStyleFlags() & (ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses)) == 0) | ComponentPeer::windowIgnoresKeyPresses)) == 0)
toFront (true); toFront (true);
@@ -302,10 +293,10 @@ void TopLevelWindow::centreAroundComponent (Component* c, const int width, const
} }
else else
{ {
Point<int> targetCentre (c->localPointToGlobal (c->getLocalBounds().getCentre()));
Rectangle<int> parentArea (c->getParentMonitorArea());
auto targetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre());
auto parentArea = c->getParentMonitorArea();
if (Component* const parent = getParentComponent())
if (auto* parent = getParentComponent())
{ {
targetCentre = parent->getLocalPoint (nullptr, targetCentre); targetCentre = parent->getLocalPoint (nullptr, targetCentre);
parentArea = parent->getLocalBounds(); parentArea = parent->getLocalBounds();
@@ -336,13 +327,13 @@ TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() noexcept
for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;) for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
{ {
TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
auto* tlw = TopLevelWindow::getTopLevelWindow (i);
if (tlw->isActiveWindow()) if (tlw->isActiveWindow())
{ {
int numTWLParents = 0; int numTWLParents = 0;
for (const Component* c = tlw->getParentComponent(); c != nullptr; c = c->getParentComponent())
for (auto* c = tlw->getParentComponent(); c != nullptr; c = c->getParentComponent())
if (dynamic_cast<const TopLevelWindow*> (c) != nullptr) if (dynamic_cast<const TopLevelWindow*> (c) != nullptr)
++numTWLParents; ++numTWLParents;


+ 1
- 1
modules/juce_gui_basics/windows/juce_TopLevelWindow.h View File

@@ -153,7 +153,7 @@ protected:
private: private:
friend class TopLevelWindowManager; friend class TopLevelWindowManager;
friend class ResizableWindow; friend class ResizableWindow;
bool useDropShadow, useNativeTitleBar, isCurrentlyActive;
bool useDropShadow = true, useNativeTitleBar = false, isCurrentlyActive = false;
ScopedPointer<DropShadower> shadower; ScopedPointer<DropShadower> shadower;
void setWindowActive (bool); void setWindowActive (bool);


Loading…
Cancel
Save