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