Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSStatusItem/Statusitem with PopOver
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS Main Plugin, MBS Util 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 Thu, 6th Jan 2016.
Project "Statusitem with PopOver.rbp"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem AppleAboutthisapplication = "About this application..."
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:

Feedback, Comments & Corrections

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

MBS Xojo tutorial videos