The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #if JUCE_MAC
  19. //==============================================================================
  20. namespace MouseCursorHelpers
  21. {
  22. static NSImage* createNSImage (const Image& image)
  23. {
  24. JUCE_AUTORELEASEPOOL
  25. NSImage* im = [[NSImage alloc] init];
  26. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  27. [im lockFocus];
  28. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  29. CGImageRef imageRef = juce_createCoreGraphicsImage (image, false, colourSpace, false);
  30. CGColorSpaceRelease (colourSpace);
  31. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  32. CGContextDrawImage (cg, convertToCGRect (image.getBounds()), imageRef);
  33. CGImageRelease (imageRef);
  34. [im unlockFocus];
  35. return im;
  36. }
  37. static void* fromWebKitFile (const char* filename, float hx, float hy)
  38. {
  39. FileInputStream fileStream (String ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources/") + filename);
  40. BufferedInputStream buf (fileStream, 4096);
  41. PNGImageFormat pngFormat;
  42. Image im (pngFormat.decodeImage (buf));
  43. if (im.isValid())
  44. return CustomMouseCursorInfo (im, (int) (hx * im.getWidth()),
  45. (int) (hy * im.getHeight())).create();
  46. jassertfalse;
  47. return nullptr;
  48. }
  49. }
  50. void* CustomMouseCursorInfo::create() const
  51. {
  52. NSImage* im = MouseCursorHelpers::createNSImage (image);
  53. NSCursor* c = [[NSCursor alloc] initWithImage: im
  54. hotSpot: NSMakePoint (hotspot.x, hotspot.y)];
  55. [im release];
  56. return c;
  57. }
  58. void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type)
  59. {
  60. JUCE_AUTORELEASEPOOL
  61. NSCursor* c = nil;
  62. switch (type)
  63. {
  64. case NormalCursor:
  65. case ParentCursor: c = [NSCursor arrowCursor]; break;
  66. case NoCursor: return CustomMouseCursorInfo (Image (Image::ARGB, 8, 8, true), 0, 0).create();
  67. case DraggingHandCursor: c = [NSCursor openHandCursor]; break;
  68. case WaitCursor: c = [NSCursor arrowCursor]; break; // avoid this on the mac, let the OS provide the beachball
  69. case IBeamCursor: c = [NSCursor IBeamCursor]; break;
  70. case PointingHandCursor: c = [NSCursor pointingHandCursor]; break;
  71. case LeftRightResizeCursor: c = [NSCursor resizeLeftRightCursor]; break;
  72. case LeftEdgeResizeCursor: c = [NSCursor resizeLeftCursor]; break;
  73. case RightEdgeResizeCursor: c = [NSCursor resizeRightCursor]; break;
  74. case CrosshairCursor: c = [NSCursor crosshairCursor]; break;
  75. case CopyingCursor: return MouseCursorHelpers::fromWebKitFile ("copyCursor.png", 0, 0);
  76. case UpDownResizeCursor:
  77. case TopEdgeResizeCursor:
  78. case BottomEdgeResizeCursor:
  79. return MouseCursorHelpers::fromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  80. case TopLeftCornerResizeCursor:
  81. case BottomRightCornerResizeCursor:
  82. return MouseCursorHelpers::fromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  83. case TopRightCornerResizeCursor:
  84. case BottomLeftCornerResizeCursor:
  85. return MouseCursorHelpers::fromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  86. case UpDownLeftRightResizeCursor:
  87. return MouseCursorHelpers::fromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  88. default:
  89. jassertfalse;
  90. break;
  91. }
  92. [c retain];
  93. return c;
  94. }
  95. void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool /*isStandard*/)
  96. {
  97. [((NSCursor*) cursorHandle) release];
  98. }
  99. void MouseCursor::showInAllWindows() const
  100. {
  101. showInWindow (nullptr);
  102. }
  103. void MouseCursor::showInWindow (ComponentPeer*) const
  104. {
  105. NSCursor* c = (NSCursor*) getHandle();
  106. if (c == nil)
  107. c = [NSCursor arrowCursor];
  108. [c set];
  109. }
  110. #else
  111. void* CustomMouseCursorInfo::create() const { return nullptr; }
  112. void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) { return nullptr; }
  113. void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  114. void MouseCursor::showInAllWindows() const {}
  115. void MouseCursor::showInWindow (ComponentPeer*) const {}
  116. #endif