FROM : Julian Cain
DATE : Fri Apr 01 19:52:54 2005
Well, the thing is in my custom cell I am doing all this...
static id _imageLeft = nil;
static id _imageMiddle = nil;
static id _imageRight = nil;
static id _imageLeftPress = nil;
static id _imageMiddlePress = nil;
static id _imageRightPress = nil;
static id _imageLeftRoll = nil;
static id _imageMiddleRoll = nil;
static id _imageRightRoll = nil;
static id _badge = nil;
static BOOL _mouseIsOver = NO;
@implementation SSTBButtonCell
/* don't have a clue */
- (id)initWithCoder:(NSCoder *)coder {
NSLog(@"Initing custom cell");
[super initWithCoder:coder];
_imageLeft = [coder decodeObjectForKey:@"kLeftImage"];
_imageLeftPress = [coder decodeObjectForKey:@"kLeftImagePress"];
_imageLeftRoll = [coder decodeObjectForKey:@"kLeftImageRoll"];
return self;
}
/* don't have a clue */
- (void)encodeWithCoder:(NSCoder *)coder {
NSLog(@"Encoding custom cell");
[super encodeWithCoder:coder];
[coder encodeObject:_imageLeft forKey:@"kLeftImage"];
[coder encodeObject:_imageLeftPress forKey:@"kLeftImagePress"];
[coder encodeObject:_imageLeftRoll forKey:@"kLeftImageRoll"];
}
+ (void)initialize {
static BOOL initialized = NO;
if(!initialized ) {
initialized = YES;
[super initialize];
/* Normal */
_imageLeft = [[[NSImage imageNamed:@"TB_Segment_LeftCap"]
setFlipped:YES] retain];
_imageMiddle = [[[NSImage imageNamed:@"TB_Single_Middle"]
setFlipped:YES] retain];
_imageRight = [[[NSImage imageNamed:@"TB_Segment_RightCap"]
setFlipped:YES] retain];
/* Press */
_imageLeftPress = [[[NSImage imageNamed:@"TB_Segment_LeftCapPress"]
setFlipped:YES] retain];
_imageMiddlePress = [[[NSImage imageNamed:@"TB_Single_MiddlePress"]
setFlipped:YES] retain];
_imageRightPress = [[[NSImage imageNamed:@"TB_Segment_RightCapPress"]
setFlipped:YES] retain];
/* Roll */
_imageLeftRoll = [[[NSImage imageNamed:@"TB_Segment_LeftCapRoll"]
setFlipped:YES] retain];
_imageMiddleRoll = [[[NSImage imageNamed:@"TB_Single_MiddleRoll"]
setFlipped:YES] retain];
_imageRightRoll = [[[NSImage imageNamed:@"TB_Segment_RightCapRoll"]
setFlipped:YES] retain];
_badge = [[[NSImage imageNamed:@"TB_CustomizeToolbar"]
setFlipped:YES] retain];
}
}
- (void)dealloc {
delete(_imageLeft);
delete(_imageMiddle);
delete(_imageRight);
delete(_imageLeftPress);
delete(_imageMiddlePress);
delete(_imageRightPress);
delete(_imageLeftRoll);
delete(_imageMiddleRoll);
delete(_imageRightRoll);
delete(_badge);
[super dealloc];
}
/*
* TODO: add "Inactive"
*/
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)view {
[super drawWithFrame:cellFrame inView:view];
[[NSColor controlBackgroundColor] set];
NSRectFill(cellFrame);
NSImage * buttonImageLeft;
NSImage * buttonImageMiddle;
NSImage * buttonImageRight;
if([self isHighlighted]) {
buttonImageLeft = _imageLeftPress;
buttonImageMiddle = _imageMiddlePress;
buttonImageRight = _imageRightPress;
} else if(_mouseIsOver) {
buttonImageLeft = _imageLeftRoll;
buttonImageMiddle = _imageMiddleRoll;
buttonImageRight = _imageRightRoll;;
} else {
buttonImageLeft = _imageLeft;
buttonImageMiddle = _imageMiddle;
buttonImageRight = _imageRight;
}
[buttonImageLeft
drawAtPoint:NSMakePoint(0, 0)
fromRect:NSMakeRect(0, 0, 15, 23)
operation:NSCompositeSourceOver fraction:1.0];
[buttonImageMiddle
drawInRect:NSMakeRect(11, 0, 15, 23)
fromRect:NSMakeRect(0, 0, 0, 23)
operation:NSCompositeSourceOver fraction:1.0];
[buttonImageRight
drawAtPoint:NSMakePoint(26, 0)
fromRect:NSMakeRect(0, 0, 15, 23)
operation:NSCompositeSourceOver fraction:1.0];
[_badge drawAtPoint:NSMakePoint(5, 1) fromRect:NSMakeRect(0, 0, 0, 23)
operation:NSCompositeSourceOver fraction:1.0];
}
~Julian
On Apr 1, 2005, at 11:52 AM, daniel wrote:
> Since the image is associated with the cell, and not with the button
> itself, you have to copy over the image from the old cell, too. I
> assume the title is carrying over OK?
>
> It looks like your custom cell is available in time to receive the
> image during the toolbar's initial creation of the toolbar items, but
> when it gets "packed up and moved", you are not replacing the image in
> the new cell you create.
>
> Daniel
>
> On Apr 1, 2005, at 8:25 AM, Julian Cain wrote:
>
> I have also changed "initWithCoder" to no avail...
>
> - (id)initWithCoder:(NSCoder *)coder {
> if( ( self = [super initWithCoder:coder] ) ) {
> NSButtonCell *oldCell = [self cell];
> NSLog(@"initWithCoder:");
> SSTBButtonCell *cell = [[SSTBButtonCell alloc] init];
> //[cell setImage[self cell] image]];
> [cell setAttributedStringValue:[oldCell attributedStringValue]];
> [cell setTarget:[oldCell target]];
> [cell setAction:[oldCell action]];
> [cell setAlignment:[oldCell alignment]];
> [cell setTitle:[oldCell title]];
> [cell setBordered:YES];
> [self setCell:cell];
> [cell release];
> }
> return self;
> }
>
> -Julian
> On Apr 1, 2005, at 10:06 AM, j o a r wrote:
>
>
>
> On 2005-04-01, at 15.30, Julian Cain wrote:
>
>
> I have created a subclassed NSButton which I have in an NSToolbar,
> however when I run the customization palette the button image goes
> blank on the palette and toolbar. My Button code looks like so:
>
>
> It seems to me that you have an incorrect implementation of NSCoding.
> You only set the custom button cell type when you "-initWithFrame:",
> not when you "-initWithCoder:".
>
> j o a r
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>-
> sweater.com
>
> This email sent to <email_removed>
>
DATE : Fri Apr 01 19:52:54 2005
Well, the thing is in my custom cell I am doing all this...
static id _imageLeft = nil;
static id _imageMiddle = nil;
static id _imageRight = nil;
static id _imageLeftPress = nil;
static id _imageMiddlePress = nil;
static id _imageRightPress = nil;
static id _imageLeftRoll = nil;
static id _imageMiddleRoll = nil;
static id _imageRightRoll = nil;
static id _badge = nil;
static BOOL _mouseIsOver = NO;
@implementation SSTBButtonCell
/* don't have a clue */
- (id)initWithCoder:(NSCoder *)coder {
NSLog(@"Initing custom cell");
[super initWithCoder:coder];
_imageLeft = [coder decodeObjectForKey:@"kLeftImage"];
_imageLeftPress = [coder decodeObjectForKey:@"kLeftImagePress"];
_imageLeftRoll = [coder decodeObjectForKey:@"kLeftImageRoll"];
return self;
}
/* don't have a clue */
- (void)encodeWithCoder:(NSCoder *)coder {
NSLog(@"Encoding custom cell");
[super encodeWithCoder:coder];
[coder encodeObject:_imageLeft forKey:@"kLeftImage"];
[coder encodeObject:_imageLeftPress forKey:@"kLeftImagePress"];
[coder encodeObject:_imageLeftRoll forKey:@"kLeftImageRoll"];
}
+ (void)initialize {
static BOOL initialized = NO;
if(!initialized ) {
initialized = YES;
[super initialize];
/* Normal */
_imageLeft = [[[NSImage imageNamed:@"TB_Segment_LeftCap"]
setFlipped:YES] retain];
_imageMiddle = [[[NSImage imageNamed:@"TB_Single_Middle"]
setFlipped:YES] retain];
_imageRight = [[[NSImage imageNamed:@"TB_Segment_RightCap"]
setFlipped:YES] retain];
/* Press */
_imageLeftPress = [[[NSImage imageNamed:@"TB_Segment_LeftCapPress"]
setFlipped:YES] retain];
_imageMiddlePress = [[[NSImage imageNamed:@"TB_Single_MiddlePress"]
setFlipped:YES] retain];
_imageRightPress = [[[NSImage imageNamed:@"TB_Segment_RightCapPress"]
setFlipped:YES] retain];
/* Roll */
_imageLeftRoll = [[[NSImage imageNamed:@"TB_Segment_LeftCapRoll"]
setFlipped:YES] retain];
_imageMiddleRoll = [[[NSImage imageNamed:@"TB_Single_MiddleRoll"]
setFlipped:YES] retain];
_imageRightRoll = [[[NSImage imageNamed:@"TB_Segment_RightCapRoll"]
setFlipped:YES] retain];
_badge = [[[NSImage imageNamed:@"TB_CustomizeToolbar"]
setFlipped:YES] retain];
}
}
- (void)dealloc {
delete(_imageLeft);
delete(_imageMiddle);
delete(_imageRight);
delete(_imageLeftPress);
delete(_imageMiddlePress);
delete(_imageRightPress);
delete(_imageLeftRoll);
delete(_imageMiddleRoll);
delete(_imageRightRoll);
delete(_badge);
[super dealloc];
}
/*
* TODO: add "Inactive"
*/
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)view {
[super drawWithFrame:cellFrame inView:view];
[[NSColor controlBackgroundColor] set];
NSRectFill(cellFrame);
NSImage * buttonImageLeft;
NSImage * buttonImageMiddle;
NSImage * buttonImageRight;
if([self isHighlighted]) {
buttonImageLeft = _imageLeftPress;
buttonImageMiddle = _imageMiddlePress;
buttonImageRight = _imageRightPress;
} else if(_mouseIsOver) {
buttonImageLeft = _imageLeftRoll;
buttonImageMiddle = _imageMiddleRoll;
buttonImageRight = _imageRightRoll;;
} else {
buttonImageLeft = _imageLeft;
buttonImageMiddle = _imageMiddle;
buttonImageRight = _imageRight;
}
[buttonImageLeft
drawAtPoint:NSMakePoint(0, 0)
fromRect:NSMakeRect(0, 0, 15, 23)
operation:NSCompositeSourceOver fraction:1.0];
[buttonImageMiddle
drawInRect:NSMakeRect(11, 0, 15, 23)
fromRect:NSMakeRect(0, 0, 0, 23)
operation:NSCompositeSourceOver fraction:1.0];
[buttonImageRight
drawAtPoint:NSMakePoint(26, 0)
fromRect:NSMakeRect(0, 0, 15, 23)
operation:NSCompositeSourceOver fraction:1.0];
[_badge drawAtPoint:NSMakePoint(5, 1) fromRect:NSMakeRect(0, 0, 0, 23)
operation:NSCompositeSourceOver fraction:1.0];
}
~Julian
On Apr 1, 2005, at 11:52 AM, daniel wrote:
> Since the image is associated with the cell, and not with the button
> itself, you have to copy over the image from the old cell, too. I
> assume the title is carrying over OK?
>
> It looks like your custom cell is available in time to receive the
> image during the toolbar's initial creation of the toolbar items, but
> when it gets "packed up and moved", you are not replacing the image in
> the new cell you create.
>
> Daniel
>
> On Apr 1, 2005, at 8:25 AM, Julian Cain wrote:
>
> I have also changed "initWithCoder" to no avail...
>
> - (id)initWithCoder:(NSCoder *)coder {
> if( ( self = [super initWithCoder:coder] ) ) {
> NSButtonCell *oldCell = [self cell];
> NSLog(@"initWithCoder:");
> SSTBButtonCell *cell = [[SSTBButtonCell alloc] init];
> //[cell setImage[self cell] image]];
> [cell setAttributedStringValue:[oldCell attributedStringValue]];
> [cell setTarget:[oldCell target]];
> [cell setAction:[oldCell action]];
> [cell setAlignment:[oldCell alignment]];
> [cell setTitle:[oldCell title]];
> [cell setBordered:YES];
> [self setCell:cell];
> [cell release];
> }
> return self;
> }
>
> -Julian
> On Apr 1, 2005, at 10:06 AM, j o a r wrote:
>
>
>
> On 2005-04-01, at 15.30, Julian Cain wrote:
>
>
> I have created a subclassed NSButton which I have in an NSToolbar,
> however when I run the customization palette the button image goes
> blank on the palette and toolbar. My Button code looks like so:
>
>
> It seems to me that you have an incorrect implementation of NSCoding.
> You only set the custom button cell type when you "-initWithFrame:",
> not when you "-initWithCoder:".
>
> j o a r
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>-
> sweater.com
>
> This email sent to <email_removed>
>
| Related mails | Author | Date |
|---|---|---|
| Julian Cain | Apr 1, 15:30 | |
| j o a r | Apr 1, 17:06 | |
| Julian Cain | Apr 1, 18:25 | |
| daniel | Apr 1, 18:52 | |
| Julian Cain | Apr 1, 19:52 | |
| j o a r | Apr 1, 20:00 | |
| Shaun Wexler | Apr 1, 20:06 | |
| Julian Cain | Apr 1, 20:28 | |
| Will Mason | Apr 1, 20:37 | |
| Guy English | Apr 1, 20:47 | |
| daniel | Apr 1, 20:49 | |
| Sean McBride | Apr 1, 20:53 |






Cocoa mail archive

