0

openGL GUIインターフェイスがあり、openGLディスプレイでこの特定のボタンが押されたときに呼び出されるポップアップメニューが必要です。NSPopUPButtonを押したときにポップアップするメニューと同様のメニューを表示したいのですが、Cocoaボタン自体を使用できません。これを実現する最良の方法は、NSPopupButtonCellを使用することのようです。Lispでコードを記述し、Objective-Cブリッジを介してCocoaにアクセスしているため、ここにコードを投稿できませんが、次の擬似コードがメニューを表示するように見えるかどうか、または明らかな欠陥があるかどうかを確認したかっただけです。私の論理:

• Pseudo Code for function that is called when button is pressed:
• Initialize an NSPopUpButtonCell Using initTextCell: "test" pullsDown: NO
• allocate an NSMenu using alloc
• add two menu items using addItem:
• set the menu of the popUpButtonCell to be the menu that was just allocated using setMenu:
• Next I tried two methods to try and get the menu to actually be displayed,
  first I tried using drawWithFrame:inView: and when that did not work I also tried 
  using drawBezelWithFrame:inView: eventhough the docs said not to use but I just 
  tried it out of desperation.
• finally, when the draw methods did not work I tried using performClick: on the 
  popupButtonCell to try and simulate the click.

これらの方法はいずれも、メニューを表示するのに成功しませんでした。セルに含まれるメニューをプログラムでポップアップする他の方法はありますか?

4

2 に答える 2

3

trackMouse:inRect:ofView:untilMouseUp:私はあなたがの方法を探していると思いますNSCell

[theCell trackMouse:[NSApp currentEvent] inRect:NSZeroRect ofView:theView untilMouseUp:YES];
于 2009-12-18T13:33:48.293 に答える
0

NSMenuプレーンと呼び出しを使用した方がよいと思います+[NSMenu popUpContextMenu:withEvent:forView:]。10.6 以降のみをターゲットにしている場合は、 もチェックしてください-[NSMenu popUpMenuPositioningItem:atLocation:inView:]。これにより、メニューの配置をより細かく制御できます。ビューに実装mouseDown:し、メニューを作成 (または nib ファイルからロード) して表示するだけで、NSMenuそこからすべての詳細を処理する必要があります。NSMenuItem項目が選択されたときにアクション メソッドが正しく呼び出されるように、それぞれのターゲットとアクションが設定されていることを確認してください。

于 2009-12-18T06:10:53.303 に答える