2011-01-19 23:19:43 +03:00
|
|
|
//
|
|
|
|
// PSMOverflowPopUpButton.m
|
|
|
|
// NetScrape
|
|
|
|
//
|
|
|
|
// Created by John Pannell on 8/4/04.
|
|
|
|
// Copyright 2004 Positive Spin Media. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "PSMRolloverButton.h"
|
|
|
|
|
|
|
|
@implementation PSMRolloverButton
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)awakeFromNib {
|
|
|
|
if([[self superclass] instancesRespondToSelector:@selector(awakeFromNib)]) {
|
|
|
|
[super awakeFromNib];
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
2011-01-26 13:52:13 +03:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(rolloverFrameDidChange:)
|
|
|
|
name:NSViewFrameDidChangeNotification
|
|
|
|
object:self];
|
2011-01-19 23:19:43 +03:00
|
|
|
[self setPostsFrameChangedNotifications:YES];
|
|
|
|
[self resetCursorRects];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
_myTrackingRectTag = -1;
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)dealloc {
|
2011-01-19 23:19:43 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[self removeTrackingRect];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
// the regular image
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)setUsualImage:(NSImage *)newImage {
|
|
|
|
[newImage retain];
|
|
|
|
[_usualImage release];
|
|
|
|
_usualImage = newImage;
|
2011-01-19 23:19:43 +03:00
|
|
|
|
|
|
|
[self setImage:_usualImage];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (NSImage *)usualImage {
|
|
|
|
return _usualImage;
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)setRolloverImage:(NSImage *)newImage {
|
|
|
|
[newImage retain];
|
|
|
|
[_rolloverImage release];
|
|
|
|
_rolloverImage = newImage;
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (NSImage *)rolloverImage {
|
|
|
|
return _rolloverImage;
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//Remove old tracking rects when we change superviews
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)viewWillMoveToSuperview:(NSView *)newSuperview {
|
2011-01-19 23:19:43 +03:00
|
|
|
[self removeTrackingRect];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[super viewWillMoveToSuperview:newSuperview];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)viewDidMoveToSuperview {
|
2011-01-19 23:19:43 +03:00
|
|
|
[super viewDidMoveToSuperview];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[self resetCursorRects];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
|
2011-01-19 23:19:43 +03:00
|
|
|
[self removeTrackingRect];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[super viewWillMoveToWindow:newWindow];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)viewDidMoveToWindow {
|
2011-01-19 23:19:43 +03:00
|
|
|
[super viewDidMoveToWindow];
|
2011-01-26 13:52:13 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
[self resetCursorRects];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)rolloverFrameDidChange:(NSNotification *)inNotification {
|
2011-01-19 23:19:43 +03:00
|
|
|
[self resetCursorRects];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)addTrackingRect {
|
|
|
|
// assign a tracking rect to watch for mouse enter/exit
|
|
|
|
NSRect trackRect = [self bounds];
|
|
|
|
NSPoint localPoint = [self convertPoint:[[self window] convertScreenToBase:[NSEvent mouseLocation]]
|
|
|
|
fromView:nil];
|
|
|
|
BOOL mouseInside = NSPointInRect(localPoint, trackRect);
|
|
|
|
|
|
|
|
_myTrackingRectTag = [self addTrackingRect:trackRect owner:self userData:nil assumeInside:mouseInside];
|
|
|
|
if(mouseInside) {
|
2016-02-10 18:27:08 +03:00
|
|
|
//[self mouseEntered:nil];
|
|
|
|
[self setImage:_rolloverImage];
|
2011-01-26 13:52:13 +03:00
|
|
|
} else{
|
2016-02-10 18:27:08 +03:00
|
|
|
//[self mouseExited:nil];
|
|
|
|
[self setImage:_usualImage];
|
2011-01-26 13:52:13 +03:00
|
|
|
}
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)removeTrackingRect {
|
|
|
|
if(_myTrackingRectTag != -1) {
|
2011-01-19 23:19:43 +03:00
|
|
|
[self removeTrackingRect:_myTrackingRectTag];
|
|
|
|
}
|
|
|
|
_myTrackingRectTag = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// override for rollover effect
|
|
|
|
- (void)mouseEntered:(NSEvent *)theEvent;
|
|
|
|
{
|
2011-01-26 13:52:13 +03:00
|
|
|
// set rollover image
|
|
|
|
[self setImage:_rolloverImage];
|
2011-01-19 23:19:43 +03:00
|
|
|
|
|
|
|
[super mouseEntered:theEvent];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseExited:(NSEvent *)theEvent;
|
|
|
|
{
|
2011-01-26 13:52:13 +03:00
|
|
|
// restore usual image
|
2011-01-19 23:19:43 +03:00
|
|
|
[self setImage:_usualImage];
|
|
|
|
|
|
|
|
[super mouseExited:theEvent];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)resetCursorRects {
|
|
|
|
// called when the button rect has been changed
|
|
|
|
[self removeTrackingRect];
|
|
|
|
[self addTrackingRect];
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)setFrame:(NSRect)rect {
|
2011-01-19 23:19:43 +03:00
|
|
|
[super setFrame:rect];
|
|
|
|
[self resetCursorRects];
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:52:13 +03:00
|
|
|
- (void)setBounds:(NSRect)rect {
|
2011-01-19 23:19:43 +03:00
|
|
|
[super setBounds:rect];
|
|
|
|
[self resetCursorRects];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Archiving
|
|
|
|
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
2011-01-26 13:52:13 +03:00
|
|
|
[super encodeWithCoder:aCoder];
|
|
|
|
if([aCoder allowsKeyedCoding]) {
|
|
|
|
[aCoder encodeObject:_rolloverImage forKey:@"rolloverImage"];
|
|
|
|
[aCoder encodeObject:_usualImage forKey:@"usualImage"];
|
|
|
|
[aCoder encodeInt64:_myTrackingRectTag forKey:@"myTrackingRectTag"];
|
|
|
|
}
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithCoder:(NSCoder *)aDecoder {
|
2011-01-26 13:52:13 +03:00
|
|
|
self = [super initWithCoder:aDecoder];
|
|
|
|
if(self) {
|
|
|
|
if([aDecoder allowsKeyedCoding]) {
|
|
|
|
_rolloverImage = [[aDecoder decodeObjectForKey:@"rolloverImage"] retain];
|
|
|
|
_usualImage = [[aDecoder decodeObjectForKey:@"usualImage"] retain];
|
|
|
|
_myTrackingRectTag = [aDecoder decodeInt64ForKey:@"myTrackingRectTag"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|