/**
TODO : Desciption
*/ @implementation NSCustomImageRep /**Initializes a new NSCustomImageRep with. When a -draw message is recieved it send aSelector message to the delegate anObject. The delegate is not retained, so it is the caller's responsibility to ensure the delegate remains valid for the life of the receiver.
See Also: -delegate -drawSelector [NSImageRep-draw]
*/ - (id) initWithDrawSelector: (SEL)aSelector delegate: (id)anObject { if ( ! ( self = [super init] ) ) return nil; _delegate = anObject; _selector = aSelector; return self; } - (void) dealloc { [super dealloc]; } /**Returns the NSCustomImageRep's delegate.
See Also: -initWithDrawSelector:delegate:
*/ - (id) delegate { return _delegate; } /**Returns the draw method sent to the delegate when NSCustomImageRep recieved a -draw message.
See Also: -initWithDrawSelector:delegate: [NSImageRep-draw]
*/ - (SEL) drawSelector { return _selector; } - (BOOL) draw { [_delegate performSelector: _selector withObject: self]; return YES; } // // TODO: For both of the following methods we can extract the // logic in the superclass to another method and call it here // if the delegate is set from both places. // - (BOOL) drawAtPoint: (NSPoint)aPoint { BOOL ok, reset; NSGraphicsContext *ctxt; NSAffineTransform *ctm = nil; // if both are zero and the delegate isn't set, return no. if (_size.width == 0 && _size.height == 0 && _delegate == nil) return NO; NSDebugLLog(@"NSImage", @"Drawing at point %f %f\n", aPoint.x, aPoint.y); reset = 0; ctxt = GSCurrentContext(); if (aPoint.x != 0 || aPoint.y != 0) { ctm = GSCurrentCTM(ctxt); DPStranslate(ctxt, aPoint.x, aPoint.y); reset = 1; } ok = [self draw]; if (reset) GSSetCTM(ctxt, ctm); return ok; } - (BOOL) drawInRect: (NSRect)aRect { NSSize scale; BOOL ok; NSGraphicsContext *ctxt; NSAffineTransform *ctm; NSDebugLLog(@"NSImage", @"Drawing in rect (%f %f %f %f)\n", NSMinX(aRect), NSMinY(aRect), NSWidth(aRect), NSHeight(aRect)); // if both are zero and the delegate isn't set. if (_size.width == 0 && _size.height == 0 && _delegate == nil) return NO; ctxt = GSCurrentContext(); // if either is zero, don't scale at all. if (_size.width == 0 || _size.height == 0) { scale = NSMakeSize(1, 1); } else { scale = NSMakeSize(NSWidth(aRect) / _size.width, NSHeight(aRect) / _size.height); } ctm = GSCurrentCTM(ctxt); DPStranslate(ctxt, NSMinX(aRect), NSMinY(aRect)); DPSscale(ctxt, scale.width, scale.height); ok = [self draw]; GSSetCTM(ctxt, ctm); return ok; } // NSCoding protocol - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; if ([aCoder allowsKeyedCoding]) { // FIXME } else { // FIXME: Should this be changed to encodeConditionalObject: ? [aCoder encodeObject: _delegate]; [aCoder encodeValueOfObjCType: @encode(SEL) at: &_selector]; } } - (id) initWithCoder: (NSCoder*)aDecoder { self = [super initWithCoder: aDecoder]; if ([aDecoder allowsKeyedCoding]) { // FIXME } else { [aDecoder decodeValueOfObjCType: @encode(id) at: &_delegate]; [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_selector]; } return self; } @end