1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="beans_XMultiPropertySet" script:language="StarBasic">
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski
6*b1cdbd2cSJim Jagielski'*************************************************************************
7*b1cdbd2cSJim Jagielski'
8*b1cdbd2cSJim Jagielski'  Licensed to the Apache Software Foundation (ASF) under one
9*b1cdbd2cSJim Jagielski'  or more contributor license agreements.  See the NOTICE file
10*b1cdbd2cSJim Jagielski'  distributed with this work for additional information
11*b1cdbd2cSJim Jagielski'  regarding copyright ownership.  The ASF licenses this file
12*b1cdbd2cSJim Jagielski'  to you under the Apache License, Version 2.0 (the
13*b1cdbd2cSJim Jagielski'  "License"); you may not use this file except in compliance
14*b1cdbd2cSJim Jagielski'  with the License.  You may obtain a copy of the License at
15*b1cdbd2cSJim Jagielski'
16*b1cdbd2cSJim Jagielski'    http://www.apache.org/licenses/LICENSE-2.0
17*b1cdbd2cSJim Jagielski'
18*b1cdbd2cSJim Jagielski'  Unless required by applicable law or agreed to in writing,
19*b1cdbd2cSJim Jagielski'  software distributed under the License is distributed on an
20*b1cdbd2cSJim Jagielski'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*b1cdbd2cSJim Jagielski'  KIND, either express or implied.  See the License for the
22*b1cdbd2cSJim Jagielski'  specific language governing permissions and limitations
23*b1cdbd2cSJim Jagielski'  under the License.
24*b1cdbd2cSJim Jagielski'
25*b1cdbd2cSJim Jagielski'*************************************************************************
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski' Be sure that all variables are dimensioned:
32*b1cdbd2cSJim Jagielskioption explicit
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim JagielskiDim nCB1Val As Integer, nCB2Val As Integer
36*b1cdbd2cSJim Jagielski
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim JagielskiSub RunTest()
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski'*************************************************************************
41*b1cdbd2cSJim Jagielski' INTERFACE:
42*b1cdbd2cSJim Jagielski' com.sun.star.beans.XMultiPropertySet
43*b1cdbd2cSJim Jagielski'*************************************************************************
44*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
45*b1cdbd2cSJim Jagielski    Dim bOK As Boolean
46*b1cdbd2cSJim Jagielski    Dim oPropertySetInfo As Object
47*b1cdbd2cSJim Jagielski    Dim oProperties As Variant
48*b1cdbd2cSJim Jagielski    Dim aProp(0 to 1) As new com.sun.star.beans.PropertyValue
49*b1cdbd2cSJim Jagielski    Dim cType As String
50*b1cdbd2cSJim Jagielski    Dim oListener1 As Object, oListener2 As Object
51*b1cdbd2cSJim Jagielski    Dim n As Integer, nMem As Integer, nIndex As Integer
52*b1cdbd2cSJim Jagielski    Dim m As Integer
53*b1cdbd2cSJim Jagielski    Dim bFound As Boolean
54*b1cdbd2cSJim Jagielski    Dim nCount As Integer
55*b1cdbd2cSJim Jagielski    Dim bBoolean As Boolean
56*b1cdbd2cSJim Jagielski    Dim nInteger As Integer
57*b1cdbd2cSJim Jagielski    Dim nLong As Long
58*b1cdbd2cSJim Jagielski    Dim nSingle As Single
59*b1cdbd2cSJim Jagielski    Dim nDouble As Double
60*b1cdbd2cSJim Jagielski    Dim vMemVal As Variant
61*b1cdbd2cSJim Jagielski    Dim nCB1ValMem As Integer
62*b1cdbd2cSJim Jagielski    Dim nCB2ValMem As Integer
63*b1cdbd2cSJim Jagielski
64*b1cdbd2cSJim Jagielski    bOK = true
65*b1cdbd2cSJim Jagielski    bFound = false
66*b1cdbd2cSJim Jagielski    nCB1Val = 0
67*b1cdbd2cSJim Jagielski    nCB2Val = 0
68*b1cdbd2cSJim Jagielski    m = 0
69*b1cdbd2cSJim Jagielski    oPropertySetInfo = oObj.GetPropertySetInfo
70*b1cdbd2cSJim Jagielski    oProperties = oPropertySetInfo.Properties
71*b1cdbd2cSJim Jagielski    nCount = uBound(oProperties)
72*b1cdbd2cSJim Jagielski    Out.Log("The Object has " + nCount + " properties"
73*b1cdbd2cSJim Jagielski
74*b1cdbd2cSJim Jagielski    Out.Log("Create linsteners...")
75*b1cdbd2cSJim Jagielski    oListener1 = createUNOListener("CB1_","com.sun.star.beans.XPropertiesChangeListener")
76*b1cdbd2cSJim Jagielski    oListener2 = createUNOListener("CB2_","com.sun.star.beans.XPropertiesChangeListener")
77*b1cdbd2cSJim Jagielski    Out.Log("oListener1 and oListener2 created"
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski    'create sequences of Propertie-Names and Values
80*b1cdbd2cSJim Jagielski    'fist get the amount of valid properties
81*b1cdbd2cSJim Jagielski    for n = 0 to (nCount)
82*b1cdbd2cSJim Jagielski        'look for readonly-properties
83*b1cdbd2cSJim Jagielski        If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.READONLY) = 0 Then
84*b1cdbd2cSJim Jagielski            'look for MAYBEVOID-Properties
85*b1cdbd2cSJim Jagielski            If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.MAYBEVOID) = 0 Then
86*b1cdbd2cSJim Jagielski                'is the Property testable
87*b1cdbd2cSJim Jagielski                m = m + 1
88*b1cdbd2cSJim Jagielski            End If
89*b1cdbd2cSJim Jagielski        End If
90*b1cdbd2cSJim Jagielski    next n
91*b1cdbd2cSJim Jagielski
92*b1cdbd2cSJim Jagielski    Out.Log("Amount of testable properites (without readonly and MAYBEVOID) is " + m)
93*b1cdbd2cSJim Jagielski
94*b1cdbd2cSJim Jagielski    'now store the names in sProperites
95*b1cdbd2cSJim Jagielski    Dim searchProperties(0 to m-1) As String
96*b1cdbd2cSJim Jagielski    m = 0
97*b1cdbd2cSJim Jagielski    for n = 0 to (nCount)
98*b1cdbd2cSJim Jagielski    'kick off readonly-properties
99*b1cdbd2cSJim Jagielski        If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.READONLY) = 0 Then
100*b1cdbd2cSJim Jagielski        'kick off MYBEVOID-Properties
101*b1cdbd2cSJim Jagielski            If (oProperties(n).Attributes AND com.sun.star.beans.PropertyAttribute.MAYBEVOID) = 0 Then
102*b1cdbd2cSJim Jagielski                searchProperties(m) = oProperties(n).Name
103*b1cdbd2cSJim Jagielski                Out.Log("" + m + " " + searchProperties(m) + " " + oObj.getPropertySetInfo.getPropertyByName(searchProperties(m)).Type.Name + " " + n)
104*b1cdbd2cSJim Jagielski                Dim pVal As Variant
105*b1cdbd2cSJim Jagielski
106*b1cdbd2cSJim Jagielski                pVal = oObj.getPropertyValue(searchProperties(m))
107*b1cdbd2cSJim Jagielski                oObj.setPropertyValues(Array(searchProperties(m)), Array(pVal))
108*b1cdbd2cSJim Jagielski                m = m + 1
109*b1cdbd2cSJim Jagielski            End If
110*b1cdbd2cSJim Jagielski        End If
111*b1cdbd2cSJim Jagielski    next n
112*b1cdbd2cSJim Jagielski    nCount = m - 1
113*b1cdbd2cSJim Jagielski
114*b1cdbd2cSJim Jagielski    Dim sProperties(0 to nCount) As String
115*b1cdbd2cSJim Jagielski    Dim vValues(0 to nCount) As Variant
116*b1cdbd2cSJim Jagielski    For n = 0 to nCount
117*b1cdbd2cSJim Jagielski        sProperties(n) = searchProperties(n)
118*b1cdbd2cSJim Jagielski    next n
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielski    vValues() = oObj.getPropertyValues(sProperties())
121*b1cdbd2cSJim Jagielski
122*b1cdbd2cSJim Jagielski    'add ChangeListener
123*b1cdbd2cSJim Jagielski    oObj.addPropertiesChangeListener(sProperties(),oListener1)
124*b1cdbd2cSJim Jagielski    oObj.addPropertiesChangeListener(sProperties(),oListener2)
125*b1cdbd2cSJim Jagielski    Out.Log("oListener1 and oListener2 added to object")
126*b1cdbd2cSJim Jagielski
127*b1cdbd2cSJim Jagielski    nIndex = 0
128*b1cdbd2cSJim Jagielski    nMem = nIndex
129*b1cdbd2cSJim Jagielski    'find at first a Boolean Value, if not available a String Property
130*b1cdbd2cSJim Jagielski    While (NOT bFound) AND ((nCount &gt;= nIndex))
131*b1cdbd2cSJim Jagielski        'get the property-type
132*b1cdbd2cSJim Jagielski        cType = oObj.getPropertySetInfo.getPropertyByName(sProperties(nIndex)).Type.Name
133*b1cdbd2cSJim Jagielski        If cType = "boolean" Then ' it is a Boolean Proerty
134*b1cdbd2cSJim Jagielski            bFound = true
135*b1cdbd2cSJim Jagielski            nMem = nIndex
136*b1cdbd2cSJim Jagielski        else
137*b1cdbd2cSJim Jagielski            If cType = "string" Then ' it is a String Property
138*b1cdbd2cSJim Jagielski                nMem = nIndex
139*b1cdbd2cSJim Jagielski            end if
140*b1cdbd2cSJim Jagielski        end if
141*b1cdbd2cSJim Jagielski        nIndex = nIndex + 1
142*b1cdbd2cSJim Jagielski    Wend
143*b1cdbd2cSJim Jagielski
144*b1cdbd2cSJim Jagielski    nIndex = nIndex - 1
145*b1cdbd2cSJim Jagielski    Out.Log("Property to change is: """ + sProperties(nIndex) + """ Type: """ + oObj.getPropertySetInfo.getPropertyByName(sProperties(nIndex)).Type.Name + """")
146*b1cdbd2cSJim Jagielski    nIndex = nMem
147*b1cdbd2cSJim Jagielski
148*b1cdbd2cSJim Jagielski    'memory the old Value
149*b1cdbd2cSJim Jagielski    vMemVal = vValues(nIndex)
150*b1cdbd2cSJim Jagielski
151*b1cdbd2cSJim Jagielski    'change a value of a property, hopefully a boolean or string property
152*b1cdbd2cSJim Jagielski    select case VarType(vValues(nIndex)
153*b1cdbd2cSJim Jagielski        case 11 'boolean
154*b1cdbd2cSJim Jagielski            bBoolean = NOT vValues(nIndex)
155*b1cdbd2cSJim Jagielski            vValues(nIndex) = bBoolean
156*b1cdbd2cSJim Jagielski        case 2 'integer
157*b1cdbd2cSJim Jagielski            nInteger = vValues(nIndex) + 1
158*b1cdbd2cSJim Jagielski            vValues(nIndex) = nInteger
159*b1cdbd2cSJim Jagielski        case 3 'long
160*b1cdbd2cSJim Jagielski            nLong = vValues(nIndex) + 1
161*b1cdbd2cSJim Jagielski            vValues(nIndex) = nLong
162*b1cdbd2cSJim Jagielski        case 4 'single
163*b1cdbd2cSJim Jagielski            nSingle = vValues(nIndex) + 1
164*b1cdbd2cSJim Jagielski            vValues(nIndex) = nSingle
165*b1cdbd2cSJim Jagielski        case 5 'double
166*b1cdbd2cSJim Jagielski            nDouble = vValues(nIndex) + 1
167*b1cdbd2cSJim Jagielski            vValues(nIndex) = nDouble
168*b1cdbd2cSJim Jagielski        case 8 'string
169*b1cdbd2cSJim Jagielski            vValues(nIndex) = vValues(nIndex) + cIfcShortName
170*b1cdbd2cSJim Jagielski    end select
171*b1cdbd2cSJim Jagielski
172*b1cdbd2cSJim Jagielski    Test.StartMethod("getPropertySetInfo()")
173*b1cdbd2cSJim Jagielski    bOK = bOK AND (uBound(oProperties) &gt; 0)
174*b1cdbd2cSJim Jagielski    Test.MethodTested("getPropertySetInfo()", bOK)
175*b1cdbd2cSJim Jagielski
176*b1cdbd2cSJim Jagielski    Test.StartMethod("getPropertyValues()")
177*b1cdbd2cSJim Jagielski    bOK = bOK AND (uBound(vValues()) &gt; 0)
178*b1cdbd2cSJim Jagielski    Test.MethodTested("getPropertyValues()", bOK)
179*b1cdbd2cSJim Jagielski
180*b1cdbd2cSJim Jagielski    Test.StartMethod("setPropertyValues()")
181*b1cdbd2cSJim Jagielski    oObj.setPropertyValues(sProperties(), vValues())
182*b1cdbd2cSJim Jagielski    vValues() = oObj.getPropertyValues(sProperties())
183*b1cdbd2cSJim Jagielski    bOK = bOK AND (vValues(nIndex) &lt;&gt; vMemVal)
184*b1cdbd2cSJim Jagielski    Test.MethodTested("setPropertyValues()", bOK)
185*b1cdbd2cSJim Jagielski
186*b1cdbd2cSJim Jagielski    Test.StartMethod("addPropertiesChangeListener()")
187*b1cdbd2cSJim Jagielski    bOK = (nCB1Val &gt;= 1) AND (nCB2Val &gt;= 1)
188*b1cdbd2cSJim Jagielski    nCB1ValMem = nCB1Val
189*b1cdbd2cSJim Jagielski    nCB2ValMem = nCb2Val
190*b1cdbd2cSJim Jagielski    Test.MethodTested("addPropertiesChangeListener()", bOK)
191*b1cdbd2cSJim Jagielski
192*b1cdbd2cSJim Jagielski    'fire !!!
193*b1cdbd2cSJim Jagielski    Out.Log("Try to fire property change event...")
194*b1cdbd2cSJim Jagielski    oObj.firePropertiesChangeEvent(sProperties(),oListener1)
195*b1cdbd2cSJim Jagielski    oObj.firePropertiesChangeEvent(sProperties(),oListener2)
196*b1cdbd2cSJim Jagielski
197*b1cdbd2cSJim Jagielski    Test.StartMethod("firePropertiesChangeEvent()")
198*b1cdbd2cSJim Jagielski    bOK = (nCB1Val &gt;= nCB1ValMem) AND (nCB2Val &gt;= nCB2ValMem)
199*b1cdbd2cSJim Jagielski    Test.MethodTested("firePropertiesChangeEvent()", bOK)
200*b1cdbd2cSJim Jagielski    nCB1ValMem = nCB1Val
201*b1cdbd2cSJim Jagielski    nCB2ValMem = nCb2Val
202*b1cdbd2cSJim Jagielski
203*b1cdbd2cSJim Jagielski
204*b1cdbd2cSJim Jagielski    'remove one Listener and fire
205*b1cdbd2cSJim Jagielski    Test.StartMethod("removePropertiesChangeListener()")
206*b1cdbd2cSJim Jagielski    oObj.removePropertiesChangeListener(oListener1)
207*b1cdbd2cSJim Jagielski    Out.Log("oListener1 removed")
208*b1cdbd2cSJim Jagielski    select case VarType(vValues(nIndex)
209*b1cdbd2cSJim Jagielski        case 11 'boolean
210*b1cdbd2cSJim Jagielski            bBoolean = NOT vValues(nIndex)
211*b1cdbd2cSJim Jagielski            vValues(nIndex) = bBoolean
212*b1cdbd2cSJim Jagielski        case 2 'integer
213*b1cdbd2cSJim Jagielski            nInteger = vValues(nIndex) + 1
214*b1cdbd2cSJim Jagielski            vValues(nIndex) = nInteger
215*b1cdbd2cSJim Jagielski        case 3 'long
216*b1cdbd2cSJim Jagielski            nLong = vValues(nIndex) + 1
217*b1cdbd2cSJim Jagielski            vValues(nIndex) = nLong
218*b1cdbd2cSJim Jagielski        case 4 'single
219*b1cdbd2cSJim Jagielski            nSingle = vValues(nIndex) + 1
220*b1cdbd2cSJim Jagielski            vValues(nIndex) = nSingle
221*b1cdbd2cSJim Jagielski        case 5 'double
222*b1cdbd2cSJim Jagielski            nDouble = vValues(nIndex) + 1
223*b1cdbd2cSJim Jagielski            vValues(nIndex) = nDouble
224*b1cdbd2cSJim Jagielski        case 8 'string
225*b1cdbd2cSJim Jagielski            vValues(nIndex) = vValues(nIndex) + cIfcShortName
226*b1cdbd2cSJim Jagielski    end select
227*b1cdbd2cSJim Jagielski
228*b1cdbd2cSJim Jagielski    Out.Log("The property '" + sProperties(nIndex) + "' was changed")
229*b1cdbd2cSJim Jagielski
230*b1cdbd2cSJim Jagielski    oObj.setPropertyValues(sProperties(), vValues())
231*b1cdbd2cSJim Jagielski
232*b1cdbd2cSJim Jagielski    bOK = (nCB1Val = nCB1ValMem) AND (nCB2Val &gt;= nCB2ValMem)
233*b1cdbd2cSJim Jagielski    Test.MethodTested("removePropertiesChangeListener()", bOK)
234*b1cdbd2cSJim Jagielski
235*b1cdbd2cSJim Jagielski    'remove the last Listener
236*b1cdbd2cSJim Jagielski    oObj.removePropertiesChangeListener(oListener2)
237*b1cdbd2cSJim Jagielski    Out.Log("oListener2 removed")
238*b1cdbd2cSJim Jagielski
239*b1cdbd2cSJim Jagielski
240*b1cdbd2cSJim JagielskiExit Sub
241*b1cdbd2cSJim JagielskiErrHndl:
242*b1cdbd2cSJim Jagielski    Test.Exception()
243*b1cdbd2cSJim Jagielski    bOK = false
244*b1cdbd2cSJim Jagielski    resume next
245*b1cdbd2cSJim JagielskiEnd Sub
246*b1cdbd2cSJim Jagielski'callback routine called firePropertiesChangeEvent
247*b1cdbd2cSJim JagielskiSub CB1_propertiesChange
248*b1cdbd2cSJim Jagielski    Out.Log("CallBack for Listener 1 was called.")
249*b1cdbd2cSJim Jagielski    nCB1Val = nCB1Val + 1
250*b1cdbd2cSJim Jagielskiend Sub
251*b1cdbd2cSJim Jagielski
252*b1cdbd2cSJim JagielskiSub CB2_propertiesChange
253*b1cdbd2cSJim Jagielski    Out.Log("CallBack for Listener 2 was called.")
254*b1cdbd2cSJim Jagielski    nCB2Val = nCB2Val + 1
255*b1cdbd2cSJim Jagielskiend Sub
256*b1cdbd2cSJim Jagielski</script:module>
257