update dev300-m58
[ooovba.git] / wizards / source / template / Autotext.xba
blob27a7bca1290e93a8639c4cbe9c9a0d291d3012fc
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
12 Sub Main()
13 Dim oCursor as Object
14 Dim oStyles as Object
15 Dim oSearchDesc as Object
16 Dim oFoundall as Object
17 Dim oFound as Object
18 Dim i as Integer
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 &apos; Initialization...
26 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
27 If InitResources(&quot;&apos;Template&apos;&quot;, &quot;tpl&quot;) Then
28 sGeneralError = GetResText(1302)
29 sTextFieldNotDefined = GetResText(1400)
30 End If
32 UserfieldDatatype(0) = &quot;COMPANY&quot;
33 UserfieldDatatype(1) = &quot;FIRSTNAME&quot;
34 UserfieldDatatype(2) = &quot;NAME&quot;
35 UserfieldDatatype(3) = &quot;SHORTCUT&quot;
36 UserfieldDatatype(4) = &quot;STREET&quot;
37 UserfieldDatatype(5) = &quot;COUNTRY&quot;
38 UserfieldDatatype(6) = &quot;ZIP&quot;
39 UserfieldDatatype(7) = &quot;CITY&quot;
40 UserfieldDatatype(8) = &quot;TITLE&quot;
41 UserfieldDatatype(9) = &quot;POSITION&quot;
42 UserfieldDatatype(10) = &quot;PHONE_PRIVATE&quot;
43 UserfieldDatatype(11) = &quot;PHONE_COMPANY&quot;
44 UserfieldDatatype(12) = &quot;FAX&quot;
45 UserfieldDatatype(13) = &quot;EMAIL&quot;
46 UserfieldDatatype(14) = &quot;STATE&quot;
47 BulletList(0) = 149
48 BulletList(1) = 34
49 BulletList(2) = 65
50 BulletList(3) = 61
51 BulletList(4) = 49
52 BulletList(5) = 47
53 BulletList(6) = 79
54 BulletList(7) = 58
56 oDocAuto = ThisComponent
57 oStyles = oDocAuto.Stylefamilies.GetByName(&quot;NumberingStyles&quot;)
59 &apos; Prepare the Search-Descriptor
60 oSearchDesc = oDocAuto.createsearchDescriptor()
61 oSearchDesc.SearchRegularExpression = True
62 oSearchDesc.SearchWords = True
63 oSearchDesc.SearchString = &quot;&lt;[^&gt;]+&gt;&quot;
64 oFoundall = oDocAuto.FindAll(oSearchDesc)
66 &apos;Loop over the foundings
67 For i = 0 To oFoundAll.Count - 1
68 oFound = oFoundAll.GetByIndex(i)
69 sFoundString = oFound.String
70 &apos;Extract the string inside the brackets
71 sFoundContent = FindPartString(sFoundString,&quot;&lt;&quot;,&quot;&gt;&quot;,1)
72 sFoundContent = LTrim(sFoundContent)
74 &apos; Define the Cursor and place it on the founding
75 oCursor = oFound.Text.CreateTextCursorbyRange(oFound)
77 &apos; Find out, which object is to be created...
78 FieldStringThere = Instr(1,sFoundContent,&quot;Field&quot;)
79 ULStringThere = Instr(1,sFoundContent,&quot;UL&quot;)
80 PHStringThere = Instr(1,sFoundContent,&quot;Placeholder&quot;)
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)
87 End If
88 Next i
90 GENERALERROR:
91 If Err &lt;&gt; 0 Then
92 Msgbox(sGeneralError,16, GetProductName())
93 Resume LETSGO
94 End If
95 LETSGO:
96 End Sub
99 &apos; creates a User - datafield out of a string with the following structure
100 &apos; &quot;&lt;field:Company&gt;&quot;
101 Sub CreateUserDatafield(oCursor, sFoundContent as String)
102 Dim MaxIndex as Integer
103 Dim sFoundList(3)
104 Dim oUserfield as Object
105 Dim UserInfo as String
106 Dim UserIndex as Integer
108 oUserfield = oDocAuto.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
109 sFoundList() = ArrayoutofString(sFoundContent,&quot;:&quot;,MaxIndex)
110 UserInfo = UCase(LTrim(sFoundList(1)))
111 UserIndex = IndexinArray(UserInfo, UserfieldDatatype())
112 If UserIndex &lt;&gt; -1 Then
113 oUserField.UserDatatype = UserIndex
114 oCursor.Text.InsertTextContent(oCursor,oUserField,True)
115 oUserField.IsFixed = True
116 Else
117 Msgbox(UserInfo &amp;&quot;: &quot; &amp; sTextFieldNotDefined,16, GetProductName())
118 End If
119 End Sub
122 &apos; Creates a Bullet by setting a soft Formatation on the first unsorted List-Templates with a defined
123 &apos; Bullet Id
124 Sub CreateBullet(oCursor, oStyles as Object)
125 Dim n, m, s as Integer
126 Dim StyleSet as Boolean
127 Dim ostyle as Object
128 Dim StyleName as String
129 Dim alevel()
130 StyleSet = False
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 &apos; The properties of the style are stored in a Name-Value-Array()
137 For m = 0 to Ubound(alevel())
138 &apos; Set the first Numbering template without a bulletID
139 If (aLevel(m).Name = &quot;BulletId&quot;) Then
140 If alevel(m).Value = BulletList(s) Then
141 oCursor.NumberingStyle = StyleName
142 oCursor.SetString(&quot;&quot;)
143 exit Sub
144 End if
145 End If
146 Next m
147 Next n
148 Next s
149 If Not StyleSet Then
150 &apos; The Template with the demanded BulletID is not available, so take the first style in the sequence
151 &apos; that has a defined Bullet ID
152 oCursor.NumberingStyleName = oStyles.GetByIndex(5).Name
153 oCursor.SetString(&quot;&quot;)
154 End If
155 End Sub
158 &apos; Creates a placeholder out of a string with the following structure:
159 &apos;&lt;placeholder:Showtext:Helptext&gt;
160 Sub CreatePlaceholder(oCursor as Object, sFoundContent as String)
161 Dim oPlaceholder as Object
162 Dim MaxIndex as Integer
163 Dim sFoundList(3)
164 oPlaceholder = oDocAuto.CreateInstance(&quot;com.sun.star.text.TextField.JumpEdit&quot;)
165 sFoundList() = ArrayoutofString(sFoundContent, &quot;:&quot; &amp; chr(34),MaxIndex)
166 &apos; 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)
170 End Sub
173 </script:module>