Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/PopupMenu in Cocoa
Function:
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/PopupMenu in Cocoa
This example is the version from Sun, 5th Sep 2015.
Project "PopupMenu in Cocoa.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action() dim items() as MyNSMenuItemMBS dim m as new NSMenuMBS // first entry dim p as new Picture(16,16,32) p.Graphics.ForeColor = &cFF0000 p.Graphics.FillRect 0, 0, 16, 16 dim item as new MyNSMenuItemMBS item.Title = "Hello World" item.Enabled = true item.Image = new NSImageMBS(p) items.append item m.addItem item // second entry p = new Picture(16,16,32) p.Graphics.ForeColor = &c0000FF p.Graphics.FillRect 0, 0, 16, 16 item = new MyNSMenuItemMBS // with font dim f as NSFontMBS = NSFontMBS.fontWithName("Zapfino", 13) dim tt as new NSMutableAttributedStringMBS if tt.initWithString("Just a test") then dim r as NSRangeMBS = NSMakeRangeMBS(0, tt.Length) tt.addAttribute tt.NSFontAttributeName, f, r item.attributedTitle = tt end if item.Enabled = true item.Image = new NSImageMBS(p) items.append item m.addItem item // show dim view as NSViewMBS = me.NSViewMBS dim r as Boolean MyNSMenuItemMBS.LastSelected = nil r = m.popUpMenuPositioningItem(items(0), NSMakePointMBS(me.MouseX, me.MouseY), view) 'm.popUpContextMenu(m, nil, view, nil) if MyNSMenuItemMBS.LastSelected <> nil then MsgBox "selected: "+MyNSMenuItemMBS.LastSelected.Title end if End EventHandler
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyNSMenuItemMBS Inherits NSMenuItemMBS
EventHandler Sub Action() // remember last item called // or do your processing here LastSelected = me End EventHandler
Property Shared LastSelected As MyNSMenuItemMBS
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacControls Plugin.




Links
MBS Xojo Plugins