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.

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