Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/WebUIDelegate
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/WebUIDelegate
This example is the version from Thu, 15th Aug 2018.
Project "WebUIDelegate.rbp"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StatusText Inherits Label
ControlInstance StatusText Inherits Label
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() // This timer is to make updates happen not too often ProgressBar1.Value=100*web.EstimatedProgressMBS End EventHandler
End Control
Control Info Inherits Label
ControlInstance Info Inherits Label
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action() web.Visible=me.Value End EventHandler
End Control
Control web Inherits HTMLViewer
ControlInstance web Inherits HTMLViewer
End Control
EventHandler Sub Close() if wui<>nil then wui.w=nil end if End EventHandler
EventHandler Sub Open() wui=new MyUIEvents wui.w=self web.InstallWebUIDelegateMBS wui if not me.Composite then MsgBox "This window must be composite!" end if End EventHandler
Property Protected wui As myuIEvents
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
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.LoadHTMLStringMBS HTMLCode.EditField1.text,"" End EventHandler
End Class
Class MyUIEvents Inherits WebUIDelegateMBS
EventHandler Function AreToolbarsVisible() As boolean system.debuglog "AreToolbarsVisible in Xojo" Return false End EventHandler
EventHandler Sub Close() 'MsgBox "Close" End EventHandler
EventHandler Function ContextMenuItemsForElement(elementInformation as Dictionary, defaultMenuItems() as NSMenuItemMBS) As NSMenuItemMBS() dim menuItems() as NSMenuItemMBS = defaultMenuItems if MenuItems.Ubound >= 0 then MenuItems.Append NSMenuItemMBS.separatorItem end if dim m as new MyNSMenuItemMBS m.Title = "Test me" m.Enabled = true // keep reference to get events later! self.myMenuItem = m MenuItems.Append m return MenuItems End EventHandler
EventHandler Function CreateWithRequest(Request as NSURLRequestMBS) As object dim w as MainWindow system.debuglog "CreateWebViewWithRequest in Xojo" w=new MainWindow if Request<>Nil then // old webkit gives request here. Newer versions call load request on new webview themself. w.web.LoadRequest Request end if Return w.web End EventHandler
EventHandler Function GetContentRect(byref left as double, byref top as double, byref width as double, byref height as double) As boolean system.debuglog "GetContentRect in Xojo" top=w.web.top left=w.web.left Width=w.web.Width Height=w.web.Height // Return true End EventHandler
EventHandler Function GetFrame(byref left as double, byref top as double, byref width as double, byref height as double) As boolean system.debuglog "GetFrame in Xojo" left=w.Left top=w.top width=w.Width height=w.Height // Return true End EventHandler
EventHandler Function GetStatusText() As String system.debuglog "GetStatusText in Xojo" Return w.StatusText.text End EventHandler
EventHandler Function IsResizable() As boolean system.debuglog "IsResizeable in Xojo" End EventHandler
EventHandler Function IsStatusBarVisible() As boolean system.debuglog "IsResizeable in Xojo" Return true End EventHandler
EventHandler Sub Open() 'MsgBox "Open" End EventHandler
EventHandler Sub RunJavaScriptAlertPanelWithMessage(message as String) system.debuglog "RunJavaScriptAlertPanelWithMessage" MsgBox message End EventHandler
EventHandler Function RunJavaScriptConfirmPanelWithMessage(message as String) As boolean system.debuglog "RunJavaScriptConfirmPanelWithMessage" MsgBox message End EventHandler
EventHandler Function RunJavaScriptTextInputPanelWithPrompt(prompt as String, defaultText as String) As String system.debuglog "RunJavaScriptTextInputPanelWithMessage" MsgBox prompt+" "+defaultText End EventHandler
EventHandler Function SetContentRect(left as double, top as double, width as double, height as double) As boolean system.debuglog "SetContentRect in Xojo" system.debuglog str(left)+"/"+str(top)+" "+str(Width)+" "+str(Height) End EventHandler
EventHandler Function SetFrame(left as double, top as double, width as double, height as double) As boolean system.debuglog "SetFrame in Xojo" system.debuglog str(left)+"/"+str(top)+" "+str(Width)+" "+str(Height) End EventHandler
EventHandler Function SetResizable(resizeable as boolean) As boolean system.debuglog "SetResizeable in Xojo" End EventHandler
EventHandler Function SetStatusBarVisible(visible as boolean) As boolean system.debuglog "SetStatusbarVisible in Xojo" End EventHandler
EventHandler Function SetStatusText(text as String) As boolean system.debuglog "SetStatusText in Xojo" system.debuglog text w.StatusText.text=text End EventHandler
EventHandler Function SetToolbarsVisible(visible as boolean) As boolean system.debuglog "SetToolbarsVisible in Xojo" End EventHandler
EventHandler Function WindowClose() As boolean system.debuglog "Closed in Xojo" w.Close End EventHandler
EventHandler Function WindowFocus() As boolean system.debuglog "Focus in Xojo" w.show End EventHandler
EventHandler Function WindowShow() As boolean system.debuglog "Show in Xojo" w.show End EventHandler
EventHandler Function WindowUnfocus() As boolean system.debuglog "Unfocus in Xojo" End EventHandler
EventHandler Function runOpenPanelForFileButtonWithResultListener(listener as WebOpenPanelResultListenerMBS, allowMultipleFiles as boolean) As boolean dim o as OpenDialog dim f as FolderItem o=new OpenDialog f=o.ShowModal if f=nil then listener.cancel else listener.chooseFilename f end if Return true End EventHandler
Property myMenuItem As MyNSMenuItemMBS
Property w As mainwindow
End Class
Class HTMLCode Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
End Class
Class MyNSMenuItemMBS Inherits NSMenuItemMBS
EventHandler Sub Action() MsgBox "Test menu item clicked" End EventHandler
EventHandler Function validateMenuItem(menuItem as NSMenuItemMBS) As boolean Return true End EventHandler
End Class
End Project

Feedback, Comments & Corrections

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




Links
MBS FileMaker blog