Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/NSStatusItem/Statusitem with PopOver
Required plugins for this example: MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Util Plugin, MBS MacControls Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSStatusItem/Statusitem with PopOver
This example is the version from Mon, 19th Jul 2020.
Project "Statusitem with PopOver.xojo_binary_project"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu7 = ""
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu6 = ""
MenuItem AppleAboutthisapplication = "About this application..."
MenuItem UntitledMenu5 = ""
MenuItem UntitledMenu4 = ""
End MenuBar
Class App Inherits Application
EventHandler Sub Close()
if s<>nil then
s.Close
DelayMBS 0.2 // wait for events to flush
s=nil
end if
End EventHandler
EventHandler Sub Open()
if TargetCocoa = false then
MsgBox "This example is only for Cocoa target."
end if
if NSPopoverMBS.available = false then
MsgBox "Please update to Mac OS X 10.7 (Lion)"
Return
end if
s=new MyNSStatusItemMBS
// Create statusitem
call s.CreateMenu
s.HighlightMode=true
s.Title="Click me"
// instead of title you may prefer to show an image and switch image when popup is visible.
End EventHandler
EventHandler Function UnhandledException(error As RuntimeException) As Boolean
quit
Return true
End EventHandler
Property Protected m As NSmenumBS
Property Protected s As NSStatusItemMBS
End Class
Class MyNSStatusItemMBS Inherits NSStatusItemMBS
EventHandler Sub Action()
if pw<>nil then
pw.performClose
pw = nil
vc = nil
else
tv = new NSTextFieldMBS(10,10, 180, 50)
tv.StringValue = "Hello World"
tv.Editable = false
tv.textColor = NSColorMBS.whiteColor
tv.drawsBackground = false
'tv.backgroundColor = NSColorMBS.blackColor
tv.Bordered = false
dim vv as new NSViewMBS(0,0,200,70)
vv.addSubview tv
vc = new NSViewControllerMBS
vc.view = vv
pw = new NSPopoverMBS
pw.animates = true
pw.contentViewController = vc
pw.behavior = pw.NSPopoverBehaviorSemitransient
'pw.appearance = pw.NSPopoverAppearanceHUD
dim f as NSRectMBS = self.window.frame
dim r as NSRectMBS = NSMakeRectMBS(0, 0, f.Width, f.Height)
dim v as NSViewMBS = self.window.contentView
pw.showRelativeToRect(r, v, pw.MaxYEdge)
end if
End EventHandler
Property pw As NSPopoverMBS
Property tv As NSTextFieldMBS
Property vc As NSViewControllerMBS
End Class
Class MyNSPopoverMBS Inherits NSPopoverMBS
End Class
End Project
See also:
- /MacCocoa/NSStatusItem/StatusItem
- /MacCocoa/NSStatusItem/Statusitem Counter
- /MacCocoa/NSStatusItem/StatusItem easy
- /MacCocoa/NSStatusItem/StatusItem with CarbonEvents
- /MacCocoa/NSStatusItem/StatusItem with Image in menu
- /MacCocoa/NSStatusItem/StatusItem with NSView
- /MacCocoa/NSStatusItem/StatusItem with PDF Icon
- /MacCocoa/NSStatusItem/Statusitem with PopOver using Container
- /MacCocoa/NSStatusItem/Statusitem with slider in menubar
- /MacCocoa/NSStatusItem/Statusitem with textfield in menubar
The items on this page are in the following plugins: MBS MacCocoa Plugin.