Project

General

Profile

HTML-BROWSER Widget and OCX Replacement

Introduction

HTML-BROWSER widget is capable to render html pages and their associated resources loaded from absolute urls or from the file system relative to the FWD client process. It is an extension to the 4GL language and behaves as any other traditional widget. That is, it can be part of a FRAME widget, can be sized, positioned, can react to user input and so on.

The widget can load html pages from absolute urls, like "https://www.example.org", or from relative paths, like "/mywebpath/index.html". The latter case requires a mapping of the request path to the file system where the html resources are loaded from. This mapping is performed for every instance of the widget using the widget attributes CONTEXT-PATH and RESOURCE-BASE. CONTEXT-PATH defines the root request path. RESOURCE-BASE is the file path location on the system where FWD client process runs where the html resources will be located. Setting CONTEXT-PATH to "/mywebpath" and RESOURCE-BASE to "file:///wwwroot" will make the request to "mywebpath/index.html" load index.html from "/wwwroot/index.html", likewise request to "mywebpath/img/image.png" will be resolved to "/wwwroot/img/image.png" (assuming <base href="..."> is correctly set in the html page).

Note that serving of pages from local file system is currently supported only in Web GUI driver, but not in Swing GUI. The work to implement this control was done in #3768 and #3910.

4GL Syntax

To create the widget, use:

DEFINE VAR h AS HANDLE.
CREATE HTML-BROWSER h ASSIGN NAME = "mybrowser" CONTEXT-PATH = "/mywebpath" RESOURCE-BASE = "file:///wwwroot" FRAME = FRAME f:HANDLE VISIBLE = TRUE WIDTH = 50 HEIGHT = 20.

Where CONTEXT-PATH and RESOURCE-BASE are optional and only needed when the requested paths must resolve to local file system (local to the FWD client process).

To navigate to a html page do:

h:OPEN-WEB-PAGE("/wwwroot/index.html")
or:
h:OPEN-WEB-PAGE("https://www.example.org").

In the former case the page is loaded from local file system on the FWD client. Any links in the loaded page pointing to "/mywebpath" will resolve to the local file system at the path "/wwwroot" (since CONTEXT-PATH in the example above is set to "/mywebpath" and RESOURCE-BASE is set to "file:///wwwroot").

The widget fires an event before the user interacting with the loaded page navigates away to another page, that is when the user clicks on a html link (<a href="page.html">). To handle this event declare the following internal procedure in the same procedure file where the widget is created:

PROCEDURE mybrowser.WebBrowser.BeforeNavigate2:
  DEFINE INPUT        PARAMETER P-PDISP           AS COM-HANDLE NO-UNDO.
  DEFINE INPUT        PARAMETER P-URL             AS CHARACTER  NO-UNDO.
  DEFINE INPUT        PARAMETER P-FLAGS           AS CHARACTER  NO-UNDO.
  DEFINE INPUT        PARAMETER P-TARGETFRAMENAME AS CHARACTER  NO-UNDO.
  DEFINE INPUT        PARAMETER P-POSTDATA        AS CHARACTER  NO-UNDO.
  DEFINE INPUT        PARAMETER P-HEADERS         AS CHARACTER  NO-UNDO.
  DEFINE INPUT-OUTPUT PARAMETER P-CANCEL          AS LOGICAL    NO-UNDO.
END.

The meaning of the parameters is as follows.

Parameter Description
P-PDISP Not used in the current implementation.
P-URL The url of the new page to be loaded.
P-FLAGS Not used in the current implementation.
P-TARGETFRAMENAME Not used in the current implementation.
P-POSTDATA Not used in the current implementation.
P-HEADERS Not used in the current implementation.
P-CANCEL Set to TRUE if the navigation request is to be canceled.

Attributes

Attribute Name Type Read Only Default Description
CONTEXT-PATH character no unknown Optional. Must be set in order to allow serving HTML pages from local file system. This sets the context path for all the HTTP requests. When the HTTP request matches the context the requested resource will be resolved in the file system directory defined with RESOURCE-BASE. For more information see above.
RESOURCE-BASE character no unknown Optional. Must be set in order to allow serving HTML pages from local file system. This is the file system directory where HTML resources will be served from. For more information see above.

Methods

Method Name Return Type Parameters Description
OPEN-WEB-PAGE logical url:CHARACTER The url to navigate to. Opens a HTML page. Supported schemes are http, https and file. When file scheme is specified, the pages will be served from local file system (local to FWD client process). Returns true if the page opens successfully, false otherwise.
PRINT void none Prints the opened html page.

OCX Conversion

FWD is capable to convert OCX HTML controls with a compatible API, the following methods are supported: openWebPage, navigate2 and print.

To enable the conversion create the file <procedurefile.p>.ext-hints with the following structure. Put the file in the same directory as the procedure file <procedurefile.p>.

<extension>
   <ocx control-frame="CtrlFrame" control-frame-handle="chCtrlFrame" com-handle="chCtrlFrame:html" target-widget="html-browser" target-handle="hHtml"/>
</extension>

The xml element ocx defines the control frame (control-frame) hosting the tree control, the control handle of the control frame (control-frame-handle), com handle of the object being converted (com-handle), target widget type (target-widget) and the target tree handle for the converted tree widget (target-handle).

To give an example, the following code sample will convert with the xml configuration given above.

define variable CtrlFrame as widget-handle no-undo.
define variable chCtrlFrame as component-handle no-undo.

procedure control_load :
define variable UIB_S    as logical    no-undo.
define variable OCXFile  as character  no-undo.

OCXFile = search( "html.wrx":U ).
  assign
    chCtrlFrame = CtrlFrame:com-handle
    UIB_S = chCtrlFrame:LoadControls( OCXFile, "html":U)
  .
end procedure.

run control_load.
chCtrlFrame:html:navigate2 (...).

procedure CtrlFrame.html.BeforeNavigate2.
   ...
end procedure.

© 2018 Golden Code Development Corporation. ALL RIGHTS RESERVED.