Feeds

New vistas with windows frames

Open your mind

Combat fraud and increase customer satisfaction

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.

High performance access to file storage

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Batten down the hatches, Ubuntu 14.04 LTS due in TWO DAYS
Admins dab straining server brows in advance of Trusty Tahr's long-term support landing
Inside the Hekaton: SQL Server 2014's database engine deconstructed
Nadella's database sqares the circle of cheap memory vs speed
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Internet-of-stuff startup dumps NoSQL for ... SQL?
NoSQL taste great at first but lacks proper nutrients, says startup cloud whiz
Windows 8.1, which you probably haven't upgraded to yet, ALREADY OBSOLETE
Pre-Update versions of new Windows version will no longer support patches
IRS boss on XP migration: 'Classic fix the airplane while you're flying it attempt'
Plus: Condoleezza Rice at Dropbox 'maybe she can find ... weapons of mass destruction'
prev story

Whitepapers

Designing a defence for mobile apps
In this whitepaper learn the various considerations for defending mobile applications; from the mobile application architecture itself to the myriad testing technologies needed to properly assess mobile applications risk.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.
Five 3D headsets to be won!
We were so impressed by the Durovis Dive headset we’ve asked the company to give some away to Reg readers.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Securing web applications made simple and scalable
In this whitepaper learn how automated security testing can provide a simple and scalable way to protect your web applications.