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];
}

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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