2010-07-13 36 views
0

我試圖在其他Carbon應用程序內創建可可窗口(這是使用AGL的OpenGL API,無法更改,因此請勿對此進行評論)。將焦點設置爲Carbon應用程序中的可可窗口

這裏有一個代碼片段:

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]; 

窗口顯示,但重點是從來沒有放棄。我無法編輯任何控件,並且一切都變灰。

help!?

我試圖

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

想這可能是一個碳/可可的事情,但無濟於事。

+0

你看過這個PDF嗎? http://developer.apple.com/legacy/mac/library/documentation/Cocoa/Conceptual/CarbonCocoaDoc/CarbonCocoaIntegration.pdf – JeremyP 2010-07-13 15:37:04

+0

是的,這就是爲什麼我在我的窗口init()方法中調用了NSApplicationLoad()調用,而不是在主線程。 – 2010-07-13 18:46:15

回答

2

在調用Cocoa方法之前,你調用了NSApplicationLoad()嗎?

+0

是的。是否需要在每個線程中調用? – 2010-07-13 18:03:44

+0

!?我簡直不敢相信。我將調用移至主線程,而不是我的渲染線程,瞧!加工! DERP * facepalm * – 2010-07-13 18:05:19

+0

好,它的工作。一般來說,你不應該從非主線程調用任何Cocoa UI方法。這很不幸,但Cocoa使用了很多主線程構造。例如您不應該從輔助線程等調用'makeKeyAndOrderFront:'等。 – Yuji 2010-07-13 21:52:35

相關問題