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="Samples" script:language="StarBasic">Option Explicit 4*cdf0e10cSrcweir 5*cdf0e10cSrcweirConst SAMPLES = 1000 6*cdf0e10cSrcweirConst STYLES = 1100 7*cdf0e10cSrcweirConst aTempFileName = "Berend_Ilko_Tom_Stella_Volker.stc" 8*cdf0e10cSrcweirPublic Const Twip = 425 9*cdf0e10cSrcweirDim oUcbObject as Object 10*cdf0e10cSrcweirPublic StylesDir as String 11*cdf0e10cSrcweirPublic StylesDialog as Object 12*cdf0e10cSrcweirPublic PathSeparator as String 13*cdf0e10cSrcweirPublic oFamilies as Object 14*cdf0e10cSrcweirPublic aOptions(0) as New com.sun.star.beans.PropertyValue 15*cdf0e10cSrcweirPublic sQueryPath as String 16*cdf0e10cSrcweirPublic NoArgs()as New com.sun.star.beans.PropertyValue 17*cdf0e10cSrcweirPublic aTempURL as String 18*cdf0e10cSrcweir 19*cdf0e10cSrcweirPublic Files(100) as String 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir'-------------------------------------------------------------------------------------- 23*cdf0e10cSrcweir'Miscellaneous Section starts here 24*cdf0e10cSrcweir 25*cdf0e10cSrcweirFunction PrepareForEditing(Optional ByVal oDocument) 26*cdf0e10cSrcweir'This sub is called when sample documents are loaded (load event). 27*cdf0e10cSrcweir'It checks whether the documents is read-only, in which case it 28*cdf0e10cSrcweir'offers the user to create a new (writable) document using the original 29*cdf0e10cSrcweir'as a template. 30*cdf0e10cSrcweirDim DocPath as String 31*cdf0e10cSrcweirDim MMessage as String 32*cdf0e10cSrcweirDim MTitle as String 33*cdf0e10cSrcweirDim RValue as Integer 34*cdf0e10cSrcweirDim oNewDocument as Object 35*cdf0e10cSrcweirDim mFileProperties(1) as New com.sun.star.beans.PropertyValue 36*cdf0e10cSrcweir PrepareForEditing = NULL 37*cdf0e10cSrcweir BasicLibraries.LoadLibrary( "Tools" ) 38*cdf0e10cSrcweir If InitResources("'Template'", "tpl") then 39*cdf0e10cSrcweir If IsMissing(oDocument) Then 40*cdf0e10cSrcweir oDocument = ThisComponent 41*cdf0e10cSrcweir End If 42*cdf0e10cSrcweir If oDocument.IsReadOnly then 43*cdf0e10cSrcweir MMessage = GetResText(SAMPLES) 44*cdf0e10cSrcweir MTitle = GetResText(SAMPLES + 1) 45*cdf0e10cSrcweir RValue = Msgbox(MMessage, (128+48+1), MTitle) 46*cdf0e10cSrcweir If RValue = 1 Then 47*cdf0e10cSrcweir DocPath = oDocument.URL 48*cdf0e10cSrcweir mFileProperties(0).Name = "AsTemplate" 49*cdf0e10cSrcweir mFileProperties(0).Value = True 50*cdf0e10cSrcweir mFileProperties(1).Name = "MacroExecutionMode" 51*cdf0e10cSrcweir mFileProperties(1).Value = com.sun.star.document.MacroExecMode.USE_CONFIG 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir oNewDocument = StarDesktop.LoadComponentFromURL(DocPath,"_default",0, mFileProperties()) 54*cdf0e10cSrcweir PrepareForEditing() = oNewDocument 55*cdf0e10cSrcweir DisposeDocument(oDocument) 56*cdf0e10cSrcweir Else 57*cdf0e10cSrcweir PrepareForEditing() = NULL 58*cdf0e10cSrcweir End If 59*cdf0e10cSrcweir Else 60*cdf0e10cSrcweir PrepareForEditing() = oDocument 61*cdf0e10cSrcweir End If 62*cdf0e10cSrcweir End If 63*cdf0e10cSrcweirEnd Function 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir'-------------------------------------------------------------------------------------- 68*cdf0e10cSrcweir'Calc Style Section starts here 69*cdf0e10cSrcweir 70*cdf0e10cSrcweirSub ShowStyles 71*cdf0e10cSrcweir'This sub displays the style selection dialog if the current document is a calc document. 72*cdf0e10cSrcweirDim TemplateDir, ActFileTitle, DisplayDummy as String 73*cdf0e10cSrcweirDim sFilterName(0) as String 74*cdf0e10cSrcweirDim StyleNames() as String 75*cdf0e10cSrcweirDim t as Integer 76*cdf0e10cSrcweirDim MaxIndex as Integer 77*cdf0e10cSrcweir BasicLibraries.LoadLibrary("Tools") 78*cdf0e10cSrcweir If InitResources("'Template'", "tpl") then 79*cdf0e10cSrcweir oDocument = ThisComponent 80*cdf0e10cSrcweir If oDocument.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then 81*cdf0e10cSrcweir ToggleWindow(False) 82*cdf0e10cSrcweir oUcbObject = createUnoService("com.sun.star.ucb.SimpleFileAccess") 83*cdf0e10cSrcweir oFamilies = oDocument.StyleFamilies 84*cdf0e10cSrcweir SaveCurrentStyles(oDocument) 85*cdf0e10cSrcweir StylesDialog = LoadDialog("Template", "DialogStyles") 86*cdf0e10cSrcweir DialogModel = StylesDialog.Model 87*cdf0e10cSrcweir TemplateDir = GetPathSettings("Template", False, 0) 88*cdf0e10cSrcweir StylesDir = GetOfficeSubPath("Template", "wizard/styles/") 89*cdf0e10cSrcweir sQueryPath = GetOfficeSubPath("Template", "../wizard/bitmap/") 90*cdf0e10cSrcweir DialogModel.Title = GetResText(STYLES) 91*cdf0e10cSrcweir DialogModel.cmdCancel.Label = GetResText(STYLES+2) 92*cdf0e10cSrcweir DialogModel.cmdOk.Label = GetResText(STYLES+3) 93*cdf0e10cSrcweir Stylenames() = ReadDirectories(StylesDir, False, False, True,) 94*cdf0e10cSrcweir MaxIndex = Ubound(Stylenames()) 95*cdf0e10cSrcweir BubbleSortList(Stylenames(),True) 96*cdf0e10cSrcweir Dim cStyles(MaxIndex) 97*cdf0e10cSrcweir For t = 0 to MaxIndex 98*cdf0e10cSrcweir Files(t) = StyleNames(t,0) 99*cdf0e10cSrcweir cStyles(t) = StyleNames(t,1) 100*cdf0e10cSrcweir Next t 101*cdf0e10cSrcweir On Local Error Resume Next 102*cdf0e10cSrcweir DialogModel.lbStyles.StringItemList() = cStyles() 103*cdf0e10cSrcweir ToggleWindow(True) 104*cdf0e10cSrcweir StylesDialog.Execute 105*cdf0e10cSrcweir End If 106*cdf0e10cSrcweir End If 107*cdf0e10cSrcweirEnd Sub 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir 110*cdf0e10cSrcweirSub SelectStyle 111*cdf0e10cSrcweir'This sub loads the specific styles from a style document and loads them into the 112*cdf0e10cSrcweir'current document. 113*cdf0e10cSrcweirDim StylePath as String 114*cdf0e10cSrcweirDim NewStyle as String 115*cdf0e10cSrcweirDim Position as Integer 116*cdf0e10cSrcweir Position = DialogModel.lbStyles.SelectedItems(0) 117*cdf0e10cSrcweir If Position > -1 Then 118*cdf0e10cSrcweir ToggleWindow(False) 119*cdf0e10cSrcweir StylePath = Files(Position) 120*cdf0e10cSrcweir aOptions(0).Name = "OverwriteStyles" 121*cdf0e10cSrcweir aOptions(0).Value = true 122*cdf0e10cSrcweir oFamilies.loadStylesFromURL(StylePath, aOptions()) 123*cdf0e10cSrcweir ToggleWindow(True) 124*cdf0e10cSrcweir End If 125*cdf0e10cSrcweirEnd Sub 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir 128*cdf0e10cSrcweirSub SaveCurrentStyles(oDocument as Object) 129*cdf0e10cSrcweir'This sub stores the current document in the user work directory 130*cdf0e10cSrcweir On Error Goto ErrorOcurred 131*cdf0e10cSrcweir aTempURL = GetPathSettings("Work", False) 132*cdf0e10cSrcweir Dim aRightMost as String 133*cdf0e10cSrcweir aRightMost = Right(aTempURL, 1) 134*cdf0e10cSrcweir if aRightMost = "/" Then 135*cdf0e10cSrcweir aTempURL = aTempURL & aTempFileName 136*cdf0e10cSrcweir Else 137*cdf0e10cSrcweir aTempURL = aTempURL & "/" & aTempFileName 138*cdf0e10cSrcweir End If 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir While FileExists(aTempURL) 141*cdf0e10cSrcweir aTempURL=Left(aTempURL,(Len(aTempURL)-4)) & "_1.stc" 142*cdf0e10cSrcweir Wend 143*cdf0e10cSrcweir oDocument.storeToURL(aTempURL, NoArgs()) 144*cdf0e10cSrcweir Exit Sub 145*cdf0e10cSrcweir 146*cdf0e10cSrcweirErrorOcurred: 147*cdf0e10cSrcweir MsgBox(GetResText( STYLES+1 ), 16, GetResText( STYLES )) 148*cdf0e10cSrcweir On Local Error Goto 0 149*cdf0e10cSrcweirEnd Sub 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir 152*cdf0e10cSrcweirSub RestoreCurrentStyles 153*cdf0e10cSrcweir'This sub retrieves the styles from the temporarily save document 154*cdf0e10cSrcweir ToggleWindow(False) 155*cdf0e10cSrcweir On Local Error Goto NoFile 156*cdf0e10cSrcweir If FileExists(aTempURL) Then 157*cdf0e10cSrcweir aOptions(0).Name = "OverwriteStyles" 158*cdf0e10cSrcweir aOptions(0).Value = true 159*cdf0e10cSrcweir oFamilies.LoadStylesFromURL(aTempURL, aOptions()) 160*cdf0e10cSrcweir KillTempFile() 161*cdf0e10cSrcweir End If 162*cdf0e10cSrcweir StylesDialog.EndExecute 163*cdf0e10cSrcweir ToggleWindow(True) 164*cdf0e10cSrcweirNOFILE: 165*cdf0e10cSrcweir If Err <> 0 Then 166*cdf0e10cSrcweir Msgbox("Cannot load Document from " & aTempUrl, 64, GetProductname()) 167*cdf0e10cSrcweir End If 168*cdf0e10cSrcweir On Local Error Goto 0 169*cdf0e10cSrcweirEnd Sub 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir 172*cdf0e10cSrcweirSub CloseStyleDialog 173*cdf0e10cSrcweir KillTempFile() 174*cdf0e10cSrcweir DialogExited = True 175*cdf0e10cSrcweir StylesDialog.Endexecute 176*cdf0e10cSrcweirEnd Sub 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweirSub KillTempFile() 180*cdf0e10cSrcweir If oUcbObject.Exists(aTempUrl) Then 181*cdf0e10cSrcweir oUcbObject.Kill(aTempUrl) 182*cdf0e10cSrcweir End If 183*cdf0e10cSrcweirEnd Sub 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir</script:module>