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.

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