diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm index 512665a9c7..64f12e34e4 100644 --- a/modules/juce_core/native/juce_mac_Files.mm +++ b/modules/juce_core/native/juce_mac_Files.mm @@ -35,15 +35,15 @@ bool File::copyInternal (const File& dest) const NSFileManager* fm = [NSFileManager defaultManager]; return [fm fileExistsAtPath: juceStringToNS (fullPath)] -#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 && [fm copyItemAtPath: juceStringToNS (fullPath) toPath: juceStringToNS (dest.getFullPathName()) error: nil]; -#else + #else && [fm copyPath: juceStringToNS (fullPath) toPath: juceStringToNS (dest.getFullPathName()) handler: nil]; -#endif + #endif } void File::findFileSystemRoots (Array& destArray) @@ -73,7 +73,7 @@ namespace FileHelpers static bool isHiddenFile (const String& path) { - #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 + #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 JUCE_AUTORELEASEPOOL NSNumber* hidden = nil; NSError* err = nil; @@ -81,25 +81,25 @@ namespace FileHelpers return [[NSURL fileURLWithPath: juceStringToNS (path)] getResourceValue: &hidden forKey: NSURLIsHiddenKey error: &err] && [hidden boolValue]; - #elif JUCE_IOS + #elif JUCE_IOS return File (path).getFileName().startsWithChar ('.'); - #else + #else FSRef ref; LSItemInfoRecord info; return FSPathMakeRefWithOptions ((const UInt8*) path.toUTF8().getAddress(), kFSPathMakeRefDoNotFollowLeafSymlink, &ref, 0) == noErr && LSCopyItemInfoForRef (&ref, kLSRequestBasicFlagsOnly, &info) == noErr && (info.flags & kLSItemInfoIsInvisible) != 0; - #endif + #endif } - #if JUCE_IOS + #if JUCE_IOS String getIOSSystemLocation (NSSearchPathDirectory type) { return nsStringToJuce ([NSSearchPathForDirectoriesInDomains (type, NSUserDomainMask, YES) objectAtIndex: 0]); } - #endif + #endif static bool launchExecutable (const String& pathAndArguments) { diff --git a/modules/juce_core/xml/juce_XmlElement.cpp b/modules/juce_core/xml/juce_XmlElement.cpp index 9ccaac26ca..1299aeb96e 100644 --- a/modules/juce_core/xml/juce_XmlElement.cpp +++ b/modules/juce_core/xml/juce_XmlElement.cpp @@ -348,21 +348,18 @@ bool XmlElement::writeToFile (const File& file, const String& encodingType, const int lineWrapLength) const { - if (file.hasWriteAccess()) + TemporaryFile tempFile (file); + { - TemporaryFile tempFile (file); - ScopedPointer out (tempFile.getFile().createOutputStream()); + FileOutputStream out (tempFile.getFile()); - if (out != nullptr) - { - writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength); - out = nullptr; + if (! out.openedOk()) + return false; - return tempFile.overwriteTargetFileWithTemporary(); - } + writeToStream (out, dtdToUse, false, true, encodingType, lineWrapLength); } - return false; + return tempFile.overwriteTargetFileWithTemporary(); } //============================================================================== diff --git a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp index 2eab107997..d457571141 100644 --- a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp +++ b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp @@ -232,7 +232,7 @@ public: component->setBounds (getLocalBounds().withTop (getHeaderSize())); } - void mouseDown (const MouseEvent& e) + void mouseDown (const MouseEvent&) { mouseDownY = getY(); dragStartSizes = getPanel().getFittedSizes(); @@ -246,7 +246,7 @@ public: panel.getHeight()), false); } - void mouseDoubleClick (const MouseEvent& e) + void mouseDoubleClick (const MouseEvent&) { getPanel().panelHeaderDoubleClicked (component); } diff --git a/modules/juce_gui_basics/layout/juce_ResizableEdgeComponent.cpp b/modules/juce_gui_basics/layout/juce_ResizableEdgeComponent.cpp index 547958de11..d927ed4c20 100644 --- a/modules/juce_gui_basics/layout/juce_ResizableEdgeComponent.cpp +++ b/modules/juce_gui_basics/layout/juce_ResizableEdgeComponent.cpp @@ -31,8 +31,8 @@ ResizableEdgeComponent::ResizableEdgeComponent (Component* const componentToResi edge (edge_) { setRepaintsOnMouseActivity (true); - setMouseCursor (MouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor - : MouseCursor::UpDownResizeCursor)); + setMouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor + : MouseCursor::UpDownResizeCursor); } ResizableEdgeComponent::~ResizableEdgeComponent() diff --git a/modules/juce_gui_basics/layout/juce_StretchableLayoutResizerBar.cpp b/modules/juce_gui_basics/layout/juce_StretchableLayoutResizerBar.cpp index e208042208..3441c35b0b 100644 --- a/modules/juce_gui_basics/layout/juce_StretchableLayoutResizerBar.cpp +++ b/modules/juce_gui_basics/layout/juce_StretchableLayoutResizerBar.cpp @@ -24,15 +24,15 @@ */ StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_, - const int itemIndex_, - const bool isVertical_) + const int index, + const bool vertical) : layout (layout_), - itemIndex (itemIndex_), - isVertical (isVertical_) + itemIndex (index), + isVertical (vertical) { setRepaintsOnMouseActivity (true); - setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor - : MouseCursor::UpDownResizeCursor)); + setMouseCursor (vertical ? MouseCursor::LeftRightResizeCursor + : MouseCursor::UpDownResizeCursor); } StretchableLayoutResizerBar::~StretchableLayoutResizerBar() diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 467999eaba..8e7dae1559 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -340,7 +340,16 @@ void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName) //============================================================================== MouseCursor LookAndFeel::getMouseCursorFor (Component& component) { - return component.getMouseCursor(); + MouseCursor m (component.getMouseCursor()); + + Component* parent = component.getParentComponent(); + while (parent != nullptr && m == MouseCursor::ParentCursor) + { + m = parent->getMouseCursor(); + parent = parent->getParentComponent(); + } + + return m; } LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point& origin, const RectangleList& initialClip) @@ -1687,8 +1696,8 @@ void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp, //============================================================================== void LookAndFeel::drawConcertinaPanelHeader (Graphics& g, const Rectangle& area, - bool isMouseOver, bool isMouseDown, - ConcertinaPanel& concertina, Component& panel) + bool isMouseOver, bool /*isMouseDown*/, + ConcertinaPanel&, Component& panel) { g.fillAll (Colours::grey.withAlpha (isMouseOver ? 0.9f : 0.7f)); g.setColour (Colours::black.withAlpha (0.5f)); diff --git a/modules/juce_gui_basics/mouse/juce_MouseCursor.cpp b/modules/juce_gui_basics/mouse/juce_MouseCursor.cpp index 123dfa1d71..335d8e5849 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseCursor.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseCursor.cpp @@ -49,19 +49,23 @@ public: static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type) { + jassert (isPositiveAndBelow (type, MouseCursor::NumStandardCursorTypes)); + const SpinLock::ScopedLockType sl (lock); - for (int i = 0; i < getCursors().size(); ++i) - { - SharedCursorHandle* const sc = getCursors().getUnchecked(i); + SharedCursorHandle*& c = getSharedCursor (type); - if (sc->standardType == type) - return sc->retain(); - } + if (c == nullptr) + c = new SharedCursorHandle (type); + else + c->retain(); + + return c; + } - SharedCursorHandle* const sc = new SharedCursorHandle (type); - getCursors().add (sc); - return sc; + bool isStandardType (MouseCursor::StandardCursorType type) const noexcept + { + return type == standardType && isStandard; } SharedCursorHandle* retain() noexcept @@ -77,7 +81,7 @@ public: if (isStandard) { const SpinLock::ScopedLockType sl (lock); - getCursors().removeFirstMatchingValue (this); + getSharedCursor (standardType) = nullptr; } delete this; @@ -86,19 +90,17 @@ public: void* getHandle() const noexcept { return handle; } - private: - //============================================================================== void* const handle; Atomic refCount; const MouseCursor::StandardCursorType standardType; const bool isStandard; static SpinLock lock; - static Array & getCursors() + static SharedCursorHandle*& getSharedCursor (const MouseCursor::StandardCursorType type) { - static Array cursors; - return cursors; + static SharedCursorHandle* cursors [MouseCursor::NumStandardCursorTypes] = {}; + return cursors [type]; } JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SharedCursorHandle); @@ -113,7 +115,7 @@ MouseCursor::MouseCursor() } MouseCursor::MouseCursor (const StandardCursorType type) - : cursorHandle (type != MouseCursor::NormalCursor ? SharedCursorHandle::createStandard (type) : 0) + : cursorHandle (type != MouseCursor::NormalCursor ? SharedCursorHandle::createStandard (type) : nullptr) { } @@ -164,11 +166,15 @@ bool MouseCursor::operator== (const MouseCursor& other) const noexcept return getHandle() == other.getHandle(); } -bool MouseCursor::operator!= (const MouseCursor& other) const noexcept +bool MouseCursor::operator== (StandardCursorType type) const noexcept { - return getHandle() != other.getHandle(); + return cursorHandle != nullptr ? cursorHandle->isStandardType (type) + : (type == NormalCursor); } +bool MouseCursor::operator!= (const MouseCursor& other) const noexcept { return ! operator== (other); } +bool MouseCursor::operator!= (StandardCursorType type) const noexcept { return ! operator== (type); } + void* MouseCursor::getHandle() const noexcept { return cursorHandle != nullptr ? cursorHandle->getHandle() : nullptr; diff --git a/modules/juce_gui_basics/mouse/juce_MouseCursor.h b/modules/juce_gui_basics/mouse/juce_MouseCursor.h index f307a95e80..04995eb072 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseCursor.h +++ b/modules/juce_gui_basics/mouse/juce_MouseCursor.h @@ -45,7 +45,9 @@ public: /** The set of available standard mouse cursors. */ enum StandardCursorType { - NoCursor = 0, /**< An invisible cursor. */ + ParentCursor = 0, /**< Indicates that the component's parent's cursor should be used. */ + + NoCursor, /**< An invisible cursor. */ NormalCursor, /**< The stardard arrow cursor. */ WaitCursor, /**< The normal hourglass or spinning-beachball 'busy' cursor. */ @@ -68,7 +70,9 @@ public: TopLeftCornerResizeCursor, /**< A platform-specific cursor for resizing the top-left-corner of a window. */ TopRightCornerResizeCursor, /**< A platform-specific cursor for resizing the top-right-corner of a window. */ BottomLeftCornerResizeCursor, /**< A platform-specific cursor for resizing the bottom-left-corner of a window. */ - BottomRightCornerResizeCursor /**< A platform-specific cursor for resizing the bottom-right-corner of a window. */ + BottomRightCornerResizeCursor, /**< A platform-specific cursor for resizing the bottom-right-corner of a window. */ + + NumStandardCursorTypes }; //============================================================================== @@ -120,6 +124,12 @@ public: */ bool operator!= (const MouseCursor& other) const noexcept; + /** Checks whether this cursor is of the standard type mentioned. */ + bool operator== (StandardCursorType type) const noexcept; + + /** Checks whether this cursor is of the standard type mentioned. */ + bool operator!= (StandardCursorType type) const noexcept; + //============================================================================== /** Makes the system show its default 'busy' cursor. diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index aa56a493cc..0a4ac12173 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -2966,7 +2966,8 @@ void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType ty switch (type) { - case NormalCursor: return None; // Use parent cursor + case NormalCursor: + case ParentCursor: return None; // Use parent cursor case NoCursor: return createMouseCursorFromImage (Image (Image::ARGB, 16, 16, true), 0, 0); case WaitCursor: shape = XC_watch; break; diff --git a/modules/juce_gui_basics/native/juce_mac_MouseCursor.mm b/modules/juce_gui_basics/native/juce_mac_MouseCursor.mm index 9700a8e968..2c31c21f4e 100644 --- a/modules/juce_gui_basics/native/juce_mac_MouseCursor.mm +++ b/modules/juce_gui_basics/native/juce_mac_MouseCursor.mm @@ -86,7 +86,8 @@ void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType ty switch (type) { - case NormalCursor: c = [NSCursor arrowCursor]; break; + case NormalCursor: + case ParentCursor: c = [NSCursor arrowCursor]; break; case NoCursor: return createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0); case DraggingHandCursor: c = [NSCursor openHandCursor]; break; case WaitCursor: c = [NSCursor arrowCursor]; break; // avoid this on the mac, let the OS provide the beachball diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 0f22110499..f338a80f7c 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -3193,7 +3193,8 @@ void* MouseCursor::createStandardMouseCursor (const MouseCursor::StandardCursorT switch (type) { - case NormalCursor: break; + case NormalCursor: + case ParentCursor: break; case NoCursor: return (void*) hiddenMouseCursorHandle; case WaitCursor: cursorName = IDC_WAIT; break; case IBeamCursor: cursorName = IDC_IBEAM; break; diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index 8df8bb6eda..df5033b2c5 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -576,9 +576,14 @@ public: valueBox->addListener (this); if (style == LinearBar) + { valueBox->addMouseListener (&owner, false); + valueBox->setMouseCursor (MouseCursor::ParentCursor); + } else + { valueBox->setTooltip (owner.getTooltip()); + } } else { diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index 60b4544540..9de6f154b5 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -865,7 +865,7 @@ public: { setWantsKeyboardFocus (false); setInterceptsMouseClicks (false, true); - setMouseCursor (MouseCursor::IBeamCursor); + setMouseCursor (MouseCursor::ParentCursor); owner.getTextValue().addListener (this); } diff --git a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp index 4e4953ccbc..32b07a6faa 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp @@ -333,7 +333,7 @@ CodeEditorComponent::CodeEditorComponent (CodeDocument& doc, CodeTokeniser* cons selectionEnd.setPositionMaintained (true); setOpaque (true); - setMouseCursor (MouseCursor (MouseCursor::IBeamCursor)); + setMouseCursor (MouseCursor::IBeamCursor); setWantsKeyboardFocus (true); addAndMakeVisible (&verticalScrollBar);