1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Autotext" script:language="StarBasic">Option Explicit
24cdf0e10cSrcweir
25cdf0e10cSrcweirPublic UserfieldDataType(14) as String
26cdf0e10cSrcweirPublic oDocAuto as Object
27cdf0e10cSrcweirPublic BulletList(7) as Integer
28cdf0e10cSrcweirPublic sTextFieldNotDefined as String
29cdf0e10cSrcweirPublic sGeneralError as String
30cdf0e10cSrcweir
31cdf0e10cSrcweir
32cdf0e10cSrcweirSub Main()
33cdf0e10cSrcweir	Dim oCursor as Object
34cdf0e10cSrcweir	Dim oStyles as Object
35cdf0e10cSrcweir	Dim oSearchDesc as Object
36cdf0e10cSrcweir	Dim oFoundall as Object
37cdf0e10cSrcweir	Dim oFound as Object
38cdf0e10cSrcweir	Dim i as Integer
39cdf0e10cSrcweir	Dim sFoundString as String
40cdf0e10cSrcweir	Dim sFoundContent as String
41cdf0e10cSrcweir	Dim FieldStringThere as String
42cdf0e10cSrcweir	Dim ULStringThere as String
43cdf0e10cSrcweir	Dim PHStringThere as String
44cdf0e10cSrcweir	On Local Error Goto GENERALERROR
45cdf0e10cSrcweir	&apos; Initialization...
46cdf0e10cSrcweir    BasicLibraries.LoadLibrary(&quot;Tools&quot;)
47cdf0e10cSrcweir	If InitResources(&quot;&apos;Template&apos;&quot;, &quot;tpl&quot;) Then
48cdf0e10cSrcweir		sGeneralError = GetResText(1302)
49cdf0e10cSrcweir		sTextFieldNotDefined = GetResText(1400)
50cdf0e10cSrcweir	End If
51cdf0e10cSrcweir
52cdf0e10cSrcweir	UserfieldDatatype(0) = &quot;COMPANY&quot;
53cdf0e10cSrcweir	UserfieldDatatype(1) = &quot;FIRSTNAME&quot;
54cdf0e10cSrcweir	UserfieldDatatype(2) = &quot;NAME&quot;
55cdf0e10cSrcweir	UserfieldDatatype(3) = &quot;SHORTCUT&quot;
56cdf0e10cSrcweir	UserfieldDatatype(4) = &quot;STREET&quot;
57cdf0e10cSrcweir	UserfieldDatatype(5) = &quot;COUNTRY&quot;
58cdf0e10cSrcweir	UserfieldDatatype(6) = &quot;ZIP&quot;
59cdf0e10cSrcweir	UserfieldDatatype(7) = &quot;CITY&quot;
60cdf0e10cSrcweir	UserfieldDatatype(8) = &quot;TITLE&quot;
61cdf0e10cSrcweir	UserfieldDatatype(9) = &quot;POSITION&quot;
62cdf0e10cSrcweir	UserfieldDatatype(10) = &quot;PHONE_PRIVATE&quot;
63cdf0e10cSrcweir	UserfieldDatatype(11) = &quot;PHONE_COMPANY&quot;
64cdf0e10cSrcweir	UserfieldDatatype(12) = &quot;FAX&quot;
65cdf0e10cSrcweir	UserfieldDatatype(13) = &quot;EMAIL&quot;
66cdf0e10cSrcweir	UserfieldDatatype(14) = &quot;STATE&quot;
67cdf0e10cSrcweir	BulletList(0) = 149
68cdf0e10cSrcweir	BulletList(1) = 34
69cdf0e10cSrcweir	BulletList(2) = 65
70cdf0e10cSrcweir	BulletList(3) = 61
71cdf0e10cSrcweir	BulletList(4) = 49
72cdf0e10cSrcweir	BulletList(5) = 47
73cdf0e10cSrcweir	BulletList(6) = 79
74cdf0e10cSrcweir	BulletList(7) = 58
75cdf0e10cSrcweir
76cdf0e10cSrcweir	oDocAuto = ThisComponent
77cdf0e10cSrcweir	oStyles = oDocAuto.Stylefamilies.GetByName(&quot;NumberingStyles&quot;)
78cdf0e10cSrcweir
79cdf0e10cSrcweir	&apos; Prepare the Search-Descriptor
80cdf0e10cSrcweir	oSearchDesc = oDocAuto.createsearchDescriptor()
81cdf0e10cSrcweir	oSearchDesc.SearchRegularExpression = True
82cdf0e10cSrcweir	oSearchDesc.SearchWords = True
83cdf0e10cSrcweir	oSearchDesc.SearchString  = &quot;&lt;[^&gt;]+&gt;&quot;
84cdf0e10cSrcweir	oFoundall = oDocAuto.FindAll(oSearchDesc)
85cdf0e10cSrcweir
86cdf0e10cSrcweir	&apos;Loop over the foundings
87cdf0e10cSrcweir	For i = 0 To oFoundAll.Count - 1
88cdf0e10cSrcweir		oFound = oFoundAll.GetByIndex(i)
89cdf0e10cSrcweir		sFoundString = oFound.String
90cdf0e10cSrcweir		&apos;Extract the string inside the brackets
91cdf0e10cSrcweir		sFoundContent = FindPartString(sFoundString,&quot;&lt;&quot;,&quot;&gt;&quot;,1)
92cdf0e10cSrcweir		sFoundContent = LTrim(sFoundContent)
93cdf0e10cSrcweir
94cdf0e10cSrcweir		&apos; Define the Cursor and place it on the founding
95cdf0e10cSrcweir		oCursor = oFound.Text.CreateTextCursorbyRange(oFound)
96cdf0e10cSrcweir
97cdf0e10cSrcweir		&apos; Find out, which object is to be created...
98cdf0e10cSrcweir		FieldStringThere = Instr(1,sFoundContent,&quot;Field&quot;)
99cdf0e10cSrcweir		ULStringThere = Instr(1,sFoundContent,&quot;UL&quot;)
100cdf0e10cSrcweir		PHStringThere = Instr(1,sFoundContent,&quot;Placeholder&quot;)
101cdf0e10cSrcweir		If FieldStringThere = 1 Then
102cdf0e10cSrcweir			CreateUserDatafield(oCursor, sFoundContent)
103cdf0e10cSrcweir		ElseIf ULStringThere = 1 Then
104cdf0e10cSrcweir			CreateBullet(oCursor, oStyles)
105cdf0e10cSrcweir		ElseIf PHStringThere = 1 Then
106cdf0e10cSrcweir			CreatePlaceholder(oCursor, sFoundContent)
107cdf0e10cSrcweir		End If
108cdf0e10cSrcweir	Next i
109cdf0e10cSrcweir
110cdf0e10cSrcweir	GENERALERROR:
111cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
112cdf0e10cSrcweir		Msgbox(sGeneralError,16, GetProductName())
113cdf0e10cSrcweir		Resume LETSGO
114cdf0e10cSrcweir	End If
115cdf0e10cSrcweir	LETSGO:
116cdf0e10cSrcweirEnd Sub
117cdf0e10cSrcweir
118cdf0e10cSrcweir
119cdf0e10cSrcweir&apos; creates a User - datafield out of a string with the following structure
120cdf0e10cSrcweir&apos; &quot;&lt;field:Company&gt;&quot;
121cdf0e10cSrcweirSub	CreateUserDatafield(oCursor, sFoundContent as String)
122cdf0e10cSrcweir	Dim MaxIndex as Integer
123cdf0e10cSrcweir	Dim sFoundList(3)
124cdf0e10cSrcweir	Dim oUserfield as Object
125cdf0e10cSrcweir	Dim UserInfo as String
126cdf0e10cSrcweir	Dim UserIndex as Integer
127cdf0e10cSrcweir
128cdf0e10cSrcweir	oUserfield = oDocAuto.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
129cdf0e10cSrcweir	sFoundList() = ArrayoutofString(sFoundContent,&quot;:&quot;,MaxIndex)
130cdf0e10cSrcweir	UserInfo = UCase(LTrim(sFoundList(1)))
131cdf0e10cSrcweir	UserIndex = IndexinArray(UserInfo, UserfieldDatatype())
132cdf0e10cSrcweir	If UserIndex &lt;&gt; -1 Then
133cdf0e10cSrcweir		oUserField.UserDatatype = UserIndex
134cdf0e10cSrcweir		oCursor.Text.InsertTextContent(oCursor,oUserField,True)
135cdf0e10cSrcweir		oUserField.IsFixed = True
136cdf0e10cSrcweir	Else
137cdf0e10cSrcweir		Msgbox(UserInfo &amp;&quot;: &quot; &amp; sTextFieldNotDefined,16, GetProductName())
138cdf0e10cSrcweir	End If
139cdf0e10cSrcweirEnd Sub
140cdf0e10cSrcweir
141cdf0e10cSrcweir
142cdf0e10cSrcweir&apos; Creates a Bullet by setting a soft Formatation on the first unsorted List-Templates with a defined
143cdf0e10cSrcweir&apos; Bullet Id
144cdf0e10cSrcweirSub	CreateBullet(oCursor, oStyles as Object)
145cdf0e10cSrcweir	Dim n, m, s as Integer
146cdf0e10cSrcweir	Dim StyleSet as Boolean
147cdf0e10cSrcweir	Dim ostyle as Object
148cdf0e10cSrcweir	Dim StyleName as String
149cdf0e10cSrcweir	Dim alevel()
150cdf0e10cSrcweir	StyleSet = False
151cdf0e10cSrcweir	For s = 0 To Ubound(BulletList())
152cdf0e10cSrcweir		For n = 0 To oStyles.Count - 1
153cdf0e10cSrcweir			ostyle = oStyles.getbyindex(n)
154cdf0e10cSrcweir			StyleName = oStyle.Name
155cdf0e10cSrcweir			alevel() = ostyle.NumberingRules.getbyindex(0)
156cdf0e10cSrcweir			&apos; The properties of the style are stored in a Name-Value-Array()
157cdf0e10cSrcweir			For m = 0 to Ubound(alevel())
158cdf0e10cSrcweir				&apos; Set the first Numbering template without a bulletID
159cdf0e10cSrcweir				If (aLevel(m).Name = &quot;BulletId&quot;) Then
160cdf0e10cSrcweir					If alevel(m).Value = BulletList(s) Then
161cdf0e10cSrcweir						oCursor.NumberingStyle = StyleName
162cdf0e10cSrcweir						oCursor.SetString(&quot;&quot;)
163cdf0e10cSrcweir						exit Sub
164cdf0e10cSrcweir					End if
165cdf0e10cSrcweir				End If
166cdf0e10cSrcweir			Next m
167cdf0e10cSrcweir		Next n
168cdf0e10cSrcweir	Next s
169cdf0e10cSrcweir	If Not StyleSet Then
170cdf0e10cSrcweir		&apos; The Template with the demanded BulletID is not available, so take the first style in the sequence
171cdf0e10cSrcweir		&apos; that has a defined Bullet ID
172cdf0e10cSrcweir		oCursor.NumberingStyleName = oStyles.GetByIndex(5).Name
173cdf0e10cSrcweir		oCursor.SetString(&quot;&quot;)
174cdf0e10cSrcweir	End If
175cdf0e10cSrcweirEnd Sub
176cdf0e10cSrcweir
177cdf0e10cSrcweir
178cdf0e10cSrcweir&apos; Creates a placeholder out of a string with the following structure:
179cdf0e10cSrcweir&apos;&lt;placeholder:Showtext:Helptext&gt;
180cdf0e10cSrcweirSub	CreatePlaceholder(oCursor as Object, sFoundContent as String)
181cdf0e10cSrcweir	Dim oPlaceholder as Object
182cdf0e10cSrcweir	Dim MaxIndex as Integer
183cdf0e10cSrcweir	Dim sFoundList(3)
184cdf0e10cSrcweir	oPlaceholder = oDocAuto.CreateInstance(&quot;com.sun.star.text.TextField.JumpEdit&quot;)
185cdf0e10cSrcweir	sFoundList() = ArrayoutofString(sFoundContent, &quot;:&quot; &amp; chr(34),MaxIndex)
186cdf0e10cSrcweir	&apos; Delete The Double-quotes
187cdf0e10cSrcweir	oPlaceholder.Hint = DeleteStr(sFoundList(2),chr(34))
188cdf0e10cSrcweir	oPlaceholder.placeholder = 	DeleteStr(sFoundList(1),chr(34))
189cdf0e10cSrcweir	oCursor.Text.InsertTextContent(oCursor,oPlaceholder,True)
190cdf0e10cSrcweirEnd Sub
191cdf0e10cSrcweir
192cdf0e10cSrcweir
193*3e02b54dSAndrew Rist</script:module>
194