My application has a custom view that displays a timeline of events. This view is wrapped in an NSScrollView
to support horizontal scrolling of the timeline. Using notifications, I've implemented a mechanism that should show another custom view which displays detail information about an event when the user clicks that event in the timeline. Below is the code that handles the event when it is received by the timeline:
NSEvent *anEvent = [aNotification object];
NSPoint aLocationInSelf = [self convertPoint: [anEvent locationInWindow] toView: self];
// Create callout view and display
NSRect aRect = NSMakeRect(aLocationInSelf.x, aLocationInSelf.y, 300, 200);
TimelineCallout *aCallout = [[TimelineCallout alloc] initWithFrame: aRect];
[self addSubview: aCallout];
In the above code I do a conversion of the point of the mouse click as registered by the event from window coordinates to view (timeline) coordinates.
However, when I step through this with the debugger no conversion is taking place and locationInSelf
shows the same coordinates as the point I get from [anEvent locationInWindow]
. As a result the callout is drawn at the wrong place or not visible at all.
I must be doing something wrong but I can't figure out what...