Below is an example using the richEdit object and linking it to a text or pdf file and includes many format and search options.
NOTE: you will find this in the 'Samples' folder as well.
** END HEADER -- do not remove this line
//
// Generated on 04/24/2018
//
parameter bModal
local f
f = new richEdit_docSampleForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class richEdit_docSampleForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
height = 27.5455
left = 7.5714
top = 0.1818
width = 151.2857
text = "RTF Doc Editor"
endwith
this.LINE1 = new LINE(this)
with (this.LINE1)
left = 0.0
right = 200.0
top = 1.3182
bottom = 1.3182
width = 1
endwith
this.SETPARANUMBEREDLIST = new CHECKBOX(this)
with (this.SETPARANUMBEREDLIST)
onChange = class::SETPARANUMBEREDLIST_ONCHANGE
height = 1.0909
left = 68.5714
top = 3.0
width = 28.0
text = "Set Paragraph Numbered List"
endwith
this.TEXTLABEL1 = new TEXTLABEL(this)
with (this.TEXTLABEL1)
height = 1.0
left = 0.8571
top = 3.0909
width = 21.2857
text = "Set Paragraph Alignment:"
endwith
this.SETPARABULLETEDLIST = new CHECKBOX(this)
with (this.SETPARABULLETEDLIST)
onChange = class::SETPARABULLETEDLIST_ONCHANGE
height = 1.0909
left = 40.1429
top = 2.9545
width = 26.7143
text = "Set Paragraph Bulleted List"
endwith
this.COMBOBOX1 = new COMBOBOX(this)
with (this.COMBOBOX1)
onChange = class::COMBOBOX1_ONCHANGE
height = 1.0
left = 22.5714
top = 2.9545
width = 16.4286
dataSource = 'array {"1 - Left","2 - Right","3 - Centered","4 - Justified"}'
style = 1 // DropDown
selectAll = false
endwith
this.GETPARAALIGNMENT = new CHECKBOX(this)
with (this.GETPARAALIGNMENT)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 131.1429
top = 4.2727
width = 18.2857
text = "getParaAlignment"
endwith
this.GETPARANUMBEREDLIST = new CHECKBOX(this)
with (this.GETPARANUMBEREDLIST)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 89.8571
top = 4.2727
width = 22.0
text = "getParaNumberedList"
endwith
this.GETPARABULLETEDLIST = new CHECKBOX(this)
with (this.GETPARABULLETEDLIST)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 111.4286
top = 4.2727
width = 19.2857
text = "getParaBulletedList"
endwith
this.GETSELHEIGHT = new CHECKBOX(this)
with (this.GETSELHEIGHT)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 57.4286
top = 4.2727
width = 16.0
text = "getSelHeight"
endwith
this.GETSELFONTNAME = new CHECKBOX(this)
with (this.GETSELFONTNAME)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 71.8571
top = 4.2727
width = 17.5714
text = "getSelFontName"
endwith
this.GETSELCOLOR = new CHECKBOX(this)
with (this.GETSELCOLOR)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 43.4286
top = 4.2727
width = 13.0
text = "getSelColor"
endwith
this.GETSELITALIC = new CHECKBOX(this)
with (this.GETSELITALIC)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 13.7143
top = 4.2727
width = 13.0
text = "getSelItalic"
endwith
this.GETSELSTRIKEOUT = new CHECKBOX(this)
with (this.GETSELSTRIKEOUT)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 26.4286
top = 4.2727
width = 16.0
text = "getSelStrikeout"
endwith
this.GETSELBOLD = new CHECKBOX(this)
with (this.GETSELBOLD)
onChange = class::GETPROPERTY_ONCHANGE
height = 1.0909
left = 0.7143
top = 4.2727
width = 12.0
text = "getSelBold"
endwith
this.PBSETSELFONT = new PUSHBUTTON(this)
with (this.PBSETSELFONT)
onClick = class::PBSETSELFONT_ONCLICK
height = 1.0
left = 60.7143
top = 1.6364
width = 24.0
text = "Set Selection Font"
borderStyle = 1 // Raised
endwith
this.PBSETSELHEIGHT = new PUSHBUTTON(this)
with (this.PBSETSELHEIGHT)
onClick = class::PBSETSELHEIGHT_ONCLICK
height = 1.0909
left = 85.7143
top = 1.6364
width = 20.0
text = "Set Selection Height"
borderStyle = 1 // Raised
endwith
this.PBCOLOR = new PUSHBUTTON(this)
with (this.PBCOLOR)
onClick = class::PBCOLOR_ONCLICK
height = 1.0909
left = 40.7143
top = 1.6364
width = 19.0
text = "Set Selection Color"
borderStyle = 1 // Raised
endwith
this.CBBOLD = new CHECKBOX(this)
with (this.CBBOLD)
onChange = class::CBBOLD_ONCHANGE
height = 1.0909
left = 0.7143
top = 1.6818
width = 19.0
text = "Set Selection Bold"
endwith
this.CBITALIC = new CHECKBOX(this)
with (this.CBITALIC)
onChange = class::CBITALIC_ONCHANGE
height = 1.0909
left = 20.7143
top = 1.6818
width = 20.0
text = "Set Selection Italic"
endwith
this.SELHEIGHT = new SPINBOX(this)
with (this.SELHEIGHT)
height = 1.0
left = 105.7143
top = 1.6818
width = 13.0
rangeMax = 100
rangeMin = 1
value = 1
borderStyle = 1 // Raised
endwith
this.RICHEDIT1 = new RICHEDIT(this)
with (this.RICHEDIT1)
onOpen = class::RICHEDIT1_ONOPEN
onLeftMouseUp = class::RICHEDIT1_ONLEFTMOUSEUP
height = 21.9091
left = 0.0
top = 5.5455
width = 151.0
textType = 1 // Plain Text
border = false
borderStyle = 3 // None
anchor = 1 // Bottom
endwith
this.EFSEARCH = new ENTRYFIELD(this)
with (this.EFSEARCH)
height = 1.0
left = 13.5714
top = 0.1818
width = 19.0
value = ""
endwith
this.PBSEARCH = new PUSHBUTTON(this)
with (this.PBSEARCH)
onClick = class::PBSEARCH_ONCLICK
height = 1.0909
left = 0.5714
top = 0.1364
width = 13.0
text = "Search Text:"
borderStyle = 1 // Raised
endwith
this.COPY = new PUSHBUTTON(this)
with (this.COPY)
onClick = class::COPY_ONCLICK
height = 1.0909
left = 35.5714
top = 0.1364
width = 8.0
text = "Copy"
borderStyle = 1 // Raised
pageno = 0
endwith
this.CUT = new PUSHBUTTON(this)
with (this.CUT)
onClick = class::CUT_ONCLICK
height = 1.0909
left = 43.1429
top = 0.1364
width = 8.0
text = "Cut"
borderStyle = 1 // Raised
pageno = 0
endwith
this.PASTE = new PUSHBUTTON(this)
with (this.PASTE)
onClick = class::PASTE_ONCLICK
height = 1.0909
left = 50.7143
top = 0.1364
width = 8.0
text = "Paste"
borderStyle = 1 // Raised
pageno = 0
endwith
this.SAVE = new PUSHBUTTON(this)
with (this.SAVE)
onClick = class::SAVE_ONCLICK
height = 1.0909
left = 73.4286
top = 0.1364
width = 8.0
text = "&SAVE"
borderStyle = 1 // Raised
pageno = 0
endwith
this.GETLINECOUNT = new PUSHBUTTON(this)
with (this.GETLINECOUNT)
onClick = class::GETLINECOUNT_ONCLICK
height = 1.0909
left = 98.5714
top = 0.1364
width = 15.2857
text = "GetLineCount"
borderStyle = 1 // Raised
pageno = 0
endwith
this.PBSCROLL = new PUSHBUTTON(this)
with (this.PBSCROLL)
onClick = class::PBSCROLL_ONCLICK
height = 1.0909
left = 115.5714
top = 0.1364
width = 6.7143
text = "Scroll: "
borderStyle = 1 // Raised
endwith
this.PBGETLENGTH = new PUSHBUTTON(this)
with (this.PBGETLENGTH)
onClick = class::PBGETLENGTH_ONCLICK
height = 1.0909
left = 83.5714
top = 0.1364
width = 15.2857
text = "GetTextLength"
borderStyle = 1 // Raised
endwith
this.PBUNDO = new PUSHBUTTON(this)
with (this.PBUNDO)
onClick = class::PBUNDO_ONCLICK
height = 1.0909
left = 58.2857
top = 0.1364
width = 8.0
text = "&UNDO"
borderStyle = 1 // Raised
endwith
this.PBREDO = new PUSHBUTTON(this)
with (this.PBREDO)
onClick = class::PBREDO_ONCLICK
height = 1.0909
left = 65.8571
top = 0.1364
width = 8.0
text = "&REDO"
borderStyle = 1 // Raised
endwith
this.EFSCROLL = new ENTRYFIELD(this)
with (this.EFSCROLL)
height = 1.0
left = 122.1429
top = 0.1818
width = 7.0
function = "J"
value = "15"
endwith
this.NEWFILE = new PUSHBUTTON(this)
with (this.NEWFILE)
onClick = class::NEWFILE_ONCLICK
height = 1.0909
left = 131.5714
top = 0.1364
width = 15.2857
text = "Get New File"
borderStyle = 1 // Raised
endwith
function CBBOLD_onChange()
form.richedit1.setSelBold(this.value)
return
function CBITALIC_onChange()
form.richedit1.setSelItalic(this.value)
return
function COMBOBOX1_onChange()
form.richedit1.setParaAlignment(VAL(LEFT(this.value,1)))
return
function COPY_onClick()
form.richEdit1.copy()
return
function CUT_onClick()
form.richEdit1.cut()
return
function GETLINECOUNT_onClick()
nLineCount = form.richEdit1.getLineCount()
Msgbox("Line Count = "+nLineCount)
return
function NEWFILE_onClick()
form.richedit1.onOpen()
return
function PASTE_onClick()
form.richEdit1.paste()
return
function PBCOLOR_onClick()
form.richedit1.setSelColor(form.getHexColor())
return
function PBGETLENGTH_onClick()
nLength = form.richEdit1.getTextLength()
MsgBox("Text Length = "+nLength)
return
function PBREDO_onClick()
form.richedit1.redo()
return
function PBSCROLL_onClick()
nScroll = val(form.efScroll.value)
form.richEdit1.scroll(nScroll,0)
return
function PBSEARCH_onClick()
nFound = form.richEdit1.findText(form.efsearch.value,false,false,true)
if nFound < 0
MsgBox("Text not found")
else
nStart = 0
nEnd = 0
form.richedit1.getSel(nStart,nEnd)
if MsgBox("Found your text Do you want to continue your search?","Text Found!",4+48) == 6
wait //routine will not work without this..
KEYBOARD("{RIGHTARROW}")
form.richedit1.setSel(nEnd,nEnd)
this.onClick()
else
//form.richedit1.setSel(nEnd-1,nEnd)
endif
endif
return
function PBSETSELFONT_onClick()
cFont = GETFONT("Get Font",form.CurrentFont)
form.currentFont = cFont
form.richedit1.setSelFont(cFont)
return
function PBSETSELHEIGHT_onClick()
form.richedit1.setSelHeight(form.SelHeight.value)
return
function PBUNDO_onClick()
form.richEdit1.undo()
return
function RICHEDIT1_onLeftMouseUp(flags, col, row)
nPara = this.getParaAlignment()
do case
case nPara = 1
form.combobox1.value = "1 - Left"
case nPara = 2
form.combobox1.value = "2 - Right"
case nPara = 3
form.combobox1.value = "3 - Centered"
case nPara = 4
form.combobox1.value = "4 - justified"
endcase
form.setParaBulletedlist.value = this.getParaBulletedlist()
form.setParaNumberedlist.value = this.getParaNumberedList()
form.cbbold.value = this.getSelBold()
form.cbitalic.value = this.getSelItalic()
return
function RICHEDIT1_onOpen()
local isRtf
this.datalink = ""
if TYPE("form.ext") <> "U"
if form.ext = "txt"
f = getfile("*.txt;*.rtf","Choose file to open",true,"Rich Text Format (*.rtf);Text (*.txt)")
else if form.ext = "rtf"
f = getfile("*.txt;*.rtf","Choose file to open",true,"Text (*.txt);Rich Text Format (*.rtf)")
endif
else
f = getfile("*.txt;*.rtf","Choose file to open",true,"Rich Text Format (*.rtf);Text (*.txt)")
endif
if not empty(f)
this.datalink = null
form.ext = lower(substr(f,rat(".", f)+1))
isRtf = iif(form.ext == "rtf", true, false )
this.textType = iif(isRtf, 0, 1)
this.top = iif(isRtf,5.68,1.41)
this.datalink = 'FILENAME '+f
endif
return
function SAVE_onClick()
form.richEdit1.save()
return
/*
GetHexColor()
Posted by J°rgen Feder in the
Visual dBASE newsgroups, Jan 19, 2000
This routine can be used for those situations where
you need the Hexadecimal color values, rather than the
RGB returned by the GetColor() function built in to
Visual dBASE.
Usage: ? GetHexColor()
This brings up the getColor() dialog, and converts the
value to Hex, which you can then use for your forms,
entryfields, and other controls ...
*/
function GetHexColor
local cStr,Ix,Jx
cStr=GetColor()
if not empty(cStr)
ix=RAT(',',cStr)
jx=AT(',',cStr)
cStr='0x'+ITOH(val(substr(cStr,ix+1)),2)+;
ITOH(val(substr(cStr,jx+1,ix-jx)),2)+;
ITOH(val(substr(cStr,1,jx-1)),2)
endif
return cStr
function setParaBulletEDLIST_onChange()
form.richedit1.setParaBulletedList(this.value)
if this.value
form.setParaNumberedList.value = false
endif
return
function SETPARANUMBEREDLIST_onChange()
form.richedit1.setParaNumberedList(this.value)
if this.value
form.setParaBulletedList.value = false
endif
return
function form_onOpen()
this.CurrentFont = ""
return
function getProperty_onChange()
private cDoMethod
cDoMethod = ""
nStart = 0
nEnd = 0
form.richedit1.getSel(nStart,nEnd)
if this.value
cDoMethod = "form.richedit1."+this.name+"()"
cVal = &cDoMethod.
if EMPTY(cVal) and nStart==nEnd
cVal = "Make sure you highlight some text to get the right value"
else if EMPTY(cVal)
cVal = this.text+' = false'
endif
if cVal == null
cVal = "null"
endif
MsgBox(""+cVAl)
endif
this.value = false //reset the combobox so user does not have to
return
endclass