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.

1913 lines
70KB

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