Re: NSButtonCell mouseEntered/mouseExited stops after view is swapped out ... [WORKAROUND]
Re: NSButtonCell mouseEntered/mouseExited stops after view is swapped out ... [WORKAROUND]
- Subject: Re: NSButtonCell mouseEntered/mouseExited stops after view is swapped out ... [WORKAROUND]
- From: "Ken Ferry" <email@hidden>
- Date: Tue, 3 Jul 2007 13:42:05 -0700
If the bug is ever fixed, then this will give you extra tracking
rects. How much of a problem that is, I'm not sure. If its not a
problem at all, you could just do this from the get-go.
Just noticed this thread. It is a bug, and it is fixed in 10.5.
For 10.4, you'll need a workaround that works enough to catch your
situation. You might try calling overriding -viewDidMoveToWindow and
doing something like this:
if ([self showsBorderOnlyWhileMouseInside]) {
[self setShowsBorderOnlyWhileMouseInside:NO];
[self setShowsBorderOnlyWhileMouseInside:YES];
}
Ken Ferry
Cocoa Frameworks
On 7/3/07, Martin Redington <email@hidden> wrote:
I just got this to work, but it is pig-ugly. More elegant solutions
welcome.
If the bug is ever fixed, then this will give you extra tracking
rects. How much of a problem that is, I'm not sure. If its not a
problem at all, you could just do this from the get-go.
I added addFrameRectManually and myTrackingRect variables to the
MyButton class.
I over-rode setShowsBorderOnlyWhileMouseInside in MyButtonCell as
follows:
- (void) setShowsBorderOnlyWhileMouseInside:(BOOL)show{
[super setShowsBorderOnlyWhileMouseInside:show];
MyButton *button = (MyButton *)[self controlView];
if([button addFrameRectManually] == YES){
NSTrackingRectTag trackingRect = [button addTrackingRect:
[button bounds] owner:self userData:nil assumeInside:NO];
[button setMyTrackingRect:trackingRect];
}else{
[button setAddFrameRectManually:NO];
}
}
and MyButton's viewWillMoveToWindow as follows.
- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
if([self window] && [self myTrackingRect]) {
[self removeTrackingRect:[self myTrackingRect]];
[self setMyTrackingRect:0];
}
}
On 3 Jul 2007, at 15:45, Martin Redington wrote:
>
> On 3 Jul 2007, at 15:12, PGM wrote:
>
>>>
>>> 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.
>>>
>>
>> Did you update the trackingRects/cursorRects for your NSButton?
>>
>> http://developer.apple.com/documentation/Cocoa/Conceptual/
>> EventOverview/MouseTrackingEvents/chapter_7_section_2.html
>
> Nope. Do I need to do that manually (with NSButton/NSButtonCell)?
>
> I just tried covering add and removeTrackingRect in the button
> subclass, so I could see when they're getting called. Output
> follows below.
>
> First time around, the tracking rects get added properly, and they
> get updated on removal, but on readdition, they don't get added
> again. I'll see if I can add the tracking rects manually the second
> time around, although if I have to manage the tracking rect tag
> myself, I may also have to handle removal manually too. It may be
> easier to just try creating a new replacement button.
>
> This definitely seems like a bug to me (and I actually just filed
> it as 5309490 just before I read your reply). If the tracking rect
> gets added manually first time around, then when the button cell is
> removed, it should go back to its initial state, and the tracking
> rect should get added automatically again next time. If anyone
> knows how to force the button back to it's initial state, that
> would be great.
>
> Its obviously trying to clean up the tracking rects automatically
> when it gets removed, judging from the output below ...
>
>
> [Session started at 2007-07-03 15:30:13 +0100.]
>
> # first view added to window in awakeFromNib
> 2007-07-03 15:30:13.638 ButtonCellIssue[23966] addTrackingRect
> called for <MyButton: 0x3260d0> Button One
>
> # move the mouse over button one, and click. view one removed, view
> two added
> 2007-07-03 15:30:20.361 ButtonCellIssue[23966] Mouse Entered
> <MyButtonCell: 0x308bc0> Button One
>
> # why does it get removed, added, and removed?
> 2007-07-03 15:30:20.917 ButtonCellIssue[23966] removeTrackingRect
> called for <MyButton: 0x3260d0> Button One
> 2007-07-03 15:30:20.917 ButtonCellIssue[23966] addTrackingRect
> called for <MyButton: 0x3260d0> Button One
> 2007-07-03 15:30:20.917 ButtonCellIssue[23966] removeTrackingRect
> called for <MyButton: 0x3260d0> Button One
>
> # view two is added
> 2007-07-03 15:30:20.917 ButtonCellIssue[23966] addTrackingRect
> called for <MyButton: 0x343330> Button Two
> 2007-07-03 15:30:22.338 ButtonCellIssue[23966] Mouse Exited
> <MyButtonCell: 0x3434b0> Button Two
>
> # move the mouse back onto the button and click again
> 2007-07-03 15:30:41.455 ButtonCellIssue[23966] Mouse Entered
> <MyButtonCell: 0x3434b0> Button Two
> 2007-07-03 15:30:42.230 ButtonCellIssue[23966] removeTrackingRect
> called for <MyButton: 0x343330> Button Two
> 2007-07-03 15:30:42.230 ButtonCellIssue[23966] addTrackingRect
> called for <MyButton: 0x343330> Button Two
> 2007-07-03 15:30:42.230 ButtonCellIssue[23966] removeTrackingRect
> called for <MyButton: 0x343330> Button Two
>
> # but addTrackingRect does not get called for button one ...
>
>
>
>
>
>
>
>>
>> Good luck, Patrick
>>
>
> _______________________________________________
>
> 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:
> 40ucl.ac.uk
>
> This email sent to email@hidden
>
_______________________________________________
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
_______________________________________________
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