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.

2522 lines
96KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. @interface NSEvent (DeviceDelta)
  19. - (float)deviceDeltaX;
  20. - (float)deviceDeltaY;
  21. @end
  22. //==============================================================================
  23. namespace juce
  24. {
  25. typedef void (*AppFocusChangeCallback)();
  26. extern AppFocusChangeCallback appFocusChangeCallback;
  27. typedef bool (*CheckEventBlockedByModalComps) (NSEvent*);
  28. extern CheckEventBlockedByModalComps isEventBlockedByModalComps;
  29. }
  30. namespace juce
  31. {
  32. //==============================================================================
  33. class NSViewComponentPeer : public ComponentPeer,
  34. private Timer
  35. {
  36. public:
  37. NSViewComponentPeer (Component& comp, const int windowStyleFlags, NSView* viewToAttachTo)
  38. : ComponentPeer (comp, windowStyleFlags),
  39. safeComponent (&comp),
  40. isSharedWindow (viewToAttachTo != nil),
  41. lastRepaintTime (Time::getMillisecondCounter())
  42. {
  43. appFocusChangeCallback = appFocusChanged;
  44. isEventBlockedByModalComps = checkEventBlockedByModalComps;
  45. auto r = makeNSRect (component.getLocalBounds());
  46. view = [createViewInstance() initWithFrame: r];
  47. setOwner (view, this);
  48. [view registerForDraggedTypes: getSupportedDragTypes()];
  49. notificationCenter = [NSNotificationCenter defaultCenter];
  50. [notificationCenter addObserver: view
  51. selector: frameChangedSelector
  52. name: NSViewFrameDidChangeNotification
  53. object: view];
  54. [view setPostsFrameChangedNotifications: YES];
  55. #if defined (MAC_OS_X_VERSION_10_8) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8) \
  56. && USE_COREGRAPHICS_RENDERING && JUCE_COREGRAPHICS_DRAW_ASYNC
  57. if (! getComponentAsyncLayerBackedViewDisabled (component))
  58. {
  59. [view setWantsLayer: YES];
  60. [[view layer] setDrawsAsynchronously: YES];
  61. }
  62. #endif
  63. if (isSharedWindow)
  64. {
  65. window = [viewToAttachTo window];
  66. [viewToAttachTo addSubview: view];
  67. }
  68. else
  69. {
  70. r.origin.x = (CGFloat) component.getX();
  71. r.origin.y = (CGFloat) component.getY();
  72. r = flippedScreenRect (r);
  73. window = [createWindowInstance() initWithContentRect: r
  74. styleMask: getNSWindowStyleMask (windowStyleFlags)
  75. backing: NSBackingStoreBuffered
  76. defer: YES];
  77. setOwner (window, this);
  78. #if JUCE_OBJC_HAS_AVAILABLE_FEATURE || (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10)
  79. #if JUCE_OBJC_HAS_AVAILABLE_FEATURE
  80. if (@available (macOS 10.10, *))
  81. #endif
  82. {
  83. [window setAccessibilityElement: component.getAccessibilityHandler() != nullptr];
  84. }
  85. #endif
  86. [window orderOut: nil];
  87. [window setDelegate: (id<NSWindowDelegate>) window];
  88. [window setOpaque: component.isOpaque()];
  89. if (! [window isOpaque])
  90. [window setBackgroundColor: [NSColor clearColor]];
  91. #if defined (MAC_OS_X_VERSION_10_9) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9)
  92. [view setAppearance: [NSAppearance appearanceNamed: NSAppearanceNameAqua]];
  93. #endif
  94. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  95. if (component.isAlwaysOnTop())
  96. setAlwaysOnTop (true);
  97. [window setContentView: view];
  98. [window setAcceptsMouseMovedEvents: YES];
  99. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  100. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  101. [window setReleasedWhenClosed: YES];
  102. [window retain];
  103. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  104. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  105. if ((windowStyleFlags & (windowHasMaximiseButton | windowHasTitleBar)) == (windowHasMaximiseButton | windowHasTitleBar))
  106. [window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
  107. if ([window respondsToSelector: @selector (setRestorable:)])
  108. [window setRestorable: NO];
  109. #if defined (MAC_OS_X_VERSION_10_13) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13)
  110. if ([window respondsToSelector: @selector (setTabbingMode:)])
  111. [window setTabbingMode: NSWindowTabbingModeDisallowed];
  112. #endif
  113. [notificationCenter addObserver: view
  114. selector: frameChangedSelector
  115. name: NSWindowDidMoveNotification
  116. object: window];
  117. [notificationCenter addObserver: view
  118. selector: frameChangedSelector
  119. name: NSWindowDidMiniaturizeNotification
  120. object: window];
  121. [notificationCenter addObserver: view
  122. selector: @selector (windowWillMiniaturize:)
  123. name: NSWindowWillMiniaturizeNotification
  124. object: window];
  125. [notificationCenter addObserver: view
  126. selector: @selector (windowDidDeminiaturize:)
  127. name: NSWindowDidDeminiaturizeNotification
  128. object: window];
  129. }
  130. auto alpha = component.getAlpha();
  131. if (alpha < 1.0f)
  132. setAlpha (alpha);
  133. setTitle (component.getName());
  134. getNativeRealtimeModifiers = []
  135. {
  136. if ([NSEvent respondsToSelector: @selector (modifierFlags)])
  137. NSViewComponentPeer::updateModifiers ([NSEvent modifierFlags]);
  138. return ModifierKeys::currentModifiers;
  139. };
  140. }
  141. ~NSViewComponentPeer() override
  142. {
  143. [notificationCenter removeObserver: view];
  144. setOwner (view, nullptr);
  145. if ([view superview] != nil)
  146. {
  147. redirectWillMoveToWindow (nullptr);
  148. [view removeFromSuperview];
  149. }
  150. if (! isSharedWindow)
  151. {
  152. setOwner (window, nullptr);
  153. [window setContentView: nil];
  154. [window close];
  155. [window release];
  156. }
  157. [view release];
  158. }
  159. //==============================================================================
  160. void* getNativeHandle() const override { return view; }
  161. void setVisible (bool shouldBeVisible) override
  162. {
  163. if (isSharedWindow)
  164. {
  165. if (shouldBeVisible)
  166. [view setHidden: false];
  167. else if ([window firstResponder] != view || ([window firstResponder] == view && [window makeFirstResponder: nil]))
  168. [view setHidden: true];
  169. }
  170. else
  171. {
  172. if (shouldBeVisible)
  173. {
  174. ++insideToFrontCall;
  175. [window orderFront: nil];
  176. --insideToFrontCall;
  177. handleBroughtToFront();
  178. }
  179. else
  180. {
  181. [window orderOut: nil];
  182. }
  183. }
  184. }
  185. void setTitle (const String& title) override
  186. {
  187. JUCE_AUTORELEASEPOOL
  188. {
  189. if (! isSharedWindow)
  190. [window setTitle: juceStringToNS (title)];
  191. }
  192. }
  193. bool setDocumentEditedStatus (bool edited) override
  194. {
  195. if (! hasNativeTitleBar())
  196. return false;
  197. [window setDocumentEdited: edited];
  198. return true;
  199. }
  200. void setRepresentedFile (const File& file) override
  201. {
  202. if (! isSharedWindow)
  203. {
  204. [window setRepresentedFilename: juceStringToNS (file != File()
  205. ? file.getFullPathName()
  206. : String())];
  207. windowRepresentsFile = (file != File());
  208. }
  209. }
  210. void setBounds (const Rectangle<int>& newBounds, bool isNowFullScreen) override
  211. {
  212. fullScreen = isNowFullScreen;
  213. auto r = makeNSRect (newBounds);
  214. auto oldViewSize = [view frame].size;
  215. if (isSharedWindow)
  216. {
  217. [view setFrame: r];
  218. }
  219. else
  220. {
  221. // Repaint behaviour of setFrame seemed to change in 10.11, and the drawing became synchronous,
  222. // causing performance issues. But sending an async update causes flickering in older versions,
  223. // hence this version check to use the old behaviour on pre 10.11 machines
  224. static bool isPre10_11 = SystemStats::getOperatingSystemType() <= SystemStats::MacOSX_10_10;
  225. [window setFrame: [window frameRectForContentRect: flippedScreenRect (r)]
  226. display: isPre10_11];
  227. }
  228. if (oldViewSize.width != r.size.width || oldViewSize.height != r.size.height)
  229. [view setNeedsDisplay: true];
  230. }
  231. Rectangle<int> getBounds (const bool global) const
  232. {
  233. auto r = [view frame];
  234. NSWindow* viewWindow = [view window];
  235. if (global && viewWindow != nil)
  236. {
  237. r = [[view superview] convertRect: r toView: nil];
  238. r = [viewWindow convertRectToScreen: r];
  239. r = flippedScreenRect (r);
  240. }
  241. return convertToRectInt (r);
  242. }
  243. Rectangle<int> getBounds() const override
  244. {
  245. return getBounds (! isSharedWindow);
  246. }
  247. Point<float> localToGlobal (Point<float> relativePosition) override
  248. {
  249. return relativePosition + getBounds (true).getPosition().toFloat();
  250. }
  251. using ComponentPeer::localToGlobal;
  252. Point<float> globalToLocal (Point<float> screenPosition) override
  253. {
  254. return screenPosition - getBounds (true).getPosition().toFloat();
  255. }
  256. using ComponentPeer::globalToLocal;
  257. void setAlpha (float newAlpha) override
  258. {
  259. if (isSharedWindow)
  260. [view setAlphaValue: (CGFloat) newAlpha];
  261. else
  262. [window setAlphaValue: (CGFloat) newAlpha];
  263. }
  264. void setMinimised (bool shouldBeMinimised) override
  265. {
  266. if (! isSharedWindow)
  267. {
  268. if (shouldBeMinimised)
  269. [window miniaturize: nil];
  270. else
  271. [window deminiaturize: nil];
  272. }
  273. }
  274. bool isMinimised() const override
  275. {
  276. return [window isMiniaturized];
  277. }
  278. void setFullScreen (bool shouldBeFullScreen) override
  279. {
  280. if (! isSharedWindow)
  281. {
  282. auto r = lastNonFullscreenBounds;
  283. if (isMinimised())
  284. setMinimised (false);
  285. if (fullScreen != shouldBeFullScreen)
  286. {
  287. if (shouldBeFullScreen && hasNativeTitleBar())
  288. {
  289. fullScreen = true;
  290. [window performZoom: nil];
  291. }
  292. else
  293. {
  294. if (shouldBeFullScreen)
  295. r = component.getParentMonitorArea();
  296. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  297. if (r != component.getBounds() && ! r.isEmpty())
  298. setBounds (ScalingHelpers::scaledScreenPosToUnscaled (component, r), shouldBeFullScreen);
  299. }
  300. }
  301. }
  302. }
  303. bool isFullScreen() const override
  304. {
  305. return fullScreen;
  306. }
  307. bool isKioskMode() const override
  308. {
  309. return isWindowInKioskMode || ComponentPeer::isKioskMode();
  310. }
  311. static bool isWindowAtPoint (NSWindow* w, NSPoint screenPoint)
  312. {
  313. if ([NSWindow respondsToSelector: @selector (windowNumberAtPoint:belowWindowWithWindowNumber:)])
  314. return [NSWindow windowNumberAtPoint: screenPoint belowWindowWithWindowNumber: 0] == [w windowNumber];
  315. return true;
  316. }
  317. bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
  318. {
  319. NSRect viewFrame = [view frame];
  320. if (! (isPositiveAndBelow (localPos.getX(), viewFrame.size.width)
  321. && isPositiveAndBelow (localPos.getY(), viewFrame.size.height)))
  322. return false;
  323. if (! SystemStats::isRunningInAppExtensionSandbox())
  324. {
  325. if (NSWindow* const viewWindow = [view window])
  326. {
  327. NSRect windowFrame = [viewWindow frame];
  328. NSPoint windowPoint = [view convertPoint: NSMakePoint (localPos.x, localPos.y) toView: nil];
  329. NSPoint screenPoint = NSMakePoint (windowFrame.origin.x + windowPoint.x,
  330. windowFrame.origin.y + windowPoint.y);
  331. if (! isWindowAtPoint (viewWindow, screenPoint))
  332. return false;
  333. }
  334. }
  335. NSView* v = [view hitTest: NSMakePoint (viewFrame.origin.x + localPos.getX(),
  336. viewFrame.origin.y + localPos.getY())];
  337. return trueIfInAChildWindow ? (v != nil)
  338. : (v == view);
  339. }
  340. BorderSize<int> getFrameSize() const override
  341. {
  342. BorderSize<int> b;
  343. if (! isSharedWindow)
  344. {
  345. NSRect v = [view convertRect: [view frame] toView: nil];
  346. NSRect w = [window frame];
  347. b.setTop ((int) v.origin.y);
  348. b.setBottom ((int) (w.size.height - (v.origin.y + v.size.height)));
  349. b.setLeft ((int) v.origin.x);
  350. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  351. }
  352. return b;
  353. }
  354. void updateFullscreenStatus()
  355. {
  356. if (hasNativeTitleBar())
  357. {
  358. isWindowInKioskMode = (([window styleMask] & NSWindowStyleMaskFullScreen) != 0);
  359. auto screen = getFrameSize().subtractedFrom (component.getParentMonitorArea());
  360. fullScreen = component.getScreenBounds().expanded (2, 2).contains (screen);
  361. }
  362. else
  363. {
  364. isWindowInKioskMode = false;
  365. }
  366. }
  367. bool hasNativeTitleBar() const
  368. {
  369. return (getStyleFlags() & windowHasTitleBar) != 0;
  370. }
  371. bool setAlwaysOnTop (bool alwaysOnTop) override
  372. {
  373. if (! isSharedWindow)
  374. {
  375. [window setLevel: alwaysOnTop ? ((getStyleFlags() & windowIsTemporary) != 0 ? NSPopUpMenuWindowLevel
  376. : NSFloatingWindowLevel)
  377. : NSNormalWindowLevel];
  378. isAlwaysOnTop = alwaysOnTop;
  379. }
  380. return true;
  381. }
  382. void toFront (bool makeActiveWindow) override
  383. {
  384. if (isSharedWindow)
  385. {
  386. NSView* superview = [view superview];
  387. NSMutableArray* subviews = [NSMutableArray arrayWithArray: [superview subviews]];
  388. const auto isFrontmost = [[subviews lastObject] isEqual: view];
  389. if (! isFrontmost)
  390. {
  391. [view retain];
  392. [subviews removeObject: view];
  393. [subviews addObject: view];
  394. [superview setSubviews: subviews];
  395. [view release];
  396. }
  397. }
  398. if (window != nil && component.isVisible())
  399. {
  400. ++insideToFrontCall;
  401. if (makeActiveWindow)
  402. [window makeKeyAndOrderFront: nil];
  403. else
  404. [window orderFront: nil];
  405. if (insideToFrontCall <= 1)
  406. {
  407. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  408. handleBroughtToFront();
  409. }
  410. --insideToFrontCall;
  411. }
  412. }
  413. void toBehind (ComponentPeer* other) override
  414. {
  415. if (auto* otherPeer = dynamic_cast<NSViewComponentPeer*> (other))
  416. {
  417. if (isSharedWindow)
  418. {
  419. NSView* superview = [view superview];
  420. NSMutableArray* subviews = [NSMutableArray arrayWithArray: [superview subviews]];
  421. const auto otherViewIndex = [subviews indexOfObject: otherPeer->view];
  422. if (otherViewIndex == NSNotFound)
  423. return;
  424. const auto isBehind = [subviews indexOfObject: view] < otherViewIndex;
  425. if (! isBehind)
  426. {
  427. [view retain];
  428. [subviews removeObject: view];
  429. [subviews insertObject: view
  430. atIndex: otherViewIndex];
  431. [superview setSubviews: subviews];
  432. [view release];
  433. }
  434. }
  435. else if (component.isVisible())
  436. {
  437. [window orderWindow: NSWindowBelow
  438. relativeTo: [otherPeer->window windowNumber]];
  439. }
  440. }
  441. else
  442. {
  443. jassertfalse; // wrong type of window?
  444. }
  445. }
  446. void setIcon (const Image& newIcon) override
  447. {
  448. if (! isSharedWindow)
  449. {
  450. // need to set a dummy represented file here to show the file icon (which we then set to the new icon)
  451. if (! windowRepresentsFile)
  452. [window setRepresentedFilename:juceStringToNS (" ")]; // can't just use an empty string for some reason...
  453. [[window standardWindowButton:NSWindowDocumentIconButton] setImage:imageToNSImage (newIcon)];
  454. }
  455. }
  456. StringArray getAvailableRenderingEngines() override
  457. {
  458. StringArray s ("Software Renderer");
  459. #if USE_COREGRAPHICS_RENDERING
  460. s.add ("CoreGraphics Renderer");
  461. #endif
  462. return s;
  463. }
  464. int getCurrentRenderingEngine() const override
  465. {
  466. return usingCoreGraphics ? 1 : 0;
  467. }
  468. void setCurrentRenderingEngine (int index) override
  469. {
  470. #if USE_COREGRAPHICS_RENDERING
  471. if (usingCoreGraphics != (index > 0))
  472. {
  473. usingCoreGraphics = index > 0;
  474. [view setNeedsDisplay: true];
  475. }
  476. #else
  477. ignoreUnused (index);
  478. #endif
  479. }
  480. void redirectMouseDown (NSEvent* ev)
  481. {
  482. if (! Process::isForegroundProcess())
  483. Process::makeForegroundProcess();
  484. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  485. sendMouseEvent (ev);
  486. }
  487. void redirectMouseUp (NSEvent* ev)
  488. {
  489. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  490. sendMouseEvent (ev);
  491. showArrowCursorIfNeeded();
  492. }
  493. void redirectMouseDrag (NSEvent* ev)
  494. {
  495. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  496. sendMouseEvent (ev);
  497. }
  498. void redirectMouseMove (NSEvent* ev)
  499. {
  500. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons();
  501. NSPoint windowPos = [ev locationInWindow];
  502. NSPoint screenPos = [[ev window] convertRectToScreen: NSMakeRect (windowPos.x, windowPos.y, 1.0f, 1.0f)].origin;
  503. if (isWindowAtPoint ([ev window], screenPos))
  504. sendMouseEvent (ev);
  505. else
  506. // moved into another window which overlaps this one, so trigger an exit
  507. handleMouseEvent (MouseInputSource::InputSourceType::mouse, MouseInputSource::offscreenMousePos, ModifierKeys::currentModifiers,
  508. getMousePressure (ev), MouseInputSource::invalidOrientation, getMouseTime (ev));
  509. showArrowCursorIfNeeded();
  510. }
  511. void redirectMouseEnter (NSEvent* ev)
  512. {
  513. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  514. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons();
  515. sendMouseEvent (ev);
  516. }
  517. void redirectMouseExit (NSEvent* ev)
  518. {
  519. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons();
  520. sendMouseEvent (ev);
  521. }
  522. static float checkDeviceDeltaReturnValue (float v) noexcept
  523. {
  524. // (deviceDeltaX can fail and return NaN, so need to sanity-check the result)
  525. v *= 0.5f / 256.0f;
  526. return (v > -1000.0f && v < 1000.0f) ? v : 0.0f;
  527. }
  528. void redirectMouseWheel (NSEvent* ev)
  529. {
  530. updateModifiers (ev);
  531. MouseWheelDetails wheel;
  532. wheel.deltaX = 0;
  533. wheel.deltaY = 0;
  534. wheel.isReversed = false;
  535. wheel.isSmooth = false;
  536. wheel.isInertial = false;
  537. @try
  538. {
  539. if ([ev respondsToSelector: @selector (isDirectionInvertedFromDevice)])
  540. wheel.isReversed = [ev isDirectionInvertedFromDevice];
  541. wheel.isInertial = ([ev momentumPhase] != NSEventPhaseNone);
  542. if ([ev respondsToSelector: @selector (hasPreciseScrollingDeltas)])
  543. {
  544. if ([ev hasPreciseScrollingDeltas])
  545. {
  546. const float scale = 0.5f / 256.0f;
  547. wheel.deltaX = scale * (float) [ev scrollingDeltaX];
  548. wheel.deltaY = scale * (float) [ev scrollingDeltaY];
  549. wheel.isSmooth = true;
  550. }
  551. }
  552. else if ([ev respondsToSelector: @selector (deviceDeltaX)])
  553. {
  554. wheel.deltaX = checkDeviceDeltaReturnValue ([ev deviceDeltaX]);
  555. wheel.deltaY = checkDeviceDeltaReturnValue ([ev deviceDeltaY]);
  556. }
  557. }
  558. @catch (...)
  559. {}
  560. if (wheel.deltaX == 0.0f && wheel.deltaY == 0.0f)
  561. {
  562. const float scale = 10.0f / 256.0f;
  563. wheel.deltaX = scale * (float) [ev deltaX];
  564. wheel.deltaY = scale * (float) [ev deltaY];
  565. }
  566. handleMouseWheel (MouseInputSource::InputSourceType::mouse, getMousePos (ev, view), getMouseTime (ev), wheel);
  567. }
  568. void redirectMagnify (NSEvent* ev)
  569. {
  570. const float invScale = 1.0f - (float) [ev magnification];
  571. if (invScale > 0.0f)
  572. handleMagnifyGesture (MouseInputSource::InputSourceType::mouse, getMousePos (ev, view), getMouseTime (ev), 1.0f / invScale);
  573. }
  574. void redirectCopy (NSObject*) { handleKeyPress (KeyPress ('c', ModifierKeys (ModifierKeys::commandModifier), 'c')); }
  575. void redirectPaste (NSObject*) { handleKeyPress (KeyPress ('v', ModifierKeys (ModifierKeys::commandModifier), 'v')); }
  576. void redirectCut (NSObject*) { handleKeyPress (KeyPress ('x', ModifierKeys (ModifierKeys::commandModifier), 'x')); }
  577. void redirectSelectAll (NSObject*) { handleKeyPress (KeyPress ('a', ModifierKeys (ModifierKeys::commandModifier), 'a')); }
  578. void redirectWillMoveToWindow (NSWindow* newWindow)
  579. {
  580. if (auto* currentWindow = [view window])
  581. {
  582. [notificationCenter removeObserver: view
  583. name: NSWindowDidMoveNotification
  584. object: currentWindow];
  585. [notificationCenter removeObserver: view
  586. name: NSWindowWillMiniaturizeNotification
  587. object: currentWindow];
  588. #if JUCE_COREGRAPHICS_DRAW_ASYNC
  589. [notificationCenter removeObserver: view
  590. name: NSWindowDidBecomeKeyNotification
  591. object: currentWindow];
  592. #endif
  593. }
  594. if (isSharedWindow && [view window] == window && newWindow == nullptr)
  595. {
  596. if (auto* comp = safeComponent.get())
  597. comp->setVisible (false);
  598. }
  599. }
  600. void sendMouseEvent (NSEvent* ev)
  601. {
  602. updateModifiers (ev);
  603. handleMouseEvent (MouseInputSource::InputSourceType::mouse, getMousePos (ev, view), ModifierKeys::currentModifiers,
  604. getMousePressure (ev), MouseInputSource::invalidOrientation, getMouseTime (ev));
  605. }
  606. bool handleKeyEvent (NSEvent* ev, bool isKeyDown)
  607. {
  608. auto unicode = nsStringToJuce ([ev characters]);
  609. auto keyCode = getKeyCodeFromEvent (ev);
  610. #if JUCE_DEBUG_KEYCODES
  611. DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  612. auto unmodified = nsStringToJuce ([ev charactersIgnoringModifiers]);
  613. DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  614. #endif
  615. if (keyCode != 0 || unicode.isNotEmpty())
  616. {
  617. if (isKeyDown)
  618. {
  619. bool used = false;
  620. for (auto u = unicode.getCharPointer(); ! u.isEmpty();)
  621. {
  622. auto textCharacter = u.getAndAdvance();
  623. switch (keyCode)
  624. {
  625. case NSLeftArrowFunctionKey:
  626. case NSRightArrowFunctionKey:
  627. case NSUpArrowFunctionKey:
  628. case NSDownArrowFunctionKey:
  629. case NSPageUpFunctionKey:
  630. case NSPageDownFunctionKey:
  631. case NSEndFunctionKey:
  632. case NSHomeFunctionKey:
  633. case NSDeleteFunctionKey:
  634. textCharacter = 0;
  635. break; // (these all seem to generate unwanted garbage unicode strings)
  636. default:
  637. if (([ev modifierFlags] & NSEventModifierFlagCommand) != 0
  638. || (keyCode >= NSF1FunctionKey && keyCode <= NSF35FunctionKey))
  639. textCharacter = 0;
  640. break;
  641. }
  642. used = handleKeyUpOrDown (true) || used;
  643. used = handleKeyPress (keyCode, textCharacter) || used;
  644. }
  645. return used;
  646. }
  647. if (handleKeyUpOrDown (false))
  648. return true;
  649. }
  650. return false;
  651. }
  652. bool redirectKeyDown (NSEvent* ev)
  653. {
  654. // (need to retain this in case a modal loop runs in handleKeyEvent and
  655. // our event object gets lost)
  656. const NSUniquePtr<NSEvent> r ([ev retain]);
  657. updateKeysDown (ev, true);
  658. bool used = handleKeyEvent (ev, true);
  659. if (([ev modifierFlags] & NSEventModifierFlagCommand) != 0)
  660. {
  661. // for command keys, the key-up event is thrown away, so simulate one..
  662. updateKeysDown (ev, false);
  663. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  664. }
  665. // (If we're running modally, don't allow unused keystrokes to be passed
  666. // along to other blocked views..)
  667. if (Component::getCurrentlyModalComponent() != nullptr)
  668. used = true;
  669. return used;
  670. }
  671. bool redirectKeyUp (NSEvent* ev)
  672. {
  673. updateKeysDown (ev, false);
  674. return handleKeyEvent (ev, false)
  675. || Component::getCurrentlyModalComponent() != nullptr;
  676. }
  677. void redirectModKeyChange (NSEvent* ev)
  678. {
  679. // (need to retain this in case a modal loop runs and our event object gets lost)
  680. const NSUniquePtr<NSEvent> r ([ev retain]);
  681. keysCurrentlyDown.clear();
  682. handleKeyUpOrDown (true);
  683. updateModifiers (ev);
  684. handleModifierKeysChange();
  685. }
  686. //==============================================================================
  687. void drawRect (NSRect r)
  688. {
  689. if (r.size.width < 1.0f || r.size.height < 1.0f)
  690. return;
  691. auto cg = (CGContextRef) [[NSGraphicsContext currentContext]
  692. #if (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10)
  693. CGContext];
  694. #else
  695. graphicsPort];
  696. #endif
  697. if (! component.isOpaque())
  698. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  699. float displayScale = 1.0f;
  700. NSScreen* screen = [[view window] screen];
  701. if ([screen respondsToSelector: @selector (backingScaleFactor)])
  702. displayScale = (float) screen.backingScaleFactor;
  703. auto invalidateTransparentWindowShadow = [this]
  704. {
  705. // transparent NSWindows with a drop-shadow need to redraw their shadow when the content
  706. // changes to avoid stale shadows being drawn behind the window
  707. if (! isSharedWindow && ! [window isOpaque] && [window hasShadow])
  708. [window invalidateShadow];
  709. };
  710. #if USE_COREGRAPHICS_RENDERING && JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS
  711. // This option invokes a separate paint call for each rectangle of the clip region.
  712. // It's a long story, but this is a basically a workaround for a CGContext not having
  713. // a way of finding whether a rectangle falls within its clip region
  714. if (usingCoreGraphics)
  715. {
  716. const NSRect* rects = nullptr;
  717. NSInteger numRects = 0;
  718. [view getRectsBeingDrawn: &rects count: &numRects];
  719. if (numRects > 1)
  720. {
  721. for (int i = 0; i < numRects; ++i)
  722. {
  723. NSRect rect = rects[i];
  724. CGContextSaveGState (cg);
  725. CGContextClipToRect (cg, CGRectMake (rect.origin.x, rect.origin.y, rect.size.width, rect.size.height));
  726. drawRect (cg, rect, displayScale);
  727. CGContextRestoreGState (cg);
  728. }
  729. invalidateTransparentWindowShadow();
  730. return;
  731. }
  732. }
  733. #endif
  734. drawRect (cg, r, displayScale);
  735. invalidateTransparentWindowShadow();
  736. }
  737. void drawRect (CGContextRef cg, NSRect r, float displayScale)
  738. {
  739. #if USE_COREGRAPHICS_RENDERING
  740. if (usingCoreGraphics)
  741. {
  742. const auto height = getComponent().getHeight();
  743. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, height));
  744. CoreGraphicsContext context (cg, (float) height);
  745. handlePaint (context);
  746. }
  747. else
  748. #endif
  749. {
  750. const Point<int> offset (-roundToInt (r.origin.x), -roundToInt (r.origin.y));
  751. auto clipW = (int) (r.size.width + 0.5f);
  752. auto clipH = (int) (r.size.height + 0.5f);
  753. RectangleList<int> clip;
  754. getClipRects (clip, offset, clipW, clipH);
  755. if (! clip.isEmpty())
  756. {
  757. Image temp (component.isOpaque() ? Image::RGB : Image::ARGB,
  758. roundToInt (clipW * displayScale),
  759. roundToInt (clipH * displayScale),
  760. ! component.isOpaque());
  761. {
  762. auto intScale = roundToInt (displayScale);
  763. if (intScale != 1)
  764. clip.scaleAll (intScale);
  765. auto context = component.getLookAndFeel()
  766. .createGraphicsContext (temp, offset * intScale, clip);
  767. if (intScale != 1)
  768. context->addTransform (AffineTransform::scale (displayScale));
  769. handlePaint (*context);
  770. }
  771. detail::ColorSpacePtr colourSpace { CGColorSpaceCreateWithName (kCGColorSpaceSRGB) };
  772. CGImageRef image = juce_createCoreGraphicsImage (temp, colourSpace.get(), false);
  773. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, r.origin.x, r.origin.y + clipH));
  774. CGContextDrawImage (cg, CGRectMake (0.0f, 0.0f, clipW, clipH), image);
  775. CGImageRelease (image);
  776. }
  777. }
  778. }
  779. void repaint (const Rectangle<int>& area) override
  780. {
  781. // In 10.11 changes were made to the way the OS handles repaint regions, and it seems that it can
  782. // no longer be trusted to coalesce all the regions, or to even remember them all without losing
  783. // a few when there's a lot of activity.
  784. // As a work around for this, we use a RectangleList to do our own coalescing of regions before
  785. // asynchronously asking the OS to repaint them.
  786. deferredRepaints.add ((float) area.getX(), (float) area.getY(),
  787. (float) area.getWidth(), (float) area.getHeight());
  788. if (isTimerRunning())
  789. return;
  790. auto now = Time::getMillisecondCounter();
  791. auto msSinceLastRepaint = (lastRepaintTime >= now) ? now - lastRepaintTime
  792. : (std::numeric_limits<uint32>::max() - lastRepaintTime) + now;
  793. static uint32 minimumRepaintInterval = 1000 / 30; // 30fps
  794. // When windows are being resized, artificially throttling high-frequency repaints helps
  795. // to stop the event queue getting clogged, and keeps everything working smoothly.
  796. // For some reason Logic also needs this throttling to record parameter events correctly.
  797. if (msSinceLastRepaint < minimumRepaintInterval && shouldThrottleRepaint())
  798. {
  799. startTimer (static_cast<int> (minimumRepaintInterval - msSinceLastRepaint));
  800. return;
  801. }
  802. setNeedsDisplayRectangles();
  803. }
  804. static bool shouldThrottleRepaint()
  805. {
  806. return areAnyWindowsInLiveResize() || ! JUCEApplication::isStandaloneApp();
  807. }
  808. void timerCallback() override
  809. {
  810. setNeedsDisplayRectangles();
  811. stopTimer();
  812. }
  813. void setNeedsDisplayRectangles()
  814. {
  815. for (auto& i : deferredRepaints)
  816. [view setNeedsDisplayInRect: makeNSRect (i)];
  817. lastRepaintTime = Time::getMillisecondCounter();
  818. deferredRepaints.clear();
  819. }
  820. void performAnyPendingRepaintsNow() override
  821. {
  822. [view displayIfNeeded];
  823. }
  824. static bool areAnyWindowsInLiveResize() noexcept
  825. {
  826. for (NSWindow* w in [NSApp windows])
  827. if ([w inLiveResize])
  828. return true;
  829. return false;
  830. }
  831. //==============================================================================
  832. bool isBlockedByModalComponent()
  833. {
  834. if (auto* modal = Component::getCurrentlyModalComponent())
  835. {
  836. if (insideToFrontCall == 0
  837. && (! getComponent().isParentOf (modal))
  838. && getComponent().isCurrentlyBlockedByAnotherModalComponent())
  839. {
  840. return true;
  841. }
  842. }
  843. return false;
  844. }
  845. void sendModalInputAttemptIfBlocked()
  846. {
  847. if (isBlockedByModalComponent())
  848. if (auto* modal = Component::getCurrentlyModalComponent())
  849. modal->inputAttemptWhenModal();
  850. }
  851. bool canBecomeKeyWindow()
  852. {
  853. return component.isVisible() && (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0;
  854. }
  855. bool canBecomeMainWindow()
  856. {
  857. return component.isVisible() && dynamic_cast<ResizableWindow*> (&component) != nullptr;
  858. }
  859. bool worksWhenModal() const
  860. {
  861. // In plugins, the host could put our plugin window inside a modal window, so this
  862. // allows us to successfully open other popups. Feels like there could be edge-case
  863. // problems caused by this, so let us know if you spot any issues..
  864. return ! JUCEApplication::isStandaloneApp();
  865. }
  866. void becomeKeyWindow()
  867. {
  868. handleBroughtToFront();
  869. grabFocus();
  870. }
  871. void resignKeyWindow()
  872. {
  873. viewFocusLoss();
  874. }
  875. bool windowShouldClose()
  876. {
  877. if (! isValidPeer (this))
  878. return YES;
  879. handleUserClosingWindow();
  880. return NO;
  881. }
  882. void redirectMovedOrResized()
  883. {
  884. updateFullscreenStatus();
  885. handleMovedOrResized();
  886. }
  887. void viewMovedToWindow()
  888. {
  889. if (isSharedWindow)
  890. {
  891. auto newWindow = [view window];
  892. bool shouldSetVisible = (window == nullptr && newWindow != nullptr);
  893. window = newWindow;
  894. if (shouldSetVisible)
  895. getComponent().setVisible (true);
  896. }
  897. if (auto* currentWindow = [view window])
  898. {
  899. [notificationCenter addObserver: view
  900. selector: dismissModalsSelector
  901. name: NSWindowDidMoveNotification
  902. object: currentWindow];
  903. [notificationCenter addObserver: view
  904. selector: dismissModalsSelector
  905. name: NSWindowWillMiniaturizeNotification
  906. object: currentWindow];
  907. #if JUCE_COREGRAPHICS_DRAW_ASYNC
  908. [notificationCenter addObserver: view
  909. selector: becomeKeySelector
  910. name: NSWindowDidBecomeKeyNotification
  911. object: currentWindow];
  912. #endif
  913. }
  914. }
  915. void dismissModals()
  916. {
  917. if (hasNativeTitleBar() || isSharedWindow)
  918. sendModalInputAttemptIfBlocked();
  919. }
  920. void becomeKey()
  921. {
  922. component.repaint();
  923. }
  924. void liveResizingStart()
  925. {
  926. if (constrainer == nullptr)
  927. return;
  928. constrainer->resizeStart();
  929. isFirstLiveResize = true;
  930. setFullScreenSizeConstraints (*constrainer);
  931. }
  932. void liveResizingEnd()
  933. {
  934. if (constrainer != nullptr)
  935. constrainer->resizeEnd();
  936. }
  937. NSRect constrainRect (const NSRect r)
  938. {
  939. if (constrainer == nullptr || isKioskMode())
  940. return r;
  941. const auto scale = getComponent().getDesktopScaleFactor();
  942. auto pos = ScalingHelpers::unscaledScreenPosToScaled (scale, convertToRectInt (flippedScreenRect (r)));
  943. const auto original = ScalingHelpers::unscaledScreenPosToScaled (scale, convertToRectInt (flippedScreenRect ([window frame])));
  944. const auto screenBounds = Desktop::getInstance().getDisplays().getTotalBounds (true);
  945. const bool inLiveResize = [window inLiveResize];
  946. if (! inLiveResize || isFirstLiveResize)
  947. {
  948. isFirstLiveResize = false;
  949. isStretchingTop = (pos.getY() != original.getY() && pos.getBottom() == original.getBottom());
  950. isStretchingLeft = (pos.getX() != original.getX() && pos.getRight() == original.getRight());
  951. isStretchingBottom = (pos.getY() == original.getY() && pos.getBottom() != original.getBottom());
  952. isStretchingRight = (pos.getX() == original.getX() && pos.getRight() != original.getRight());
  953. }
  954. constrainer->checkBounds (pos, original, screenBounds,
  955. isStretchingTop, isStretchingLeft, isStretchingBottom, isStretchingRight);
  956. return flippedScreenRect (makeNSRect (ScalingHelpers::scaledScreenPosToUnscaled (scale, pos)));
  957. }
  958. static void showArrowCursorIfNeeded()
  959. {
  960. auto& desktop = Desktop::getInstance();
  961. auto mouse = desktop.getMainMouseSource();
  962. if (mouse.getComponentUnderMouse() == nullptr
  963. && desktop.findComponentAt (mouse.getScreenPosition().roundToInt()) == nullptr)
  964. {
  965. [[NSCursor arrowCursor] set];
  966. }
  967. }
  968. static void updateModifiers (NSEvent* e)
  969. {
  970. updateModifiers ([e modifierFlags]);
  971. }
  972. static void updateModifiers (const NSUInteger flags)
  973. {
  974. int m = 0;
  975. if ((flags & NSEventModifierFlagShift) != 0) m |= ModifierKeys::shiftModifier;
  976. if ((flags & NSEventModifierFlagControl) != 0) m |= ModifierKeys::ctrlModifier;
  977. if ((flags & NSEventModifierFlagOption) != 0) m |= ModifierKeys::altModifier;
  978. if ((flags & NSEventModifierFlagCommand) != 0) m |= ModifierKeys::commandModifier;
  979. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withOnlyMouseButtons().withFlags (m);
  980. }
  981. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  982. {
  983. updateModifiers (ev);
  984. if (auto keyCode = getKeyCodeFromEvent (ev))
  985. {
  986. if (isKeyDown)
  987. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  988. else
  989. keysCurrentlyDown.removeFirstMatchingValue (keyCode);
  990. }
  991. }
  992. static int getKeyCodeFromEvent (NSEvent* ev)
  993. {
  994. // Unfortunately, charactersIgnoringModifiers does not ignore the shift key.
  995. // Using [ev keyCode] is not a solution either as this will,
  996. // for example, return VK_KEY_Y if the key is pressed which
  997. // is typically located at the Y key position on a QWERTY
  998. // keyboard. However, on international keyboards this might not
  999. // be the key labeled Y (for example, on German keyboards this key
  1000. // has a Z label). Therefore, we need to query the current keyboard
  1001. // layout to figure out what character the key would have produced
  1002. // if the shift key was not pressed
  1003. String unmodified;
  1004. #if JUCE_SUPPORT_CARBON
  1005. if (auto currentKeyboard = CFUniquePtr<TISInputSourceRef> (TISCopyCurrentKeyboardInputSource()))
  1006. {
  1007. if (auto layoutData = (CFDataRef) TISGetInputSourceProperty (currentKeyboard,
  1008. kTISPropertyUnicodeKeyLayoutData))
  1009. {
  1010. if (auto* layoutPtr = (const UCKeyboardLayout*) CFDataGetBytePtr (layoutData))
  1011. {
  1012. UInt32 keysDown = 0;
  1013. UniChar buffer[4];
  1014. UniCharCount actual;
  1015. if (UCKeyTranslate (layoutPtr, [ev keyCode], kUCKeyActionDown, 0, LMGetKbdType(),
  1016. kUCKeyTranslateNoDeadKeysBit, &keysDown, sizeof (buffer) / sizeof (UniChar),
  1017. &actual, buffer) == 0)
  1018. unmodified = String (CharPointer_UTF16 (reinterpret_cast<CharPointer_UTF16::CharType*> (buffer)), 4);
  1019. }
  1020. }
  1021. }
  1022. // did the above layout conversion fail
  1023. if (unmodified.isEmpty())
  1024. #endif
  1025. {
  1026. unmodified = nsStringToJuce ([ev charactersIgnoringModifiers]);
  1027. }
  1028. auto keyCode = (int) unmodified[0];
  1029. if (keyCode == 0x19) // (backwards-tab)
  1030. keyCode = '\t';
  1031. else if (keyCode == 0x03) // (enter)
  1032. keyCode = '\r';
  1033. else
  1034. keyCode = (int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  1035. if (([ev modifierFlags] & NSEventModifierFlagNumericPad) != 0)
  1036. {
  1037. const int numPadConversions[] = { '0', KeyPress::numberPad0, '1', KeyPress::numberPad1,
  1038. '2', KeyPress::numberPad2, '3', KeyPress::numberPad3,
  1039. '4', KeyPress::numberPad4, '5', KeyPress::numberPad5,
  1040. '6', KeyPress::numberPad6, '7', KeyPress::numberPad7,
  1041. '8', KeyPress::numberPad8, '9', KeyPress::numberPad9,
  1042. '+', KeyPress::numberPadAdd, '-', KeyPress::numberPadSubtract,
  1043. '*', KeyPress::numberPadMultiply, '/', KeyPress::numberPadDivide,
  1044. '.', KeyPress::numberPadDecimalPoint,
  1045. ',', KeyPress::numberPadDecimalPoint, // (to deal with non-english kbds)
  1046. '=', KeyPress::numberPadEquals };
  1047. for (int i = 0; i < numElementsInArray (numPadConversions); i += 2)
  1048. if (keyCode == numPadConversions [i])
  1049. keyCode = numPadConversions [i + 1];
  1050. }
  1051. return keyCode;
  1052. }
  1053. static int64 getMouseTime (NSEvent* e) noexcept
  1054. {
  1055. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  1056. + (int64) ([e timestamp] * 1000.0);
  1057. }
  1058. static float getMousePressure (NSEvent* e) noexcept
  1059. {
  1060. @try
  1061. {
  1062. if (e.type != NSEventTypeMouseEntered && e.type != NSEventTypeMouseExited)
  1063. return (float) e.pressure;
  1064. }
  1065. @catch (NSException* e) {}
  1066. @finally {}
  1067. return 0.0f;
  1068. }
  1069. static Point<float> getMousePos (NSEvent* e, NSView* view)
  1070. {
  1071. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  1072. return { (float) p.x, (float) p.y };
  1073. }
  1074. static int getModifierForButtonNumber (const NSInteger num)
  1075. {
  1076. return num == 0 ? ModifierKeys::leftButtonModifier
  1077. : (num == 1 ? ModifierKeys::rightButtonModifier
  1078. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  1079. }
  1080. static unsigned int getNSWindowStyleMask (const int flags) noexcept
  1081. {
  1082. unsigned int style = (flags & windowHasTitleBar) != 0 ? NSWindowStyleMaskTitled
  1083. : NSWindowStyleMaskBorderless;
  1084. if ((flags & windowHasMinimiseButton) != 0) style |= NSWindowStyleMaskMiniaturizable;
  1085. if ((flags & windowHasCloseButton) != 0) style |= NSWindowStyleMaskClosable;
  1086. if ((flags & windowIsResizable) != 0) style |= NSWindowStyleMaskResizable;
  1087. return style;
  1088. }
  1089. static NSArray* getSupportedDragTypes()
  1090. {
  1091. const auto type =
  1092. #if defined (MAC_OS_X_VERSION_10_13) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_13
  1093. NSPasteboardTypeFileURL;
  1094. #else
  1095. kUTTypeFileURL;
  1096. #endif
  1097. return [NSArray arrayWithObjects: (NSString*) type, (NSString*) kPasteboardTypeFileURLPromise, NSPasteboardTypeString, nil];
  1098. }
  1099. BOOL sendDragCallback (const int type, id <NSDraggingInfo> sender)
  1100. {
  1101. NSPasteboard* pasteboard = [sender draggingPasteboard];
  1102. NSString* contentType = [pasteboard availableTypeFromArray: getSupportedDragTypes()];
  1103. if (contentType == nil)
  1104. return false;
  1105. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  1106. ComponentPeer::DragInfo dragInfo;
  1107. dragInfo.position.setXY ((int) p.x, (int) p.y);
  1108. if (contentType == NSPasteboardTypeString)
  1109. dragInfo.text = nsStringToJuce ([pasteboard stringForType: NSPasteboardTypeString]);
  1110. else
  1111. dragInfo.files = getDroppedFiles (pasteboard, contentType);
  1112. if (! dragInfo.isEmpty())
  1113. {
  1114. switch (type)
  1115. {
  1116. case 0: return handleDragMove (dragInfo);
  1117. case 1: return handleDragExit (dragInfo);
  1118. case 2: return handleDragDrop (dragInfo);
  1119. default: jassertfalse; break;
  1120. }
  1121. }
  1122. return false;
  1123. }
  1124. StringArray getDroppedFiles (NSPasteboard* pasteboard, NSString* contentType)
  1125. {
  1126. StringArray files;
  1127. NSString* iTunesPasteboardType = nsStringLiteral ("CorePasteboardFlavorType 0x6974756E"); // 'itun'
  1128. if ([contentType isEqualToString: (NSString*) kPasteboardTypeFileURLPromise]
  1129. && [[pasteboard types] containsObject: iTunesPasteboardType])
  1130. {
  1131. id list = [pasteboard propertyListForType: iTunesPasteboardType];
  1132. if ([list isKindOfClass: [NSDictionary class]])
  1133. {
  1134. NSDictionary* iTunesDictionary = (NSDictionary*) list;
  1135. NSArray* tracks = [iTunesDictionary valueForKey: nsStringLiteral ("Tracks")];
  1136. NSEnumerator* enumerator = [tracks objectEnumerator];
  1137. NSDictionary* track;
  1138. while ((track = [enumerator nextObject]) != nil)
  1139. {
  1140. if (id value = [track valueForKey: nsStringLiteral ("Location")])
  1141. {
  1142. NSURL* url = [NSURL URLWithString: value];
  1143. if ([url isFileURL])
  1144. files.add (nsStringToJuce ([url path]));
  1145. }
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. NSArray* items = [pasteboard readObjectsForClasses:@[[NSURL class]] options: nil];
  1152. for (unsigned int i = 0; i < [items count]; ++i)
  1153. {
  1154. NSURL* url = [items objectAtIndex: i];
  1155. if ([url isFileURL])
  1156. files.add (nsStringToJuce ([url path]));
  1157. }
  1158. }
  1159. return files;
  1160. }
  1161. //==============================================================================
  1162. void viewFocusGain()
  1163. {
  1164. if (currentlyFocusedPeer != this)
  1165. {
  1166. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  1167. currentlyFocusedPeer->handleFocusLoss();
  1168. currentlyFocusedPeer = this;
  1169. handleFocusGain();
  1170. }
  1171. }
  1172. void viewFocusLoss()
  1173. {
  1174. if (currentlyFocusedPeer == this)
  1175. {
  1176. currentlyFocusedPeer = nullptr;
  1177. handleFocusLoss();
  1178. }
  1179. }
  1180. bool isFocused() const override
  1181. {
  1182. return (isSharedWindow || ! JUCEApplication::isStandaloneApp())
  1183. ? this == currentlyFocusedPeer
  1184. : [window isKeyWindow];
  1185. }
  1186. void grabFocus() override
  1187. {
  1188. if (window != nil && [window canBecomeKeyWindow])
  1189. {
  1190. [window makeKeyWindow];
  1191. [window makeFirstResponder: view];
  1192. viewFocusGain();
  1193. }
  1194. }
  1195. void textInputRequired (Point<int>, TextInputTarget&) override {}
  1196. void resetWindowPresentation()
  1197. {
  1198. if (hasNativeTitleBar())
  1199. {
  1200. [window setStyleMask: (NSViewComponentPeer::getNSWindowStyleMask (getStyleFlags()))];
  1201. setTitle (getComponent().getName()); // required to force the OS to update the title
  1202. }
  1203. [NSApp setPresentationOptions: NSApplicationPresentationDefault];
  1204. }
  1205. //==============================================================================
  1206. NSWindow* window = nil;
  1207. NSView* view = nil;
  1208. WeakReference<Component> safeComponent;
  1209. bool isSharedWindow = false, fullScreen = false;
  1210. bool isWindowInKioskMode = false;
  1211. #if USE_COREGRAPHICS_RENDERING
  1212. bool usingCoreGraphics = true;
  1213. #else
  1214. bool usingCoreGraphics = false;
  1215. #endif
  1216. bool isZooming = false, isFirstLiveResize = false, textWasInserted = false;
  1217. bool isStretchingTop = false, isStretchingLeft = false, isStretchingBottom = false, isStretchingRight = false;
  1218. bool windowRepresentsFile = false;
  1219. bool isAlwaysOnTop = false, wasAlwaysOnTop = false;
  1220. String stringBeingComposed;
  1221. NSNotificationCenter* notificationCenter = nil;
  1222. RectangleList<float> deferredRepaints;
  1223. uint32 lastRepaintTime;
  1224. static ComponentPeer* currentlyFocusedPeer;
  1225. static Array<int> keysCurrentlyDown;
  1226. static int insideToFrontCall;
  1227. static const SEL dismissModalsSelector;
  1228. static const SEL frameChangedSelector;
  1229. static const SEL asyncMouseDownSelector;
  1230. static const SEL asyncMouseUpSelector;
  1231. static const SEL becomeKeySelector;
  1232. private:
  1233. static NSView* createViewInstance();
  1234. static NSWindow* createWindowInstance();
  1235. static void setOwner (id viewOrWindow, NSViewComponentPeer* newOwner)
  1236. {
  1237. object_setInstanceVariable (viewOrWindow, "owner", newOwner);
  1238. }
  1239. void getClipRects (RectangleList<int>& clip, Point<int> offset, int clipW, int clipH)
  1240. {
  1241. const NSRect* rects = nullptr;
  1242. NSInteger numRects = 0;
  1243. [view getRectsBeingDrawn: &rects count: &numRects];
  1244. const Rectangle<int> clipBounds (clipW, clipH);
  1245. clip.ensureStorageAllocated ((int) numRects);
  1246. for (int i = 0; i < numRects; ++i)
  1247. clip.addWithoutMerging (clipBounds.getIntersection (Rectangle<int> (roundToInt (rects[i].origin.x) + offset.x,
  1248. roundToInt (rects[i].origin.y) + offset.y,
  1249. roundToInt (rects[i].size.width),
  1250. roundToInt (rects[i].size.height))));
  1251. }
  1252. static void appFocusChanged()
  1253. {
  1254. keysCurrentlyDown.clear();
  1255. if (isValidPeer (currentlyFocusedPeer))
  1256. {
  1257. if (Process::isForegroundProcess())
  1258. {
  1259. currentlyFocusedPeer->handleFocusGain();
  1260. ModalComponentManager::getInstance()->bringModalComponentsToFront();
  1261. }
  1262. else
  1263. {
  1264. currentlyFocusedPeer->handleFocusLoss();
  1265. }
  1266. }
  1267. }
  1268. static bool checkEventBlockedByModalComps (NSEvent* e)
  1269. {
  1270. if (Component::getNumCurrentlyModalComponents() == 0)
  1271. return false;
  1272. NSWindow* const w = [e window];
  1273. if (w == nil || [w worksWhenModal])
  1274. return false;
  1275. bool isKey = false, isInputAttempt = false;
  1276. switch ([e type])
  1277. {
  1278. case NSEventTypeKeyDown:
  1279. case NSEventTypeKeyUp:
  1280. isKey = isInputAttempt = true;
  1281. break;
  1282. case NSEventTypeLeftMouseDown:
  1283. case NSEventTypeRightMouseDown:
  1284. case NSEventTypeOtherMouseDown:
  1285. isInputAttempt = true;
  1286. break;
  1287. case NSEventTypeLeftMouseDragged:
  1288. case NSEventTypeRightMouseDragged:
  1289. case NSEventTypeLeftMouseUp:
  1290. case NSEventTypeRightMouseUp:
  1291. case NSEventTypeOtherMouseUp:
  1292. case NSEventTypeOtherMouseDragged:
  1293. if (Desktop::getInstance().getDraggingMouseSource(0) != nullptr)
  1294. return false;
  1295. break;
  1296. case NSEventTypeMouseMoved:
  1297. case NSEventTypeMouseEntered:
  1298. case NSEventTypeMouseExited:
  1299. case NSEventTypeCursorUpdate:
  1300. case NSEventTypeScrollWheel:
  1301. case NSEventTypeTabletPoint:
  1302. case NSEventTypeTabletProximity:
  1303. break;
  1304. case NSEventTypeFlagsChanged:
  1305. case NSEventTypeAppKitDefined:
  1306. case NSEventTypeSystemDefined:
  1307. case NSEventTypeApplicationDefined:
  1308. case NSEventTypePeriodic:
  1309. case NSEventTypeGesture:
  1310. case NSEventTypeMagnify:
  1311. case NSEventTypeSwipe:
  1312. case NSEventTypeRotate:
  1313. case NSEventTypeBeginGesture:
  1314. case NSEventTypeEndGesture:
  1315. case NSEventTypeQuickLook:
  1316. #if JUCE_64BIT
  1317. case NSEventTypeSmartMagnify:
  1318. case NSEventTypePressure:
  1319. #endif
  1320. #if defined (MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
  1321. #if JUCE_64BIT
  1322. case NSEventTypeDirectTouch:
  1323. #endif
  1324. #if defined (MAC_OS_X_VERSION_10_15) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_15
  1325. case NSEventTypeChangeMode:
  1326. #endif
  1327. #endif
  1328. default:
  1329. return false;
  1330. }
  1331. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  1332. {
  1333. if (auto* peer = dynamic_cast<NSViewComponentPeer*> (ComponentPeer::getPeer (i)))
  1334. {
  1335. if ([peer->view window] == w)
  1336. {
  1337. if (isKey)
  1338. {
  1339. if (peer->view == [w firstResponder])
  1340. return false;
  1341. }
  1342. else
  1343. {
  1344. if (peer->isSharedWindow
  1345. ? NSPointInRect ([peer->view convertPoint: [e locationInWindow] fromView: nil], [peer->view bounds])
  1346. : NSPointInRect ([e locationInWindow], NSMakeRect (0, 0, [w frame].size.width, [w frame].size.height)))
  1347. return false;
  1348. }
  1349. }
  1350. }
  1351. }
  1352. if (isInputAttempt)
  1353. {
  1354. if (! [NSApp isActive])
  1355. [NSApp activateIgnoringOtherApps: YES];
  1356. if (auto* modal = Component::getCurrentlyModalComponent())
  1357. modal->inputAttemptWhenModal();
  1358. }
  1359. return true;
  1360. }
  1361. void setFullScreenSizeConstraints (const ComponentBoundsConstrainer& c)
  1362. {
  1363. const auto minSize = NSMakeSize (static_cast<float> (c.getMinimumWidth()),
  1364. 0.0f);
  1365. [window setMinFullScreenContentSize: minSize];
  1366. }
  1367. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer)
  1368. };
  1369. int NSViewComponentPeer::insideToFrontCall = 0;
  1370. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wundeclared-selector")
  1371. const SEL NSViewComponentPeer::dismissModalsSelector = @selector (dismissModals);
  1372. const SEL NSViewComponentPeer::frameChangedSelector = @selector (frameChanged:);
  1373. const SEL NSViewComponentPeer::asyncMouseDownSelector = @selector (asyncMouseDown:);
  1374. const SEL NSViewComponentPeer::asyncMouseUpSelector = @selector (asyncMouseUp:);
  1375. const SEL NSViewComponentPeer::becomeKeySelector = @selector (becomeKey:);
  1376. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  1377. //==============================================================================
  1378. template <typename Base>
  1379. struct NSViewComponentPeerWrapper : public Base
  1380. {
  1381. explicit NSViewComponentPeerWrapper (const char* baseName)
  1382. : Base (baseName)
  1383. {
  1384. Base::template addIvar<NSViewComponentPeer*> ("owner");
  1385. }
  1386. static NSViewComponentPeer* getOwner (id self)
  1387. {
  1388. return Base::template getIvar<NSViewComponentPeer*> (self, "owner");
  1389. }
  1390. static id getAccessibleChild (id self)
  1391. {
  1392. if (auto* owner = getOwner (self))
  1393. if (auto* handler = owner->getComponent().getAccessibilityHandler())
  1394. return (id) handler->getNativeImplementation();
  1395. return nil;
  1396. }
  1397. };
  1398. struct JuceNSViewClass : public NSViewComponentPeerWrapper<ObjCClass<NSView>>
  1399. {
  1400. JuceNSViewClass() : NSViewComponentPeerWrapper ("JUCEView_")
  1401. {
  1402. addMethod (@selector (isOpaque), isOpaque, "c@:");
  1403. addMethod (@selector (drawRect:), drawRect, "v@:", @encode (NSRect));
  1404. addMethod (@selector (mouseDown:), mouseDown, "v@:@");
  1405. addMethod (@selector (mouseUp:), mouseUp, "v@:@");
  1406. addMethod (@selector (mouseDragged:), mouseDragged, "v@:@");
  1407. addMethod (@selector (mouseMoved:), mouseMoved, "v@:@");
  1408. addMethod (@selector (mouseEntered:), mouseEntered, "v@:@");
  1409. addMethod (@selector (mouseExited:), mouseExited, "v@:@");
  1410. addMethod (@selector (rightMouseDown:), mouseDown, "v@:@");
  1411. addMethod (@selector (rightMouseDragged:), mouseDragged, "v@:@");
  1412. addMethod (@selector (rightMouseUp:), mouseUp, "v@:@");
  1413. addMethod (@selector (otherMouseDown:), mouseDown, "v@:@");
  1414. addMethod (@selector (otherMouseDragged:), mouseDragged, "v@:@");
  1415. addMethod (@selector (otherMouseUp:), mouseUp, "v@:@");
  1416. addMethod (@selector (scrollWheel:), scrollWheel, "v@:@");
  1417. addMethod (@selector (magnifyWithEvent:), magnify, "v@:@");
  1418. addMethod (@selector (acceptsFirstMouse:), acceptsFirstMouse, "c@:@");
  1419. addMethod (@selector (windowWillMiniaturize:), windowWillMiniaturize, "v@:@");
  1420. addMethod (@selector (windowDidDeminiaturize:), windowDidDeminiaturize, "v@:@");
  1421. addMethod (@selector (wantsDefaultClipping), wantsDefaultClipping, "c@:");
  1422. addMethod (@selector (worksWhenModal), worksWhenModal, "c@:");
  1423. addMethod (@selector (viewDidMoveToWindow), viewDidMoveToWindow, "v@:");
  1424. addMethod (@selector (viewWillDraw), viewWillDraw, "v@:");
  1425. addMethod (@selector (keyDown:), keyDown, "v@:@");
  1426. addMethod (@selector (keyUp:), keyUp, "v@:@");
  1427. addMethod (@selector (insertText:), insertText, "v@:@");
  1428. addMethod (@selector (doCommandBySelector:), doCommandBySelector, "v@::");
  1429. addMethod (@selector (setMarkedText:selectedRange:), setMarkedText, "v@:@", @encode (NSRange));
  1430. addMethod (@selector (unmarkText), unmarkText, "v@:");
  1431. addMethod (@selector (hasMarkedText), hasMarkedText, "c@:");
  1432. addMethod (@selector (conversationIdentifier), conversationIdentifier, "l@:");
  1433. addMethod (@selector (attributedSubstringFromRange:), attributedSubstringFromRange, "@@:", @encode (NSRange));
  1434. addMethod (@selector (markedRange), markedRange, @encode (NSRange), "@:");
  1435. addMethod (@selector (selectedRange), selectedRange, @encode (NSRange), "@:");
  1436. addMethod (@selector (firstRectForCharacterRange:), firstRectForCharacterRange, @encode (NSRect), "@:", @encode (NSRange));
  1437. addMethod (@selector (characterIndexForPoint:), characterIndexForPoint, "L@:", @encode (NSPoint));
  1438. addMethod (@selector (validAttributesForMarkedText), validAttributesForMarkedText, "@@:");
  1439. addMethod (@selector (flagsChanged:), flagsChanged, "v@:@");
  1440. addMethod (@selector (becomeFirstResponder), becomeFirstResponder, "c@:");
  1441. addMethod (@selector (resignFirstResponder), resignFirstResponder, "c@:");
  1442. addMethod (@selector (acceptsFirstResponder), acceptsFirstResponder, "c@:");
  1443. addMethod (@selector (draggingEntered:), draggingEntered, @encode (NSDragOperation), "@:@");
  1444. addMethod (@selector (draggingUpdated:), draggingUpdated, @encode (NSDragOperation), "@:@");
  1445. addMethod (@selector (draggingEnded:), draggingEnded, "v@:@");
  1446. addMethod (@selector (draggingExited:), draggingExited, "v@:@");
  1447. addMethod (@selector (prepareForDragOperation:), prepareForDragOperation, "c@:@");
  1448. addMethod (@selector (performDragOperation:), performDragOperation, "c@:@");
  1449. addMethod (@selector (concludeDragOperation:), concludeDragOperation, "v@:@");
  1450. addMethod (@selector (paste:), paste, "v@:@");
  1451. addMethod (@selector (copy:), copy, "v@:@");
  1452. addMethod (@selector (cut:), cut, "v@:@");
  1453. addMethod (@selector (selectAll:), selectAll, "v@:@");
  1454. addMethod (@selector (viewWillMoveToWindow:), willMoveToWindow, "v@:@");
  1455. addMethod (@selector (isAccessibilityElement), getIsAccessibilityElement, "c@:");
  1456. addMethod (@selector (accessibilityChildren), getAccessibilityChildren, "@@:");
  1457. addMethod (@selector (accessibilityHitTest:), accessibilityHitTest, "@@:", @encode (NSPoint));
  1458. addMethod (@selector (accessibilityFocusedUIElement), getAccessibilityFocusedUIElement, "@@:");
  1459. // deprecated methods required for backwards compatibility
  1460. addMethod (@selector (accessibilityIsIgnored), getAccessibilityIsIgnored, "c@:");
  1461. addMethod (@selector (accessibilityAttributeValue:), getAccessibilityAttributeValue, "@@:@");
  1462. addMethod (@selector (isFlipped), isFlipped, "c@:");
  1463. addMethod (NSViewComponentPeer::dismissModalsSelector, dismissModals, "v@:");
  1464. addMethod (NSViewComponentPeer::asyncMouseDownSelector, asyncMouseDown, "v@:@");
  1465. addMethod (NSViewComponentPeer::asyncMouseUpSelector, asyncMouseUp, "v@:@");
  1466. addMethod (NSViewComponentPeer::frameChangedSelector, frameChanged, "v@:@");
  1467. addMethod (NSViewComponentPeer::becomeKeySelector, becomeKey, "v@:@");
  1468. addProtocol (@protocol (NSTextInput));
  1469. registerClass();
  1470. }
  1471. private:
  1472. static void mouseDown (id self, SEL s, NSEvent* ev)
  1473. {
  1474. if (JUCEApplicationBase::isStandaloneApp())
  1475. {
  1476. asyncMouseDown (self, s, ev);
  1477. }
  1478. else
  1479. {
  1480. // In some host situations, the host will stop modal loops from working
  1481. // correctly if they're called from a mouse event, so we'll trigger
  1482. // the event asynchronously..
  1483. [self performSelectorOnMainThread: NSViewComponentPeer::asyncMouseDownSelector
  1484. withObject: ev
  1485. waitUntilDone: NO];
  1486. }
  1487. }
  1488. static void mouseUp (id self, SEL s, NSEvent* ev)
  1489. {
  1490. if (JUCEApplicationBase::isStandaloneApp())
  1491. {
  1492. asyncMouseUp (self, s, ev);
  1493. }
  1494. else
  1495. {
  1496. // In some host situations, the host will stop modal loops from working
  1497. // correctly if they're called from a mouse event, so we'll trigger
  1498. // the event asynchronously..
  1499. [self performSelectorOnMainThread: NSViewComponentPeer::asyncMouseUpSelector
  1500. withObject: ev
  1501. waitUntilDone: NO];
  1502. }
  1503. }
  1504. static void asyncMouseDown (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseDown (ev); }
  1505. static void asyncMouseUp (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseUp (ev); }
  1506. static void mouseDragged (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseDrag (ev); }
  1507. static void mouseMoved (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseMove (ev); }
  1508. static void mouseEntered (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseEnter (ev); }
  1509. static void mouseExited (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseExit (ev); }
  1510. static void scrollWheel (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMouseWheel (ev); }
  1511. static void magnify (id self, SEL, NSEvent* ev) { if (auto* p = getOwner (self)) p->redirectMagnify (ev); }
  1512. static void copy (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectCopy (s); }
  1513. static void paste (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectPaste (s); }
  1514. static void cut (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectCut (s); }
  1515. static void selectAll (id self, SEL, NSObject* s) { if (auto* p = getOwner (self)) p->redirectSelectAll (s); }
  1516. static void willMoveToWindow (id self, SEL, NSWindow* w) { if (auto* p = getOwner (self)) p->redirectWillMoveToWindow (w); }
  1517. static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; }
  1518. static BOOL wantsDefaultClipping (id, SEL) { return YES; } // (this is the default, but may want to customise it in future)
  1519. static BOOL worksWhenModal (id self, SEL) { if (auto* p = getOwner (self)) return p->worksWhenModal(); return NO; }
  1520. static void drawRect (id self, SEL, NSRect r) { if (auto* p = getOwner (self)) p->drawRect (r); }
  1521. static void frameChanged (id self, SEL, NSNotification*) { if (auto* p = getOwner (self)) p->redirectMovedOrResized(); }
  1522. static void viewDidMoveToWindow (id self, SEL) { if (auto* p = getOwner (self)) p->viewMovedToWindow(); }
  1523. static void dismissModals (id self, SEL) { if (auto* p = getOwner (self)) p->dismissModals(); }
  1524. static void becomeKey (id self, SEL) { if (auto* p = getOwner (self)) p->becomeKey(); }
  1525. static BOOL isFlipped (id, SEL) { return true; }
  1526. static void viewWillDraw (id self, SEL)
  1527. {
  1528. // Without setting contentsFormat macOS Big Sur will always set the invalid area
  1529. // to be the entire frame.
  1530. #if defined (MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
  1531. if (NSFoundationVersionNumber > (double) NSFoundationVersionNumber10_11_Max)
  1532. {
  1533. CALayer* layer = ((NSView*) self).layer;
  1534. layer.contentsFormat = kCAContentsFormatRGBA8Uint;
  1535. }
  1536. #endif
  1537. sendSuperclassMessage<void> (self, @selector (viewWillDraw));
  1538. }
  1539. static void windowWillMiniaturize (id self, SEL, NSNotification*)
  1540. {
  1541. if (auto* p = getOwner (self))
  1542. {
  1543. if (p->isAlwaysOnTop)
  1544. {
  1545. // there is a bug when restoring minimised always on top windows so we need
  1546. // to remove this behaviour before minimising and restore it afterwards
  1547. p->setAlwaysOnTop (false);
  1548. p->wasAlwaysOnTop = true;
  1549. }
  1550. }
  1551. }
  1552. static void windowDidDeminiaturize (id self, SEL, NSNotification*)
  1553. {
  1554. if (auto* p = getOwner (self))
  1555. {
  1556. if (p->wasAlwaysOnTop)
  1557. p->setAlwaysOnTop (true);
  1558. p->redirectMovedOrResized();
  1559. }
  1560. }
  1561. static BOOL isOpaque (id self, SEL)
  1562. {
  1563. auto* owner = getOwner (self);
  1564. return owner == nullptr || owner->getComponent().isOpaque();
  1565. }
  1566. //==============================================================================
  1567. static void keyDown (id self, SEL, NSEvent* ev)
  1568. {
  1569. if (auto* owner = getOwner (self))
  1570. {
  1571. auto* target = owner->findCurrentTextInputTarget();
  1572. owner->textWasInserted = false;
  1573. if (target != nullptr)
  1574. [(NSView*) self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  1575. else
  1576. owner->stringBeingComposed.clear();
  1577. if (! (owner->textWasInserted || owner->redirectKeyDown (ev)))
  1578. sendSuperclassMessage<void> (self, @selector (keyDown:), ev);
  1579. }
  1580. }
  1581. static void keyUp (id self, SEL, NSEvent* ev)
  1582. {
  1583. auto* owner = getOwner (self);
  1584. if (! owner->redirectKeyUp (ev))
  1585. sendSuperclassMessage<void> (self, @selector (keyUp:), ev);
  1586. }
  1587. //==============================================================================
  1588. static void insertText (id self, SEL, id aString)
  1589. {
  1590. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  1591. if (auto* owner = getOwner (self))
  1592. {
  1593. NSString* newText = [aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString;
  1594. if ([newText length] > 0)
  1595. {
  1596. if (auto* target = owner->findCurrentTextInputTarget())
  1597. {
  1598. target->insertTextAtCaret (nsStringToJuce (newText));
  1599. owner->textWasInserted = true;
  1600. }
  1601. }
  1602. owner->stringBeingComposed.clear();
  1603. }
  1604. }
  1605. static void doCommandBySelector (id, SEL, SEL) {}
  1606. static void setMarkedText (id self, SEL, id aString, NSRange)
  1607. {
  1608. if (auto* owner = getOwner (self))
  1609. {
  1610. owner->stringBeingComposed = nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]]
  1611. ? [aString string] : aString);
  1612. if (auto* target = owner->findCurrentTextInputTarget())
  1613. {
  1614. auto currentHighlight = target->getHighlightedRegion();
  1615. target->insertTextAtCaret (owner->stringBeingComposed);
  1616. target->setHighlightedRegion (currentHighlight.withLength (owner->stringBeingComposed.length()));
  1617. owner->textWasInserted = true;
  1618. }
  1619. }
  1620. }
  1621. static void unmarkText (id self, SEL)
  1622. {
  1623. if (auto* owner = getOwner (self))
  1624. {
  1625. if (owner->stringBeingComposed.isNotEmpty())
  1626. {
  1627. if (auto* target = owner->findCurrentTextInputTarget())
  1628. {
  1629. target->insertTextAtCaret (owner->stringBeingComposed);
  1630. owner->textWasInserted = true;
  1631. }
  1632. owner->stringBeingComposed.clear();
  1633. }
  1634. }
  1635. }
  1636. static BOOL hasMarkedText (id self, SEL)
  1637. {
  1638. auto* owner = getOwner (self);
  1639. return owner != nullptr && owner->stringBeingComposed.isNotEmpty();
  1640. }
  1641. static long conversationIdentifier (id self, SEL)
  1642. {
  1643. return (long) (pointer_sized_int) self;
  1644. }
  1645. static NSAttributedString* attributedSubstringFromRange (id self, SEL, NSRange theRange)
  1646. {
  1647. if (auto* owner = getOwner (self))
  1648. {
  1649. if (auto* target = owner->findCurrentTextInputTarget())
  1650. {
  1651. Range<int> r ((int) theRange.location,
  1652. (int) (theRange.location + theRange.length));
  1653. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  1654. }
  1655. }
  1656. return nil;
  1657. }
  1658. static NSRange markedRange (id self, SEL)
  1659. {
  1660. if (auto* owner = getOwner (self))
  1661. if (owner->stringBeingComposed.isNotEmpty())
  1662. return NSMakeRange (0, (NSUInteger) owner->stringBeingComposed.length());
  1663. return NSMakeRange (NSNotFound, 0);
  1664. }
  1665. static NSRange selectedRange (id self, SEL)
  1666. {
  1667. if (auto* owner = getOwner (self))
  1668. {
  1669. if (auto* target = owner->findCurrentTextInputTarget())
  1670. {
  1671. auto highlight = target->getHighlightedRegion();
  1672. if (! highlight.isEmpty())
  1673. return NSMakeRange ((NSUInteger) highlight.getStart(),
  1674. (NSUInteger) highlight.getLength());
  1675. }
  1676. }
  1677. return NSMakeRange (NSNotFound, 0);
  1678. }
  1679. static NSRect firstRectForCharacterRange (id self, SEL, NSRange)
  1680. {
  1681. if (auto* owner = getOwner (self))
  1682. if (auto* comp = dynamic_cast<Component*> (owner->findCurrentTextInputTarget()))
  1683. return flippedScreenRect (makeNSRect (comp->getScreenBounds()));
  1684. return NSZeroRect;
  1685. }
  1686. static NSUInteger characterIndexForPoint (id, SEL, NSPoint) { return NSNotFound; }
  1687. static NSArray* validAttributesForMarkedText (id, SEL) { return [NSArray array]; }
  1688. //==============================================================================
  1689. static void flagsChanged (id self, SEL, NSEvent* ev)
  1690. {
  1691. if (auto* owner = getOwner (self))
  1692. owner->redirectModKeyChange (ev);
  1693. }
  1694. static BOOL becomeFirstResponder (id self, SEL)
  1695. {
  1696. if (auto* owner = getOwner (self))
  1697. owner->viewFocusGain();
  1698. return YES;
  1699. }
  1700. static BOOL resignFirstResponder (id self, SEL)
  1701. {
  1702. if (auto* owner = getOwner (self))
  1703. owner->viewFocusLoss();
  1704. return YES;
  1705. }
  1706. static BOOL acceptsFirstResponder (id self, SEL)
  1707. {
  1708. auto* owner = getOwner (self);
  1709. return owner != nullptr && owner->canBecomeKeyWindow();
  1710. }
  1711. //==============================================================================
  1712. static NSDragOperation draggingEntered (id self, SEL s, id<NSDraggingInfo> sender)
  1713. {
  1714. return draggingUpdated (self, s, sender);
  1715. }
  1716. static NSDragOperation draggingUpdated (id self, SEL, id<NSDraggingInfo> sender)
  1717. {
  1718. if (auto* owner = getOwner (self))
  1719. if (owner->sendDragCallback (0, sender))
  1720. return NSDragOperationGeneric;
  1721. return NSDragOperationNone;
  1722. }
  1723. static void draggingEnded (id self, SEL s, id<NSDraggingInfo> sender)
  1724. {
  1725. draggingExited (self, s, sender);
  1726. }
  1727. static void draggingExited (id self, SEL, id<NSDraggingInfo> sender)
  1728. {
  1729. if (auto* owner = getOwner (self))
  1730. owner->sendDragCallback (1, sender);
  1731. }
  1732. static BOOL prepareForDragOperation (id, SEL, id<NSDraggingInfo>)
  1733. {
  1734. return YES;
  1735. }
  1736. static BOOL performDragOperation (id self, SEL, id<NSDraggingInfo> sender)
  1737. {
  1738. auto* owner = getOwner (self);
  1739. return owner != nullptr && owner->sendDragCallback (2, sender);
  1740. }
  1741. static void concludeDragOperation (id, SEL, id<NSDraggingInfo>) {}
  1742. //==============================================================================
  1743. static BOOL getIsAccessibilityElement (id, SEL)
  1744. {
  1745. return NO;
  1746. }
  1747. static NSArray* getAccessibilityChildren (id self, SEL)
  1748. {
  1749. return NSAccessibilityUnignoredChildrenForOnlyChild (getAccessibleChild (self));
  1750. }
  1751. static id accessibilityHitTest (id self, SEL, NSPoint point)
  1752. {
  1753. return [getAccessibleChild (self) accessibilityHitTest: point];
  1754. }
  1755. static id getAccessibilityFocusedUIElement (id self, SEL)
  1756. {
  1757. return [getAccessibleChild (self) accessibilityFocusedUIElement];
  1758. }
  1759. static BOOL getAccessibilityIsIgnored (id self, SEL)
  1760. {
  1761. return ! [self isAccessibilityElement];
  1762. }
  1763. static id getAccessibilityAttributeValue (id self, SEL, NSString* attribute)
  1764. {
  1765. if ([attribute isEqualToString: NSAccessibilityChildrenAttribute])
  1766. return getAccessibilityChildren (self, {});
  1767. return sendSuperclassMessage<id> (self, @selector (accessibilityAttributeValue:), attribute);
  1768. }
  1769. };
  1770. //==============================================================================
  1771. struct JuceNSWindowClass : public NSViewComponentPeerWrapper<ObjCClass<NSWindow>>
  1772. {
  1773. JuceNSWindowClass() : NSViewComponentPeerWrapper ("JUCEWindow_")
  1774. {
  1775. addMethod (@selector (canBecomeKeyWindow), canBecomeKeyWindow, "c@:");
  1776. addMethod (@selector (canBecomeMainWindow), canBecomeMainWindow, "c@:");
  1777. addMethod (@selector (becomeKeyWindow), becomeKeyWindow, "v@:");
  1778. addMethod (@selector (resignKeyWindow), resignKeyWindow, "v@:");
  1779. addMethod (@selector (windowShouldClose:), windowShouldClose, "c@:@");
  1780. addMethod (@selector (constrainFrameRect:toScreen:), constrainFrameRect, @encode (NSRect), "@:", @encode (NSRect), "@");
  1781. addMethod (@selector (windowWillResize:toSize:), windowWillResize, @encode (NSSize), "@:@", @encode (NSSize));
  1782. addMethod (@selector (windowDidExitFullScreen:), windowDidExitFullScreen, "v@:@");
  1783. addMethod (@selector (windowWillEnterFullScreen:), windowWillEnterFullScreen, "v@:@");
  1784. addMethod (@selector (zoom:), zoom, "v@:@");
  1785. addMethod (@selector (windowWillStartLiveResize:), windowWillStartLiveResize, "v@:@");
  1786. addMethod (@selector (windowDidEndLiveResize:), windowDidEndLiveResize, "v@:@");
  1787. addMethod (@selector (window:shouldPopUpDocumentPathMenu:), shouldPopUpPathMenu, "B@:@", @encode (NSMenu*));
  1788. addMethod (@selector (isFlipped), isFlipped, "c@:");
  1789. addMethod (@selector (accessibilityTitle), getAccessibilityTitle, "@@:");
  1790. addMethod (@selector (accessibilityLabel), getAccessibilityLabel, "@@:");
  1791. addMethod (@selector (accessibilityTopLevelUIElement), getAccessibilityWindow, "@@:");
  1792. addMethod (@selector (accessibilityWindow), getAccessibilityWindow, "@@:");
  1793. addMethod (@selector (accessibilityRole), getAccessibilityRole, "@@:");
  1794. addMethod (@selector (accessibilitySubrole), getAccessibilitySubrole, "@@:");
  1795. addMethod (@selector (window:shouldDragDocumentWithEvent:from:withPasteboard:),
  1796. shouldAllowIconDrag, "B@:@", @encode (NSEvent*), @encode (NSPoint), @encode (NSPasteboard*));
  1797. addProtocol (@protocol (NSWindowDelegate));
  1798. registerClass();
  1799. }
  1800. private:
  1801. //==============================================================================
  1802. static BOOL isFlipped (id, SEL) { return true; }
  1803. static BOOL canBecomeKeyWindow (id self, SEL)
  1804. {
  1805. auto* owner = getOwner (self);
  1806. return owner != nullptr
  1807. && owner->canBecomeKeyWindow()
  1808. && ! owner->isBlockedByModalComponent();
  1809. }
  1810. static BOOL canBecomeMainWindow (id self, SEL)
  1811. {
  1812. auto* owner = getOwner (self);
  1813. return owner != nullptr
  1814. && owner->canBecomeMainWindow()
  1815. && ! owner->isBlockedByModalComponent();
  1816. }
  1817. static void becomeKeyWindow (id self, SEL)
  1818. {
  1819. sendSuperclassMessage<void> (self, @selector (becomeKeyWindow));
  1820. if (auto* owner = getOwner (self))
  1821. {
  1822. if (owner->canBecomeKeyWindow())
  1823. {
  1824. owner->becomeKeyWindow();
  1825. return;
  1826. }
  1827. // this fixes a bug causing hidden windows to sometimes become visible when the app regains focus
  1828. if (! owner->getComponent().isVisible())
  1829. [(NSWindow*) self orderOut: nil];
  1830. }
  1831. }
  1832. static void resignKeyWindow (id self, SEL)
  1833. {
  1834. sendSuperclassMessage<void> (self, @selector (resignKeyWindow));
  1835. if (auto* owner = getOwner (self))
  1836. owner->resignKeyWindow();
  1837. }
  1838. static BOOL windowShouldClose (id self, SEL, id /*window*/)
  1839. {
  1840. auto* owner = getOwner (self);
  1841. return owner == nullptr || owner->windowShouldClose();
  1842. }
  1843. static NSRect constrainFrameRect (id self, SEL, NSRect frameRect, NSScreen* screen)
  1844. {
  1845. if (auto* owner = getOwner (self))
  1846. {
  1847. frameRect = sendSuperclassMessage<NSRect, NSRect, NSScreen*> (self, @selector (constrainFrameRect:toScreen:),
  1848. frameRect, screen);
  1849. frameRect = owner->constrainRect (frameRect);
  1850. }
  1851. return frameRect;
  1852. }
  1853. static NSSize windowWillResize (id self, SEL, NSWindow*, NSSize proposedFrameSize)
  1854. {
  1855. auto* owner = getOwner (self);
  1856. if (owner == nullptr || owner->isZooming)
  1857. return proposedFrameSize;
  1858. NSRect frameRect = flippedScreenRect ([(NSWindow*) self frame]);
  1859. frameRect.size = proposedFrameSize;
  1860. frameRect = owner->constrainRect (flippedScreenRect (frameRect));
  1861. owner->dismissModals();
  1862. return frameRect.size;
  1863. }
  1864. static void windowDidExitFullScreen (id self, SEL, NSNotification*)
  1865. {
  1866. if (auto* owner = getOwner (self))
  1867. owner->resetWindowPresentation();
  1868. }
  1869. static void windowWillEnterFullScreen (id self, SEL, NSNotification*)
  1870. {
  1871. if (SystemStats::getOperatingSystemType() <= SystemStats::MacOSX_10_9)
  1872. return;
  1873. if (auto* owner = getOwner (self))
  1874. if (owner->hasNativeTitleBar() && (owner->getStyleFlags() & ComponentPeer::windowIsResizable) == 0)
  1875. [owner->window setStyleMask: NSWindowStyleMaskBorderless];
  1876. }
  1877. static void zoom (id self, SEL, id sender)
  1878. {
  1879. if (auto* owner = getOwner (self))
  1880. {
  1881. {
  1882. const ScopedValueSetter<bool> svs (owner->isZooming, true);
  1883. sendSuperclassMessage<void> (self, @selector (zoom:), sender);
  1884. }
  1885. owner->redirectMovedOrResized();
  1886. }
  1887. }
  1888. static void windowWillStartLiveResize (id self, SEL, NSNotification*)
  1889. {
  1890. if (auto* owner = getOwner (self))
  1891. owner->liveResizingStart();
  1892. }
  1893. static void windowDidEndLiveResize (id self, SEL, NSNotification*)
  1894. {
  1895. if (auto* owner = getOwner (self))
  1896. owner->liveResizingEnd();
  1897. }
  1898. static bool shouldPopUpPathMenu (id self, SEL, id /*window*/, NSMenu*)
  1899. {
  1900. if (auto* owner = getOwner (self))
  1901. return owner->windowRepresentsFile;
  1902. return false;
  1903. }
  1904. static bool shouldAllowIconDrag (id self, SEL, id /*window*/, NSEvent*, NSPoint, NSPasteboard*)
  1905. {
  1906. if (auto* owner = getOwner (self))
  1907. return owner->windowRepresentsFile;
  1908. return false;
  1909. }
  1910. static NSString* getAccessibilityTitle (id self, SEL)
  1911. {
  1912. return [self title];
  1913. }
  1914. static NSString* getAccessibilityLabel (id self, SEL)
  1915. {
  1916. return [getAccessibleChild (self) accessibilityLabel];
  1917. }
  1918. static id getAccessibilityWindow (id self, SEL)
  1919. {
  1920. return self;
  1921. }
  1922. static NSAccessibilityRole getAccessibilityRole (id, SEL)
  1923. {
  1924. return NSAccessibilityWindowRole;
  1925. }
  1926. static NSAccessibilityRole getAccessibilitySubrole (id self, SEL)
  1927. {
  1928. return [getAccessibleChild (self) accessibilitySubrole];
  1929. }
  1930. };
  1931. NSView* NSViewComponentPeer::createViewInstance()
  1932. {
  1933. static JuceNSViewClass cls;
  1934. return cls.createInstance();
  1935. }
  1936. NSWindow* NSViewComponentPeer::createWindowInstance()
  1937. {
  1938. static JuceNSWindowClass cls;
  1939. return cls.createInstance();
  1940. }
  1941. //==============================================================================
  1942. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = nullptr;
  1943. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  1944. //==============================================================================
  1945. bool KeyPress::isKeyCurrentlyDown (int keyCode)
  1946. {
  1947. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  1948. return true;
  1949. if (keyCode >= 'A' && keyCode <= 'Z'
  1950. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  1951. return true;
  1952. if (keyCode >= 'a' && keyCode <= 'z'
  1953. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  1954. return true;
  1955. return false;
  1956. }
  1957. //==============================================================================
  1958. bool MouseInputSource::SourceList::addSource()
  1959. {
  1960. if (sources.size() == 0)
  1961. {
  1962. addSource (0, MouseInputSource::InputSourceType::mouse);
  1963. return true;
  1964. }
  1965. return false;
  1966. }
  1967. bool MouseInputSource::SourceList::canUseTouch()
  1968. {
  1969. return false;
  1970. }
  1971. //==============================================================================
  1972. void Desktop::setKioskComponent (Component* kioskComp, bool shouldBeEnabled, bool allowMenusAndBars)
  1973. {
  1974. auto* peer = dynamic_cast<NSViewComponentPeer*> (kioskComp->getPeer());
  1975. jassert (peer != nullptr); // (this should have been checked by the caller)
  1976. if (peer->hasNativeTitleBar()
  1977. && [peer->window respondsToSelector: @selector (toggleFullScreen:)])
  1978. {
  1979. if (shouldBeEnabled && ! allowMenusAndBars)
  1980. [NSApp setPresentationOptions: NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar];
  1981. else if (! shouldBeEnabled)
  1982. [NSApp setPresentationOptions: NSApplicationPresentationDefault];
  1983. [peer->window performSelector: @selector (toggleFullScreen:) withObject: nil];
  1984. }
  1985. else
  1986. {
  1987. if (shouldBeEnabled)
  1988. {
  1989. if (peer->hasNativeTitleBar())
  1990. [peer->window setStyleMask: NSWindowStyleMaskBorderless];
  1991. [NSApp setPresentationOptions: (allowMenusAndBars ? (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)
  1992. : (NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar))];
  1993. kioskComp->setBounds (getDisplays().getDisplayForRect (kioskComp->getScreenBounds())->totalArea);
  1994. peer->becomeKeyWindow();
  1995. }
  1996. else
  1997. {
  1998. peer->resetWindowPresentation();
  1999. }
  2000. }
  2001. }
  2002. void Desktop::allowedOrientationsChanged() {}
  2003. //==============================================================================
  2004. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  2005. {
  2006. return new NSViewComponentPeer (*this, styleFlags, (NSView*) windowToAttachTo);
  2007. }
  2008. //==============================================================================
  2009. const int KeyPress::spaceKey = ' ';
  2010. const int KeyPress::returnKey = 0x0d;
  2011. const int KeyPress::escapeKey = 0x1b;
  2012. const int KeyPress::backspaceKey = 0x7f;
  2013. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  2014. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  2015. const int KeyPress::upKey = NSUpArrowFunctionKey;
  2016. const int KeyPress::downKey = NSDownArrowFunctionKey;
  2017. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  2018. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  2019. const int KeyPress::endKey = NSEndFunctionKey;
  2020. const int KeyPress::homeKey = NSHomeFunctionKey;
  2021. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  2022. const int KeyPress::insertKey = -1;
  2023. const int KeyPress::tabKey = 9;
  2024. const int KeyPress::F1Key = NSF1FunctionKey;
  2025. const int KeyPress::F2Key = NSF2FunctionKey;
  2026. const int KeyPress::F3Key = NSF3FunctionKey;
  2027. const int KeyPress::F4Key = NSF4FunctionKey;
  2028. const int KeyPress::F5Key = NSF5FunctionKey;
  2029. const int KeyPress::F6Key = NSF6FunctionKey;
  2030. const int KeyPress::F7Key = NSF7FunctionKey;
  2031. const int KeyPress::F8Key = NSF8FunctionKey;
  2032. const int KeyPress::F9Key = NSF9FunctionKey;
  2033. const int KeyPress::F10Key = NSF10FunctionKey;
  2034. const int KeyPress::F11Key = NSF11FunctionKey;
  2035. const int KeyPress::F12Key = NSF12FunctionKey;
  2036. const int KeyPress::F13Key = NSF13FunctionKey;
  2037. const int KeyPress::F14Key = NSF14FunctionKey;
  2038. const int KeyPress::F15Key = NSF15FunctionKey;
  2039. const int KeyPress::F16Key = NSF16FunctionKey;
  2040. const int KeyPress::F17Key = NSF17FunctionKey;
  2041. const int KeyPress::F18Key = NSF18FunctionKey;
  2042. const int KeyPress::F19Key = NSF19FunctionKey;
  2043. const int KeyPress::F20Key = NSF20FunctionKey;
  2044. const int KeyPress::F21Key = NSF21FunctionKey;
  2045. const int KeyPress::F22Key = NSF22FunctionKey;
  2046. const int KeyPress::F23Key = NSF23FunctionKey;
  2047. const int KeyPress::F24Key = NSF24FunctionKey;
  2048. const int KeyPress::F25Key = NSF25FunctionKey;
  2049. const int KeyPress::F26Key = NSF26FunctionKey;
  2050. const int KeyPress::F27Key = NSF27FunctionKey;
  2051. const int KeyPress::F28Key = NSF28FunctionKey;
  2052. const int KeyPress::F29Key = NSF29FunctionKey;
  2053. const int KeyPress::F30Key = NSF30FunctionKey;
  2054. const int KeyPress::F31Key = NSF31FunctionKey;
  2055. const int KeyPress::F32Key = NSF32FunctionKey;
  2056. const int KeyPress::F33Key = NSF33FunctionKey;
  2057. const int KeyPress::F34Key = NSF34FunctionKey;
  2058. const int KeyPress::F35Key = NSF35FunctionKey;
  2059. const int KeyPress::numberPad0 = 0x30020;
  2060. const int KeyPress::numberPad1 = 0x30021;
  2061. const int KeyPress::numberPad2 = 0x30022;
  2062. const int KeyPress::numberPad3 = 0x30023;
  2063. const int KeyPress::numberPad4 = 0x30024;
  2064. const int KeyPress::numberPad5 = 0x30025;
  2065. const int KeyPress::numberPad6 = 0x30026;
  2066. const int KeyPress::numberPad7 = 0x30027;
  2067. const int KeyPress::numberPad8 = 0x30028;
  2068. const int KeyPress::numberPad9 = 0x30029;
  2069. const int KeyPress::numberPadAdd = 0x3002a;
  2070. const int KeyPress::numberPadSubtract = 0x3002b;
  2071. const int KeyPress::numberPadMultiply = 0x3002c;
  2072. const int KeyPress::numberPadDivide = 0x3002d;
  2073. const int KeyPress::numberPadSeparator = 0x3002e;
  2074. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  2075. const int KeyPress::numberPadEquals = 0x30030;
  2076. const int KeyPress::numberPadDelete = 0x30031;
  2077. const int KeyPress::playKey = 0x30000;
  2078. const int KeyPress::stopKey = 0x30001;
  2079. const int KeyPress::fastForwardKey = 0x30002;
  2080. const int KeyPress::rewindKey = 0x30003;
  2081. } // namespace juce