update dev300-m57
[ooovba.git] / wizards / source / gimmicks / AutoText.xba
blob5d3cc18e5e136667dee63afffa085bee4aca9126
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">&apos; BASIC
4 Option Explicit
5 Dim oDocument as Object
6 Dim sDocumentTitle as String
9 Sub Main()
10 Dim oTable as Object
11 Dim oRows as Object
12 Dim oDocuText as Object
13 Dim oAutoTextCursor as Object
14 Dim oAutoTextContainer as Object
15 Dim oAutogroup as Object
16 Dim oAutoText as Object
17 Dim oCharStyles as Object
18 Dim oContentStyle as Object
19 Dim oHeaderStyle as Object
20 Dim oGroupTitleStyle as Object
21 Dim n, m, iAutoCount as Integer
22 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
23 sDocumentTitle = &quot;Installed AutoTexts&quot;
25 &apos; Open a new empty document
26 oDocument = CreateNewDocument(&quot;swriter&quot;)
27 If Not IsNull(oDocument) Then
28 oDocument.DocumentProperties.Title = sDocumentTitle
29 oDocuText = oDocument.Text
31 &apos; Create The Character-templates
32 oCharStyles = oDocument.StyleFamilies.GetByName(&quot;CharacterStyles&quot;)
34 &apos; The Characterstyle for the Header that describes the Title of Autotextgroups
35 oGroupTitleStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
36 oCharStyles.InsertbyName(&quot;AutoTextGroupTitle&quot;, oGroupTitleStyle)
38 oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
39 oGroupTitleStyle.CharHeight = 14
41 &apos; The Characterstyle for the Header that describes the Title of Autotextgroups
42 oHeaderStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
43 oCharStyles.InsertbyName(&quot;AutoTextHeading&quot;, oHeaderStyle)
44 oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
46 &apos; &quot;Ordinary&quot; Table Content
47 oContentStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
48 oCharStyles.InsertbyName(&quot;TableContent&quot;, oContentStyle)
50 oAutoTextContainer = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
52 oAutoTextCursor = oDocuText.CreateTextCursor()
54 oAutoTextCursor.CharStyleName = &quot;AutoTextGroupTitle&quot;
55 &apos; Link the Title with the following table
56 oAutoTextCursor.ParaKeepTogether = True
58 For n = 0 To oAutoTextContainer.Count - 1
59 oAutoGroup = oAutoTextContainer.GetByIndex(n)
61 oAutoTextCursor.SetString(oAutoGroup.Title)
62 oAutoTextCursor.CollapseToEnd()
63 oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
64 oTable = oDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
65 &apos; Divide the table if necessary
66 oTable.Split = True
67 &apos; oTable.KeepTogether = False
68 oTable.RepeatHeadLine = True
69 oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
70 InsertStringToCell(&quot;AutoText Name&quot;,oTable.GetCellbyPosition(0,0), &quot;AutoTextHeading&quot;)
71 InsertStringToCell(&quot;AutoText Shortcut&quot;,oTable.GetCellbyPosition(1,0), &quot;AutoTextHeading&quot;)
72 &apos; Insert one row at the bottom of the table
73 oRows = oTable.Rows
74 iAutoCount = oAutoGroup.Count
75 For m = 0 To iAutoCount-1
76 &apos; Insert the name and the title of all Autotexts
77 oAutoText = oAutoGroup.GetByIndex(m)
78 InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), &quot;TableContent&quot;)
79 InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), &quot;TableContent&quot;)
80 If m &lt; iAutoCount-1 Then
81 oRows.InsertbyIndex(m + 2,1)
82 End If
83 Next m
84 oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
85 oAutoTextCursor.CollapseToEnd()
86 Next n
87 End If
88 End Sub
91 Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
92 Dim oCellCursor as Object
93 oCellCursor = oCell.CreateTextCursor()
94 oCellCursor.CharStyleName = sCellStyle
95 oCell.Text.insertString(oCellCursor,sCellString,False)
96 oDocument.CurrentController.Select(oCellCursor)
97 End Sub</script:module>