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.

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