delegate question

  • Hi
    here is a situation
    I have implementation of some NSView that I can use in Java
    application via Apple's CocoaComponent java class
    so

    I don't have any nib file
    I didn't create NSApplication (so I cannot create my NSApplication
    class)
    I didn't create NSWindow
    that owns my NSView (so I cannot create my own NSWindow class)

    I didn't set delegate for that NSWindow, but I definitely can get
    instance of delegate
    and I can substitute it by my own

    I have to catch Command-C key-stroke
    so I'll be able to handle copy command

    solution that I can think of is to
    create all delegate methods from NSWindow in my NSView
    cache original NSWindow delegate
    set my NSView as a new delegate for NSWindow
    and delegate everything to former delegate
    all I need is to do some small job in the keyUp/Down and after that
    to send keyUp/Down
    to the former delegate

    but I wonder is there better way to do what I want?
    (I read in that list about installing event handler, but I, probably
    cannot do that too,
    because I'm getting control way too late for doing that)

    thanks in advance

    Dmitry Markman
  • Overriding public void keyDown(NSEvent theEvent) in your view subclass
    should do it.

    Read up on the Responder Chain to find out why this will work. Also,
    read the NSEvent documentation to figure out how to handle the key
    stroke.

    Hope this helps, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
  • thanks for your answer
    for some reason I don't get keyDown message
    I suspect that's because of
    - (void)webView:(WebView *)sender makeFirstResponder:(NSResponder *)
    responder
    {
        [[self window] makeFirstResponder : responder];
    }

    without that I have different problems

    thanks again

    On Oct 7, 2006, at 11:25 AM, Alan Smith wrote:

    > Overriding public void keyDown(NSEvent theEvent) in your view subclass
    > should do it.
    >
    > Read up on the Responder Chain to find out why this will work. Also,
    > read the NSEvent documentation to figure out how to handle the key
    > stroke.
    >
    > Hope this helps, Alan
    >
    > --
    > // Quotes from yours truly -------------------------
    > "You don't forget, you just don't remember."
    > "Maturity resides in the mind."
    > "Silence is the Universe's greatest gift."

    Dmitry Markman
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today