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)
: TopLevelWindow (title, true),
alertIconType (iconType),
associatedComponent (comp),
escapeKeyCancels (true)
associatedComponent (comp)
{
setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
@@ -71,7 +70,7 @@ void AlertWindow::userTriedToCloseWindow()
//==============================================================================
void AlertWindow::setMessage (const String& message)
{
const String newMessage (message.substring (0, 2048));
auto newMessage = message.substring (0, 2048);
if (text != newMessage)
{
@@ -84,7 +83,7 @@ void AlertWindow::setMessage (const String& message)
//==============================================================================
void AlertWindow::buttonClicked (Button* button)
{
if (Component* parent = button->getParentComponent())
if (auto* parent = button->getParentComponent())
parent->exitModalState (button->getCommandID());
}
@@ -94,7 +93,7 @@ void AlertWindow::addButton (const String& name,
const KeyPress& shortcutKey1,
const KeyPress& shortcutKey2)
{
TextButton* const b = new TextButton (name, String());
auto* b = new TextButton (name, {});
buttons.add (b);
b->setWantsKeyboardFocus (true);
@@ -105,19 +104,18 @@ void AlertWindow::addButton (const String& name,
b->addListener (this);
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());
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);
updateLayout (false);
}
@@ -128,10 +126,8 @@ int AlertWindow::getNumButtons() const
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())
{
b->triggerClick();
@@ -151,7 +147,7 @@ void AlertWindow::addTextEditor (const String& name,
const String& onScreenLabel,
const bool isPasswordBox)
{
TextEditor* ed = new TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0);
auto* ed = new TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0);
ed->setSelectAllWhenFocused (true);
ed->setEscapeAndReturnKeysConsumed (false);
textBoxes.add (ed);
@@ -169,9 +165,9 @@ void AlertWindow::addTextEditor (const String& name,
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;
}
@@ -190,7 +186,7 @@ void AlertWindow::addComboBox (const String& name,
const StringArray& items,
const String& onScreenLabel)
{
ComboBox* const cb = new ComboBox (name);
auto* cb = new ComboBox (name);
comboBoxes.add (cb);
allComps.add (cb);
@@ -205,9 +201,9 @@ void AlertWindow::addComboBox (const String& name,
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;
}
@@ -231,15 +227,12 @@ public:
setScrollbarsShown (true);
lookAndFeelChanged();
setWantsKeyboardFocus (false);
setFont (font);
setText (message, false);
bestWidth = 2 * (int) std::sqrt (font.getHeight() * font.getStringWidth (message));
}
int getPreferredWidth() const noexcept { return bestWidth; }
void updateLayout (const int width)
{
AttributedString s;
@@ -251,7 +244,6 @@ public:
setSize (width, jmin (width, (int) (text.getHeight() + getFont().getHeight())));
}
private:
int bestWidth;
JUCE_DECLARE_NON_COPYABLE (AlertTextComp)
@@ -259,10 +251,9 @@ private:
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);
allComps.add (c);
addAndMakeVisible (c);
updateLayout (false);
@@ -271,10 +262,9 @@ void AlertWindow::addTextBlock (const String& textBlock)
//==============================================================================
void AlertWindow::addProgressBarComponent (double& progressValue)
{
ProgressBar* const pb = new ProgressBar (progressValue);
auto* pb = new ProgressBar (progressValue);
progressBars.add (pb);
allComps.add (pb);
addAndMakeVisible (pb);
updateLayout (false);
@@ -285,25 +275,17 @@ void AlertWindow::addCustomComponent (Component* const component)
{
customComps.add (component);
allComps.add (component);
addAndMakeVisible (component);
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* const c = getCustomComponent (index);
auto* c = getCustomComponent (index);
if (c != nullptr)
{
@@ -320,14 +302,15 @@ Component* AlertWindow::removeCustomComponent (const int index)
//==============================================================================
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.setFont (getLookAndFeel().getAlertWindowFont());
g.setFont (lf.getAlertWindowFont());
for (int i = textBoxes.size(); --i >= 0;)
{
const TextEditor* const te = textBoxes.getUnchecked(i);
auto* te = textBoxes.getUnchecked(i);
g.drawFittedText (textboxNames[i],
te->getX(), te->getY() - 14,
@@ -337,7 +320,7 @@ void AlertWindow::paint (Graphics& g)
for (int i = comboBoxNames.size(); --i >= 0;)
{
const ComboBox* const cb = comboBoxes.getUnchecked(i);
auto* cb = comboBoxes.getUnchecked(i);
g.drawFittedText (comboBoxNames[i],
cb->getX(), cb->getY() - 14,
@@ -345,15 +328,11 @@ void AlertWindow::paint (Graphics& g)
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(),
c->getX(), c->getY() - 14,
c->getWidth(), 14,
Justification::centredLeft, 1);
}
}
void AlertWindow::updateLayout (const bool onlyIncreaseSize)
@@ -361,15 +340,14 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
const int titleH = 24;
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 labelHeight = 18;
int iconSpace = 0;
@@ -397,24 +375,24 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
w = jmax (350, (int) textLayout.getWidth() + iconSpace + edgeGap * 4);
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 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);
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);
h += 10 + c->getHeight();
@@ -422,17 +400,14 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
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));
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));
h += ac->getHeight() + 10;
}
@@ -455,15 +430,14 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
const int spacer = 16;
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();
c->setTopLeftPosition (x, ny);
if (ny < y)
@@ -476,9 +450,8 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize)
y = textBottom;
for (int i = 0; i < allComps.size(); ++i)
for (auto* c : allComps)
{
Component* const c = allComps.getUnchecked(i);
h = 22;
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)
{
for (int i = buttons.size(); --i >= 0;)
for (auto* b : buttons)
{
TextButton* const b = buttons.getUnchecked(i);
if (b->isRegisteredForShortcut (key))
{
b->triggerClick();
@@ -579,8 +550,7 @@ public:
AlertWindow::AlertIconType icon, int numButts,
ModalComponentManager::Callback* cb, bool runModally)
: 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:
AlertWindow::AlertIconType iconType;
int numButtons, returnValue;
int numButtons, returnValue = 0;
WeakReference<Component> associatedComponent;
ModalComponentManager::Callback* callback;
bool modal;
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,
iconType, numButtons, associatedComponent));


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

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


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

@@ -27,8 +27,8 @@
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);
@@ -84,7 +84,7 @@ public:
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!
@@ -110,7 +110,7 @@ void CallOutBox::paint (Graphics& g)
void CallOutBox::resized()
{
const int borderSpace = getBorderSize();
auto borderSpace = getBorderSize();
content.setTopLeftPosition (borderSpace, borderSpace);
refreshPath();
}
@@ -143,7 +143,8 @@ void CallOutBox::inputAttemptWhenModal()
// as Windows still sends touch events before the CallOutBox had a chance
// to really open.
RelativeTime elapsed = Time::getCurrentTime() - creationTime;
auto elapsed = Time::getCurrentTime() - creationTime;
if (elapsed.inMilliseconds() > 200)
dismiss();
}
@@ -193,29 +194,29 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
targetArea = newAreaToPointTo;
availableArea = newAreaToFitIn;
const int borderSpace = getBorderSize();
auto borderSpace = getBorderSize();
Rectangle<int> newBounds (content.getWidth() + 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;
@@ -224,8 +225,8 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
Line<float> constrainedLine (centrePointArea.getConstrainedPoint (lines[i].getStart()),
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]))
distanceFromCentre += 1000.0f;
@@ -233,8 +234,8 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
if (distanceFromCentre < nearest)
{
nearest = distanceFromCentre;
targetPoint = targets[i];
newBounds.setPosition ((int) (centre.x - hw),
(int) (centre.y - hh));
}
@@ -246,7 +247,7 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
void CallOutBox::refreshPath()
{
repaint();
background = Image();
background = {};
outline.clear();
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.
*/
CallOutBox (Component& contentComponent,
const Rectangle<int>& areaToPointTo,
Rectangle<int> areaToPointTo,
Component* parentComponent);
/** Destructor. */
@@ -117,7 +117,7 @@ public:
If this is a nullptr, the call-out will be added to the desktop.
*/
static CallOutBox& launchAsynchronously (Component* contentComponent,
const Rectangle<int>& areaToPointTo,
Rectangle<int> areaToPointTo,
Component* parentComponent);
/** Posts a message which will dismiss the callout box asynchronously.
@@ -167,13 +167,13 @@ public:
private:
//==============================================================================
float arrowSize;
Component& content;
Path outline;
Point<float> targetPoint;
Rectangle<int> availableArea, targetArea;
Image background;
bool dismissalMouseClicksAreAlwaysConsumed;
float arrowSize = 16.0f;
bool dismissalMouseClicksAreAlwaysConsumed = false;
Time creationTime;


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

@@ -63,7 +63,7 @@ void DialogWindow::resized()
if (escapeKeyTriggersCloseButton)
{
if (Button* const close = getCloseButton())
if (auto* close = getCloseButton())
{
const KeyPress esc (KeyPress::escapeKey, 0, 0);
@@ -102,15 +102,7 @@ private:
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()
{
@@ -121,7 +113,7 @@ DialogWindow* DialogWindow::LaunchOptions::create()
DialogWindow* DialogWindow::LaunchOptions::launchAsync()
{
DialogWindow* const d = create();
auto* d = create();
d->enterModalState (true, nullptr, true);
return d;
}


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

@@ -87,7 +87,7 @@ public:
String dialogTitle;
/** 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!
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
more info about this parameter.
*/
Component* componentToCentreAround;
Component* componentToCentreAround = nullptr;
/** 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() */
bool useNativeTitleBar;
bool useNativeTitleBar = true;
/** 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() */
bool useBottomRightCornerResizer;
bool useBottomRightCornerResizer = false;
/** Launches a new modal dialog window.
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_,
bool addToDesktop_)
: ResizableWindow (title, backgroundColour, addToDesktop_),
titleBarHeight (26),
menuBarHeight (24),
requiredButtons (requiredButtons_),
#if JUCE_MAC
positionTitleBarButtonsOnLeft (true),
positionTitleBarButtonsOnLeft (true)
#else
positionTitleBarButtonsOnLeft (false),
positionTitleBarButtonsOnLeft (false)
#endif
drawTitleTextCentred (true),
menuBarModel (nullptr)
{
setResizeLimits (128, 128, 32768, 32768);
@@ -77,8 +73,8 @@ DocumentWindow::~DocumentWindow()
jassert (titleBarButtons[1] == nullptr || getIndexOfChildComponent (titleBarButtons[1]) >= 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;
}
@@ -193,16 +189,16 @@ void DocumentWindow::paint (Graphics& g)
{
ResizableWindow::paint (g);
const Rectangle<int> titleBarArea (getTitleBarArea());
auto titleBarArea = getTitleBarArea();
g.reduceClipRegion (titleBarArea);
g.setOrigin (titleBarArea.getPosition());
int titleSpaceX1 = 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)
titleSpaceX1 = jmax (titleSpaceX1, b->getRight() + (getWidth() - b->getRight()) / 8);
@@ -224,10 +220,10 @@ void DocumentWindow::resized()
{
ResizableWindow::resized();
if (Button* const b = getMaximiseButton())
if (auto* b = getMaximiseButton())
b->setToggleState (isFullScreen(), dontSendNotification);
const Rectangle<int> titleBarArea (getTitleBarArea());
auto titleBarArea = getTitleBarArea();
getLookAndFeel()
.positionDocumentWindowButtons (*this,
@@ -250,7 +246,7 @@ BorderSize<int> DocumentWindow::getBorderThickness()
BorderSize<int> DocumentWindow::getContentComponentBorder()
{
BorderSize<int> border (getBorderThickness());
auto border = getBorderThickness();
if (! isKioskMode())
border.setTop (border.getTop()
@@ -267,13 +263,11 @@ int DocumentWindow::getTitleBarHeight() const
Rectangle<int> DocumentWindow::getTitleBarArea()
{
const BorderSize<int> border (getBorderThickness());
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]; }
@@ -282,7 +276,7 @@ Button* DocumentWindow::getMaximiseButton() const noexcept { return titleBarBut
int DocumentWindow::getDesktopWindowStyleFlags() const
{
int styleFlags = ResizableWindow::getDesktopWindowStyleFlags();
auto styleFlags = ResizableWindow::getDesktopWindowStyleFlags();
if ((requiredButtons & minimiseButton) != 0) styleFlags |= ComponentPeer::windowHasMinimiseButton;
if ((requiredButtons & maximiseButton) != 0) styleFlags |= ComponentPeer::windowHasMaximiseButton;
@@ -293,8 +287,8 @@ int DocumentWindow::getDesktopWindowStyleFlags() const
void DocumentWindow::lookAndFeelChanged()
{
for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
titleBarButtons[i] = nullptr;
for (auto& b : titleBarButtons)
b = nullptr;
if (! isUsingNativeTitleBar())
{
@@ -304,9 +298,9 @@ void DocumentWindow::lookAndFeelChanged()
if ((requiredButtons & maximiseButton) != 0) titleBarButtons[1] = lf.createDocumentWindowButton (maximiseButton);
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)
buttonListener = new ButtonListenerProxy (*this);
@@ -319,7 +313,7 @@ void DocumentWindow::lookAndFeelChanged()
}
}
if (Button* const b = getCloseButton())
if (auto* b = getCloseButton())
{
#if JUCE_MAC
b->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
@@ -342,21 +336,21 @@ void DocumentWindow::parentHierarchyChanged()
void DocumentWindow::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)
menuBar->setEnabled (isActiveWindow());
menuBar->setEnabled (isActive);
}
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()


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

@@ -276,12 +276,12 @@ public:
private:
//==============================================================================
int titleBarHeight, menuBarHeight, requiredButtons;
bool positionTitleBarButtonsOnLeft, drawTitleTextCentred;
int titleBarHeight = 26, menuBarHeight = 24, requiredButtons;
bool positionTitleBarButtonsOnLeft, drawTitleTextCentred = true;
ScopedPointer<Button> titleBarButtons [3];
Image titleBarIcon;
ScopedPointer<Component> menuBar;
MenuBarModel* menuBarModel;
MenuBarModel* menuBarModel = nullptr;
class 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)
{
setBackgroundColour (bkgnd);
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..
const BorderSize<int> border (getContentComponentBorder());
auto border = getContentComponentBorder();
setSize (width + border.getLeftAndRight(),
height + border.getTopAndBottom());
@@ -177,7 +176,7 @@ void ResizableWindow::setContentComponentSize (int width, int height)
BorderSize<int> ResizableWindow::getBorderThickness()
{
if (isUsingNativeTitleBar() || isKioskMode())
return BorderSize<int>();
return {};
return BorderSize<int> ((resizableBorder != nullptr && ! isFullScreen()) ? 4 : 1);
}
@@ -195,7 +194,6 @@ void ResizableWindow::moved()
void ResizableWindow::visibilityChanged()
{
TopLevelWindow::visibilityChanged();
updateLastPosIfShowing();
}
@@ -256,9 +254,9 @@ void ResizableWindow::childBoundsChanged (Component* child)
//==============================================================================
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.removeFromLeft (border.getLeft()));
repaint (area.removeFromRight (border.getRight()));
@@ -308,10 +306,10 @@ bool ResizableWindow::isResizable() const noexcept
|| 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..
jassert (constrainer == &defaultConstrainer || constrainer == nullptr);
@@ -336,8 +334,8 @@ void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* 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;
resizableBorder = nullptr;
@@ -358,7 +356,7 @@ void ResizableWindow::setBoundsConstrained (const Rectangle<int>& newBounds)
//==============================================================================
void ResizableWindow::paint (Graphics& g)
{
LookAndFeel& lf = getLookAndFeel();
auto& lf = getLookAndFeel();
lf.fillResizableWindowBackground (g, getWidth(), getHeight(),
getBorderThickness(), *this);
@@ -401,13 +399,12 @@ Colour ResizableWindow::getBackgroundColour() const noexcept
void ResizableWindow::setBackgroundColour (Colour newColour)
{
Colour backgroundColour (newColour);
auto backgroundColour = newColour;
if (! Desktop::canUseSemiTransparentWindows())
backgroundColour = newColour.withAlpha (1.0f);
setColour (backgroundColourId, backgroundColour);
setOpaque (backgroundColour.isOpaque());
repaint();
}
@@ -417,7 +414,7 @@ bool ResizableWindow::isFullScreen() const
{
if (isOnDesktop())
{
ComponentPeer* const peer = getPeer();
auto* peer = getPeer();
return peer != nullptr && peer->isFullScreen();
}
@@ -433,10 +430,10 @@ void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
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
const Rectangle<int> lastPos (lastNonFullScreenPos);
auto lastPos = lastNonFullScreenPos;
peer->setFullScreen (shouldBeFullScreen);
@@ -462,7 +459,7 @@ void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
bool ResizableWindow::isMinimised() const
{
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
return peer->isMinimised();
return false;
@@ -472,7 +469,7 @@ void ResizableWindow::setMinimised (const bool shouldMinimise)
{
if (shouldMinimise != isMinimised())
{
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
{
updateLastPosIfShowing();
peer->setMinimised (shouldMinimise);
@@ -487,7 +484,7 @@ void ResizableWindow::setMinimised (const bool shouldMinimise)
bool ResizableWindow::isKioskMode() const
{
if (isOnDesktop())
if (ComponentPeer* peer = getPeer())
if (auto* peer = getPeer())
return peer->isKioskMode();
return Desktop::getInstance().getKioskModeComponent() == this;
@@ -511,7 +508,7 @@ void ResizableWindow::updateLastPosIfNotFullScreen()
void ResizableWindow::updatePeerConstrainer()
{
if (isOnDesktop())
if (ComponentPeer* const peer = getPeer())
if (auto* peer = getPeer())
peer->setConstrainer (constrainer);
}
@@ -549,19 +546,20 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s)
if (newPos.isEmpty())
return false;
ComponentPeer* const peer = isOnDesktop() ? getPeer() : nullptr;
auto* peer = isOnDesktop() ? getPeer() : nullptr;
if (peer != nullptr)
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);
const Rectangle<int> onScreenArea (allMonitors.getBounds());
auto onScreenArea = allMonitors.getBounds();
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()),
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
{
public:
TopLevelWindowManager() : currentActive (nullptr)
{
}
~TopLevelWindowManager()
{
clearSingletonInstance();
}
TopLevelWindowManager() {}
~TopLevelWindowManager() { clearSingletonInstance(); }
juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
@@ -52,14 +46,14 @@ public:
{
startTimer (jmin (1731, getTimerInterval() * 2));
TopLevelWindow* newActive = findCurrentlyActiveWindow();
auto* newActive = findCurrentlyActiveWindow();
if (newActive != currentActive)
{
currentActive = newActive;
for (int i = windows.size(); --i >= 0;)
if (TopLevelWindow* tlw = windows[i])
if (auto* tlw = windows[i])
tlw->setWindowActive (isWindowActive (tlw));
Desktop::getInstance().triggerFocusCallback();
@@ -83,14 +77,14 @@ public:
windows.removeFirstMatchingValue (w);
if (windows.size() == 0)
if (windows.isEmpty())
deleteInstance();
}
Array<TopLevelWindow*> windows;
private:
TopLevelWindow* currentActive;
TopLevelWindow* currentActive = nullptr;
void timerCallback() override
{
@@ -109,8 +103,8 @@ private:
{
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)
w = focusedComp->findParentComponentOfClass<TopLevelWindow>();
@@ -133,16 +127,13 @@ juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
void juce_checkCurrentlyFocusedTopLevelWindow();
void juce_checkCurrentlyFocusedTopLevelWindow()
{
if (TopLevelWindowManager* const wm = TopLevelWindowManager::getInstanceWithoutCreating())
if (auto* wm = TopLevelWindowManager::getInstanceWithoutCreating())
wm->checkFocusAsync();
}
//==============================================================================
TopLevelWindow::TopLevelWindow (const String& name, const bool shouldAddToDesktop)
: Component (name),
useDropShadow (true),
useNativeTitleBar (false),
isCurrentlyActive (false)
: Component (name)
{
setOpaque (true);
@@ -165,7 +156,7 @@ TopLevelWindow::~TopLevelWindow()
//==============================================================================
void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
{
TopLevelWindowManager* const wm = TopLevelWindowManager::getInstance();
auto* wm = TopLevelWindowManager::getInstance();
if (hasKeyboardFocus (true))
wm->checkFocus();
@@ -194,7 +185,7 @@ bool TopLevelWindow::isUsingNativeTitleBar() const noexcept
void TopLevelWindow::visibilityChanged()
{
if (isShowing())
if (ComponentPeer* p = getPeer())
if (auto* p = getPeer())
if ((p->getStyleFlags() & (ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses)) == 0)
toFront (true);
@@ -302,10 +293,10 @@ void TopLevelWindow::centreAroundComponent (Component* c, const int width, const
}
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);
parentArea = parent->getLocalBounds();
@@ -336,13 +327,13 @@ TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() noexcept
for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
{
TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
auto* tlw = TopLevelWindow::getTopLevelWindow (i);
if (tlw->isActiveWindow())
{
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)
++numTWLParents;


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

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


Loading…
Cancel
Save