diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp index b019f7d34f..f35ba3c49c 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp @@ -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 buttonsArray (buttons.begin(), buttons.size()); + auto& lf = getLookAndFeel(); - const int buttonHeight = getLookAndFeel().getAlertWindowButtonHeight(); - const Array 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 (textBlocks.getUnchecked(i)); - w = jmax (w, ac->getPreferredWidth()); - } + for (auto* tb : textBlocks) + w = jmax (w, static_cast (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 (textBlocks.getUnchecked(i)); + auto* ac = static_cast (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 (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 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 alertBox (lf.createAlertWindow (title, message, button1, button2, button3, iconType, numButtons, associatedComponent)); diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.h b/modules/juce_gui_basics/windows/juce_AlertWindow.h index e3f3ce5692..13dc9154f6 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.h +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.h @@ -479,8 +479,8 @@ private: OwnedArray textBlocks; Array allComps; StringArray textboxNames, comboBoxNames; - Component* associatedComponent; - bool escapeKeyCancels; + Component* const associatedComponent; + bool escapeKeyCancels = true; void updateLayout (bool onlyIncreaseSize); diff --git a/modules/juce_gui_basics/windows/juce_CallOutBox.cpp b/modules/juce_gui_basics/windows/juce_CallOutBox.cpp index d867b8748b..0fa102f008 100644 --- a/modules/juce_gui_basics/windows/juce_CallOutBox.cpp +++ b/modules/juce_gui_basics/windows/juce_CallOutBox.cpp @@ -27,8 +27,8 @@ namespace juce { -CallOutBox::CallOutBox (Component& c, const Rectangle& area, Component* const parent) - : arrowSize (16.0f), content (c), dismissalMouseClicksAreAlwaysConsumed (false) +CallOutBox::CallOutBox (Component& c, Rectangle 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& area, Component* parent) +CallOutBox& CallOutBox::launchAsynchronously (Component* content, Rectangle 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& newAreaToPointTo, const R targetArea = newAreaToPointTo; availableArea = newAreaToFitIn; - const int borderSpace = getBorderSize(); + auto borderSpace = getBorderSize(); Rectangle 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 targets[4] = { Point ((float) targetArea.getCentreX(), (float) targetArea.getBottom()), - Point ((float) targetArea.getRight(), (float) targetArea.getCentreY()), - Point ((float) targetArea.getX(), (float) targetArea.getCentreY()), - Point ((float) targetArea.getCentreX(), (float) targetArea.getY()) }; + Point 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 lines[4] = { Line (targets[0].translated (-hwReduced, hh - arrowIndent), targets[0].translated (hwReduced, hh - arrowIndent)), - Line (targets[1].translated (hw - arrowIndent, -hhReduced), targets[1].translated (hw - arrowIndent, hhReduced)), - Line (targets[2].translated (-(hw - arrowIndent), -hhReduced), targets[2].translated (-(hw - arrowIndent), hhReduced)), - Line (targets[3].translated (-hwReduced, -(hh - arrowIndent)), targets[3].translated (hwReduced, -(hh - arrowIndent))) }; + Line 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 centrePointArea (newAreaToFitIn.reduced (hw, hh).toFloat()); - const Point 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& newAreaToPointTo, const R Line constrainedLine (centrePointArea.getConstrainedPoint (lines[i].getStart()), centrePointArea.getConstrainedPoint (lines[i].getEnd())); - const Point 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& 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& newAreaToPointTo, const R void CallOutBox::refreshPath() { repaint(); - background = Image(); + background = {}; outline.clear(); const float gap = 4.5f; diff --git a/modules/juce_gui_basics/windows/juce_CallOutBox.h b/modules/juce_gui_basics/windows/juce_CallOutBox.h index 0a52efbf3f..fbfecb82c3 100644 --- a/modules/juce_gui_basics/windows/juce_CallOutBox.h +++ b/modules/juce_gui_basics/windows/juce_CallOutBox.h @@ -73,7 +73,7 @@ public: If this is a nullptr, the call-out will be added to the desktop. */ CallOutBox (Component& contentComponent, - const Rectangle& areaToPointTo, + Rectangle 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& areaToPointTo, + Rectangle 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 targetPoint; Rectangle availableArea, targetArea; Image background; - bool dismissalMouseClicksAreAlwaysConsumed; + float arrowSize = 16.0f; + bool dismissalMouseClicksAreAlwaysConsumed = false; Time creationTime; diff --git a/modules/juce_gui_basics/windows/juce_DialogWindow.cpp b/modules/juce_gui_basics/windows/juce_DialogWindow.cpp index 0c6af0d1ee..9f99b66f53 100644 --- a/modules/juce_gui_basics/windows/juce_DialogWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_DialogWindow.cpp @@ -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; } diff --git a/modules/juce_gui_basics/windows/juce_DialogWindow.h b/modules/juce_gui_basics/windows/juce_DialogWindow.h index 090af5697a..db5516b072 100644 --- a/modules/juce_gui_basics/windows/juce_DialogWindow.h +++ b/modules/juce_gui_basics/windows/juce_DialogWindow.h @@ -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, diff --git a/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp b/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp index c81be075a2..018a0f08bd 100644 --- a/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp @@ -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 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 titleBarArea (getTitleBarArea()); + auto titleBarArea = getTitleBarArea(); getLookAndFeel() .positionDocumentWindowButtons (*this, @@ -250,7 +246,7 @@ BorderSize DocumentWindow::getBorderThickness() BorderSize DocumentWindow::getContentComponentBorder() { - BorderSize border (getBorderThickness()); + auto border = getBorderThickness(); if (! isKioskMode()) border.setTop (border.getTop() @@ -267,13 +263,11 @@ int DocumentWindow::getTitleBarHeight() const Rectangle DocumentWindow::getTitleBarArea() { - const BorderSize border (getBorderThickness()); - if (isKioskMode()) - return Rectangle(); + return {}; - return Rectangle (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() diff --git a/modules/juce_gui_basics/windows/juce_DocumentWindow.h b/modules/juce_gui_basics/windows/juce_DocumentWindow.h index d6da6cd363..ca75123e71 100644 --- a/modules/juce_gui_basics/windows/juce_DocumentWindow.h +++ b/modules/juce_gui_basics/windows/juce_DocumentWindow.h @@ -276,12 +276,12 @@ public: private: //============================================================================== - int titleBarHeight, menuBarHeight, requiredButtons; - bool positionTitleBarButtonsOnLeft, drawTitleTextCentred; + int titleBarHeight = 26, menuBarHeight = 24, requiredButtons; + bool positionTitleBarButtonsOnLeft, drawTitleTextCentred = true; ScopedPointer