diff --git a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp index 1f5030f4f9..feb2003aba 100644 --- a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp +++ b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp @@ -315,9 +315,8 @@ struct AppearanceEditor if (fontsToScan.size() == 0) { getAppSettings().monospacedFontNames = fontsFound; - DialogWindow* w = findParentComponentOfClass(); - if (w != nullptr) + if (DialogWindow* w = findParentComponentOfClass()) w->setContentOwned (new EditorPanel(), false); } else diff --git a/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp b/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp index aa7187a36d..bc53f2a3d5 100644 --- a/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp +++ b/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp @@ -45,9 +45,8 @@ void DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Documen if (document == closingDoc) { jassert (document != nullptr); - ProjectContentComponent* pcc = findParentComponentOfClass(); - if (pcc != nullptr) + if (ProjectContentComponent* pcc = findParentComponentOfClass()) { pcc->hideDocument (document); return; diff --git a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp index 7215b005ad..ca6c5810aa 100644 --- a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp @@ -130,9 +130,7 @@ bool MainWindow::closeProject (Project* project) project->getStoredProperties().setValue (getProjectWindowPosName(), getWindowStateAsString()); - ProjectContentComponent* const pcc = getProjectContentComponent(); - - if (pcc != nullptr) + if (ProjectContentComponent* const pcc = getProjectContentComponent()) { pcc->saveTreeViewState(); pcc->saveOpenDocumentList(); @@ -262,8 +260,8 @@ void MainWindow::activeWindowStatusChanged() { DocumentWindow::activeWindowStatusChanged(); - if (getProjectContentComponent() != nullptr) - getProjectContentComponent()->updateMissingFileStatuses(); + if (ProjectContentComponent* const pcc = getProjectContentComponent()) + pcc->updateMissingFileStatuses(); IntrojucerApp::getApp().openDocumentManager.reloadModifiedFiles(); } @@ -506,10 +504,9 @@ void MainWindowList::saveCurrentlyOpenProjectList() Desktop& desktop = Desktop::getInstance(); for (int i = 0; i < desktop.getNumComponents(); ++i) { - MainWindow* const mw = dynamic_cast (desktop.getComponent(i)); - - if (mw != nullptr && mw->getProject() != nullptr) - projects.add (mw->getProject()->getFile()); + if (MainWindow* const mw = dynamic_cast (desktop.getComponent(i))) + if (Project* p = mw->getProject()) + projects.add (p->getFile()); } getAppSettings().setLastProjects (projects); diff --git a/extras/Introjucer/Source/Project/jucer_ModulesPanel.h b/extras/Introjucer/Source/Project/jucer_ModulesPanel.h index da81b73f2e..c7930090f2 100644 --- a/extras/Introjucer/Source/Project/jucer_ModulesPanel.h +++ b/extras/Introjucer/Source/Project/jucer_ModulesPanel.h @@ -168,9 +168,7 @@ public: if (rowIsSelected) g.fillAll (findColour (TextEditor::highlightColourId)); - const ModuleList::Module* const m = list.modules [rowNumber]; - - if (m != nullptr) + if (const ModuleList::Module* const m = list.modules [rowNumber]) { const float tickSize = height * 0.7f; @@ -210,9 +208,7 @@ public: void flipRow (int row) { - const ModuleList::Module* const m = list.modules [row]; - - if (m != nullptr) + if (const ModuleList::Module* const m = list.modules [row]) owner->setEnabled (m, ! owner->isEnabled (m)); } @@ -246,9 +242,9 @@ public: if (project.isModuleEnabled (moduleID)) { - const ModuleList::Module* m = moduleList.findModuleInfo (moduleID); - if (m != nullptr && moduleList.getExtraDependenciesNeeded (project, *m).size() > 0) - props.add (new MissingDependenciesComponent (project, moduleList, moduleID)); + if (const ModuleList::Module* m = moduleList.findModuleInfo (moduleID)) + if (moduleList.getExtraDependenciesNeeded (project, *m).size() > 0) + props.add (new MissingDependenciesComponent (project, moduleList, moduleID)); } props.add (new BooleanPropertyComponent (project.shouldShowAllModuleFilesInProject (moduleID), @@ -308,9 +304,7 @@ public: g.setColour (Colours::white.withAlpha (0.4f)); g.fillRect (0, 0, getWidth(), getHeight() - 1); - const ModuleList::Module* module = moduleList.findModuleInfo (moduleID); - - if (module != nullptr) + if (const ModuleList::Module* module = moduleList.findModuleInfo (moduleID)) { String text; text << module->name << newLine << "Version: " << module->version << newLine << newLine @@ -341,9 +335,7 @@ public: project (p), moduleList (list), moduleID (modID), fixButton ("Enable Required Modules") { - const ModuleList::Module* module = moduleList.findModuleInfo (moduleID); - - if (module != nullptr) + if (const ModuleList::Module* module = moduleList.findModuleInfo (moduleID)) missingDependencies = moduleList.getExtraDependenciesNeeded (project, *module); addAndMakeVisible (&fixButton); @@ -375,8 +367,7 @@ public: for (int i = missingDependencies.size(); --i >= 0;) project.addModule (missingDependencies[i], isModuleCopiedLocally); - ModulesPanel* mp = findParentComponentOfClass(); - if (mp != nullptr) + if (ModulesPanel* mp = findParentComponentOfClass()) mp->refresh(); } diff --git a/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp b/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp index e25c580a59..dea1455465 100644 --- a/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp +++ b/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp @@ -141,9 +141,7 @@ void AudioFormatReader::read (AudioSampleBuffer* buffer, { for (int j = 0; j < 2; ++j) { - float* const d = reinterpret_cast (chans[j]); - - if (d != nullptr) + if (float* const d = reinterpret_cast (chans[j])) { const float multiplier = 1.0f / 0x7fffffff; diff --git a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm index 22392b0328..4b1a301d96 100644 --- a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm +++ b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm @@ -727,12 +727,13 @@ public: { for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i) { - const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i); - - if (p != nullptr && p->presetNumber == index) + if (const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i)) { - s = String::fromCFString (p->presetName); - break; + if (p->presetNumber == index) + { + s = String::fromCFString (p->presetName); + break; + } } } diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp index c21793a130..333bf1b3d9 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp @@ -119,22 +119,19 @@ void AudioProcessor::setParameterNotifyingHost (const int parameterIndex, sendParamChangeMessageToListeners (parameterIndex, newValue); } +AudioProcessorListener* AudioProcessor::getListenerLocked (const int index) const noexcept +{ + const ScopedLock sl (listenerLock); + return listeners [index]; +} + void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue) { jassert (isPositiveAndBelow (parameterIndex, getNumParameters())); for (int i = listeners.size(); --i >= 0;) - { - AudioProcessorListener* l; - - { - const ScopedLock sl (listenerLock); - l = listeners [i]; - } - - if (l != nullptr) + if (AudioProcessorListener* l = getListenerLocked (i)) l->audioProcessorParameterChanged (this, parameterIndex, newValue); - } } void AudioProcessor::beginParameterChangeGesture (int parameterIndex) @@ -149,17 +146,8 @@ void AudioProcessor::beginParameterChangeGesture (int parameterIndex) #endif for (int i = listeners.size(); --i >= 0;) - { - AudioProcessorListener* l; - - { - const ScopedLock sl (listenerLock); - l = listeners [i]; - } - - if (l != nullptr) + if (AudioProcessorListener* l = getListenerLocked (i)) l->audioProcessorParameterChangeGestureBegin (this, parameterIndex); - } } void AudioProcessor::endParameterChangeGesture (int parameterIndex) @@ -175,33 +163,15 @@ void AudioProcessor::endParameterChangeGesture (int parameterIndex) #endif for (int i = listeners.size(); --i >= 0;) - { - AudioProcessorListener* l; - - { - const ScopedLock sl (listenerLock); - l = listeners [i]; - } - - if (l != nullptr) + if (AudioProcessorListener* l = getListenerLocked (i)) l->audioProcessorParameterChangeGestureEnd (this, parameterIndex); - } } void AudioProcessor::updateHostDisplay() { for (int i = listeners.size(); --i >= 0;) - { - AudioProcessorListener* l; - - { - const ScopedLock sl (listenerLock); - l = listeners [i]; - } - - if (l != nullptr) + if (AudioProcessorListener* l = getListenerLocked (i)) l->audioProcessorChanged (this); - } } String AudioProcessor::getParameterLabel (int) const { return String::empty; } diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessor.h b/modules/juce_audio_processors/processors/juce_AudioProcessor.h index 22ff64e03e..e7098fe542 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessor.h +++ b/modules/juce_audio_processors/processors/juce_AudioProcessor.h @@ -634,6 +634,8 @@ private: BigInteger changingParams; #endif + AudioProcessorListener* getListenerLocked (int) const noexcept; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessor) }; diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp index d431e84954..1fee618d8b 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp @@ -789,9 +789,8 @@ private: int recursionCheck) const noexcept { int index; - const Entry* const entry = findEntry (possibleDestinationId, index); - if (entry != nullptr) + if (const Entry* const entry = findEntry (possibleDestinationId, index)) { const SortedSet& srcNodes = entry->srcNodes; @@ -917,10 +916,8 @@ void AudioProcessorGraph::Node::unprepare() void AudioProcessorGraph::Node::setParentGraph (AudioProcessorGraph* const graph) const { - AudioProcessorGraph::AudioGraphIOProcessor* const ioProc - = dynamic_cast (processor.get()); - - if (ioProc != nullptr) + if (AudioProcessorGraph::AudioGraphIOProcessor* const ioProc + = dynamic_cast (processor.get())) ioProc->setParentGraph (graph); } diff --git a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp index a84958da4c..c8154d5893 100644 --- a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp @@ -411,9 +411,7 @@ public: updateControlPanelButton(); - AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice(); - - if (currentDevice != nullptr) + if (AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice()) { if (setup.maxNumOutputChannels > 0 && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size()) @@ -688,9 +686,7 @@ public: { items.clear(); - AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice(); - - if (currentDevice != nullptr) + if (AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice()) { if (type == audioInputType) items = currentDevice->getInputChannelNames(); @@ -1041,9 +1037,7 @@ void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasCha { if (comboBoxThatHasChanged == deviceTypeDropDown) { - AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1]; - - if (type != nullptr) + if (AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1]) { audioDeviceSettingsComp = nullptr; @@ -1074,11 +1068,9 @@ void AudioDeviceSelectorComponent::updateAllControls() audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType(); audioDeviceSettingsComp = nullptr; - AudioIODeviceType* const type - = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == nullptr - ? 0 : deviceTypeDropDown->getSelectedId() - 1]; - - if (type != nullptr) + if (AudioIODeviceType* const type + = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == nullptr + ? 0 : deviceTypeDropDown->getSelectedId() - 1]) { AudioDeviceSetupDetails details; details.manager = &deviceManager; diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp index 290555daaa..d29e29563a 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp @@ -211,12 +211,8 @@ private: void createReader() { if (reader == nullptr && source != nullptr) - { - InputStream* audioFileStream = source->createInputStream(); - - if (audioFileStream != nullptr) + if (InputStream* audioFileStream = source->createInputStream()) reader = owner.formatManagerToUse.createReaderFor (audioFileStream); - } } bool readNextBlock() diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp index 69ac7fc62b..4e7cc8b42e 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnailCache.cpp @@ -99,9 +99,8 @@ int AudioThumbnailCache::findOldestThumb() const bool AudioThumbnailCache::loadThumb (AudioThumbnailBase& thumb, const int64 hashCode) { const ScopedLock sl (lock); - ThumbnailCacheEntry* te = findThumbFor (hashCode); - if (te != nullptr) + if (ThumbnailCacheEntry* te = findThumbFor (hashCode)) { te->lastUsed = Time::getMillisecondCounter(); diff --git a/modules/juce_core/threads/juce_TimeSliceThread.cpp b/modules/juce_core/threads/juce_TimeSliceThread.cpp index 1f4f2d79e8..ba2d37e9d4 100644 --- a/modules/juce_core/threads/juce_TimeSliceThread.cpp +++ b/modules/juce_core/threads/juce_TimeSliceThread.cpp @@ -125,8 +125,7 @@ void TimeSliceThread::run() index = clients.size() > 0 ? ((index + 1) % clients.size()) : 0; - TimeSliceClient* const firstClient = getNextClient (index); - if (firstClient != nullptr) + if (TimeSliceClient* const firstClient = getNextClient (index)) nextClientTime = firstClient->nextCallTime; } diff --git a/modules/juce_core/xml/juce_XmlElement.cpp b/modules/juce_core/xml/juce_XmlElement.cpp index 1299aeb96e..27585047a8 100644 --- a/modules/juce_core/xml/juce_XmlElement.cpp +++ b/modules/juce_core/xml/juce_XmlElement.cpp @@ -254,7 +254,6 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, { outputStream.writeByte ('>'); - bool lastWasTextNode = false; for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem) @@ -500,9 +499,7 @@ void XmlElement::setAttribute (const String& attributeName, const String& value) } else { - XmlAttributeNode* att = attributes; - - for (;;) + for (XmlAttributeNode* att = attributes; ; att = att->nextListItem) { if (att->hasName (attributeName)) { @@ -514,8 +511,6 @@ void XmlElement::setAttribute (const String& attributeName, const String& value) att->nextListItem = new XmlAttributeNode (attributeName, value); break; } - - att = att->nextListItem; } } } @@ -532,17 +527,15 @@ void XmlElement::setAttribute (const String& attributeName, const double number) void XmlElement::removeAttribute (const String& attributeName) noexcept { - LinkedListPointer* att = &attributes; - - while (att->get() != nullptr) + for (LinkedListPointer* att = &attributes; + att->get() != nullptr; + att = &(att->get()->nextListItem)) { if (att->get()->hasName (attributeName)) { delete att->removeNext(); break; } - - att = &(att->get()->nextListItem); } } @@ -599,9 +592,7 @@ bool XmlElement::replaceChildElement (XmlElement* const currentChildElement, { if (newNode != nullptr) { - LinkedListPointer* const p = firstChildElement.findPointerTo (currentChildElement); - - if (p != nullptr) + if (LinkedListPointer* const p = firstChildElement.findPointerTo (currentChildElement)) { if (currentChildElement != newNode) delete p->replaceNext (newNode); @@ -705,9 +696,7 @@ void XmlElement::deleteAllChildElements() noexcept void XmlElement::deleteAllChildElementsWithTagName (const String& name) noexcept { - XmlElement* child = firstChildElement; - - while (child != nullptr) + for (XmlElement* child = firstChildElement; child != nullptr;) { XmlElement* const nextChild = child->nextListItem; @@ -733,9 +722,7 @@ XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLo if (elementToLookFor == child) return this; - XmlElement* const found = child->findParentElementOf (elementToLookFor); - - if (found != nullptr) + if (XmlElement* const found = child->findParentElementOf (elementToLookFor)) return found; } @@ -801,9 +788,7 @@ String XmlElement::getAllSubText() const String XmlElement::getChildElementAllSubText (const String& childTagName, const String& defaultReturnValue) const { - const XmlElement* const child = getChildByName (childTagName); - - if (child != nullptr) + if (const XmlElement* const child = getChildByName (childTagName)) return child->getAllSubText(); return defaultReturnValue; @@ -823,9 +808,7 @@ void XmlElement::addTextElement (const String& text) void XmlElement::deleteAllTextElements() noexcept { - XmlElement* child = firstChildElement; - - while (child != nullptr) + for (XmlElement* child = firstChildElement; child != nullptr;) { XmlElement* const next = child->nextListItem; diff --git a/modules/juce_core/zip/juce_ZipFile.cpp b/modules/juce_core/zip/juce_ZipFile.cpp index 798d3e0fe4..04c0a76328 100644 --- a/modules/juce_core/zip/juce_ZipFile.cpp +++ b/modules/juce_core/zip/juce_ZipFile.cpp @@ -265,8 +265,10 @@ int ZipFile::getNumEntries() const noexcept const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const noexcept { - ZipEntryHolder* const zei = entries [index]; - return zei != nullptr ? &(zei->entry) : nullptr; + if (ZipEntryHolder* const zei = entries [index]) + return &(zei->entry); + + return nullptr; } int ZipFile::getIndexOfFileName (const String& fileName) const noexcept @@ -285,10 +287,9 @@ const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const noexce InputStream* ZipFile::createStreamForEntry (const int index) { - ZipEntryHolder* const zei = entries[index]; InputStream* stream = nullptr; - if (zei != nullptr) + if (ZipEntryHolder* const zei = entries[index]) { stream = new ZipInputStream (*this, *zei); diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 661aa4eb90..789763addb 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -358,8 +358,10 @@ struct Component::ComponentHelpers static Rectangle getParentOrMainMonitorBounds (const Component& comp) { - return comp.getParentComponent() != nullptr ? comp.getParentComponent()->getLocalBounds() - : Desktop::getInstance().getDisplays().getMainDisplay().userArea; + if (Component* p = comp.getParentComponent()) + return p->getLocalBounds(); + + return Desktop::getInstance().getDisplays().getMainDisplay().userArea; } }; @@ -498,8 +500,10 @@ bool Component::isShowing() const if (parentComponent != nullptr) return parentComponent->isShowing(); - const ComponentPeer* const peer = getPeer(); - return peer != nullptr && ! peer->isMinimised(); + if (const ComponentPeer* const peer = getPeer()) + return ! peer->isMinimised(); + + return false; } diff --git a/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp b/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp index be1b85c49c..0bd88b1b98 100644 --- a/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp +++ b/modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp @@ -383,9 +383,7 @@ void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortF for (int i = columns.size(); --i >= 0;) columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards); - ColumnInfo* const ci = getInfoForId (columnId); - - if (ci != nullptr) + if (ColumnInfo* const ci = getInfoForId (columnId)) ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards); reSortTable(); @@ -451,9 +449,7 @@ void TableHeaderComponent::restoreFromString (const String& storedVersion) { const int tabId = col->getIntAttribute ("id"); - ColumnInfo* const ci = getInfoForId (tabId); - - if (ci != nullptr) + if (ColumnInfo* const ci = getInfoForId (tabId)) { columns.move (columns.indexOf (ci), index); ci->width = col->getIntAttribute ("width"); @@ -609,9 +605,7 @@ void TableHeaderComponent::mouseDrag (const MouseEvent& e) if (columnIdBeingResized != 0) { - const ColumnInfo* const ci = getInfoForId (columnIdBeingResized); - - if (ci != nullptr) + if (const ColumnInfo* const ci = getInfoForId (columnIdBeingResized)) { int w = jlimit (ci->minimumWidth, ci->maximumWidth, initialColumnWidth + e.getDistanceFromDragStartX()); diff --git a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp index 42444a5ca7..f13a35719f 100644 --- a/modules/juce_gui_basics/widgets/juce_Toolbar.cpp +++ b/modules/juce_gui_basics/widgets/juce_Toolbar.cpp @@ -175,9 +175,7 @@ public: { for (int i = 0; i < getNumChildComponents(); ++i) { - ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i)); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i))) { tc->setVisible (false); const int index = oldIndexes.remove (i); @@ -199,9 +197,7 @@ public: for (int i = 0; i < getNumChildComponents(); ++i) { - ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i)); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = dynamic_cast (getChildComponent (i))) { int preferredSize = 1, minSize = 1, maxSize = 1; @@ -290,18 +286,16 @@ void Toolbar::addItemInternal (ToolbarItemFactory& factory, // An ID can't be zero - this might indicate a mistake somewhere? jassert (itemId != 0); - ToolbarItemComponent* const tc = createItem (factory, itemId); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = createItem (factory, itemId)) { -#if JUCE_DEBUG + #if JUCE_DEBUG Array allowedIds; factory.getAllToolbarItemIds (allowedIds); // If your factory can create an item for a given ID, it must also return // that ID from its getAllToolbarItemIds() method! jassert (allowedIds.contains (itemId)); -#endif + #endif items.insert (insertIndex, tc); addAndMakeVisible (tc, insertIndex); @@ -548,17 +542,13 @@ bool Toolbar::isInterestedInDragSource (const SourceDetails& dragSourceDetails) void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) { - ToolbarItemComponent* const tc = dynamic_cast (dragSourceDetails.sourceComponent.get()); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = dynamic_cast (dragSourceDetails.sourceComponent.get())) { if (! items.contains (tc)) { if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette) { - ToolbarItemPalette* const palette = tc->findParentComponentOfClass(); - - if (palette != nullptr) + if (ToolbarItemPalette* const palette = tc->findParentComponentOfClass()) palette->replaceComponent (tc); } else @@ -582,9 +572,8 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) const Rectangle current (Desktop::getInstance().getAnimator() .getComponentDestination (getChildComponent (newIndex))); - ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1); - if (prev != nullptr) + if (ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1)) { const Rectangle previousPos (Desktop::getInstance().getAnimator().getComponentDestination (prev)); @@ -595,8 +584,7 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) } } - ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1); - if (next != nullptr) + if (ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1)) { const Rectangle nextPos (Desktop::getInstance().getAnimator().getComponentDestination (next)); @@ -621,21 +609,20 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) void Toolbar::itemDragExit (const SourceDetails& dragSourceDetails) { - ToolbarItemComponent* const tc = dynamic_cast (dragSourceDetails.sourceComponent.get()); - - if (tc != nullptr && isParentOf (tc)) + if (ToolbarItemComponent* const tc = dynamic_cast (dragSourceDetails.sourceComponent.get())) { - items.removeObject (tc, false); - removeChildComponent (tc); - updateAllItemPositions (true); + if (isParentOf (tc)) + { + items.removeObject (tc, false); + removeChildComponent (tc); + updateAllItemPositions (true); + } } } void Toolbar::itemDropped (const SourceDetails& dragSourceDetails) { - ToolbarItemComponent* const tc = dynamic_cast (dragSourceDetails.sourceComponent.get()); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = dynamic_cast (dragSourceDetails.sourceComponent.get())) tc->setState (Button::buttonNormal); } @@ -784,9 +771,7 @@ private: { Colour background; - DialogWindow* const dw = findParentComponentOfClass(); - - if (dw != nullptr) + if (DialogWindow* const dw = findParentComponentOfClass()) background = dw->getBackgroundColour(); g.setColour (background.contrasting().withAlpha (0.3f)); diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp b/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp index b485e94651..d8c11e2a8a 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp @@ -45,24 +45,23 @@ public: void paint (Graphics& g) { - ToolbarItemComponent* const tc = getToolbarItemComponent(); - - if (isMouseOverOrDragging() - && tc != nullptr - && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar) + if (ToolbarItemComponent* const tc = getToolbarItemComponent()) { - g.setColour (findColour (Toolbar::editingModeOutlineColourId, true)); - g.drawRect (0, 0, getWidth(), getHeight(), - jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2)); + if (isMouseOverOrDragging() + && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar) + { + g.setColour (findColour (Toolbar::editingModeOutlineColourId, true)); + g.drawRect (0, 0, getWidth(), getHeight(), + jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2)); + } } } void mouseDown (const MouseEvent& e) { isDragging = false; - ToolbarItemComponent* const tc = getToolbarItemComponent(); - if (tc != nullptr) + if (ToolbarItemComponent* const tc = getToolbarItemComponent()) { tc->dragOffsetX = e.x; tc->dragOffsetY = e.y; @@ -74,15 +73,12 @@ public: if (! (isDragging || e.mouseWasClicked())) { isDragging = true; - DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this); - if (dnd != nullptr) + if (DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this)) { dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), Image::null, true); - ToolbarItemComponent* const tc = getToolbarItemComponent(); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = getToolbarItemComponent()) { tc->isBeingDragged = true; @@ -96,15 +92,12 @@ public: void mouseUp (const MouseEvent&) { isDragging = false; - ToolbarItemComponent* const tc = getToolbarItemComponent(); - if (tc != nullptr) + if (ToolbarItemComponent* const tc = getToolbarItemComponent()) { tc->isBeingDragged = false; - Toolbar* const tb = tc->getToolbar(); - - if (tb != nullptr) + if (Toolbar* const tb = tc->getToolbar()) tb->updateAllItemPositions (true); else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar) delete tc; diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp index 0dec08ac27..9df6ee7607 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp @@ -47,15 +47,16 @@ ToolbarItemPalette::~ToolbarItemPalette() //============================================================================== void ToolbarItemPalette::addComponent (const int itemId, const int index) { - ToolbarItemComponent* const tc = Toolbar::createItem (factory, itemId); - jassert (tc != nullptr); - - if (tc != nullptr) + if (ToolbarItemComponent* const tc = Toolbar::createItem (factory, itemId)) { items.insert (index, tc); viewport.getViewedComponent()->addAndMakeVisible (tc, index); tc->setEditingMode (ToolbarItemComponent::editableOnPalette); } + else + { + jassertfalse; + } } void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp) diff --git a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp index 7c93b9d8cb..2baffb8902 100644 --- a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp @@ -128,9 +128,7 @@ juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager) void juce_checkCurrentlyFocusedTopLevelWindow(); void juce_checkCurrentlyFocusedTopLevelWindow() { - TopLevelWindowManager* const wm = TopLevelWindowManager::getInstanceWithoutCreating(); - - if (wm != nullptr) + if (TopLevelWindowManager* const wm = TopLevelWindowManager::getInstanceWithoutCreating()) wm->checkFocusAsync(); }