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.

1978 lines
64KB

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