Matt Legend Gemmell Modesty is Lying

Mac OS X Cocoa and iPhone Development Services available at Instinctive Code.
Mac OS X Cocoa and iPhone Developer for hire

Other Pages

Categories

Posted
12 October 2006 @ 10pm

Categories
Development, Source

Tags
, , , , ,

More RoundedBox updates

This time… it’s editable.

Specifically, the title is editable; just click into it and type. I realise it’s slightly bizarre to have a box whose title is user-editable, but I’m going somewhere with this, so just relax, damn it.

There are still some weird issues with editing, such as when you click at the very end of the title text to edit it, then immediately press Return, the text vanishes from sight - though it’s still actually there. Anyone know why that happens? The view doesn’t get a -textDidChange: notification in these circumstances, if that helps (so it’s not like it’s inserting a superfluous newline).

Obviously, the view now also uses its titleCell to draw its title, rather than drawing text into its background. This is long overdue and much, much better, giving us stuff like automatically shunting the subviews down as the title font size increases, and presumably providing better accessibility features. Anyhow, get it from the Cocoa Source Code page as usual.

My closing remarks tonight will consist of just these two items:

  • Trac + Subversion = good^2
  • I am more like Superman than anyone else I know

I bid you a pleasant evening.


4 Comments

Jesper
12 October 2006 @ 11pm

Newlines, Superman? ;)


Matt Gemmell
13 October 2006 @ 9am

Hey Jesper,

Like I said, if it was a newline being inserted, surely the field editor’s delegate would get a -textDidChange: notification? The RoundedBox itself is the field editor’s delegate; try implementing -textDidChange: (for example to just NSLog the notification object’s -string) and you’ll see that no such notification is given when the field blanks out after pressing return. Am I missing something?

- (void)textDidChange:(NSNotification *)notification
{
NSLog(@”fieldEditor’s contents are: %@”,
[(NSText *)[notification object] string]);
}


Matt
15 October 2006 @ 5pm

Solved the issue. Since the -drawRect: implementation was calling the titleCell’s -drawInteriorWithFrame: method, the titleCell had no background (that was deliberate). Thus, I used the _drawsTitle flag to determine whether to ask the titleCell to draw itself at any given time, so that whenever title editing began, I could essentially “hide” the titleCell (because otherwise it would show through beneath the fieldEditor, giving an unpleasant double-text effect).

I set the titleCell to show itself once again in the -textShouldEndEditing: implementation, but of course that isn’t always called, hence the vanishing text problem: hitting Return was ending editing without calling -textShouldEndEditing:, so the titleCell wasn’t being redisplayed. The fix, of course, was to do the title updating (and reset the title cell’s visibility) in -textDidEndEditing: instead of in -textShouldEndEditing:.

In short, make the -textShouldEndEditing: implementation just return YES, and move all the rest of the crap from that method into the -textDidEndEditing: implementation instead.


Barnaby
25 April 2007 @ 10pm

The RoundedBox on the source page doesn’t support editing the title. I’ve tried recompiling it from source. I did notice that the dates on the source files coincide with the earlier post on the source being updated. Is it possible to take a look at the update with the editable title?

Very nice source, btw.


Leave a Comment

RoundedBox source code updated Applications 2.0