On Jul 13, 2008, at 12:46 AM, Jens Alfke wrote:


On 12 Jul '08, at 7:50 PM, Stefan Arentz wrote:

I would like to use text labels that turn into editable text fields when you click them. Like Address Book has when you edit an address card. Does anyone know how those work? Is it a matter of flipping the editable property or are those custom controls?

You can implement a text field like that fairly easily; I have one that's a subclass of NSTextField overriding two methods (see below).

What Address Book does is a different matter. The card is, I believe, a single NSTextView with some tricky delegate methods that control what ranges of the text are editable and selectable.

—Jens

- (void) mouseDown: (NSEvent*)event
{
   if( ! [self isEditable] ) {
       [self setBezeled: YES];
       [self setDrawsBackground: YES];
       [self setEditable: YES];
       self.frame = NSInsetRect(self.frame, -2, -3);
       [self.window makeFirstResponder: self];
   }
}

- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
{
   if( [self isEditable] ) {
       [self setEditable: NO];
       [self setDrawsBackground: NO];
       [self setBezeled: NO];
       self.frame = NSInsetRect(self.frame, 2, 3);
   }
   return [super sendAction: theAction to: theTarget];
}

Thanks Jens. That looks like a good start.

I did remember where I found some more 'official' code now btw. It was part of a Cocoa Techniques session at WWDC 2003. I did attend that WWDC but I can't find that code in my ADC account anymore. I guess it is too old. Does anyone still have a copy of that code? Or was it ever put on a developer DVD?

 S.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to