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.

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