Feeds

Leopard pimpin' method madness

Surf the information super hierarchy

Build a business case: developing custom apps

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.

Boost IT visibility and business value

More from The Register

next story
The Return of BSOD: Does ANYONE trust Microsoft patches?
Sysadmins, you're either fighting fires or seen as incompetents now
Microsoft refuses to nip 'Windows 9' unzip lip slip
Look at the shiny Windows 8.1, why can't you people talk about 8.1, sobs an exec somewhere
Intel's Raspberry Pi rival Galileo can now run Windows
Behold the Internet of Things. Wintel Things
Linux Foundation says many Linux admins and engineers are certifiable
Floats exam program to help IT employers lock up talent
Microsoft cries UNINSTALL in the wake of Blue Screens of Death™
Cache crash causes contained choloric calamity
Eat up Martha! Microsoft slings handwriting recog into OneNote on Android
Freehand input on non-Windows kit for the first time
Linux kernel devs made to finger their dongles before contributing code
Two-factor auth enabled for Kernel.org repositories
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.
7 Elements of Radically Simple OS Migration
Avoid the typical headaches of OS migration during your next project by learning about 7 elements of radically simple OS migration.
BYOD's dark side: Data protection
An endpoint data protection solution that adds value to the user and the organization so it can protect itself from data loss as well as leverage corporate data.
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.
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?