BBjHtmlEdit

Description

In BBj 16.0 and higher, the BBjHtmlEdit control implements a rich text editor backed by HTML.

Setting the STBL("!OPTIONS") JAVAFX_HTMLEDIT option to TRUE makes the BBjHtmlEdit control in the Java Swing GUI client use JavaFX (if available). In this configuration, the BBjHtmlEdit uses an embedded WebKit browser, with support for HTML5, CSS, and JavaScript.

In BBj 19.0 and higher, setting the STBL("!OPTIONS") CHROMIUM_HTMLEDIT option to TRUE makes the BBjHtmlEdit control in the Java Swing GUI client use a Chromium engine (if available). In this configuration, the BBjHtmlEdit uses an embedded Chromium-based web browser, with support for HTML5, CSS, and JavaScript.

BUI logoDWC logo

In BBj 23.00 and higher, the default editor component for the BUI and DWC browser clients is TinyMCE. Setting the STBL("!OPTIONS") CKEDITOR_HTMLEDIT option to TRUE makes the BBjHtmlEdit control in the BUI and DWC browser clients use the original CKEditor 4 editor component. This is a temporary convenience; CKEditor 4 is no longer supported as of June 2023.

In BBj 25.00 and higher, the editor component for the BUI and DWC browser clients is an internal BASIS editor with the same toolbar options as the GUI CHROMIUM_HTMLEDIT editor. In BBj 24.12 and higher, a preview of this internal editor component can be configured by setting the STBL("!OPTIONS") BASIS_HTMLEDIT option to TRUE. All third party editor components have been removed as of BBj 25.00.

Access to the CHROMIUM_HTMLEDIT feature requires an active Software Asset Management (SAM) subscription. See Benefits of ‘Software Asset Management' Feature Line.

Implemented Interfaces

Focusable, TabTraversable

Creation

BBjAPI > BBjSysGui > BBjWindow > BBjHtmlEdit

A BBjHtmlEdit object is created through the following BBjWindow methods:

Return Value

Method

BBjHtmlEdit

addHtmlEdit(int ID, number x, number y, number width, number height, string html)

BBjHtmlEdit

addHtmlEdit(int ID, number x, number y, number width, number height, string html, string flags)

Methods of BBjHtmlEdit

Return Value

Method

BBjVector

getAllToolbarStyles()

BBjVector getAvailableSpellCheckLanguages()
BBjVector getAvailableStates()

boolean

getBasicToolbar()

BBjVector

getBasicToolbarStyles()

string

getClientType()

string

getClientVersion()

string getLocale()
BBjVector getLocales()

string

getPlainText()

string getSpellCheckLanguage()
boolean getState(String state)

string

getText()

boolean isSpellChecked()

void

setBasicToolbar(boolean basicToolbar)

void

setBasicToolbarStyles(BBjVector styles)

void setLocale(string locale)

void

setPlainText(string text)

void setState(String state, Boolean value)
void setSpellChecked(boolean spellChecked)
void setSpellCheckLanguage(string language)

void

setText(string text)

Methods of BBjHtmlEdit implemented for Focusable

Return Value Method
boolean isFocusable()
void setFocusable(boolean focus)

Methods of BBjHtmlEdit implemented for TabTraversable

Return Value Method
boolean isTabTraversable()
void setTabTraversable(boolean trav)

Methods of BBjHtmlEdit inherited from BBjControl

Events

Callback Code

Object-oriented Event

Read Record Event

Code

ON_EDIT_MODIFY

BBjEditModifyEvent

Edit Control Modify Event

e

ON_GAINED_FOCUS

BBjGainedFocusEvent

Control Focus Gained/Lost Event

f

ON_LOST_FOCUS

BBjLostFocusEvent

Control Focus Gained/Lost Event

f

ON_MOUSE_ENTER

BBjMouseEnterEvent

Mouse Enter/Exit Event

E

ON_MOUSE_EXIT

BBjMouseExitEvent

Mouse Enter/Exit Event

E

ON_PAGE_LOADED

BBjPageLoadedEvent

Page Loaded Event

x

ON_POPUP_REQUEST

BBjPopupRequestEvent

Popup Request Event

r

ON_RIGHT_MOUSE_DOWN

BBjRightMouseDownEvent

Right Mouse Button Down Event

R

ON_STATE_CHANGE BBjStateChangeEvent State Change Event x

BUI logoCSS

The visual appearance of BUI controls is defined using CSS (cascading style sheets) rules. Easily change the default colors, border, and other settings by customizing these rules, all without changing any application code. See CSS API for a high-level overview of BUI CSS.

The BBjHtmlEdit control is a <div> containing an editor component consisting of a toolbar and an editing area. The BBjHtmlEdit defines the following CSS style names:

.BBjHtmlEdit (the top level control)

.BBjHtmlEdit.bbj-disabled (the control is disabled)

Most of the styling happens internally within the editor component; these CSS selectors can only apply minimal additional styling, and some rules may require the use of!importantto override internal editor rules.

Chromium BBjHtmlEdit

On supported platforms in the Java Swing GUI client, BBjHtmlEdit uses an embedded Chromium-based browser.

To change the type of browser used by the BBjHtmlEdit, use the STBL("!OPTIONS") JAVAFX_HTMLVIEW option and the STBL("!OPTIONS") CHROMIUM_HTMLEDIT option.

Access to the CHROMIUM_HTMLEDIT feature requires an active Software Asset Management (SAM) subscription. See Benefits of ‘Software Asset Management' Feature Line.

If the Chromium-based BBjHtmlEdit is used, the STBL("!CHROMIUM_DIR") string can specify a preferred client-side directory to extract the Chromium binaries. This can be particularly useful in a BBj environment that runs concurrent thin client sessions against multiple servers, where it may be necessary to specify a different Chromium directory for each server.

ClosedVersion History

Constants inherited from BBjControl

Example

rem ' BBjHtmlEdit
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
flags$ = $00190083$; rem ' for testing DWC flow layout
flags$ = $00090083$
window! = sysgui!.addWindow(25,25,900,500,"BBjHtmlEdit",flags$)
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$ = $0010$; rem ' initially invisible
flags$ = $0000$; rem ' initially visible
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/sites/basis.com/files/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$ + "<p>English color colour sample."
text$ = text$ + "<p>Das ist deutsch."
text$ = text$ + "<p>C'est du français."
text$ = text$ + "<p>Esto es español."
text$ = text$ + "</body></html>"
text = unt
open (text,err=oops)"htmledit.html"
readrecord (text,siz=999999)text$
close (unt)
oops:
font = iff(info(3,6)="5" or info(3,6)="6",11,8)
font! = sysgui!.makeFont("SansSerif",font,BBjFont.BOLD)
clientfilesystem! = null()
clientfilesystem! = bbjapi().getThinClient(err=*next).getClientFileSystem(err=*next)
f$ = iff(clientfilesystem!=null(),$0001$,$0000$)
clientfile! = window!.addButton(101,25,25,120,25,"Open Client File",f$)
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")
getHtml! = window!.addButton(107,775,25,120,25,"showHtml",$$)
getHtml!.setFont(font!)
getHtml!.setCallback(getHtml!.ON_BUTTON_PUSH,"getHtml")
setLocale! = window!.addListButton(108,25,50,120,425,"",$0000$)
setLocale!.setToolTipText("setLocale")
setLocale!.setCallback(setLocale!.ON_LIST_SELECT,"setLocale")
spellChecked! = window!.addCheckBox(109,150,50,120,25,"Spell Checked",$$)
spellChecked!.setToolTipText("setSpellChecked")
spellChecked!.setCallback(spellChecked!.ON_CHECK_ON,"spellCheckedOn")
spellChecked!.setCallback(spellChecked!.ON_CHECK_OFF,"spellCheckedOff")
setSpellCheckLanguage! = window!.addListButton(110,275,50,120,425,"",$0000$)
setSpellCheckLanguage!.setToolTipText("setSpellCheckLanguage")
setSpellCheckLanguage!.setCallback(setSpellCheckLanguage!.ON_LIST_SELECT,"setSpellCheckLanguage")
visible$ = iff(flags$=$0010$,$0000$,$0004$)
visible! = window!.addCheckBox(111,400,50,125,25,"setVisible",visible$)
visible!.setCallback(visible!.ON_CHECK_ON,"visible_on")
visible!.setCallback(visible!.ON_CHECK_OFF,"visible_off")
htmledit! = window!.addHtmlEdit(100,25,75,850,400,text$,flags$)
title$ = "BBjHtmlEdit " + htmledit!.getClientType() + " " + htmledit!.getClientVersion()
window!.setTitle(title$)
htmledit!.setCallback(htmledit!.ON_PAGE_LOADED,"page")
htmledit!.setCallback(htmledit!.ON_EDIT_MODIFY,"modify")
htmledit!.setCallback(htmledit!.ON_GAINED_FOCUS,"event")
htmledit!.setCallback(htmledit!.ON_LOST_FOCUS,"event")
htmledit!.setCallback(htmledit!.ON_MOUSE_ENTER,"event")
htmledit!.setCallback(htmledit!.ON_MOUSE_EXIT,"event")
htmledit!.setCallback(htmledit!.ON_POPUP_REQUEST,"event")
 htmledit!.setCallback(htmledit!.ON_RIGHT_MOUSE_DOWN,"event")
htmledit!.setCallback(htmledit!.ON_STATE_CHANGE,"state")
locales! = htmledit!.getLocales()
if locales!.size() = 0 then
   setLocale!.setText("en_US")
else
   setLocale!.insertItems(-1,locales!)
endif
locale$ = htmledit!.getLocale()
languages! = htmledit!.getAvailableSpellCheckLanguages()
if languages!.size() = 0 then
   setSpellCheckLanguage!.setText("en_US")
else
   setSpellCheckLanguage!.insertItems(-1,languages!)
endif

window!.setVisible(1)
showText = 0
showHtml = 0
print htmledit!.getCharset()

title$ = "BBjHtmlEdit " + htmledit!.getClientType() + " " + htmledit!.getClientVersion()
window!.setTitle(title$)

process_events

eoj:
  release

setLocale:
  event! = sysgui!.getLastEvent()
  locale$ = event!.getSelectedItem()
  htmledit!.setLocale(locale$)
  print "getLocale ",htmledit!.getLocale()
return

spellCheckedOn:
  htmledit!.setSpellChecked(1)
  print "isSpellChecked ",htmledit!.isSpellChecked()
return

spellCheckedOff:
  htmledit!.setSpellChecked(0)
  print "isSpellChecked ",htmledit!.isSpellChecked()
return

setSpellCheckLanguage:
  event! = sysgui!.getLastEvent()
  language$ = event!.getSelectedItem()
  htmledit!.setSpellCheckLanguage(language$)
  print "getSpellCheckLanguage ",htmledit!.getSpellCheckLanguage()
  print "getAvailableSpellCheckLanguages ",htmledit!.getAvailableSpellCheckLanguages()
return

page:
  gosub event
  print event!.getText()
  title$ = "BBjHtmlEdit " + htmledit!.getClientType() + " " + htmledit!.getClientVersion()
  window!.setTitle(title$)
return
resize:
  gosub event
  width = event!.getWidth() - 50
  height = event!.getHeight() - 100
  htmledit!.setSize(width,height)
  print width,height
return

state:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()+" "+event!.getState()+" "+Boolean.toString(event!.getValue())
  print event$
return

event:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  print event$
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
     html! = text$
     html$ = html!.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")
     html$ = fnhtml$(html$)
     htmledit!.setText(html$); rem ' text
     header$ = "<html><head><style>p{margin:0;padding:0;white-space:pre-wrap;}</style></head><body>"
     html$ = header$ + "<pre>" + text$ + "</pre></body></html>"
     htmledit!.setText(html$)
  else
     htmledit!.setText(text$); rem ' html
  endif
return

def fnhtml$(_text$)
    st! = new java.io.BufferedReader(new java.io.StringReader(_text$))
    header$ = "<html><head><style>p{margin:0;padding:0;white-space:pre-wrap;}</style></head><body>"
    buf! = new StringBuilder(header$)
    buf!.append("<p>")
    str! = st!.readLine()
    while (str! <> null())
        rem if (str!.length() = 0) str! = "<br>"
        rem buf!.append("<p>").append(str!).append("</p>").append($0a$)
        buf!.append(str!).append("<br>")
        str! = st!.readLine()
    wend
    buf!.append("</p>")
    buf!.append("</body></html>")
    return buf!.toString()
fnend

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,style=style")
  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
     html! = text$
     html$ = html!.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")
     html$ = fnhtml$(html$)
     htmledit!.setText(html$); rem ' text
     header$ = "<html><head><style>p{margin:0;padding:0;white-space:pre-wrap;}</style></head><body>"
     html$ = header$ + "<pre>" + text$ + "</pre></body></html>"
     htmledit!.setText(html$)
     htmledit!.setPlainText(text$); rem ' text
  else
     htmledit!.setText(text$); rem ' html
  endif
return

newHtml:
  new$ = "<html><head><style>body{font-family:Dialog;font-size:16px;font-style:normal;}p{margin:0;padding:0;white-space:pre-wrap;}</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:
  text$ = htmledit!.getPlainText()
  title$ = "BBjHtmlEdit::getPlainText"
  gosub showText
return

getHtml:
  text$ = htmledit!.getText()
  title$ = "BBjHtmlEdit::showHtml"
  gosub showHtml
return
getImage:
  image = unt
  format$ = "png"
  image! = htmledit!.getImage()
  if image!=null() then
     i = msgbox("BBjHtmlEdit::getImage() returned null()")
     return
  endif
  image$ = image!.getBytes(format$)
  path$ = System.getProperty("user.home")+"/Desktop/"
  open (image,mode="O_CREATE,O_TRUNC")path$+"htmledit.png"
  writerecord (image)image$
  close (image)
return

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

resizeShowText:
  event! = sysgui!.getLastEvent()
  cedit!.setSize(event!.getWidth(),event!.getHeight())
return

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

showHtml:
  if showHtml then gosub closeShowHtml
  showHtml = sysgui!.getAvailableContext()
  x = window!.getX() + 25
  y = window!.getY() + 25
  w = window!.getWidth() - 50
  h = window!.getHeight() - 50
  showHtml! = sysgui!.addWindow(showHtml,x,y,w,h,title$,$000b0083$)
  showHtml!.setCallback(showHtml!.ON_RESIZE,"resizeShowHtml")
  showHtml!.setCallback(showHtml!.ON_CLOSE,"closeShowHtml")
  showHtmlView! = showHtml!.addHtmlView(101,0,0,w,h,text$,$$)
return

resizeShowHtml:
  event! = sysgui!.getLastEvent()
  showHtmlView!.setSize(event!.getWidth(),event!.getHeight())
return

closeShowHtml:
  if showHtml!<>null() then showHtml!.destroy(err=*next); showHtml! = 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()
  info$ = event!.getEventName()+" "+event!.getText()
  print info$
return

visible_on:
  htmledit!.setVisible(1)
return

visible_off:
  htmledit!.setVisible(0)
return

See Also

BBjAPI

BBjSysGui

BBjWindow

CALLBACK Verb - Register BBj Subroutine

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