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