Browse Source

New type of mouse cursor: ParentCursor, which means "show the same cursor as the parent component".

tags/2021-05-28
jules 13 years ago
parent
commit
b7089dfa45
14 changed files with 87 additions and 57 deletions
  1. +9
    -9
      modules/juce_core/native/juce_mac_Files.mm
  2. +7
    -10
      modules/juce_core/xml/juce_XmlElement.cpp
  3. +2
    -2
      modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp
  4. +2
    -2
      modules/juce_gui_basics/layout/juce_ResizableEdgeComponent.cpp
  5. +6
    -6
      modules/juce_gui_basics/layout/juce_StretchableLayoutResizerBar.cpp
  6. +12
    -3
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp
  7. +24
    -18
      modules/juce_gui_basics/mouse/juce_MouseCursor.cpp
  8. +12
    -2
      modules/juce_gui_basics/mouse/juce_MouseCursor.h
  9. +2
    -1
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  10. +2
    -1
      modules/juce_gui_basics/native/juce_mac_MouseCursor.mm
  11. +2
    -1
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp
  12. +5
    -0
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  13. +1
    -1
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp
  14. +1
    -1
      modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp

+ 9
- 9
modules/juce_core/native/juce_mac_Files.mm View File

@@ -35,15 +35,15 @@ bool File::copyInternal (const File& dest) const
NSFileManager* fm = [NSFileManager defaultManager]; NSFileManager* fm = [NSFileManager defaultManager];
return [fm fileExistsAtPath: juceStringToNS (fullPath)] 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) && [fm copyItemAtPath: juceStringToNS (fullPath)
toPath: juceStringToNS (dest.getFullPathName()) toPath: juceStringToNS (dest.getFullPathName())
error: nil]; error: nil];
#else
#else
&& [fm copyPath: juceStringToNS (fullPath) && [fm copyPath: juceStringToNS (fullPath)
toPath: juceStringToNS (dest.getFullPathName()) toPath: juceStringToNS (dest.getFullPathName())
handler: nil]; handler: nil];
#endif
#endif
} }
void File::findFileSystemRoots (Array<File>& destArray) void File::findFileSystemRoots (Array<File>& destArray)
@@ -73,7 +73,7 @@ namespace FileHelpers
static bool isHiddenFile (const String& path) 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 JUCE_AUTORELEASEPOOL
NSNumber* hidden = nil; NSNumber* hidden = nil;
NSError* err = nil; NSError* err = nil;
@@ -81,25 +81,25 @@ namespace FileHelpers
return [[NSURL fileURLWithPath: juceStringToNS (path)] return [[NSURL fileURLWithPath: juceStringToNS (path)]
getResourceValue: &hidden forKey: NSURLIsHiddenKey error: &err] getResourceValue: &hidden forKey: NSURLIsHiddenKey error: &err]
&& [hidden boolValue]; && [hidden boolValue];
#elif JUCE_IOS
#elif JUCE_IOS
return File (path).getFileName().startsWithChar ('.'); return File (path).getFileName().startsWithChar ('.');
#else
#else
FSRef ref; FSRef ref;
LSItemInfoRecord info; LSItemInfoRecord info;
return FSPathMakeRefWithOptions ((const UInt8*) path.toUTF8().getAddress(), kFSPathMakeRefDoNotFollowLeafSymlink, &ref, 0) == noErr return FSPathMakeRefWithOptions ((const UInt8*) path.toUTF8().getAddress(), kFSPathMakeRefDoNotFollowLeafSymlink, &ref, 0) == noErr
&& LSCopyItemInfoForRef (&ref, kLSRequestBasicFlagsOnly, &info) == noErr && LSCopyItemInfoForRef (&ref, kLSRequestBasicFlagsOnly, &info) == noErr
&& (info.flags & kLSItemInfoIsInvisible) != 0; && (info.flags & kLSItemInfoIsInvisible) != 0;
#endif
#endif
} }
#if JUCE_IOS
#if JUCE_IOS
String getIOSSystemLocation (NSSearchPathDirectory type) String getIOSSystemLocation (NSSearchPathDirectory type)
{ {
return nsStringToJuce ([NSSearchPathForDirectoriesInDomains (type, NSUserDomainMask, YES) return nsStringToJuce ([NSSearchPathForDirectoriesInDomains (type, NSUserDomainMask, YES)
objectAtIndex: 0]); objectAtIndex: 0]);
} }
#endif
#endif
static bool launchExecutable (const String& pathAndArguments) static bool launchExecutable (const String& pathAndArguments)
{ {


+ 7
- 10
modules/juce_core/xml/juce_XmlElement.cpp View File

@@ -348,21 +348,18 @@ bool XmlElement::writeToFile (const File& file,
const String& encodingType, const String& encodingType,
const int lineWrapLength) const const int lineWrapLength) const
{ {
if (file.hasWriteAccess())
TemporaryFile tempFile (file);
{ {
TemporaryFile tempFile (file);
ScopedPointer <FileOutputStream> 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();
} }
//============================================================================== //==============================================================================


+ 2
- 2
modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp View File

@@ -232,7 +232,7 @@ public:
component->setBounds (getLocalBounds().withTop (getHeaderSize())); component->setBounds (getLocalBounds().withTop (getHeaderSize()));
} }
void mouseDown (const MouseEvent& e)
void mouseDown (const MouseEvent&)
{ {
mouseDownY = getY(); mouseDownY = getY();
dragStartSizes = getPanel().getFittedSizes(); dragStartSizes = getPanel().getFittedSizes();
@@ -246,7 +246,7 @@ public:
panel.getHeight()), false); panel.getHeight()), false);
} }
void mouseDoubleClick (const MouseEvent& e)
void mouseDoubleClick (const MouseEvent&)
{ {
getPanel().panelHeaderDoubleClicked (component); getPanel().panelHeaderDoubleClicked (component);
} }


+ 2
- 2
modules/juce_gui_basics/layout/juce_ResizableEdgeComponent.cpp View File

@@ -31,8 +31,8 @@ ResizableEdgeComponent::ResizableEdgeComponent (Component* const componentToResi
edge (edge_) edge (edge_)
{ {
setRepaintsOnMouseActivity (true); setRepaintsOnMouseActivity (true);
setMouseCursor (MouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor
: MouseCursor::UpDownResizeCursor));
setMouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor
: MouseCursor::UpDownResizeCursor);
} }
ResizableEdgeComponent::~ResizableEdgeComponent() ResizableEdgeComponent::~ResizableEdgeComponent()


+ 6
- 6
modules/juce_gui_basics/layout/juce_StretchableLayoutResizerBar.cpp View File

@@ -24,15 +24,15 @@
*/ */
StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_, StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
const int itemIndex_,
const bool isVertical_)
const int index,
const bool vertical)
: layout (layout_), : layout (layout_),
itemIndex (itemIndex_),
isVertical (isVertical_)
itemIndex (index),
isVertical (vertical)
{ {
setRepaintsOnMouseActivity (true); setRepaintsOnMouseActivity (true);
setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
: MouseCursor::UpDownResizeCursor));
setMouseCursor (vertical ? MouseCursor::LeftRightResizeCursor
: MouseCursor::UpDownResizeCursor);
} }
StretchableLayoutResizerBar::~StretchableLayoutResizerBar() StretchableLayoutResizerBar::~StretchableLayoutResizerBar()


+ 12
- 3
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp View File

@@ -340,7 +340,16 @@ void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
//============================================================================== //==============================================================================
MouseCursor LookAndFeel::getMouseCursorFor (Component& component) 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<int>& origin, const RectangleList& initialClip) LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point<int>& origin, const RectangleList& initialClip)
@@ -1687,8 +1696,8 @@ void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
//============================================================================== //==============================================================================
void LookAndFeel::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area, void LookAndFeel::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& 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.fillAll (Colours::grey.withAlpha (isMouseOver ? 0.9f : 0.7f));
g.setColour (Colours::black.withAlpha (0.5f)); g.setColour (Colours::black.withAlpha (0.5f));


+ 24
- 18
modules/juce_gui_basics/mouse/juce_MouseCursor.cpp View File

@@ -49,19 +49,23 @@ public:
static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type) static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type)
{ {
jassert (isPositiveAndBelow (type, MouseCursor::NumStandardCursorTypes));
const SpinLock::ScopedLockType sl (lock); 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 SharedCursorHandle* retain() noexcept
@@ -77,7 +81,7 @@ public:
if (isStandard) if (isStandard)
{ {
const SpinLock::ScopedLockType sl (lock); const SpinLock::ScopedLockType sl (lock);
getCursors().removeFirstMatchingValue (this);
getSharedCursor (standardType) = nullptr;
} }
delete this; delete this;
@@ -86,19 +90,17 @@ public:
void* getHandle() const noexcept { return handle; } void* getHandle() const noexcept { return handle; }
private: private:
//==============================================================================
void* const handle; void* const handle;
Atomic <int> refCount; Atomic <int> refCount;
const MouseCursor::StandardCursorType standardType; const MouseCursor::StandardCursorType standardType;
const bool isStandard; const bool isStandard;
static SpinLock lock; static SpinLock lock;
static Array <SharedCursorHandle*>& getCursors()
static SharedCursorHandle*& getSharedCursor (const MouseCursor::StandardCursorType type)
{ {
static Array <SharedCursorHandle*> cursors;
return cursors;
static SharedCursorHandle* cursors [MouseCursor::NumStandardCursorTypes] = {};
return cursors [type];
} }
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SharedCursorHandle); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SharedCursorHandle);
@@ -113,7 +115,7 @@ MouseCursor::MouseCursor()
} }
MouseCursor::MouseCursor (const StandardCursorType type) 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(); 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 void* MouseCursor::getHandle() const noexcept
{ {
return cursorHandle != nullptr ? cursorHandle->getHandle() : nullptr; return cursorHandle != nullptr ? cursorHandle->getHandle() : nullptr;


+ 12
- 2
modules/juce_gui_basics/mouse/juce_MouseCursor.h View File

@@ -45,7 +45,9 @@ public:
/** The set of available standard mouse cursors. */ /** The set of available standard mouse cursors. */
enum StandardCursorType 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. */ NormalCursor, /**< The stardard arrow cursor. */
WaitCursor, /**< The normal hourglass or spinning-beachball 'busy' 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. */ 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. */ 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. */ 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; 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. /** Makes the system show its default 'busy' cursor.


+ 2
- 1
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -2966,7 +2966,8 @@ void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType ty
switch (type) 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 NoCursor: return createMouseCursorFromImage (Image (Image::ARGB, 16, 16, true), 0, 0);
case WaitCursor: shape = XC_watch; break; case WaitCursor: shape = XC_watch; break;


+ 2
- 1
modules/juce_gui_basics/native/juce_mac_MouseCursor.mm View File

@@ -86,7 +86,8 @@ void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType ty
switch (type) 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 NoCursor: return createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
case DraggingHandCursor: c = [NSCursor openHandCursor]; break; case DraggingHandCursor: c = [NSCursor openHandCursor]; break;
case WaitCursor: c = [NSCursor arrowCursor]; break; // avoid this on the mac, let the OS provide the beachball case WaitCursor: c = [NSCursor arrowCursor]; break; // avoid this on the mac, let the OS provide the beachball


+ 2
- 1
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -3193,7 +3193,8 @@ void* MouseCursor::createStandardMouseCursor (const MouseCursor::StandardCursorT
switch (type) switch (type)
{ {
case NormalCursor: break;
case NormalCursor:
case ParentCursor: break;
case NoCursor: return (void*) hiddenMouseCursorHandle; case NoCursor: return (void*) hiddenMouseCursorHandle;
case WaitCursor: cursorName = IDC_WAIT; break; case WaitCursor: cursorName = IDC_WAIT; break;
case IBeamCursor: cursorName = IDC_IBEAM; break; case IBeamCursor: cursorName = IDC_IBEAM; break;


+ 5
- 0
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -576,9 +576,14 @@ public:
valueBox->addListener (this); valueBox->addListener (this);
if (style == LinearBar) if (style == LinearBar)
{
valueBox->addMouseListener (&owner, false); valueBox->addMouseListener (&owner, false);
valueBox->setMouseCursor (MouseCursor::ParentCursor);
}
else else
{
valueBox->setTooltip (owner.getTooltip()); valueBox->setTooltip (owner.getTooltip());
}
} }
else else
{ {


+ 1
- 1
modules/juce_gui_basics/widgets/juce_TextEditor.cpp View File

@@ -865,7 +865,7 @@ public:
{ {
setWantsKeyboardFocus (false); setWantsKeyboardFocus (false);
setInterceptsMouseClicks (false, true); setInterceptsMouseClicks (false, true);
setMouseCursor (MouseCursor::IBeamCursor);
setMouseCursor (MouseCursor::ParentCursor);
owner.getTextValue().addListener (this); owner.getTextValue().addListener (this);
} }


+ 1
- 1
modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp View File

@@ -333,7 +333,7 @@ CodeEditorComponent::CodeEditorComponent (CodeDocument& doc, CodeTokeniser* cons
selectionEnd.setPositionMaintained (true); selectionEnd.setPositionMaintained (true);
setOpaque (true); setOpaque (true);
setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
setMouseCursor (MouseCursor::IBeamCursor);
setWantsKeyboardFocus (true); setWantsKeyboardFocus (true);
addAndMakeVisible (&verticalScrollBar); addAndMakeVisible (&verticalScrollBar);


Loading…
Cancel
Save