Blog

Hovering Buttons in an NSTableView

Aug 11, 2007 — Whitney Young (Updated Feb 6, 2008)

iTunes, Mail, and the Finder all have buttons that are displayed in a table view on the right hand side of the cell. When you hover over these buttons, the image used changes to indicate that it's a button. There is really no easy way to add this functionality to your own custom cell. Searching for others who tried to do the same sort of thing pulled up one thread on the coca-dev mailing list with no conclusion to the person's issue.

I just finished adding hoverable buttons to Senuti's source list, and it was very tricky. Here's what I did.

  • Created an NSWindow subclass for custom event dispatching
  • Created an NSTableView subclass for custom event dispatching
  • Created a custom NSCell to handle event notification from the table view

So the cell needs to respond to mouseMoved: events. NSButtonCell does that, you think, but NSButtonCell doesn't receive the events in an NSTableView. So that's what the NSTableView subclass is for. It handles mouse events and dispatches them to the cell. The cell isn't really part of any control, though, and is reused throughout the rows of the table. Therefore, calling the table delegate method, tableView:willDisplayCell:forTableColumn:row:, before sending messages to the cell was necessary. The cell then responds and lets the table view know whether or not it needs to redraw that cell.

And of course, you have to have the table view become the firstResponder in order to receive mouseMoved: events. If it does become the firstResponder, though, then whenever the mouse enters the table view, focus will change to that view. That's not a good thing. That's where the NSWindow subclass comes into play. Each mouseMoved: event tracked in the window is forwarded to a list of additional responders. The table view adds and removes itself from the additional responders list when the mouse enters/exits.

All that's left to do is draw the button image, and update when the mouse enters/leaves/clicks in the button area. Since this post doesn't go into much detail, the implementation of what I did is all available under the GPL. SEButtonImageTextCell, SEEventTable, and SEEventWindow.

1 Comment Tags: Apple, Cocoa, Code, GPL, Objective-C, OS X, Senuti

Mac OS X Client RAID

Apr 23, 2007 — Whitney Young

About a year ago I thought it would be a good idea to buy a spare hard drive and set up RAID 1 (mirrored) on my computer. I've gotten so many emails from users of Senuti who have had failed hard drives. It kind of made me paranoid that my hard drive would fail. A second internal hard drive wasn't too expensive, so I went ahead and bought one.

I got pretty much the same model as the one that came with the computer. Same size and everything; it might have just been a generation newer, but for all intensive purposes, the same drive. It took me a while to get around to setting up the RAID because I needed to format the drive at the same time. I did get around to it eventually, and it went pretty well. Disk Utility was pretty easy to use to set it up. I got a partition on each of the two disks to mirror each other.

Fast forward a year when I decided to try to get more than one partition to work with RAID 1. I don't claim to be an expert with RAIDs, but I can't think of any reason that you wouldn't be able to set up two disks with multiple partitions to mirror each other. Partitions A1, B1, and C1 on the first drive could mirror partitions A2, B2, and C2 on the second drive if the sizes were the same. Disk Utility doesn't let you do this. It doesn't tell you that you can't, though. It will just go ahead and attempt it anyway. You can set up A1 to mirror A2 just fine, but if you try to make B1 mirror B2 it will probably fail to work and also put your A1-A2 RIAD into a degraded state. When I did this, A1 and A2 held all of my important data.

Read More...

No Comments Tags: Apple, OS X, RAID, Tiger

The Switch to Intel

Nov 16, 2005 — Whitney Young

I imagine that the transition should go fairly smoothly. Rosette seems like it will work pretty well for many applications that can't compile right away for x86. By that I mean that from reports it seems like users will be able to run the applications without noticing too much of a speed lag if any at all.

From reports around the internet it seems that Apple might be ahead of schedule. That's all just speculation, so it's hard to say one way or another.

Anyway, my plan at this time is to release universal binaries for each of my applications around the time that the Intel machines start to ship (or possibly sooner). I'll hope to be able to make all of the universal binaries run on the same PPC platforms that they do right now. The information to target different settings for different architectures was buried deep in Apple's documentation, but it looks like it should be possible to get universal binaries that can work on all systems down to the ones that are currently supported. I don't have a way of testing on Intel machines, so I'll have to rely on community feedback (I have recieved a report that Senuti runs just fine on OS X for x86 when compiled for the x86 machines and don't know how it does under Rosette, but that shouldn't be an issue).

I'm posting this to give anyone who strongly objects the chance to do so, but I don't see any reason that anyone would.

No Comments Tags: Cashbox, iColors, OS X, Senuti, TuneKeys, Update

Tiger arrived

May 9, 2005 — Whitney Young

Tiger arrived today. I've had a chance to compile and suppress warnings in Senuti and will check out my other applications over the next few days. So far I am extremely impressed with Tiger. It continues to amaze me that every major upgrade of OS X is significantly faster. I haven't managed to check out all of the 200+ new features yet, but the ones that I have seen appear to be all that Apple said they were. I'd recommend going out and getting a copy as soon as you can, especially those of you still on Jaguar. It'll be worth it!

No Comments Tags: OS X, Senuti

More articles: 1 2