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.

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