I'm subclassing NSTextFieldCell to display an icon (a favicon of a webpage,
to be specific) in the left end of the text field. The text field's cell is
set to my subclass in Interface Builder. When I start my application, the
icon is displayed, but the text that should be in the text field is not.
When the text field is in focus, it beeps every time you hit a key and
doesn't display the key you pressed. I've been trying to figure this out for
quite awhile to no avail. Here is the interface file:

@interface SBIconTextFieldCell : NSTextFieldCell {

    NSImage *icon;

}

@property(nonatomic, retain) NSImage *icon;

@end

And this is the implementation file:

#import "SBIconTextFieldCell.h"


@implementation SBIconTextFieldCell

- (NSImage *)icon {

    return icon;

}

- (void)setIcon:(NSImage *)newValue {

    [icon release];

    icon = [newValue retain];

    [icon setFlipped:YES];

    if (icon) [[self controlView] setNeedsDisplayInRect:NSMakeRect(2, 3, 16,
16)];

    else [[self controlView] setNeedsDisplay:YES];

}

- (void)dealloc {

    [icon release];

    [super dealloc];

}

- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView {

   NSRect rect = NSMakeRect(2, 3, 16, 16);

    if ([controlView needsToDrawRect:rect])

        [icon drawInRect:rect fromRect:NSZeroRect operation:
NSCompositeSourceOver fraction:1];

    if (icon) {

        frame.origin.x += 16;

        frame.size.width -= 16;

    }

    [super drawInteriorWithFrame:frame inView:controlView];

}

- (void)editWithFrame:(NSRect)rect inView:(NSView *)view
editor:(NSText*)text delegate:(
id)object

                event:(NSEvent *)event {

    if (icon) {

        rect.origin.x += 16;

        rect.size.width -= 16;

    }

    [super editWithFrame:rect inView:view editor:text delegate:object event
:event];

}

- (void)selectWithFrame:(NSRect)rect inView:(NSView *)view
editor:(NSText*)text delegate:(
id)object

                  start:(NSInteger)start length:(NSInteger)length {

    if (icon) {

        rect.origin.x += 16;

        rect.size.width -= 16;

    }

    [super selectWithFrame:rect inView:view editor:text delegate:object
start:start length:length];

}

@end

Does anyone have insight as to what I'm doing wrong?
_______________________________________________

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 arch...@mail-archive.com

Reply via email to