LibreOffice logo
BASEDOCUMENTER
The software tool for documenting your LibreOffice Base applications
 
Database file/home/jean-pierre/Documents/BaseDocumenter/www/databases/LODoc/Example_Autotext_Searchmark_Spelling.odb
File actual save date2018-08-21 16:38:15
Scanning done on2018-08-21 16:57:13
Documentation generated on2018-08-21 16:57:24
Table of contents
Example_Autotext_Searchmark_Spelling
Procedures by module
Library Module name Procedure name Language Used by Number of code lines Procedure code
Standard Module1 Autotext Basic Autotext|MemoFormat (Control) 27
SUB Autotext(oEvent AS OBJECT)	'Properties: TextBox → Events → Text modified
DIM arText()
DIM stText AS STRING
DIM oSelection AS NEW com.sun.star.awt.Selection
DIM oField AS OBJECT
DIM oAutotexts AS OBJECT
DIM oRange AS OBJECT
DIM oCursor AS OBJECT
oField = oEvent.Source
IF oField.text <> "" THEN
arText = Split(oField.text)
stText = arText(Ubound(arText))
oAutotexts = createunoservice("com.sun.star.text.AutoTextContainer")
oRange = oAutotexts.getByName("standard") 'template, standard, crdbus50, mytexts - Autotext will be started in Writer by shortcut and F3.
IF oRange.hasByName(stText) THEN
oAutotext = oRange.getByName(stText) 'Example: DMS is the shortcut for "Dear Madam or Sir" (Writer → Edit → AutoText)
oCursor = oField.Model.createTextCursor()
oCursor.gotoEnd(true)
oCursor.goLeft(len(stText),true)
oField.Model.insertString(oCursor,oAutotext.String,true)
oSelection.Min = len(oField.Text)
oSelection.Max = len(oField.Text)
oField.setFocus
oField.Selection = oSelection
END IF
END IF
END SUB
Standard Module1 ContentRead Basic Search_mark (Form) 41
Sub ContentRead(oEvent AS OBJECT)	'Form Properties → Events → After record change
DIM inMemo AS INTEGER
DIM oField AS OBJECT
DIM stSearchtext AS STRING
DIM oCursor AS OBJECT
DIM inSearch AS INTEGER
DIM inSearchOld AS INTEGER
DIM inLen AS INTEGER
oForm = oEvent.Source
inMemo = oForm.findColumn("memo")
oField = oForm.getByName("MemoFormat")
oField.Text = oForm.getString(inMemo)
' Marking
Wait 5
stSearchtext = oForm.Parent.getByname("FormFilter").getByName("Search").Text
oCursor = oField.createTextCursor()
oCursor.gotoStart(true)
oCursor.gotoEnd(true)
oCursor.CharHeight = 10
oCursor.CharFontName = "Arial, Helvetica, Tahoma"
oCursor.CharColor = RGB(0,0,0)
oCursor.CharWeight = 100.000000 'com::sun::star::awt::FontWeight
oCursor.gotoStart(false)
IF oField.Text <> "" AND stSearchtext <> "" THEN
IF inStr(oField.Text, stSearchtext) THEN
inSearch = 1
inSearchOld = 0
inLen = Len(stSearchtext)
DO WHILE inStr(inSearch, oField.Text, stSearchtext) > 0
inSearch = inStr(inSearch, oField.Text, stSearchtext) - 1
oCursor.goRight(inSearch-inSearchOld,false)
oCursor.goRight(inLen,true)
oCursor.CharColor = RGB(102,102,255)
oCursor.CharWeight = 110.000000
oCursor.goLeft(inLen,false)
inSearchOld = inSearch
inSearch = inSearch + 2
LOOP
END IF
END IF
End Sub
Standard Module1 ContentReadWithoutSearch Basic Spelling_afterwards (Form)
Spelling_directly (Form)
20
Sub ContentReadWithoutSearch(oEvent AS OBJECT)	'Form Properties → Events → After record change
DIM inMemo AS INTEGER
DIM oField AS OBJECT
DIM stSearchtext AS STRING
DIM oCursor AS OBJECT
oForm = oEvent.Source
inMemo = oForm.findColumn("memo")
oField = oForm.getByName("MemoFormat")
oField.Text = oForm.getString(inMemo)
' Markieren
Wait 5
oCursor = oField.createTextCursor()
oCursor.gotoStart(true)
oCursor.gotoEnd(true)
oCursor.CharHeight = 10
oCursor.CharFontName = "Arial, Helvetica, Tahoma"
oCursor.CharColor = RGB(0,0,0)
oCursor.CharWeight = 100.000000 'com::sun::star::awt::FontWeight
oCursor.gotoStart(false)
End Sub
Standard Module1 ContentWrite Basic Search_mark (Form)
Spelling_afterwards (Form)
Spelling_directly (Form)
22
Sub ContentWrite(oEvent AS OBJECT)	'Form Properties → Events → Before record change
DIM oForm AS OBJECT
DIM inMemo AS INTEGER
DIM loID AS LONG
DIM oField AS OBJECT
DIM stMemo AS STRING
oForm = oEvent.Source
IF InStr(oForm.ImplementationName, "ODatabaseForm") THEN 'Event has two implementations, only ODatabaseForm works right here
IF NOT oForm.isBeforeFirst() AND NOT oForm.isAfterLast() THEN 'At the begin, also wen reloading form, cursor is positioned before the first row (Invalid cursorstatus)
inMemo = oForm.findColumn("memo")
loID = oForm.findColumn("ID")
oField = oForm.getByName("MemoFormat")
stMemo = oField.Text
IF stMemo <> "" THEN
oForm.updateString(inMemo,stMemo)
END IF
IF stMemo <> "" AND oForm.getString(loID) <> "" THEN
oForm.UpdateRow()
END IF
END IF
END IF
End Sub
Standard Module1 MarkWrongWordsDirect Basic Spelling_directly|MemoFormat (Control) 47
SUB MarkWrongWordsDirect(oEvent AS OBJECT)	'Properties: TextBox → Events → Key released
' Space or Return starts searching through the whole written text.
GlobalScope.BasicLibraries.LoadLibrary("Tools") 'Function RTrimStr, LTrimChar is needed for deleting punctuation characters
DIM aProp() AS NEW com.sun.star.beans.PropertyValue
DIM oLinuSvcMgr AS OBJECT
DIM oSpellChk AS OBJECT
DIM oField AS OBJECT
DIM arText()
DIM stWord AS STRING
DIM inlenWord AS INTEGER
DIM ink AS INTEGER
DIM i AS INTEGER
DIM oCursor AS OBJECT
DIM stText AS STRING
oLinguSvcMgr = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
IF NOT IsNull(oLinguSvcMgr) THEN
oSpellChk = oLinguSvcMgr.getSpellChecker()
END IF
oField = oEvent.Source.Model
ink = 0
IF oEvent.KeyCode = 1280 OR oEvent.KeyCode = 1284 THEN 'KeyCode für Return und Leertaste
stText = Join(Split(oField.Text,CHR(10))," ")
stText = Join(Split(stText,CHR(13))," ")
arText = Split(RTrim(stText)," ")
FOR i = LBound(arText) TO UBound(arText)
stWord = arText(i)
inlenWord = len(stWord)
stWord = Trim(RTrimStr(RTrimStr(RTrimStr(RTrimStr(RTrimStr(RTrimStr(stWord,","),"."),"?"),"!"),"."),")")) 'Delete comma or other punctuation characters at the end
stWord = LTrimChar(stWord,"(")
IF stWord <> "" THEN
oCursor = oField.createTextCursor()
oCursor.gotoStart(false)
oCursor.goRight(ink,false)
oCursor.goRight(inLenWord,true)
IF NOT oSpellChk.isValid(stWord, "en", aProp()) THEN
' isValid( [in] string aWord, [in] com::sun::star::lang::Locale aLocale, [in] com::sun::star::beans::PropertyValues aProperties )
oCursor.CharUnderline = 9
oCursor.CharUnderlineHasColor = True
oCursor.CharUnderlineColor = RGB(255,51,51)
ELSE
oCursor.CharUnderline = 0
END IF
END IF
ink = ink + inLenWord + 1
NEXT
END IF
END SUB
Standard Module1 MarkWrongWordsWaveLine Basic Spelling_afterwards|MemoFormat (Control) 37
SUB MarkWrongWordsWaveLine(oEvent AS OBJECT)	'Properties: TextBox → Events → Text modified
' Event will be triggered by loosing focus of the textbox - click on background of the form
' Event doesn't trigger directly, because input in a field without connection to the database is ignored.
' The whole text will be written new.
' Punctuation characters will show the words as wrong - for solution see procedure MarkWrongWordsDirect
DIM aProp() AS NEW com.sun.star.beans.PropertyValue
DIM n AS INTEGER
DIM oField AS OBJECT
DIM oCursor AS OBJECT
DIM aText()
DIM oLinguSvcMgr AS OBJECT
DIM oSpellChk AS OBJECT
DIM i AS INTEGER
oField = oEvent.Source
oCursor = oField.Model.createTextCursor()
IF oField.text <> "" THEN
aText = Split(oField.text)
oLinguSvcMgr = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
IF NOT IsNull(oLinguSvcMgr) THEN
oSpellChk = oLinguSvcMgr.getSpellChecker()
END IF
FOR i = LBound(aText) TO UBound(aText)
oCursor.gotoEnd(true)
IF NOT oSpellChk.isValid(aText(i), "en", aProp()) THEN
oCursor.CharUnderline = 9
oCursor.CharUnderlineHasColor = True
oCursor.CharUnderlineColor = RGB(255,51,51)
END IF
oField.Model.insertString(oCursor,aText(i),true)
IF i < UBound(aText) THEN
oCursor.gotoEnd(true)
oCursor.CharUnderline = 0
oField.Model.insertString(oCursor," ",true)
END IF
NEXT
END IF
END SUB