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.

Securing Web Applications Made Simple and Scalable

More from The Register

next story
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Do YOU work at Microsoft? Um. Are you SURE about that?
Nokia and marketing types first to get the bullet, says report
Microsoft takes on Chromebook with low-cost Windows laptops
Redmond's chief salesman: We're taking 'hard' decisions
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
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.
Reducing security risks from open source software
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.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.