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.

2562 lines
95KB

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