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.

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