1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoText" script:language="StarBasic">' BASIC 24Option Explicit 25Dim oDocument as Object 26Dim sDocumentTitle as String 27 28 29Sub Main() 30Dim oTable as Object 31Dim oRows as Object 32Dim oDocuText as Object 33Dim oAutoTextCursor as Object 34Dim oAutoTextContainer as Object 35Dim oAutogroup as Object 36Dim oAutoText as Object 37Dim oCharStyles as Object 38Dim oContentStyle as Object 39Dim oHeaderStyle as Object 40Dim oGroupTitleStyle as Object 41Dim n, m, iAutoCount as Integer 42 BasicLibraries.LoadLibrary("Tools") 43 sDocumentTitle = "Installed AutoTexts" 44 45 ' Open a new empty document 46 oDocument = CreateNewDocument("swriter") 47 If Not IsNull(oDocument) Then 48 oDocument.DocumentProperties.Title = sDocumentTitle 49 oDocuText = oDocument.Text 50 51 ' Create The Character-templates 52 oCharStyles = oDocument.StyleFamilies.GetByName("CharacterStyles") 53 54 ' The Characterstyle for the Header that describes the Title of Autotextgroups 55 oGroupTitleStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle") 56 oCharStyles.InsertbyName("AutoTextGroupTitle", oGroupTitleStyle) 57 58 oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD 59 oGroupTitleStyle.CharHeight = 14 60 61 ' The Characterstyle for the Header that describes the Title of Autotextgroups 62 oHeaderStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle") 63 oCharStyles.InsertbyName("AutoTextHeading", oHeaderStyle) 64 oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD 65 66 ' "Ordinary" Table Content 67 oContentStyle = oDocument.createInstance("com.sun.star.style.CharacterStyle") 68 oCharStyles.InsertbyName("TableContent", oContentStyle) 69 70 oAutoTextContainer = CreateUnoService("com.sun.star.text.AutoTextContainer") 71 72 oAutoTextCursor = oDocuText.CreateTextCursor() 73 74 oAutoTextCursor.CharStyleName = "AutoTextGroupTitle" 75 ' Link the Title with the following table 76 oAutoTextCursor.ParaKeepTogether = True 77 78 For n = 0 To oAutoTextContainer.Count - 1 79 oAutoGroup = oAutoTextContainer.GetByIndex(n) 80 81 oAutoTextCursor.SetString(oAutoGroup.Title) 82 oAutoTextCursor.CollapseToEnd() 83 oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False) 84 oTable = oDocument.CreateInstance("com.sun.star.text.TextTable") 85 ' Divide the table if necessary 86 oTable.Split = True 87' oTable.KeepTogether = False 88 oTable.RepeatHeadLine = True 89 oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False) 90 InsertStringToCell("AutoText Name",oTable.GetCellbyPosition(0,0), "AutoTextHeading") 91 InsertStringToCell("AutoText Shortcut",oTable.GetCellbyPosition(1,0), "AutoTextHeading") 92 ' Insert one row at the bottom of the table 93 oRows = oTable.Rows 94 iAutoCount = oAutoGroup.Count 95 For m = 0 To iAutoCount-1 96 ' Insert the name and the title of all Autotexts 97 oAutoText = oAutoGroup.GetByIndex(m) 98 InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), "TableContent") 99 InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), "TableContent") 100 If m < iAutoCount-1 Then 101 oRows.InsertbyIndex(m + 2,1) 102 End If 103 Next m 104 oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False) 105 oAutoTextCursor.CollapseToEnd() 106 Next n 107 End If 108End Sub 109 110 111Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String) 112Dim oCellCursor as Object 113 oCellCursor = oCell.CreateTextCursor() 114 oCellCursor.CharStyleName = sCellStyle 115 oCell.Text.insertString(oCellCursor,sCellString,False) 116 oDocument.CurrentController.Select(oCellCursor) 117End Sub</script:module> 118