Feeds

Leopard pimpin' method madness

Surf the information super hierarchy

Choosing a cloud hosting partner with confidence

Mac secrets Having dipped into the undocumented frame class used by NSWindow to handle the parts of a window not directly under the control of the application program, its time to go further. Let's dig into the methods exposed by the frame class hierarchy.

The hierarchy of undocumented classes will become obvious if you checked out the source code for last month's project, especially the header files.

At the lowest level, NSFrameView is a direct descendant of NSView. Amongst other things, NSFrameView defines the instance variables for the aforementioned close, zoom and minimize buttons. It also takes care of managing the _titleCell (actually, an instance of NSTextFieldCell) that implements a window's caption.

You might think that by simply sub-classing the frame class (NSThemeFrame, as I demonstrated last time) it should be possible to directly access the titleCell variable and, for example, change the colour of the displayed text in a caption bar. In fact this won't work; the color used for the caption bar text is supplied "on the fly" by another routine with the method signature _drawTitleStringIn:withColor:.

You can see how to exploit this method from a custom frame class below:


- (void) _drawTitleStringIn: (NSRect) rect withColor: (NSColor *) color
{
        [super _drawTitleStringIn: rect withColor: [NSColor redColor]];
}

As you'd expect, this will give you a bright red window title: definitely not something you'd ordinarily want to do, except when displaying an "Are you sure you want to reformat the universe?" dialog box.

Although changing the text color of the caption bar's title cell isn't easy unless you're using the method above, it is relatively straightforward to change the background color of the caption text. Simply set up the titleCell instance variable from inside the initializer of your custom frame class like this:


- (id) initWithFrame: (NSRect) frame styleMask: (unsigned) style owner:(id) owner
{
        self = [super initWithFrame: frame styleMask: style owner: owner];
        if (self)
        {
                NSTextFieldCell * cell = [self titleCell];
                [cell setBackgroundColor: [NSColor yellowColor]];
                [cell setDrawsBackground: YES];
        }
        
        return self;
}

The NSTitledFrame class inherits from NSFrameView and NSThemeFrame inherits from NSTitledFrame. If you want to do other unspeakable things to the caption bar, then check out two other routines that are implemented by these classes: titlebarRect returns an NSRect, which corresponds to the entire area of the caption bar, and _titlebarTitleRect, which returns an NSRect that just covers the window title itself.

Window with extra shadow

Demo app sporting a little extra shadow

Another interesting aspect of the frame classes hierarchy is the code that handles the shadow effects associated with a window. The "official" API control you have here is pretty minimalist: you can use the setHasShadow: method to determine whether or not your window has a shadow, and that's about it.

Secure remote control for conventional and virtual desktops

More from The Register

next story
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
You stupid BRICK! PCs running Avast AV can't handle Windows fixes
Fix issued, fingers pointed, forums in flames
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
First in line to order a Nexus 6? AT&T has a BRICK for you
Black Screen of Death plagues early Google-mobe batch
prev story

Whitepapers

Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Driving business with continuous operational intelligence
Introducing an innovative approach offered by ExtraHop for producing continuous operational intelligence.
10 threats to successful enterprise endpoint backup
10 threats to a successful backup including issues with BYOD, slow backups and ineffective security.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?