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.

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