Matt Gemmell

TOLL is available now!

An action-thriller novel — book 2 in the KESTREL series.

★★★★★ — Amazon

MAAttachedWindow NSWindow subclass

development & source 1 min read

I once again come bearing gifts for you: this time it’s MAAttachedWindow, an NSWindow subclass that lets you visually attach borderless windows to other windows or just to specified points on the screen. It’s potentially useful for displaying contextual help, options related to a part of your UI, or just for drawing attention to things.

Take a look at the pic below to see what I mean (you can click it to see a larger version; you’re seeing the demo app included in the download).

I’ve made the class quite configurable, and hopefully you’ll find it useful. Drop me a line in the comments here or via email if you’re using it, or just to lavish some goddamn praise. It’s why I do this, after all (and you thought it was sheer altruism, hah).

There are a bunch of different constructors available, but in most cases you’ll specify a point (either in an existing window, or on screen) at which to attach the window, what side of the point the window should attach to (there are 12 options, plus an “automatic” setting which tries to position the attached window sensibly), and what view to show in the window. Take a look at the sample app to see more about how it works.

Download, as ever, from the Cocoa Source Code page. Please do read the documentation in the MAAttachedWindow.h file; it’ll help you get the most out of the class.

Update: The source has been updated today (5pm GMT on Fri 5th Oct 2007), to fix a possible recursion bug due to the attached window registering for frame-change notifications on itself. We now prevent a potential infinite loop. We also now accept key (but not main) status by default, and have an implementation of -validateMenuItem: which passes off to either the window we’re attached to, or to super.