Archive for the ‘Development’ Category

NSScroller

Thursday, February 11th, 2010

I’m ba-ack! I really have been neglecting this block, and I’m going to try to post more often.

The subject of this post is the NSScroller class, since I recently needed to work with it and I found the documentation lacking and a bit out of date. Further, I couldn’t find much about the class on the web, and most of the comments involved sub-classing the control, which really isn’t a good idea. So here is what I’ve learned about NSScroller.

You almost never need to use NSScroller in your code, because NSScrollView will do everything you need. Also, consider using NSSlider instead.

So, you’ve thought about your UI design, and decided that a scroller really is the way to go. So, fire up Interface Builder, open your window, and drag a scroller instance from the palette to your window.

What’s that?

You can’t find the scroller objects in IB? That’s because they’re not there; you’ll have to create the scroller in code. It’s really not that hard. First, figure out where you want the scroller to live on the screen. You’ll need the x,y co-ordinates of the bottom left corner. Now, make a rect with those co-ordinates and the width and length of the scroller you want.

For my horizontal scroller, it looks like this


-(void)awakeFromNib
{
    NSRect winRect = [window frame];
    NSRect scrollFrame = NSMakeRect(20.0, 20.0,
        winRect.size.width -40.0,[NSScroller scrollerWidth] );
    hScroller = [[NSScroller alloc] initWithFrame:scrollFrame];

Here, hScroller is a property so that you can get at it from other places in your code.

Now, there are a few setup steps that are necessary for the scroller to appear in the window.


    // Proportion is the amount of the scroller that
    // the knob takes up,
    // the width of the knob for a horizontal scroller,
    //  or the height for a vertical scroller.
    [hScroller setKnobProportion:0.05];
    // the scroller double value is the position of
    // the knob on the slider, with a range of
    // 0.0 to 1.0
    [hScroller setDoubleValue:0.5];
    [hScroller setEnabled:YES];
    [[window contentView] addSubview:hScroller];

The setEnabled message is necessary because the control defaults to disabled. I suspect this is for the scrollview implementation.

Now, if you run your program, you’ll see a scroller that you can interact with. The arrows work, and sliding the knob works. The next step is dealing with the interactions in code. You need to connect the scroller action to the controller.

So, back in the awakeFromNib method, add two more lines.

SEL mySelector = NSSelectorFromString(@"scrollAction:");
	[hScroller setAction:mySelector];

And that’s it; setup complete.

Now, to handle the messages sent by the scroller, you need to implement the scrollAction method. The trick seems to be to read the hitPart property to figure out which part on the scroller was clicked. Here is a sample handler:


- (IBAction)scrollAction:(id)sender
{
  switch ([hScroller hitPart]) {
  case NSScrollerNoPart:
    break;
  case NSScrollerDecrementPage:
    NSLog(@"decrementPage");
    break;
  case NSScrollerKnob:
    NSLog(@"scrollerKnob, value= %f",[hScroller doubleValue]);
    break;
  case NSScrollerIncrementPage:
    NSLog(@"incrementPage");
    break;
  case NSScrollerDecrementLine:
    NSLog(@"decrementLine");
    break;
  case NSScrollerIncrementLine:
    NSLog(@"incrementLine");
    break;
  case NSScrollerKnobSlot:
    NSLog(@"knobSlot, value= %f",[hScroller doubleValue]);
    break;
  default:
    break;
  }
}

Now, when you get a page or line change you’ll need to adjust the doubleValue accordingly, to reposition the knob.

By experimenting with these messages you should be able to adapt the scroller to suit your needs.

One last thing: the top of the Apple documentation states that setFloatValue:knobProportion: is a commonly used method, but further on down you’ll learn that it is, in fact, deprecated. You should be using setDoubleValue: and setKnobProportion instead.

That’s it. If you have any questions, or anything to add, please let me know in the comments.

Off to See the Wizards

Friday, May 2nd, 2008

I’m heading down to the Apple World-Wide Developers Conference (WWDC) the second week of June. I plan on spending the days in Apple seminars and labs; learning as much as I can from the Apple engineers there. The objectives are to figure out the best way to build Horizon for the iPhone, and pick up enough about Mac development to take Horizon to the next level.

In the evenings I plan on hitting as many gatherings as possible; to shmooz and learn new and better ways to market the program. To that end I’ve started compiling the WWDC party list on Google Calendar. You can subscribe to it, or download the iCal version to your Mac or iPhone.

Here’s the link.

Please let me know of any other gatherings, and I’ll add them to the calendar.

Interview on MacNN

Monday, March 3rd, 2008

Last week, I was interviewed for the macnn podcast. You can find a link to the podcast here, it’s the 4th from the top. Victor Marks of macnn interviewed me about Horizon; how it works, how I developed it, and where it’s going. I hope this provides some insight into the program. Give it a listen and let me know what you think.

Horizon 1.4.1 Data Import

Wednesday, February 27th, 2008

Horizon 1.4.1 is now available. I’ve fixed a few bugs, improved the ‘undo’ code, and added the ability to import from CSV. The CSV function will import files with four or five columns; the ‘category group’ column is optional. You can either put in a header row, or follow the layout described in the Help file, or both.

As always, I’d love to hear feedback on this new feature; what works for you and what doesn’t, so that I can continue to improve the program.

1.4 is Out!

Tuesday, February 12th, 2008

I released version 1.4 of Horizon this morning. The category groups now work as advertised and expected, but Apple sure didn’t make it easy. I had to pull a lot of magic tricks to make things look simple.

Anyway, it’s out, so grab a copy and tell your friends.

Version 1.4 Beta Features

Thursday, January 17th, 2008

I’m adding a major new feature for version 1.4: category groups. Here’s a peek at how it works. You will be able to create groups, and add categories to them, like this:

outlinetest.horizon.jpg

With the group expanded, the Summary View looks like this:

Horizon-1.jpg

If you have a lot of categories, and you’re not interested in the details at the moment, you can collapse the group:

outlinetest.horizon-1.jpg

and the Summary View will summarize the group for you:

Horizon-2.jpg

Once again, I’m looking for beta testers. Because this update changes the structure of the data files, you will have to back up your data (but you do that anyway, don’t you?) and keep a copy of Horizon 1.3.5 around, just to be safe. If you’re interested in testing this version, drop me an email at the contact address and let me know. I’ll send you the link to the beta version. Thanks to everyone who helped test last time, and thanks in advance to everyone who can help with this version.

Version 1.3.5 and a Special Offer

Monday, December 17th, 2007

Version 1.3.5 is available now, either through the Sparkle Update or the download link.. This version adds two date fields to the Summary View. You can use these fields to set the beginning and ending dates for the summary, so you are no longer confined to viewing a single month. This should make it easier to do budgeting and forecasting with Horizon.

The second piece of news is that, for today only, Horizon is available at 20% off the usual price of $29.95 U.S. As part of the MacSanta campaign, you can use the coupon code ‘MACSANTA07′ in the built-in store to get the discount. You might want to visit the MacSanta store as well, to see the other great software deals.

Another Beta Round

Sunday, December 9th, 2007

Version 1.3.5 is ready for beta testing, and it includes a major change to the Summary View. I’d really like to get this release bullet-proof before I release it to the general public, so if you’re interested in playing with it, send me an email.

Fixes and Hints

Monday, December 3rd, 2007

Version 1.3.3 was released yesterday, to fix a couple of regression bugs that crept in. The first bug was really ugly; repeats looked like they had broken. If you moved to another month and then moved back, the repeated cells would appear in the right places. Anyway, this is now fixed.

The second bug had to do with editing a cell that contained a relative reference, like ‘yesterday’ or ‘last week’. Clicking on the cell wouldn’t show the right contents in the edit field. This bug has been there for a while, so I’m surprised no one has noticed it before now.

Finally, I’ve set up a mailing list for Horizon Hints. This will be a weekly email describing some feature or trick, and you can subscribe by filling in the form here. The first hint will go out next week, and I’ll set up an archive for them shortly.

Updates, updates

Thursday, November 29th, 2007

Version 1.3.2 was released yesterday. There are two major new features in 1.3.2. The first is an option in ‘Preferences’ to let you choose which day of the week you want the calendar to start on. In North America and the UK(I think) the calendar starts with Sunday, but in a lot of countries in Europe, the calendar starts with Monday. Now you have the option.

Trust me, Apple didn’t make this easy to implement. Even with all the locale settings, the list of localized day names is hard-wired to start with the local equivalent of ‘Sunday’, so I had to build a way of ’spinning’ the list so that it could start at any day of the week.

The second feature is tied to the first. The calendar now determines how many rows are needed to display the whole month, and draws five or six rows as needed. Of course, changing the start day can affect the number of rows, so the two features are intertwined. I hope they both make Horizon easier to use, and more compatible with the way you work.

Also, I’ve added an RSS feed to the front page of the site. You can subscribe to this feed with your favorite newsreader, and get the news on the latest updates.