简体   繁体   中英

Set Focus to a Cocoa Window in Carbon App

I'm trying to create a Cocoa Window within an otherwise Carbon Application (it's an OpenGL API that uses AGL. Can't change it so don't comment on that).

Here's a code snippit:

WindowRef winref = static_cast<eq::AGLWindow*>(getOSWindow())->getCarbonWindow();
vc = [[SFAttachedViewController alloc] initWithConfig:config]; //loads from view nib
NSPoint buttonPoint = NSMakePoint(event.pointerButtonPress.x + [cocoaWrap frame].origin.x, [cocoaWrap frame].size.height - event.pointerButtonPress.y + [cocoaWrap frame].origin.y);
MAAttachedWindow *attachedWindow = [[MAAttachedWindow alloc] initWithView:[vc view] attachedToPoint:buttonPoint onSide:side atDistance:0.0f]; // some Matt Gemmell goodness!

And I try to show it with one of the following lines:

// A)
[NSApp runModalForWindow:[attachedWindow retain]]; // makes a white box
// B)
NSWindow *cocoaWrap = [[NSWindow alloc] initWithWindowRef:winref];
[cocoaWrap addChildWindow:attachedWindow ordered:NSWindowAbove];
// C)
[attachedWindow makeKeyAndOrderFront:NSApp];

The window shows, but the focus is never given. I can't edit any of the controls, and everything is grayed out.

help!?

I tried

HIViewRef viewRef;
HICocoaViewCreate([vc view], 0, &viewRef);
WindowRef attachedRef = (WindowRef)[attachedWindow windowRef];
SetKeyboardFocus(attachedRef, viewRef, kControlNoPart);

Thinking it might have been a Carbon/Cocoa thing, but to no avail.

在调用Cocoa方法之前,您是否调用过NSApplicationLoad()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM