diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 2d9e08f258..89f9f815bc 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -69,21 +69,8 @@ class NSViewComponentPeer : public ComponentPeer, public: NSViewComponentPeer (Component& comp, const int windowStyleFlags, NSView* viewToAttachTo) : ComponentPeer (comp, windowStyleFlags), - window (nil), - view (nil), isSharedWindow (viewToAttachTo != nil), - fullScreen (false), - #if USE_COREGRAPHICS_RENDERING - usingCoreGraphics (true), - #else - usingCoreGraphics (false), - #endif - isZooming (false), - isFirstLiveResize (false), - textWasInserted (false), - isStretchingTop (false), isStretchingLeft (false), - isStretchingBottom (false), isStretchingRight (false), - notificationCenter (nil), lastRepaintTime (Time::getMillisecondCounter()) + lastRepaintTime (Time::getMillisecondCounter()) { appFocusChangeCallback = appFocusChanged; isEventBlockedByModalComps = checkEventBlockedByModalComps; @@ -493,7 +480,7 @@ public: void toBehind (ComponentPeer* other) override { - if (NSViewComponentPeer* const otherPeer = dynamic_cast (other)) + if (auto* otherPeer = dynamic_cast (other)) { if (isSharedWindow) { @@ -962,7 +949,7 @@ public: //============================================================================== bool sendModalInputAttemptIfBlocked() { - if (Component* modal = Component::getCurrentlyModalComponent()) + if (auto* modal = Component::getCurrentlyModalComponent()) { if (insideToFrontCall == 0 && (! getComponent().isParentOf (modal)) @@ -1042,8 +1029,8 @@ public: { const float scale = getComponent().getDesktopScaleFactor(); - Rectangle pos = ScalingHelpers::unscaledScreenPosToScaled (scale, convertToRectInt (flippedScreenRect (r))); - Rectangle original = ScalingHelpers::unscaledScreenPosToScaled (scale, convertToRectInt (flippedScreenRect ([window frame]))); + auto pos = ScalingHelpers::unscaledScreenPosToScaled (scale, convertToRectInt (flippedScreenRect (r))); + auto original = ScalingHelpers::unscaledScreenPosToScaled (scale, convertToRectInt (flippedScreenRect ([window frame]))); const Rectangle screenBounds (Desktop::getInstance().getDisplays().getTotalBounds (true)); @@ -1076,8 +1063,8 @@ public: static void showArrowCursorIfNeeded() { - Desktop& desktop = Desktop::getInstance(); - MouseInputSource mouse = desktop.getMainMouseSource(); + auto& desktop = Desktop::getInstance(); + auto mouse = desktop.getMainMouseSource(); if (mouse.getComponentUnderMouse() == nullptr && desktop.findComponentAt (mouse.getScreenPosition().roundToInt()) == nullptr) @@ -1138,9 +1125,8 @@ public: if (layoutData != nullptr) { - if (const UCKeyboardLayout* layoutPtr = (const UCKeyboardLayout*) CFDataGetBytePtr (layoutData)) + if (auto* layoutPtr = (const UCKeyboardLayout*) CFDataGetBytePtr (layoutData)) { - UInt32 keysDown = 0; UniChar buffer[4]; UniCharCount actual; @@ -1214,7 +1200,7 @@ public: static Point getMousePos (NSEvent* e, NSView* view) { NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil]; - return Point ((float) p.x, (float) ([view frame].size.height - p.y)); + return { (float) p.x, (float) ([view frame].size.height - p.y) }; } static int getModifierForButtonNumber (const NSInteger num) @@ -1356,13 +1342,18 @@ public: void textInputRequired (Point, TextInputTarget&) override {} //============================================================================== - NSWindow* window; - NSView* view; - bool isSharedWindow, fullScreen; - bool usingCoreGraphics, isZooming, isFirstLiveResize, textWasInserted; - bool isStretchingTop, isStretchingLeft, isStretchingBottom, isStretchingRight; + NSWindow* window = nil; + NSView* view = nil; + bool isSharedWindow = false, fullScreen = false; + #if USE_COREGRAPHICS_RENDERING + bool usingCoreGraphics = true; + #else + bool usingCoreGraphics = false; + #endif + bool isZooming = false, isFirstLiveResize = false, textWasInserted = false; + bool isStretchingTop = false, isStretchingLeft = false, isStretchingBottom = false, isStretchingRight = false; String stringBeingComposed; - NSNotificationCenter* notificationCenter; + NSNotificationCenter* notificationCenter = nil; RectangleList deferredRepaints; uint32 lastRepaintTime; @@ -1466,7 +1457,7 @@ private: for (int i = ComponentPeer::getNumPeers(); --i >= 0;) { - if (NSViewComponentPeer* peer = dynamic_cast (ComponentPeer::getPeer (i))) + if (auto* peer = dynamic_cast (ComponentPeer::getPeer (i))) { if ([peer->view window] == w) { @@ -1603,43 +1594,39 @@ private: waitUntilDone: NO]; } - static void asyncMouseDown (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseDown (ev); } - static void asyncMouseUp (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseUp (ev); } - static void mouseDragged (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseDrag (ev); } - static void mouseMoved (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseMove (ev); } - static void mouseEntered (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseEnter (ev); } - static void mouseExited (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseExit (ev); } - static void scrollWheel (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMouseWheel (ev); } - static void magnify (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMagnify (ev); } - static void copy (id self, SEL, NSObject* s) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectCopy (s); } - static void paste (id self, SEL, NSObject* s) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectPaste (s); } - static void cut (id self, SEL, NSObject* s) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectCut (s); } + static void asyncMouseDown (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseDown (ev); } + static void asyncMouseUp (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseUp (ev); } + static void mouseDragged (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseDrag (ev); } + static void mouseMoved (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseMove (ev); } + static void mouseEntered (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseEnter (ev); } + static void mouseExited (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseExit (ev); } + static void scrollWheel (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseWheel (ev); } + static void magnify (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMagnify (ev); } + static void copy (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectCopy (s); } + static void paste (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectPaste (s); } + static void cut (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectCut (s); } + static void willMoveToWindow (id self, SEL, NSWindow* w) { if (auto* p = getOwner (self)) p->redirectWillMoveToWindow (w); } - static void willMoveToWindow (id self, SEL, NSWindow* window) - { - if (NSViewComponentPeer* p = getOwner (self)) p->redirectWillMoveToWindow (window); - } + static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; } + static BOOL wantsDefaultClipping (id, SEL) { return YES; } // (this is the default, but may want to customise it in future) + static BOOL worksWhenModal (id self, SEL) { if (auto* p = getOwner (self)) return p->worksWhenModal(); return NO; } - static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; } - static BOOL wantsDefaultClipping (id, SEL) { return YES; } // (this is the default, but may want to customise it in future) - static BOOL worksWhenModal (id self, SEL) { if (NSViewComponentPeer* p = getOwner (self)) return p->worksWhenModal(); return NO; } - - static void drawRect (id self, SEL, NSRect r) { if (NSViewComponentPeer* p = getOwner (self)) p->drawRect (r); } - static void frameChanged (id self, SEL, NSNotification*) { if (NSViewComponentPeer* p = getOwner (self)) p->redirectMovedOrResized(); } - static void viewDidMoveToWindow (id self, SEL) { if (NSViewComponentPeer* p = getOwner (self)) p->viewMovedToWindow(); } + static void drawRect (id self, SEL, NSRect r) { if (auto* p = getOwner (self)) p->drawRect (r); } + static void frameChanged (id self, SEL, NSNotification*) { if (auto* p = getOwner (self)) p->redirectMovedOrResized(); } + static void viewDidMoveToWindow (id self, SEL) { if (auto* p = getOwner (self)) p->viewMovedToWindow(); } static BOOL isOpaque (id self, SEL) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner == nullptr || owner->getComponent().isOpaque(); } //============================================================================== static void keyDown (id self, SEL, NSEvent* ev) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { - TextInputTarget* const target = owner->findCurrentTextInputTarget(); + auto* target = owner->findCurrentTextInputTarget(); owner->textWasInserted = false; if (target != nullptr) @@ -1647,7 +1634,7 @@ private: else owner->stringBeingComposed.clear(); - if ((! owner->textWasInserted) && (owner == nullptr || ! owner->redirectKeyDown (ev))) + if (! (owner->textWasInserted || owner->redirectKeyDown (ev))) { objc_super s = { self, [NSView class] }; getMsgSendSuperFn() (&s, @selector (keyDown:), ev); @@ -1657,7 +1644,7 @@ private: static void keyUp (id self, SEL, NSEvent* ev) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); if (owner == nullptr || ! owner->redirectKeyUp (ev)) { @@ -1670,13 +1657,13 @@ private: static void insertText (id self, SEL, id aString) { // This commits multi-byte text when return is pressed, or after every keypress for western keyboards - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { NSString* newText = [aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString; if ([newText length] > 0) { - if (TextInputTarget* const target = owner->findCurrentTextInputTarget()) + if (auto* target = owner->findCurrentTextInputTarget()) { target->insertTextAtCaret (nsStringToJuce (newText)); owner->textWasInserted = true; @@ -1691,14 +1678,14 @@ private: static void setMarkedText (id self, SEL, id aString, NSRange) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { owner->stringBeingComposed = nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString); - if (TextInputTarget* const target = owner->findCurrentTextInputTarget()) + if (auto* target = owner->findCurrentTextInputTarget()) { - const Range currentHighlight (target->getHighlightedRegion()); + auto currentHighlight = target->getHighlightedRegion(); target->insertTextAtCaret (owner->stringBeingComposed); target->setHighlightedRegion (currentHighlight.withLength (owner->stringBeingComposed.length())); owner->textWasInserted = true; @@ -1708,11 +1695,11 @@ private: static void unmarkText (id self, SEL) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { if (owner->stringBeingComposed.isNotEmpty()) { - if (TextInputTarget* const target = owner->findCurrentTextInputTarget()) + if (auto* target = owner->findCurrentTextInputTarget()) { target->insertTextAtCaret (owner->stringBeingComposed); owner->textWasInserted = true; @@ -1725,7 +1712,7 @@ private: static BOOL hasMarkedText (id self, SEL) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner != nullptr && owner->stringBeingComposed.isNotEmpty(); } @@ -1736,9 +1723,9 @@ private: static NSAttributedString* attributedSubstringFromRange (id self, SEL, NSRange theRange) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { - if (TextInputTarget* const target = owner->findCurrentTextInputTarget()) + if (auto* target = owner->findCurrentTextInputTarget()) { const Range r ((int) theRange.location, (int) (theRange.location + theRange.length)); @@ -1752,7 +1739,7 @@ private: static NSRange markedRange (id self, SEL) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) if (owner->stringBeingComposed.isNotEmpty()) return NSMakeRange (0, (NSUInteger) owner->stringBeingComposed.length()); @@ -1761,11 +1748,11 @@ private: static NSRange selectedRange (id self, SEL) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { - if (TextInputTarget* const target = owner->findCurrentTextInputTarget()) + if (auto* target = owner->findCurrentTextInputTarget()) { - const Range highlight (target->getHighlightedRegion()); + auto highlight = target->getHighlightedRegion(); if (! highlight.isEmpty()) return NSMakeRange ((NSUInteger) highlight.getStart(), @@ -1778,8 +1765,8 @@ private: static NSRect firstRectForCharacterRange (id self, SEL, NSRange) { - if (NSViewComponentPeer* const owner = getOwner (self)) - if (Component* const comp = dynamic_cast (owner->findCurrentTextInputTarget())) + if (auto* owner = getOwner (self)) + if (auto* comp = dynamic_cast (owner->findCurrentTextInputTarget())) return flippedScreenRect (makeNSRect (comp->getScreenBounds())); return NSZeroRect; @@ -1791,13 +1778,13 @@ private: //============================================================================== static void flagsChanged (id self, SEL, NSEvent* ev) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->redirectModKeyChange (ev); } static BOOL becomeFirstResponder (id self, SEL) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->viewFocusGain(); return YES; @@ -1805,7 +1792,7 @@ private: static BOOL resignFirstResponder (id self, SEL) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->viewFocusLoss(); return YES; @@ -1813,7 +1800,7 @@ private: static BOOL acceptsFirstResponder (id self, SEL) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner != nullptr && owner->canBecomeKeyWindow(); } @@ -1825,7 +1812,7 @@ private: static NSDragOperation draggingUpdated (id self, SEL, id sender) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) if (owner->sendDragCallback (0, sender)) return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric; @@ -1839,7 +1826,7 @@ private: static void draggingExited (id self, SEL, id sender) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->sendDragCallback (1, sender); } @@ -1850,7 +1837,7 @@ private: static BOOL performDragOperation (id self, SEL, id sender) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner != nullptr && owner->sendDragCallback (2, sender); } @@ -1892,7 +1879,7 @@ private: //============================================================================== static BOOL canBecomeKeyWindow (id self, SEL) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner != nullptr && owner->canBecomeKeyWindow() @@ -1901,7 +1888,7 @@ private: static BOOL canBecomeMainWindow (id self, SEL) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner != nullptr && owner->canBecomeMainWindow() @@ -1912,19 +1899,19 @@ private: { sendSuperclassMessage (self, @selector (becomeKeyWindow)); - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->becomeKeyWindow(); } static BOOL windowShouldClose (id self, SEL, id /*window*/) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); return owner == nullptr || owner->windowShouldClose(); } static NSRect constrainFrameRect (id self, SEL, NSRect frameRect, NSScreen*) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) frameRect = owner->constrainRect (frameRect); return frameRect; @@ -1932,7 +1919,7 @@ private: static NSSize windowWillResize (id self, SEL, NSWindow*, NSSize proposedFrameSize) { - NSViewComponentPeer* const owner = getOwner (self); + auto* owner = getOwner (self); if (owner == nullptr || owner->isZooming) return proposedFrameSize; @@ -1958,7 +1945,7 @@ private: static void zoom (id self, SEL, id sender) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) { owner->isZooming = true; objc_super s = { self, [NSWindow class] }; @@ -1971,20 +1958,20 @@ private: static void windowWillMove (id self, SEL, NSNotification*) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) if (owner->hasNativeTitleBar()) owner->sendModalInputAttemptIfBlocked(); } static void windowWillStartLiveResize (id self, SEL, NSNotification*) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->liveResizingStart(); } static void windowDidEndLiveResize (id self, SEL, NSNotification*) { - if (NSViewComponentPeer* const owner = getOwner (self)) + if (auto* owner = getOwner (self)) owner->liveResizingEnd(); } }; @@ -2063,7 +2050,7 @@ void Desktop::setKioskComponent (Component* kioskComp, bool shouldBeEnabled, boo { #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 - NSViewComponentPeer* const peer = dynamic_cast (kioskComp->getPeer()); + auto* peer = dynamic_cast (kioskComp->getPeer()); jassert (peer != nullptr); // (this should have been checked by the caller) #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 diff --git a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm index 154d322338..359f8422d5 100644 --- a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm +++ b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm @@ -108,10 +108,8 @@ private: if (allowMultipleFiles ? chooser.browseForMultipleFilesToOpen() : chooser.browseForFileToOpen()) { - const Array& files = chooser.getResults(); - - for (int i = 0; i < files.size(); ++i) - [resultListener chooseFilename: juceStringToNS (files.getReference(i).getFullPathName())]; + for (auto& f : chooser.getResults()) + [resultListener chooseFilename: juceStringToNS (f.getFullPathName())]; } #else ignoreUnused (resultListener, allowMultipleFiles); @@ -440,14 +438,14 @@ void WebBrowserComponent::focusGained (FocusChangeType) void WebBrowserComponent::clearCookies() { - NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + NSHTTPCookieStorage* storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; - if (NSArray* cookies = [storage cookies]) + if (NSArray* cookies = [storage cookies]) { const NSUInteger n = [cookies count]; for (NSUInteger i = 0; i < n; ++i) - [storage deleteCookie:[cookies objectAtIndex:i]]; + [storage deleteCookie: [cookies objectAtIndex: i]]; } [[NSUserDefaults standardUserDefaults] synchronize];