Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSStatusItem/Statusitem with slider in menubar
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 slider in menubar
This example is the version from Sun, 17th Mar 2012.
Project "Statusitem with slider in menubar.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() myview = new NSViewMBS(0,0,150,20) myslider = new MyNSSliderMBS(20, 0, 80, 20) mylabel = new NSTextViewMBS(110, 0, 40, 20) mylabel.text = "50" myslider.mylabel = mylabel myslider.maxValue = 100 myslider.minValue = 0 myslider.intValue = 50 myview.addSubview myslider myview.addSubview mylabel s=new NSStatusItemMBS // Create statusitem call s.CreateMenu s.HighlightMode=true s.Title="Click me" // create a menu to attach to the statusitem m=new NSMenuMBS // Create menu items VisitWebsiteMenu=new MyCocoamenuitem VisitWebsiteMenu.CreateMenuItem "Visit website" VisitWebsiteMenu.ID=2 m.AddItem VisitWebsiteMenu dim d as new NSMenuItemMBS d.CreateSeparator m.AddItem d DisplayMenu=new MyCocoamenuitem DisplayMenu.CreateMenuItem "" DisplayMenu.view = myview DisplayMenu.id=10 m.AddItem DisplayMenu d=new NSMenuItemMBS d.CreateSeparator m.AddItem d QuitMenu=new MyCocoamenuitem QuitMenu.CreateMenuItem "Quit" QuitMenu.ID=1 m.AddItem QuitMenu // attach menu s.Menu=m End EventHandler
EventHandler Function UnhandledException(error As RuntimeException) As Boolean quit Return true End EventHandler
Property Private DisplayMenu As myCocoamenuitem
Property QuitMenu As MyCocoamenuitem
Property UpdateMenu As mycocoamenuitem
Property VisitWebsiteMenu As mycocoamenuitem
Property Protected m As NSmenumBS
Property mylabel As NSTextViewMBS
Property myslider As MyNSSliderMBS
Property myview As NSViewMBS
Property Protected s As NSStatusItemMBS
End Class
Class MyCocoamenuitem Inherits NSMenuItemMBS
EventHandler Sub Action() Select case id case 1 quit case 2 ShowURL "http://www.monkeybreadsoftware.de" end Select End EventHandler
Property ID As integer
End Class
Class MyNSSliderMBS Inherits NSSliderMBS
EventHandler Sub Action() mylabel.text = str(me.intValue) End EventHandler
Property mylabel As NSTextViewMBS
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS Xojo blog