1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"AutoText" script:
language=
"StarBasic">' BASIC
22 Dim oDocument as Object
23 Dim sDocumentTitle as String
29 Dim oDocuText as Object
30 Dim oAutoTextCursor as Object
31 Dim oAutoTextContainer as Object
32 Dim oAutogroup as Object
33 Dim oAutoText as Object
34 Dim oCharStyles as Object
35 Dim oContentStyle as Object
36 Dim oHeaderStyle as Object
37 Dim oGroupTitleStyle as Object
38 Dim n, m, iAutoCount as Integer
39 BasicLibraries.LoadLibrary(
"Tools
")
40 sDocumentTitle =
"Installed AutoTexts
"
42 ' Open a new empty document
43 oDocument = CreateNewDocument(
"swriter
")
44 If Not IsNull(oDocument) Then
45 oDocument.DocumentProperties.Title = sDocumentTitle
46 oDocuText = oDocument.Text
48 ' Create The Character-templates
49 oCharStyles = oDocument.StyleFamilies.GetByName(
"CharacterStyles
")
51 ' The Characterstyle for the Header that describes the Title of Autotextgroups
52 oGroupTitleStyle = oDocument.createInstance(
"com.sun.star.style.CharacterStyle
")
53 oCharStyles.InsertbyName(
"AutoTextGroupTitle
", oGroupTitleStyle)
55 oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
56 oGroupTitleStyle.CharHeight =
14
58 ' The Characterstyle for the Header that describes the Title of Autotextgroups
59 oHeaderStyle = oDocument.createInstance(
"com.sun.star.style.CharacterStyle
")
60 oCharStyles.InsertbyName(
"AutoTextHeading
", oHeaderStyle)
61 oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
63 ' "Ordinary
" Table Content
64 oContentStyle = oDocument.createInstance(
"com.sun.star.style.CharacterStyle
")
65 oCharStyles.InsertbyName(
"TableContent
", oContentStyle)
67 oAutoTextContainer = CreateUnoService(
"com.sun.star.text.AutoTextContainer
")
69 oAutoTextCursor = oDocuText.CreateTextCursor()
71 oAutoTextCursor.CharStyleName =
"AutoTextGroupTitle
"
72 ' Link the Title with the following table
73 oAutoTextCursor.ParaKeepTogether = True
75 For n =
0 To oAutoTextContainer.Count -
1
76 oAutoGroup = oAutoTextContainer.GetByIndex(n)
78 oAutoTextCursor.SetString(oAutoGroup.Title)
79 oAutoTextCursor.CollapseToEnd()
80 oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
81 oTable = oDocument.CreateInstance(
"com.sun.star.text.TextTable
")
82 ' Divide the table if necessary
84 ' oTable.KeepTogether = False
85 oTable.RepeatHeadLine = True
86 oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
87 InsertStringToCell(
"AutoText Name
",oTable.GetCellbyPosition(
0,
0),
"AutoTextHeading
")
88 InsertStringToCell(
"AutoText Shortcut
",oTable.GetCellbyPosition(
1,
0),
"AutoTextHeading
")
89 ' Insert one row at the bottom of the table
91 iAutoCount = oAutoGroup.Count
92 For m =
0 To iAutoCount-
1
93 ' Insert the name and the title of all Autotexts
94 oAutoText = oAutoGroup.GetByIndex(m)
95 InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(
0, m +
1),
"TableContent
")
96 InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(
1, m +
1),
"TableContent
")
97 If m
< iAutoCount-
1 Then
98 oRows.InsertbyIndex(m +
2,
1)
101 oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
102 oAutoTextCursor.CollapseToEnd()
108 Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
109 Dim oCellCursor as Object
110 oCellCursor = oCell.CreateTextCursor()
111 oCellCursor.CharStyleName = sCellStyle
112 oCell.Text.insertString(oCellCursor,sCellString,False)
113 oDocument.CurrentController.Select(oCellCursor)
114 End Sub
</script:module>