Feeds

New vistas with windows frames

Open your mind

Boost IT visibility and business value

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.

Boost IT visibility and business value

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
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
Leaked Windows Phone 8.1 Update specs tease details of Nokia's next mobes
New screen sizes, dual SIMs, voice over LTE, and more
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
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
Mozilla keeps its Beard, hopes anti-gay marriage troubles are now over
Plenty on new CEO's todo list – starting with Firefox's slipping grasp
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
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.
Backing up Big Data
Solving backup challenges and “protect everything from everywhere,” as we move into the era of big data management and the adoption of BYOD.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
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.