obj-c help for NSScrollView

Hi,

I have troubles translating the code below in order to forward the scrollWheel event. Unfortunately
the macoslib doesn’t have any hints. I have already overridden the method it’s called correctly but
I can’t handle the sendSuper and nextResponder stuff. Can someone help ?

codescrollWheel:(NSEvent *)theEvent
{
[super scrollWheel:theEvent];
[[self nextResponder] scrollWheel:theEvent];
}[/code]

I think you need to look at the C function objc_msgSendSuper and the structure objc_super in the Objective C Runtime. I don’t use macoslib, so I don’t know if there is a better solution within it.

ok at least for the super I think I have something found:
https://forum.xojo.com/11168-obj-c-declares-how-to-call-super

Yes, that will do.

The second line would be something like this:

[code]Declare Function nextResponder Lib “Cocoa” Selector “nextResponder” (receiver As Ptr) As Ptr
Declare Sub scrollWheel Lib “Cocoa” Selector “scrollWheel:” (receiver As Ptr, NSEvent As Ptr)

Dim nextResponderPtr As Ptr = nextResponder(scrollViewPtr)
scrollWheel(nextResponderPtr, theEventPtr)[/code]

What a heck of testing but I have managed it. It has been crashing 100 times when I stumbled over an older post:
https://forum.xojo.com/24858-subclass-nsview-in-xojo-pagefooter

that mentioned to specify arguments for the objc_msgSendSuper which is really important and may be left unnoticed.

here’s my code:

[quote]Private Shared Sub dispatch_scrollWheel(id as ptr, sel as ptr, evt as ptr)
/* This code will show how to handle the scrollWheel event of a subclasses NSScrollView
/* If you have for instance several views nested, they current view receiving the scroll but doesn’t have anything
/* to scroll actually blocks the event of the parent views but here send the event to nextResponder chain so that the other
/* views can take up this event.

// - (void)scrollWheel:(NSEvent *)theEvent
// {
// [super scrollWheel:theEvent];
// [[self nextResponder] scrollWheel:theEvent];
// }

Declare Function nextResponder Lib CocoaLib Selector “nextResponder” (receiver As Ptr) As Ptr
Declare Sub scrollWheel Lib CocoaLib Selector “scrollWheel:” (receiver As Ptr, NSEvent As Ptr)
Declare Function objc_msgSendSuper lib ObjCLib (byref sup As objc_super, sel As Ptr,evt as ptr) as ptr
declare function objc_getClass lib ObjCLib (name as CString) as ptr

dim view as NSScollView = findScrollView(id)
if view<>nil then
dim s as objc_super
s.receiver = id
s.pClass = NSClassFromString(“NSScrollView”)
call objc_msgSendSuper(s,sel,evt)

dim hasScroller as Boolean = view.hasHorizontalScroller or view.hasVerticalScroller
if not hasScroller then
  scrollWheel(nextResponder(id), evt)
end if

end if
End Sub[/quote]

Thanks Eli for your help !

You have to byRef the objc_super? Thanks a lot! This could be the reason I never succeeded calling a super method!

It’s convenient, yes. It wasn’t mentioned in the documention before but last year they updated it

You can use byref for all structures if you want to pass the pointer to a declare. This way, you can save a lot of troubles with
a memoryblock and 32/64bit sizes.
http://developer.xojo.com/byref
(see Notes)

I have made logical mistake. That’s better.

dim view as NSScollView = findObject(id,scrollList) if view<>nil then dim hasScroller as Boolean = view.hasHorizontalScroller or view.hasVerticalScroller if not hasScroller then scrollWheel(nextResponder(id), evt) else dim s as objc_super s.receiver = id s.pClass = NSClassFromString(kNSScollViewClassName) call objc_msgSendSuper(s,sel,evt) end if end if