To capture gesture events I’ve been following the pattern used by NSImageView in MacOSLib: dynamically
subclass NSView, adding an instance as a subview of your Canvas/RectControl/etc.
For these events I’ve found subclassing NSResponder and inserting into the nextResponder chain works just as well, including to the top of the window, but is this safe or is it ‘messing with the view hierarchy’?
I don’t know, but I’ve been subclassing my canvas (Xojo canvas is an NSView) and adding the events to it. Haven’t seen any bad effects yet I wonder if that’s an ok way to approach it.
How are you adding events? Do you mean directly to the XOJView class?
The bad stuff I know about is moving a widget to something elses subview, like embedding a ContainerControl someplace then moving it to a NSPopover, or moving a Pushbutton to the themeFrame. Actually, I’m not so clear and maybe that last one is OK.
That’s how it’s working now with NSView subclass added as a subview but I’m thinking to refactor as NSResponder for greater flexibility such as a single, window-level handler of gesture events.
[quote=94231:@Will Shank]How are you adding events? Do you mean directly to the XOJView class?
[/quote]
Yes, I use something like
dim objectClass As ptr=object_getClass(self.Handle)
MyCocoaSubclass= objc_allocateClassPair(objectClass, "myCustomView", 0)
then use class_replaceMethod to add handlers and such. This way I can override built-in methods like wantsDefaultClipping etc.
dim objectClass As ptr=object_getClass(self.Handle)
MyCocoaSubclass= objc_allocateClassPair(objectClass, "myCustomView", 0)
then use class_replaceMethod to add handlers and such. This way I can override built-in methods like wantsDefaultClipping etc.[/quote]
Are you using object_setClass to swap out the view’s class for your own subclass?