Class
WebSDKUIControl
Description
WebSDKUIControl is a direct subclass of WebUIControl, but because WebUIControl inherits from WebControl it means that WebSDKUIControl doesn't actually have a direct relationship with WebSDKControl.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
allowedDragActionTypes As WebDragItem.DragActionTypes |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All |
|||
script As String |
|||
Events
Name |
Parameters |
Returns |
---|---|---|
hitItem As WebMenuItem |
||
g As Graphics |
||
obj As WebDragItem, action As WebDragItem.DragActionTypes, x As Integer, y As Integer |
||
request As WebRequest, response As WebResponse |
||
js As JSONItem |
||
session As WebSession |
||
session As WebSession |
||
session As WebSession |
||
Constants
These constants are designed to be used with the WebSDKUIControl to show icons at the Navigator and Library.
Name
Description
NavigatorIcon
This constant is used to override the icon of your control in the Navigator. Using the WebSDKIconConverter, place the Base64 icon data into the value of this constant.
LibraryIcon
This constant is used to override the icon of your control in the Library. Using the WebSDKIconConverter, place the Base64 icon data into the value of this constant.
Enumerations
WebSDKUIControl.Indicators
Indicators
Specifies the color scheme for the control.
Name
Default
Primary
Secondary
Success
Danger
Warning
Info
Light
Dark
Link
Property descriptions
WebSDKUIControl.ContextualMenu
ContextualMenu As WebMenuItem
If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.
On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.
This code populates a contextual menu in the Shown event of the control.
Var menu As New WebMenuItem menu.AddMenuItem("One") menu.AddMenuItem("Two") menu.AddMenuItem("Three") Me.ContextualMenu = menuThe menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:
Select Case hitItem.Text Case "One" MessageBox("One") Case "Two" MessageBox("Two") Case "Three" MessageBox("Three") End Select
WebSDKUIControl.ControlID
ControlID As String
Identifies the control on a per session basis.
This property is read-only.
WebSDKUIControl.Enabled
Enabled As Boolean
When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.
In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.
Disable a button when a check box value changes:
If AllowSaveCheckBox.Value Then SaveButton.Enabled = True Else AllowSaveButton.Enabled = False End If
WebSDKUIControl.Height
Height As Integer
The height (in pixels) of the control.
WebSDKUIControl.Indicator
Indicator As WebUIControl.Indicators
The color scheme for the control.
This example sets the indicator of the button to Danger:
Button1.Indicator = WebUIControl.Indicators.Danger
WebSDKUIControl.Left
Left As Integer
The position of the left side of the WebUIControl in pixels, relative to the web page.
WebSDKUIControl.LockBottom
LockBottom As Boolean
Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.
WebSDKUIControl.LockHorizontal
LockHorizontal As Boolean
LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).
For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.
WebSDKUIControl.LockLeft
LockLeft As Boolean
Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.
WebSDKUIControl.LockRight
LockRight As Boolean
Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.
WebSDKUIControl.LockTop
LockTop As Boolean
Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning web page.
WebSDKUIControl.LockVertical
LockVertical As Boolean
LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.
For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.
WebSDKUIControl.Name
Name As String
The name of the control.
This property is read-only.
WebSDKUIControl.Page
Page As WebPage
Identifies the web page that contains the control.
This property is read-only.
WebSDKUIControl.PanelIndex
PanelIndex As Integer
If the control has been placed on a WebTabPanel or WebPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use SelectedPanelIndex.
This code displays the panel index of the control that is on the page.
MessageBox(Me.SelectedPanelIndex.ToString)
WebSDKUIControl.Parent
Parent As WebView
Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.
This property is read-only.
WebSDKUIControl.TabIndex
TabIndex As Integer
The WebUIControl's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.
This example sets the control's TabIndex.
Me.TabIndex = 2
WebSDKUIControl.Tooltip
Tooltip As WebToolTip
Text of a message displayed as a tooltip.
The tip is displayed when the user places the mouse on the control and leaves it there.
This code in the Shown event of a Button sets the tooltip:
Me.Tooltip = "Save changes"
WebSDKUIControl.Top
Top As Integer
The top of the control in local coordinates relative to the web page.
WebSDKUIControl.Visible
Visible As Boolean
WebSDKUIControl.Width
Width As Integer
The width (in pixels) of the web control.
This code in the Shown event handler increases the size of the control:
Me.Width = Me.Width + 50
Method descriptions
WebSDKUIControl.AcceptPictureDrop
AcceptPictureDrop(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to accept a picture drop of a WebDragItem.
WebSDKUIControl.AcceptRawDataDrop
AcceptRawDataDrop(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to accept a raw data drop of a WebDragItem.
WebSDKUIControl.AcceptTextDrop
AcceptTextDrop(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to accept a picture drop of a WebDragItem.
WebSDKUIControl.AllowPictureDrag
AllowPictureDrag(allowedDragActionTypes As WebDragItem.DragActionTypes)
Allows the control to be dragged as a picture.
WebSDKUIControl.AllowRawDataDrag
AllowRawDataDrag(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to be dragged as raw data.
WebSDKUIControl.AllowTextDrag
AllowTextDrag(dragActionType As WebDragItem.DragActionTypes = WebDragItem.DragActionTypes.All)
Allows the control to be dragged as text.
WebSDKUIControl.Close
Close
Removes the control from the page.
WebSDKUIControl.CSSClasses
CSSClasses As WebCSSClasses
Returns the instance of WebCSSClasses for this control allowing you to add CSS classes to and remove CSS classes from the control.
WebSDKUIControl.ExecuteJavaScript
ExecuteJavaScript(script As String)
Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.
The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.
This code in the Pressed event of a Button displays an alert using JavaScript:
Me.ExecuteJavaScript("alert('Hello!');")This code will select the text in a WebTextField (or WebTextArea):
WebTextField1.ExecuteJavascript("document.getElementById('" + _ WebTextField1.ControlID + "_inner').select();")
WebSDKUIControl.GoToURL
GoToURL(url As String, inNewWindow As Boolean = False)
Opens the passed url in place of the current web page or downloads a file. If inNewWindow is True, the browser is asked to open the url in a new window.
If the browser has popup windows disabled and inNewWindow is True, the method silently fails and the page is not shown.
If inNewWindow is False, the running web app is replaced with the specified url. If you want to display an external web site within your web app, use the WebHTMLViewer control.
Display a web site in a new popup window:
Me.GoToURL("http://www.wikipedia.org", True)
WebSDKUIControl.SetFocus
SetFocus
If the control is enabled, this method sets the focus to the WebUIControl.
This code checks for a required value when a button is pressed:
If UserNameField.Text.IsEmpty Then MessageBox("Please enter your UserName.") UserNameField.SetFocus Return End If
WebSDKUIControl.Style
Style As WebStyle
Returns the WebStyle for the control.
Style(Assigns value As WebStyle)
WebSDKUIControl.UpdateBrowser
UpdateBrowser
Forces the current values of the control to be sent to the browser.
This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.
This code iterates through a RowSet of database rows, updates a ProgressBar and then forces the updated ProgressBar to be sent to the browser via UpdateBrowser.
ProgressBar1.MaximumValue = SalesData.RowCount For Each row As DatabaseRow in SalesData AnalyzeSales(row) ProgressBar1.Value = ProgressBar1.Value + 1 ProgressBar1.UpdateBrowser Next
WebSDKUIControl.UpdateControl
UpdateControl(sendImmediately As Boolean = False)
Similar to the UpdateBrowser method, this method also sets the internal flag which indicates to the framework that your control needs a refresh on the browser. When sendImmediately is False, any changes made are deferred until the event loop completes. When sendImmediately is True, the changes will be sent at that very moment.
Note
Calling this method with sendImmediately set to True will override the "deferred" option of any changes before it was called.
Event descriptions
WebSDKUIControl.Closed
Closed
The control has been removed from the browser either because the page has closed or the control's Close method was called.
WebSDKUIControl.ContextualMenuSelected
ContextualMenuSelected(hitItem As WebMenuItem)
Called when a contextual menu item is selected. This selected item is contained in hitItem.
This code populates a contextual menu in the Opening event of a WebToolbar:
Var menu As New WebMenuItem menu.AddMenuItem("One") menu.AddMenuItem("Two") menu.AddMenuItem("Three") Me.ContextualMenu = menuThe menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:
Select Case hitItem.Text Case "One" MessageBox("One") Case "Two" MessageBox("Two") Case "Three" MessageBox("Three") End Select
WebSDKUIControl.DrawControlInLayoutEditor
DrawControlInLayoutEditor(g As Graphics)
This event fires whenever your control needs to be refreshed in the IDE's layout editor.
For more information of how this works, see Drawing Your Control.
WebSDKUIControl.DropObject
DropObject(obj As WebDragItem, action As WebDragItem.DragActionTypes, x As Integer, y As Integer)
Called when a dragged item is over a control that can accept it. The dragged item is contained in obj and the type of drag is identified by action.
WebSDKUIControl.ExecuteEvent
ExecuteEvent(name As String, parameters As JSONItem) As Boolean
This event fires when an event is sent from the browser to the app using the
triggerServerEvent
JavaScript method. Return True if your control has handled the event.
WebSDKUIControl.HandleRequest
HandleRequest(request As WebRequest, response As WebResponse) As Boolean
This event fires in the same way as App.HandleURL does except that it is for requests that are only for the current control.
To trigger this event you will need to create a specially formed URL:
Var url As String = "https://www.yourdomain.com/sdk/" + Self.ControlIDSee the documentation for WebApplication.HandleURL for usage.
WebSDKUIControl.Hidden
Hidden
The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.
Note
This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.
WebSDKUIControl.JavaScriptClassName
JavaScriptClassName As String
This event fires when the control is first created to send the JavaScript constructor for your control to the browser.
WebSDKUIControl.Opening
Opening
The control has been created and the page is opening but has not been sent to the browser yet.
The Opening event handler can be used to initialize non-visual properties and settings for controls.
In most cases, you should use the Shown event to initialize controls.
WebSDKUIControl.Serialize
Serialize(js As JSONItem)
This event fires when the framework sends the first configuration to your control in the browser, whenever a property on WebControl is changed and whenever you call the Xojo UpdateBrowser method.
WebSDKUIControl.SessionCSSURLs
SessionCSSURLs(session As WebSession) As String()
This event fires each time a new session starts. You should return an array of URLs which point to any css stylesheets you need for your control to function. The Xojo framework will attempt to prevent duplicate URLs from being sent to the same session.
Note
Hint: One reason we supply the session object is so you can figure out whether or not items have already been delivered to a particular session.
WebSDKUIControl.SessionHead
SessionHead(session As WebSession) As String
This event fires each time a new session starts. You should return a String containing the items you wish to add to the
<head>
tag.
WebSDKUIControl.SessionJavascriptURLs
SessionJavascriptURLs(session As WebSession) As String()
This event fires each time a new session starts. You should return an array of URLs which point to any javascript you need for your control to function, whether it be a subclass of XojoControl or an external library. The Xojo framework will attempt to prevent duplicate URLs from being sent to the same session.
Note
One reason we supply the session object is so you can figure out whether or not items have already been delivered to a particular session.
WebSDKUIControl.Shown
Shown
The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.
Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.
Note
This event is the web equivalent to the DesktopWindow.Activated event.
This code in the Shown event of a WebListBox adds 2 rows with 3 columns:
Me.RemoveAllRows Me.AddRow("Row 1", "Bob", "Roberts") Me.AddRow("Row 2", "Barb", "Reynolds")This example sets the text of a label:
If Session.LoggedIn Then Me.Text = "Welcome!" Else Me.Text = "Welcome, " + Session.UserName End If
Drawing Your Control
WebSDK Controls in 2020r1 and above have the ability to draw themselves in the layout editor using the same techniques that you might use to draw a control in the Paint event of a canvas. We developed a specialized XojoScript API 2 compatible Graphics context which allows you to draw just as you would in the Paint event of a canvas object. The difference here is that you also have access to the Properties and Constants of your class as well as being able to query the current Bootstrap theme.
For the purposes of drawing controls in the Layout Editor, you will need to implement the DrawControlInLayoutEditor event (you should implement it even if you're not using it, just so your end-users don't see the event). You can put just about any API 2 graphics drawing code into this event and have it render in the Layout editor. If the code you have placed in the event can't compile or runs into a runtime issue, an amber warning icon will be drawn on your control and the errors will be sent to the Messages panel.
Here's an example of how you would draw a red oval within the bounds of the control:
g.DrawingColor = &cFF0000
g.DrawOval(0, 0, g.Width, g.Height)
In addition to the standard drawing controls, there are also some methods for accessing the properties and constants in your control as well as getting values from the user's current Bootstrap theme file.
Property Methods
BooleanProperty(Name as String) as Boolean
Gets the current value of a Boolean property of your control.
ColorProperty(name As String) As Color
Gets the current value of a Color property of your control.
DoubleProperty(name As String) As Double
Gets the current value of a Double property of your control.
IntegerProperty(name As String) As Integer
Gets the current value of an Integer property of your control.
PictureProperty(name As String) As Picture
Gets the current value of a Picture property of your control.
StringProperty(name As String) As String
Gets the current value of a String property of your control.
Constant Methods
ConstantValue(name As String) As String
Gets the value of a constant in your control as a String.
PictureConstant(name As String) As Picture
Gets the value of a constant in your control as a Picture.
Color Methods
ColorGroup.NamedColor(name As String) As Color
When running on a platform that supports named colors (only macOS at the time of this writing), this method returns the named OS.
Note
Color names are case sensitive, so the macOS secondary label color should be "secondaryLabelColor".
TextColor As Color
Returns the current text color of the platform that the IDE is running on.
FillColor As Color
Returns the current fill color of the platform that the IDE is running on.
IsDarkMode As Boolean
Returns True if the system is running in dark mode (only macOS at the time of this writing).
Font Methods
FontCount As Integer
Returns the number of fonts available on the system.
FontAt(index As Integer) As String
Returns the name of the font at the specified index.
CSS Methods
CSSColorValue(selector as String, propertyName As String, fallbackColor As Color) As Color
Returns a Xojo color converted from whatever format was used in the CSS color definition. Automatically converts #RRGGBB, rgb(1, 0, 0) and rgba(1, 0, 0, 0.5) style colors.
CSSPixelValue(selector As String, propertyName As String, fallbackValue As Double) As Double
Returns a pixel value for a particular selector and property, making automatic adjustments for things that may be in units other than px. Useful for things that may be represented in millimeters, points or rems (rems is multiplied by the value of Body font-size).
CSSStringValue(selector As String, propertyName As String) As String
Returns the raw value of a particular selector and property.