How to restore keyWindow (NSView - Appkit)

95 Views Asked by At

I have some code which opens a modal window (itself composed from a few views) and makes it closed when we click anywhere on it.

here is some part of code:

int myFunc()
{
    // Create views
    NSPanel *panel =  ...;

    CustomNSTextView * textView = ... ;
    CustomNSImageView * imageView = ...;

    [view addSubview:textView];
    [view addSubview:imageView];
    [panel setContentView:view];

    [[NSApplication sharedApplication] runModalForWindow:panel];

    NSView* parentView = [view superview];
    [[parentView window] makeFirstResponder:parentView];


    [textView release];
    [imageView release];
    [view release];
    [panel release];
}

@implementation CustomNSTextView : NSTextView

- (void) mouseDown:(NSEvent *)theEvent
{
#pragma unused(theEvent)
    [[NSApplication sharedApplication] stopModal];
}

@implementation CustomNSImageView : NSImageView

- (void) mouseDown:(NSEvent *)theEvent
{
#pragma unused(theEvent)
    [[NSApplication sharedApplication] stopModal];
}

The bug is after the window is closed, the application (that launched the modal window), won't receive any key event anymore (while it still was as the modal window was still open). Only after I refocus on the application, it will receive key events again.

Please anyone gives me some idea, I could not find something relevant on the net.

Thanks Nathaniel

0

There are 0 best solutions below