summaryrefslogtreecommitdiffstats
path: root/wizards/source/template/Samples.xba
blob: 25ff81bcf14d836e6b14aca71d7957e3c484ad42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Samples" script:language="StarBasic">Option Explicit

Const NumStyles = 18
Const aTempFileName = &quot;Berend_Ilko_Tom_Stella_Volker.stc&quot;
Dim oUcbObject as Object
Public StylesDir as String
Public StylesDialog as Object
Public PathSeparator as String
Public oFamilies  as Object
Public aOptions(0) as New com.sun.star.beans.PropertyValue
Public sQueryPath as String
Public NoArgs()as New com.sun.star.beans.PropertyValue
Public aTempURL as String

Public Files(100) as String

&apos;--------------------------------------------------------------------------------------
&apos;Calc Style Section starts here

Sub ShowStyles
&apos;This sub displays the style selection dialog if the current document is a calc document.
Dim TemplateDir, ActFileTitle, DisplayDummy as String
Dim sFilterName(0) as String
Dim StyleNames() as String
Dim LocalizedStyleNames(NumStyles,2) As String
Dim LocalizedStyleName As String
Dim t as Integer
Dim MaxIndex as Integer
Dim StyleNameDef As Variant
	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
	If InitResources(&quot;&apos;Template&apos;&quot;) then
	oDocument = ThisComponent
		If oDocument.SupportsService(&quot;com.sun.star.sheet.SpreadsheetDocument&quot;) Then
			ToggleWindow(False)
			oUcbObject = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
			oFamilies = oDocument.StyleFamilies
			SaveCurrentStyles(oDocument)
			StylesDialog = LoadDialog(&quot;Template&quot;, &quot;DialogStyles&quot;)
			DialogModel = StylesDialog.Model
			TemplateDir = GetPathSettings(&quot;Template&quot;, False, 0)
			StylesDir = GetOfficeSubPath(&quot;Template&quot;, &quot;wizard/styles/&quot;)
			sQueryPath = GetOfficeSubPath(&quot;Template&quot;, &quot;../wizard/bitmap/&quot;)
			DialogModel.Title = GetResText(&quot;STYLES_0&quot;)
			DialogModel.cmdCancel.Label = GetResText(&quot;STYLES_2&quot;)
			DialogModel.cmdOk.Label = GetResText(&quot;STYLES_3&quot;)
			StyleNameDef = Array("(Standard)", "Autumn Leaves", "Be", "Black and White", "Blackberry Bush", "Blue Jeans", "Fifties Diner", "Glacier", "Green Grapes", "Marine", "Millennium", "Nature", "Neon", "Night", "PC Nostalgia", "Pastel", "Pool Party", "Pumpkin")
			For t = 0 to NumStyles - 1
				LocalizedStyleNames(t,0) = StyleNameDef(t)
				LocalizedStyleNames(t,1) = GetResText(&quot;STYLENAME_&quot; &amp; Trim(Str(t)))
			Next t
			Stylenames() = ReadDirectories(StylesDir, False, False, True,)
			MaxIndex = Ubound(Stylenames())
			For t = 0 to MaxIndex
				LocalizedStyleName = StringInMultiArray(LocalizedStyleNames(), StyleNames(t,1), 0, 1)
				If LocalizedStyleName &lt;&gt; "" Then
					StyleNames(t,1) = LocalizedStyleName
				End If
			Next t
			BubbleSortList(Stylenames(),True)
			Dim cStyles(MaxIndex)
			For t = 0 to MaxIndex
				Files(t) = StyleNames(t,0)
				cStyles(t) = StyleNames(t,1)
			Next t
			On Local Error Resume Next
			DialogModel.lbStyles.StringItemList() = cStyles()
			ToggleWindow(True)
			StylesDialog.Execute
		End If
	End If
End Sub


Sub SelectStyle
&apos;This sub loads the specific styles from a style document and loads them into the
&apos;current document.
Dim StylePath as String
Dim NewStyle as String
Dim Position as Integer
	Position = DialogModel.lbStyles.SelectedItems(0)
	If Position &gt; -1 Then
		ToggleWindow(False)
		StylePath = Files(Position)
		aOptions(0).Name = &quot;OverwriteStyles&quot;
		aOptions(0).Value = true
		oFamilies.loadStylesFromURL(StylePath, aOptions())
		ToggleWindow(True)
	End If
End Sub


Sub SaveCurrentStyles(oDocument as Object)
&apos;This sub stores the current document in the directory to hold temporary files.
	On Error Goto ErrorOccurred
	aTempURL = GetPathSettings(&quot;Temp&quot;, False)
	Dim aRightMost as String
	aRightMost = Right(aTempURL, 1)
	if aRightMost = &quot;/&quot; Then
		aTempURL = aTempURL &amp; aTempFileName
	Else
		aTempURL = aTempURL &amp; &quot;/&quot; &amp; aTempFileName
	End If

	While FileExists(aTempURL)
		aTempURL=Left(aTempURL,(Len(aTempURL)-4)) &amp; &quot;_1.stc&quot;
	Wend
	oDocument.storeToURL(aTempURL, NoArgs())
	Exit Sub

ErrorOccurred:
	MsgBox(GetResText(&quot;STYLES_1&quot;), 16, GetResText(&quot;STYLES_0&quot;))
	On Local Error Goto 0
End Sub


Sub RestoreCurrentStyles
&apos;This sub retrieves the styles from the temporarily save document
	ToggleWindow(False)
	On Local Error Goto NoFile
	If FileExists(aTempURL) Then
		aOptions(0).Name = &quot;OverwriteStyles&quot;
		aOptions(0).Value = true
		oFamilies.LoadStylesFromURL(aTempURL, aOptions())
		KillTempFile()
	End If
	StylesDialog.EndExecute
	ToggleWindow(True)
NOFILE:
	If Err &lt;&gt; 0 Then
		Msgbox(&quot;Cannot load Document from &quot; &amp; aTempUrl, 64, GetProductname())
	End If
	On Local Error Goto 0
End Sub


Sub CloseStyleDialog
	KillTempFile()
	DialogExited = True
	StylesDialog.Endexecute
End Sub


Sub KillTempFile()
	If oUcbObject.Exists(aTempUrl) Then
		oUcbObject.Kill(aTempUrl)
	End If
End Sub

</script:module>