I am using an NSTextField-with-image technique taken from the Drag N Drop 
Outline View sample code, but when the custom cell is "edited" in an 
NSTextField the drawing is offset down and to the right. Unedited drawing is 
fine and editing in an NSTableView is fine. The following code seems most 
relevant:

- (NSRect)titleRectForBounds:(NSRect)cellFrame
{
  NSRect result;
  if (self.validationError != nil)
  {
    CGFloat imageWidth = [self _imageSize].width;
    result = cellFrame;
    result.size.width -= (3 + imageWidth);
  }
  else
  {
    result = [super titleRectForBounds:cellFrame];
  }
  return result;
}

- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText 
*)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
  [super editWithFrame:[self titleRectForBounds:aRect] inView:controlView 
editor:textObj delegate:anObject event:theEvent];
}

- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView 
editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart 
length:(NSInteger)selLength
{
  [super selectWithFrame:[self titleRectForBounds:aRect] inView:controlView 
editor:textObj delegate:anObject start:selStart length:selLength];
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
  if (self.validationError != nil)
  {
    NSRect imageFrame = [self imageRectForBounds:cellFrame];
    [self.errorImage drawInRect:imageFrame fromRect:NSZeroRect 
operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
    CGFloat newX = NSMaxX(imageFrame) + 3;
    cellFrame.size.width = NSMaxX(cellFrame) - newX;
    cellFrame.origin.x = newX;
  }
  [super drawWithFrame:cellFrame inView:controlView];
}

Note that validationError is always null, so I would expect everything to draw 
properly. I vaguely recall mention of this offset issue at some point but Ic 
an't seem to google any references to it. Any help is appreciated.

TIA,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to