2010-02-04 4 views
1

다양한 시나리오에서 화면에 상황에 맞는 메뉴를 표시해야하는 응용 프로그램을 작성하고 있습니다. 필자가 작성한 기능에서 NSWindows 나 NSViews에 액세스 할 수 없습니다. 이 함수는 10.6에서 완벽하게 작동하므로 popUpMenuPositioningItem : atLocation : inView를 사용하고 싶습니다. 그러나 10.5를 지원해야한다는 요구 사항이 있으므로이 기능을 사용할 수 없습니다.popUpMenuPositioningItem을 찾고 있습니다 : atLocation : inView : 10.5에 해당합니다.

문서에 명시된대로 내가 가장 관심이 기능은 다음과 같습니다 뷰가 전무 인 경우

, 위치는 좌표계 화면에서 해석 입니다. 이렇게하면 메뉴가 어떤 창과도 연결되지 않은 상태로 팝업 될 수 있습니다.

기본적으로 화면에 위치가 있지만 연결된보기가없는 상황에 맞는 메뉴를 표시해야합니다.

10.5에서이를 수행 할 수있는 방법이 있습니까?

답변

0

나는 코코아에서 그것을하는 방법을 모르지만 Carbon 함수 PopUpMenuSelect를 사용할 수 있습니다.

+0

감사합니다.하지만 Carbon을 피할 필요가 있습니다. 또한, 나는 PopUpMenuSelect가 사용되지 않습니다 믿습니다. –

1
// Set up the button cell, converting to NSView coordinates. The menu is 
// positioned such that the currently selected menu item appears over the 
// popup button, which is the expected Mac popup menu behavior. 
NSPopUpButtonCell* button = [[NSPopUpButtonCell alloc] initTextCell:@"" 
                  pullsDown:NO]; 
[button autorelease]; 
[button setMenu:menu_]; 
// We use selectItemWithTag below so if the index is out-of-bounds nothing 
// bad happens. 
[button selectItemWithTag:index]; 
[button setFont:[NSFont menuFontOfSize:fontSize_]]; 

// Create a dummy view to associate the popup with, since the OS will use 
// that view for positioning the menu. 
NSView* dummyView = [[[NSView alloc] initWithFrame:bounds] autorelease]; 
[view addSubview:dummyView]; 
NSRect dummyBounds = [dummyView convertRect:bounds fromView:view]; 

// Display the menu, and set a flag if a menu item was chosen. 
[button performClickWithFrame:dummyBounds inView:dummyView]; 

if ([self menuItemWasChosen]) 
    index_ = [button indexOfSelectedItem]; 

[dummyView removeFromSuperview];