xref: /AOO41X/main/wizards/source/gimmicks/AutoText.xba (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoText" script:language="StarBasic">&apos; BASIC
4*cdf0e10cSrcweirOption Explicit
5*cdf0e10cSrcweirDim oDocument as Object
6*cdf0e10cSrcweirDim sDocumentTitle as String
7*cdf0e10cSrcweir
8*cdf0e10cSrcweir
9*cdf0e10cSrcweirSub Main()
10*cdf0e10cSrcweirDim oTable as Object
11*cdf0e10cSrcweirDim oRows as Object
12*cdf0e10cSrcweirDim oDocuText as Object
13*cdf0e10cSrcweirDim oAutoTextCursor as Object
14*cdf0e10cSrcweirDim oAutoTextContainer as Object
15*cdf0e10cSrcweirDim oAutogroup as Object
16*cdf0e10cSrcweirDim oAutoText as Object
17*cdf0e10cSrcweirDim oCharStyles as Object
18*cdf0e10cSrcweirDim oContentStyle as Object
19*cdf0e10cSrcweirDim oHeaderStyle as Object
20*cdf0e10cSrcweirDim oGroupTitleStyle as Object
21*cdf0e10cSrcweirDim n, m, iAutoCount as Integer
22*cdf0e10cSrcweir    BasicLibraries.LoadLibrary(&quot;Tools&quot;)
23*cdf0e10cSrcweir    sDocumentTitle = &quot;Installed AutoTexts&quot;
24*cdf0e10cSrcweir
25*cdf0e10cSrcweir    &apos; Open a new empty document
26*cdf0e10cSrcweir    oDocument = CreateNewDocument(&quot;swriter&quot;)
27*cdf0e10cSrcweir    If Not IsNull(oDocument) Then
28*cdf0e10cSrcweir        oDocument.DocumentProperties.Title = sDocumentTitle
29*cdf0e10cSrcweir        oDocuText = oDocument.Text
30*cdf0e10cSrcweir
31*cdf0e10cSrcweir        &apos; Create The Character-templates
32*cdf0e10cSrcweir        oCharStyles = oDocument.StyleFamilies.GetByName(&quot;CharacterStyles&quot;)
33*cdf0e10cSrcweir
34*cdf0e10cSrcweir        &apos; The Characterstyle for the Header that describes the Title of Autotextgroups
35*cdf0e10cSrcweir        oGroupTitleStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
36*cdf0e10cSrcweir        oCharStyles.InsertbyName(&quot;AutoTextGroupTitle&quot;, oGroupTitleStyle)
37*cdf0e10cSrcweir
38*cdf0e10cSrcweir        oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
39*cdf0e10cSrcweir        oGroupTitleStyle.CharHeight = 14
40*cdf0e10cSrcweir
41*cdf0e10cSrcweir        &apos; The Characterstyle for the Header that describes the Title of Autotextgroups
42*cdf0e10cSrcweir        oHeaderStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
43*cdf0e10cSrcweir        oCharStyles.InsertbyName(&quot;AutoTextHeading&quot;, oHeaderStyle)
44*cdf0e10cSrcweir        oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
45*cdf0e10cSrcweir
46*cdf0e10cSrcweir        &apos; &quot;Ordinary&quot; Table Content
47*cdf0e10cSrcweir        oContentStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
48*cdf0e10cSrcweir        oCharStyles.InsertbyName(&quot;TableContent&quot;, oContentStyle)
49*cdf0e10cSrcweir
50*cdf0e10cSrcweir        oAutoTextContainer = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
51*cdf0e10cSrcweir
52*cdf0e10cSrcweir        oAutoTextCursor = oDocuText.CreateTextCursor()
53*cdf0e10cSrcweir
54*cdf0e10cSrcweir        oAutoTextCursor.CharStyleName = &quot;AutoTextGroupTitle&quot;
55*cdf0e10cSrcweir        &apos; Link the Title with the following table
56*cdf0e10cSrcweir        oAutoTextCursor.ParaKeepTogether = True
57*cdf0e10cSrcweir
58*cdf0e10cSrcweir        For n = 0 To oAutoTextContainer.Count - 1
59*cdf0e10cSrcweir            oAutoGroup = oAutoTextContainer.GetByIndex(n)
60*cdf0e10cSrcweir
61*cdf0e10cSrcweir            oAutoTextCursor.SetString(oAutoGroup.Title)
62*cdf0e10cSrcweir            oAutoTextCursor.CollapseToEnd()
63*cdf0e10cSrcweir            oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
64*cdf0e10cSrcweir            oTable = oDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
65*cdf0e10cSrcweir            &apos; Divide the table if necessary
66*cdf0e10cSrcweir            oTable.Split = True
67*cdf0e10cSrcweir&apos;          oTable.KeepTogether = False
68*cdf0e10cSrcweir            oTable.RepeatHeadLine = True
69*cdf0e10cSrcweir            oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
70*cdf0e10cSrcweir            InsertStringToCell(&quot;AutoText Name&quot;,oTable.GetCellbyPosition(0,0), &quot;AutoTextHeading&quot;)
71*cdf0e10cSrcweir            InsertStringToCell(&quot;AutoText Shortcut&quot;,oTable.GetCellbyPosition(1,0), &quot;AutoTextHeading&quot;)
72*cdf0e10cSrcweir            &apos; Insert one row at the bottom of the table
73*cdf0e10cSrcweir            oRows = oTable.Rows
74*cdf0e10cSrcweir            iAutoCount = oAutoGroup.Count
75*cdf0e10cSrcweir            For m = 0 To iAutoCount-1
76*cdf0e10cSrcweir                &apos; Insert the name and the title of all Autotexts
77*cdf0e10cSrcweir                oAutoText = oAutoGroup.GetByIndex(m)
78*cdf0e10cSrcweir                InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), &quot;TableContent&quot;)
79*cdf0e10cSrcweir                InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), &quot;TableContent&quot;)
80*cdf0e10cSrcweir                If m &lt; iAutoCount-1 Then
81*cdf0e10cSrcweir                    oRows.InsertbyIndex(m + 2,1)
82*cdf0e10cSrcweir                End If
83*cdf0e10cSrcweir            Next m
84*cdf0e10cSrcweir            oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
85*cdf0e10cSrcweir            oAutoTextCursor.CollapseToEnd()
86*cdf0e10cSrcweir        Next n
87*cdf0e10cSrcweir    End If
88*cdf0e10cSrcweirEnd Sub
89*cdf0e10cSrcweir
90*cdf0e10cSrcweir
91*cdf0e10cSrcweirSub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
92*cdf0e10cSrcweirDim oCellCursor as Object
93*cdf0e10cSrcweir    oCellCursor = oCell.CreateTextCursor()
94*cdf0e10cSrcweir    oCellCursor.CharStyleName = sCellStyle
95*cdf0e10cSrcweir    oCell.Text.insertString(oCellCursor,sCellString,False)
96*cdf0e10cSrcweir    oDocument.CurrentController.Select(oCellCursor)
97*cdf0e10cSrcweirEnd Sub</script:module>
98