【发布时间】:2010-07-13 12:40:38
【问题描述】:
我正在尝试在其他 Carbon 应用程序中创建一个 Cocoa 窗口(它是一个使用 AGL 的 OpenGL API。无法更改它所以不要对此发表评论)。
这是一个代码片段:
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!
我尝试用以下几行之一来展示它:
// 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];
窗口显示,但从未给出焦点。我无法编辑任何控件,并且所有控件都显示为灰色。
求助!?
我试过了
HIViewRef viewRef;
HICocoaViewCreate([vc view], 0, &viewRef);
WindowRef attachedRef = (WindowRef)[attachedWindow windowRef];
SetKeyboardFocus(attachedRef, viewRef, kControlNoPart);
认为它可能是碳/可可的东西,但无济于事。
【问题讨论】:
-
是的,这就是为什么我在窗口 init() 方法中而不是在主线程中调用 NSApplicationLoad()。
标签: c++ objective-c cocoa macos-carbon nswindow