Getting mouse events in an NSImageView
Getting mouse events in an NSImageView
- Subject: Getting mouse events in an NSImageView
- From: Christian Mike <email@hidden>
- Date: Thu, 24 Jan 2002 18:43:49 -0500
I am trying to create an x-y graph in a window and allow the user to click
on a point to display the X-Y value at that point. The graph can be bigger
than the window, so I did the following:
- Create an NSWindowController to control the window
- Create an NSImageView to hold the image
- Place the NSImageView in an NSScrollView to handle the scrolling
I created an IBOutlet for the NSImageView and NSScrollView and connected
them in IB. I then create an NSImage dynamically and set it into the
NSImageView.
All of that is working fine. Now I am trying to get the mouseDown events in
the NSImageView. If I add mouseDown to the window controller, it only gets
called when I click in the area of the window outside of the NSScrollView.
If I click in the NSScrollView or the contained image, I don't get any
mouseDown events.
I tried subclassing both the NSImageView and the NSScrollView then making
the IBOutlets be those new sub-classes, however neither of the subclasses
receive mouseDown events. I then tried to go back into IB and make the
connections, but IB claimed that the connections to the views had to be the
exact class of the view. It wouldn't let me connect the subclasses.
So - how do I get the mouseDown events in my NSImageView? It would be even
nicer if I could track the mouse motions while the button was held down.
Thanks.
Michael Christian
Thomson multimedia Inc.