Feeds

Leopard pimpin' method madness

Surf the information super hierarchy

The Power of One Brief: Top reasons to choose HP BladeSystem

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.

Seven Steps to Software Security

More from The Register

next story
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
KDE releases ice-cream coloured Plasma 5 just in time for summer
Melty but refreshing - popular rival to Mint's Cinnamon's still a work in progress
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Application security programs and practises
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Securing Web Applications Made Simple and Scalable
Learn how automated security testing can provide a simple and scalable way to protect your web applications.