xref: /trunk/main/wizards/source/euro/Soft.xba (revision 10d685eaf05487ae305fb27895e68dff92c96120)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Soft" script:language="StarBasic">Option Explicit
24cdf0e10cSrcweirREM ***** BASIC *****
25cdf0e10cSrcweir
26cdf0e10cSrcweir
27cdf0e10cSrcweirSub CreateStyleEnumeration()
28cdf0e10cSrcweir    EmptySelection()
29cdf0e10cSrcweir    EmptyListbox(DialogModel.lstSelection)
30cdf0e10cSrcweir    CurSheetName = oDocument.CurrentController.GetActiveSheet.Name
31cdf0e10cSrcweir    MakeStyleEnumeration(False)
32cdf0e10cSrcweir    DialogModel.lblSelection.Label = sTEMPLATES
33cdf0e10cSrcweirEnd Sub
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweirSub MakeStyleEnumeration(bAddToListbox as Boolean)
37cdf0e10cSrcweirDim m as integer
38cdf0e10cSrcweirDim aStyleFormat as Object
39cdf0e10cSrcweirDim Stylename as String
40cdf0e10cSrcweir    StyleIndex = -1
41cdf0e10cSrcweir    oStyles = oDocument.StyleFamilies.GetbyIndex(0)
42cdf0e10cSrcweir    For m = 0 To oStyles.count-1
43cdf0e10cSrcweir        oStyle = oStyles.GetbyIndex(m)
44cdf0e10cSrcweir        StyleName = oStyle.Name
45cdf0e10cSrcweir        If CheckFormatType(oStyle) Then
46cdf0e10cSrcweir            If Not bAddToListBox Then
47cdf0e10cSrcweir                AddSingleItemToListbox(DialogModel.lstSelection, Stylename)
48cdf0e10cSrcweir            Else
49cdf0e10cSrcweir                SwitchNumberFormat(ostyle, oFormats, sEuroSign)
50cdf0e10cSrcweir            End If
51cdf0e10cSrcweir            StyleIndex = StyleIndex + 1
52cdf0e10cSrcweir            If StyleIndex &gt; Ubound(StyleRangeAssignMentList()) Then
53cdf0e10cSrcweir                Redim Preserve StyleRangeAssignmentList(StyleIndex)
54cdf0e10cSrcweir            End If
55cdf0e10cSrcweir            StyleRangeAssignmentList(StyleIndex) =  &quot;&lt;STYLENAME&gt;&quot; &amp; Stylename &amp; &quot;&lt;/STYLENAME&gt;&quot; &amp; _
56cdf0e10cSrcweir                                                    &quot;&lt;DEFINED&gt;FALSE&lt;/DEFINED&gt;&quot; &amp; &quot;&lt;RANGES&gt;&lt;/RANGES&gt;&quot; &amp;_
57cdf0e10cSrcweir                                                    &quot;&lt;CELLCOUNT&gt;0&lt;/CELLCOUNT&gt;&quot; &amp;_
58cdf0e10cSrcweir                                                    &quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;
59cdf0e10cSrcweir        End If
60cdf0e10cSrcweir    Next m
61cdf0e10cSrcweir    If StyleIndex &gt; -1 Then
62cdf0e10cSrcweir        Redim Preserve StyleRangeAssignmentList(StyleIndex)
63cdf0e10cSrcweir    Else
64cdf0e10cSrcweir        ReDim StyleRangeAssignmentList()
65cdf0e10cSrcweir    End If
66cdf0e10cSrcweirEnd Sub
67cdf0e10cSrcweir
68cdf0e10cSrcweir
69cdf0e10cSrcweirSub AssignRangestoStyle(StyleList(), SelList())
70cdf0e10cSrcweirDim i as Integer
71cdf0e10cSrcweirDim n as integer
72cdf0e10cSrcweirDim LastIndex as Integer
73cdf0e10cSrcweirDim CurStyleName as String
74cdf0e10cSrcweirDim AssignString as String
75cdf0e10cSrcweir    LastIndex = Ubound(StyleList())
76cdf0e10cSrcweir    StatusValue = 0
77cdf0e10cSrcweir    SetStatusLineText(sStsRELRANGES)
78cdf0e10cSrcweir    For i = 0 To LastIndex
79cdf0e10cSrcweir        CurStyleName = StyleList(i)
80cdf0e10cSrcweir        n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName, 0)
81cdf0e10cSrcweir        AssignString = StyleRangeAssignmentlist(n)
82cdf0e10cSrcweir        If IndexInArray(CurStyleName, SelList()) &lt;&gt; -1 Then
83cdf0e10cSrcweir            &apos; Style is selected
84cdf0e10cSrcweir            If FindPartString(AssignString, &quot;&lt;DEFINED&gt;&quot;, &quot;&lt;/DEFINED&gt;&quot;, 1) = &quot;FALSE&quot; Then
85cdf0e10cSrcweir                AssignString = ReplaceString(AssignString, &quot;&lt;SELECTED&gt;TRUE&lt;/SELECTED&gt;&quot;, &quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;)
86cdf0e10cSrcweir                AssignCellFormatRanges(n, AssignString, CurStyleName)
87cdf0e10cSrcweir            End If
88cdf0e10cSrcweir        Else
89cdf0e10cSrcweir            &apos; Style is not selected
90cdf0e10cSrcweir            If FindPartString(AssignString, &quot;&lt;SELECTED&gt;&quot;, &quot;&lt;/SELECTED&gt;&quot;, 1) = &quot;FALSE&quot; Then
91cdf0e10cSrcweir                DeselectStyle(CurStyleName, n)
92cdf0e10cSrcweir            End If
93cdf0e10cSrcweir        End If
94cdf0e10cSrcweir        IncreaseStatusvalue(SBRELGET/(LastIndex+1))
95cdf0e10cSrcweir    Next i
96cdf0e10cSrcweirEnd Sub
97cdf0e10cSrcweir
98cdf0e10cSrcweir
99cdf0e10cSrcweirSub AssignCellFormatRanges(n as Integer, AssignString as String, CurStyleName as String)
100cdf0e10cSrcweirDim oRanges() as Object
101cdf0e10cSrcweirDim oRange as Object
102cdf0e10cSrcweirDim oRangeAddress
103cdf0e10cSrcweirDim oSheet as Object
104cdf0e10cSrcweirDim StyleCellCount as Long
105cdf0e10cSrcweirDim i as Integer
106cdf0e10cSrcweirDim MaxIndex as Integer
107cdf0e10cSrcweirDim RangeString as String
108cdf0e10cSrcweirDim SheetName as String
109cdf0e10cSrcweirDim RangeName as String
110cdf0e10cSrcweirDim CellCountString as String
111cdf0e10cSrcweir    StyleCellCount = 0
112cdf0e10cSrcweir    RangeString = &quot;&lt;RANGES&gt;&quot;
113cdf0e10cSrcweir    MaxIndex = oSheets.Count-1
114cdf0e10cSrcweir    For i = 0 To MaxIndex
115cdf0e10cSrcweir        oSheet = oSheets(i)
116cdf0e10cSrcweir        SheetName = oSheet.Name
117cdf0e10cSrcweir        oRanges = osheet.CellFormatRanges.CreateEnumeration
118cdf0e10cSrcweir        While oRanges.hasMoreElements
119cdf0e10cSrcweir            oRange = oRanges.NextElement
120cdf0e10cSrcweir            If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
121cdf0e10cSrcweir                If oRange.CellStyle = CurStyleName Then
122cdf0e10cSrcweir                    oRangeAddress = oRange.RangeAddress
123cdf0e10cSrcweir                    RangeName = RetrieveRangeNamefromAddress(oRange)
124cdf0e10cSrcweir                    RangeString = RangeString &amp; RangeName &amp; &quot;,&quot;
125cdf0e10cSrcweir                    StyleCellCount = StyleCellCount + CountRangeCells(oRange)
126cdf0e10cSrcweir                End If
127cdf0e10cSrcweir            End If
128cdf0e10cSrcweir        Wend
129cdf0e10cSrcweir    Next i
130cdf0e10cSrcweir    If StyleCellCount &gt; 0 Then
131cdf0e10cSrcweir        TotCellCount = TotCellCount + StyleCellCount
132cdf0e10cSrcweir        RangeString = RTrimStr(RangeString,&quot;,&quot;)
133cdf0e10cSrcweir        RangeString = RangeString &amp; &quot;&lt;/RANGES&gt;&quot;
134cdf0e10cSrcweir        CellCountString = &quot;&lt;CELLCOUNT&gt;&quot; &amp; StyleCellCount &amp; &quot;&lt;/CELLCOUNT&quot;
135cdf0e10cSrcweir        AssignString = ReplaceString(AssignString, RangeString,&quot;&lt;RANGES&gt;&lt;/RANGES&gt;&quot;)
136cdf0e10cSrcweir        AssignString = ReplaceString(AssignString, CellCountString,&quot;&lt;CELLCOUNT&gt;0&lt;/CELLCOUNT&gt;&quot;)
137cdf0e10cSrcweir    End If
138cdf0e10cSrcweir    AssignString = ReplaceString(AssignString, &quot;&lt;DEFINED&gt;TRUE&lt;/DEFINED&gt;&quot;, &quot;&lt;DEFINED&gt;FALSE&lt;/DEFINED&gt;&quot;)
139cdf0e10cSrcweir    StyleRangeAssignmentList(n) = AssignString
140cdf0e10cSrcweirEnd Sub
141cdf0e10cSrcweir
142cdf0e10cSrcweir
143cdf0e10cSrcweir&apos; deletes a styletemplate from the Collection that selects the ranges
144cdf0e10cSrcweirSub DeselectStyle(DeSelStyleName as String, n as Integer)
145cdf0e10cSrcweirDim i as Integer
146cdf0e10cSrcweirDim RangeName as String
147cdf0e10cSrcweirDim SelectString as String
148cdf0e10cSrcweirDim AssignString as String
149cdf0e10cSrcweirDim StyleRangeList() as String
150cdf0e10cSrcweirDim MaxIndex as Integer
151cdf0e10cSrcweir    SelectString =&quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;
152cdf0e10cSrcweir    AssignString = StyleRangeAssignmentList(n)
153cdf0e10cSrcweir    RangeString = FindPartString(AssignString,&quot;&lt;RANGES&gt;&quot;,&quot;&lt;/RANGES&gt;&quot;,1)
154cdf0e10cSrcweir    StyleRangeList() = ArrayoutofString(RangeString,&quot;,&quot;)
155cdf0e10cSrcweir    MaxIndex = Ubound(StyleRangeList())
156cdf0e10cSrcweir    For i = 0 To MaxIndex
157cdf0e10cSrcweir        RangeName = StyleRangeList(i)
158cdf0e10cSrcweir        If oSelRanges.HasbyName(RangeName) Then
159cdf0e10cSrcweir            oSelRanges.RemovebyName(RangeName)
160cdf0e10cSrcweir        End If
161cdf0e10cSrcweir    Next i
162cdf0e10cSrcweir    AssignString = ReplaceString(AssignString, &quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;, &quot;&lt;SELECTED&gt;TRUE&lt;/SELECTED&gt;&quot;)
163cdf0e10cSrcweir    StyleRangeAssignmentList(n) = AssignString
164cdf0e10cSrcweirEnd Sub
165cdf0e10cSrcweir
166cdf0e10cSrcweir
167cdf0e10cSrcweirFunction RetrieveRangeNamefromAddress(oRange as Object) as String
168cdf0e10cSrcweirDim Rangename as String
169cdf0e10cSrcweirDim oAddressRanges as Object
170cdf0e10cSrcweir    oAddressRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
171cdf0e10cSrcweir    oAddressRanges.InsertbyName(&quot;&quot;,oRange)
172cdf0e10cSrcweir    Rangename = oAddressRanges.RangeAddressesasString
173cdf0e10cSrcweir&apos;  Msgbox &quot;Adresse: &quot; &amp; oRangeAddress.StartColumn &amp; &quot; ; &quot; &amp; oRangeAddress.EndColumn &amp; &quot; ; &quot; &amp; oRangeAddress.StartRow &amp; &quot; ; &quot; &amp; oRangeAddress.EndRow &amp; chr(13) &amp; RangeName
174cdf0e10cSrcweir&apos;  oAddressRanges.RemovebyName(RangeName)
175cdf0e10cSrcweir    RetrieveRangeNamefromAddress = Rangename
176cdf0e10cSrcweirEnd Function
177cdf0e10cSrcweir
178cdf0e10cSrcweir
179cdf0e10cSrcweir&apos; creates a sheet object from an according sectionname
180cdf0e10cSrcweirFunction RetrieveSheetoutofRangeName(TableText as String)
181cdf0e10cSrcweirDim DescriptionList() as String
182cdf0e10cSrcweirDim SheetName as String
183cdf0e10cSrcweirDim MaxIndex as integer
184cdf0e10cSrcweir    &apos; find out in which sheet the range is
185cdf0e10cSrcweir    DescriptionList() = ArrayOutofString(TableText,&quot;.&quot;,MaxIndex)
186cdf0e10cSrcweir    SheetName = DescriptionList(0)
187cdf0e10cSrcweir    SheetName = DeleteStr(SheetName,&quot;&apos;&quot;)
188cdf0e10cSrcweir    &apos; set the viewcursor on this sheet
189cdf0e10cSrcweir    RetrieveSheetoutofRangeName = oSheets.GetbyName(SheetName)
190cdf0e10cSrcweirEnd Function
191cdf0e10cSrcweir
192cdf0e10cSrcweir
193cdf0e10cSrcweir&apos; creates a rangeobject from an according rangename
194cdf0e10cSrcweirFunction RetrieveRangeoutofRangeName(TableText as String)
195cdf0e10cSrcweir    oSheet = RetrieveSheetoutofRangeName(TableText)
196cdf0e10cSrcweir    oRange = oSheet.GetCellRangebyName(TableText)
197cdf0e10cSrcweir    RetrieveRangeoutofRangeName = oRange
198cdf0e10cSrcweirEnd Function
199cdf0e10cSrcweir
200cdf0e10cSrcweir
201cdf0e10cSrcweirSub ConvertTheSoftWay(StyleList(), bDeSelect as Boolean)
202cdf0e10cSrcweirDim i as Integer
203cdf0e10cSrcweirDim l as Integer
204cdf0e10cSrcweirDim s as Integer
205cdf0e10cSrcweirDim n as Integer
206cdf0e10cSrcweirDim CurStyleName as String
207cdf0e10cSrcweirDim RangeName as String
208cdf0e10cSrcweirDim OldStatusValue as Integer
209cdf0e10cSrcweirDim LastIndex as Integer
210cdf0e10cSrcweirDim oSelListbox as Object
211cdf0e10cSrcweirDim StyleRangeList() as String
212cdf0e10cSrcweirDim MaxIndex as Integer
213cdf0e10cSrcweir    oSelListbox = DialogConvert.GetControl(&quot;lstSelection&quot;)
214cdf0e10cSrcweir    LastIndex = Ubound(StyleList())
215cdf0e10cSrcweir    OldStatusValue = StatusValue
216cdf0e10cSrcweir    For i = 0 To LastIndex
217cdf0e10cSrcweir        CurStyleName = StyleList(i)
218cdf0e10cSrcweir        oStyle = oStyles.GetbyName(CurStyleName)
219cdf0e10cSrcweir        StyleRangeList() = GetAssignedRanges(CurStyleName, n)
220cdf0e10cSrcweir        MaxIndex = Ubound(StyleRangeList())
221cdf0e10cSrcweir        For s = 0 To MaxIndex
222cdf0e10cSrcweir            RangeName = StyleRangeList(s)
223cdf0e10cSrcweir            oRange = RetrieveRangeoutofRangeName(RangeName)
224cdf0e10cSrcweir            If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
225cdf0e10cSrcweir                &apos; Range is hard formatted
226cdf0e10cSrcweir                ConvertCellCurrencies(oRange)
227cdf0e10cSrcweir                CurCellCount = CountRangeCells(oRange)
228cdf0e10cSrcweir            End If
229cdf0e10cSrcweir            IncreaseStatusvalue((CurCellCount/TotCellCount)*(95-OldStatusValue))
230cdf0e10cSrcweir            If bDeSelect Then
231cdf0e10cSrcweir                &apos; Note: On Problems see Bug #73157
232cdf0e10cSrcweir                If oSelRanges.HasbyName(RangeName) Then
233cdf0e10cSrcweir                    oSelRanges.RemovebyName(RangeName)
234cdf0e10cSrcweir                    oDocument.CurrentController.Select(oSelRanges)
235cdf0e10cSrcweir                End If
236cdf0e10cSrcweir            End If
237cdf0e10cSrcweir        Next s
238cdf0e10cSrcweir        SwitchNumberFormat(ostyle, oFormats, sEuroSign)
239cdf0e10cSrcweir        StyleRangeAssignmentList(n) = &quot;&quot;
240cdf0e10cSrcweir        l = GetItemPos(oSelListBox.Model, CurStyleName)
241cdf0e10cSrcweir        oSelListbox.RemoveItems(l,1)
242cdf0e10cSrcweir    Next
243cdf0e10cSrcweirEnd Sub
244cdf0e10cSrcweir
245cdf0e10cSrcweir
246cdf0e10cSrcweirFunction GetAssignedRanges(CurStyleName as String, n as Integer)
247cdf0e10cSrcweirDim StyleRangeList() as String
248cdf0e10cSrcweirDim RangeString as String
249cdf0e10cSrcweirDim AssignString as String
250cdf0e10cSrcweir    n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName, 0)
251cdf0e10cSrcweir    If n &lt;&gt; -1 Then
252cdf0e10cSrcweir        AssignString = StyleRangeAssignmentList(n)
253cdf0e10cSrcweir        RangeString = FindPartString(AssignString,&quot;&lt;RANGES&gt;&quot;, &quot;&lt;/RANGES&gt;&quot;,1)
254cdf0e10cSrcweir        If RangeString &lt;&gt; &quot;&quot; Then
255cdf0e10cSrcweir            StyleRangeList() = ArrayoutofString(RangeString,&quot;,&quot;)
256cdf0e10cSrcweir        End If
257cdf0e10cSrcweir    End If
258cdf0e10cSrcweir    GetAssignedRanges() = StyleRangeList()
259cdf0e10cSrcweirEnd Function</script:module>
260