1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Autotext" script:
language=
"StarBasic">Option Explicit
5 Public UserfieldDataType(
14) as String
6 Public oDocAuto as Object
7 Public BulletList(
7) as Integer
8 Public sTextFieldNotDefined as String
9 Public sGeneralError as String
15 Dim oSearchDesc as Object
16 Dim oFoundall as Object
19 Dim sFoundString as String
20 Dim sFoundContent as String
21 Dim FieldStringThere as String
22 Dim ULStringThere as String
23 Dim PHStringThere as String
24 On Local Error Goto GENERALERROR
25 ' Initialization...
26 BasicLibraries.LoadLibrary(
"Tools
")
27 If InitResources(
"'Template
'",
"tpl
") Then
28 sGeneralError = GetResText(
1302)
29 sTextFieldNotDefined = GetResText(
1400)
32 UserfieldDatatype(
0) =
"COMPANY
"
33 UserfieldDatatype(
1) =
"FIRSTNAME
"
34 UserfieldDatatype(
2) =
"NAME
"
35 UserfieldDatatype(
3) =
"SHORTCUT
"
36 UserfieldDatatype(
4) =
"STREET
"
37 UserfieldDatatype(
5) =
"COUNTRY
"
38 UserfieldDatatype(
6) =
"ZIP
"
39 UserfieldDatatype(
7) =
"CITY
"
40 UserfieldDatatype(
8) =
"TITLE
"
41 UserfieldDatatype(
9) =
"POSITION
"
42 UserfieldDatatype(
10) =
"PHONE_PRIVATE
"
43 UserfieldDatatype(
11) =
"PHONE_COMPANY
"
44 UserfieldDatatype(
12) =
"FAX
"
45 UserfieldDatatype(
13) =
"EMAIL
"
46 UserfieldDatatype(
14) =
"STATE
"
56 oDocAuto = ThisComponent
57 oStyles = oDocAuto.Stylefamilies.GetByName(
"NumberingStyles
")
59 ' Prepare the Search-Descriptor
60 oSearchDesc = oDocAuto.createsearchDescriptor()
61 oSearchDesc.SearchRegularExpression = True
62 oSearchDesc.SearchWords = True
63 oSearchDesc.SearchString =
"<[^
>]+
>"
64 oFoundall = oDocAuto.FindAll(oSearchDesc)
66 'Loop over the foundings
67 For i =
0 To oFoundAll.Count -
1
68 oFound = oFoundAll.GetByIndex(i)
69 sFoundString = oFound.String
70 'Extract the string inside the brackets
71 sFoundContent = FindPartString(sFoundString,
"<",
">",
1)
72 sFoundContent = LTrim(sFoundContent)
74 ' Define the Cursor and place it on the founding
75 oCursor = oFound.Text.CreateTextCursorbyRange(oFound)
77 ' Find out, which object is to be created...
78 FieldStringThere = Instr(
1,sFoundContent,
"Field
")
79 ULStringThere = Instr(
1,sFoundContent,
"UL
")
80 PHStringThere = Instr(
1,sFoundContent,
"Placeholder
")
81 If FieldStringThere =
1 Then
82 CreateUserDatafield(oCursor, sFoundContent)
83 ElseIf ULStringThere =
1 Then
84 CreateBullet(oCursor, oStyles)
85 ElseIf PHStringThere =
1 Then
86 CreatePlaceholder(oCursor, sFoundContent)
91 If Err
<> 0 Then
92 Msgbox(sGeneralError,
16, GetProductName())
99 ' creates a User - datafield out of a string with the following structure
100 ' "<field:Company
>"
101 Sub CreateUserDatafield(oCursor, sFoundContent as String)
102 Dim MaxIndex as Integer
104 Dim oUserfield as Object
105 Dim UserInfo as String
106 Dim UserIndex as Integer
108 oUserfield = oDocAuto.CreateInstance(
"com.sun.star.text.TextField.ExtendedUser
")
109 sFoundList() = ArrayoutofString(sFoundContent,
":
",MaxIndex)
110 UserInfo = UCase(LTrim(sFoundList(
1)))
111 UserIndex = IndexinArray(UserInfo, UserfieldDatatype())
112 If UserIndex
<> -
1 Then
113 oUserField.UserDatatype = UserIndex
114 oCursor.Text.InsertTextContent(oCursor,oUserField,True)
115 oUserField.IsFixed = True
117 Msgbox(UserInfo
&":
" & sTextFieldNotDefined,
16, GetProductName())
122 ' Creates a Bullet by setting a soft Formatation on the first unsorted List-Templates with a defined
124 Sub CreateBullet(oCursor, oStyles as Object)
125 Dim n, m, s as Integer
126 Dim StyleSet as Boolean
128 Dim StyleName as String
131 For s =
0 To Ubound(BulletList())
132 For n =
0 To oStyles.Count -
1
133 ostyle = oStyles.getbyindex(n)
134 StyleName = oStyle.Name
135 alevel() = ostyle.NumberingRules.getbyindex(
0)
136 ' The properties of the style are stored in a Name-Value-Array()
137 For m =
0 to Ubound(alevel())
138 ' Set the first Numbering template without a bulletID
139 If (aLevel(m).Name =
"BulletId
") Then
140 If alevel(m).Value = BulletList(s) Then
141 oCursor.NumberingStyle = StyleName
142 oCursor.SetString(
"")
150 ' The Template with the demanded BulletID is not available, so take the first style in the sequence
151 ' that has a defined Bullet ID
152 oCursor.NumberingStyleName = oStyles.GetByIndex(
5).Name
153 oCursor.SetString(
"")
158 ' Creates a placeholder out of a string with the following structure:
159 '<placeholder:Showtext:Helptext
>
160 Sub CreatePlaceholder(oCursor as Object, sFoundContent as String)
161 Dim oPlaceholder as Object
162 Dim MaxIndex as Integer
164 oPlaceholder = oDocAuto.CreateInstance(
"com.sun.star.text.TextField.JumpEdit
")
165 sFoundList() = ArrayoutofString(sFoundContent,
":
" & chr(
34),MaxIndex)
166 ' Delete The Double-quotes
167 oPlaceholder.Hint = DeleteStr(sFoundList(
2),chr(
34))
168 oPlaceholder.placeholder = DeleteStr(sFoundList(
1),chr(
34))
169 oCursor.Text.InsertTextContent(oCursor,oPlaceholder,True)