BBjHtmlEdit::getText

Description

In BBj 16.0 and higher, this method returns the HTML content of a BBjHtmlEdit control.

Syntax

Return Value

Method

string

getText()

Parameters

None.

Return Value

Returns the underlying HTML content (i.e. text + HTML tags) of a BBjHtmlEdit control.

Remarks

To return only plain text without HTML tags, use getPlainText.

Example

rem ' BBjHtmlEdit::getText
basic = 0
minimized = 0
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,800,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$
if minimized then flags$ = ior(flags$,$0002$)
if basic then flags$ = ior(flags$,$0004$)
text$ = "<html><head><title>BASIS</title></head><body>"
img$ = "http://www.basis.com/sites/basis.com/files/images/BusJGBetter.jpg"
text$ = text$ + "<img src="""+img$+""">"
url$ = "http://documentation.basis.com/BASISHelp/WebHelp/gridctrl2/bbjhtmledit.htm"
text$ = text$ + "<p>This is a <a href="""+url$+""">BBjHtmlEdit</a>."
text$ = text$ + "</body></html>"
htmledit! = window!.addHtmlEdit(100,25,75,750,400,"",flags$)
htmledit!.setText(text$)
htmledit!.setCallback(htmledit!.ON_PAGE_LOADED,"page")
clientfilesystem! = null()
clientfilesystem! = bbjapi().getThinClient(err=*next).getClientFileSystem(err=*next)
flags$ = iff(clientfilesystem!=null(),$0001$,$0000$)
clientfile! = window!.addButton(101,25,25,145,25,"Open Client File",flags$)
clientfile!.setCallback(clientfile!.ON_BUTTON_PUSH,"clientfile")
serverfile! = window!.addButton(102,175,25,145,25,"Open Server File",$$)
serverfile!.setCallback(serverfile!.ON_BUTTON_PUSH,"serverfile")
getText! = window!.addButton(103,325,25,145,25,"getText (HTML)",$$)
getText!.setCallback(getText!.ON_BUTTON_PUSH,"getText")
getPlainText! = window!.addButton(104,475,25,145,25,"getPlainText",$$)
getPlainText!.setCallback(getPlainText!.ON_BUTTON_PUSH,"getPlainText")
window!.setVisible(1)
process_events
eoj:
release
page:
  gosub event
  rem print event!.getControl().getText()
  rem print event!.getControl().getPlainText()
return
resize:
  gosub event
  width = event!.getWidth()
  height = event!.getHeight()
  htmledit!.setSize(width-50,height-100)
return
event:
  event! = sysgui!.getLastEvent()
  event$ = event!.toString()
  event$ = event$(1,pos("@"=event$,-1)-1)
  print event$," ",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
getText:
  text$ = htmledit!.getText()
  title$ = "BBjHtmlEdit::getText"
  gosub showText
return
getPlainText:
  text$ = htmledit!.getPlainText()
  title$ = "BBjHtmlEdit::getPlainText"
  gosub showText
return
showText:
  showText = sysgui!.getAvailableContext()
  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

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

BBjHtmlEdit::getPlainText

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



______________________________________________________________________________________

Copyright BASIS International Ltd. BBj®, Visual PRO/5®, PRO/5®, and BBx® are registered trademarks.