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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32'*************************************************************************
33
34
35
36' Be sure that all variables are dimensioned:
37option explicit
38
39'*************************************************************************
40' This Interface/Service test depends on the following GLOBAL variables,
41' which must be specified in the object creation:
42
43'     - Global SelectableObj1 As Object
44'     - Global SelectableObj2 As Object
45
46'*************************************************************************
47
48
49
50
51Dim nCB1Val, nCB2Val As Integer
52
53
54Sub RunTest()
55
56'*************************************************************************
57' INTERFACE:
58' com.sun.star.view.XSelectionSupplier
59'*************************************************************************
60On Error Goto ErrHndl
61    Dim bOK, bSelected As Boolean
62    Dim oListener1, oListener2, oSelection As Object
63
64    Out.Log("creating two Listeners")
65    oListener1 = createUNOListener("CB1_", "com.sun.star.view.XSelectionChangeListener")
66    oListener2 = createUNOListener("CB2_", "com.sun.star.view.XSelectionChangeListener")
67    bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2)
68    Out.Log("Listeners creation : " &amp; bOK)
69
70    Test.StartMethod("select()")
71    bOK = true
72    out.log("Trying to select ...")
73    bOK = bOK AND oObj.select(SelectableObj1)
74    Test.MethodTested("select()", bOK)
75
76    Test.StartMethod("getSelection()")
77    bOK = true
78    oSelection = oObj.getSelection()
79    bOK = bOK AND NOT isNULL(oSelection)
80
81    ' The selection is either specified by an object which is contained
82    ' in the component to which the view belongs or it is an interface of a
83    ' collection which contains such objects.
84
85    if bOK then
86        if (cObjectName = "sw.SwXTextView") then
87            bOK = bOK AND oSelection.hasElements()
88            bOK = bOK AND (oSelection.getByIndex(0).String = SelectableObj1.String)
89        elseif (hasUnoInterfaces(oSelection, "com.sun.star.container.XElementAccess")) then
90            bOK = bOK AND oSelection.hasElements()
91            if bOK then bOK = bOK AND (oSelection.getByIndex(0).dbg_methods = SelectableObj1.dbg_methods)
92        else
93            bOK = bOK AND (oSelection.dbg_methods = SelectableObj1.dbg_methods)
94        end if
95    end if
96
97    Test.MethodTested("getSelection()", bOK)
98
99    Test.StartMethod("addSelectionChangeListener()")
100    bOK = true
101    Out.Log("Adding two listeners...")
102    oObj.addSelectionChangeListener(oListener1)
103    oObj.addSelectionChangeListener(oListener2)
104
105    Out.Log("Select item...")
106    ResetCB()
107    bOK = bOK AND oObj.select(SelectableObj2)
108    bOK = bOK AND (nCB1Val &gt; 0) AND (nCB2Val &gt; 0)
109    Test.MethodTested("addSelectionChangeListener()", bOK)
110
111    Test.StartMethod("removeSelectionChangeListener()")
112    bOK = true
113    Out.Log("Remove first listener...")
114    oObj.removeSelectionChangeListener(oListener1)
115
116    Out.Log("Select item...")
117    ResetCB()
118    bOK = bOK AND oObj.select(SelectableObj1)
119    bOK = bOK AND (nCB1Val = 0) AND (nCB2Val &gt; 0)
120    Test.MethodTested("removeSelectionChangeListener()", bOK)
121
122    Out.Log("Remove last listener...")
123    oObj.removeSelectionChangeListener(oListener2)
124
125Exit Sub
126ErrHndl:
127    Test.Exception()
128    bOK = false
129    resume next
130End Sub
131
132Sub CB1_selectionChanged
133    Out.Log("Listener 1 was called")
134    nCB1Val = nCB1Val + 1
135end sub
136
137Sub CB2_selectionChanged
138    Out.Log("Listener 2 was called")
139    nCB2Val = nCB2Val + 1
140end sub
141
142Sub ResetCB()
143    nCB1Val = 0
144    nCB2Val = 0
145End Sub
146</script:module>
147