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.

1953 lines
72KB

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