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