how to channel input events through classes

Discussion in 'Mac Programming' started by Bug-Creator, Jun 17, 2017.

  1. Bug-Creator macrumors 6502

    Bug-Creator

    Joined:
    May 30, 2011
    Location:
    Germany
    #1
    <- Objective-C/Cocoa newbie here

    What I got is a class deviated from NSView which implements "- (void) mouseDown:(NSEvent *)event" and "- (void) mouseMoved:(NSEvent *)event". Both work pretty much expected but want those events (and others) to go through other classes depending on which tool was set by the user.

    Found "nextResponder" and tried to set that to one of my tool classes (based on NSResponder) but solar no luck.

    Ideal solution would be for the tool class to receive all events first and either refer them back to NSView based class or "eat" them.
     
  2. Bug-Creator thread starter macrumors 6502

    Bug-Creator

    Joined:
    May 30, 2011
    Location:
    Germany
    #2
    Well found a solution and in case someone hits here via Google:

    self.nextResponder = ehandler; does send messages not defined in NSVIew (self) to ehandler (the tool)

    It gets a bit more complicated for events that I might want to use NSView or "eaten" by the tool.
    - (void) mouseDown:(NSEvent *)event
    {
    [ehandler mouseDown:event];
    }

    Does work, but I have no way of telling wether the event should be "eaten" cos that function return void.

    a) find a way to invalidate an NSEvent
    b) implement eventhandling in the tool classes independently of functions inherited from NSResponder
     

Share This Page