Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/HTMLViewer Mac/WebResourceLoadDelegate
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/WebResourceLoadDelegate
This example is the version from Sun, 17th Mar 2012.
Project "WebResourceLoadDelegate.rbp"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control Info Inherits Label
ControlInstance Info Inherits Label
End Control
Control web Inherits HTMLViewer
ControlInstance web Inherits HTMLViewer
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
EventHandler Sub Open() if not me.Composite then MsgBox "This window must be composite!" quit end if wui=new MyLoadEvents web.InstallWebResourceLoadDelegateMBS wui End EventHandler
Property Protected wui As myLoadEvents
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO then // ok else MsgBox "This project works only as MachO target on Mac OS X." end if MainWindow.show MainWindow.web.LoadURL "http://www.apple.com" End EventHandler
End Class
Class MyLoadEvents Inherits WebResourceLoadDelegateMBS
Const Untitled = "d"
EventHandler Sub Close() System.DebugLog "Close" End EventHandler
EventHandler Sub Open() System.DebugLog "Open" End EventHandler
EventHandler Sub didFailLoadingWithError(id as string, errorString as string, dataSource as WebDataSourceMBS) dim d,i,c,n as integer d=val(id) c=MainWindow.List.ListCount-1 for i=c downto 0 n=val(MainWindow.List.CellTag(i,0)) if n=d then MainWindow.List.cell(i,1)="failed" exit end if next End EventHandler
EventHandler Sub didFinishLoadingFromDataSource(id as string, dataSource as WebDataSourceMBS) dim d,i,c,n as integer d=val(id) c=MainWindow.List.ListCount-1 for i=c downto 0 n=val(MainWindow.List.CellTag(i,0)) if n=d then n=MainWindow.list.CellTag(i,1) // length of file if n=0 then MainWindow.List.cell(i,1)="done" else MainWindow.List.cell(i,1)="done, "+Format(n,"0")+" Bytes" end if exit end if next End EventHandler
EventHandler Sub didReceiveContentLength(id as string, length as integer, dataSource as WebDataSourceMBS) dim d,i,c,n as integer d=val(id) c=MainWindow.List.ListCount-1 for i=c downto 0 n=val(MainWindow.List.CellTag(i,0)) if n=d then MainWindow.List.CellTag(i,1)=length MainWindow.List.cell(i,1)=Format(length,"0")+" Bytes" exit end if next End EventHandler
EventHandler Sub didReceiveResponse(id as string, response as NSURLResponseMBS, dataSource as WebDataSourceMBS) dim d,i,c,n as integer d=val(id) c=MainWindow.List.ListCount-1 for i=c downto 0 n=val(MainWindow.List.CellTag(i,0)) if n=d then MainWindow.List.cell(i,1)="Receiving..." exit end if next End EventHandler
EventHandler Function identifierForInitialRequest(request as NSURLRequestMBS, dataSource as WebDataSourceMBS) As string dim n as string // we assign a row and return the row number as ID for further calls count=count+1 n=str(count) MainWindow.List.AddRow request.url MainWindow.List.celltag(MainWindow.List.LastIndex,0)=count Return n End EventHandler
EventHandler Function willSendRequest(id as string, request as NSURLRequestMBS, redirectResponse as NSURLResponseMBS, dataSource as WebDataSourceMBS) As NSURLRequestMBS dim d,i,c,n as integer d=val(id) c=MainWindow.List.ListCount-1 for i=c downto 0 n=val(MainWindow.List.CellTag(i,0)) if n=d then MainWindow.List.Cell(i,0)=request.url MainWindow.List.cell(i,1)="Sending..." exit end if next Return request End EventHandler
Property Protected count As Integer
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo PDF Plugins