+@interface NSWindow (wxNSWindowSupport)
+
+- (wxNonOwnedWindowCocoaImpl*) WX_implementation;
+
+- (bool) WX_filterSendEvent:(NSEvent *) event;
+
+@end
+
+@implementation NSWindow (wxNSWindowSupport)
+
+- (wxNonOwnedWindowCocoaImpl*) WX_implementation
+{
+ return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
+}
+
+// TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occured,
+// this does not conform to the wx behaviour if the window is not captured, so try to resend
+// or capture all wx mouse event handling at the tlw as we did for carbon
+
+- (bool) WX_filterSendEvent:(NSEvent *) event
+{
+ bool handled = false;
+ if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) )
+ {
+ WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
+ WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
+
+ wxWindow* cw = wxWindow::GetCapture();
+ if ( cw != NULL )
+ {
+ if (wxTheApp)
+ wxTheApp->MacSetCurrentEvent(event, NULL);
+ ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
+ handled = true;
+ }
+ else if ( [event type] == NSMouseMoved )
+ {
+ NSPoint nsPoint = [event locationInWindow];
+ if ( [event window] != nil )
+ nsPoint = [[event window] convertBaseToScreen:nsPoint];
+
+ wxPoint pt = wxFromNSPoint(NULL, nsPoint);
+ wxWindow* mw = ::wxFindWindowAtPoint(pt);
+ if ( mw )
+ {
+ if (wxTheApp)
+ wxTheApp->MacSetCurrentEvent(event, NULL);
+ ((wxWidgetCocoaImpl*)mw->GetPeer())->DoHandleMouseEvent( event);
+ handled = true;
+ }
+ }
+ if ( handled )
+ {
+ if (wxTheApp)
+ wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
+ }
+ }
+ return handled;
+}
+@end
+
+//
+// wx native implementation
+//