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

Thunderstorm

Jun 27, 2007 — Whitney Young

I started an internship at a local company about two weeks ago. When I say local, I really mean local. I walk 4 blocks to work. So today while I was at work, the lights flickered because of a storm that was passing by. It didn't seem that bad at all, but one of my coworkers joked, "save your work." Of course that's become habit for most of us now. I didn't think much about it until I got home.

I sat down at my computer and tried to wake it up. It didn't work when I clicked the mouse, so I tried the keyboard. No go. All the fans were on in the apartment, so I knew the power was on. The light on the front of the computer was on, too. I remembered the storm and thought that maybe the power had gone off. The clock on the microwave in the kitchen had been reset, so I know that it did. Maybe the computer was just frozen? I tried pushing and holding down the power button to turn it off. The light on the front of it just stayed on, so something was seriously wrong. I got down closer to the computer and realized that it wasn't humming at all (the only humming I heard was of the apartment's fans). Now I started to get reall scared.

I tried turning off the power strip. Sure enough, the light on the front of the computer went off. I turned it back on, and the light turned back on, but the computer still wouldn't start. Maybe one of the outlets was bad? I tried that, too, but nothing. Next step: Apple support. I followed their instructions for if a computer won't start. I reset the SMU both by unplugging the computer for 2 minutes and by opening the computer and pressing the reset button. No luck.

The only things left to do were search the internet or go to an Apple Store and get help. I really didn't feel like lugging my computer to the store. After some googling, I found some people with similar problems. Of course there were the threads on discussion boards that end with people never getting to a solution (I hate those), but one person with the same experience had found the answer before. I'm going to repeat the solution here so that anyone having this issue might be able to find it easier.

If your PowerMac G5 won't start and the power light is always on:

Have you tried pressing the PMU reset button?
This is located close to the center of the RAM slots, at the bottom of the
logic board. You'll have to slide out the inlet fan assembly to see it.
Press and release that button. Do not press a second time, unless this doesn't
help. 
You can also remove the battery (this is in a holder at the top center of the
logic board) Leave this out and the power cord disconnected for 10 minutes or
so. Put the battery back in. reconnect the power cord. Wait 10 seconds. Press
the PMU reset button, Wait 10 more seconds. Make sure the fans are back in
place, and the clear cover is secure. Press the power button.
If it works, you'll need to reset the time and date.
If it doesn't work - take to an Apple auth service.

2 Comments Tags: Apple, Hardware, Personal, PowerMac G5, Thunderstorm

Cleaning Your Apple Mouse

Apr 24, 2007 — Whitney Young

This article is for the Mighty Mouse, but worked just fine for my older Apple wireless mouse: MightyMEng. It worked beautifully. It's like I have a completely new mouse.

1 Comment Tags: Apple, Cleaning, Hardware, Mouse

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

More articles: 1 2