2017-05-21 12:52:57 -05:00
|
|
|
<?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 = "Berend_Ilko_Tom_Stella_Volker.stc"
|
|
|
|
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
|
|
|
|
|
|
|
|
'--------------------------------------------------------------------------------------
|
|
|
|
'Calc Style Section starts here
|
|
|
|
|
|
|
|
Sub ShowStyles
|
|
|
|
'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
|
2017-05-24 11:33:50 -05:00
|
|
|
Dim StyleNameDef As Variant
|
2017-05-21 12:52:57 -05:00
|
|
|
BasicLibraries.LoadLibrary("Tools")
|
2017-05-24 11:33:50 -05:00
|
|
|
If InitResources("'Template'") then
|
2017-05-21 12:52:57 -05:00
|
|
|
oDocument = ThisComponent
|
|
|
|
If oDocument.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
|
|
|
|
ToggleWindow(False)
|
|
|
|
oUcbObject = createUnoService("com.sun.star.ucb.SimpleFileAccess")
|
|
|
|
oFamilies = oDocument.StyleFamilies
|
|
|
|
SaveCurrentStyles(oDocument)
|
|
|
|
StylesDialog = LoadDialog("Template", "DialogStyles")
|
|
|
|
DialogModel = StylesDialog.Model
|
|
|
|
TemplateDir = GetPathSettings("Template", False, 0)
|
|
|
|
StylesDir = GetOfficeSubPath("Template", "wizard/styles/")
|
|
|
|
sQueryPath = GetOfficeSubPath("Template", "../wizard/bitmap/")
|
2017-05-24 11:33:50 -05:00
|
|
|
DialogModel.Title = GetResText("STYLES_0")
|
|
|
|
DialogModel.cmdCancel.Label = GetResText("STYLES_2")
|
|
|
|
DialogModel.cmdOk.Label = GetResText("STYLES_3")
|
|
|
|
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")
|
2017-05-21 12:52:57 -05:00
|
|
|
For t = 0 to NumStyles - 1
|
2017-05-24 11:33:50 -05:00
|
|
|
LocalizedStyleNames(t,0) = StyleNameDef(t)
|
|
|
|
LocalizedStyleNames(t,1) = GetResText("STYLENAME_" & Trim(Str(t)))
|
2017-05-21 12:52:57 -05:00
|
|
|
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 <> "" 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
|
|
|
|
'This sub loads the specific styles from a style document and loads them into the
|
|
|
|
'current document.
|
|
|
|
Dim StylePath as String
|
|
|
|
Dim NewStyle as String
|
|
|
|
Dim Position as Integer
|
|
|
|
Position = DialogModel.lbStyles.SelectedItems(0)
|
|
|
|
If Position > -1 Then
|
|
|
|
ToggleWindow(False)
|
|
|
|
StylePath = Files(Position)
|
|
|
|
aOptions(0).Name = "OverwriteStyles"
|
|
|
|
aOptions(0).Value = true
|
|
|
|
oFamilies.loadStylesFromURL(StylePath, aOptions())
|
|
|
|
ToggleWindow(True)
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub SaveCurrentStyles(oDocument as Object)
|
|
|
|
'This sub stores the current document in the user work directory
|
|
|
|
On Error Goto ErrorOcurred
|
|
|
|
aTempURL = GetPathSettings("Work", False)
|
|
|
|
Dim aRightMost as String
|
|
|
|
aRightMost = Right(aTempURL, 1)
|
|
|
|
if aRightMost = "/" Then
|
|
|
|
aTempURL = aTempURL & aTempFileName
|
|
|
|
Else
|
|
|
|
aTempURL = aTempURL & "/" & aTempFileName
|
|
|
|
End If
|
|
|
|
|
|
|
|
While FileExists(aTempURL)
|
|
|
|
aTempURL=Left(aTempURL,(Len(aTempURL)-4)) & "_1.stc"
|
|
|
|
Wend
|
|
|
|
oDocument.storeToURL(aTempURL, NoArgs())
|
|
|
|
Exit Sub
|
|
|
|
|
|
|
|
ErrorOcurred:
|
2017-05-24 11:33:50 -05:00
|
|
|
MsgBox(GetResText("STYLES_1"), 16, GetResText("STYLES_0"))
|
2017-05-21 12:52:57 -05:00
|
|
|
On Local Error Goto 0
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub RestoreCurrentStyles
|
|
|
|
'This sub retrieves the styles from the temporarily save document
|
|
|
|
ToggleWindow(False)
|
|
|
|
On Local Error Goto NoFile
|
|
|
|
If FileExists(aTempURL) Then
|
|
|
|
aOptions(0).Name = "OverwriteStyles"
|
|
|
|
aOptions(0).Value = true
|
|
|
|
oFamilies.LoadStylesFromURL(aTempURL, aOptions())
|
|
|
|
KillTempFile()
|
|
|
|
End If
|
|
|
|
StylesDialog.EndExecute
|
|
|
|
ToggleWindow(True)
|
|
|
|
NOFILE:
|
|
|
|
If Err <> 0 Then
|
|
|
|
Msgbox("Cannot load Document from " & 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>
|