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="view_XSelectionSupplier" 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 Jagielski' This Interface/Service test depends on the following GLOBAL variables,
36*b1cdbd2cSJim Jagielski' which must be specified in the object creation:
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski'     - Global SelectableObj1 As Object
39*b1cdbd2cSJim Jagielski'     - Global SelectableObj2 As Object
40*b1cdbd2cSJim Jagielski
41*b1cdbd2cSJim Jagielski'*************************************************************************
42*b1cdbd2cSJim Jagielski
43*b1cdbd2cSJim Jagielski
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski
46*b1cdbd2cSJim JagielskiDim nCB1Val, nCB2Val As Integer
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim JagielskiSub RunTest()
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski'*************************************************************************
52*b1cdbd2cSJim Jagielski' INTERFACE:
53*b1cdbd2cSJim Jagielski' com.sun.star.view.XSelectionSupplier
54*b1cdbd2cSJim Jagielski'*************************************************************************
55*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
56*b1cdbd2cSJim Jagielski    Dim bOK, bSelected As Boolean
57*b1cdbd2cSJim Jagielski    Dim oListener1, oListener2, oSelection As Object
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski    Out.Log("creating two Listeners")
60*b1cdbd2cSJim Jagielski    oListener1 = createUNOListener("CB1_", "com.sun.star.view.XSelectionChangeListener")
61*b1cdbd2cSJim Jagielski    oListener2 = createUNOListener("CB2_", "com.sun.star.view.XSelectionChangeListener")
62*b1cdbd2cSJim Jagielski    bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2)
63*b1cdbd2cSJim Jagielski    Out.Log("Listeners creation : " &amp; bOK)
64*b1cdbd2cSJim Jagielski
65*b1cdbd2cSJim Jagielski    Test.StartMethod("select()")
66*b1cdbd2cSJim Jagielski    bOK = true
67*b1cdbd2cSJim Jagielski    out.log("Trying to select ...")
68*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.select(SelectableObj1)
69*b1cdbd2cSJim Jagielski    Test.MethodTested("select()", bOK)
70*b1cdbd2cSJim Jagielski
71*b1cdbd2cSJim Jagielski    Test.StartMethod("getSelection()")
72*b1cdbd2cSJim Jagielski    bOK = true
73*b1cdbd2cSJim Jagielski    oSelection = oObj.getSelection()
74*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT isNULL(oSelection)
75*b1cdbd2cSJim Jagielski
76*b1cdbd2cSJim Jagielski    ' The selection is either specified by an object which is contained
77*b1cdbd2cSJim Jagielski    ' in the component to which the view belongs or it is an interface of a
78*b1cdbd2cSJim Jagielski    ' collection which contains such objects.
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski    if bOK then
81*b1cdbd2cSJim Jagielski        if (cObjectName = "sw.SwXTextView") then
82*b1cdbd2cSJim Jagielski            bOK = bOK AND oSelection.hasElements()
83*b1cdbd2cSJim Jagielski            bOK = bOK AND (oSelection.getByIndex(0).String = SelectableObj1.String)
84*b1cdbd2cSJim Jagielski        elseif (hasUnoInterfaces(oSelection, "com.sun.star.container.XElementAccess")) then
85*b1cdbd2cSJim Jagielski            bOK = bOK AND oSelection.hasElements()
86*b1cdbd2cSJim Jagielski            if bOK then bOK = bOK AND (oSelection.getByIndex(0).dbg_methods = SelectableObj1.dbg_methods)
87*b1cdbd2cSJim Jagielski        else
88*b1cdbd2cSJim Jagielski            bOK = bOK AND (oSelection.dbg_methods = SelectableObj1.dbg_methods)
89*b1cdbd2cSJim Jagielski        end if
90*b1cdbd2cSJim Jagielski    end if
91*b1cdbd2cSJim Jagielski
92*b1cdbd2cSJim Jagielski    Test.MethodTested("getSelection()", bOK)
93*b1cdbd2cSJim Jagielski
94*b1cdbd2cSJim Jagielski    Test.StartMethod("addSelectionChangeListener()")
95*b1cdbd2cSJim Jagielski    bOK = true
96*b1cdbd2cSJim Jagielski    Out.Log("Adding two listeners...")
97*b1cdbd2cSJim Jagielski    oObj.addSelectionChangeListener(oListener1)
98*b1cdbd2cSJim Jagielski    oObj.addSelectionChangeListener(oListener2)
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski    Out.Log("Select item...")
101*b1cdbd2cSJim Jagielski    ResetCB()
102*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.select(SelectableObj2)
103*b1cdbd2cSJim Jagielski    bOK = bOK AND (nCB1Val &gt; 0) AND (nCB2Val &gt; 0)
104*b1cdbd2cSJim Jagielski    Test.MethodTested("addSelectionChangeListener()", bOK)
105*b1cdbd2cSJim Jagielski
106*b1cdbd2cSJim Jagielski    Test.StartMethod("removeSelectionChangeListener()")
107*b1cdbd2cSJim Jagielski    bOK = true
108*b1cdbd2cSJim Jagielski    Out.Log("Remove first listener...")
109*b1cdbd2cSJim Jagielski    oObj.removeSelectionChangeListener(oListener1)
110*b1cdbd2cSJim Jagielski
111*b1cdbd2cSJim Jagielski    Out.Log("Select item...")
112*b1cdbd2cSJim Jagielski    ResetCB()
113*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.select(SelectableObj1)
114*b1cdbd2cSJim Jagielski    bOK = bOK AND (nCB1Val = 0) AND (nCB2Val &gt; 0)
115*b1cdbd2cSJim Jagielski    Test.MethodTested("removeSelectionChangeListener()", bOK)
116*b1cdbd2cSJim Jagielski
117*b1cdbd2cSJim Jagielski    Out.Log("Remove last listener...")
118*b1cdbd2cSJim Jagielski    oObj.removeSelectionChangeListener(oListener2)
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim JagielskiExit Sub
121*b1cdbd2cSJim JagielskiErrHndl:
122*b1cdbd2cSJim Jagielski    Test.Exception()
123*b1cdbd2cSJim Jagielski    bOK = false
124*b1cdbd2cSJim Jagielski    resume next
125*b1cdbd2cSJim JagielskiEnd Sub
126*b1cdbd2cSJim Jagielski
127*b1cdbd2cSJim JagielskiSub CB1_selectionChanged
128*b1cdbd2cSJim Jagielski    Out.Log("Listener 1 was called")
129*b1cdbd2cSJim Jagielski    nCB1Val = nCB1Val + 1
130*b1cdbd2cSJim Jagielskiend sub
131*b1cdbd2cSJim Jagielski
132*b1cdbd2cSJim JagielskiSub CB2_selectionChanged
133*b1cdbd2cSJim Jagielski    Out.Log("Listener 2 was called")
134*b1cdbd2cSJim Jagielski    nCB2Val = nCB2Val + 1
135*b1cdbd2cSJim Jagielskiend sub
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim JagielskiSub ResetCB()
138*b1cdbd2cSJim Jagielski    nCB1Val = 0
139*b1cdbd2cSJim Jagielski    nCB2Val = 0
140*b1cdbd2cSJim JagielskiEnd Sub
141*b1cdbd2cSJim Jagielski</script:module>
142