# Mouse event issue of juce::Component on third party NSWindow

**URL:** <https://forum.juce.com/t/mouse-event-issue-of-juce-component-on-third-party-nswindow/5773>\
**Category:** MacOSX and iOS\
**Created:** [October 14, 2010, 11:49am UTC](https://forum.juce.com/t/mouse-event-issue-of-juce-component-on-third-party-nswindow/5773 "2010-10-14T11:49:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dheeraj](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@Dheeraj](https://forum.juce.com/u/Dheeraj)\
**Post date:** [October 14, 2010, 11:49am UTC](https://forum.juce.com/t/mouse-event-issue-of-juce-component-on-third-party-nswindow/5773/1 "2010-10-14T11:49:50Z")

</div>

Hi Jules,

JUCE Version : 1.51  
OS : 10.5 & 10.6

I have gone through the post regarding shared window focus issue : [http://www.rawmaterialsoftware.com/viewtopic.php?t=&f=&p=24594](http://www.rawmaterialsoftware.com/viewtopic.php?t=&f=&p=24594)  
But I still have focus issue on juce component if I am adding it to third party NSWindow. I tried to resolve the issue and added following code to  
juce\_mac\_NSViewComponentPeer.mm file

```auto
- (void) viewDidMoveToWindow
{

	int	options =	NSTrackingMouseEnteredAndExited |    
				         NSTrackingActiveAlways |
                     NSTrackingMouseMoved |
				         NSTrackingInVisibleRect;		  
	
	
	NSTrackingArea *ta;
	
	
	ta = [[NSTrackingArea alloc] initWithRect:NSZeroRect
									  options:options
										owner:self
									 userInfo:nil];
	[self addTrackingArea:ta];
	[ta release];
	
	if (owner != 0)
       owner->viewMovedToWindow();
}

```

Then Juce::Component starts receiving mouseOver and MouseMoved events but breaks mouseDrag event when dragged out side juce::Component, e.g if i drag a slider and if mouse cursor goes out of juce::Component, then dragging stops.  
Everything works fine in juce standalone application. Even I checked these events with cocoa application everything works fine.

Please help me in solving this issue.

Thanks & Regards,  
Dheeraj.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 14, 2010, 12:03pm UTC](https://forum.juce.com/t/mouse-event-issue-of-juce-component-on-third-party-nswindow/5773/2 "2010-10-14T12:03:24Z")

</div>

Yes, tracking areas don’t seem to provide a way to keep hold of the mouse events when you move outside - that’s why I avoided using them in the library. I’m afraid you’re on your own with that one!

---

<div class="post-metadata">

**Author:** ![Dheeraj](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@Dheeraj](https://forum.juce.com/u/Dheeraj)\
**Post date:** [October 14, 2010, 12:39pm UTC](https://forum.juce.com/t/mouse-event-issue-of-juce-component-on-third-party-nswindow/5773/3 "2010-10-14T12:39:10Z")

</div>

Can you please give any idea to track this issue where it may be going wrong? I have put logger messages in [NSComponentPeer.mm](http://NSComponentPeer.mm) file but there are no callbacks in drag methods.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 14, 2010, 1:00pm UTC](https://forum.juce.com/t/mouse-event-issue-of-juce-component-on-third-party-nswindow/5773/4 "2010-10-14T13:00:11Z")

</div>

Sorry, all I know is that I tried using tracking a long time ago, and it couldn’t get it to work.
