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