MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

MBS Real Studio Plugin Tutorial Videos

NSStatusItem Source

Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = E&xit
Const kEditClear = &Delete

// Properties
Dim statusitem As NSStatusItemMBS
Dim menu As NSMenuMBS
Dim items(-1) As NSMenuItemMBS
Dim submenu As NSMenuMBS
Dim subsubmenu As NSMenuMBS

// Event implementations
Sub Open()
statusitem=new NSStatusItemMBS

if statusitem.CreateMenu then

const NSLeftMouseDownMask = 2
const NSLeftMouseUpMask = 4

statusitem.SendActionOn NSLeftMouseDownMask+NSLeftMouseUpMask

dim p,m as Picture
dim n as NSImageMBS

p=NewPicture(16,16,32)
p.Graphics.ForeColor=&cFF0000 // red
p.Graphics.FillOval 0,0,16,16

m=NewPicture(16,16,32)
m.Graphics.ForeColor=&c000000
m.Graphics.FillOval 0,0,16,16

n=new NSImageMBS(p,m)

statusitem.image=n

statusitem.Title="Hello"
statusitem.HighlightMode=true
statusitem.ToolTip="Just a little test"

menu=new NSMenuMBS
call menu.CreateMenu

dim item as NSMenuItemMBS

item=new MyNSMenuItem
item.CreateMenuItem
item.Title="Hello"
item.state=1

menu.addItem item
items.Append item // keep a reference!

item=new MyWebSiteNSMenuItem
item.CreateMenuItem
item.title="Visit Website..."
item.enabled=true
item.image=GetSafariIcon

menu.addItem item
items.Append item

item=new NSMenuItemMBS
item.CreateSeparator

menu.addItem item
items.Append item // keep a reference!

item=new MyNSMenuItem
item.CreateMenuItem
item.Title="World"
item.Enabled=false

menu.addItem item
items.Append item // keep a reference!

submenu=new NSMenuMBS
call submenu.CreateMenu

subsubmenu=new NSMenuMBS
call subsubmenu.CreateMenu

item=new MyNSMenuItem
item.CreateMenuItem
item.Title="our submenu"
item.Enabled=true

menu.addItem item
items.Append item // keep a reference!

item.submenu=submenu

item=new MyNSMenuItem
item.CreateMenuItem
item.Title="inside submenu"
item.Enabled=true
item.submenu=subsubmenu

submenu.addItem item
items.Append item // keep a reference!

dim myitem as MyNSMenuItem

myitem=new MyNSMenuItem
myitem.CreateMenuItem
myitem.Title="inside subsubmenu"
myitem.SpeakText="I'm in the submenu"
myitem.Enabled=true

subsubmenu.addItem myitem
items.Append myitem // keep a reference!

item=new MyNSMenuItem
item.CreateMenuItem
item.Title="inside subsubmenu with beep"
item.tag=2
item.Enabled=true

subsubmenu.addItem item
items.Append item // keep a reference!


statusitem.menu=menu
else
MsgBox "This example requires Mac OS X 10.3 or newer."
end if
End Sub

// Methods
Function GetSafariIcon() As NSImageMBS
dim file as FolderItem

file=LaunchServicesFindApplicationForInfoMBS("","com.apple.Safari","")

if file<>nil then
dim p,m as Picture

p=file.IconImageMBS(16)
m=file.IconMaskMBS(16)

if p<>Nil and m<>nil then
Return new NSImageMBS(p,m)
end if
end if
End Function
End Class

Class Window1
Inherits Window
End Class

Class MyNSMenuItem
Inherits NSMenuItemMBS
// Properties
Dim SpeakText As string

// Event implementations
Sub Action()
if me.tag=2 then
beep
end if

if SpeakText<>"" then
Speak SpeakText
end if

MsgBox "You clicked on the menu item "+me.Title

'app.statusitem.Menu.Item(2).Enabled=true
End Sub
End Class

Class MyWebSiteNSMenuItem
Inherits NSMenuItemMBS
// Event implementations
Sub Action()
showurl "http://www.monkeybreadsoftware.de"
End Sub
End Class


All movies




Links
MBS Xojo Plugins