Example: /MacControls/PopupMenu in Cocoa

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/PopupMenu in Cocoa


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 Fri, 14th Feb 2019.

Project "PopupMenu in Cocoa.xojo_binary_project"
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(0,0), 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:

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


💬 Ask a question or report a problem