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.

1911 lines
71KB

  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 sendModalInputAttemptIfBlocked()
  647. {
  648. Component* const modal = Component::getCurrentlyModalComponent();
  649. if (modal != nullptr
  650. && (! getComponent().isParentOf (modal))
  651. && getComponent().isCurrentlyBlockedByAnotherModalComponent())
  652. {
  653. modal->inputAttemptWhenModal();
  654. return true;
  655. }
  656. return false;
  657. }
  658. bool canBecomeKeyWindow()
  659. {
  660. return (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0;
  661. }
  662. void becomeKeyWindow()
  663. {
  664. handleBroughtToFront();
  665. grabFocus();
  666. }
  667. bool windowShouldClose()
  668. {
  669. if (! isValidPeer (this))
  670. return YES;
  671. handleUserClosingWindow();
  672. return NO;
  673. }
  674. void redirectMovedOrResized()
  675. {
  676. updateFullscreenStatus();
  677. handleMovedOrResized();
  678. }
  679. void viewMovedToWindow()
  680. {
  681. if (isSharedWindow)
  682. window = [view window];
  683. }
  684. NSRect constrainRect (NSRect r)
  685. {
  686. if (constrainer != nullptr
  687. #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
  688. && ([window styleMask] & NSFullScreenWindowMask) == 0
  689. #endif
  690. )
  691. {
  692. NSRect current = [window frame];
  693. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  694. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  695. Rectangle<int> pos (convertToRectInt (r));
  696. Rectangle<int> original (convertToRectInt (current));
  697. const Rectangle<int> screenBounds (Desktop::getInstance().getDisplays().getTotalBounds (true));
  698. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  699. if ([window inLiveResize])
  700. #else
  701. if ([window respondsToSelector: @selector (inLiveResize)]
  702. && [window performSelector: @selector (inLiveResize)])
  703. #endif
  704. {
  705. constrainer->checkBounds (pos, original, screenBounds,
  706. false, false, true, true);
  707. }
  708. else
  709. {
  710. constrainer->checkBounds (pos, original, screenBounds,
  711. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  712. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  713. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  714. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  715. }
  716. r.origin.x = pos.getX();
  717. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  718. r.size.width = pos.getWidth();
  719. r.size.height = pos.getHeight();
  720. }
  721. return r;
  722. }
  723. static void showArrowCursorIfNeeded()
  724. {
  725. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  726. if (mouse.getComponentUnderMouse() == nullptr
  727. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == nullptr)
  728. {
  729. [[NSCursor arrowCursor] set];
  730. }
  731. }
  732. static void updateModifiers (NSEvent* e)
  733. {
  734. updateModifiers ([e modifierFlags]);
  735. }
  736. static void updateModifiers (const NSUInteger flags)
  737. {
  738. int m = 0;
  739. if ((flags & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  740. if ((flags & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  741. if ((flags & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  742. if ((flags & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  743. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  744. }
  745. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  746. {
  747. updateModifiers (ev);
  748. int keyCode = getKeyCodeFromEvent (ev);
  749. if (keyCode != 0)
  750. {
  751. if (isKeyDown)
  752. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  753. else
  754. keysCurrentlyDown.removeFirstMatchingValue (keyCode);
  755. }
  756. }
  757. static int getKeyCodeFromEvent (NSEvent* ev)
  758. {
  759. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  760. int keyCode = unmodified[0];
  761. if (keyCode == 0x19) // (backwards-tab)
  762. keyCode = '\t';
  763. else if (keyCode == 0x03) // (enter)
  764. keyCode = '\r';
  765. else
  766. keyCode = (int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  767. if (([ev modifierFlags] & NSNumericPadKeyMask) != 0)
  768. {
  769. const int numPadConversions[] = { '0', KeyPress::numberPad0, '1', KeyPress::numberPad1,
  770. '2', KeyPress::numberPad2, '3', KeyPress::numberPad3,
  771. '4', KeyPress::numberPad4, '5', KeyPress::numberPad5,
  772. '6', KeyPress::numberPad6, '7', KeyPress::numberPad7,
  773. '8', KeyPress::numberPad8, '9', KeyPress::numberPad9,
  774. '+', KeyPress::numberPadAdd, '-', KeyPress::numberPadSubtract,
  775. '*', KeyPress::numberPadMultiply, '/', KeyPress::numberPadDivide,
  776. '.', KeyPress::numberPadDecimalPoint, '=', KeyPress::numberPadEquals };
  777. for (int i = 0; i < numElementsInArray (numPadConversions); i += 2)
  778. if (keyCode == numPadConversions [i])
  779. keyCode = numPadConversions [i + 1];
  780. }
  781. return keyCode;
  782. }
  783. static int64 getMouseTime (NSEvent* e)
  784. {
  785. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  786. + (int64) ([e timestamp] * 1000.0);
  787. }
  788. static Point<int> getMousePos (NSEvent* e, NSView* view)
  789. {
  790. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  791. return Point<int> ((int) p.x, (int) ([view frame].size.height - p.y));
  792. }
  793. static int getModifierForButtonNumber (const NSInteger num)
  794. {
  795. return num == 0 ? ModifierKeys::leftButtonModifier
  796. : (num == 1 ? ModifierKeys::rightButtonModifier
  797. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  798. }
  799. static unsigned int getNSWindowStyleMask (const int flags) noexcept
  800. {
  801. unsigned int style = (flags & windowHasTitleBar) != 0 ? NSTitledWindowMask
  802. : NSBorderlessWindowMask;
  803. if ((flags & windowHasMinimiseButton) != 0) style |= NSMiniaturizableWindowMask;
  804. if ((flags & windowHasCloseButton) != 0) style |= NSClosableWindowMask;
  805. if ((flags & windowIsResizable) != 0) style |= NSResizableWindowMask;
  806. return style;
  807. }
  808. static NSArray* getSupportedDragTypes()
  809. {
  810. return [NSArray arrayWithObjects: NSFilenamesPboardType, NSFilesPromisePboardType, NSStringPboardType, nil];
  811. }
  812. BOOL sendDragCallback (const int type, id <NSDraggingInfo> sender)
  813. {
  814. NSPasteboard* pasteboard = [sender draggingPasteboard];
  815. NSString* contentType = [pasteboard availableTypeFromArray: getSupportedDragTypes()];
  816. if (contentType == nil)
  817. return false;
  818. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  819. ComponentPeer::DragInfo dragInfo;
  820. dragInfo.position.setXY ((int) p.x, (int) ([view frame].size.height - p.y));
  821. if (contentType == NSStringPboardType)
  822. dragInfo.text = nsStringToJuce ([pasteboard stringForType: NSStringPboardType]);
  823. else
  824. dragInfo.files = getDroppedFiles (pasteboard, contentType);
  825. if (dragInfo.files.size() > 0 || dragInfo.text.isNotEmpty())
  826. {
  827. switch (type)
  828. {
  829. case 0: return handleDragMove (dragInfo);
  830. case 1: return handleDragExit (dragInfo);
  831. case 2: return handleDragDrop (dragInfo);
  832. default: jassertfalse; break;
  833. }
  834. }
  835. return false;
  836. }
  837. StringArray getDroppedFiles (NSPasteboard* pasteboard, NSString* contentType)
  838. {
  839. StringArray files;
  840. NSString* iTunesPasteboardType = nsStringLiteral ("CorePasteboardFlavorType 0x6974756E"); // 'itun'
  841. if (contentType == NSFilesPromisePboardType
  842. && [[pasteboard types] containsObject: iTunesPasteboardType])
  843. {
  844. id list = [pasteboard propertyListForType: iTunesPasteboardType];
  845. if ([list isKindOfClass: [NSDictionary class]])
  846. {
  847. NSDictionary* iTunesDictionary = (NSDictionary*) list;
  848. NSArray* tracks = [iTunesDictionary valueForKey: nsStringLiteral ("Tracks")];
  849. NSEnumerator* enumerator = [tracks objectEnumerator];
  850. NSDictionary* track;
  851. while ((track = [enumerator nextObject]) != nil)
  852. {
  853. NSURL* url = [NSURL URLWithString: [track valueForKey: nsStringLiteral ("Location")]];
  854. if ([url isFileURL])
  855. files.add (nsStringToJuce ([url path]));
  856. }
  857. }
  858. }
  859. else
  860. {
  861. id list = [pasteboard propertyListForType: NSFilenamesPboardType];
  862. if ([list isKindOfClass: [NSArray class]])
  863. {
  864. NSArray* items = (NSArray*) [pasteboard propertyListForType: NSFilenamesPboardType];
  865. for (unsigned int i = 0; i < [items count]; ++i)
  866. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  867. }
  868. }
  869. return files;
  870. }
  871. //==============================================================================
  872. void viewFocusGain()
  873. {
  874. if (currentlyFocusedPeer != this)
  875. {
  876. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  877. currentlyFocusedPeer->handleFocusLoss();
  878. currentlyFocusedPeer = this;
  879. handleFocusGain();
  880. }
  881. }
  882. void viewFocusLoss()
  883. {
  884. if (currentlyFocusedPeer == this)
  885. {
  886. currentlyFocusedPeer = nullptr;
  887. handleFocusLoss();
  888. }
  889. }
  890. bool isFocused() const
  891. {
  892. return isSharedWindow ? this == currentlyFocusedPeer
  893. : [window isKeyWindow];
  894. }
  895. void grabFocus()
  896. {
  897. if (window != nil)
  898. {
  899. [window makeKeyWindow];
  900. [window makeFirstResponder: view];
  901. viewFocusGain();
  902. }
  903. }
  904. void textInputRequired (const Point<int>&) {}
  905. //==============================================================================
  906. void repaint (const Rectangle<int>& area)
  907. {
  908. if (insideDrawRect)
  909. {
  910. class AsyncRepaintMessage : public CallbackMessage
  911. {
  912. public:
  913. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  914. : peer (peer_), rect (rect_)
  915. {}
  916. void messageCallback()
  917. {
  918. if (ComponentPeer::isValidPeer (peer))
  919. peer->repaint (rect);
  920. }
  921. private:
  922. NSViewComponentPeer* const peer;
  923. const Rectangle<int> rect;
  924. };
  925. (new AsyncRepaintMessage (this, area))->post();
  926. }
  927. else
  928. {
  929. [view setNeedsDisplayInRect: NSMakeRect ((CGFloat) area.getX(), [view frame].size.height - (CGFloat) area.getBottom(),
  930. (CGFloat) area.getWidth(), (CGFloat) area.getHeight())];
  931. }
  932. }
  933. void performAnyPendingRepaintsNow()
  934. {
  935. [view displayIfNeeded];
  936. }
  937. //==============================================================================
  938. NSWindow* window;
  939. NSView* view;
  940. bool isSharedWindow, fullScreen, insideDrawRect;
  941. bool usingCoreGraphics, recursiveToFrontCall, isZooming, textWasInserted;
  942. String stringBeingComposed;
  943. NSNotificationCenter* notificationCenter;
  944. static ModifierKeys currentModifiers;
  945. static ComponentPeer* currentlyFocusedPeer;
  946. static Array<int> keysCurrentlyDown;
  947. private:
  948. static NSView* createViewInstance();
  949. static NSWindow* createWindowInstance();
  950. static void setOwner (id viewOrWindow, NSViewComponentPeer* newOwner)
  951. {
  952. object_setInstanceVariable (viewOrWindow, "owner", newOwner);
  953. }
  954. void getClipRects (RectangleList& clip, const int xOffset, const int yOffset, const int clipW, const int clipH)
  955. {
  956. const NSRect* rects = nullptr;
  957. NSInteger numRects = 0;
  958. [view getRectsBeingDrawn: &rects count: &numRects];
  959. const Rectangle<int> clipBounds (clipW, clipH);
  960. const CGFloat viewH = [view frame].size.height;
  961. for (int i = 0; i < numRects; ++i)
  962. clip.addWithoutMerging (clipBounds.getIntersection (Rectangle<int> (roundToInt (rects[i].origin.x) + xOffset,
  963. roundToInt (viewH - (rects[i].origin.y + rects[i].size.height)) + yOffset,
  964. roundToInt (rects[i].size.width),
  965. roundToInt (rects[i].size.height))));
  966. }
  967. static void appFocusChanged()
  968. {
  969. keysCurrentlyDown.clear();
  970. if (isValidPeer (currentlyFocusedPeer))
  971. {
  972. if (Process::isForegroundProcess())
  973. {
  974. currentlyFocusedPeer->handleFocusGain();
  975. ModalComponentManager::getInstance()->bringModalComponentsToFront();
  976. }
  977. else
  978. {
  979. currentlyFocusedPeer->handleFocusLoss();
  980. }
  981. }
  982. }
  983. static bool checkEventBlockedByModalComps (NSEvent* e)
  984. {
  985. if (Component::getNumCurrentlyModalComponents() == 0)
  986. return false;
  987. NSWindow* const w = [e window];
  988. if (w == nil || [w worksWhenModal])
  989. return false;
  990. bool isKey = false, isInputAttempt = false;
  991. switch ([e type])
  992. {
  993. case NSKeyDown:
  994. case NSKeyUp:
  995. isKey = isInputAttempt = true;
  996. break;
  997. case NSLeftMouseDown:
  998. case NSRightMouseDown:
  999. case NSOtherMouseDown:
  1000. isInputAttempt = true;
  1001. break;
  1002. case NSLeftMouseDragged:
  1003. case NSRightMouseDragged:
  1004. case NSLeftMouseUp:
  1005. case NSRightMouseUp:
  1006. case NSOtherMouseUp:
  1007. case NSOtherMouseDragged:
  1008. if (Desktop::getInstance().getDraggingMouseSource(0) != nullptr)
  1009. return false;
  1010. break;
  1011. case NSMouseMoved:
  1012. case NSMouseEntered:
  1013. case NSMouseExited:
  1014. case NSCursorUpdate:
  1015. case NSScrollWheel:
  1016. case NSTabletPoint:
  1017. case NSTabletProximity:
  1018. break;
  1019. default:
  1020. return false;
  1021. }
  1022. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  1023. {
  1024. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  1025. NSView* const compView = (NSView*) peer->getNativeHandle();
  1026. if ([compView window] == w)
  1027. {
  1028. if (isKey)
  1029. {
  1030. if (compView == [w firstResponder])
  1031. return false;
  1032. }
  1033. else
  1034. {
  1035. NSViewComponentPeer* nsViewPeer = dynamic_cast<NSViewComponentPeer*> (peer);
  1036. if ((nsViewPeer == nullptr || ! nsViewPeer->isSharedWindow)
  1037. ? NSPointInRect ([e locationInWindow], NSMakeRect (0, 0, [w frame].size.width, [w frame].size.height))
  1038. : NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil], [compView bounds]))
  1039. return false;
  1040. }
  1041. }
  1042. }
  1043. if (isInputAttempt)
  1044. {
  1045. if (! [NSApp isActive])
  1046. [NSApp activateIgnoringOtherApps: YES];
  1047. Component* const modal = Component::getCurrentlyModalComponent();
  1048. if (modal != nullptr)
  1049. modal->inputAttemptWhenModal();
  1050. }
  1051. return true;
  1052. }
  1053. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer);
  1054. };
  1055. //==============================================================================
  1056. struct JuceNSViewClass : public ObjCClass <NSView>
  1057. {
  1058. JuceNSViewClass() : ObjCClass <NSView> ("JUCEView_")
  1059. {
  1060. addIvar<NSViewComponentPeer*> ("owner");
  1061. addMethod (@selector (isOpaque), isOpaque, "c@:");
  1062. addMethod (@selector (drawRect:), drawRect, "v@:", @encode (NSRect));
  1063. addMethod (@selector (mouseDown:), mouseDown, "v@:@");
  1064. addMethod (@selector (asyncMouseDown:), asyncMouseDown, "v@:@");
  1065. addMethod (@selector (mouseUp:), mouseUp, "v@:@");
  1066. addMethod (@selector (asyncMouseUp:), asyncMouseUp, "v@:@");
  1067. addMethod (@selector (mouseDragged:), mouseDragged, "v@:@");
  1068. addMethod (@selector (mouseMoved:), mouseMoved, "v@:@");
  1069. addMethod (@selector (mouseEntered:), mouseEntered, "v@:@");
  1070. addMethod (@selector (mouseExited:), mouseExited, "v@:@");
  1071. addMethod (@selector (rightMouseDown:), rightMouseDown, "v@:@");
  1072. addMethod (@selector (rightMouseDragged:), rightMouseDragged, "v@:@");
  1073. addMethod (@selector (rightMouseUp:), rightMouseUp, "v@:@");
  1074. addMethod (@selector (otherMouseDown:), otherMouseDown, "v@:@");
  1075. addMethod (@selector (otherMouseDragged:), otherMouseDragged, "v@:@");
  1076. addMethod (@selector (otherMouseUp:), otherMouseUp, "v@:@");
  1077. addMethod (@selector (scrollWheel:), scrollWheel, "v@:@");
  1078. addMethod (@selector (acceptsFirstMouse:), acceptsFirstMouse, "v@:@");
  1079. addMethod (@selector (frameChanged:), frameChanged, "v@:@");
  1080. addMethod (@selector (viewDidMoveToWindow), viewDidMoveToWindow, "v@:");
  1081. addMethod (@selector (keyDown:), keyDown, "v@:@");
  1082. addMethod (@selector (keyUp:), keyUp, "v@:@");
  1083. addMethod (@selector (insertText:), insertText, "v@:@");
  1084. addMethod (@selector (doCommandBySelector:), doCommandBySelector, "v@::");
  1085. addMethod (@selector (setMarkedText:selectedRange:), setMarkedText, "v@:@", @encode (NSRange));
  1086. addMethod (@selector (unmarkText), unmarkText, "v@:");
  1087. addMethod (@selector (hasMarkedText), hasMarkedText, "c@:");
  1088. addMethod (@selector (conversationIdentifier), conversationIdentifier, "l@:");
  1089. addMethod (@selector (attributedSubstringFromRange:), attributedSubstringFromRange, "@@:", @encode (NSRange));
  1090. addMethod (@selector (markedRange), markedRange, @encode (NSRange), "@:");
  1091. addMethod (@selector (selectedRange), selectedRange, @encode (NSRange), "@:");
  1092. addMethod (@selector (firstRectForCharacterRange:), firstRectForCharacterRange, @encode (NSRect), "@:", @encode (NSRange));
  1093. addMethod (@selector (validAttributesForMarkedText), validAttributesForMarkedText, "@@:");
  1094. addMethod (@selector (flagsChanged:), flagsChanged, "v@:@");
  1095. addMethod (@selector (becomeFirstResponder), becomeFirstResponder, "c@:");
  1096. addMethod (@selector (resignFirstResponder), resignFirstResponder, "c@:");
  1097. addMethod (@selector (acceptsFirstResponder), acceptsFirstResponder, "c@:");
  1098. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  1099. addMethod (@selector (performKeyEquivalent:), performKeyEquivalent, "c@:@");
  1100. #endif
  1101. addMethod (@selector (draggingEntered:), draggingEntered, @encode (NSDragOperation), "@:@");
  1102. addMethod (@selector (draggingUpdated:), draggingUpdated, @encode (NSDragOperation), "@:@");
  1103. addMethod (@selector (draggingEnded:), draggingEnded, "v@:@");
  1104. addMethod (@selector (draggingExited:), draggingExited, "v@:@");
  1105. addMethod (@selector (prepareForDragOperation:), prepareForDragOperation, "c@:@");
  1106. addMethod (@selector (performDragOperation:), performDragOperation, "c@:@");
  1107. addMethod (@selector (concludeDragOperation:), concludeDragOperation, "v@:@");
  1108. addProtocol (@protocol (NSTextInput));
  1109. registerClass();
  1110. }
  1111. private:
  1112. static NSViewComponentPeer* getOwner (id self)
  1113. {
  1114. return getIvar<NSViewComponentPeer*> (self, "owner");
  1115. }
  1116. static void mouseDown (id self, SEL s, NSEvent* ev)
  1117. {
  1118. if (JUCEApplication::isStandaloneApp())
  1119. asyncMouseDown (self, s, ev);
  1120. else
  1121. // In some host situations, the host will stop modal loops from working
  1122. // correctly if they're called from a mouse event, so we'll trigger
  1123. // the event asynchronously..
  1124. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  1125. withObject: ev
  1126. waitUntilDone: NO];
  1127. }
  1128. static void mouseUp (id self, SEL s, NSEvent* ev)
  1129. {
  1130. if (! JUCEApplication::isStandaloneApp())
  1131. asyncMouseUp (self, s, ev);
  1132. else
  1133. // In some host situations, the host will stop modal loops from working
  1134. // correctly if they're called from a mouse event, so we'll trigger
  1135. // the event asynchronously..
  1136. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  1137. withObject: ev
  1138. waitUntilDone: NO];
  1139. }
  1140. static void asyncMouseDown (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseDown (ev); }
  1141. static void asyncMouseUp (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseUp (ev); }
  1142. static void mouseDragged (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseDrag (ev); }
  1143. static void mouseMoved (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseMove (ev); }
  1144. static void mouseEntered (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseEnter (ev); }
  1145. static void mouseExited (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseExit (ev); }
  1146. static void scrollWheel (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseWheel (ev); }
  1147. static void rightMouseDown (id self, SEL s, NSEvent* ev) { mouseDown (self, s, ev); }
  1148. static void otherMouseDown (id self, SEL s, NSEvent* ev) { mouseDown (self, s, ev); }
  1149. static void rightMouseDragged (id self, SEL s, NSEvent* ev) { mouseDragged (self, s, ev); }
  1150. static void otherMouseDragged (id self, SEL s, NSEvent* ev) { mouseDragged (self, s, ev); }
  1151. static void rightMouseUp (id self, SEL s, NSEvent* ev) { mouseUp (self, s, ev); }
  1152. static void otherMouseUp (id self, SEL s, NSEvent* ev) { mouseUp (self, s, ev); }
  1153. static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; }
  1154. static void drawRect (id self, SEL, NSRect r) { if (NSViewComponentPeer* const p = getOwner (self)) p->drawRect (r); }
  1155. static void frameChanged (id self, SEL, NSNotification*) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMovedOrResized(); }
  1156. static void viewDidMoveToWindow (id self, SEL) { if (NSViewComponentPeer* const p = getOwner (self)) p->viewMovedToWindow(); }
  1157. static BOOL isOpaque (id self, SEL)
  1158. {
  1159. NSViewComponentPeer* const owner = getOwner (self);
  1160. return owner == nullptr || owner->isOpaque();
  1161. }
  1162. //==============================================================================
  1163. static void keyDown (id self, SEL, NSEvent* ev)
  1164. {
  1165. if (NSViewComponentPeer* const owner = getOwner (self))
  1166. {
  1167. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  1168. owner->textWasInserted = false;
  1169. if (target != nullptr)
  1170. [(NSView*) self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  1171. else
  1172. owner->stringBeingComposed = String::empty;
  1173. if ((! owner->textWasInserted) && (owner == nullptr || ! owner->redirectKeyDown (ev)))
  1174. {
  1175. objc_super s = { self, [NSView class] };
  1176. objc_msgSendSuper (&s, @selector (keyDown:), ev);
  1177. }
  1178. }
  1179. }
  1180. static void keyUp (id self, SEL, NSEvent* ev)
  1181. {
  1182. NSViewComponentPeer* const owner = getOwner (self);
  1183. if (owner == nullptr || ! owner->redirectKeyUp (ev))
  1184. {
  1185. objc_super s = { self, [NSView class] };
  1186. objc_msgSendSuper (&s, @selector (keyUp:), ev);
  1187. }
  1188. }
  1189. //==============================================================================
  1190. static void insertText (id self, SEL, id aString)
  1191. {
  1192. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  1193. if (NSViewComponentPeer* const owner = getOwner (self))
  1194. {
  1195. NSString* newText = [aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString;
  1196. if ([newText length] > 0)
  1197. {
  1198. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1199. {
  1200. target->insertTextAtCaret (nsStringToJuce (newText));
  1201. owner->textWasInserted = true;
  1202. }
  1203. }
  1204. owner->stringBeingComposed = String::empty;
  1205. }
  1206. }
  1207. static void doCommandBySelector (id, SEL, SEL) {}
  1208. static void setMarkedText (id self, SEL, id aString, NSRange)
  1209. {
  1210. if (NSViewComponentPeer* const owner = getOwner (self))
  1211. {
  1212. owner->stringBeingComposed = nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]]
  1213. ? [aString string] : aString);
  1214. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1215. {
  1216. const Range<int> currentHighlight (target->getHighlightedRegion());
  1217. target->insertTextAtCaret (owner->stringBeingComposed);
  1218. target->setHighlightedRegion (currentHighlight.withLength (owner->stringBeingComposed.length()));
  1219. owner->textWasInserted = true;
  1220. }
  1221. }
  1222. }
  1223. static void unmarkText (id self, SEL)
  1224. {
  1225. if (NSViewComponentPeer* const owner = getOwner (self))
  1226. {
  1227. if (owner->stringBeingComposed.isNotEmpty())
  1228. {
  1229. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1230. {
  1231. target->insertTextAtCaret (owner->stringBeingComposed);
  1232. owner->textWasInserted = true;
  1233. }
  1234. owner->stringBeingComposed = String::empty;
  1235. }
  1236. }
  1237. }
  1238. static BOOL hasMarkedText (id self, SEL)
  1239. {
  1240. NSViewComponentPeer* const owner = getOwner (self);
  1241. return owner != nullptr && owner->stringBeingComposed.isNotEmpty();
  1242. }
  1243. static long conversationIdentifier (id self, SEL)
  1244. {
  1245. return (long) (pointer_sized_int) self;
  1246. }
  1247. static NSAttributedString* attributedSubstringFromRange (id self, SEL, NSRange theRange)
  1248. {
  1249. if (NSViewComponentPeer* const owner = getOwner (self))
  1250. {
  1251. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1252. {
  1253. const Range<int> r ((int) theRange.location,
  1254. (int) (theRange.location + theRange.length));
  1255. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  1256. }
  1257. }
  1258. return nil;
  1259. }
  1260. static NSRange markedRange (id self, SEL)
  1261. {
  1262. NSViewComponentPeer* const owner = getOwner (self);
  1263. return owner->stringBeingComposed.isNotEmpty() ? NSMakeRange (0, owner->stringBeingComposed.length())
  1264. : NSMakeRange (NSNotFound, 0);
  1265. }
  1266. static NSRange selectedRange (id self, SEL)
  1267. {
  1268. if (NSViewComponentPeer* const owner = getOwner (self))
  1269. {
  1270. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1271. {
  1272. const Range<int> highlight (target->getHighlightedRegion());
  1273. if (! highlight.isEmpty())
  1274. return NSMakeRange (highlight.getStart(), highlight.getLength());
  1275. }
  1276. }
  1277. return NSMakeRange (NSNotFound, 0);
  1278. }
  1279. static NSRect firstRectForCharacterRange (id self, SEL, NSRange)
  1280. {
  1281. if (NSViewComponentPeer* const owner = getOwner (self))
  1282. {
  1283. if (Component* const comp = dynamic_cast <Component*> (owner->findCurrentTextInputTarget()))
  1284. {
  1285. const Rectangle<int> bounds (comp->getScreenBounds());
  1286. return NSMakeRect (bounds.getX(),
  1287. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  1288. bounds.getWidth(),
  1289. bounds.getHeight());
  1290. }
  1291. }
  1292. return NSZeroRect;
  1293. }
  1294. static NSUInteger characterIndexForPoint (id, SEL, NSPoint) { return NSNotFound; }
  1295. static NSArray* validAttributesForMarkedText (id, SEL) { return [NSArray array]; }
  1296. //==============================================================================
  1297. static void flagsChanged (id self, SEL, NSEvent* ev)
  1298. {
  1299. if (NSViewComponentPeer* const owner = getOwner (self))
  1300. owner->redirectModKeyChange (ev);
  1301. }
  1302. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  1303. static BOOL performKeyEquivalent (id self, SEL, NSEvent* ev)
  1304. {
  1305. NSViewComponentPeer* const owner = getOwner (self);
  1306. if (owner != nullptr && owner->redirectPerformKeyEquivalent (ev))
  1307. return true;
  1308. objc_super s = { self, [NSView class] };
  1309. return objc_msgSendSuper (&s, @selector (performKeyEquivalent:), ev) != nil;
  1310. }
  1311. #endif
  1312. static BOOL becomeFirstResponder (id self, SEL)
  1313. {
  1314. if (NSViewComponentPeer* const owner = getOwner (self))
  1315. owner->viewFocusGain();
  1316. return YES;
  1317. }
  1318. static BOOL resignFirstResponder (id self, SEL)
  1319. {
  1320. if (NSViewComponentPeer* const owner = getOwner (self))
  1321. owner->viewFocusLoss();
  1322. return YES;
  1323. }
  1324. static BOOL acceptsFirstResponder (id self, SEL)
  1325. {
  1326. NSViewComponentPeer* const owner = getOwner (self);
  1327. return owner != nullptr && owner->canBecomeKeyWindow();
  1328. }
  1329. //==============================================================================
  1330. static NSDragOperation draggingEntered (id self, SEL s, id <NSDraggingInfo> sender)
  1331. {
  1332. return draggingUpdated (self, s, sender);
  1333. }
  1334. static NSDragOperation draggingUpdated (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 void draggingEnded (id self, SEL s, id <NSDraggingInfo> sender)
  1343. {
  1344. draggingExited (self, s, sender);
  1345. }
  1346. static void draggingExited (id self, SEL, id <NSDraggingInfo> sender)
  1347. {
  1348. if (NSViewComponentPeer* const owner = getOwner (self))
  1349. owner->sendDragCallback (1, sender);
  1350. }
  1351. static BOOL prepareForDragOperation (id self, SEL, id <NSDraggingInfo>)
  1352. {
  1353. return YES;
  1354. }
  1355. static BOOL performDragOperation (id self, SEL, id <NSDraggingInfo> sender)
  1356. {
  1357. NSViewComponentPeer* const owner = getOwner (self);
  1358. return owner != nullptr && owner->sendDragCallback (2, sender);
  1359. }
  1360. static void concludeDragOperation (id, SEL, id <NSDraggingInfo>) {}
  1361. };
  1362. //==============================================================================
  1363. struct JuceNSWindowClass : public ObjCClass <NSWindow>
  1364. {
  1365. JuceNSWindowClass() : ObjCClass <NSWindow> ("JUCEWindow_")
  1366. {
  1367. addIvar<NSViewComponentPeer*> ("owner");
  1368. addMethod (@selector (canBecomeKeyWindow), canBecomeKeyWindow, "c@:");
  1369. addMethod (@selector (becomeKeyWindow), becomeKeyWindow, "v@:");
  1370. addMethod (@selector (windowShouldClose:), windowShouldClose, "c@:@");
  1371. addMethod (@selector (constrainFrameRect:toScreen:), constrainFrameRect, @encode (NSRect), "@:", @encode (NSRect*), "@");
  1372. addMethod (@selector (windowWillResize:toSize:), windowWillResize, @encode (NSSize), "@:@", @encode (NSSize));
  1373. addMethod (@selector (zoom:), zoom, "v@:@");
  1374. addMethod (@selector (windowWillMove:), windowWillMove, "v@:@");
  1375. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1376. addProtocol (@protocol (NSWindowDelegate));
  1377. #endif
  1378. registerClass();
  1379. }
  1380. private:
  1381. static NSViewComponentPeer* getOwner (id self)
  1382. {
  1383. return getIvar<NSViewComponentPeer*> (self, "owner");
  1384. }
  1385. //==============================================================================
  1386. static BOOL canBecomeKeyWindow (id self, SEL)
  1387. {
  1388. NSViewComponentPeer* const owner = getOwner (self);
  1389. return owner != nullptr
  1390. && owner->canBecomeKeyWindow()
  1391. && ! owner->sendModalInputAttemptIfBlocked();
  1392. }
  1393. static void becomeKeyWindow (id self, SEL)
  1394. {
  1395. sendSuperclassMessage (self, @selector (becomeKeyWindow));
  1396. if (NSViewComponentPeer* const owner = getOwner (self))
  1397. owner->becomeKeyWindow();
  1398. }
  1399. static BOOL windowShouldClose (id self, SEL, id /*window*/)
  1400. {
  1401. NSViewComponentPeer* const owner = getOwner (self);
  1402. return owner == nullptr || owner->windowShouldClose();
  1403. }
  1404. static NSRect constrainFrameRect (id self, SEL, NSRect frameRect, NSScreen*)
  1405. {
  1406. if (NSViewComponentPeer* const owner = getOwner (self))
  1407. frameRect = owner->constrainRect (frameRect);
  1408. return frameRect;
  1409. }
  1410. static NSSize windowWillResize (id self, SEL, NSWindow*, NSSize proposedFrameSize)
  1411. {
  1412. NSViewComponentPeer* const owner = getOwner (self);
  1413. if (owner == nullptr || owner->isZooming)
  1414. return proposedFrameSize;
  1415. NSRect frameRect = [(NSWindow*) self frame];
  1416. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  1417. frameRect.size = proposedFrameSize;
  1418. frameRect = owner->constrainRect (frameRect);
  1419. if (owner->hasNativeTitleBar())
  1420. owner->sendModalInputAttemptIfBlocked();
  1421. return frameRect.size;
  1422. }
  1423. static void zoom (id self, SEL, id sender)
  1424. {
  1425. if (NSViewComponentPeer* const owner = getOwner (self))
  1426. {
  1427. owner->isZooming = true;
  1428. objc_super s = { self, [NSWindow class] };
  1429. objc_msgSendSuper (&s, @selector (zoom:), sender);
  1430. owner->isZooming = false;
  1431. owner->redirectMovedOrResized();
  1432. }
  1433. }
  1434. static void windowWillMove (id self, SEL, NSNotification*)
  1435. {
  1436. NSViewComponentPeer* const owner = getOwner (self);
  1437. if (owner != nullptr && owner->hasNativeTitleBar())
  1438. owner->sendModalInputAttemptIfBlocked();
  1439. }
  1440. };
  1441. NSView* NSViewComponentPeer::createViewInstance()
  1442. {
  1443. static JuceNSViewClass cls;
  1444. return cls.createInstance();
  1445. }
  1446. NSWindow* NSViewComponentPeer::createWindowInstance()
  1447. {
  1448. static JuceNSWindowClass cls;
  1449. return cls.createInstance();
  1450. }
  1451. //==============================================================================
  1452. ModifierKeys NSViewComponentPeer::currentModifiers;
  1453. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = nullptr;
  1454. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  1455. //==============================================================================
  1456. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  1457. {
  1458. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  1459. return true;
  1460. if (keyCode >= 'A' && keyCode <= 'Z'
  1461. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  1462. return true;
  1463. if (keyCode >= 'a' && keyCode <= 'z'
  1464. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  1465. return true;
  1466. return false;
  1467. }
  1468. ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
  1469. {
  1470. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1471. if ([NSEvent respondsToSelector: @selector (modifierFlags)])
  1472. NSViewComponentPeer::updateModifiers ((NSUInteger) [NSEvent modifierFlags]);
  1473. #endif
  1474. return NSViewComponentPeer::currentModifiers;
  1475. }
  1476. void ModifierKeys::updateCurrentModifiers() noexcept
  1477. {
  1478. currentModifiers = NSViewComponentPeer::currentModifiers;
  1479. }
  1480. //==============================================================================
  1481. void Desktop::createMouseInputSources()
  1482. {
  1483. mouseSources.add (new MouseInputSource (0, true));
  1484. }
  1485. //==============================================================================
  1486. void Desktop::setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  1487. {
  1488. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  1489. NSViewComponentPeer* const peer = dynamic_cast<NSViewComponentPeer*> (kioskModeComponent->getPeer());
  1490. #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
  1491. if (peer != nullptr
  1492. && peer->hasNativeTitleBar()
  1493. && [peer->window respondsToSelector: @selector (toggleFullScreen:)])
  1494. {
  1495. [peer->window performSelector: @selector (toggleFullScreen:)
  1496. withObject: [NSNumber numberWithBool: (BOOL) enableOrDisable]];
  1497. }
  1498. else
  1499. #endif
  1500. {
  1501. if (enableOrDisable)
  1502. {
  1503. if (peer->hasNativeTitleBar())
  1504. [peer->window setStyleMask: NSBorderlessWindowMask];
  1505. [NSApp setPresentationOptions: (allowMenusAndBars ? (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)
  1506. : (NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar))];
  1507. kioskModeComponent->setBounds (Desktop::getInstance().getDisplays().getMainDisplay().totalArea);
  1508. peer->becomeKeyWindow();
  1509. }
  1510. else
  1511. {
  1512. if (peer->hasNativeTitleBar())
  1513. {
  1514. [peer->window setStyleMask: (NSViewComponentPeer::getNSWindowStyleMask (peer->getStyleFlags()))];
  1515. peer->setTitle (peer->component.getName()); // required to force the OS to update the title
  1516. }
  1517. [NSApp setPresentationOptions: NSApplicationPresentationDefault];
  1518. }
  1519. }
  1520. #elif JUCE_SUPPORT_CARBON
  1521. if (enableOrDisable)
  1522. {
  1523. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  1524. kioskModeComponent->setBounds (Desktop::getInstance().getDisplays().getMainDisplay().totalArea);
  1525. }
  1526. else
  1527. {
  1528. SetSystemUIMode (kUIModeNormal, 0);
  1529. }
  1530. #else
  1531. // If you're targeting OSes earlier than 10.6 and want to use this feature,
  1532. // you'll need to enable JUCE_SUPPORT_CARBON.
  1533. jassertfalse;
  1534. #endif
  1535. }
  1536. //==============================================================================
  1537. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  1538. {
  1539. return new NSViewComponentPeer (*this, styleFlags, (NSView*) windowToAttachTo);
  1540. }
  1541. //==============================================================================
  1542. const int KeyPress::spaceKey = ' ';
  1543. const int KeyPress::returnKey = 0x0d;
  1544. const int KeyPress::escapeKey = 0x1b;
  1545. const int KeyPress::backspaceKey = 0x7f;
  1546. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  1547. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  1548. const int KeyPress::upKey = NSUpArrowFunctionKey;
  1549. const int KeyPress::downKey = NSDownArrowFunctionKey;
  1550. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  1551. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  1552. const int KeyPress::endKey = NSEndFunctionKey;
  1553. const int KeyPress::homeKey = NSHomeFunctionKey;
  1554. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  1555. const int KeyPress::insertKey = -1;
  1556. const int KeyPress::tabKey = 9;
  1557. const int KeyPress::F1Key = NSF1FunctionKey;
  1558. const int KeyPress::F2Key = NSF2FunctionKey;
  1559. const int KeyPress::F3Key = NSF3FunctionKey;
  1560. const int KeyPress::F4Key = NSF4FunctionKey;
  1561. const int KeyPress::F5Key = NSF5FunctionKey;
  1562. const int KeyPress::F6Key = NSF6FunctionKey;
  1563. const int KeyPress::F7Key = NSF7FunctionKey;
  1564. const int KeyPress::F8Key = NSF8FunctionKey;
  1565. const int KeyPress::F9Key = NSF9FunctionKey;
  1566. const int KeyPress::F10Key = NSF10FunctionKey;
  1567. const int KeyPress::F11Key = NSF1FunctionKey;
  1568. const int KeyPress::F12Key = NSF12FunctionKey;
  1569. const int KeyPress::F13Key = NSF13FunctionKey;
  1570. const int KeyPress::F14Key = NSF14FunctionKey;
  1571. const int KeyPress::F15Key = NSF15FunctionKey;
  1572. const int KeyPress::F16Key = NSF16FunctionKey;
  1573. const int KeyPress::numberPad0 = 0x30020;
  1574. const int KeyPress::numberPad1 = 0x30021;
  1575. const int KeyPress::numberPad2 = 0x30022;
  1576. const int KeyPress::numberPad3 = 0x30023;
  1577. const int KeyPress::numberPad4 = 0x30024;
  1578. const int KeyPress::numberPad5 = 0x30025;
  1579. const int KeyPress::numberPad6 = 0x30026;
  1580. const int KeyPress::numberPad7 = 0x30027;
  1581. const int KeyPress::numberPad8 = 0x30028;
  1582. const int KeyPress::numberPad9 = 0x30029;
  1583. const int KeyPress::numberPadAdd = 0x3002a;
  1584. const int KeyPress::numberPadSubtract = 0x3002b;
  1585. const int KeyPress::numberPadMultiply = 0x3002c;
  1586. const int KeyPress::numberPadDivide = 0x3002d;
  1587. const int KeyPress::numberPadSeparator = 0x3002e;
  1588. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  1589. const int KeyPress::numberPadEquals = 0x30030;
  1590. const int KeyPress::numberPadDelete = 0x30031;
  1591. const int KeyPress::playKey = 0x30000;
  1592. const int KeyPress::stopKey = 0x30001;
  1593. const int KeyPress::fastForwardKey = 0x30002;
  1594. const int KeyPress::rewindKey = 0x30003;