subclassing NSButton not working
subclassing NSButton not working
- Subject: subclassing NSButton not working
- From: Jeffrey Drake <email@hidden>
- Date: Wed, 8 Jan 2003 01:05:07 -0500
After seeing Safari's Favorites toolbar, I wanted to make my own
version of its type of button. I didn't see anything else I could use
for it.
Documentation and examples for subclassing NSButton and ...Cell seems
nonexistent.
Source code:
http://homepage.mac.com/jeffreydrake under public folder
it is 'interfacedevelopment.tgz'.
I have put break points in every function, only the awakeFromNib even
entered.
In interface builder I am using an NSButton with a custom class of
JDRolloverButton.
Any help at all is really appreciated, i even tried in #gnustep on opn
and one of the guys there said it should have worked.
Regards,
Jeffrey Drake
//
// JDRolloverButton.h
// InterfaceDevelopment
//
// Created by Jeffrey Drake on Tue Jan 07 2003.
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "JDRolloverButtonCell.h"
@interface JDRolloverButton : NSButton {
}
@end
//
// JDRolloverButton.m
// InterfaceDevelopment
//
// Created by Jeffrey Drake on Tue Jan 07 2003.
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//
#import "JDRolloverButton.h"
@implementation JDRolloverButton
-(void) awakeFromNib
{
int a;
a = 1;
}
+ (Class) cellClass
{
return [JDRolloverButtonCell class];
}
@end
//
// JDRolloverButtonCell.h
// InterfaceDevelopment
//
// Created by Jeffrey Drake on Tue Jan 07 2003.
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface JDRolloverButtonCell : NSButtonCell {
}
@end
//
// JDRolloverButtonCell.m
// InterfaceDevelopment
//
// Created by Jeffrey Drake on Tue Jan 07 2003.
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//
#import "JDRolloverButtonCell.h"
@implementation JDRolloverButtonCell
- (id)initImageCell:(NSImage *)anImage
{
self = [super initTextCell:@""];
return self;
}
- (id)initTextCell:(NSString *)aString
{
self = [self initImageCell:nil];
return self;
}
- (NSSize)cellSize
{
return
[[self stringValue] sizeWithAttributes:
[NSDictionary dictionaryWithObject: [self font] forKey:
NSFontAttributeName]];
}
- (NSSize)cellSizeForBounds:(NSRect)aRect
{
return [self cellSize];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSSize textSize;
float left;
float top;
textSize = [[self stringValue]
sizeWithAttributes:[NSDictionary dictionaryWithObject: [self font]
forKey: NSFontAttributeName]];
left = cellFrame.origin.x + (cellFrame.size.width / 2) -
(textSize.width/2);
top = cellFrame.origin.y + (cellFrame.size.height / 2) -
(textSize.height/2);
[[self stringValue] drawAtPoint: NSMakePoint(left, top)
withAttributes: [NSDictionary dictionaryWithObject: [self font]
forKey: NSFontAttributeName]];
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.