When I get a mouseDragged event, how can I find out if it is dragging a window or just a file? - cocoa

I want to respond to the drag event when it is dragging a file but not a window.
I got the mouseDragged event like this:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDraggedMask
handler: ^(NSEvent *mouseDraggedEvent){
//do something with event
}];

The drag and drop system is implemented atop the event-handling system. The event-handling system (which is what you are monitoring) has no concept of what is being dragged, just that a mouse drag is occurring.
If you want to know what is being dragged then you will need to record the location of the mouse at the start of the drag and use that to calculate what is being dragged. You could use the accessibility APIs for this.

Related

How to capture Datawindow move event?

My Datawindow has title with it and user can drag it inside main window anywhere.
I need to move other controls away in the main window to make room for new position for the Datawindow control at runtime.
I dont want to do it with mousemove or drag events because that will increase my code like grass.
Simple move of the control should have a way somehow.
How do i capture the move event for the datawindow control?
You can create a custom event on the datawindow mapped to pbm_dwnmousemove. Within your new event you would have to check to see if the datawindow is moving on top of the other controls and then re-position them as appropriate.

Changing NSCollectionView dragging image while moving mouse around

I use a NSCollectionView as a toolbox (like in Xcode's Interface Builder). When dragging a tool out of the collection view I would like to change the "dragging image" under the mouse cursor into the real tool image. It should behave similar to Interface Builder when dragging a UI item into the users canvas. Es expected, it should change back to the previous image when I move the mouse back into the collection view.
I tried several delegate methods, but I can't see a way to change the cursor image during mouse movement.
Any suggestions?
Thanks to all! :-)
Regards,
Ulf
make a subclass of nscollectionview
override
func beginDraggingSession(with items: [NSDraggingItem], event: NSEvent, source: NSDraggingSource) -> NSDraggingSession
use setDraggingFrame(_:contents:)
you can get the mouse point from event.locatoinInWindow (dont forget converting to your collectionview cordinate)

Detect double-click mouse event in a MKMapView (not iOS touch event)

I am writing a custom app using a MKMapView, and I need add a place mark in the map by clicking in the map view, but the mouseDown method is never called. I can not find any doc in the apple developer help.
Place a MKAnnotation is not problem.
Any one can help me with this
You'll need to disable mouse interaction with the MKMapView, by setting the scrollEnabled and zoomEnabled properties to No.
Once those are set the mouseDown and other mouse events fire as expected.

Programmatic start NSSlider dragging

I would like to start a slider action programmatically. So pressing on some text in a NSTextView that displays a slider also automatically starts the mousedown event on the slider so you can drag immediately instead of pressing twice. What approach should i take on this? Should i listen for global mouse events and then manually update the slider position, or can i somehow imitate the systems mouseDown / mouseMoved calls on the NSSlider?

MouseDragged not released when dragging on other views

I have 2 subclasses of NSView that are subviews to a common superview. They dont overlap and they both intercept mousedragged calls. When I drag from one of the subclasses to the other the mousedragged function will be called until I release the mouse button even when I drag all over the screen. I though the default behavior was for the mousedragged function to be called only when the mouse was over the bounds of the receiver.
Iam also using NSTrackingArea for mouse enter, exit and move events, but from what I've been reading does not involve drag events
Thank you for your time,
Jose.
You could subclass the NSWindow and override sendEvent:. That way, you can intercept the NSLeftMouseDragged events and dispatch them in whatever way you wish.

Resources