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="view_XSelectionSupplier" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*3709053cSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*3709053cSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*3709053cSAndrew Rist'  distributed with this work for additional information
11*3709053cSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*3709053cSAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*3709053cSAndrew Rist'  "License"); you may not use this file except in compliance
14*3709053cSAndrew Rist'  with the License.  You may obtain a copy of the License at
15*3709053cSAndrew Rist'
16*3709053cSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*3709053cSAndrew Rist'
18*3709053cSAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*3709053cSAndrew Rist'  software distributed under the License is distributed on an
20*3709053cSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*3709053cSAndrew Rist'  KIND, either express or implied.  See the License for the
22*3709053cSAndrew Rist'  specific language governing permissions and limitations
23*3709053cSAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29*3709053cSAndrew Rist
30*3709053cSAndrew Rist
31cdf0e10cSrcweir' Be sure that all variables are dimensioned:
32cdf0e10cSrcweiroption explicit
33cdf0e10cSrcweir
34cdf0e10cSrcweir'*************************************************************************
35cdf0e10cSrcweir' This Interface/Service test depends on the following GLOBAL variables,
36cdf0e10cSrcweir' which must be specified in the object creation:
37cdf0e10cSrcweir
38cdf0e10cSrcweir'     - Global SelectableObj1 As Object
39cdf0e10cSrcweir'     - Global SelectableObj2 As Object
40cdf0e10cSrcweir
41cdf0e10cSrcweir'*************************************************************************
42cdf0e10cSrcweir
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir
46cdf0e10cSrcweirDim nCB1Val, nCB2Val As Integer
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweirSub RunTest()
50cdf0e10cSrcweir
51cdf0e10cSrcweir'*************************************************************************
52cdf0e10cSrcweir' INTERFACE:
53cdf0e10cSrcweir' com.sun.star.view.XSelectionSupplier
54cdf0e10cSrcweir'*************************************************************************
55cdf0e10cSrcweirOn Error Goto ErrHndl
56cdf0e10cSrcweir    Dim bOK, bSelected As Boolean
57cdf0e10cSrcweir    Dim oListener1, oListener2, oSelection As Object
58cdf0e10cSrcweir
59cdf0e10cSrcweir    Out.Log("creating two Listeners")
60cdf0e10cSrcweir    oListener1 = createUNOListener("CB1_", "com.sun.star.view.XSelectionChangeListener")
61cdf0e10cSrcweir    oListener2 = createUNOListener("CB2_", "com.sun.star.view.XSelectionChangeListener")
62cdf0e10cSrcweir    bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2)
63cdf0e10cSrcweir    Out.Log("Listeners creation : " &amp; bOK)
64cdf0e10cSrcweir
65cdf0e10cSrcweir    Test.StartMethod("select()")
66cdf0e10cSrcweir    bOK = true
67cdf0e10cSrcweir    out.log("Trying to select ...")
68cdf0e10cSrcweir    bOK = bOK AND oObj.select(SelectableObj1)
69cdf0e10cSrcweir    Test.MethodTested("select()", bOK)
70cdf0e10cSrcweir
71cdf0e10cSrcweir    Test.StartMethod("getSelection()")
72cdf0e10cSrcweir    bOK = true
73cdf0e10cSrcweir    oSelection = oObj.getSelection()
74cdf0e10cSrcweir    bOK = bOK AND NOT isNULL(oSelection)
75cdf0e10cSrcweir
76cdf0e10cSrcweir    ' The selection is either specified by an object which is contained
77cdf0e10cSrcweir    ' in the component to which the view belongs or it is an interface of a
78cdf0e10cSrcweir    ' collection which contains such objects.
79cdf0e10cSrcweir
80cdf0e10cSrcweir    if bOK then
81cdf0e10cSrcweir        if (cObjectName = "sw.SwXTextView") then
82cdf0e10cSrcweir            bOK = bOK AND oSelection.hasElements()
83cdf0e10cSrcweir            bOK = bOK AND (oSelection.getByIndex(0).String = SelectableObj1.String)
84cdf0e10cSrcweir        elseif (hasUnoInterfaces(oSelection, "com.sun.star.container.XElementAccess")) then
85cdf0e10cSrcweir            bOK = bOK AND oSelection.hasElements()
86cdf0e10cSrcweir            if bOK then bOK = bOK AND (oSelection.getByIndex(0).dbg_methods = SelectableObj1.dbg_methods)
87cdf0e10cSrcweir        else
88cdf0e10cSrcweir            bOK = bOK AND (oSelection.dbg_methods = SelectableObj1.dbg_methods)
89cdf0e10cSrcweir        end if
90cdf0e10cSrcweir    end if
91cdf0e10cSrcweir
92cdf0e10cSrcweir    Test.MethodTested("getSelection()", bOK)
93cdf0e10cSrcweir
94cdf0e10cSrcweir    Test.StartMethod("addSelectionChangeListener()")
95cdf0e10cSrcweir    bOK = true
96cdf0e10cSrcweir    Out.Log("Adding two listeners...")
97cdf0e10cSrcweir    oObj.addSelectionChangeListener(oListener1)
98cdf0e10cSrcweir    oObj.addSelectionChangeListener(oListener2)
99cdf0e10cSrcweir
100cdf0e10cSrcweir    Out.Log("Select item...")
101cdf0e10cSrcweir    ResetCB()
102cdf0e10cSrcweir    bOK = bOK AND oObj.select(SelectableObj2)
103cdf0e10cSrcweir    bOK = bOK AND (nCB1Val &gt; 0) AND (nCB2Val &gt; 0)
104cdf0e10cSrcweir    Test.MethodTested("addSelectionChangeListener()", bOK)
105cdf0e10cSrcweir
106cdf0e10cSrcweir    Test.StartMethod("removeSelectionChangeListener()")
107cdf0e10cSrcweir    bOK = true
108cdf0e10cSrcweir    Out.Log("Remove first listener...")
109cdf0e10cSrcweir    oObj.removeSelectionChangeListener(oListener1)
110cdf0e10cSrcweir
111cdf0e10cSrcweir    Out.Log("Select item...")
112cdf0e10cSrcweir    ResetCB()
113cdf0e10cSrcweir    bOK = bOK AND oObj.select(SelectableObj1)
114cdf0e10cSrcweir    bOK = bOK AND (nCB1Val = 0) AND (nCB2Val &gt; 0)
115cdf0e10cSrcweir    Test.MethodTested("removeSelectionChangeListener()", bOK)
116cdf0e10cSrcweir
117cdf0e10cSrcweir    Out.Log("Remove last listener...")
118cdf0e10cSrcweir    oObj.removeSelectionChangeListener(oListener2)
119cdf0e10cSrcweir
120cdf0e10cSrcweirExit Sub
121cdf0e10cSrcweirErrHndl:
122cdf0e10cSrcweir    Test.Exception()
123cdf0e10cSrcweir    bOK = false
124cdf0e10cSrcweir    resume next
125cdf0e10cSrcweirEnd Sub
126cdf0e10cSrcweir
127cdf0e10cSrcweirSub CB1_selectionChanged
128cdf0e10cSrcweir    Out.Log("Listener 1 was called")
129cdf0e10cSrcweir    nCB1Val = nCB1Val + 1
130cdf0e10cSrcweirend sub
131cdf0e10cSrcweir
132cdf0e10cSrcweirSub CB2_selectionChanged
133cdf0e10cSrcweir    Out.Log("Listener 2 was called")
134cdf0e10cSrcweir    nCB2Val = nCB2Val + 1
135cdf0e10cSrcweirend sub
136cdf0e10cSrcweir
137cdf0e10cSrcweirSub ResetCB()
138cdf0e10cSrcweir    nCB1Val = 0
139cdf0e10cSrcweir    nCB2Val = 0
140cdf0e10cSrcweirEnd Sub
141cdf0e10cSrcweir</script:module>
142