Aperture Plugin: Making A Customized Button

cocoasmall
The next feature I want to add is a Bagelturf badge that can be clicked to launch a browser to my home page. For that I need a graphic and some way of making a click open a URL. Since the badge won't obviously be a button, or have a button action, I want the cursor to change to a pointing hand to show that it is clickable.
rwok230
After a lot of messing about with tracking rectangles I discovered that the correct way to implement the pointing hand was by using -resetCursorRects. I have to subclass NSButton and then override -resetCursorRects to define the cursor shape that I want when the cursor is inside my button.

First I drag a button in Interface Builder onto my window and select the Rounded bevel Button type. Then I create a new file and declare it as a subclass of NSButton using this code:
rwok200
Then I add the implementation code:
rwok201
To use the custom class in my nib file, I save those files and drag the .h file onto my nib file. This makes the nib file aware of the custom class and selects the class:
rwok202
Now I can select my button and set its custom class to BTPointingHandButton:
rwok203
By making a small image in Photoshop that has transparent background and saving it as a TIFF, I can have the image lay on the window background. To add the image to my XCode project I drag it onto the Resources folder and opt to copy it in.
rwok231
Clicking on the image and using the inspector shows me what is there:
rwok204
By dragging the image onto the button, the image is automatically set:
rwok205
And finally I can add an action to File's owner via the attributes pane called bagelturfAction and hook it up to the button with control-drag. To make the action open a URL I add the action code to Random_Wok.m and use NSWorkspace's openURL method:
rwok206
Done. Now if I hover over the button the cursor changes and a click launches Safari and goes to my home page.

The other parts of this series can be found via the Cocoa page.
The Bagelturf site welcomes Donations of any size