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">&apos; BASIC
24cdf0e10cSrcweirOption Explicit
25cdf0e10cSrcweirDim oDocument as Object
26cdf0e10cSrcweirDim sDocumentTitle as String
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweirSub Main()
30cdf0e10cSrcweirDim oTable as Object
31cdf0e10cSrcweirDim oRows as Object
32cdf0e10cSrcweirDim oDocuText as Object
33cdf0e10cSrcweirDim oAutoTextCursor as Object
34cdf0e10cSrcweirDim oAutoTextContainer as Object
35cdf0e10cSrcweirDim oAutogroup as Object
36cdf0e10cSrcweirDim oAutoText as Object
37cdf0e10cSrcweirDim oCharStyles as Object
38cdf0e10cSrcweirDim oContentStyle as Object
39cdf0e10cSrcweirDim oHeaderStyle as Object
40cdf0e10cSrcweirDim oGroupTitleStyle as Object
41cdf0e10cSrcweirDim n, m, iAutoCount as Integer
42cdf0e10cSrcweir	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
43cdf0e10cSrcweir	sDocumentTitle = &quot;Installed AutoTexts&quot;
44cdf0e10cSrcweir
45cdf0e10cSrcweir	&apos; Open a new empty document
46cdf0e10cSrcweir	oDocument = CreateNewDocument(&quot;swriter&quot;)
47cdf0e10cSrcweir	If Not IsNull(oDocument) Then
48cdf0e10cSrcweir		oDocument.DocumentProperties.Title = sDocumentTitle
49cdf0e10cSrcweir		oDocuText = oDocument.Text
50cdf0e10cSrcweir
51cdf0e10cSrcweir		&apos; Create The Character-templates
52cdf0e10cSrcweir		oCharStyles = oDocument.StyleFamilies.GetByName(&quot;CharacterStyles&quot;)
53cdf0e10cSrcweir
54cdf0e10cSrcweir		&apos; The Characterstyle for the Header that describes the Title of Autotextgroups
55cdf0e10cSrcweir		oGroupTitleStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
56cdf0e10cSrcweir		oCharStyles.InsertbyName(&quot;AutoTextGroupTitle&quot;, oGroupTitleStyle)
57cdf0e10cSrcweir
58cdf0e10cSrcweir		oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
59cdf0e10cSrcweir		oGroupTitleStyle.CharHeight = 14
60cdf0e10cSrcweir
61cdf0e10cSrcweir		&apos; The Characterstyle for the Header that describes the Title of Autotextgroups
62cdf0e10cSrcweir		oHeaderStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
63cdf0e10cSrcweir		oCharStyles.InsertbyName(&quot;AutoTextHeading&quot;, oHeaderStyle)
64cdf0e10cSrcweir		oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
65cdf0e10cSrcweir
66cdf0e10cSrcweir		&apos; &quot;Ordinary&quot; Table Content
67cdf0e10cSrcweir		oContentStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
68cdf0e10cSrcweir		oCharStyles.InsertbyName(&quot;TableContent&quot;, oContentStyle)
69cdf0e10cSrcweir
70cdf0e10cSrcweir		oAutoTextContainer = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
71cdf0e10cSrcweir
72cdf0e10cSrcweir		oAutoTextCursor = oDocuText.CreateTextCursor()
73cdf0e10cSrcweir
74cdf0e10cSrcweir		oAutoTextCursor.CharStyleName = &quot;AutoTextGroupTitle&quot;
75cdf0e10cSrcweir		&apos; Link the Title with the following table
76cdf0e10cSrcweir		oAutoTextCursor.ParaKeepTogether = True
77cdf0e10cSrcweir
78cdf0e10cSrcweir		For n = 0 To oAutoTextContainer.Count - 1
79cdf0e10cSrcweir			oAutoGroup = oAutoTextContainer.GetByIndex(n)
80cdf0e10cSrcweir
81cdf0e10cSrcweir			oAutoTextCursor.SetString(oAutoGroup.Title)
82cdf0e10cSrcweir			oAutoTextCursor.CollapseToEnd()
83cdf0e10cSrcweir   			oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
84cdf0e10cSrcweir			oTable = oDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
85cdf0e10cSrcweir			&apos; Divide the table if necessary
86cdf0e10cSrcweir			oTable.Split = True
87cdf0e10cSrcweir&apos;			oTable.KeepTogether = False
88cdf0e10cSrcweir			oTable.RepeatHeadLine = True
89cdf0e10cSrcweir			oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
90cdf0e10cSrcweir			InsertStringToCell(&quot;AutoText Name&quot;,oTable.GetCellbyPosition(0,0), &quot;AutoTextHeading&quot;)
91cdf0e10cSrcweir			InsertStringToCell(&quot;AutoText Shortcut&quot;,oTable.GetCellbyPosition(1,0), &quot;AutoTextHeading&quot;)
92cdf0e10cSrcweir			&apos; Insert one row at the bottom of the table
93cdf0e10cSrcweir			oRows = oTable.Rows
94cdf0e10cSrcweir			iAutoCount = oAutoGroup.Count
95cdf0e10cSrcweir			For m = 0 To iAutoCount-1
96cdf0e10cSrcweir				&apos; Insert the name and the title of all Autotexts
97cdf0e10cSrcweir				oAutoText = oAutoGroup.GetByIndex(m)
98cdf0e10cSrcweir				InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), &quot;TableContent&quot;)
99cdf0e10cSrcweir				InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), &quot;TableContent&quot;)
100cdf0e10cSrcweir				If m &lt; iAutoCount-1 Then
101cdf0e10cSrcweir					oRows.InsertbyIndex(m + 2,1)
102cdf0e10cSrcweir				End If
103cdf0e10cSrcweir			Next m
104cdf0e10cSrcweir	   		oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
105cdf0e10cSrcweir			oAutoTextCursor.CollapseToEnd()
106cdf0e10cSrcweir		Next n
107cdf0e10cSrcweir	End If
108cdf0e10cSrcweirEnd Sub
109cdf0e10cSrcweir
110cdf0e10cSrcweir
111cdf0e10cSrcweirSub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
112cdf0e10cSrcweirDim oCellCursor as Object
113cdf0e10cSrcweir	oCellCursor = oCell.CreateTextCursor()
114cdf0e10cSrcweir	oCellCursor.CharStyleName = sCellStyle
115cdf0e10cSrcweir	oCell.Text.insertString(oCellCursor,sCellString,False)
116cdf0e10cSrcweir	oDocument.CurrentController.Select(oCellCursor)
117cdf0e10cSrcweirEnd Sub</script:module>
118