Required plugins for this example: MBS MacCocoa Plugin, MBS MacBase Plugin, MBS DynaPDF 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 PDF Icon
Class Window1 Inherits Window
Control CreateMenuButton Inherits PushButton
ControlInstance CreateMenuButton Inherits PushButton
EventHandler Sub Action()
e = new NSStatusItemMBS
if not e.Available then
MsgBox "Not available?"
Return
end if
call e.CreateMenu(-1)
e.Title="PDF"
e.HighlightMode=true // clickable
dim img as new NSImageMBS(pdfdata)
img.setSize(20,20)
e.Image = img
End EventHandler
End Control
Control CreatePDFButton Inherits PushButton
ControlInstance CreatePDFButton Inherits PushButton
EventHandler Sub Action()
// we use DynaPDF plugin to create PDF
dim pdf as new MyDynapdfMBS
pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
call pdf.CreateNewPDF nil
call pdf.Append
call pdf.SetPageWidth(32)
call pdf.SetPageHeight(32)
call pdf.SetFillColorSpace(pdf.kcsDeviceRGB)
call pdf.SetFillColor(255)
call pdf.Rectangle(0, 0, 16, 16, pdf.kfmFill)
call pdf.Rectangle(16, 16, 16, 16, pdf.kfmFill)
call pdf.EndPage
call pdf.CloseFile
PDFData = pdf.GetBuffer
CreateMenuButton.Enabled = true
// display
dim img as new NSImageMBS(pdfdata)
canvas1.Backdrop = img.CopyPictureWithMask
End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Property Protected e As NSStatusItemMBS
Property pdfdata As string
End Class
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"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
if TargetMachO=false then
MsgBox "This example needs a MachO target running on Mac OS X."
quit
end if
End EventHandler
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
// output all messages on the console:
System.DebugLog str(ErrorCode)+": "+ErrorMessage
// and display dialog:
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
d.icon=MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Continue"
d.CancelButton.Visible=True //show the Cancel button
// a warning or an error?
if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then
// if user decided to ignore, we'll ignore
if IgnoreWarnings then Return 0
d.Message="A warning occurred while processing your PDF code."
// we add a third button to display all warnings
d.AlternateActionButton.Caption = "Ignore warnings"
d.AlternateActionButton.Visible = true
else
d.Message="An error occurred while processing your PDF code."
end if
d.Explanation = str(ErrorCode)+": "+ErrorMessage
b=d.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case d.ActionButton
Return 0 // ignore
Case d.AlternateActionButton
IgnoreWarnings = true
Return 0 // ignore
Case d.CancelButton
Return -1 // stop
End select
End EventHandler
Property IgnoreWarnings As Boolean
End Class