Feeds

New vistas with windows frames

Open your mind

Next gen security for virtualised datacentres

Mac Secrets Time to look at the mysterious 'borderView' object, used by the Cocoa libraries to render a window to the screen. Although you'll not often need the specialised facilities provided by the border view, they can be very useful when creating certain kinds of application.

Here's a little experiment you can try. In xCode, create a new, windowed Cocoa application and then add a subclass of NSWindow. You can call this subclass anything you like, but I called mine MyAppWindow. Now go into Interface Builder and change the class of the application window to match. Finally, go into MyAppWindow.m, add an awakeFromNib method, and put the following code inside it:

 

NSLog ([[self _borderView] className]);

When you build the application, the compiler will whinge that the window might not respond to the _borderView selector. If you want to shut the compiler up, check out how I do it by downloading the sample application, at the end. When you run the app, you should see the string NSThemeFrame displayed on the Console. So, what is the border view, and why should you care?

Cocoa programmers are generally only concerned with the content area of a window, and ordinarily, this is the only part of the window they have direct control over. However, the minimize, maximize and close buttons, together with the whole title-bar area are also part of the window, as are the bottom left- and right-hand corners.

All this stuff is handled by a specialised hierarchy of NSView descendents, of which NSThemeFrame is the most commonly encountered. The undocumented _borderView selector returns an instance of this class, which is referred to as a border view or frame view.

Work with handlers

So what can we do with it? If you look at the methods associated with NSThemeFrame, you'll see a couple called setIsClosable: and setIsResizable:. As the name suggests, you can use these methods to control whether or not the window shows a close button, or can be resized. To show this functionality, I added a couple of checkboxes to this month's demo program at the end, and hooked them up to these action handlers:

 

- (IBAction) toggleClosable: (id) sender
{
        [[self _borderView] setIsClosable: [sender state]];
}

- (IBAction) toggleSizable: (id) sender
{
        [[self _borderView] setIsResizable: [sender state]];
}

Ordinarily, you control whether a window can be closed or resized when creating the window, but in exceptional circumstances, you might want to programmatically change these attributes on the fly. (Hint: think of the Karelia Media Browser, and how the window "flips" over. You might want one side of your window to be resizable, and the other not).

Accessing these frame view methods makes this dead easy.

Build a business case: developing custom apps

More from The Register

next story
Why has the web gone to hell? Market chaos and HUMAN NATURE
Tim Berners-Lee isn't happy, but we should be
Mozilla's 'Tiles' ads debut in new Firefox nightlies
You can try turning them off and on again
Microsoft boots 1,500 dodgy apps from the Windows Store
DEVELOPERS! DEVELOPERS! DEVELOPERS! Naughty, misleading developers!
'Stop dissing Google or quit': OK, I quit, says Code Club co-founder
And now a message from our sponsors: 'STFU or else'
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
Uber, Lyft and cutting corners: The true face of the Sharing Economy
Casual labour and tired ideas = not really web-tastic
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
prev story

Whitepapers

Gartner critical capabilities for enterprise endpoint backup
Learn why inSync received the highest overall rating from Druva and is the top choice for the mobile workforce.
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.
Rethinking backup and recovery in the modern data center
Combining intelligence, operational analytics, and automation to enable efficient, data-driven IT organizations using the HP ABR approach.
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.
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.