Audio plugin host https://kx.studio/carla
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.

1977 lines
73KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. typedef void (*AppFocusChangeCallback)();
  18. extern AppFocusChangeCallback appFocusChangeCallback;
  19. typedef bool (*CheckEventBlockedByModalComps) (NSEvent*);
  20. extern CheckEventBlockedByModalComps isEventBlockedByModalComps;
  21. //==============================================================================
  22. #if ! (defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
  23. } // (juce namespace)
  24. @interface NSEvent (JuceDeviceDelta)
  25. - (CGFloat) scrollingDeltaX;
  26. - (CGFloat) scrollingDeltaY;
  27. - (BOOL) hasPreciseScrollingDeltas;
  28. - (BOOL) isDirectionInvertedFromDevice;
  29. @end
  30. namespace juce {
  31. #endif
  32. //==============================================================================
  33. static CGFloat getMainScreenHeight() noexcept
  34. {
  35. return [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  36. }
  37. static void flipScreenRect (NSRect& r) noexcept
  38. {
  39. r.origin.y = getMainScreenHeight() - (r.origin.y + r.size.height);
  40. }
  41. static NSRect flippedScreenRect (NSRect r) noexcept
  42. {
  43. flipScreenRect (r);
  44. return r;
  45. }
  46. //==============================================================================
  47. class NSViewComponentPeer : public ComponentPeer
  48. {
  49. public:
  50. NSViewComponentPeer (Component& comp, const int windowStyleFlags, NSView* viewToAttachTo)
  51. : ComponentPeer (comp, windowStyleFlags),
  52. window (nil),
  53. view (nil),
  54. isSharedWindow (viewToAttachTo != nil),
  55. fullScreen (false),
  56. insideDrawRect (false),
  57. #if USE_COREGRAPHICS_RENDERING
  58. usingCoreGraphics (true),
  59. #else
  60. usingCoreGraphics (false),
  61. #endif
  62. isZooming (false),
  63. textWasInserted (false),
  64. notificationCenter (nil)
  65. {
  66. appFocusChangeCallback = appFocusChanged;
  67. isEventBlockedByModalComps = checkEventBlockedByModalComps;
  68. NSRect r = makeNSRect (component.getLocalBounds());
  69. view = [createViewInstance() initWithFrame: r];
  70. setOwner (view, this);
  71. [view registerForDraggedTypes: getSupportedDragTypes()];
  72. notificationCenter = [NSNotificationCenter defaultCenter];
  73. [notificationCenter addObserver: view
  74. selector: @selector (frameChanged:)
  75. name: NSViewFrameDidChangeNotification
  76. object: view];
  77. if (! isSharedWindow)
  78. {
  79. [notificationCenter addObserver: view
  80. selector: @selector (frameChanged:)
  81. name: NSWindowDidMoveNotification
  82. object: window];
  83. [notificationCenter addObserver: view
  84. selector: @selector (frameChanged:)
  85. name: NSWindowDidMiniaturizeNotification
  86. object: window];
  87. [notificationCenter addObserver: view
  88. selector: @selector (frameChanged:)
  89. name: NSWindowDidDeminiaturizeNotification
  90. object: window];
  91. }
  92. [view setPostsFrameChangedNotifications: YES];
  93. if (isSharedWindow)
  94. {
  95. window = [viewToAttachTo window];
  96. [viewToAttachTo addSubview: view];
  97. }
  98. else
  99. {
  100. r.origin.x = (CGFloat) component.getX();
  101. r.origin.y = (CGFloat) component.getY();
  102. flipScreenRect (r);
  103. window = [createWindowInstance() initWithContentRect: r
  104. styleMask: getNSWindowStyleMask (windowStyleFlags)
  105. backing: NSBackingStoreBuffered
  106. defer: YES];
  107. setOwner (window, this);
  108. [window orderOut: nil];
  109. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  110. [window setDelegate: (id<NSWindowDelegate>) window];
  111. #else
  112. [window setDelegate: window];
  113. #endif
  114. [window setOpaque: component.isOpaque()];
  115. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  116. if (component.isAlwaysOnTop())
  117. [window setLevel: NSFloatingWindowLevel];
  118. [window setContentView: view];
  119. [window setAutodisplay: YES];
  120. [window setAcceptsMouseMovedEvents: YES];
  121. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  122. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  123. [window setReleasedWhenClosed: YES];
  124. [window retain];
  125. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  126. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  127. #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
  128. if ((windowStyleFlags & (windowHasMaximiseButton | windowHasTitleBar)) == (windowHasMaximiseButton | windowHasTitleBar))
  129. [window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
  130. if ([window respondsToSelector: @selector (setRestorable:)])
  131. [window setRestorable: NO];
  132. #endif
  133. }
  134. const float alpha = component.getAlpha();
  135. if (alpha < 1.0f)
  136. setAlpha (alpha);
  137. setTitle (component.getName());
  138. }
  139. ~NSViewComponentPeer()
  140. {
  141. [notificationCenter removeObserver: view];
  142. setOwner (view, nullptr);
  143. if ([view superview] != nil)
  144. [view removeFromSuperview];
  145. [view release];
  146. if (! isSharedWindow)
  147. {
  148. setOwner (window, nullptr);
  149. [window close];
  150. [window release];
  151. }
  152. }
  153. //==============================================================================
  154. void* getNativeHandle() const override { return view; }
  155. void setVisible (bool shouldBeVisible) override
  156. {
  157. if (isSharedWindow)
  158. {
  159. [view setHidden: ! shouldBeVisible];
  160. }
  161. else
  162. {
  163. if (shouldBeVisible)
  164. {
  165. [window orderFront: nil];
  166. handleBroughtToFront();
  167. }
  168. else
  169. {
  170. [window orderOut: nil];
  171. }
  172. }
  173. }
  174. void setTitle (const String& title) override
  175. {
  176. JUCE_AUTORELEASEPOOL
  177. {
  178. if (! isSharedWindow)
  179. [window setTitle: juceStringToNS (title)];
  180. }
  181. }
  182. bool setDocumentEditedStatus (bool edited) override
  183. {
  184. if (! hasNativeTitleBar())
  185. return false;
  186. [window setDocumentEdited: edited];
  187. return true;
  188. }
  189. void setRepresentedFile (const File& file) override
  190. {
  191. if (! isSharedWindow)
  192. [window setRepresentedFilename: juceStringToNS (file != File::nonexistent
  193. ? file.getFullPathName()
  194. : String::empty)];
  195. }
  196. void setBounds (const Rectangle<int>& newBounds, bool isNowFullScreen) override
  197. {
  198. fullScreen = isNowFullScreen;
  199. NSRect r = makeNSRect (newBounds);
  200. if (isSharedWindow)
  201. {
  202. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203. if ([view frame].size.width != r.size.width
  204. || [view frame].size.height != r.size.height)
  205. {
  206. [view setNeedsDisplay: true];
  207. }
  208. [view setFrame: r];
  209. }
  210. else
  211. {
  212. [window setFrame: [window frameRectForContentRect: flippedScreenRect (r)]
  213. display: true];
  214. }
  215. }
  216. Rectangle<int> getBounds (const bool global) const
  217. {
  218. NSRect r = [view frame];
  219. NSWindow* viewWindow = [view window];
  220. if (global && viewWindow != nil)
  221. {
  222. r = [[view superview] convertRect: r toView: nil];
  223. #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
  224. r = [viewWindow convertRectToScreen: r];
  225. #else
  226. r.origin = [viewWindow convertBaseToScreen: r.origin];
  227. #endif
  228. flipScreenRect (r);
  229. }
  230. else
  231. {
  232. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  233. }
  234. return convertToRectInt (r);
  235. }
  236. Rectangle<int> getBounds() const override
  237. {
  238. return getBounds (! isSharedWindow);
  239. }
  240. Point<int> localToGlobal (Point<int> relativePosition) override
  241. {
  242. return relativePosition + getBounds (true).getPosition();
  243. }
  244. Point<int> globalToLocal (Point<int> screenPosition) override
  245. {
  246. return screenPosition - getBounds (true).getPosition();
  247. }
  248. void setAlpha (float newAlpha) override
  249. {
  250. if (! isSharedWindow)
  251. {
  252. [window setAlphaValue: (CGFloat) newAlpha];
  253. }
  254. else
  255. {
  256. #if defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  257. [view setAlphaValue: (CGFloat) newAlpha];
  258. #else
  259. if ([view respondsToSelector: @selector (setAlphaValue:)])
  260. {
  261. // PITA dynamic invocation for 10.4 builds..
  262. NSInvocation* inv = [NSInvocation invocationWithMethodSignature: [view methodSignatureForSelector: @selector (setAlphaValue:)]];
  263. [inv setSelector: @selector (setAlphaValue:)];
  264. [inv setTarget: view];
  265. CGFloat cgNewAlpha = (CGFloat) newAlpha;
  266. [inv setArgument: &cgNewAlpha atIndex: 2];
  267. [inv invoke];
  268. }
  269. #endif
  270. }
  271. }
  272. void setMinimised (bool shouldBeMinimised) override
  273. {
  274. if (! isSharedWindow)
  275. {
  276. if (shouldBeMinimised)
  277. [window miniaturize: nil];
  278. else
  279. [window deminiaturize: nil];
  280. }
  281. }
  282. bool isMinimised() const override
  283. {
  284. return [window isMiniaturized];
  285. }
  286. void setFullScreen (bool shouldBeFullScreen) override
  287. {
  288. if (! isSharedWindow)
  289. {
  290. Rectangle<int> r (lastNonFullscreenBounds);
  291. if (isMinimised())
  292. setMinimised (false);
  293. if (fullScreen != shouldBeFullScreen)
  294. {
  295. if (shouldBeFullScreen && hasNativeTitleBar())
  296. {
  297. fullScreen = true;
  298. [window performZoom: nil];
  299. }
  300. else
  301. {
  302. if (shouldBeFullScreen)
  303. r = component.getParentMonitorArea();
  304. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  305. if (r != component.getBounds() && ! r.isEmpty())
  306. setBounds (r, shouldBeFullScreen);
  307. }
  308. }
  309. }
  310. }
  311. bool isFullScreen() const override
  312. {
  313. return fullScreen;
  314. }
  315. bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
  316. {
  317. NSRect frameRect = [view frame];
  318. if (! (isPositiveAndBelow (localPos.getX(), (int) frameRect.size.width)
  319. && isPositiveAndBelow (localPos.getY(), (int) frameRect.size.height)))
  320. return false;
  321. NSView* v = [view hitTest: NSMakePoint (frameRect.origin.x + localPos.getX(),
  322. frameRect.origin.y + frameRect.size.height - localPos.getY())];
  323. return trueIfInAChildWindow ? (v != nil)
  324. : (v == view);
  325. }
  326. BorderSize<int> getFrameSize() const override
  327. {
  328. BorderSize<int> b;
  329. if (! isSharedWindow)
  330. {
  331. NSRect v = [view convertRect: [view frame] toView: nil];
  332. NSRect w = [window frame];
  333. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  334. b.setBottom ((int) v.origin.y);
  335. b.setLeft ((int) v.origin.x);
  336. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  337. }
  338. return b;
  339. }
  340. void updateFullscreenStatus()
  341. {
  342. if (hasNativeTitleBar())
  343. {
  344. const Rectangle<int> screen (getFrameSize().subtractedFrom (component.getParentMonitorArea()));
  345. fullScreen = component.getScreenBounds().expanded (2, 2).contains (screen);
  346. }
  347. }
  348. bool hasNativeTitleBar() const
  349. {
  350. return (getStyleFlags() & windowHasTitleBar) != 0;
  351. }
  352. bool setAlwaysOnTop (bool alwaysOnTop) override
  353. {
  354. if (! isSharedWindow)
  355. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  356. : NSNormalWindowLevel];
  357. return true;
  358. }
  359. void toFront (bool makeActiveWindow) override
  360. {
  361. if (isSharedWindow)
  362. [[view superview] addSubview: view
  363. positioned: NSWindowAbove
  364. relativeTo: nil];
  365. if (window != nil && component.isVisible())
  366. {
  367. ++insideToFrontCall;
  368. if (makeActiveWindow)
  369. [window makeKeyAndOrderFront: nil];
  370. else
  371. [window orderFront: nil];
  372. if (insideToFrontCall <= 1)
  373. {
  374. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  375. handleBroughtToFront();
  376. }
  377. --insideToFrontCall;
  378. }
  379. }
  380. void toBehind (ComponentPeer* other) override
  381. {
  382. NSViewComponentPeer* const otherPeer = dynamic_cast <NSViewComponentPeer*> (other);
  383. jassert (otherPeer != nullptr); // wrong type of window?
  384. if (otherPeer != nullptr)
  385. {
  386. if (isSharedWindow)
  387. {
  388. [[view superview] addSubview: view
  389. positioned: NSWindowBelow
  390. relativeTo: otherPeer->view];
  391. }
  392. else
  393. {
  394. [window orderWindow: NSWindowBelow
  395. relativeTo: [otherPeer->window windowNumber]];
  396. }
  397. }
  398. }
  399. void setIcon (const Image&) override
  400. {
  401. // to do..
  402. }
  403. StringArray getAvailableRenderingEngines() override
  404. {
  405. StringArray s ("Software Renderer");
  406. #if USE_COREGRAPHICS_RENDERING
  407. s.add ("CoreGraphics Renderer");
  408. #endif
  409. return s;
  410. }
  411. int getCurrentRenderingEngine() const override
  412. {
  413. return usingCoreGraphics ? 1 : 0;
  414. }
  415. void setCurrentRenderingEngine (int index) override
  416. {
  417. #if USE_COREGRAPHICS_RENDERING
  418. if (usingCoreGraphics != (index > 0))
  419. {
  420. usingCoreGraphics = index > 0;
  421. [view setNeedsDisplay: true];
  422. }
  423. #endif
  424. }
  425. void redirectMouseDown (NSEvent* ev)
  426. {
  427. if (! Process::isForegroundProcess())
  428. Process::makeForegroundProcess();
  429. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  430. sendMouseEvent (ev);
  431. }
  432. void redirectMouseUp (NSEvent* ev)
  433. {
  434. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  435. sendMouseEvent (ev);
  436. showArrowCursorIfNeeded();
  437. }
  438. void redirectMouseDrag (NSEvent* ev)
  439. {
  440. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  441. sendMouseEvent (ev);
  442. }
  443. void redirectMouseMove (NSEvent* ev)
  444. {
  445. currentModifiers = currentModifiers.withoutMouseButtons();
  446. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  447. if ([NSWindow respondsToSelector: @selector (windowNumberAtPoint:belowWindowWithWindowNumber:)]
  448. && [NSWindow windowNumberAtPoint: [[ev window] convertBaseToScreen: [ev locationInWindow]]
  449. belowWindowWithWindowNumber: 0] != [window windowNumber])
  450. {
  451. // moved into another window which overlaps this one, so trigger an exit
  452. handleMouseEvent (0, Point<int> (-1, -1), currentModifiers, getMouseTime (ev));
  453. }
  454. else
  455. #endif
  456. {
  457. sendMouseEvent (ev);
  458. }
  459. showArrowCursorIfNeeded();
  460. }
  461. void redirectMouseEnter (NSEvent* ev)
  462. {
  463. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  464. currentModifiers = currentModifiers.withoutMouseButtons();
  465. sendMouseEvent (ev);
  466. }
  467. void redirectMouseExit (NSEvent* ev)
  468. {
  469. currentModifiers = currentModifiers.withoutMouseButtons();
  470. sendMouseEvent (ev);
  471. }
  472. static float checkDeviceDeltaReturnValue (float v) noexcept
  473. {
  474. // (deviceDeltaX can fail and return NaN, so need to sanity-check the result)
  475. v *= 0.5f / 256.0f;
  476. return (v > -1000.0f && v < 1000.0f) ? v : 0.0f;
  477. }
  478. void redirectMouseWheel (NSEvent* ev)
  479. {
  480. updateModifiers (ev);
  481. MouseWheelDetails wheel;
  482. wheel.deltaX = 0;
  483. wheel.deltaY = 0;
  484. wheel.isReversed = false;
  485. wheel.isSmooth = false;
  486. #if ! JUCE_PPC
  487. @try
  488. {
  489. #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
  490. if ([ev respondsToSelector: @selector (isDirectionInvertedFromDevice)])
  491. wheel.isReversed = [ev isDirectionInvertedFromDevice];
  492. if ([ev respondsToSelector: @selector (hasPreciseScrollingDeltas)])
  493. {
  494. if ([ev hasPreciseScrollingDeltas])
  495. {
  496. const float scale = 0.5f / 256.0f;
  497. wheel.deltaX = [ev scrollingDeltaX] * scale;
  498. wheel.deltaY = [ev scrollingDeltaY] * scale;
  499. wheel.isSmooth = true;
  500. }
  501. }
  502. else
  503. #endif
  504. if ([ev respondsToSelector: @selector (deviceDeltaX)])
  505. {
  506. wheel.deltaX = checkDeviceDeltaReturnValue ((float) objc_msgSend_fpret (ev, @selector (deviceDeltaX)));
  507. wheel.deltaY = checkDeviceDeltaReturnValue ((float) objc_msgSend_fpret (ev, @selector (deviceDeltaY)));
  508. }
  509. }
  510. @catch (...)
  511. {}
  512. #endif
  513. if (wheel.deltaX == 0 && wheel.deltaY == 0)
  514. {
  515. const float scale = 10.0f / 256.0f;
  516. wheel.deltaX = [ev deltaX] * scale;
  517. wheel.deltaY = [ev deltaY] * scale;
  518. }
  519. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev), wheel);
  520. }
  521. void redirectMagnify (NSEvent* ev)
  522. {
  523. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  524. const float invScale = 1.0f - [ev magnification];
  525. if (invScale != 0.0f)
  526. handleMagnifyGesture (0, getMousePos (ev, view), getMouseTime (ev), 1.0f / invScale);
  527. #endif
  528. (void) ev;
  529. }
  530. void sendMouseEvent (NSEvent* ev)
  531. {
  532. updateModifiers (ev);
  533. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  534. }
  535. bool handleKeyEvent (NSEvent* ev, bool isKeyDown)
  536. {
  537. const String unicode (nsStringToJuce ([ev characters]));
  538. const int keyCode = getKeyCodeFromEvent (ev);
  539. #if JUCE_DEBUG_KEYCODES
  540. DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  541. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  542. DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  543. #endif
  544. if (keyCode != 0 || unicode.isNotEmpty())
  545. {
  546. if (isKeyDown)
  547. {
  548. bool used = false;
  549. for (String::CharPointerType u (unicode.getCharPointer()); ! u.isEmpty();)
  550. {
  551. juce_wchar textCharacter = u.getAndAdvance();
  552. switch (keyCode)
  553. {
  554. case NSLeftArrowFunctionKey:
  555. case NSRightArrowFunctionKey:
  556. case NSUpArrowFunctionKey:
  557. case NSDownArrowFunctionKey:
  558. case NSPageUpFunctionKey:
  559. case NSPageDownFunctionKey:
  560. case NSEndFunctionKey:
  561. case NSHomeFunctionKey:
  562. case NSDeleteFunctionKey:
  563. textCharacter = 0;
  564. break; // (these all seem to generate unwanted garbage unicode strings)
  565. default:
  566. if (([ev modifierFlags] & NSCommandKeyMask) != 0
  567. || (keyCode >= NSF1FunctionKey && keyCode <= NSF35FunctionKey))
  568. textCharacter = 0;
  569. break;
  570. }
  571. used = handleKeyUpOrDown (true) || used;
  572. used = handleKeyPress (keyCode, textCharacter) || used;
  573. }
  574. return used;
  575. }
  576. if (handleKeyUpOrDown (false))
  577. return true;
  578. }
  579. return false;
  580. }
  581. bool redirectKeyDown (NSEvent* ev)
  582. {
  583. // (need to retain this in case a modal loop runs in handleKeyEvent and
  584. // our event object gets lost)
  585. const NSObjectRetainer<NSEvent> r (ev);
  586. updateKeysDown (ev, true);
  587. bool used = handleKeyEvent (ev, true);
  588. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  589. {
  590. // for command keys, the key-up event is thrown away, so simulate one..
  591. updateKeysDown (ev, false);
  592. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  593. }
  594. // (If we're running modally, don't allow unused keystrokes to be passed
  595. // along to other blocked views..)
  596. if (Component::getCurrentlyModalComponent() != nullptr)
  597. used = true;
  598. return used;
  599. }
  600. bool redirectKeyUp (NSEvent* ev)
  601. {
  602. updateKeysDown (ev, false);
  603. return handleKeyEvent (ev, false)
  604. || Component::getCurrentlyModalComponent() != nullptr;
  605. }
  606. void redirectModKeyChange (NSEvent* ev)
  607. {
  608. // (need to retain this in case a modal loop runs and our event object gets lost)
  609. const NSObjectRetainer<NSEvent> r (ev);
  610. keysCurrentlyDown.clear();
  611. handleKeyUpOrDown (true);
  612. updateModifiers (ev);
  613. handleModifierKeysChange();
  614. }
  615. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  616. bool redirectPerformKeyEquivalent (NSEvent* ev)
  617. {
  618. if ([ev type] == NSKeyDown) return redirectKeyDown (ev);
  619. if ([ev type] == NSKeyUp) return redirectKeyUp (ev);
  620. return false;
  621. }
  622. #endif
  623. void drawRect (NSRect r)
  624. {
  625. if (r.size.width < 1.0f || r.size.height < 1.0f)
  626. return;
  627. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  628. if (! component.isOpaque())
  629. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  630. float displayScale = 1.0f;
  631. #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
  632. NSScreen* screen = [[view window] screen];
  633. if ([screen respondsToSelector: @selector (backingScaleFactor)])
  634. displayScale = screen.backingScaleFactor;
  635. #endif
  636. #if USE_COREGRAPHICS_RENDERING
  637. if (usingCoreGraphics)
  638. {
  639. CoreGraphicsContext context (cg, (float) [view frame].size.height, displayScale);
  640. insideDrawRect = true;
  641. handlePaint (context);
  642. insideDrawRect = false;
  643. }
  644. else
  645. #endif
  646. {
  647. const Point<int> offset (-roundToInt (r.origin.x),
  648. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  649. const int clipW = (int) (r.size.width + 0.5f);
  650. const int clipH = (int) (r.size.height + 0.5f);
  651. RectangleList<int> clip;
  652. getClipRects (clip, offset, clipW, clipH);
  653. if (! clip.isEmpty())
  654. {
  655. Image temp (component.isOpaque() ? Image::RGB : Image::ARGB,
  656. roundToInt (clipW * displayScale),
  657. roundToInt (clipH * displayScale),
  658. ! component.isOpaque());
  659. {
  660. const int intScale = roundToInt (displayScale);
  661. if (intScale != 1)
  662. clip.scaleAll (intScale);
  663. ScopedPointer<LowLevelGraphicsContext> context (component.getLookAndFeel()
  664. .createGraphicsContext (temp, offset * intScale, clip));
  665. if (intScale != 1)
  666. context->addTransform (AffineTransform::scale (displayScale));
  667. insideDrawRect = true;
  668. handlePaint (*context);
  669. insideDrawRect = false;
  670. }
  671. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  672. CGImageRef image = juce_createCoreGraphicsImage (temp, colourSpace, false);
  673. CGColorSpaceRelease (colourSpace);
  674. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, clipW, clipH), image);
  675. CGImageRelease (image);
  676. }
  677. }
  678. }
  679. bool sendModalInputAttemptIfBlocked()
  680. {
  681. Component* const modal = Component::getCurrentlyModalComponent();
  682. if (modal != nullptr
  683. && insideToFrontCall == 0
  684. && (! getComponent().isParentOf (modal))
  685. && getComponent().isCurrentlyBlockedByAnotherModalComponent())
  686. {
  687. modal->inputAttemptWhenModal();
  688. return true;
  689. }
  690. return false;
  691. }
  692. bool canBecomeKeyWindow()
  693. {
  694. return (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0;
  695. }
  696. void becomeKeyWindow()
  697. {
  698. handleBroughtToFront();
  699. grabFocus();
  700. }
  701. bool windowShouldClose()
  702. {
  703. if (! isValidPeer (this))
  704. return YES;
  705. handleUserClosingWindow();
  706. return NO;
  707. }
  708. void redirectMovedOrResized()
  709. {
  710. updateFullscreenStatus();
  711. handleMovedOrResized();
  712. }
  713. void viewMovedToWindow()
  714. {
  715. if (isSharedWindow)
  716. window = [view window];
  717. }
  718. void liveResizingStart()
  719. {
  720. if (constrainer != nullptr)
  721. constrainer->resizeStart();
  722. }
  723. void liveResizingEnd()
  724. {
  725. if (constrainer != nullptr)
  726. constrainer->resizeEnd();
  727. }
  728. NSRect constrainRect (NSRect r)
  729. {
  730. if (constrainer != nullptr
  731. #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
  732. && ([window styleMask] & NSFullScreenWindowMask) == 0
  733. #endif
  734. )
  735. {
  736. Rectangle<int> pos (convertToRectInt (flippedScreenRect (r)));
  737. Rectangle<int> original (convertToRectInt (flippedScreenRect ([window frame])));
  738. const Rectangle<int> screenBounds (Desktop::getInstance().getDisplays().getTotalBounds (true));
  739. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  740. if ([window inLiveResize])
  741. #else
  742. if ([window respondsToSelector: @selector (inLiveResize)]
  743. && [window performSelector: @selector (inLiveResize)])
  744. #endif
  745. {
  746. constrainer->checkBounds (pos, original, screenBounds,
  747. false, false, true, true);
  748. }
  749. else
  750. {
  751. constrainer->checkBounds (pos, original, screenBounds,
  752. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  753. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  754. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  755. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  756. }
  757. r = flippedScreenRect (makeNSRect (pos));
  758. }
  759. return r;
  760. }
  761. static void showArrowCursorIfNeeded()
  762. {
  763. Desktop& desktop = Desktop::getInstance();
  764. MouseInputSource mouse = desktop.getMainMouseSource();
  765. if (mouse.getComponentUnderMouse() == nullptr
  766. && desktop.findComponentAt (mouse.getScreenPosition()) == nullptr)
  767. {
  768. [[NSCursor arrowCursor] set];
  769. }
  770. }
  771. static void updateModifiers (NSEvent* e)
  772. {
  773. updateModifiers ([e modifierFlags]);
  774. }
  775. static void updateModifiers (const NSUInteger flags)
  776. {
  777. int m = 0;
  778. if ((flags & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  779. if ((flags & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  780. if ((flags & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  781. if ((flags & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  782. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  783. }
  784. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  785. {
  786. updateModifiers (ev);
  787. int keyCode = getKeyCodeFromEvent (ev);
  788. if (keyCode != 0)
  789. {
  790. if (isKeyDown)
  791. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  792. else
  793. keysCurrentlyDown.removeFirstMatchingValue (keyCode);
  794. }
  795. }
  796. static int getKeyCodeFromEvent (NSEvent* ev)
  797. {
  798. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  799. int keyCode = unmodified[0];
  800. if (keyCode == 0x19) // (backwards-tab)
  801. keyCode = '\t';
  802. else if (keyCode == 0x03) // (enter)
  803. keyCode = '\r';
  804. else
  805. keyCode = (int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  806. if (([ev modifierFlags] & NSNumericPadKeyMask) != 0)
  807. {
  808. const int numPadConversions[] = { '0', KeyPress::numberPad0, '1', KeyPress::numberPad1,
  809. '2', KeyPress::numberPad2, '3', KeyPress::numberPad3,
  810. '4', KeyPress::numberPad4, '5', KeyPress::numberPad5,
  811. '6', KeyPress::numberPad6, '7', KeyPress::numberPad7,
  812. '8', KeyPress::numberPad8, '9', KeyPress::numberPad9,
  813. '+', KeyPress::numberPadAdd, '-', KeyPress::numberPadSubtract,
  814. '*', KeyPress::numberPadMultiply, '/', KeyPress::numberPadDivide,
  815. '.', KeyPress::numberPadDecimalPoint, '=', KeyPress::numberPadEquals };
  816. for (int i = 0; i < numElementsInArray (numPadConversions); i += 2)
  817. if (keyCode == numPadConversions [i])
  818. keyCode = numPadConversions [i + 1];
  819. }
  820. return keyCode;
  821. }
  822. static int64 getMouseTime (NSEvent* e)
  823. {
  824. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  825. + (int64) ([e timestamp] * 1000.0);
  826. }
  827. static Point<int> getMousePos (NSEvent* e, NSView* view)
  828. {
  829. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  830. return Point<int> ((int) p.x, (int) ([view frame].size.height - p.y));
  831. }
  832. static int getModifierForButtonNumber (const NSInteger num)
  833. {
  834. return num == 0 ? ModifierKeys::leftButtonModifier
  835. : (num == 1 ? ModifierKeys::rightButtonModifier
  836. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  837. }
  838. static unsigned int getNSWindowStyleMask (const int flags) noexcept
  839. {
  840. unsigned int style = (flags & windowHasTitleBar) != 0 ? NSTitledWindowMask
  841. : NSBorderlessWindowMask;
  842. if ((flags & windowHasMinimiseButton) != 0) style |= NSMiniaturizableWindowMask;
  843. if ((flags & windowHasCloseButton) != 0) style |= NSClosableWindowMask;
  844. if ((flags & windowIsResizable) != 0) style |= NSResizableWindowMask;
  845. return style;
  846. }
  847. static NSArray* getSupportedDragTypes()
  848. {
  849. return [NSArray arrayWithObjects: NSFilenamesPboardType, NSFilesPromisePboardType, NSStringPboardType, nil];
  850. }
  851. BOOL sendDragCallback (const int type, id <NSDraggingInfo> sender)
  852. {
  853. NSPasteboard* pasteboard = [sender draggingPasteboard];
  854. NSString* contentType = [pasteboard availableTypeFromArray: getSupportedDragTypes()];
  855. if (contentType == nil)
  856. return false;
  857. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  858. ComponentPeer::DragInfo dragInfo;
  859. dragInfo.position.setXY ((int) p.x, (int) ([view frame].size.height - p.y));
  860. if (contentType == NSStringPboardType)
  861. dragInfo.text = nsStringToJuce ([pasteboard stringForType: NSStringPboardType]);
  862. else
  863. dragInfo.files = getDroppedFiles (pasteboard, contentType);
  864. if (! dragInfo.isEmpty())
  865. {
  866. switch (type)
  867. {
  868. case 0: return handleDragMove (dragInfo);
  869. case 1: return handleDragExit (dragInfo);
  870. case 2: return handleDragDrop (dragInfo);
  871. default: jassertfalse; break;
  872. }
  873. }
  874. return false;
  875. }
  876. StringArray getDroppedFiles (NSPasteboard* pasteboard, NSString* contentType)
  877. {
  878. StringArray files;
  879. NSString* iTunesPasteboardType = nsStringLiteral ("CorePasteboardFlavorType 0x6974756E"); // 'itun'
  880. if (contentType == NSFilesPromisePboardType
  881. && [[pasteboard types] containsObject: iTunesPasteboardType])
  882. {
  883. id list = [pasteboard propertyListForType: iTunesPasteboardType];
  884. if ([list isKindOfClass: [NSDictionary class]])
  885. {
  886. NSDictionary* iTunesDictionary = (NSDictionary*) list;
  887. NSArray* tracks = [iTunesDictionary valueForKey: nsStringLiteral ("Tracks")];
  888. NSEnumerator* enumerator = [tracks objectEnumerator];
  889. NSDictionary* track;
  890. while ((track = [enumerator nextObject]) != nil)
  891. {
  892. NSURL* url = [NSURL URLWithString: [track valueForKey: nsStringLiteral ("Location")]];
  893. if ([url isFileURL])
  894. files.add (nsStringToJuce ([url path]));
  895. }
  896. }
  897. }
  898. else
  899. {
  900. id list = [pasteboard propertyListForType: NSFilenamesPboardType];
  901. if ([list isKindOfClass: [NSArray class]])
  902. {
  903. NSArray* items = (NSArray*) [pasteboard propertyListForType: NSFilenamesPboardType];
  904. for (unsigned int i = 0; i < [items count]; ++i)
  905. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  906. }
  907. }
  908. return files;
  909. }
  910. //==============================================================================
  911. void viewFocusGain()
  912. {
  913. if (currentlyFocusedPeer != this)
  914. {
  915. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  916. currentlyFocusedPeer->handleFocusLoss();
  917. currentlyFocusedPeer = this;
  918. handleFocusGain();
  919. }
  920. }
  921. void viewFocusLoss()
  922. {
  923. if (currentlyFocusedPeer == this)
  924. {
  925. currentlyFocusedPeer = nullptr;
  926. handleFocusLoss();
  927. }
  928. }
  929. bool isFocused() const override
  930. {
  931. return isSharedWindow ? this == currentlyFocusedPeer
  932. : [window isKeyWindow];
  933. }
  934. void grabFocus() override
  935. {
  936. if (window != nil)
  937. {
  938. [window makeKeyWindow];
  939. [window makeFirstResponder: view];
  940. viewFocusGain();
  941. }
  942. }
  943. void textInputRequired (const Point<int>&) override {}
  944. //==============================================================================
  945. void repaint (const Rectangle<int>& area) override
  946. {
  947. if (insideDrawRect)
  948. {
  949. class AsyncRepaintMessage : public CallbackMessage
  950. {
  951. public:
  952. AsyncRepaintMessage (NSViewComponentPeer* const p, const Rectangle<int>& r)
  953. : peer (p), rect (r)
  954. {}
  955. void messageCallback() override
  956. {
  957. if (ComponentPeer::isValidPeer (peer))
  958. peer->repaint (rect);
  959. }
  960. private:
  961. NSViewComponentPeer* const peer;
  962. const Rectangle<int> rect;
  963. };
  964. (new AsyncRepaintMessage (this, area))->post();
  965. }
  966. else
  967. {
  968. [view setNeedsDisplayInRect: NSMakeRect ((CGFloat) area.getX(), [view frame].size.height - (CGFloat) area.getBottom(),
  969. (CGFloat) area.getWidth(), (CGFloat) area.getHeight())];
  970. }
  971. }
  972. void performAnyPendingRepaintsNow() override
  973. {
  974. [view displayIfNeeded];
  975. }
  976. //==============================================================================
  977. NSWindow* window;
  978. NSView* view;
  979. bool isSharedWindow, fullScreen, insideDrawRect;
  980. bool usingCoreGraphics, isZooming, textWasInserted;
  981. String stringBeingComposed;
  982. NSNotificationCenter* notificationCenter;
  983. static ModifierKeys currentModifiers;
  984. static ComponentPeer* currentlyFocusedPeer;
  985. static Array<int> keysCurrentlyDown;
  986. static int insideToFrontCall;
  987. private:
  988. static NSView* createViewInstance();
  989. static NSWindow* createWindowInstance();
  990. static void setOwner (id viewOrWindow, NSViewComponentPeer* newOwner)
  991. {
  992. object_setInstanceVariable (viewOrWindow, "owner", newOwner);
  993. }
  994. void getClipRects (RectangleList<int>& clip, const Point<int> offset, const int clipW, const int clipH)
  995. {
  996. const NSRect* rects = nullptr;
  997. NSInteger numRects = 0;
  998. [view getRectsBeingDrawn: &rects count: &numRects];
  999. const Rectangle<int> clipBounds (clipW, clipH);
  1000. const CGFloat viewH = [view frame].size.height;
  1001. for (int i = 0; i < numRects; ++i)
  1002. clip.addWithoutMerging (clipBounds.getIntersection (Rectangle<int> (roundToInt (rects[i].origin.x) + offset.x,
  1003. roundToInt (viewH - (rects[i].origin.y + rects[i].size.height)) + offset.y,
  1004. roundToInt (rects[i].size.width),
  1005. roundToInt (rects[i].size.height))));
  1006. }
  1007. static void appFocusChanged()
  1008. {
  1009. keysCurrentlyDown.clear();
  1010. if (isValidPeer (currentlyFocusedPeer))
  1011. {
  1012. if (Process::isForegroundProcess())
  1013. {
  1014. currentlyFocusedPeer->handleFocusGain();
  1015. ModalComponentManager::getInstance()->bringModalComponentsToFront();
  1016. }
  1017. else
  1018. {
  1019. currentlyFocusedPeer->handleFocusLoss();
  1020. }
  1021. }
  1022. }
  1023. static bool checkEventBlockedByModalComps (NSEvent* e)
  1024. {
  1025. if (Component::getNumCurrentlyModalComponents() == 0)
  1026. return false;
  1027. NSWindow* const w = [e window];
  1028. if (w == nil || [w worksWhenModal])
  1029. return false;
  1030. bool isKey = false, isInputAttempt = false;
  1031. switch ([e type])
  1032. {
  1033. case NSKeyDown:
  1034. case NSKeyUp:
  1035. isKey = isInputAttempt = true;
  1036. break;
  1037. case NSLeftMouseDown:
  1038. case NSRightMouseDown:
  1039. case NSOtherMouseDown:
  1040. isInputAttempt = true;
  1041. break;
  1042. case NSLeftMouseDragged:
  1043. case NSRightMouseDragged:
  1044. case NSLeftMouseUp:
  1045. case NSRightMouseUp:
  1046. case NSOtherMouseUp:
  1047. case NSOtherMouseDragged:
  1048. if (Desktop::getInstance().getDraggingMouseSource(0) != nullptr)
  1049. return false;
  1050. break;
  1051. case NSMouseMoved:
  1052. case NSMouseEntered:
  1053. case NSMouseExited:
  1054. case NSCursorUpdate:
  1055. case NSScrollWheel:
  1056. case NSTabletPoint:
  1057. case NSTabletProximity:
  1058. break;
  1059. default:
  1060. return false;
  1061. }
  1062. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  1063. {
  1064. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  1065. NSView* const compView = (NSView*) peer->getNativeHandle();
  1066. if ([compView window] == w)
  1067. {
  1068. if (isKey)
  1069. {
  1070. if (compView == [w firstResponder])
  1071. return false;
  1072. }
  1073. else
  1074. {
  1075. NSViewComponentPeer* nsViewPeer = dynamic_cast<NSViewComponentPeer*> (peer);
  1076. if ((nsViewPeer == nullptr || ! nsViewPeer->isSharedWindow)
  1077. ? NSPointInRect ([e locationInWindow], NSMakeRect (0, 0, [w frame].size.width, [w frame].size.height))
  1078. : NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil], [compView bounds]))
  1079. return false;
  1080. }
  1081. }
  1082. }
  1083. if (isInputAttempt)
  1084. {
  1085. if (! [NSApp isActive])
  1086. [NSApp activateIgnoringOtherApps: YES];
  1087. if (Component* const modal = Component::getCurrentlyModalComponent())
  1088. modal->inputAttemptWhenModal();
  1089. }
  1090. return true;
  1091. }
  1092. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer)
  1093. };
  1094. int NSViewComponentPeer::insideToFrontCall = 0;
  1095. //==============================================================================
  1096. struct JuceNSViewClass : public ObjCClass <NSView>
  1097. {
  1098. JuceNSViewClass() : ObjCClass <NSView> ("JUCEView_")
  1099. {
  1100. addIvar<NSViewComponentPeer*> ("owner");
  1101. addMethod (@selector (isOpaque), isOpaque, "c@:");
  1102. addMethod (@selector (drawRect:), drawRect, "v@:", @encode (NSRect));
  1103. addMethod (@selector (mouseDown:), mouseDown, "v@:@");
  1104. addMethod (@selector (asyncMouseDown:), asyncMouseDown, "v@:@");
  1105. addMethod (@selector (mouseUp:), mouseUp, "v@:@");
  1106. addMethod (@selector (asyncMouseUp:), asyncMouseUp, "v@:@");
  1107. addMethod (@selector (mouseDragged:), mouseDragged, "v@:@");
  1108. addMethod (@selector (mouseMoved:), mouseMoved, "v@:@");
  1109. addMethod (@selector (mouseEntered:), mouseEntered, "v@:@");
  1110. addMethod (@selector (mouseExited:), mouseExited, "v@:@");
  1111. addMethod (@selector (rightMouseDown:), mouseDown, "v@:@");
  1112. addMethod (@selector (rightMouseDragged:), mouseDragged, "v@:@");
  1113. addMethod (@selector (rightMouseUp:), mouseUp, "v@:@");
  1114. addMethod (@selector (otherMouseDown:), mouseDown, "v@:@");
  1115. addMethod (@selector (otherMouseDragged:), mouseDragged, "v@:@");
  1116. addMethod (@selector (otherMouseUp:), mouseUp, "v@:@");
  1117. addMethod (@selector (scrollWheel:), scrollWheel, "v@:@");
  1118. addMethod (@selector (magnifyWithEvent:), magnify, "v@:@");
  1119. addMethod (@selector (acceptsFirstMouse:), acceptsFirstMouse, "v@:@");
  1120. addMethod (@selector (frameChanged:), frameChanged, "v@:@");
  1121. addMethod (@selector (viewDidMoveToWindow), viewDidMoveToWindow, "v@:");
  1122. addMethod (@selector (keyDown:), keyDown, "v@:@");
  1123. addMethod (@selector (keyUp:), keyUp, "v@:@");
  1124. addMethod (@selector (insertText:), insertText, "v@:@");
  1125. addMethod (@selector (doCommandBySelector:), doCommandBySelector, "v@::");
  1126. addMethod (@selector (setMarkedText:selectedRange:), setMarkedText, "v@:@", @encode (NSRange));
  1127. addMethod (@selector (unmarkText), unmarkText, "v@:");
  1128. addMethod (@selector (hasMarkedText), hasMarkedText, "c@:");
  1129. addMethod (@selector (conversationIdentifier), conversationIdentifier, "l@:");
  1130. addMethod (@selector (attributedSubstringFromRange:), attributedSubstringFromRange, "@@:", @encode (NSRange));
  1131. addMethod (@selector (markedRange), markedRange, @encode (NSRange), "@:");
  1132. addMethod (@selector (selectedRange), selectedRange, @encode (NSRange), "@:");
  1133. addMethod (@selector (firstRectForCharacterRange:), firstRectForCharacterRange, @encode (NSRect), "@:", @encode (NSRange));
  1134. addMethod (@selector (validAttributesForMarkedText), validAttributesForMarkedText, "@@:");
  1135. addMethod (@selector (flagsChanged:), flagsChanged, "v@:@");
  1136. addMethod (@selector (becomeFirstResponder), becomeFirstResponder, "c@:");
  1137. addMethod (@selector (resignFirstResponder), resignFirstResponder, "c@:");
  1138. addMethod (@selector (acceptsFirstResponder), acceptsFirstResponder, "c@:");
  1139. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  1140. addMethod (@selector (performKeyEquivalent:), performKeyEquivalent, "c@:@");
  1141. #endif
  1142. addMethod (@selector (draggingEntered:), draggingEntered, @encode (NSDragOperation), "@:@");
  1143. addMethod (@selector (draggingUpdated:), draggingUpdated, @encode (NSDragOperation), "@:@");
  1144. addMethod (@selector (draggingEnded:), draggingEnded, "v@:@");
  1145. addMethod (@selector (draggingExited:), draggingExited, "v@:@");
  1146. addMethod (@selector (prepareForDragOperation:), prepareForDragOperation, "c@:@");
  1147. addMethod (@selector (performDragOperation:), performDragOperation, "c@:@");
  1148. addMethod (@selector (concludeDragOperation:), concludeDragOperation, "v@:@");
  1149. addProtocol (@protocol (NSTextInput));
  1150. registerClass();
  1151. }
  1152. private:
  1153. static NSViewComponentPeer* getOwner (id self)
  1154. {
  1155. return getIvar<NSViewComponentPeer*> (self, "owner");
  1156. }
  1157. static void mouseDown (id self, SEL s, NSEvent* ev)
  1158. {
  1159. if (JUCEApplicationBase::isStandaloneApp())
  1160. asyncMouseDown (self, s, ev);
  1161. else
  1162. // In some host situations, the host will stop modal loops from working
  1163. // correctly if they're called from a mouse event, so we'll trigger
  1164. // the event asynchronously..
  1165. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  1166. withObject: ev
  1167. waitUntilDone: NO];
  1168. }
  1169. static void mouseUp (id self, SEL s, NSEvent* ev)
  1170. {
  1171. if (JUCEApplicationBase::isStandaloneApp())
  1172. asyncMouseUp (self, s, ev);
  1173. else
  1174. // In some host situations, the host will stop modal loops from working
  1175. // correctly if they're called from a mouse event, so we'll trigger
  1176. // the event asynchronously..
  1177. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  1178. withObject: ev
  1179. waitUntilDone: NO];
  1180. }
  1181. static void asyncMouseDown (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseDown (ev); }
  1182. static void asyncMouseUp (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseUp (ev); }
  1183. static void mouseDragged (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseDrag (ev); }
  1184. static void mouseMoved (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseMove (ev); }
  1185. static void mouseEntered (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseEnter (ev); }
  1186. static void mouseExited (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseExit (ev); }
  1187. static void scrollWheel (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseWheel (ev); }
  1188. static void magnify (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMagnify (ev); }
  1189. static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; }
  1190. static void drawRect (id self, SEL, NSRect r) { if (NSViewComponentPeer* const p = getOwner (self)) p->drawRect (r); }
  1191. static void frameChanged (id self, SEL, NSNotification*) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMovedOrResized(); }
  1192. static void viewDidMoveToWindow (id self, SEL) { if (NSViewComponentPeer* const p = getOwner (self)) p->viewMovedToWindow(); }
  1193. static BOOL isOpaque (id self, SEL)
  1194. {
  1195. NSViewComponentPeer* const owner = getOwner (self);
  1196. return owner == nullptr || owner->getComponent().isOpaque();
  1197. }
  1198. //==============================================================================
  1199. static void keyDown (id self, SEL, NSEvent* ev)
  1200. {
  1201. if (NSViewComponentPeer* const owner = getOwner (self))
  1202. {
  1203. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  1204. owner->textWasInserted = false;
  1205. if (target != nullptr)
  1206. [(NSView*) self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  1207. else
  1208. owner->stringBeingComposed = String::empty;
  1209. if ((! owner->textWasInserted) && (owner == nullptr || ! owner->redirectKeyDown (ev)))
  1210. {
  1211. objc_super s = { self, [NSView class] };
  1212. objc_msgSendSuper (&s, @selector (keyDown:), ev);
  1213. }
  1214. }
  1215. }
  1216. static void keyUp (id self, SEL, NSEvent* ev)
  1217. {
  1218. NSViewComponentPeer* const owner = getOwner (self);
  1219. if (owner == nullptr || ! owner->redirectKeyUp (ev))
  1220. {
  1221. objc_super s = { self, [NSView class] };
  1222. objc_msgSendSuper (&s, @selector (keyUp:), ev);
  1223. }
  1224. }
  1225. //==============================================================================
  1226. static void insertText (id self, SEL, id aString)
  1227. {
  1228. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  1229. if (NSViewComponentPeer* const owner = getOwner (self))
  1230. {
  1231. NSString* newText = [aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString;
  1232. if ([newText length] > 0)
  1233. {
  1234. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1235. {
  1236. target->insertTextAtCaret (nsStringToJuce (newText));
  1237. owner->textWasInserted = true;
  1238. }
  1239. }
  1240. owner->stringBeingComposed = String::empty;
  1241. }
  1242. }
  1243. static void doCommandBySelector (id, SEL, SEL) {}
  1244. static void setMarkedText (id self, SEL, id aString, NSRange)
  1245. {
  1246. if (NSViewComponentPeer* const owner = getOwner (self))
  1247. {
  1248. owner->stringBeingComposed = nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]]
  1249. ? [aString string] : aString);
  1250. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1251. {
  1252. const Range<int> currentHighlight (target->getHighlightedRegion());
  1253. target->insertTextAtCaret (owner->stringBeingComposed);
  1254. target->setHighlightedRegion (currentHighlight.withLength (owner->stringBeingComposed.length()));
  1255. owner->textWasInserted = true;
  1256. }
  1257. }
  1258. }
  1259. static void unmarkText (id self, SEL)
  1260. {
  1261. if (NSViewComponentPeer* const owner = getOwner (self))
  1262. {
  1263. if (owner->stringBeingComposed.isNotEmpty())
  1264. {
  1265. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1266. {
  1267. target->insertTextAtCaret (owner->stringBeingComposed);
  1268. owner->textWasInserted = true;
  1269. }
  1270. owner->stringBeingComposed = String::empty;
  1271. }
  1272. }
  1273. }
  1274. static BOOL hasMarkedText (id self, SEL)
  1275. {
  1276. NSViewComponentPeer* const owner = getOwner (self);
  1277. return owner != nullptr && owner->stringBeingComposed.isNotEmpty();
  1278. }
  1279. static long conversationIdentifier (id self, SEL)
  1280. {
  1281. return (long) (pointer_sized_int) self;
  1282. }
  1283. static NSAttributedString* attributedSubstringFromRange (id self, SEL, NSRange theRange)
  1284. {
  1285. if (NSViewComponentPeer* const owner = getOwner (self))
  1286. {
  1287. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1288. {
  1289. const Range<int> r ((int) theRange.location,
  1290. (int) (theRange.location + theRange.length));
  1291. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  1292. }
  1293. }
  1294. return nil;
  1295. }
  1296. static NSRange markedRange (id self, SEL)
  1297. {
  1298. if (NSViewComponentPeer* const owner = getOwner (self))
  1299. if (owner->stringBeingComposed.isNotEmpty())
  1300. return NSMakeRange (0, (NSUInteger) owner->stringBeingComposed.length());
  1301. return NSMakeRange (NSNotFound, 0);
  1302. }
  1303. static NSRange selectedRange (id self, SEL)
  1304. {
  1305. if (NSViewComponentPeer* const owner = getOwner (self))
  1306. {
  1307. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1308. {
  1309. const Range<int> highlight (target->getHighlightedRegion());
  1310. if (! highlight.isEmpty())
  1311. return NSMakeRange ((NSUInteger) highlight.getStart(),
  1312. (NSUInteger) highlight.getLength());
  1313. }
  1314. }
  1315. return NSMakeRange (NSNotFound, 0);
  1316. }
  1317. static NSRect firstRectForCharacterRange (id self, SEL, NSRange)
  1318. {
  1319. if (NSViewComponentPeer* const owner = getOwner (self))
  1320. if (Component* const comp = dynamic_cast <Component*> (owner->findCurrentTextInputTarget()))
  1321. return flippedScreenRect (makeNSRect (comp->getScreenBounds()));
  1322. return NSZeroRect;
  1323. }
  1324. static NSUInteger characterIndexForPoint (id, SEL, NSPoint) { return NSNotFound; }
  1325. static NSArray* validAttributesForMarkedText (id, SEL) { return [NSArray array]; }
  1326. //==============================================================================
  1327. static void flagsChanged (id self, SEL, NSEvent* ev)
  1328. {
  1329. if (NSViewComponentPeer* const owner = getOwner (self))
  1330. owner->redirectModKeyChange (ev);
  1331. }
  1332. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  1333. static BOOL performKeyEquivalent (id self, SEL, NSEvent* ev)
  1334. {
  1335. if (NSViewComponentPeer* const owner = getOwner (self))
  1336. if (owner->redirectPerformKeyEquivalent (ev))
  1337. return true;
  1338. objc_super s = { self, [NSView class] };
  1339. return objc_msgSendSuper (&s, @selector (performKeyEquivalent:), ev) != nil;
  1340. }
  1341. #endif
  1342. static BOOL becomeFirstResponder (id self, SEL)
  1343. {
  1344. if (NSViewComponentPeer* const owner = getOwner (self))
  1345. owner->viewFocusGain();
  1346. return YES;
  1347. }
  1348. static BOOL resignFirstResponder (id self, SEL)
  1349. {
  1350. if (NSViewComponentPeer* const owner = getOwner (self))
  1351. owner->viewFocusLoss();
  1352. return YES;
  1353. }
  1354. static BOOL acceptsFirstResponder (id self, SEL)
  1355. {
  1356. NSViewComponentPeer* const owner = getOwner (self);
  1357. return owner != nullptr && owner->canBecomeKeyWindow();
  1358. }
  1359. //==============================================================================
  1360. static NSDragOperation draggingEntered (id self, SEL s, id <NSDraggingInfo> sender)
  1361. {
  1362. return draggingUpdated (self, s, sender);
  1363. }
  1364. static NSDragOperation draggingUpdated (id self, SEL, id <NSDraggingInfo> sender)
  1365. {
  1366. if (NSViewComponentPeer* const owner = getOwner (self))
  1367. if (owner->sendDragCallback (0, sender))
  1368. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  1369. return NSDragOperationNone;
  1370. }
  1371. static void draggingEnded (id self, SEL s, id <NSDraggingInfo> sender)
  1372. {
  1373. draggingExited (self, s, sender);
  1374. }
  1375. static void draggingExited (id self, SEL, id <NSDraggingInfo> sender)
  1376. {
  1377. if (NSViewComponentPeer* const owner = getOwner (self))
  1378. owner->sendDragCallback (1, sender);
  1379. }
  1380. static BOOL prepareForDragOperation (id, SEL, id <NSDraggingInfo>)
  1381. {
  1382. return YES;
  1383. }
  1384. static BOOL performDragOperation (id self, SEL, id <NSDraggingInfo> sender)
  1385. {
  1386. NSViewComponentPeer* const owner = getOwner (self);
  1387. return owner != nullptr && owner->sendDragCallback (2, sender);
  1388. }
  1389. static void concludeDragOperation (id, SEL, id <NSDraggingInfo>) {}
  1390. };
  1391. //==============================================================================
  1392. struct JuceNSWindowClass : public ObjCClass <NSWindow>
  1393. {
  1394. JuceNSWindowClass() : ObjCClass <NSWindow> ("JUCEWindow_")
  1395. {
  1396. addIvar<NSViewComponentPeer*> ("owner");
  1397. addMethod (@selector (canBecomeKeyWindow), canBecomeKeyWindow, "c@:");
  1398. addMethod (@selector (becomeKeyWindow), becomeKeyWindow, "v@:");
  1399. addMethod (@selector (windowShouldClose:), windowShouldClose, "c@:@");
  1400. addMethod (@selector (constrainFrameRect:toScreen:), constrainFrameRect, @encode (NSRect), "@:", @encode (NSRect), "@");
  1401. addMethod (@selector (windowWillResize:toSize:), windowWillResize, @encode (NSSize), "@:@", @encode (NSSize));
  1402. addMethod (@selector (zoom:), zoom, "v@:@");
  1403. addMethod (@selector (windowWillMove:), windowWillMove, "v@:@");
  1404. addMethod (@selector (windowWillStartLiveResize:), windowWillStartLiveResize, "v@:@");
  1405. addMethod (@selector (windowDidEndLiveResize:), windowDidEndLiveResize, "v@:@");
  1406. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1407. addProtocol (@protocol (NSWindowDelegate));
  1408. #endif
  1409. registerClass();
  1410. }
  1411. private:
  1412. static NSViewComponentPeer* getOwner (id self)
  1413. {
  1414. return getIvar<NSViewComponentPeer*> (self, "owner");
  1415. }
  1416. //==============================================================================
  1417. static BOOL canBecomeKeyWindow (id self, SEL)
  1418. {
  1419. NSViewComponentPeer* const owner = getOwner (self);
  1420. return owner != nullptr
  1421. && owner->canBecomeKeyWindow()
  1422. && ! owner->sendModalInputAttemptIfBlocked();
  1423. }
  1424. static void becomeKeyWindow (id self, SEL)
  1425. {
  1426. sendSuperclassMessage (self, @selector (becomeKeyWindow));
  1427. if (NSViewComponentPeer* const owner = getOwner (self))
  1428. owner->becomeKeyWindow();
  1429. }
  1430. static BOOL windowShouldClose (id self, SEL, id /*window*/)
  1431. {
  1432. NSViewComponentPeer* const owner = getOwner (self);
  1433. return owner == nullptr || owner->windowShouldClose();
  1434. }
  1435. static NSRect constrainFrameRect (id self, SEL, NSRect frameRect, NSScreen*)
  1436. {
  1437. if (NSViewComponentPeer* const owner = getOwner (self))
  1438. frameRect = owner->constrainRect (frameRect);
  1439. return frameRect;
  1440. }
  1441. static NSSize windowWillResize (id self, SEL, NSWindow*, NSSize proposedFrameSize)
  1442. {
  1443. NSViewComponentPeer* const owner = getOwner (self);
  1444. if (owner == nullptr || owner->isZooming)
  1445. return proposedFrameSize;
  1446. NSRect frameRect = [(NSWindow*) self frame];
  1447. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  1448. frameRect.size = proposedFrameSize;
  1449. frameRect = owner->constrainRect (frameRect);
  1450. if (owner->hasNativeTitleBar())
  1451. owner->sendModalInputAttemptIfBlocked();
  1452. return frameRect.size;
  1453. }
  1454. static void zoom (id self, SEL, id sender)
  1455. {
  1456. if (NSViewComponentPeer* const owner = getOwner (self))
  1457. {
  1458. owner->isZooming = true;
  1459. objc_super s = { self, [NSWindow class] };
  1460. objc_msgSendSuper (&s, @selector (zoom:), sender);
  1461. owner->isZooming = false;
  1462. owner->redirectMovedOrResized();
  1463. }
  1464. }
  1465. static void windowWillMove (id self, SEL, NSNotification*)
  1466. {
  1467. if (NSViewComponentPeer* const owner = getOwner (self))
  1468. if (owner->hasNativeTitleBar())
  1469. owner->sendModalInputAttemptIfBlocked();
  1470. }
  1471. static void windowWillStartLiveResize (id self, SEL, NSNotification*)
  1472. {
  1473. if (NSViewComponentPeer* const owner = getOwner (self))
  1474. owner->liveResizingStart();
  1475. }
  1476. static void windowDidEndLiveResize (id self, SEL, NSNotification*)
  1477. {
  1478. if (NSViewComponentPeer* const owner = getOwner (self))
  1479. owner->liveResizingEnd();
  1480. }
  1481. };
  1482. NSView* NSViewComponentPeer::createViewInstance()
  1483. {
  1484. static JuceNSViewClass cls;
  1485. return cls.createInstance();
  1486. }
  1487. NSWindow* NSViewComponentPeer::createWindowInstance()
  1488. {
  1489. static JuceNSWindowClass cls;
  1490. return cls.createInstance();
  1491. }
  1492. //==============================================================================
  1493. ModifierKeys NSViewComponentPeer::currentModifiers;
  1494. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = nullptr;
  1495. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  1496. //==============================================================================
  1497. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  1498. {
  1499. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  1500. return true;
  1501. if (keyCode >= 'A' && keyCode <= 'Z'
  1502. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  1503. return true;
  1504. if (keyCode >= 'a' && keyCode <= 'z'
  1505. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  1506. return true;
  1507. return false;
  1508. }
  1509. ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
  1510. {
  1511. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1512. if ([NSEvent respondsToSelector: @selector (modifierFlags)])
  1513. NSViewComponentPeer::updateModifiers ((NSUInteger) [NSEvent modifierFlags]);
  1514. #endif
  1515. return NSViewComponentPeer::currentModifiers;
  1516. }
  1517. void ModifierKeys::updateCurrentModifiers() noexcept
  1518. {
  1519. currentModifiers = NSViewComponentPeer::currentModifiers;
  1520. }
  1521. //==============================================================================
  1522. bool MouseInputSource::SourceList::addSource()
  1523. {
  1524. if (sources.size() == 0)
  1525. {
  1526. addSource (0, true);
  1527. return true;
  1528. }
  1529. return false;
  1530. }
  1531. //==============================================================================
  1532. void Desktop::setKioskComponent (Component* kioskComp, bool enableOrDisable, bool allowMenusAndBars)
  1533. {
  1534. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  1535. NSViewComponentPeer* const peer = dynamic_cast<NSViewComponentPeer*> (kioskComp->getPeer());
  1536. jassert (peer != nullptr); // (this should have been checked by the caller)
  1537. #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
  1538. if (peer->hasNativeTitleBar()
  1539. && [peer->window respondsToSelector: @selector (toggleFullScreen:)])
  1540. {
  1541. [peer->window performSelector: @selector (toggleFullScreen:)
  1542. withObject: [NSNumber numberWithBool: (BOOL) enableOrDisable]];
  1543. }
  1544. else
  1545. #endif
  1546. {
  1547. if (enableOrDisable)
  1548. {
  1549. if (peer->hasNativeTitleBar())
  1550. [peer->window setStyleMask: NSBorderlessWindowMask];
  1551. [NSApp setPresentationOptions: (allowMenusAndBars ? (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)
  1552. : (NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar))];
  1553. kioskComp->setBounds (Desktop::getInstance().getDisplays().getMainDisplay().totalArea);
  1554. peer->becomeKeyWindow();
  1555. }
  1556. else
  1557. {
  1558. if (peer->hasNativeTitleBar())
  1559. {
  1560. [peer->window setStyleMask: (NSViewComponentPeer::getNSWindowStyleMask (peer->getStyleFlags()))];
  1561. peer->setTitle (peer->getComponent().getName()); // required to force the OS to update the title
  1562. }
  1563. [NSApp setPresentationOptions: NSApplicationPresentationDefault];
  1564. }
  1565. }
  1566. #elif JUCE_SUPPORT_CARBON
  1567. (void) kioskComp; (void) enableOrDisable; (void) allowMenusAndBars;
  1568. if (enableOrDisable)
  1569. {
  1570. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  1571. kioskComp->setBounds (Desktop::getInstance().getDisplays().getMainDisplay().totalArea);
  1572. }
  1573. else
  1574. {
  1575. SetSystemUIMode (kUIModeNormal, 0);
  1576. }
  1577. #else
  1578. (void) kioskComp; (void) enableOrDisable; (void) allowMenusAndBars;
  1579. // If you're targeting OSes earlier than 10.6 and want to use this feature,
  1580. // you'll need to enable JUCE_SUPPORT_CARBON.
  1581. jassertfalse;
  1582. #endif
  1583. }
  1584. //==============================================================================
  1585. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  1586. {
  1587. return new NSViewComponentPeer (*this, styleFlags, (NSView*) windowToAttachTo);
  1588. }
  1589. //==============================================================================
  1590. const int KeyPress::spaceKey = ' ';
  1591. const int KeyPress::returnKey = 0x0d;
  1592. const int KeyPress::escapeKey = 0x1b;
  1593. const int KeyPress::backspaceKey = 0x7f;
  1594. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  1595. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  1596. const int KeyPress::upKey = NSUpArrowFunctionKey;
  1597. const int KeyPress::downKey = NSDownArrowFunctionKey;
  1598. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  1599. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  1600. const int KeyPress::endKey = NSEndFunctionKey;
  1601. const int KeyPress::homeKey = NSHomeFunctionKey;
  1602. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  1603. const int KeyPress::insertKey = -1;
  1604. const int KeyPress::tabKey = 9;
  1605. const int KeyPress::F1Key = NSF1FunctionKey;
  1606. const int KeyPress::F2Key = NSF2FunctionKey;
  1607. const int KeyPress::F3Key = NSF3FunctionKey;
  1608. const int KeyPress::F4Key = NSF4FunctionKey;
  1609. const int KeyPress::F5Key = NSF5FunctionKey;
  1610. const int KeyPress::F6Key = NSF6FunctionKey;
  1611. const int KeyPress::F7Key = NSF7FunctionKey;
  1612. const int KeyPress::F8Key = NSF8FunctionKey;
  1613. const int KeyPress::F9Key = NSF9FunctionKey;
  1614. const int KeyPress::F10Key = NSF10FunctionKey;
  1615. const int KeyPress::F11Key = NSF1FunctionKey;
  1616. const int KeyPress::F12Key = NSF12FunctionKey;
  1617. const int KeyPress::F13Key = NSF13FunctionKey;
  1618. const int KeyPress::F14Key = NSF14FunctionKey;
  1619. const int KeyPress::F15Key = NSF15FunctionKey;
  1620. const int KeyPress::F16Key = NSF16FunctionKey;
  1621. const int KeyPress::numberPad0 = 0x30020;
  1622. const int KeyPress::numberPad1 = 0x30021;
  1623. const int KeyPress::numberPad2 = 0x30022;
  1624. const int KeyPress::numberPad3 = 0x30023;
  1625. const int KeyPress::numberPad4 = 0x30024;
  1626. const int KeyPress::numberPad5 = 0x30025;
  1627. const int KeyPress::numberPad6 = 0x30026;
  1628. const int KeyPress::numberPad7 = 0x30027;
  1629. const int KeyPress::numberPad8 = 0x30028;
  1630. const int KeyPress::numberPad9 = 0x30029;
  1631. const int KeyPress::numberPadAdd = 0x3002a;
  1632. const int KeyPress::numberPadSubtract = 0x3002b;
  1633. const int KeyPress::numberPadMultiply = 0x3002c;
  1634. const int KeyPress::numberPadDivide = 0x3002d;
  1635. const int KeyPress::numberPadSeparator = 0x3002e;
  1636. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  1637. const int KeyPress::numberPadEquals = 0x30030;
  1638. const int KeyPress::numberPadDelete = 0x30031;
  1639. const int KeyPress::playKey = 0x30000;
  1640. const int KeyPress::stopKey = 0x30001;
  1641. const int KeyPress::fastForwardKey = 0x30002;
  1642. const int KeyPress::rewindKey = 0x30003;