Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/InstantMessage
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/InstantMessage
This example is the version from Sun, 17th Mar 2012.
Project "InstantMessage.rbp"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() updatemystatus End EventHandler
End Control
Control Status Inherits Label
ControlInstance Status Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control IdleTime Inherits Label
ControlInstance IdleTime Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
EventHandler Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean if row >= me.ListCount then Return false if column >0 then Return false dim p as Picture p = me.CellTag(row,1) if p<>Nil then g.DrawPicture p,13,3 end if p = me.CellTag(row,0) if p<>Nil then g.DrawPicture p,3,3 end if Return true End EventHandler
End Control
EventHandler Sub Open() InstantMessage=new MyInstantMessageMBS updatemystatus End EventHandler
Protected Function GetStatusPicture(n as integer) As picture dim name as string = InstantMessage.imageNameForStatus(n) if name<>"" then dim image as NSImageMBS = NSImageMBS.imageNamed(name) if image<>nil then Return image.CopyPictureWithMask end if end if End Function
Protected Function ServiceStatus(n as integer) As string Select case n case IMServiceMBS.IMServiceStatusDisconnected return "Disconnected" case IMServiceMBS.IMServiceStatusLoggedIn return "LoggedIn" case IMServiceMBS.IMServiceStatusLoggedOut return "LoggedOut" case IMServiceMBS.IMServiceStatusLoggingIn return "LoggingIn" case IMServiceMBS.IMServiceStatusLoggingOut return "LoggingOut" else return "unknown?" end Select End Function
Sub Update() // just to keep it not updating 100 times a second timer1.mode=1 End Sub
Sub updatemystatus() Status.text=ServiceStatus(InstantMessage.myStatus) dim d as Double = InstantMessage.myIdleTime if d>1 then IdleTime.text = str(d)+"s" else IdleTime.Text = "" end if Canvas1.Backdrop=GetStatusPicture(InstantMessage.myStatus) list.DeleteAllRows List.ColumnAlignmentOffset(0)=80 dim sa(-1) as IMServiceMBS = InstantMessage.allServices for each s as IMServiceMBS in sa list.AddRow s.Name+" ("+s.LocalizedName+") - "+ServiceStatus(s.Status) List.cellbold(list.LastIndex,0)=true dim dics() as Dictionary = s.infoForAllScreenNames for each dic as Dictionary in dics dim ScreenName as string = dic.Lookup(IMServiceMBS.IMPersonScreenNameKey,"") dim FirstName as string = dic.Lookup(IMServiceMBS.IMPersonFirstNameKey,"") dim LastName as string = dic.Lookup(IMServiceMBS.IMPersonLastNameKey,"") dim StatusMessage as string = dic.Lookup(IMServiceMBS.IMPersonStatusMessageKey,"") dim PictureData as string = dic.Lookup(IMServiceMBS.IMPersonPictureDataKey, "") dim status as integer= dic.Lookup(IMServiceMBS.IMPersonStatusKey, -1) List.AddRow ScreenName List.Cell(List.LastIndex,1) = FirstName List.Cell(List.LastIndex,2) = LastName List.Cell(List.LastIndex,3) = StatusMessage if PictureData<>"" then dim n as new NSImageMBS(PictureData) if n<>nil then List.CellTag(list.LastIndex,1) = n.CopyPicture end if end if List.CellTag(list.LastIndex,0) = GetStatusPicture(Status) next next End Sub
Property Protected InstantMessage As InstantMessageMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
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 MyInstantMessageMBS Inherits InstantMessageMBS
EventHandler Sub PersonInfoChanged(info as dictionary) window1.Update End EventHandler
EventHandler Sub PersonStatusChanged(info as dictionary) window1.Update End EventHandler
EventHandler Sub ServiceStatusChanged() window1.Update End EventHandler
End Class
End Project

Feedback, Comments & Corrections

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





Links
MBS Xojo PDF Plugins