1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Autotext" script:
language=
"StarBasic">Option Explicit
22 Public UserfieldDataType(
14) as String
23 Public oDocAuto as Object
24 Public BulletList(
7) as Integer
25 Public sTextFieldNotDefined as String
26 Public sGeneralError as String
32 Dim oSearchDesc as Object
33 Dim oFoundall as Object
36 Dim sFoundString as String
37 Dim sFoundContent as String
38 Dim FieldStringThere as String
39 Dim ULStringThere as String
40 Dim PHStringThere as String
41 On Local Error Goto GENERALERROR
42 ' Initialization...
43 BasicLibraries.LoadLibrary(
"Tools
")
44 If InitResources(
"'Template
'") Then
45 sGeneralError = GetResText(
"CorrespondenceMsgError
")
46 sTextFieldNotDefined = GetResText(
"TextField
")
49 UserfieldDatatype(
0) =
"COMPANY
"
50 UserfieldDatatype(
1) =
"FIRSTNAME
"
51 UserfieldDatatype(
2) =
"NAME
"
52 UserfieldDatatype(
3) =
"SHORTCUT
"
53 UserfieldDatatype(
4) =
"STREET
"
54 UserfieldDatatype(
5) =
"COUNTRY
"
55 UserfieldDatatype(
6) =
"ZIP
"
56 UserfieldDatatype(
7) =
"CITY
"
57 UserfieldDatatype(
8) =
"TITLE
"
58 UserfieldDatatype(
9) =
"POSITION
"
59 UserfieldDatatype(
10) =
"PHONE_PRIVATE
"
60 UserfieldDatatype(
11) =
"PHONE_COMPANY
"
61 UserfieldDatatype(
12) =
"FAX
"
62 UserfieldDatatype(
13) =
"EMAIL
"
63 UserfieldDatatype(
14) =
"STATE
"
73 oDocAuto = ThisComponent
74 oStyles = oDocAuto.Stylefamilies.GetByName(
"NumberingStyles
")
76 ' Prepare the Search-Descriptor
77 oSearchDesc = oDocAuto.createsearchDescriptor()
78 oSearchDesc.SearchRegularExpression = True
79 oSearchDesc.SearchWords = True
80 oSearchDesc.SearchString =
"<[^
>]+
>"
81 oFoundall = oDocAuto.FindAll(oSearchDesc)
83 'Loop over the foundings
84 For i =
0 To oFoundAll.Count -
1
85 oFound = oFoundAll.GetByIndex(i)
86 sFoundString = oFound.String
87 'Extract the string inside the brackets
88 sFoundContent = FindPartString(sFoundString,
"<",
">",
1)
89 sFoundContent = LTrim(sFoundContent)
91 ' Define the Cursor and place it on the founding
92 oCursor = oFound.Text.CreateTextCursorbyRange(oFound)
94 ' Find out, which object is to be created...
95 FieldStringThere = Instr(
1,sFoundContent,
"Field
")
96 ULStringThere = Instr(
1,sFoundContent,
"UL
")
97 PHStringThere = Instr(
1,sFoundContent,
"Placeholder
")
98 If FieldStringThere =
1 Then
99 CreateUserDatafield(oCursor, sFoundContent)
100 ElseIf ULStringThere =
1 Then
101 CreateBullet(oCursor, oStyles)
102 ElseIf PHStringThere =
1 Then
103 CreatePlaceholder(oCursor, sFoundContent)
108 If Err
<> 0 Then
109 Msgbox(sGeneralError,
16, GetProductName())
116 ' creates a User - datafield out of a string with the following structure
117 ' "<field:Company
>"
118 Sub CreateUserDatafield(oCursor, sFoundContent as String)
119 Dim MaxIndex as Integer
121 Dim oUserfield as Object
122 Dim UserInfo as String
123 Dim UserIndex as Integer
125 oUserfield = oDocAuto.CreateInstance(
"com.sun.star.text.TextField.ExtendedUser
")
126 sFoundList() = ArrayoutofString(sFoundContent,
":
",MaxIndex)
127 UserInfo = UCase(LTrim(sFoundList(
1)))
128 UserIndex = IndexInArray(UserInfo, UserfieldDatatype())
129 If UserIndex
<> -
1 Then
130 oUserField.UserDatatype = UserIndex
131 oCursor.Text.InsertTextContent(oCursor,oUserField,True)
132 oUserField.IsFixed = True
134 Msgbox(UserInfo
&":
" & sTextFieldNotDefined,
16, GetProductName())
139 ' Creates a Bullet by setting a soft Formatation on the first unsorted List-Templates with a defined
141 Sub CreateBullet(oCursor, oStyles as Object)
142 Dim n, m, s as Integer
143 Dim StyleSet as Boolean
145 Dim StyleName as String
148 For s =
0 To Ubound(BulletList())
149 For n =
0 To oStyles.Count -
1
150 ostyle = oStyles.getbyindex(n)
151 StyleName = oStyle.Name
152 alevel() = ostyle.NumberingRules.getbyindex(
0)
153 ' The properties of the style are stored in a Name-Value-Array()
154 For m =
0 to Ubound(alevel())
155 ' Set the first Numbering template without a bulletID
156 If (aLevel(m).Name =
"BulletId
") Then
157 If alevel(m).Value = BulletList(s) Then
158 oCursor.NumberingStyle = StyleName
159 oCursor.SetString(
"")
167 ' The Template with the demanded BulletID is not available, so take the first style in the sequence
168 ' that has a defined Bullet ID
169 oCursor.NumberingStyleName = oStyles.GetByIndex(
5).Name
170 oCursor.SetString(
"")
175 ' Creates a placeholder out of a string with the following structure:
176 '<placeholder:Showtext:Helptext
>
177 Sub CreatePlaceholder(oCursor as Object, sFoundContent as String)
178 Dim oPlaceholder as Object
179 Dim MaxIndex as Integer
181 oPlaceholder = oDocAuto.CreateInstance(
"com.sun.star.text.TextField.JumpEdit
")
182 sFoundList() = ArrayoutofString(sFoundContent,
":
" & chr(
34),MaxIndex)
183 ' Delete The Double-quotes
184 oPlaceholder.Hint = DeleteStr(sFoundList(
2),chr(
34))
185 oPlaceholder.placeholder = DeleteStr(sFoundList(
1),chr(
34))
186 oCursor.Text.InsertTextContent(oCursor,oPlaceholder,True)