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=
"Samples" script:
language=
"StarBasic">Option Explicit
24 Const STYLENAME_DEF =
1120
25 Const STYLENAME =
1150
27 Const aTempFileName =
"Berend_Ilko_Tom_Stella_Volker.stc
"
28 Public Const Twip =
425
29 Dim oUcbObject as Object
30 Public StylesDir as String
31 Public StylesDialog as Object
32 Public PathSeparator as String
33 Public oFamilies as Object
34 Public aOptions(
0) as New com.sun.star.beans.PropertyValue
35 Public sQueryPath as String
36 Public NoArgs()as New com.sun.star.beans.PropertyValue
37 Public aTempURL as String
39 Public Files(
100) as String
42 '--------------------------------------------------------------------------------------
43 'Miscellaneous Section starts here
45 Function PrepareForEditing(Optional ByVal oDocument)
46 'This sub is called when sample documents are loaded (load event).
47 'It checks whether the documents is read-only, in which case it
48 'offers the user to create a new (writable) document using the original
51 Dim MMessage as String
54 Dim oNewDocument as Object
55 Dim mFileProperties(
1) as New com.sun.star.beans.PropertyValue
56 PrepareForEditing = NULL
57 BasicLibraries.LoadLibrary(
"Tools
" )
58 If InitResources(
"'Template
'",
"tpl
") then
59 If IsMissing(oDocument) Then
60 oDocument = ThisComponent
62 If oDocument.IsReadOnly then
63 MMessage = GetResText(SAMPLES)
64 MTitle = GetResText(SAMPLES +
1)
65 RValue = Msgbox(MMessage, (
128+
48+
1), MTitle)
67 DocPath = oDocument.URL
68 mFileProperties(
0).Name =
"AsTemplate
"
69 mFileProperties(
0).Value = True
70 mFileProperties(
1).Name =
"MacroExecutionMode
"
71 mFileProperties(
1).Value = com.sun.star.document.MacroExecMode.USE_CONFIG
73 oNewDocument = StarDesktop.LoadComponentFromURL(DocPath,
"_default
",
0, mFileProperties())
74 PrepareForEditing() = oNewDocument
75 DisposeDocument(oDocument)
77 PrepareForEditing() = NULL
80 PrepareForEditing() = oDocument
87 '--------------------------------------------------------------------------------------
88 'Calc Style Section starts here
91 'This sub displays the style selection dialog if the current document is a calc document.
92 Dim TemplateDir, ActFileTitle, DisplayDummy as String
93 Dim sFilterName(
0) as String
94 Dim StyleNames() as String
95 Dim LocalizedStyleNames(NumStyles,
2) As String
96 Dim LocalizedStyleName As String
98 Dim MaxIndex as Integer
99 BasicLibraries.LoadLibrary(
"Tools
")
100 If InitResources(
"'Template
'",
"tpl
") then
101 oDocument = ThisComponent
102 If oDocument.SupportsService(
"com.sun.star.sheet.SpreadsheetDocument
") Then
104 oUcbObject = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
105 oFamilies = oDocument.StyleFamilies
106 SaveCurrentStyles(oDocument)
107 StylesDialog = LoadDialog(
"Template
",
"DialogStyles
")
108 DialogModel = StylesDialog.Model
109 TemplateDir = GetPathSettings(
"Template
", False,
0)
110 StylesDir = GetOfficeSubPath(
"Template
",
"wizard/styles/
")
111 sQueryPath = GetOfficeSubPath(
"Template
",
"../wizard/bitmap/
")
112 DialogModel.Title = GetResText(STYLES)
113 DialogModel.cmdCancel.Label = GetResText(STYLES+
2)
114 DialogModel.cmdOk.Label = GetResText(STYLES+
3)
115 For t =
0 to NumStyles -
1
116 LocalizedStyleNames(t,
0) = GetResText(STYLENAME_DEF+t)
117 LocalizedStyleNames(t,
1) = GetResText(STYLENAME+t)
119 Stylenames() = ReadDirectories(StylesDir, False, False, True,)
120 MaxIndex = Ubound(Stylenames())
121 For t =
0 to MaxIndex
122 LocalizedStyleName = StringInMultiArray(LocalizedStyleNames(), StyleNames(t,
1),
0,
1)
123 If LocalizedStyleName
<> "" Then
124 StyleNames(t,
1) = LocalizedStyleName
127 BubbleSortList(Stylenames(),True)
128 Dim cStyles(MaxIndex)
129 For t =
0 to MaxIndex
130 Files(t) = StyleNames(t,
0)
131 cStyles(t) = StyleNames(t,
1)
133 On Local Error Resume Next
134 DialogModel.lbStyles.StringItemList() = cStyles()
143 'This sub loads the specific styles from a style document and loads them into the
144 'current document.
145 Dim StylePath as String
146 Dim NewStyle as String
147 Dim Position as Integer
148 Position = DialogModel.lbStyles.SelectedItems(
0)
149 If Position
> -
1 Then
151 StylePath = Files(Position)
152 aOptions(
0).Name =
"OverwriteStyles
"
153 aOptions(
0).Value = true
154 oFamilies.loadStylesFromURL(StylePath, aOptions())
160 Sub SaveCurrentStyles(oDocument as Object)
161 'This sub stores the current document in the user work directory
162 On Error Goto ErrorOcurred
163 aTempURL = GetPathSettings(
"Work
", False)
164 Dim aRightMost as String
165 aRightMost = Right(aTempURL,
1)
166 if aRightMost =
"/
" Then
167 aTempURL = aTempURL
& aTempFileName
169 aTempURL = aTempURL
& "/
" & aTempFileName
172 While FileExists(aTempURL)
173 aTempURL=Left(aTempURL,(Len(aTempURL)-
4))
& "_1.stc
"
175 oDocument.storeToURL(aTempURL, NoArgs())
179 MsgBox(GetResText( STYLES+
1 ),
16, GetResText( STYLES ))
180 On Local Error Goto
0
184 Sub RestoreCurrentStyles
185 'This sub retrieves the styles from the temporarily save document
187 On Local Error Goto NoFile
188 If FileExists(aTempURL) Then
189 aOptions(
0).Name =
"OverwriteStyles
"
190 aOptions(
0).Value = true
191 oFamilies.LoadStylesFromURL(aTempURL, aOptions())
194 StylesDialog.EndExecute
197 If Err
<> 0 Then
198 Msgbox(
"Cannot load Document from
" & aTempUrl,
64, GetProductname())
200 On Local Error Goto
0
207 StylesDialog.Endexecute
212 If oUcbObject.Exists(aTempUrl) Then
213 oUcbObject.Kill(aTempUrl)