NSButtonCell mouseEntered/mouseExited stops after view is swapped out ...
NSButtonCell mouseEntered/mouseExited stops after view is swapped out ...
- Subject: NSButtonCell mouseEntered/mouseExited stops after view is swapped out ...
- From: Martin Redington <email@hidden>
- Date: Tue, 3 Jul 2007 06:21:13 +0100
I'm seeing NSButtonCell stop acknowledging mouseEntered/mouseExited
events after its superview is removed from, and then re-added to a
window.
I have a window whose contentViews can be switched. The contentViews
contain buttons that initiate the switching.
I subclassed NSButton and NSButtonCell, so that I could over-ride
NSButtonCell's mouseEntered and mouseExited methods (I want to update
my UI when this happens - why isn't important).
Everything works absolutely fine, and I can see mouseEntered/Exited
firing off happily.
I switch to the other view. Again, the mouseEntered/mouseExited
methods for its button cell fire off no problem.
I switch back to the original view - mouseEntered/mouseExited no
longer work on either button.
I've posted the actual code below.
Any suggestions or workarounds would be great.
cheers,
m.
====
@class MyButton;
@class MyButtonCell;
@interface MyController : NSObject {
IBOutlet NSWindow *mWindow;
IBOutlet NSView *mViewOne;
IBOutlet NSView *mViewTwo;
IBOutlet MyButton *mButtonOne;
IBOutlet MyButton *mButtonTwo;
}
- (IBAction) firstButtonPressed:(id)sender;
- (IBAction) secondButtonPressed:(id)sender;
@end
//
@implementation MyController
- (void) awakeFromNib
{
// if setShowsBorderOnlyWhileMouseInside:YES is called before the
// subview is initially set, mouseEntered/mouseExited does not
// work. I moved it to the actions below, which actually set up
// the view, so its always called afterwards.
// [[mButtonOne cell] setShowsBorderOnlyWhileMouseInside:YES];
// [[mButtonTwo cell] setShowsBorderOnlyWhileMouseInside:YES];
// set up the initial view.
[self secondButtonPressed:self];
}
- (IBAction) firstButtonPressed:(id)sender
{
[mWindow setContentView:mViewTwo];
[[mButtonTwo cell] setShowsBorderOnlyWhileMouseInside:YES];
}
- (IBAction) secondButtonPressed:(id)sender
{
[mWindow setContentView:mViewOne];
[[mButtonOne cell] setShowsBorderOnlyWhileMouseInside:YES];
}
@end
//
@implementation MyButton
// Make sure we get the correct buttoncell class.
- (id) initWithCoder: (NSCoder *)origCoder
{
NSKeyedUnarchiver *coder = (id)origCoder;
// gather info about the superclass's cell and save the
archiver's old mapping
Class superCell = [[self superclass] cellClass];
NSString *oldClassName = NSStringFromClass( superCell );
Class oldClass = [coder classForClassName: oldClassName];
if( !oldClass )
oldClass = superCell;
// override what comes out of the unarchiver
[coder setClass: [[self class] cellClass] forClassName:
oldClassName];
// unarchive
self = [super initWithCoder: coder];
// set it back
[coder setClass: oldClass forClassName: oldClassName];
return self;
}
+ (Class) cellClass{ return [MyButtonCell class]; }
@end
//
//
//
@implementation MyButtonCell
- (void) mouseEntered:(NSEvent *)event{ NSLog(@"Mouse Entered"); }
- (void) mouseExited:(NSEvent *)event{ NSLog(@"Mouse Exited"); }
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden