The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1927 lines
71KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. typedef void (*AppFocusChangeCallback)();
  19. extern AppFocusChangeCallback appFocusChangeCallback;
  20. typedef bool (*CheckEventBlockedByModalComps) (NSEvent*);
  21. extern CheckEventBlockedByModalComps isEventBlockedByModalComps;
  22. //==============================================================================
  23. #if ! (defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
  24. } // (juce namespace)
  25. @interface NSEvent (JuceDeviceDelta)
  26. - (CGFloat) scrollingDeltaX;
  27. - (CGFloat) scrollingDeltaY;
  28. - (BOOL) hasPreciseScrollingDeltas;
  29. - (BOOL) isDirectionInvertedFromDevice;
  30. @end
  31. namespace juce {
  32. #endif
  33. //==============================================================================
  34. class NSViewComponentPeer : public ComponentPeer
  35. {
  36. public:
  37. NSViewComponentPeer (Component& comp, const int windowStyleFlags, NSView* viewToAttachTo)
  38. : ComponentPeer (comp, windowStyleFlags),
  39. window (nil),
  40. view (nil),
  41. isSharedWindow (viewToAttachTo != nil),
  42. fullScreen (false),
  43. insideDrawRect (false),
  44. #if USE_COREGRAPHICS_RENDERING
  45. usingCoreGraphics (true),
  46. #else
  47. usingCoreGraphics (false),
  48. #endif
  49. 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. currentModifiers = currentModifiers.withoutMouseButtons();
  430. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  431. if ([NSWindow respondsToSelector: @selector (windowNumberAtPoint:belowWindowWithWindowNumber:)]
  432. && [NSWindow windowNumberAtPoint: [[ev window] convertBaseToScreen: [ev locationInWindow]]
  433. belowWindowWithWindowNumber: 0] != [window windowNumber])
  434. {
  435. // moved into another window which overlaps this one, so trigger an exit
  436. handleMouseEvent (0, Point<int> (-1, -1), currentModifiers, getMouseTime (ev));
  437. }
  438. else
  439. #endif
  440. {
  441. sendMouseEvent (ev);
  442. }
  443. showArrowCursorIfNeeded();
  444. }
  445. void redirectMouseEnter (NSEvent* ev)
  446. {
  447. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  448. currentModifiers = currentModifiers.withoutMouseButtons();
  449. sendMouseEvent (ev);
  450. }
  451. void redirectMouseExit (NSEvent* ev)
  452. {
  453. currentModifiers = currentModifiers.withoutMouseButtons();
  454. sendMouseEvent (ev);
  455. }
  456. static float checkDeviceDeltaReturnValue (float v) noexcept
  457. {
  458. // (deviceDeltaX can fail and return NaN, so need to sanity-check the result)
  459. v *= 0.5f / 256.0f;
  460. return (v > -1000.0f && v < 1000.0f) ? v : 0.0f;
  461. }
  462. void redirectMouseWheel (NSEvent* ev)
  463. {
  464. updateModifiers (ev);
  465. MouseWheelDetails wheel;
  466. wheel.deltaX = 0;
  467. wheel.deltaY = 0;
  468. wheel.isReversed = false;
  469. wheel.isSmooth = false;
  470. #if ! JUCE_PPC
  471. @try
  472. {
  473. #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
  474. if ([ev respondsToSelector: @selector (isDirectionInvertedFromDevice)])
  475. wheel.isReversed = [ev isDirectionInvertedFromDevice];
  476. if ([ev respondsToSelector: @selector (hasPreciseScrollingDeltas)])
  477. {
  478. if ([ev hasPreciseScrollingDeltas])
  479. {
  480. const float scale = 0.5f / 256.0f;
  481. wheel.deltaX = [ev scrollingDeltaX] * scale;
  482. wheel.deltaY = [ev scrollingDeltaY] * scale;
  483. wheel.isSmooth = true;
  484. }
  485. }
  486. else
  487. #endif
  488. if ([ev respondsToSelector: @selector (deviceDeltaX)])
  489. {
  490. wheel.deltaX = checkDeviceDeltaReturnValue ((float) objc_msgSend_fpret (ev, @selector (deviceDeltaX)));
  491. wheel.deltaY = checkDeviceDeltaReturnValue ((float) objc_msgSend_fpret (ev, @selector (deviceDeltaY)));
  492. }
  493. }
  494. @catch (...)
  495. {}
  496. #endif
  497. if (wheel.deltaX == 0 && wheel.deltaY == 0)
  498. {
  499. const float scale = 10.0f / 256.0f;
  500. wheel.deltaX = [ev deltaX] * scale;
  501. wheel.deltaY = [ev deltaY] * scale;
  502. }
  503. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev), wheel);
  504. }
  505. void sendMouseEvent (NSEvent* ev)
  506. {
  507. updateModifiers (ev);
  508. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  509. }
  510. bool handleKeyEvent (NSEvent* ev, bool isKeyDown)
  511. {
  512. const String unicode (nsStringToJuce ([ev characters]));
  513. const int keyCode = getKeyCodeFromEvent (ev);
  514. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  515. //String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  516. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  517. if (keyCode != 0 || unicode.isNotEmpty())
  518. {
  519. if (isKeyDown)
  520. {
  521. bool used = false;
  522. for (String::CharPointerType u (unicode.getCharPointer()); ! u.isEmpty();)
  523. {
  524. juce_wchar textCharacter = u.getAndAdvance();
  525. switch (keyCode)
  526. {
  527. case NSLeftArrowFunctionKey:
  528. case NSRightArrowFunctionKey:
  529. case NSUpArrowFunctionKey:
  530. case NSDownArrowFunctionKey:
  531. case NSPageUpFunctionKey:
  532. case NSPageDownFunctionKey:
  533. case NSEndFunctionKey:
  534. case NSHomeFunctionKey:
  535. case NSDeleteFunctionKey:
  536. textCharacter = 0;
  537. break; // (these all seem to generate unwanted garbage unicode strings)
  538. default:
  539. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  540. textCharacter = 0;
  541. break;
  542. }
  543. used = handleKeyUpOrDown (true) || used;
  544. used = handleKeyPress (keyCode, textCharacter) || used;
  545. }
  546. return used;
  547. }
  548. else
  549. {
  550. if (handleKeyUpOrDown (false))
  551. return true;
  552. }
  553. }
  554. return false;
  555. }
  556. bool redirectKeyDown (NSEvent* ev)
  557. {
  558. updateKeysDown (ev, true);
  559. bool used = handleKeyEvent (ev, true);
  560. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  561. {
  562. // for command keys, the key-up event is thrown away, so simulate one..
  563. updateKeysDown (ev, false);
  564. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  565. }
  566. // (If we're running modally, don't allow unused keystrokes to be passed
  567. // along to other blocked views..)
  568. if (Component::getCurrentlyModalComponent() != nullptr)
  569. used = true;
  570. return used;
  571. }
  572. bool redirectKeyUp (NSEvent* ev)
  573. {
  574. updateKeysDown (ev, false);
  575. return handleKeyEvent (ev, false)
  576. || Component::getCurrentlyModalComponent() != nullptr;
  577. }
  578. void redirectModKeyChange (NSEvent* ev)
  579. {
  580. keysCurrentlyDown.clear();
  581. handleKeyUpOrDown (true);
  582. updateModifiers (ev);
  583. handleModifierKeysChange();
  584. }
  585. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  586. bool redirectPerformKeyEquivalent (NSEvent* ev)
  587. {
  588. if ([ev type] == NSKeyDown)
  589. return redirectKeyDown (ev);
  590. else if ([ev type] == NSKeyUp)
  591. return redirectKeyUp (ev);
  592. return false;
  593. }
  594. #endif
  595. bool isOpaque()
  596. {
  597. return component.isOpaque();
  598. }
  599. void drawRect (NSRect r)
  600. {
  601. if (r.size.width < 1.0f || r.size.height < 1.0f)
  602. return;
  603. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  604. if (! component.isOpaque())
  605. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  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. #if USE_COREGRAPHICS_RENDERING
  613. if (usingCoreGraphics)
  614. {
  615. CoreGraphicsContext context (cg, (float) [view frame].size.height, displayScale);
  616. insideDrawRect = true;
  617. handlePaint (context);
  618. insideDrawRect = false;
  619. }
  620. else
  621. #endif
  622. {
  623. const Point<int> offset (-roundToInt (r.origin.x),
  624. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  625. const int clipW = (int) (r.size.width + 0.5f);
  626. const int clipH = (int) (r.size.height + 0.5f);
  627. RectangleList clip;
  628. getClipRects (clip, offset, clipW, clipH);
  629. if (! clip.isEmpty())
  630. {
  631. Image temp (component.isOpaque() ? Image::RGB : Image::ARGB,
  632. roundToInt (clipW * displayScale),
  633. roundToInt (clipH * displayScale),
  634. ! component.isOpaque());
  635. {
  636. const int intScale = roundToInt (displayScale);
  637. if (intScale != 1)
  638. clip.scaleAll (intScale);
  639. ScopedPointer<LowLevelGraphicsContext> context (component.getLookAndFeel()
  640. .createGraphicsContext (temp, offset * intScale, clip));
  641. if (intScale != 1)
  642. context->addTransform (AffineTransform::scale (displayScale));
  643. insideDrawRect = true;
  644. handlePaint (*context);
  645. insideDrawRect = false;
  646. }
  647. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  648. CGImageRef image = juce_createCoreGraphicsImage (temp, false, colourSpace, false);
  649. CGColorSpaceRelease (colourSpace);
  650. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, clipW, clipH), image);
  651. CGImageRelease (image);
  652. }
  653. }
  654. }
  655. bool sendModalInputAttemptIfBlocked()
  656. {
  657. Component* const modal = Component::getCurrentlyModalComponent();
  658. if (modal != nullptr
  659. && insideToFrontCall == 0
  660. && (! getComponent().isParentOf (modal))
  661. && getComponent().isCurrentlyBlockedByAnotherModalComponent())
  662. {
  663. modal->inputAttemptWhenModal();
  664. return true;
  665. }
  666. return false;
  667. }
  668. bool canBecomeKeyWindow()
  669. {
  670. return (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0;
  671. }
  672. void becomeKeyWindow()
  673. {
  674. handleBroughtToFront();
  675. grabFocus();
  676. }
  677. bool windowShouldClose()
  678. {
  679. if (! isValidPeer (this))
  680. return YES;
  681. handleUserClosingWindow();
  682. return NO;
  683. }
  684. void redirectMovedOrResized()
  685. {
  686. updateFullscreenStatus();
  687. handleMovedOrResized();
  688. }
  689. void viewMovedToWindow()
  690. {
  691. if (isSharedWindow)
  692. window = [view window];
  693. }
  694. NSRect constrainRect (NSRect r)
  695. {
  696. if (constrainer != nullptr
  697. #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
  698. && ([window styleMask] & NSFullScreenWindowMask) == 0
  699. #endif
  700. )
  701. {
  702. NSRect current = [window frame];
  703. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  704. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  705. Rectangle<int> pos (convertToRectInt (r));
  706. Rectangle<int> original (convertToRectInt (current));
  707. const Rectangle<int> screenBounds (Desktop::getInstance().getDisplays().getTotalBounds (true));
  708. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  709. if ([window inLiveResize])
  710. #else
  711. if ([window respondsToSelector: @selector (inLiveResize)]
  712. && [window performSelector: @selector (inLiveResize)])
  713. #endif
  714. {
  715. constrainer->checkBounds (pos, original, screenBounds,
  716. false, false, true, true);
  717. }
  718. else
  719. {
  720. constrainer->checkBounds (pos, original, screenBounds,
  721. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  722. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  723. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  724. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  725. }
  726. r.origin.x = pos.getX();
  727. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  728. r.size.width = pos.getWidth();
  729. r.size.height = pos.getHeight();
  730. }
  731. return r;
  732. }
  733. static void showArrowCursorIfNeeded()
  734. {
  735. Desktop& desktop = Desktop::getInstance();
  736. MouseInputSource& mouse = desktop.getMainMouseSource();
  737. if (mouse.getComponentUnderMouse() == nullptr
  738. && desktop.findComponentAt (mouse.getScreenPosition()) == nullptr)
  739. {
  740. [[NSCursor arrowCursor] set];
  741. }
  742. }
  743. static void updateModifiers (NSEvent* e)
  744. {
  745. updateModifiers ([e modifierFlags]);
  746. }
  747. static void updateModifiers (const NSUInteger flags)
  748. {
  749. int m = 0;
  750. if ((flags & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  751. if ((flags & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  752. if ((flags & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  753. if ((flags & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  754. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  755. }
  756. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  757. {
  758. updateModifiers (ev);
  759. int keyCode = getKeyCodeFromEvent (ev);
  760. if (keyCode != 0)
  761. {
  762. if (isKeyDown)
  763. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  764. else
  765. keysCurrentlyDown.removeFirstMatchingValue (keyCode);
  766. }
  767. }
  768. static int getKeyCodeFromEvent (NSEvent* ev)
  769. {
  770. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  771. int keyCode = unmodified[0];
  772. if (keyCode == 0x19) // (backwards-tab)
  773. keyCode = '\t';
  774. else if (keyCode == 0x03) // (enter)
  775. keyCode = '\r';
  776. else
  777. keyCode = (int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  778. if (([ev modifierFlags] & NSNumericPadKeyMask) != 0)
  779. {
  780. const int numPadConversions[] = { '0', KeyPress::numberPad0, '1', KeyPress::numberPad1,
  781. '2', KeyPress::numberPad2, '3', KeyPress::numberPad3,
  782. '4', KeyPress::numberPad4, '5', KeyPress::numberPad5,
  783. '6', KeyPress::numberPad6, '7', KeyPress::numberPad7,
  784. '8', KeyPress::numberPad8, '9', KeyPress::numberPad9,
  785. '+', KeyPress::numberPadAdd, '-', KeyPress::numberPadSubtract,
  786. '*', KeyPress::numberPadMultiply, '/', KeyPress::numberPadDivide,
  787. '.', KeyPress::numberPadDecimalPoint, '=', KeyPress::numberPadEquals };
  788. for (int i = 0; i < numElementsInArray (numPadConversions); i += 2)
  789. if (keyCode == numPadConversions [i])
  790. keyCode = numPadConversions [i + 1];
  791. }
  792. return keyCode;
  793. }
  794. static int64 getMouseTime (NSEvent* e)
  795. {
  796. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  797. + (int64) ([e timestamp] * 1000.0);
  798. }
  799. static Point<int> getMousePos (NSEvent* e, NSView* view)
  800. {
  801. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  802. return Point<int> ((int) p.x, (int) ([view frame].size.height - p.y));
  803. }
  804. static int getModifierForButtonNumber (const NSInteger num)
  805. {
  806. return num == 0 ? ModifierKeys::leftButtonModifier
  807. : (num == 1 ? ModifierKeys::rightButtonModifier
  808. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  809. }
  810. static unsigned int getNSWindowStyleMask (const int flags) noexcept
  811. {
  812. unsigned int style = (flags & windowHasTitleBar) != 0 ? NSTitledWindowMask
  813. : NSBorderlessWindowMask;
  814. if ((flags & windowHasMinimiseButton) != 0) style |= NSMiniaturizableWindowMask;
  815. if ((flags & windowHasCloseButton) != 0) style |= NSClosableWindowMask;
  816. if ((flags & windowIsResizable) != 0) style |= NSResizableWindowMask;
  817. return style;
  818. }
  819. static NSArray* getSupportedDragTypes()
  820. {
  821. return [NSArray arrayWithObjects: NSFilenamesPboardType, NSFilesPromisePboardType, NSStringPboardType, nil];
  822. }
  823. BOOL sendDragCallback (const int type, id <NSDraggingInfo> sender)
  824. {
  825. NSPasteboard* pasteboard = [sender draggingPasteboard];
  826. NSString* contentType = [pasteboard availableTypeFromArray: getSupportedDragTypes()];
  827. if (contentType == nil)
  828. return false;
  829. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  830. ComponentPeer::DragInfo dragInfo;
  831. dragInfo.position.setXY ((int) p.x, (int) ([view frame].size.height - p.y));
  832. if (contentType == NSStringPboardType)
  833. dragInfo.text = nsStringToJuce ([pasteboard stringForType: NSStringPboardType]);
  834. else
  835. dragInfo.files = getDroppedFiles (pasteboard, contentType);
  836. if (! dragInfo.isEmpty())
  837. {
  838. switch (type)
  839. {
  840. case 0: return handleDragMove (dragInfo);
  841. case 1: return handleDragExit (dragInfo);
  842. case 2: return handleDragDrop (dragInfo);
  843. default: jassertfalse; break;
  844. }
  845. }
  846. return false;
  847. }
  848. StringArray getDroppedFiles (NSPasteboard* pasteboard, NSString* contentType)
  849. {
  850. StringArray files;
  851. NSString* iTunesPasteboardType = nsStringLiteral ("CorePasteboardFlavorType 0x6974756E"); // 'itun'
  852. if (contentType == NSFilesPromisePboardType
  853. && [[pasteboard types] containsObject: iTunesPasteboardType])
  854. {
  855. id list = [pasteboard propertyListForType: iTunesPasteboardType];
  856. if ([list isKindOfClass: [NSDictionary class]])
  857. {
  858. NSDictionary* iTunesDictionary = (NSDictionary*) list;
  859. NSArray* tracks = [iTunesDictionary valueForKey: nsStringLiteral ("Tracks")];
  860. NSEnumerator* enumerator = [tracks objectEnumerator];
  861. NSDictionary* track;
  862. while ((track = [enumerator nextObject]) != nil)
  863. {
  864. NSURL* url = [NSURL URLWithString: [track valueForKey: nsStringLiteral ("Location")]];
  865. if ([url isFileURL])
  866. files.add (nsStringToJuce ([url path]));
  867. }
  868. }
  869. }
  870. else
  871. {
  872. id list = [pasteboard propertyListForType: NSFilenamesPboardType];
  873. if ([list isKindOfClass: [NSArray class]])
  874. {
  875. NSArray* items = (NSArray*) [pasteboard propertyListForType: NSFilenamesPboardType];
  876. for (unsigned int i = 0; i < [items count]; ++i)
  877. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  878. }
  879. }
  880. return files;
  881. }
  882. //==============================================================================
  883. void viewFocusGain()
  884. {
  885. if (currentlyFocusedPeer != this)
  886. {
  887. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  888. currentlyFocusedPeer->handleFocusLoss();
  889. currentlyFocusedPeer = this;
  890. handleFocusGain();
  891. }
  892. }
  893. void viewFocusLoss()
  894. {
  895. if (currentlyFocusedPeer == this)
  896. {
  897. currentlyFocusedPeer = nullptr;
  898. handleFocusLoss();
  899. }
  900. }
  901. bool isFocused() const
  902. {
  903. return isSharedWindow ? this == currentlyFocusedPeer
  904. : [window isKeyWindow];
  905. }
  906. void grabFocus()
  907. {
  908. if (window != nil)
  909. {
  910. [window makeKeyWindow];
  911. [window makeFirstResponder: view];
  912. viewFocusGain();
  913. }
  914. }
  915. void textInputRequired (const Point<int>&) {}
  916. //==============================================================================
  917. void repaint (const Rectangle<int>& area)
  918. {
  919. if (insideDrawRect)
  920. {
  921. class AsyncRepaintMessage : public CallbackMessage
  922. {
  923. public:
  924. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  925. : peer (peer_), rect (rect_)
  926. {}
  927. void messageCallback()
  928. {
  929. if (ComponentPeer::isValidPeer (peer))
  930. peer->repaint (rect);
  931. }
  932. private:
  933. NSViewComponentPeer* const peer;
  934. const Rectangle<int> rect;
  935. };
  936. (new AsyncRepaintMessage (this, area))->post();
  937. }
  938. else
  939. {
  940. [view setNeedsDisplayInRect: NSMakeRect ((CGFloat) area.getX(), [view frame].size.height - (CGFloat) area.getBottom(),
  941. (CGFloat) area.getWidth(), (CGFloat) area.getHeight())];
  942. }
  943. }
  944. void performAnyPendingRepaintsNow()
  945. {
  946. [view displayIfNeeded];
  947. }
  948. //==============================================================================
  949. NSWindow* window;
  950. NSView* view;
  951. bool isSharedWindow, fullScreen, insideDrawRect;
  952. bool usingCoreGraphics, isZooming, textWasInserted;
  953. String stringBeingComposed;
  954. NSNotificationCenter* notificationCenter;
  955. static ModifierKeys currentModifiers;
  956. static ComponentPeer* currentlyFocusedPeer;
  957. static Array<int> keysCurrentlyDown;
  958. static int insideToFrontCall;
  959. private:
  960. static NSView* createViewInstance();
  961. static NSWindow* createWindowInstance();
  962. static void setOwner (id viewOrWindow, NSViewComponentPeer* newOwner)
  963. {
  964. object_setInstanceVariable (viewOrWindow, "owner", newOwner);
  965. }
  966. void getClipRects (RectangleList& clip, const Point<int> offset, const int clipW, const int clipH)
  967. {
  968. const NSRect* rects = nullptr;
  969. NSInteger numRects = 0;
  970. [view getRectsBeingDrawn: &rects count: &numRects];
  971. const Rectangle<int> clipBounds (clipW, clipH);
  972. const CGFloat viewH = [view frame].size.height;
  973. for (int i = 0; i < numRects; ++i)
  974. clip.addWithoutMerging (clipBounds.getIntersection (Rectangle<int> (roundToInt (rects[i].origin.x) + offset.x,
  975. roundToInt (viewH - (rects[i].origin.y + rects[i].size.height)) + offset.y,
  976. roundToInt (rects[i].size.width),
  977. roundToInt (rects[i].size.height))));
  978. }
  979. static void appFocusChanged()
  980. {
  981. keysCurrentlyDown.clear();
  982. if (isValidPeer (currentlyFocusedPeer))
  983. {
  984. if (Process::isForegroundProcess())
  985. {
  986. currentlyFocusedPeer->handleFocusGain();
  987. ModalComponentManager::getInstance()->bringModalComponentsToFront();
  988. }
  989. else
  990. {
  991. currentlyFocusedPeer->handleFocusLoss();
  992. }
  993. }
  994. }
  995. static bool checkEventBlockedByModalComps (NSEvent* e)
  996. {
  997. if (Component::getNumCurrentlyModalComponents() == 0)
  998. return false;
  999. NSWindow* const w = [e window];
  1000. if (w == nil || [w worksWhenModal])
  1001. return false;
  1002. bool isKey = false, isInputAttempt = false;
  1003. switch ([e type])
  1004. {
  1005. case NSKeyDown:
  1006. case NSKeyUp:
  1007. isKey = isInputAttempt = true;
  1008. break;
  1009. case NSLeftMouseDown:
  1010. case NSRightMouseDown:
  1011. case NSOtherMouseDown:
  1012. isInputAttempt = true;
  1013. break;
  1014. case NSLeftMouseDragged:
  1015. case NSRightMouseDragged:
  1016. case NSLeftMouseUp:
  1017. case NSRightMouseUp:
  1018. case NSOtherMouseUp:
  1019. case NSOtherMouseDragged:
  1020. if (Desktop::getInstance().getDraggingMouseSource(0) != nullptr)
  1021. return false;
  1022. break;
  1023. case NSMouseMoved:
  1024. case NSMouseEntered:
  1025. case NSMouseExited:
  1026. case NSCursorUpdate:
  1027. case NSScrollWheel:
  1028. case NSTabletPoint:
  1029. case NSTabletProximity:
  1030. break;
  1031. default:
  1032. return false;
  1033. }
  1034. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  1035. {
  1036. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  1037. NSView* const compView = (NSView*) peer->getNativeHandle();
  1038. if ([compView window] == w)
  1039. {
  1040. if (isKey)
  1041. {
  1042. if (compView == [w firstResponder])
  1043. return false;
  1044. }
  1045. else
  1046. {
  1047. NSViewComponentPeer* nsViewPeer = dynamic_cast<NSViewComponentPeer*> (peer);
  1048. if ((nsViewPeer == nullptr || ! nsViewPeer->isSharedWindow)
  1049. ? NSPointInRect ([e locationInWindow], NSMakeRect (0, 0, [w frame].size.width, [w frame].size.height))
  1050. : NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil], [compView bounds]))
  1051. return false;
  1052. }
  1053. }
  1054. }
  1055. if (isInputAttempt)
  1056. {
  1057. if (! [NSApp isActive])
  1058. [NSApp activateIgnoringOtherApps: YES];
  1059. if (Component* const modal = Component::getCurrentlyModalComponent())
  1060. modal->inputAttemptWhenModal();
  1061. }
  1062. return true;
  1063. }
  1064. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NSViewComponentPeer)
  1065. };
  1066. int NSViewComponentPeer::insideToFrontCall = 0;
  1067. //==============================================================================
  1068. struct JuceNSViewClass : public ObjCClass <NSView>
  1069. {
  1070. JuceNSViewClass() : ObjCClass <NSView> ("JUCEView_")
  1071. {
  1072. addIvar<NSViewComponentPeer*> ("owner");
  1073. addMethod (@selector (isOpaque), isOpaque, "c@:");
  1074. addMethod (@selector (drawRect:), drawRect, "v@:", @encode (NSRect));
  1075. addMethod (@selector (mouseDown:), mouseDown, "v@:@");
  1076. addMethod (@selector (asyncMouseDown:), asyncMouseDown, "v@:@");
  1077. addMethod (@selector (mouseUp:), mouseUp, "v@:@");
  1078. addMethod (@selector (asyncMouseUp:), asyncMouseUp, "v@:@");
  1079. addMethod (@selector (mouseDragged:), mouseDragged, "v@:@");
  1080. addMethod (@selector (mouseMoved:), mouseMoved, "v@:@");
  1081. addMethod (@selector (mouseEntered:), mouseEntered, "v@:@");
  1082. addMethod (@selector (mouseExited:), mouseExited, "v@:@");
  1083. addMethod (@selector (rightMouseDown:), mouseDown, "v@:@");
  1084. addMethod (@selector (rightMouseDragged:), mouseDragged, "v@:@");
  1085. addMethod (@selector (rightMouseUp:), mouseUp, "v@:@");
  1086. addMethod (@selector (otherMouseDown:), mouseDown, "v@:@");
  1087. addMethod (@selector (otherMouseDragged:), mouseDragged, "v@:@");
  1088. addMethod (@selector (otherMouseUp:), mouseUp, "v@:@");
  1089. addMethod (@selector (scrollWheel:), scrollWheel, "v@:@");
  1090. addMethod (@selector (acceptsFirstMouse:), acceptsFirstMouse, "v@:@");
  1091. addMethod (@selector (frameChanged:), frameChanged, "v@:@");
  1092. addMethod (@selector (viewDidMoveToWindow), viewDidMoveToWindow, "v@:");
  1093. addMethod (@selector (keyDown:), keyDown, "v@:@");
  1094. addMethod (@selector (keyUp:), keyUp, "v@:@");
  1095. addMethod (@selector (insertText:), insertText, "v@:@");
  1096. addMethod (@selector (doCommandBySelector:), doCommandBySelector, "v@::");
  1097. addMethod (@selector (setMarkedText:selectedRange:), setMarkedText, "v@:@", @encode (NSRange));
  1098. addMethod (@selector (unmarkText), unmarkText, "v@:");
  1099. addMethod (@selector (hasMarkedText), hasMarkedText, "c@:");
  1100. addMethod (@selector (conversationIdentifier), conversationIdentifier, "l@:");
  1101. addMethod (@selector (attributedSubstringFromRange:), attributedSubstringFromRange, "@@:", @encode (NSRange));
  1102. addMethod (@selector (markedRange), markedRange, @encode (NSRange), "@:");
  1103. addMethod (@selector (selectedRange), selectedRange, @encode (NSRange), "@:");
  1104. addMethod (@selector (firstRectForCharacterRange:), firstRectForCharacterRange, @encode (NSRect), "@:", @encode (NSRange));
  1105. addMethod (@selector (validAttributesForMarkedText), validAttributesForMarkedText, "@@:");
  1106. addMethod (@selector (flagsChanged:), flagsChanged, "v@:@");
  1107. addMethod (@selector (becomeFirstResponder), becomeFirstResponder, "c@:");
  1108. addMethod (@selector (resignFirstResponder), resignFirstResponder, "c@:");
  1109. addMethod (@selector (acceptsFirstResponder), acceptsFirstResponder, "c@:");
  1110. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  1111. addMethod (@selector (performKeyEquivalent:), performKeyEquivalent, "c@:@");
  1112. #endif
  1113. addMethod (@selector (draggingEntered:), draggingEntered, @encode (NSDragOperation), "@:@");
  1114. addMethod (@selector (draggingUpdated:), draggingUpdated, @encode (NSDragOperation), "@:@");
  1115. addMethod (@selector (draggingEnded:), draggingEnded, "v@:@");
  1116. addMethod (@selector (draggingExited:), draggingExited, "v@:@");
  1117. addMethod (@selector (prepareForDragOperation:), prepareForDragOperation, "c@:@");
  1118. addMethod (@selector (performDragOperation:), performDragOperation, "c@:@");
  1119. addMethod (@selector (concludeDragOperation:), concludeDragOperation, "v@:@");
  1120. addProtocol (@protocol (NSTextInput));
  1121. registerClass();
  1122. }
  1123. private:
  1124. static NSViewComponentPeer* getOwner (id self)
  1125. {
  1126. return getIvar<NSViewComponentPeer*> (self, "owner");
  1127. }
  1128. static void mouseDown (id self, SEL s, NSEvent* ev)
  1129. {
  1130. if (JUCEApplication::isStandaloneApp())
  1131. asyncMouseDown (self, s, ev);
  1132. else
  1133. // In some host situations, the host will stop modal loops from working
  1134. // correctly if they're called from a mouse event, so we'll trigger
  1135. // the event asynchronously..
  1136. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  1137. withObject: ev
  1138. waitUntilDone: NO];
  1139. }
  1140. static void mouseUp (id self, SEL s, NSEvent* ev)
  1141. {
  1142. if (JUCEApplication::isStandaloneApp())
  1143. asyncMouseUp (self, s, ev);
  1144. else
  1145. // In some host situations, the host will stop modal loops from working
  1146. // correctly if they're called from a mouse event, so we'll trigger
  1147. // the event asynchronously..
  1148. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  1149. withObject: ev
  1150. waitUntilDone: NO];
  1151. }
  1152. static void asyncMouseDown (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseDown (ev); }
  1153. static void asyncMouseUp (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseUp (ev); }
  1154. static void mouseDragged (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseDrag (ev); }
  1155. static void mouseMoved (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseMove (ev); }
  1156. static void mouseEntered (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseEnter (ev); }
  1157. static void mouseExited (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseExit (ev); }
  1158. static void scrollWheel (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseWheel (ev); }
  1159. static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; }
  1160. static void drawRect (id self, SEL, NSRect r) { if (NSViewComponentPeer* const p = getOwner (self)) p->drawRect (r); }
  1161. static void frameChanged (id self, SEL, NSNotification*) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMovedOrResized(); }
  1162. static void viewDidMoveToWindow (id self, SEL) { if (NSViewComponentPeer* const p = getOwner (self)) p->viewMovedToWindow(); }
  1163. static BOOL isOpaque (id self, SEL)
  1164. {
  1165. NSViewComponentPeer* const owner = getOwner (self);
  1166. return owner == nullptr || owner->isOpaque();
  1167. }
  1168. //==============================================================================
  1169. static void keyDown (id self, SEL, NSEvent* ev)
  1170. {
  1171. if (NSViewComponentPeer* const owner = getOwner (self))
  1172. {
  1173. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  1174. owner->textWasInserted = false;
  1175. if (target != nullptr)
  1176. [(NSView*) self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  1177. else
  1178. owner->stringBeingComposed = String::empty;
  1179. if ((! owner->textWasInserted) && (owner == nullptr || ! owner->redirectKeyDown (ev)))
  1180. {
  1181. objc_super s = { self, [NSView class] };
  1182. objc_msgSendSuper (&s, @selector (keyDown:), ev);
  1183. }
  1184. }
  1185. }
  1186. static void keyUp (id self, SEL, NSEvent* ev)
  1187. {
  1188. NSViewComponentPeer* const owner = getOwner (self);
  1189. if (owner == nullptr || ! owner->redirectKeyUp (ev))
  1190. {
  1191. objc_super s = { self, [NSView class] };
  1192. objc_msgSendSuper (&s, @selector (keyUp:), ev);
  1193. }
  1194. }
  1195. //==============================================================================
  1196. static void insertText (id self, SEL, id aString)
  1197. {
  1198. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  1199. if (NSViewComponentPeer* const owner = getOwner (self))
  1200. {
  1201. NSString* newText = [aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString;
  1202. if ([newText length] > 0)
  1203. {
  1204. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1205. {
  1206. target->insertTextAtCaret (nsStringToJuce (newText));
  1207. owner->textWasInserted = true;
  1208. }
  1209. }
  1210. owner->stringBeingComposed = String::empty;
  1211. }
  1212. }
  1213. static void doCommandBySelector (id, SEL, SEL) {}
  1214. static void setMarkedText (id self, SEL, id aString, NSRange)
  1215. {
  1216. if (NSViewComponentPeer* const owner = getOwner (self))
  1217. {
  1218. owner->stringBeingComposed = nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]]
  1219. ? [aString string] : aString);
  1220. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1221. {
  1222. const Range<int> currentHighlight (target->getHighlightedRegion());
  1223. target->insertTextAtCaret (owner->stringBeingComposed);
  1224. target->setHighlightedRegion (currentHighlight.withLength (owner->stringBeingComposed.length()));
  1225. owner->textWasInserted = true;
  1226. }
  1227. }
  1228. }
  1229. static void unmarkText (id self, SEL)
  1230. {
  1231. if (NSViewComponentPeer* const owner = getOwner (self))
  1232. {
  1233. if (owner->stringBeingComposed.isNotEmpty())
  1234. {
  1235. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1236. {
  1237. target->insertTextAtCaret (owner->stringBeingComposed);
  1238. owner->textWasInserted = true;
  1239. }
  1240. owner->stringBeingComposed = String::empty;
  1241. }
  1242. }
  1243. }
  1244. static BOOL hasMarkedText (id self, SEL)
  1245. {
  1246. NSViewComponentPeer* const owner = getOwner (self);
  1247. return owner != nullptr && owner->stringBeingComposed.isNotEmpty();
  1248. }
  1249. static long conversationIdentifier (id self, SEL)
  1250. {
  1251. return (long) (pointer_sized_int) self;
  1252. }
  1253. static NSAttributedString* attributedSubstringFromRange (id self, SEL, NSRange theRange)
  1254. {
  1255. if (NSViewComponentPeer* const owner = getOwner (self))
  1256. {
  1257. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1258. {
  1259. const Range<int> r ((int) theRange.location,
  1260. (int) (theRange.location + theRange.length));
  1261. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  1262. }
  1263. }
  1264. return nil;
  1265. }
  1266. static NSRange markedRange (id self, SEL)
  1267. {
  1268. NSViewComponentPeer* const owner = getOwner (self);
  1269. return owner->stringBeingComposed.isNotEmpty() ? NSMakeRange (0, (NSUInteger) owner->stringBeingComposed.length())
  1270. : NSMakeRange (NSNotFound, 0);
  1271. }
  1272. static NSRange selectedRange (id self, SEL)
  1273. {
  1274. if (NSViewComponentPeer* const owner = getOwner (self))
  1275. {
  1276. if (TextInputTarget* const target = owner->findCurrentTextInputTarget())
  1277. {
  1278. const Range<int> highlight (target->getHighlightedRegion());
  1279. if (! highlight.isEmpty())
  1280. return NSMakeRange ((NSUInteger) highlight.getStart(),
  1281. (NSUInteger) highlight.getLength());
  1282. }
  1283. }
  1284. return NSMakeRange (NSNotFound, 0);
  1285. }
  1286. static NSRect firstRectForCharacterRange (id self, SEL, NSRange)
  1287. {
  1288. if (NSViewComponentPeer* const owner = getOwner (self))
  1289. {
  1290. if (Component* const comp = dynamic_cast <Component*> (owner->findCurrentTextInputTarget()))
  1291. {
  1292. const Rectangle<int> bounds (comp->getScreenBounds());
  1293. return NSMakeRect (bounds.getX(),
  1294. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  1295. bounds.getWidth(),
  1296. bounds.getHeight());
  1297. }
  1298. }
  1299. return NSZeroRect;
  1300. }
  1301. static NSUInteger characterIndexForPoint (id, SEL, NSPoint) { return NSNotFound; }
  1302. static NSArray* validAttributesForMarkedText (id, SEL) { return [NSArray array]; }
  1303. //==============================================================================
  1304. static void flagsChanged (id self, SEL, NSEvent* ev)
  1305. {
  1306. if (NSViewComponentPeer* const owner = getOwner (self))
  1307. owner->redirectModKeyChange (ev);
  1308. }
  1309. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  1310. static BOOL performKeyEquivalent (id self, SEL, NSEvent* ev)
  1311. {
  1312. NSViewComponentPeer* const owner = getOwner (self);
  1313. if (owner != nullptr && owner->redirectPerformKeyEquivalent (ev))
  1314. return true;
  1315. objc_super s = { self, [NSView class] };
  1316. return objc_msgSendSuper (&s, @selector (performKeyEquivalent:), ev) != nil;
  1317. }
  1318. #endif
  1319. static BOOL becomeFirstResponder (id self, SEL)
  1320. {
  1321. if (NSViewComponentPeer* const owner = getOwner (self))
  1322. owner->viewFocusGain();
  1323. return YES;
  1324. }
  1325. static BOOL resignFirstResponder (id self, SEL)
  1326. {
  1327. if (NSViewComponentPeer* const owner = getOwner (self))
  1328. owner->viewFocusLoss();
  1329. return YES;
  1330. }
  1331. static BOOL acceptsFirstResponder (id self, SEL)
  1332. {
  1333. NSViewComponentPeer* const owner = getOwner (self);
  1334. return owner != nullptr && owner->canBecomeKeyWindow();
  1335. }
  1336. //==============================================================================
  1337. static NSDragOperation draggingEntered (id self, SEL s, id <NSDraggingInfo> sender)
  1338. {
  1339. return draggingUpdated (self, s, sender);
  1340. }
  1341. static NSDragOperation draggingUpdated (id self, SEL, id <NSDraggingInfo> sender)
  1342. {
  1343. NSViewComponentPeer* const owner = getOwner (self);
  1344. if (owner != nullptr && owner->sendDragCallback (0, sender))
  1345. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  1346. else
  1347. return NSDragOperationNone;
  1348. }
  1349. static void draggingEnded (id self, SEL s, id <NSDraggingInfo> sender)
  1350. {
  1351. draggingExited (self, s, sender);
  1352. }
  1353. static void draggingExited (id self, SEL, id <NSDraggingInfo> sender)
  1354. {
  1355. if (NSViewComponentPeer* const owner = getOwner (self))
  1356. owner->sendDragCallback (1, sender);
  1357. }
  1358. static BOOL prepareForDragOperation (id, SEL, id <NSDraggingInfo>)
  1359. {
  1360. return YES;
  1361. }
  1362. static BOOL performDragOperation (id self, SEL, id <NSDraggingInfo> sender)
  1363. {
  1364. NSViewComponentPeer* const owner = getOwner (self);
  1365. return owner != nullptr && owner->sendDragCallback (2, sender);
  1366. }
  1367. static void concludeDragOperation (id, SEL, id <NSDraggingInfo>) {}
  1368. };
  1369. //==============================================================================
  1370. struct JuceNSWindowClass : public ObjCClass <NSWindow>
  1371. {
  1372. JuceNSWindowClass() : ObjCClass <NSWindow> ("JUCEWindow_")
  1373. {
  1374. addIvar<NSViewComponentPeer*> ("owner");
  1375. addMethod (@selector (canBecomeKeyWindow), canBecomeKeyWindow, "c@:");
  1376. addMethod (@selector (becomeKeyWindow), becomeKeyWindow, "v@:");
  1377. addMethod (@selector (windowShouldClose:), windowShouldClose, "c@:@");
  1378. addMethod (@selector (constrainFrameRect:toScreen:), constrainFrameRect, @encode (NSRect), "@:", @encode (NSRect*), "@");
  1379. addMethod (@selector (windowWillResize:toSize:), windowWillResize, @encode (NSSize), "@:@", @encode (NSSize));
  1380. addMethod (@selector (zoom:), zoom, "v@:@");
  1381. addMethod (@selector (windowWillMove:), windowWillMove, "v@:@");
  1382. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1383. addProtocol (@protocol (NSWindowDelegate));
  1384. #endif
  1385. registerClass();
  1386. }
  1387. private:
  1388. static NSViewComponentPeer* getOwner (id self)
  1389. {
  1390. return getIvar<NSViewComponentPeer*> (self, "owner");
  1391. }
  1392. //==============================================================================
  1393. static BOOL canBecomeKeyWindow (id self, SEL)
  1394. {
  1395. NSViewComponentPeer* const owner = getOwner (self);
  1396. return owner != nullptr
  1397. && owner->canBecomeKeyWindow()
  1398. && ! owner->sendModalInputAttemptIfBlocked();
  1399. }
  1400. static void becomeKeyWindow (id self, SEL)
  1401. {
  1402. sendSuperclassMessage (self, @selector (becomeKeyWindow));
  1403. if (NSViewComponentPeer* const owner = getOwner (self))
  1404. owner->becomeKeyWindow();
  1405. }
  1406. static BOOL windowShouldClose (id self, SEL, id /*window*/)
  1407. {
  1408. NSViewComponentPeer* const owner = getOwner (self);
  1409. return owner == nullptr || owner->windowShouldClose();
  1410. }
  1411. static NSRect constrainFrameRect (id self, SEL, NSRect frameRect, NSScreen*)
  1412. {
  1413. if (NSViewComponentPeer* const owner = getOwner (self))
  1414. frameRect = owner->constrainRect (frameRect);
  1415. return frameRect;
  1416. }
  1417. static NSSize windowWillResize (id self, SEL, NSWindow*, NSSize proposedFrameSize)
  1418. {
  1419. NSViewComponentPeer* const owner = getOwner (self);
  1420. if (owner == nullptr || owner->isZooming)
  1421. return proposedFrameSize;
  1422. NSRect frameRect = [(NSWindow*) self frame];
  1423. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  1424. frameRect.size = proposedFrameSize;
  1425. frameRect = owner->constrainRect (frameRect);
  1426. if (owner->hasNativeTitleBar())
  1427. owner->sendModalInputAttemptIfBlocked();
  1428. return frameRect.size;
  1429. }
  1430. static void zoom (id self, SEL, id sender)
  1431. {
  1432. if (NSViewComponentPeer* const owner = getOwner (self))
  1433. {
  1434. owner->isZooming = true;
  1435. objc_super s = { self, [NSWindow class] };
  1436. objc_msgSendSuper (&s, @selector (zoom:), sender);
  1437. owner->isZooming = false;
  1438. owner->redirectMovedOrResized();
  1439. }
  1440. }
  1441. static void windowWillMove (id self, SEL, NSNotification*)
  1442. {
  1443. NSViewComponentPeer* const owner = getOwner (self);
  1444. if (owner != nullptr && owner->hasNativeTitleBar())
  1445. owner->sendModalInputAttemptIfBlocked();
  1446. }
  1447. };
  1448. NSView* NSViewComponentPeer::createViewInstance()
  1449. {
  1450. static JuceNSViewClass cls;
  1451. return cls.createInstance();
  1452. }
  1453. NSWindow* NSViewComponentPeer::createWindowInstance()
  1454. {
  1455. static JuceNSWindowClass cls;
  1456. return cls.createInstance();
  1457. }
  1458. //==============================================================================
  1459. ModifierKeys NSViewComponentPeer::currentModifiers;
  1460. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = nullptr;
  1461. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  1462. //==============================================================================
  1463. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  1464. {
  1465. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  1466. return true;
  1467. if (keyCode >= 'A' && keyCode <= 'Z'
  1468. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  1469. return true;
  1470. if (keyCode >= 'a' && keyCode <= 'z'
  1471. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  1472. return true;
  1473. return false;
  1474. }
  1475. ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
  1476. {
  1477. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  1478. if ([NSEvent respondsToSelector: @selector (modifierFlags)])
  1479. NSViewComponentPeer::updateModifiers ((NSUInteger) [NSEvent modifierFlags]);
  1480. #endif
  1481. return NSViewComponentPeer::currentModifiers;
  1482. }
  1483. void ModifierKeys::updateCurrentModifiers() noexcept
  1484. {
  1485. currentModifiers = NSViewComponentPeer::currentModifiers;
  1486. }
  1487. //==============================================================================
  1488. void Desktop::createMouseInputSources()
  1489. {
  1490. mouseSources.add (new MouseInputSource (0, true));
  1491. }
  1492. //==============================================================================
  1493. void Desktop::setKioskComponent (Component* kioskComp, bool enableOrDisable, bool allowMenusAndBars)
  1494. {
  1495. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
  1496. NSViewComponentPeer* const peer = dynamic_cast<NSViewComponentPeer*> (kioskComp->getPeer());
  1497. jassert (peer != nullptr); // (this should have been checked by the caller)
  1498. #if defined (MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
  1499. if (peer->hasNativeTitleBar()
  1500. && [peer->window respondsToSelector: @selector (toggleFullScreen:)])
  1501. {
  1502. [peer->window performSelector: @selector (toggleFullScreen:)
  1503. withObject: [NSNumber numberWithBool: (BOOL) enableOrDisable]];
  1504. }
  1505. else
  1506. #endif
  1507. {
  1508. if (enableOrDisable)
  1509. {
  1510. if (peer->hasNativeTitleBar())
  1511. [peer->window setStyleMask: NSBorderlessWindowMask];
  1512. [NSApp setPresentationOptions: (allowMenusAndBars ? (NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)
  1513. : (NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar))];
  1514. kioskComp->setBounds (Desktop::getInstance().getDisplays().getMainDisplay().totalArea);
  1515. peer->becomeKeyWindow();
  1516. }
  1517. else
  1518. {
  1519. if (peer->hasNativeTitleBar())
  1520. {
  1521. [peer->window setStyleMask: (NSViewComponentPeer::getNSWindowStyleMask (peer->getStyleFlags()))];
  1522. peer->setTitle (peer->getComponent().getName()); // required to force the OS to update the title
  1523. }
  1524. [NSApp setPresentationOptions: NSApplicationPresentationDefault];
  1525. }
  1526. }
  1527. #elif JUCE_SUPPORT_CARBON
  1528. if (enableOrDisable)
  1529. {
  1530. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  1531. kioskComp->setBounds (Desktop::getInstance().getDisplays().getMainDisplay().totalArea);
  1532. }
  1533. else
  1534. {
  1535. SetSystemUIMode (kUIModeNormal, 0);
  1536. }
  1537. #else
  1538. // If you're targeting OSes earlier than 10.6 and want to use this feature,
  1539. // you'll need to enable JUCE_SUPPORT_CARBON.
  1540. jassertfalse;
  1541. #endif
  1542. }
  1543. //==============================================================================
  1544. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  1545. {
  1546. return new NSViewComponentPeer (*this, styleFlags, (NSView*) windowToAttachTo);
  1547. }
  1548. //==============================================================================
  1549. const int KeyPress::spaceKey = ' ';
  1550. const int KeyPress::returnKey = 0x0d;
  1551. const int KeyPress::escapeKey = 0x1b;
  1552. const int KeyPress::backspaceKey = 0x7f;
  1553. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  1554. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  1555. const int KeyPress::upKey = NSUpArrowFunctionKey;
  1556. const int KeyPress::downKey = NSDownArrowFunctionKey;
  1557. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  1558. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  1559. const int KeyPress::endKey = NSEndFunctionKey;
  1560. const int KeyPress::homeKey = NSHomeFunctionKey;
  1561. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  1562. const int KeyPress::insertKey = -1;
  1563. const int KeyPress::tabKey = 9;
  1564. const int KeyPress::F1Key = NSF1FunctionKey;
  1565. const int KeyPress::F2Key = NSF2FunctionKey;
  1566. const int KeyPress::F3Key = NSF3FunctionKey;
  1567. const int KeyPress::F4Key = NSF4FunctionKey;
  1568. const int KeyPress::F5Key = NSF5FunctionKey;
  1569. const int KeyPress::F6Key = NSF6FunctionKey;
  1570. const int KeyPress::F7Key = NSF7FunctionKey;
  1571. const int KeyPress::F8Key = NSF8FunctionKey;
  1572. const int KeyPress::F9Key = NSF9FunctionKey;
  1573. const int KeyPress::F10Key = NSF10FunctionKey;
  1574. const int KeyPress::F11Key = NSF1FunctionKey;
  1575. const int KeyPress::F12Key = NSF12FunctionKey;
  1576. const int KeyPress::F13Key = NSF13FunctionKey;
  1577. const int KeyPress::F14Key = NSF14FunctionKey;
  1578. const int KeyPress::F15Key = NSF15FunctionKey;
  1579. const int KeyPress::F16Key = NSF16FunctionKey;
  1580. const int KeyPress::numberPad0 = 0x30020;
  1581. const int KeyPress::numberPad1 = 0x30021;
  1582. const int KeyPress::numberPad2 = 0x30022;
  1583. const int KeyPress::numberPad3 = 0x30023;
  1584. const int KeyPress::numberPad4 = 0x30024;
  1585. const int KeyPress::numberPad5 = 0x30025;
  1586. const int KeyPress::numberPad6 = 0x30026;
  1587. const int KeyPress::numberPad7 = 0x30027;
  1588. const int KeyPress::numberPad8 = 0x30028;
  1589. const int KeyPress::numberPad9 = 0x30029;
  1590. const int KeyPress::numberPadAdd = 0x3002a;
  1591. const int KeyPress::numberPadSubtract = 0x3002b;
  1592. const int KeyPress::numberPadMultiply = 0x3002c;
  1593. const int KeyPress::numberPadDivide = 0x3002d;
  1594. const int KeyPress::numberPadSeparator = 0x3002e;
  1595. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  1596. const int KeyPress::numberPadEquals = 0x30030;
  1597. const int KeyPress::numberPadDelete = 0x30031;
  1598. const int KeyPress::playKey = 0x30000;
  1599. const int KeyPress::stopKey = 0x30001;
  1600. const int KeyPress::fastForwardKey = 0x30002;
  1601. const int KeyPress::rewindKey = 0x30003;