diff --git a/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentDragOperation.h b/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentDragOperation.h index 34e4f57897..b180e4444f 100644 --- a/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentDragOperation.h +++ b/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentDragOperation.h @@ -36,7 +36,8 @@ public: const ResizableBorderComponent::Zone& zone_) : canvas (canvas_), snapGuideParentComp (snapGuideParentComp_), - zone (zone_) + zone (zone_), + mouseDownPos (e.getPosition()) { int i; for (i = 0; i < items.size(); ++i) @@ -168,12 +169,13 @@ public: { getDocument().getUndoManager()->undoCurrentTransactionOnly(); - Point distance (e.getOffsetFromDragStart()); + // (can't use getOffsetFromDragStart() because of auto-scrolling) + Point distance (e.getPosition() - mouseDownPos); if (! isDraggingLeftRight()) - distance = Point (0, distance.getY()); + distance = distance.withX (0); if (! isDraggingUpDown()) - distance = Point (distance.getX(), 0); + distance = distance.withY (0); snapGuides.clear(); @@ -221,6 +223,7 @@ private: const ResizableBorderComponent::Zone zone; OwnedArray snapGuides; Component* snapGuideParentComp; + Point mouseDownPos; ComponentDocument& getDocument() throw() { return canvas.getDocument(); } diff --git a/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentEditorCanvas.cpp b/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentEditorCanvas.cpp index e44f8da7f8..59f1322361 100644 --- a/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentEditorCanvas.cpp +++ b/extras/Jucer (experimental)/Source/ui/Component Editor/jucer_ComponentEditorCanvas.cpp @@ -72,7 +72,7 @@ public: if (component != 0) { updateDragZone (e.getPosition()); - canvas.beginDrag (e, dragZone); + canvas.beginDrag (e.getEventRelativeTo (getParentComponent()), dragZone); canvas.showSizeGuides(); } } @@ -80,7 +80,10 @@ public: void mouseDrag (const MouseEvent& e) { if (component != 0) - canvas.continueDrag (e); + { + canvas.continueDrag (e.getEventRelativeTo (getParentComponent())); + autoScrollForMouseEvent (e); + } } void mouseUp (const MouseEvent& e) @@ -88,7 +91,7 @@ public: canvas.hideSizeGuides(); if (component != 0) - canvas.endDrag (e); + canvas.endDrag (e.getEventRelativeTo (getParentComponent())); updateDragZone (e.getPosition()); } @@ -297,6 +300,7 @@ public: void mouseDown (const MouseEvent& e) { + mouseDownPos = e.getEventRelativeTo (getParentComponent()).getMouseDownPosition(); toFront (false); updateLabel(); @@ -320,6 +324,9 @@ public: { if (isDragging) { + autoScrollForMouseEvent (e); + const MouseEvent e2 (e.getEventRelativeTo (getParentComponent())); + ComponentDocument& doc = getDocument(); doc.getUndoManager()->undoCurrentTransactionOnly(); @@ -332,8 +339,10 @@ public: if (axis.expanded (30, 30).contains (e.x, e.y)) { Coordinate coord (getMarkerList().getCoordinate (marker)); - coord.moveToAbsolute (jmax (0, roundToInt (dragStartPos + (isX ? e.getDistanceFromDragStartX() - : e.getDistanceFromDragStartY()))), + + // (can't use getDistanceFromDragStart() because it doesn't take into account auto-scrolling) + coord.moveToAbsolute (jmax (0, roundToInt (dragStartPos + (isX ? e2.x - mouseDownPos.getX() + : e2.y - mouseDownPos.getY()))), getMarkerList()); getMarkerList().setCoordinate (marker, coord); } @@ -378,6 +387,7 @@ private: bool isDragging; FloatingLabelComponent label; String labelText; + Point mouseDownPos; }; @@ -486,13 +496,7 @@ public: showSizeGuides(); } - Viewport* viewport = Component::findParentComponentOfClass ((Viewport*) 0); - - if (viewport != 0) - { - MouseEvent e2 (e.getEventRelativeTo (viewport)); - viewport->autoScroll (e2.x, e2.y, 8, 16); - } + autoScrollForMouseEvent (e); } void mouseUp (const MouseEvent& e) diff --git a/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.cpp b/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.cpp index 3417b3a453..88adcc28f6 100644 --- a/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.cpp +++ b/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.cpp @@ -373,6 +373,17 @@ const String makeValidCppIdentifier (String s, return n; } +void autoScrollForMouseEvent (const MouseEvent& e) +{ + Viewport* const viewport = e.eventComponent->findParentComponentOfClass ((Viewport*) 0); + + if (viewport != 0) + { + const MouseEvent e2 (e.getEventRelativeTo (viewport)); + viewport->autoScroll (e2.x, e2.y, 8, 16); + } +} + //============================================================================== const String floatToCode (const float v) { diff --git a/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.h b/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.h index b643ed6dec..62f4260fdd 100644 --- a/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.h +++ b/extras/Jucer (experimental)/Source/utility/jucer_UtilityFunctions.h @@ -78,6 +78,8 @@ const String indentCode (const String& code, const int numSpaces); int indexOfLineStartingWith (const StringArray& lines, const String& text, int startIndex); +void autoScrollForMouseEvent (const MouseEvent& e); + //============================================================================== class FileModificationDetector { diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 7a1f52d46e..2c512efacb 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -69336,15 +69336,11 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_MouseCursor.cpp ***/ BEGIN_JUCE_NAMESPACE -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY); -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type); -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard); - class MouseCursor::SharedCursorHandle { public: explicit SharedCursorHandle (const MouseCursor::StandardCursorType type) - : handle (juce_createStandardMouseCursor (type)), + : handle (createStandardMouseCursor (type)), refCount (1), standardType (type), isStandard (true) @@ -69352,7 +69348,7 @@ public: } SharedCursorHandle (const Image& image, const int hotSpotX, const int hotSpotY) - : handle (juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY)), + : handle (createMouseCursorFromImage (image, hotSpotX, hotSpotY)), refCount (1), standardType (MouseCursor::NormalCursor), isStandard (false) @@ -69420,7 +69416,7 @@ private: ~SharedCursorHandle() { - juce_deleteMouseCursor (handle, isStandard); + deleteMouseCursor (handle, isStandard); } SharedCursorHandle& operator= (const SharedCursorHandle&); @@ -211123,11 +211119,7 @@ void juce_CloseThreadHandle (void* handle) void* juce_createThread (void* userData) { unsigned int threadId; - - return (void*) _beginthreadex (0, 0, - &threadEntryProc, - userData, - 0, &threadId); + return (void*) _beginthreadex (0, 0, &threadEntryProc, userData, 0, &threadId); } void juce_killThread (void* handle) @@ -213075,7 +213067,7 @@ void MessageManager::broadcastMessage (const String& value) throw() GetWindowText (hwnd, windowName, 64); windowName [63] = 0; - if (String (windowName) == String (messageWindowName)) + if (String (windowName) == messageWindowName) { DWORD_PTR result; SendMessageTimeout (hwnd, WM_COPYDATA, @@ -215457,6 +215449,13 @@ static Image* createImageFromHICON (HICON icon) throw() static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw() { + WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true); + + { + Graphics g (bitmap); + g.drawImageAt (&image, 0, 0); + } + HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0); ICONINFO info; @@ -215464,45 +215463,9 @@ static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int ho info.xHotspot = hotspotX; info.yHotspot = hotspotY; info.hbmMask = mask; - HICON hi = 0; - - if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP) - { - WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true); - Graphics g (bitmap); - g.drawImageAt (&image, 0, 0); - - info.hbmColor = bitmap.hBitmap; - hi = CreateIconIndirect (&info); - } - else - { - HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight()); - - HDC colDC = CreateCompatibleDC (GetDC (0)); - HDC alphaDC = CreateCompatibleDC (GetDC (0)); - SelectObject (colDC, colour); - SelectObject (alphaDC, mask); - - for (int y = image.getHeight(); --y >= 0;) - { - for (int x = image.getWidth(); --x >= 0;) - { - const Colour c (image.getPixelAt (x, y)); - - SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16))); - SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16)))); - } - } - - DeleteDC (colDC); - DeleteDC (alphaDC); - - info.hbmColor = colour; - hi = CreateIconIndirect (&info); - DeleteObject (colour); - } + info.hbmColor = bitmap.hBitmap; + HICON hi = CreateIconIndirect (&info); DeleteObject (mask); return hi; } @@ -215527,13 +215490,13 @@ Image* juce_createIconForFile (const File& file) return image; } -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { const int maxW = GetSystemMetrics (SM_CXCURSOR); const int maxH = GetSystemMetrics (SM_CYCURSOR); const Image* im = ℑ - Image* newIm = 0; + ScopedPointer newIm; if (image.getWidth() > maxW || image.getHeight() > maxH) { @@ -215544,127 +215507,67 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot } void* cursorH = 0; - const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType(); - if (os == SystemStats::WinXP) - { - cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY); - } - else - { - const int stride = (maxW + 7) >> 3; - HeapBlock andPlane, xorPlane; - andPlane.calloc (stride * maxH); - xorPlane.calloc (stride * maxH); - int index = 0; - - for (int y = 0; y < maxH; ++y) - { - for (int x = 0; x < maxW; ++x) - { - const unsigned char bit = (unsigned char) (1 << (7 - (x & 7))); - - const Colour pixelColour (im->getPixelAt (x, y)); - - if (pixelColour.getAlpha() < 127) - andPlane [index + (x >> 3)] |= bit; - else if (pixelColour.getBrightness() >= 0.5f) - xorPlane [index + (x >> 3)] |= bit; - } - - index += stride; - } - - cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane); - } - - delete newIm; - return cursorH; + return createHICONFromImage (*im, FALSE, hotspotX, hotspotY); } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) { if (cursorHandle != 0 && ! isStandard) DestroyCursor ((HCURSOR) cursorHandle); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (const MouseCursor::StandardCursorType type) { LPCTSTR cursorName = IDC_ARROW; switch (type) { - case MouseCursor::NormalCursor: - cursorName = IDC_ARROW; - break; + case NormalCursor: break; + case NoCursor: return 0; + case WaitCursor: cursorName = IDC_WAIT; break; + case IBeamCursor: cursorName = IDC_IBEAM; break; + case PointingHandCursor: cursorName = MAKEINTRESOURCE(32649); break; + case CrosshairCursor: cursorName = IDC_CROSS; break; + case CopyingCursor: break; // can't seem to find one of these in the win32 list.. - case MouseCursor::NoCursor: - return 0; + case LeftRightResizeCursor: + case LeftEdgeResizeCursor: + case RightEdgeResizeCursor: cursorName = IDC_SIZEWE; break; - case MouseCursor::DraggingHandCursor: - { - static void* dragHandCursor = 0; + case UpDownResizeCursor: + case TopEdgeResizeCursor: + case BottomEdgeResizeCursor: cursorName = IDC_SIZENS; break; - if (dragHandCursor == 0) + case TopLeftCornerResizeCursor: + case BottomRightCornerResizeCursor: cursorName = IDC_SIZENWSE; break; + + case TopRightCornerResizeCursor: + case BottomLeftCornerResizeCursor: cursorName = IDC_SIZENESW; break; + + case UpDownLeftRightResizeCursor: cursorName = IDC_SIZEALL; break; + + case DraggingHandCursor: { - static const unsigned char dragHandData[] = - { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, - 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138, - 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; + static void* dragHandCursor = 0; - const ScopedPointer image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData))); - dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7); + if (dragHandCursor == 0) + { + static const unsigned char dragHandData[] = + { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, + 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138, + 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; + + const ScopedPointer image (ImageFileFormat::loadFrom (dragHandData, sizeof (dragHandData))); + dragHandCursor = createMouseCursorFromImage (*image, 8, 7); + } + + return dragHandCursor; } - return dragHandCursor; - } - - case MouseCursor::WaitCursor: - cursorName = IDC_WAIT; - break; - - case MouseCursor::IBeamCursor: - cursorName = IDC_IBEAM; - break; - - case MouseCursor::PointingHandCursor: - cursorName = MAKEINTRESOURCE(32649); - break; - - case MouseCursor::LeftRightResizeCursor: - case MouseCursor::LeftEdgeResizeCursor: - case MouseCursor::RightEdgeResizeCursor: - cursorName = IDC_SIZEWE; - break; - - case MouseCursor::UpDownResizeCursor: - case MouseCursor::TopEdgeResizeCursor: - case MouseCursor::BottomEdgeResizeCursor: - cursorName = IDC_SIZENS; - break; - - case MouseCursor::TopLeftCornerResizeCursor: - case MouseCursor::BottomRightCornerResizeCursor: - cursorName = IDC_SIZENWSE; - break; - - case MouseCursor::TopRightCornerResizeCursor: - case MouseCursor::BottomLeftCornerResizeCursor: - cursorName = IDC_SIZENESW; - break; - - case MouseCursor::UpDownLeftRightResizeCursor: - cursorName = IDC_SIZEALL; - break; - - case MouseCursor::CrosshairCursor: - cursorName = IDC_CROSS; - break; - - case MouseCursor::CopyingCursor: - // can't seem to find one of these in the win32 list.. - break; + default: + jassertfalse; break; } HCURSOR cursorH = LoadCursor (0, cursorName); @@ -232928,7 +232831,7 @@ bool Desktop::isScreenSaverEnabled() throw() return screenSaverAllowed; } -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { ScopedXLock xlock; const unsigned int imageW = image.getWidth(); @@ -233053,117 +232956,64 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot return result; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool) { ScopedXLock xlock; if (cursorHandle != 0) XFreeCursor (display, (Cursor) cursorHandle); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { unsigned int shape; switch (type) { - case MouseCursor::NoCursor: - { - const Image im (Image::ARGB, 16, 16, true); - return juce_createMouseCursorFromImage (im, 0, 0); - } + case NormalCursor: return None; // Use parent cursor + case NoCursor: return createMouseCursorFromImage (Image (Image::ARGB, 16, 16, true), 0, 0); - case MouseCursor::NormalCursor: - return (void*) None; // Use parent cursor + case WaitCursor: shape = XC_watch; break; + case IBeamCursor: shape = XC_xterm; break; + case PointingHandCursor: shape = XC_hand2; break; + case LeftRightResizeCursor: shape = XC_sb_h_double_arrow; break; + case UpDownResizeCursor: shape = XC_sb_v_double_arrow; break; + case UpDownLeftRightResizeCursor: shape = XC_fleur; break; + case TopEdgeResizeCursor: shape = XC_top_side; break; + case BottomEdgeResizeCursor: shape = XC_bottom_side; break; + case LeftEdgeResizeCursor: shape = XC_left_side; break; + case RightEdgeResizeCursor: shape = XC_right_side; break; + case TopLeftCornerResizeCursor: shape = XC_top_left_corner; break; + case TopRightCornerResizeCursor: shape = XC_top_right_corner; break; + case BottomLeftCornerResizeCursor: shape = XC_bottom_left_corner; break; + case BottomRightCornerResizeCursor: shape = XC_bottom_right_corner; break; + case CrosshairCursor: shape = XC_crosshair; break; - case MouseCursor::DraggingHandCursor: + case DraggingHandCursor: { - static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0, - 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, - 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, - 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217, - 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; + static unsigned char dragHandData[] = { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0, + 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, + 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217, 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; const int dragHandDataSize = 99; const ScopedPointer im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize)); - return juce_createMouseCursorFromImage (*im, 8, 7); + return createMouseCursorFromImage (*im, 8, 7); } - case MouseCursor::CopyingCursor: + case CopyingCursor: { - static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0, - 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0, - 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111, - 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174, - 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112, + static unsigned char copyCursorData[] = { 71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0, + 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0, 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111, + 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174, 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112, 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 }; const int copyCursorSize = 119; const ScopedPointer im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize)); - return juce_createMouseCursorFromImage (*im, 1, 3); + return createMouseCursorFromImage (*im, 1, 3); } - case MouseCursor::WaitCursor: - shape = XC_watch; - break; - - case MouseCursor::IBeamCursor: - shape = XC_xterm; - break; - - case MouseCursor::PointingHandCursor: - shape = XC_hand2; - break; - - case MouseCursor::LeftRightResizeCursor: - shape = XC_sb_h_double_arrow; - break; - - case MouseCursor::UpDownResizeCursor: - shape = XC_sb_v_double_arrow; - break; - - case MouseCursor::UpDownLeftRightResizeCursor: - shape = XC_fleur; - break; - - case MouseCursor::TopEdgeResizeCursor: - shape = XC_top_side; - break; - - case MouseCursor::BottomEdgeResizeCursor: - shape = XC_bottom_side; - break; - - case MouseCursor::LeftEdgeResizeCursor: - shape = XC_left_side; - break; - - case MouseCursor::RightEdgeResizeCursor: - shape = XC_right_side; - break; - - case MouseCursor::TopLeftCornerResizeCursor: - shape = XC_top_left_corner; - break; - - case MouseCursor::TopRightCornerResizeCursor: - shape = XC_top_right_corner; - break; - - case MouseCursor::BottomLeftCornerResizeCursor: - shape = XC_bottom_left_corner; - break; - - case MouseCursor::BottomRightCornerResizeCursor: - shape = XC_bottom_right_corner; - break; - - case MouseCursor::CrosshairCursor: - shape = XC_crosshair; - break; - default: - return (void*) None; // Use parent cursor + jassertfalse; + return None; } ScopedXLock xlock; @@ -241325,118 +241175,85 @@ void juce_glViewport (const int w, const int h) #if JUCE_MAC -Image* juce_loadPNGImageFromStream (InputStream& inputStream); - -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +namespace MouseCursorHelpers { - NSImage* im = CoreGraphicsImage::createNSImage (image); - NSCursor* c = [[NSCursor alloc] initWithImage: im - hotSpot: NSMakePoint (hotspotX, hotspotY)]; - [im release]; + static void* createFromImage (const Image& image, float hotspotX, float hotspotY) + { + NSImage* im = CoreGraphicsImage::createNSImage (image); + NSCursor* c = [[NSCursor alloc] initWithImage: im + hotSpot: NSMakePoint (hotspotX, hotspotY)]; + [im release]; + return c; + } - return c; -} + static void* fromWebKitFile (const char* filename, float hx, float hy) + { + FileInputStream fileStream (String ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources/") + filename); + BufferedInputStream buf (&fileStream, 4096, false); -static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy) -{ - MemoryInputStream stream (data, false); - ScopedPointer im (juce_loadPNGImageFromStream (stream)); - jassert (im != 0); + PNGImageFormat pngFormat; + const ScopedPointer im (pngFormat.decodeImage (buf)); - if (im == 0) + if (im != 0) + return createFromImage (*im, hx * im->getWidth(), hy * im->getHeight()); + + jassertfalse; return 0; - - return juce_createMouseCursorFromImage (*im, - (int) (hx * im->getWidth()), - (int) (hy * im->getHeight())); + } } -static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { - const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources"); - - MemoryBlock mb; - if (f.getChildFile (filename).loadFileAsData (mb)) - return juce_cursorFromData (mb, hx, hy); - - return 0; + return MouseCursorHelpers::createFromImage (image, (float) hotspotX, (float) hotspotY); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { const ScopedAutoReleasePool pool; NSCursor* c = 0; switch (type) { - case MouseCursor::NormalCursor: - c = [NSCursor arrowCursor]; - break; + case NormalCursor: 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 + case IBeamCursor: c = [NSCursor IBeamCursor]; break; + case PointingHandCursor: c = [NSCursor pointingHandCursor]; break; + case LeftRightResizeCursor: c = [NSCursor resizeLeftRightCursor]; break; + case LeftEdgeResizeCursor: c = [NSCursor resizeLeftCursor]; break; + case RightEdgeResizeCursor: c = [NSCursor resizeRightCursor]; break; + case CrosshairCursor: c = [NSCursor crosshairCursor]; break; + case CopyingCursor: return MouseCursorHelpers::fromWebKitFile ("copyCursor.png", 0, 0); - case MouseCursor::NoCursor: - return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0); + case UpDownResizeCursor: + case TopEdgeResizeCursor: + case BottomEdgeResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::DraggingHandCursor: - c = [NSCursor openHandCursor]; - break; + case TopLeftCornerResizeCursor: + case BottomRightCornerResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::CopyingCursor: - return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0); + case TopRightCornerResizeCursor: + case BottomLeftCornerResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::WaitCursor: - c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball - break; - //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f); + case UpDownLeftRightResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("moveCursor.png", 0.5f, 0.5f); - case MouseCursor::IBeamCursor: - c = [NSCursor IBeamCursor]; - break; - - case MouseCursor::PointingHandCursor: - c = [NSCursor pointingHandCursor]; - break; - - case MouseCursor::LeftRightResizeCursor: - c = [NSCursor resizeLeftRightCursor]; - break; - - case MouseCursor::LeftEdgeResizeCursor: - c = [NSCursor resizeLeftCursor]; - break; - - case MouseCursor::RightEdgeResizeCursor: - c = [NSCursor resizeRightCursor]; - break; - - case MouseCursor::UpDownResizeCursor: - case MouseCursor::TopEdgeResizeCursor: - case MouseCursor::BottomEdgeResizeCursor: - return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::TopLeftCornerResizeCursor: - case MouseCursor::BottomRightCornerResizeCursor: - return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::TopRightCornerResizeCursor: - case MouseCursor::BottomLeftCornerResizeCursor: - return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::UpDownLeftRightResizeCursor: - return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f); - - case MouseCursor::CrosshairCursor: - c = [NSCursor crosshairCursor]; - break; + default: + jassertfalse; + break; } [c retain]; return c; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) { - NSCursor* c = (NSCursor*) cursorHandle; - [c release]; + [((NSCursor*) cursorHandle) release]; } void MouseCursor::showInAllWindows() const @@ -241446,15 +241263,14 @@ void MouseCursor::showInAllWindows() const void MouseCursor::showInWindow (ComponentPeer*) const { - NSCursor* const c = (NSCursor*) getHandle(); - [c set]; + [((NSCursor*) getHandle()) set]; } #else -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {} +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; } +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; } +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) {} void MouseCursor::showInAllWindows() const {} void MouseCursor::showInWindow (ComponentPeer*) const {} @@ -245857,118 +245673,85 @@ const int KeyPress::rewindKey = 0x30003; #if JUCE_MAC -Image* juce_loadPNGImageFromStream (InputStream& inputStream); - -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +namespace MouseCursorHelpers { - NSImage* im = CoreGraphicsImage::createNSImage (image); - NSCursor* c = [[NSCursor alloc] initWithImage: im - hotSpot: NSMakePoint (hotspotX, hotspotY)]; - [im release]; + static void* createFromImage (const Image& image, float hotspotX, float hotspotY) + { + NSImage* im = CoreGraphicsImage::createNSImage (image); + NSCursor* c = [[NSCursor alloc] initWithImage: im + hotSpot: NSMakePoint (hotspotX, hotspotY)]; + [im release]; + return c; + } - return c; -} + static void* fromWebKitFile (const char* filename, float hx, float hy) + { + FileInputStream fileStream (String ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources/") + filename); + BufferedInputStream buf (&fileStream, 4096, false); -static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy) -{ - MemoryInputStream stream (data, false); - ScopedPointer im (juce_loadPNGImageFromStream (stream)); - jassert (im != 0); + PNGImageFormat pngFormat; + const ScopedPointer im (pngFormat.decodeImage (buf)); - if (im == 0) + if (im != 0) + return createFromImage (*im, hx * im->getWidth(), hy * im->getHeight()); + + jassertfalse; return 0; - - return juce_createMouseCursorFromImage (*im, - (int) (hx * im->getWidth()), - (int) (hy * im->getHeight())); + } } -static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { - const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources"); - - MemoryBlock mb; - if (f.getChildFile (filename).loadFileAsData (mb)) - return juce_cursorFromData (mb, hx, hy); - - return 0; + return MouseCursorHelpers::createFromImage (image, (float) hotspotX, (float) hotspotY); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { const ScopedAutoReleasePool pool; NSCursor* c = 0; switch (type) { - case MouseCursor::NormalCursor: - c = [NSCursor arrowCursor]; - break; + case NormalCursor: 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 + case IBeamCursor: c = [NSCursor IBeamCursor]; break; + case PointingHandCursor: c = [NSCursor pointingHandCursor]; break; + case LeftRightResizeCursor: c = [NSCursor resizeLeftRightCursor]; break; + case LeftEdgeResizeCursor: c = [NSCursor resizeLeftCursor]; break; + case RightEdgeResizeCursor: c = [NSCursor resizeRightCursor]; break; + case CrosshairCursor: c = [NSCursor crosshairCursor]; break; + case CopyingCursor: return MouseCursorHelpers::fromWebKitFile ("copyCursor.png", 0, 0); - case MouseCursor::NoCursor: - return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0); + case UpDownResizeCursor: + case TopEdgeResizeCursor: + case BottomEdgeResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::DraggingHandCursor: - c = [NSCursor openHandCursor]; - break; + case TopLeftCornerResizeCursor: + case BottomRightCornerResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::CopyingCursor: - return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0); + case TopRightCornerResizeCursor: + case BottomLeftCornerResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::WaitCursor: - c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball - break; - //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f); + case UpDownLeftRightResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("moveCursor.png", 0.5f, 0.5f); - case MouseCursor::IBeamCursor: - c = [NSCursor IBeamCursor]; - break; - - case MouseCursor::PointingHandCursor: - c = [NSCursor pointingHandCursor]; - break; - - case MouseCursor::LeftRightResizeCursor: - c = [NSCursor resizeLeftRightCursor]; - break; - - case MouseCursor::LeftEdgeResizeCursor: - c = [NSCursor resizeLeftCursor]; - break; - - case MouseCursor::RightEdgeResizeCursor: - c = [NSCursor resizeRightCursor]; - break; - - case MouseCursor::UpDownResizeCursor: - case MouseCursor::TopEdgeResizeCursor: - case MouseCursor::BottomEdgeResizeCursor: - return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::TopLeftCornerResizeCursor: - case MouseCursor::BottomRightCornerResizeCursor: - return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::TopRightCornerResizeCursor: - case MouseCursor::BottomLeftCornerResizeCursor: - return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::UpDownLeftRightResizeCursor: - return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f); - - case MouseCursor::CrosshairCursor: - c = [NSCursor crosshairCursor]; - break; + default: + jassertfalse; + break; } [c retain]; return c; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) { - NSCursor* c = (NSCursor*) cursorHandle; - [c release]; + [((NSCursor*) cursorHandle) release]; } void MouseCursor::showInAllWindows() const @@ -245978,15 +245761,14 @@ void MouseCursor::showInAllWindows() const void MouseCursor::showInWindow (ComponentPeer*) const { - NSCursor* const c = (NSCursor*) getHandle(); - [c set]; + [((NSCursor*) getHandle()) set]; } #else -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {} +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; } +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; } +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) {} void MouseCursor::showInAllWindows() const {} void MouseCursor::showInWindow (ComponentPeer*) const {} diff --git a/juce_amalgamated.h b/juce_amalgamated.h index d55db71207..ff3249b03a 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -9382,6 +9382,10 @@ private: void showInWindow (ComponentPeer* window) const; void showInAllWindows() const; void* getHandle() const throw(); + + static void* createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY); + static void* createStandardMouseCursor (MouseCursor::StandardCursorType type); + static void deleteMouseCursor (void* cursorHandle, bool isStandard); }; #endif // __JUCE_MOUSECURSOR_JUCEHEADER__ diff --git a/src/gui/components/mouse/juce_MouseCursor.cpp b/src/gui/components/mouse/juce_MouseCursor.cpp index d68d4ca3e2..3354eaf085 100644 --- a/src/gui/components/mouse/juce_MouseCursor.cpp +++ b/src/gui/components/mouse/juce_MouseCursor.cpp @@ -33,17 +33,13 @@ BEGIN_JUCE_NAMESPACE #include "../mouse/juce_MouseInputSource.h" #include "../../../threads/juce_ScopedLock.h" -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY); -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type); -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard); - //============================================================================== class MouseCursor::SharedCursorHandle { public: explicit SharedCursorHandle (const MouseCursor::StandardCursorType type) - : handle (juce_createStandardMouseCursor (type)), + : handle (createStandardMouseCursor (type)), refCount (1), standardType (type), isStandard (true) @@ -51,7 +47,7 @@ public: } SharedCursorHandle (const Image& image, const int hotSpotX, const int hotSpotY) - : handle (juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY)), + : handle (createMouseCursorFromImage (image, hotSpotX, hotSpotY)), refCount (1), standardType (MouseCursor::NormalCursor), isStandard (false) @@ -121,7 +117,7 @@ private: ~SharedCursorHandle() { - juce_deleteMouseCursor (handle, isStandard); + deleteMouseCursor (handle, isStandard); } SharedCursorHandle& operator= (const SharedCursorHandle&); diff --git a/src/gui/components/mouse/juce_MouseCursor.h b/src/gui/components/mouse/juce_MouseCursor.h index 4e4b0f8a62..c36ea62c97 100644 --- a/src/gui/components/mouse/juce_MouseCursor.h +++ b/src/gui/components/mouse/juce_MouseCursor.h @@ -151,6 +151,10 @@ private: void showInWindow (ComponentPeer* window) const; void showInAllWindows() const; void* getHandle() const throw(); + + static void* createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY); + static void* createStandardMouseCursor (MouseCursor::StandardCursorType type); + static void deleteMouseCursor (void* cursorHandle, bool isStandard); }; #endif // __JUCE_MOUSECURSOR_JUCEHEADER__ diff --git a/src/native/juce_mac_NativeCode.mm b/src/native/juce_mac_NativeCode.mm index 4c072a0896..a51a77ef32 100644 --- a/src/native/juce_mac_NativeCode.mm +++ b/src/native/juce_mac_NativeCode.mm @@ -51,6 +51,7 @@ BEGIN_JUCE_NAMESPACE #include "../io/files/juce_DirectoryIterator.h" #include "../io/network/juce_URL.h" #include "../io/streams/juce_MemoryInputStream.h" +#include "../io/streams/juce_BufferedInputStream.h" #include "../core/juce_PlatformUtilities.h" #include "../text/juce_LocalisedStrings.h" #include "../utilities/juce_DeletedAtShutdown.h" diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index b46728e115..c748cc829c 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -2960,7 +2960,7 @@ bool Desktop::isScreenSaverEnabled() throw() } //============================================================================== -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { ScopedXLock xlock; const unsigned int imageW = image.getWidth(); @@ -3085,117 +3085,64 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot return result; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool) { ScopedXLock xlock; if (cursorHandle != 0) XFreeCursor (display, (Cursor) cursorHandle); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { unsigned int shape; switch (type) { - case MouseCursor::NoCursor: - { - const Image im (Image::ARGB, 16, 16, true); - return juce_createMouseCursorFromImage (im, 0, 0); - } + case NormalCursor: return None; // Use parent cursor + case NoCursor: return createMouseCursorFromImage (Image (Image::ARGB, 16, 16, true), 0, 0); - case MouseCursor::NormalCursor: - return (void*) None; // Use parent cursor + case WaitCursor: shape = XC_watch; break; + case IBeamCursor: shape = XC_xterm; break; + case PointingHandCursor: shape = XC_hand2; break; + case LeftRightResizeCursor: shape = XC_sb_h_double_arrow; break; + case UpDownResizeCursor: shape = XC_sb_v_double_arrow; break; + case UpDownLeftRightResizeCursor: shape = XC_fleur; break; + case TopEdgeResizeCursor: shape = XC_top_side; break; + case BottomEdgeResizeCursor: shape = XC_bottom_side; break; + case LeftEdgeResizeCursor: shape = XC_left_side; break; + case RightEdgeResizeCursor: shape = XC_right_side; break; + case TopLeftCornerResizeCursor: shape = XC_top_left_corner; break; + case TopRightCornerResizeCursor: shape = XC_top_right_corner; break; + case BottomLeftCornerResizeCursor: shape = XC_bottom_left_corner; break; + case BottomRightCornerResizeCursor: shape = XC_bottom_right_corner; break; + case CrosshairCursor: shape = XC_crosshair; break; - case MouseCursor::DraggingHandCursor: + case DraggingHandCursor: { - static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0, - 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, - 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, - 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217, - 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; + static unsigned char dragHandData[] = { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0, + 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, + 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217, 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; const int dragHandDataSize = 99; const ScopedPointer im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize)); - return juce_createMouseCursorFromImage (*im, 8, 7); + return createMouseCursorFromImage (*im, 8, 7); } - case MouseCursor::CopyingCursor: + case CopyingCursor: { - static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0, - 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0, - 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111, - 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174, - 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112, + static unsigned char copyCursorData[] = { 71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0, + 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0, 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111, + 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174, 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112, 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 }; const int copyCursorSize = 119; const ScopedPointer im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize)); - return juce_createMouseCursorFromImage (*im, 1, 3); + return createMouseCursorFromImage (*im, 1, 3); } - case MouseCursor::WaitCursor: - shape = XC_watch; - break; - - case MouseCursor::IBeamCursor: - shape = XC_xterm; - break; - - case MouseCursor::PointingHandCursor: - shape = XC_hand2; - break; - - case MouseCursor::LeftRightResizeCursor: - shape = XC_sb_h_double_arrow; - break; - - case MouseCursor::UpDownResizeCursor: - shape = XC_sb_v_double_arrow; - break; - - case MouseCursor::UpDownLeftRightResizeCursor: - shape = XC_fleur; - break; - - case MouseCursor::TopEdgeResizeCursor: - shape = XC_top_side; - break; - - case MouseCursor::BottomEdgeResizeCursor: - shape = XC_bottom_side; - break; - - case MouseCursor::LeftEdgeResizeCursor: - shape = XC_left_side; - break; - - case MouseCursor::RightEdgeResizeCursor: - shape = XC_right_side; - break; - - case MouseCursor::TopLeftCornerResizeCursor: - shape = XC_top_left_corner; - break; - - case MouseCursor::TopRightCornerResizeCursor: - shape = XC_top_right_corner; - break; - - case MouseCursor::BottomLeftCornerResizeCursor: - shape = XC_bottom_left_corner; - break; - - case MouseCursor::BottomRightCornerResizeCursor: - shape = XC_bottom_right_corner; - break; - - case MouseCursor::CrosshairCursor: - shape = XC_crosshair; - break; - default: - return (void*) None; // Use parent cursor + jassertfalse; + return None; } ScopedXLock xlock; diff --git a/src/native/mac/juce_mac_MouseCursor.mm b/src/native/mac/juce_mac_MouseCursor.mm index ba0de028b5..a8100ea15e 100644 --- a/src/native/mac/juce_mac_MouseCursor.mm +++ b/src/native/mac/juce_mac_MouseCursor.mm @@ -29,119 +29,86 @@ #if JUCE_MAC -Image* juce_loadPNGImageFromStream (InputStream& inputStream); - //============================================================================== -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +namespace MouseCursorHelpers { - NSImage* im = CoreGraphicsImage::createNSImage (image); - NSCursor* c = [[NSCursor alloc] initWithImage: im - hotSpot: NSMakePoint (hotspotX, hotspotY)]; - [im release]; + static void* createFromImage (const Image& image, float hotspotX, float hotspotY) + { + NSImage* im = CoreGraphicsImage::createNSImage (image); + NSCursor* c = [[NSCursor alloc] initWithImage: im + hotSpot: NSMakePoint (hotspotX, hotspotY)]; + [im release]; + return c; + } - return c; -} + static void* fromWebKitFile (const char* filename, float hx, float hy) + { + FileInputStream fileStream (String ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources/") + filename); + BufferedInputStream buf (&fileStream, 4096, false); -static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy) -{ - MemoryInputStream stream (data, false); - ScopedPointer im (juce_loadPNGImageFromStream (stream)); - jassert (im != 0); + PNGImageFormat pngFormat; + const ScopedPointer im (pngFormat.decodeImage (buf)); - if (im == 0) + if (im != 0) + return createFromImage (*im, hx * im->getWidth(), hy * im->getHeight()); + + jassertfalse; return 0; - - return juce_createMouseCursorFromImage (*im, - (int) (hx * im->getWidth()), - (int) (hy * im->getHeight())); + } } -static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { - const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources"); - - MemoryBlock mb; - if (f.getChildFile (filename).loadFileAsData (mb)) - return juce_cursorFromData (mb, hx, hy); - - return 0; + return MouseCursorHelpers::createFromImage (image, (float) hotspotX, (float) hotspotY); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { const ScopedAutoReleasePool pool; NSCursor* c = 0; switch (type) { - case MouseCursor::NormalCursor: - c = [NSCursor arrowCursor]; - break; + case NormalCursor: 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 + case IBeamCursor: c = [NSCursor IBeamCursor]; break; + case PointingHandCursor: c = [NSCursor pointingHandCursor]; break; + case LeftRightResizeCursor: c = [NSCursor resizeLeftRightCursor]; break; + case LeftEdgeResizeCursor: c = [NSCursor resizeLeftCursor]; break; + case RightEdgeResizeCursor: c = [NSCursor resizeRightCursor]; break; + case CrosshairCursor: c = [NSCursor crosshairCursor]; break; + case CopyingCursor: return MouseCursorHelpers::fromWebKitFile ("copyCursor.png", 0, 0); - case MouseCursor::NoCursor: - return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0); + case UpDownResizeCursor: + case TopEdgeResizeCursor: + case BottomEdgeResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::DraggingHandCursor: - c = [NSCursor openHandCursor]; - break; + case TopLeftCornerResizeCursor: + case BottomRightCornerResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::CopyingCursor: - return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0); + case TopRightCornerResizeCursor: + case BottomLeftCornerResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f); - case MouseCursor::WaitCursor: - c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball - break; - //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f); + case UpDownLeftRightResizeCursor: + return MouseCursorHelpers::fromWebKitFile ("moveCursor.png", 0.5f, 0.5f); - case MouseCursor::IBeamCursor: - c = [NSCursor IBeamCursor]; - break; - - case MouseCursor::PointingHandCursor: - c = [NSCursor pointingHandCursor]; - break; - - case MouseCursor::LeftRightResizeCursor: - c = [NSCursor resizeLeftRightCursor]; - break; - - case MouseCursor::LeftEdgeResizeCursor: - c = [NSCursor resizeLeftCursor]; - break; - - case MouseCursor::RightEdgeResizeCursor: - c = [NSCursor resizeRightCursor]; - break; - - case MouseCursor::UpDownResizeCursor: - case MouseCursor::TopEdgeResizeCursor: - case MouseCursor::BottomEdgeResizeCursor: - return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::TopLeftCornerResizeCursor: - case MouseCursor::BottomRightCornerResizeCursor: - return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::TopRightCornerResizeCursor: - case MouseCursor::BottomLeftCornerResizeCursor: - return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f); - - case MouseCursor::UpDownLeftRightResizeCursor: - return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f); - - case MouseCursor::CrosshairCursor: - c = [NSCursor crosshairCursor]; - break; + default: + jassertfalse; + break; } [c retain]; return c; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) { - NSCursor* c = (NSCursor*) cursorHandle; - [c release]; + [((NSCursor*) cursorHandle) release]; } void MouseCursor::showInAllWindows() const @@ -151,15 +118,14 @@ void MouseCursor::showInAllWindows() const void MouseCursor::showInWindow (ComponentPeer*) const { - NSCursor* const c = (NSCursor*) getHandle(); - [c set]; + [((NSCursor*) getHandle()) set]; } #else -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {} +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; } +void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; } +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) {} void MouseCursor::showInAllWindows() const {} void MouseCursor::showInWindow (ComponentPeer*) const {} diff --git a/src/native/windows/juce_win32_Messaging.cpp b/src/native/windows/juce_win32_Messaging.cpp index 8eb8fc4ca0..eda57f6aa0 100644 --- a/src/native/windows/juce_win32_Messaging.cpp +++ b/src/native/windows/juce_win32_Messaging.cpp @@ -238,7 +238,7 @@ void MessageManager::broadcastMessage (const String& value) throw() GetWindowText (hwnd, windowName, 64); windowName [63] = 0; - if (String (windowName) == String (messageWindowName)) + if (String (windowName) == messageWindowName) { DWORD_PTR result; SendMessageTimeout (hwnd, WM_COPYDATA, diff --git a/src/native/windows/juce_win32_Threads.cpp b/src/native/windows/juce_win32_Threads.cpp index 54be49dc90..7fdb884eb2 100644 --- a/src/native/windows/juce_win32_Threads.cpp +++ b/src/native/windows/juce_win32_Threads.cpp @@ -128,11 +128,7 @@ void juce_CloseThreadHandle (void* handle) void* juce_createThread (void* userData) { unsigned int threadId; - - return (void*) _beginthreadex (0, 0, - &threadEntryProc, - userData, - 0, &threadId); + return (void*) _beginthreadex (0, 0, &threadEntryProc, userData, 0, &threadId); } void juce_killThread (void* handle) diff --git a/src/native/windows/juce_win32_Windowing.cpp b/src/native/windows/juce_win32_Windowing.cpp index 1ef038e8bc..90d31cd2a4 100644 --- a/src/native/windows/juce_win32_Windowing.cpp +++ b/src/native/windows/juce_win32_Windowing.cpp @@ -2407,6 +2407,13 @@ static Image* createImageFromHICON (HICON icon) throw() static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw() { + WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true); + + { + Graphics g (bitmap); + g.drawImageAt (&image, 0, 0); + } + HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0); ICONINFO info; @@ -2414,45 +2421,9 @@ static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int ho info.xHotspot = hotspotX; info.yHotspot = hotspotY; info.hbmMask = mask; - HICON hi = 0; - - if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP) - { - WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true); - Graphics g (bitmap); - g.drawImageAt (&image, 0, 0); - - info.hbmColor = bitmap.hBitmap; - hi = CreateIconIndirect (&info); - } - else - { - HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight()); - - HDC colDC = CreateCompatibleDC (GetDC (0)); - HDC alphaDC = CreateCompatibleDC (GetDC (0)); - SelectObject (colDC, colour); - SelectObject (alphaDC, mask); - - for (int y = image.getHeight(); --y >= 0;) - { - for (int x = image.getWidth(); --x >= 0;) - { - const Colour c (image.getPixelAt (x, y)); - - SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16))); - SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16)))); - } - } - - DeleteDC (colDC); - DeleteDC (alphaDC); - - info.hbmColor = colour; - hi = CreateIconIndirect (&info); - DeleteObject (colour); - } + info.hbmColor = bitmap.hBitmap; + HICON hi = CreateIconIndirect (&info); DeleteObject (mask); return hi; } @@ -2478,13 +2449,13 @@ Image* juce_createIconForFile (const File& file) } //============================================================================== -void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) +void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { const int maxW = GetSystemMetrics (SM_CXCURSOR); const int maxH = GetSystemMetrics (SM_CYCURSOR); const Image* im = ℑ - Image* newIm = 0; + ScopedPointer newIm; if (image.getWidth() > maxW || image.getHeight() > maxH) { @@ -2495,127 +2466,67 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot } void* cursorH = 0; - const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType(); - if (os == SystemStats::WinXP) - { - cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY); - } - else - { - const int stride = (maxW + 7) >> 3; - HeapBlock andPlane, xorPlane; - andPlane.calloc (stride * maxH); - xorPlane.calloc (stride * maxH); - int index = 0; - - for (int y = 0; y < maxH; ++y) - { - for (int x = 0; x < maxW; ++x) - { - const unsigned char bit = (unsigned char) (1 << (7 - (x & 7))); - - const Colour pixelColour (im->getPixelAt (x, y)); - - if (pixelColour.getAlpha() < 127) - andPlane [index + (x >> 3)] |= bit; - else if (pixelColour.getBrightness() >= 0.5f) - xorPlane [index + (x >> 3)] |= bit; - } - - index += stride; - } - - cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane); - } - - delete newIm; - return cursorH; + return createHICONFromImage (*im, FALSE, hotspotX, hotspotY); } -void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) +void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) { if (cursorHandle != 0 && ! isStandard) DestroyCursor ((HCURSOR) cursorHandle); } -void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) +void* MouseCursor::createStandardMouseCursor (const MouseCursor::StandardCursorType type) { LPCTSTR cursorName = IDC_ARROW; switch (type) { - case MouseCursor::NormalCursor: - cursorName = IDC_ARROW; - break; + case NormalCursor: break; + case NoCursor: return 0; + case WaitCursor: cursorName = IDC_WAIT; break; + case IBeamCursor: cursorName = IDC_IBEAM; break; + case PointingHandCursor: cursorName = MAKEINTRESOURCE(32649); break; + case CrosshairCursor: cursorName = IDC_CROSS; break; + case CopyingCursor: break; // can't seem to find one of these in the win32 list.. - case MouseCursor::NoCursor: - return 0; + case LeftRightResizeCursor: + case LeftEdgeResizeCursor: + case RightEdgeResizeCursor: cursorName = IDC_SIZEWE; break; - case MouseCursor::DraggingHandCursor: - { - static void* dragHandCursor = 0; + case UpDownResizeCursor: + case TopEdgeResizeCursor: + case BottomEdgeResizeCursor: cursorName = IDC_SIZENS; break; - if (dragHandCursor == 0) + case TopLeftCornerResizeCursor: + case BottomRightCornerResizeCursor: cursorName = IDC_SIZENWSE; break; + + case TopRightCornerResizeCursor: + case BottomLeftCornerResizeCursor: cursorName = IDC_SIZENESW; break; + + case UpDownLeftRightResizeCursor: cursorName = IDC_SIZEALL; break; + + case DraggingHandCursor: { - static const unsigned char dragHandData[] = - { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, - 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138, - 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; + static void* dragHandCursor = 0; - const ScopedPointer image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData))); - dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7); + if (dragHandCursor == 0) + { + static const unsigned char dragHandData[] = + { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0, + 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138, + 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 }; + + const ScopedPointer image (ImageFileFormat::loadFrom (dragHandData, sizeof (dragHandData))); + dragHandCursor = createMouseCursorFromImage (*image, 8, 7); + } + + return dragHandCursor; } - return dragHandCursor; - } - - case MouseCursor::WaitCursor: - cursorName = IDC_WAIT; - break; - - case MouseCursor::IBeamCursor: - cursorName = IDC_IBEAM; - break; - - case MouseCursor::PointingHandCursor: - cursorName = MAKEINTRESOURCE(32649); - break; - - case MouseCursor::LeftRightResizeCursor: - case MouseCursor::LeftEdgeResizeCursor: - case MouseCursor::RightEdgeResizeCursor: - cursorName = IDC_SIZEWE; - break; - - case MouseCursor::UpDownResizeCursor: - case MouseCursor::TopEdgeResizeCursor: - case MouseCursor::BottomEdgeResizeCursor: - cursorName = IDC_SIZENS; - break; - - case MouseCursor::TopLeftCornerResizeCursor: - case MouseCursor::BottomRightCornerResizeCursor: - cursorName = IDC_SIZENWSE; - break; - - case MouseCursor::TopRightCornerResizeCursor: - case MouseCursor::BottomLeftCornerResizeCursor: - cursorName = IDC_SIZENESW; - break; - - case MouseCursor::UpDownLeftRightResizeCursor: - cursorName = IDC_SIZEALL; - break; - - case MouseCursor::CrosshairCursor: - cursorName = IDC_CROSS; - break; - - case MouseCursor::CopyingCursor: - // can't seem to find one of these in the win32 list.. - break; + default: + jassertfalse; break; } HCURSOR cursorH = LoadCursor (0, cursorName);