xref: /AOO41X/main/wizards/source/webwizard/Common.xba (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Common" script:language="StarBasic">REM  *****  BASIC  *****
24Option Explicit
25
26
27Function LoadNewStyles(oDocument as Object, oDialogModel as Object, CurIndex as Integer, SourceFile as String, Styles() as String, TextureDir as String) as Boolean
28Dim BackGroundURL as String
29Dim oBackGraph as Object
30Dim i, BackColor as Long
31Dim bLocWithBackGraphic as Boolean
32Dim oFamilies as Object, oFamily as Object&apos;, oStyle as Object
33Dim StylesOptions(0) as New com.sun.star.beans.PropertyValue
34
35    If SourceFile &lt;&gt; &quot;&quot; Then
36        StylesOptions(0).Name = &quot;OverwriteStyles&quot;
37        StylesOptions(0).Value = True
38        oDocument.StyleFamilies.LoadStylesFromURL(SourceFile, StylesOptions())
39    End If
40
41    &apos; Read array fields for background, bullet &amp; graphics
42    BackgroundURL = Styles(CurIndex, 7)
43    If Left(BackgroundURL, 1) &lt;&gt; &quot;#&quot; Then
44        BackgroundURL = TextureDir + BackgroundURL
45        bLocWithBackGraphic = True
46    Else
47        BackColor = clng(&quot;&amp;H&quot; &amp; Right(BackgroundURL, Len(BackgroundURL)-1))
48        bLocWithBackGraphic = False
49    End If
50    oFamilies = oDocument.StyleFamilies
51    oFamily = oFamilies.GetbyName(&quot;PageStyles&quot;)
52    For i = 0 To oFamily.Count - 1
53        If oFamily.GetByIndex(i).IsInUse Then
54            oStyle = oFamily.GetbyIndex(i)
55            If oStyle.PropertySetInfo.HasPropertybyName(&quot;BackGraphicURL&quot;) Then
56                If Left(BackgroundURL, 1) = &quot;#&quot; Then
57                    oStyle.BackGraphicURL = &quot;&quot;
58                    oStyle.BackColor = BackColor
59                    oStyle.BackTransparent = False
60                Else
61                    oStyle.BackGraphicUrl = BackGroundURL
62                    SetTileBackgroundorNot(oDialogModel, oStyle)
63                End If
64                Exit For
65            End If
66        End If
67    Next i
68    LoadNewStyles() = bLocWithBackGraphic
69ErrorOcurred:
70    If Err &lt;&gt; 0 Then
71        MsgBox (WebWiz_gErrWhileLoadStyles$, 16, WebWiz_gWizardName$)
72        RESUME EXITSUB
73EXITSUB:
74    End If
75End Function
76
77
78
79Sub ChangeBackGraphicUrl(SavePath as String)
80Dim oPageFamily as Object
81Dim i as Integer
82    oPageFamily = oBaseDocument.StyleFamilies.GetbyName(&quot;PageStyles&quot;)
83    For i = 0 To oPageFamily.Count - 1
84        If oPageFamily.GetByIndex(i).IsInUse Then
85            oStyle = oPageFamily.GetbyIndex(i)
86            If oStyle.PropertySetInfo.HasPropertybyName(&quot;BackGraphicURL&quot;) Then
87                If oStyle.BackGraphicUrl &lt;&gt; &quot;&quot; Then
88                    oStyle.BackGraphicUrl = CopyFile(oStyle.BackGraphicUrl, SavePath)
89                    Exit Sub
90                End If
91            End If
92        End If
93    Next i
94End Sub
95
96
97Sub SetBackGraphicStyle(oEvent as Object)
98Dim oFamilies as Object
99Dim oFamily as Object
100Dim i as Integer
101Dim oOptModel as Object
102Dim iBackgroundValue as Integer
103Dim oLocDocument as Object
104    ooptModel = oEvent.Source.Model
105    iBackgroundValue = Val(ooptModel.Tag)
106    oLocDocument = StarDesktop.ActiveFrame.Controller.Model
107    oLocDocument.LockControllers
108    oFamilies = oLocDocument.StyleFamilies
109    oFamily = oFamilies.GetbyName(&quot;PageStyles&quot;)
110    For i = 0 To oFamily.Count - 1
111        If oFamily.GetByIndex(i).IsInUse Then
112            oStyle = oFamily.GetbyIndex(i)
113            If oStyle.PropertySetInfo.HasPropertybyName(&quot;BackGraphicURL&quot;) Then
114                oStyle.BackGraphicLocation = iBackgroundValue
115            End If
116        End If
117    Next i
118    oLocDocument.UnlockControllers
119End Sub
120
121
122Sub SetTileBackgroundorNot(DialogModel as Object, oStyle as Object)
123    If Not IsNull(DialogModel) Then
124        If DialogModel.optTiled.State = 1 Then
125            oStyle.BackGraphicLocation = com.sun.star.style.GraphicLocation.TILED
126        Else
127            oStyle.BackGraphicLocation = com.sun.star.style.GraphicLocation.AREA
128        End If
129    End If
130End Sub
131
132
133Sub ToggleOptionButtons(DialogModel as Object, bDoEnable as Integer)
134    If Not IsNull(DialogModel) Then
135        DialogModel.optTiled.Enabled = bDoEnable
136        DialogModel.optArea.Enabled = bDoEnable
137        DialogModel.hlnBackground.Enabled = bDoEnable
138    End If
139End Sub
140
141
142Function GetCurIndex(oListbox as Object, sList() as String, FileIndex as Integer)
143Dim i as Integer
144Dim n as Integer
145Dim SelValue as String
146Dim MaxIndex as Integer
147    If IsNull(oListBox) Then
148        &apos; Startup for WebWizard
149        SelValue = sList(0,1)
150    Else
151        n = oListbox.SelectedItems(0)
152        SelValue = oListbox.StringItemList(n)
153    End If
154    &apos; Find field index for chosen list entry
155    MaxIndex = Ubound(sList)
156    For i = 0 To MaxIndex
157        If sList(i,1) = SelValue Then
158            FileStr = sList(i, FileIndex)
159            Exit For
160        End If
161    Next
162    GetCurIndex = i
163End Function
164
165</script:module>
166