views:

39

answers:

1

Hi,

I'm developing an application in Cocoa which allows users to draw on any given window in OS X. The drawings move along with the corresponding window when dragged on screen. To complete this tie between drawings and the windows (and their contents) beneath, I'd like to catch scrolling events from the window in order to react on the positioning/visibility of the drawings.

An example:

The user opens Safari and browses the web. On a specific website s/he draws a circle around a link and takes hand written notes (this is all considered a drawing, input by a pen tablet). Afterwards s/he moves the window, the drawings are also being moved so that they remain on top of the link on the website. Then s/he begins to scroll the website and the location of the link changes (moves up until it's outside of the viewport).

Now I'd like to catch that event and also move the layer with the drawings to keep them on top of the link. When the link is no longer visible, I'd turn off the visibility of the drawing and turn it back on when scrolling brings the link back on to the viewport.

I know this is a quite tricky assignment and being able to intercept such events from another application might as well be considered an OS security flaw but maybe someone out there is good enough a coder to give me a hint... :)

The Cocoa Accessibility classes may be helpful but until now I haven't found the solution.

Thanks for your help.

Oh, and if that's not tricky to you, maybe you can tell me how to get notified when Safari switches Tabs ;)

kkthxbai

+1  A: 

I'm not sure if you can monitor scroll events. However, it's a lot easier if you just monitor the position of the link with the Accessibility API.

Just hold a reference to that link and constantly poll it for its position, if the position changes, you know what to do.

You could also try using AXObserverAddNotification, but as far as I am aware, there is no notification you can monitor for position changes.

If you haven't discovered it already, the Accessibility Inspector can help you a lot with identifying things that you can get using the Accessibility API and pfiddlesoft's UI Browser lets you register for notifications.

bogdansrc