Re: scrolling with MightyMouse
Re: scrolling with MightyMouse
- Subject: Re: scrolling with MightyMouse
- From: Troy Gaul <email@hidden>
- Date: Sat, 28 Jan 2006 16:08:33 -0600
I'm seeing a similar problem. In my case, it seems to happen with
both the Mighty Mouse scroll wheel and also with trackpad scrolling
with the recent generation of PowerBooks that support that feature.
I have views that include a scroller, and those scroll fine, but a
scroll view without any visible scrollers (I'm using a disconnected
scroller that's separately bound to the scroll view) doesn't scroll
when the mouse is over it.
Another difference in my case is that since I'm scrolling content in a
child window that normally doesn't get key focus, I've found that
scrolling only works when I give the window key focus before sending
it the scroll wheel event (I do this in an NSApplication subclass's
sendEvent method). I then set the key window back after the event is
processed. This works fine with a normal mouse, but with these two
devices it causes a visible flicker of the titlebar in the main window
(since key focus is being taken away from it temporarily, this isn't
overly surprising, but it doesn't happen with other mice).
It would seem that the difference is that these devices generate the
smooth scrolling events described in that technote at:
http://developer.apple.com/qa/qa2005/qa1453.html
This would seem to be an AppKit bug, AFAICT.
The workaround I came up with is to override scrollWheel: in
NSScrollView and handle it manually, at least in the case there there
are no scrollers. Unfortunately, that means not getting changes made
to the base implementation in the future (until this hack can be
removed if they fix the problem).
Now, in looking into this, I was able to determine that the Mighty
Mouse and trackpad given an event subtype of 1 (which, for at least
some event types maps to NSTabletPointEventSubtype -- it's possible
the meaning for wheel events will eventually have a different name, I
suppose) where my other mouse has subtype 0.
- (void) scrollWheel: (NSEvent*) theEvent
{
if( ![ self hasVerticalScroller ] && ![ self hasHorizontalScroller ]
&& [ theEvent subtype ] == 1 ) {
// Mighty Mouse/Scrolling Trackpad seem to give this value for subtype.
NSView* docView = [ self documentView ];
NSRect docVisible = [ docView visibleRect ];
NSPoint scrollOrigin = docVisible.origin;
scrollOrigin.x -= [ theEvent deltaX ] * [ self horizontalLineScroll ];
if( NSHeight( docVisible ) < NSHeight( [ docView bounds ] ) )
scrollOrigin.y -= [ theEvent deltaY ] * [ self verticalLineScroll ];
else if( [ theEvent deltaX ] == 0 )
scrollOrigin.x -= [ theEvent deltaY ] * [ self horizontalLineScroll ];
[ docView scrollPoint: scrollOrigin ];
}
else {
[ super scrollWheel: theEvent ];
}
}
Scrolling done this way doesn't seem to have quite as much precision
as the Mighty Mouse is capable of (when moving the scroll ball slowly
and going through NSScrollView's normal scrollWheel: method, it will
scroll less than a full vertical/horizontal line scroll, it seems).
Anyway, so far this code is working for me. YMMV.
_troy
On 12/5/05, Denise Eatherly <email@hidden> wrote:
> Ricky,
>
> The scrollview is a standard NSScrollView set up in IB with a custom
> view in it. The only unusual thing about it is that it doesn't have
> vertical or horizontal scrollers. I have a sample app with an
> NSScrollView with no scroller that works just fine with either mouse
> s, so I don't think that is the problem.
>
> There is a Carbon Tech Note regarding the difference in AppleEvents
> generated by the MM, but I don't know what I need to do to handle
> order to handle the MM scrolling correctly. The window is
> definitely getting the events, but I can't tell what it is doing with
> them. There is a scrollWheel method in NSScrollView, but I tried
> setting a breakpoint on it and it never hits no matter what mouse I'm
> using. Is there some message the documentView might be blocking?
>
> Denise
>
> >
> >> Has anyone else had problems with NSScrollview failing to respond
> >> to the NSScrollwheel events from the Mighty Mouse??
> >>
> >> There are no problems with the scrollwheel on the Mighty Mouse
> >> under 10.3.9. However, under 10.4.3, scrolling is ignored when I
> >> use the Mighty Mouse ( but occurs properly with a microsoft
> >> mouse.) The NSScrollwheel event seems to be a bit different, but
> >> I'm not sure what I need to do to make it work correctly under 10.4
> >>
> >> Any suggestions would be most welcome.
> >
> > What exactly is your UI (i.e. are you subclassing NSScrollView and/
> > or what are you putting inside it)?
> >
> > The Examples/AppKit/OutlineView example works a-ok for me with
> > Mighty Mouse (I have 10.4.3).
> >
> > ___________________________________________________________
> > Ricky A. Sharp mailto:email@hidden
> > Instant Interactive(tm) http://www.instantinteractive.com
> >
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden