BBjWindow::addHtmlEdit

Description

In BBj 16.00 and higher, this method creates a BBjHtmlEdit control in the BBjWindow.

Syntax

Return Value

Method

BBjHtmlEdit

addHtmlEdit(int ID, number x, number y, number w, number h ,string html)

BBjHtmlEdit

addHtmlEdit(int ID, number x, number y, number w, number h, string html, string flags)

BBjHtmlEdit addHtmlEdit(int ID, number x, number y, number w, number h, string html, string flags, string chromium_switches$)
BBjHtmlEdit addHtmlEdit(int ID, string html)
BBjHtmlEdit addHtmlEdit(int ID, string html, string flags)
BBjHtmlEdit addHtmlEdit(int ID, string html, string flags, string chromium_switches$)
BBjHtmlEdit addHtmlEdit(string html)
BBjHtmlEdit addHtmlEdit(string html, string flags)
BBjHtmlEdit addHtmlEdit(string html, string flags, string chromium_switches$)

Parameters

Variable

Description

Variable

Description

ID

Control ID number. It must be an integer between 1 and 32767 and be unique within a given top-level window.

x

Horizontal position of the upper-left corner of the control in current units.

y

Vertical position of the upper-left corner of the control in current units.

width

Width of the control in current units.

height

Height of the control in current units.

html

Initial HTML value.

flags

Control flags, as follows:

Flag  Description
$0001$ Sets the control to be initially disabled.
$0002$ Sets the toolbar to be initially minimized (if supported by the client).
$0004$ Selects the basic toolbar (if supported by the client).
$0010$ Sets the control to be initially invisible.
$0800$ Draws a recessed client edge around the control.
$1000$ Draws a raised edge around the control.
chromium_switches$

In BBj 20.20 and higher, this optional string can specify an arbitrary number of space-delimited Chromium command-line switches (e.g. "--remote-debugging-port=9223 --lang=de"). These switches are only meaningful to the CHROMIUM_HTMLEDIT client. See STBL("!CHROMIUM_SWITCHES").

In BBj 22.13 and higher, the following BBj-specific switches can be specified in this string:

--bbj-save-password={save|never|ignore}

--bbj-update-password={update|ignore}

For more information, see: Passwords.

Return Value

This method returns the BBjHtmlEdit control.

Remarks

If the ID parameter is not specified, a control ID is assigned dynamically using getAvailableControlID().

If the x, y, width, and height parameters are not specified, they are all initialized to 0. This is typically for use with DWC windows that dynamically arrange their contents (window creation flag $00100000$).

If the initialization of a CHROMIUM_HTMLEDIT client fails, BBj logs the error, then tries again without any STBL("!CHROMIUM_DIR") and STBL("!CHROMIUM_SWITCHES") that might have been specified.

Example

rem ' BBjWindow::addHtmlEdit Example

rem ' BBjHtmlEdit
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,900,500,"BBjHtmlEdit",$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_RESIZE,"resize")

rem ' $0001$ = disabled, $0010$ = invisible
rem ' $0002$ = minimized toolbar, $0004$ = basic toolbar
flags$ = $0000$
basic = 0, minimized = 0
if minimized then flags$ = ior(flags$,$0002$)
if basic then flags$ = ior(flags$,$0004$)
text$ = "<html><head><style>p{margin:0;padding:0;}</style><title>BASIS</title></head><body>"
img$ = "https://www.basis.cloud/images/BusJGBetter.jpg"
text$ = text$ + "<img src="""+img$+""">"
url$ = "https://documentation.basis.cloud/BASISHelp/WebHelp/bbjobjects/Window/bbjhtmledit/BBjHtmlEdit.htm"
text$ = text$ + "<p>This is a <a href="""+url$+""">BBjHtmlEdit</a>."
text$ = text$ + "</body></html>"

rem 'goto oops
text = unt
open (text,err=oops)"htmledit.html"
readrecord (text,siz=999999)text$
close (unt)

oops:
client = 0
if (info(3,6)<>"5" and info(3,6)<>"6") then
    client = msgbox("BBjHtmlEdit Client",7+32+512,"BBjHtmlEdit","Swing","JavaFX","Chromium")
    switch client
        case 1; rem ' Swing
            print stbl("!OPTIONS","CHROMIUM_HTMLEDIT=FALSE",ERR=*NEXT)
            print stbl("!OPTIONS","JAVAFX_HTMLEDIT=FALSE",ERR=*NEXT)
            break
        case 2; rem ' JavaFX
            print stbl("!OPTIONS","CHROMIUM_HTMLEDIT=FALSE",ERR=*NEXT)
            print stbl("!OPTIONS","JAVAFX_HTMLEDIT=TRUE",ERR=*NEXT)
            break
        case 3; rem ' Chromium
            print stbl("!OPTIONS","CHROMIUM_HTMLEDIT=TRUE",ERR=*NEXT)
            print stbl("!OPTIONS","JAVAFX_HTMLEDIT=TRUE",ERR=*NEXT)
            break
    swend
endif
htmledit! = window!.addHtmlEdit(100,25,75,850,400,text$,flags$)
print "getClientType: ",htmledit!.getClientType(err=*next)
print "getClientVersion: ",htmledit!.getClientVersion(err=*next)
title$ = window!.getTitle() + " " + htmledit!.getClientType(err=*next) + " " + htmledit!.getClientVersion(err=*next)
window!.setTitle(title$)
htmledit!.setCallback(htmledit!.ON_PAGE_LOADED,"page")
htmledit!.setCallback(htmledit!.ON_EDIT_MODIFY,"modify")
font! = sysgui!.makeFont("Sans Serif",9,0)
clientfilesystem! = null()
clientfilesystem! = bbjapi().getThinClient(err=*next).getClientFileSystem(err=*next)
flags$ = iff(clientfilesystem!=null(),$0001$,$0000$)
clientfile! = window!.addButton(101,25,25,120,25,"Open Client File",flags$)
clientfile!.setFont(font!)
clientfile!.setCallback(clientfile!.ON_BUTTON_PUSH,"clientfile")
serverfile! = window!.addButton(102,150,25,120,25,"Open Server File",$$)
serverfile!.setFont(font!)
serverfile!.setCallback(serverfile!.ON_BUTTON_PUSH,"serverfile")
newHtml! = window!.addButton(103,275,25,120,25,"New HTML Doc",$$)
newHtml!.setFont(font!)
newHtml!.setCallback(newHtml!.ON_BUTTON_PUSH,"newHtml")
newText! = window!.addButton(104,400,25,120,25,"New Text Doc",$$)
newText!.setFont(font!)
newText!.setCallback(newText!.ON_BUTTON_PUSH,"newText")
getText! = window!.addButton(105,525,25,120,25,"getText (HTML)",$$)
getText!.setFont(font!)
getText!.setCallback(getText!.ON_BUTTON_PUSH,"getText")
getPlainText! = window!.addButton(106,650,25,120,25,"getPlainText",$$)
getPlainText!.setFont(font!)
getPlainText!.setCallback(getPlainText!.ON_BUTTON_PUSH,"getPlainText")
getImage! = window!.addButton(107,775,25,120,25,"getImage",$$)
getImage!.setFont(font!)
getImage!.setCallback(getImage!.ON_BUTTON_PUSH,"getImage")
window!.setVisible(1)
showText = sysgui!.getAvailableContext()
isDirty = 0
process_events

eoj:
release

page:
    gosub event
    if (isDirty) then
        text$ = htmledit!.getPlainText()
        title$ = "BBjHtmlEdit::getPlainText"
        isDirty = 0
        gosub showText
    else
        htmledit!.focus()
    endif
return

resize:
    gosub event
    width = event!.getWidth() - 50
    height = event!.getHeight() - 100
    htmledit!.setSize(width,height)
    print width,height
    wait 0
    htmledit!.focus()
return

event:
    event! = sysgui!.getLastEvent()
    print event!.getEventName()," ",event!.getControl()
return

clientfile:
    filter$ = "All Files (*.*)"+$0a$+"*.*"
    filter$ = filter$ + $0a$ + "HTML"+$0a$+"*.htm;*.html"
    filter$ = filter$ + $0a$ + "Text" + $0a$+"*.txt;*.src"
    clientfile$ = fileopen("Open Client File","","","",filter$,mode="client")
    if pos("::"=clientfile$) then return
    clientfile! = clientfilesystem!.getClientFile(clientfile$)
    serverfile$ = clientfile!.copyFromClient()
    serverfile = unt
    open (serverfile,err=*return)serverfile$
    bytes = dec(fin(serverfile)(1,4))
    text$ = ""
    if bytes then readrecord (serverfile,siz=bytes)text$
    close (serverfile)
    if (fnIsText(clientfile$,text$)) then
        htmledit!.setPlainText(text$); rem ' text
    else
        htmledit!.setText(text$); rem ' html
    endif
return

serverfile:
    filter$ = "All Files (*.*)"+$0a$+"*.*"
    filter$ = filter$ + $0a$ + "HTML"+$0a$+"*.htm;*.html"
    filter$ = filter$ + $0a$ + "Text" + $0a$+"*.txt;*.src"
    serverfile$ = fileopen("Open Server File","","","",filter$,mode="server")
    if pos("::"=serverfile$) then return
    serverfile = unt
    open (serverfile,err=*return)serverfile$
    bytes = dec(fin(serverfile)(1,4))
    text$ = ""
    if bytes then readrecord (serverfile,siz=bytes)text$
    close (serverfile)
    if (fnIsText(serverfile$,text$)) then
        htmledit!.setPlainText(text$); rem ' text
    else
        htmledit!.setText(text$); rem ' html
    endif
return

newHtml:
    new$ = "<html><head><style>p{margin:0;padding:0;}</style></head><body></body></html>"
    htmledit!.setText(new$)
return

newText:
    htmledit!.setPlainText(new String($000a00a0000a$,"UTF-16"))
return

getText:
    text$ = htmledit!.getText()
    title$ = "BBjHtmlEdit::getText"
    gosub showText
return

getPlainText:
    if isDirty then return
    isDirty = htmledit!.isDirty()
    if isDirty then return
    text$ = htmledit!.getPlainText()
    title$ = "BBjHtmlEdit::getPlainText"
    gosub showText
return

getImage:
    image = unt
    format$ = "png"
    image! = htmledit!.getImage()
    image$ = image!.getBytes(format$)
    path$ = System.getProperty("user.home")+"/Desktop/"
    open (image,mode="O_CREATE,O_TRUNC")path$+"html.png"
    writerecord (image)image$
    close (image)
return

showText:
    gosub closeShowText
    x = window!.getX() + 25
    y = window!.getY() + 25
    w = window!.getWidth()
    h = window!.getHeight()
    showText! = sysgui!.addWindow(showText,x,y,w,h,title$,$000b0003$)
    showText!.setCallback(showText!.ON_CLOSE,"closeShowText")
    cedit! = showText!.addCEdit(101,0,0,0,0,text$,$0182$)
return

closeShowText:
    if showText!<>null() then showText!.destroy(err=*next); showText! = null()
return

def fnIsText(_f$,_t$)
    rem ' treat this file (filename = _f$, contents = _t$) as plain text?
    rem ' this can be whatever combination of tests works for you.
    print "fnIsText ",_f$," (bytes=",str(len(_t$)),"): ",
    if pos("<html>"=cvs(_t$,8))=1 then print "<html> = html"; return 0
    _f$ = cvs(_f$,8); rem ' lowercase
    if pos(".html"=_f$,-1)=len(_f$)-4 then print ".html = html"; return 0
    if pos(".htm"=_f$,-1)=len(_f$)-3 then print ".htm = html"; return 0
    if pos(".txt"=_f$,-1)=len(_f$)-3 then print ".txt = text"; return 1
    if pos(".src"=_f$,-1)=len(_f$)-3 then print ".src = text"; return 1
    if pos(".properties"=_f$,-1)=len(_f$)-10 then print ".properties = text"; return 1
    print "default to text"; return 1; rem ' pick a default
fnend

modify:
    event! = sysgui!.getLastEvent()
    print event!.getEventName()," ",event!.getText()
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.