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="awt_XTextComponent" 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 JagielskiDim bCB1_textChanged As Boolean
36*b1cdbd2cSJim JagielskiDim bCB2_textChanged As Boolean
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski
39*b1cdbd2cSJim JagielskiSub RunTest()
40*b1cdbd2cSJim Jagielski
41*b1cdbd2cSJim Jagielski'*************************************************************************
42*b1cdbd2cSJim Jagielski' INTERFACE:
43*b1cdbd2cSJim Jagielski' com.sun.star.awt.XTextComponent
44*b1cdbd2cSJim Jagielski'*************************************************************************
45*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
46*b1cdbd2cSJim Jagielski    Dim bOK As Boolean
47*b1cdbd2cSJim Jagielski    Dim oListener1 As Object, oListener2 As Object
48*b1cdbd2cSJim Jagielski    Dim vSelection As new com.sun.star.awt.Selection
49*b1cdbd2cSJim Jagielski    Dim vSelectionSelection As new com.sun.star.awt.Selection
50*b1cdbd2cSJim Jagielski    Dim vGetSelection As  new com.sun.star.awt.Selection
51*b1cdbd2cSJim Jagielski    Dim vInsertSelection As  new com.sun.star.awt.Selection
52*b1cdbd2cSJim Jagielski    Dim cGetText As String
53*b1cdbd2cSJim Jagielski    Dim len2set As Integer
54*b1cdbd2cSJim Jagielski
55*b1cdbd2cSJim Jagielski    Out.Log("create two com.sun.star.awt.XTextListener")
56*b1cdbd2cSJim Jagielski    oListener1 = createUNOListener("CB1_", "com.sun.star.awt.XTextListener")
57*b1cdbd2cSJim Jagielski    oListener2 = createUNOListener("CB2_", "com.sun.star.awt.XTextListener")
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski    Test.StartMethod("setText()")
60*b1cdbd2cSJim Jagielski    bOK = true
61*b1cdbd2cSJim Jagielski    Dim cText As String
62*b1cdbd2cSJim Jagielski    cText = "XTextComponent: setText()"
63*b1cdbd2cSJim Jagielski    oObj.setText(cText)
64*b1cdbd2cSJim Jagielski    Test.StartMethod("getText()")
65*b1cdbd2cSJim Jagielski    bOK = bOK AND (cText = oObj.getText())
66*b1cdbd2cSJim Jagielski    Test.MethodTested("setText()", bOK)
67*b1cdbd2cSJim Jagielski    Test.MethodTested("getText()", bOK)
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski    Test.StartMethod("insertText()")
70*b1cdbd2cSJim Jagielski    bOK = true
71*b1cdbd2cSJim Jagielski    oObj.setText("setSelection")
72*b1cdbd2cSJim Jagielski    vInsertSelection.Min = 0
73*b1cdbd2cSJim Jagielski    vInsertSelection.Max = 3
74*b1cdbd2cSJim Jagielski    oObj.insertText(vInsertSelection,"new")
75*b1cdbd2cSJim Jagielski    Out.Log("result of getText is: '" + oObj.getText() +"'. It sould be 'newSelection'")
76*b1cdbd2cSJim Jagielski    bOK = bOK AND (oObj.getText() = "newSelection")
77*b1cdbd2cSJim Jagielski    Test.MethodTested("insertText()", bOK)
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski    Test.StartMethod("setSelection()")
81*b1cdbd2cSJim Jagielski    bOK = true
82*b1cdbd2cSJim Jagielski    vSelectionSelection.Min = 2
83*b1cdbd2cSJim Jagielski    vSelectionSelection.Max = 3
84*b1cdbd2cSJim Jagielski    oObj.setSelection(vSelectionSelection)
85*b1cdbd2cSJim Jagielski    Test.StartMethod("getSelection()")
86*b1cdbd2cSJim Jagielski    vGetSelection = oObj.getSelection()
87*b1cdbd2cSJim Jagielski    bOK = bOK AND (vGetSelection.Min = vSelectionSelection.Min) AND _
88*b1cdbd2cSJim Jagielski          (vGetSelection.Max = vSelectionSelection.Max)
89*b1cdbd2cSJim Jagielski    Test.MethodTested("setSelection()", bOK)
90*b1cdbd2cSJim Jagielski    Test.MethodTested("getSelection()", bOK)
91*b1cdbd2cSJim Jagielski
92*b1cdbd2cSJim Jagielski    Test.StartMethod("getSelectedText()")
93*b1cdbd2cSJim Jagielski    bOK = true
94*b1cdbd2cSJim Jagielski    oObj.setText("getSelectedText")
95*b1cdbd2cSJim Jagielski    vSelectionSelection.Min = 0
96*b1cdbd2cSJim Jagielski    vSelectionSelection.Max = 3
97*b1cdbd2cSJim Jagielski    oObj.setSelection(vSelectionSelection)
98*b1cdbd2cSJim Jagielski    Out.Log("result of getSelectedText is: '" + oObj.getSelectedText() +"'. It sould be 'get'")
99*b1cdbd2cSJim Jagielski    bOK = bOK AND (oObj.getSelectedText() = "get")
100*b1cdbd2cSJim Jagielski    Test.MethodTested("getSelectedText()", bOK)
101*b1cdbd2cSJim Jagielski
102*b1cdbd2cSJim Jagielski    Test.StartMethod("setEditable()")
103*b1cdbd2cSJim Jagielski    bOK = true
104*b1cdbd2cSJim Jagielski    oObj.setEditable(true)
105*b1cdbd2cSJim Jagielski    Test.StartMethod("isEditable()")
106*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.isEditable()
107*b1cdbd2cSJim Jagielski    oObj.setEditable(false)
108*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT oObj.isEditable()
109*b1cdbd2cSJim Jagielski    oObj.setEditable(true)
110*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.isEditable()
111*b1cdbd2cSJim Jagielski    Test.MethodTested("setEditable()", bOK)
112*b1cdbd2cSJim Jagielski    Test.MethodTested("isEditable()", bOK)
113*b1cdbd2cSJim Jagielski
114*b1cdbd2cSJim Jagielski    Test.StartMethod("setMaxTextLen()")
115*b1cdbd2cSJim Jagielski    bOK = true
116*b1cdbd2cSJim Jagielski    if (oObj.getMaxTextLen = 12) then
117*b1cdbd2cSJim Jagielski        len2set = 10
118*b1cdbd2cSJim Jagielski    else
119*b1cdbd2cSJim Jagielski        len2set = 12
120*b1cdbd2cSJim Jagielski    endif
121*b1cdbd2cSJim Jagielski    oObj.setMaxTextLen(len2set)
122*b1cdbd2cSJim Jagielski    oObj.setText("0123456789ABCDE")
123*b1cdbd2cSJim Jagielski    cGetText = oObj.getText()
124*b1cdbd2cSJim Jagielski    Out.Log("result of Len(cGetText) is: '" + Len(cGetText) + "'. It sould be >'" + len2set+"' ")
125*b1cdbd2cSJim Jagielski    bOK = bOK AND (Len(cGetText) > len2set)
126*b1cdbd2cSJim Jagielski    Test.MethodTested("setMaxTextLen()", bOK)
127*b1cdbd2cSJim Jagielski
128*b1cdbd2cSJim Jagielski    Test.StartMethod("getMaxTextLen()")
129*b1cdbd2cSJim Jagielski    bOK = true
130*b1cdbd2cSJim Jagielski    if (oObj.getMaxTextLen = 12) then
131*b1cdbd2cSJim Jagielski        len2set = 10
132*b1cdbd2cSJim Jagielski    else
133*b1cdbd2cSJim Jagielski        len2set = 12
134*b1cdbd2cSJim Jagielski    endif
135*b1cdbd2cSJim Jagielski    oObj.setMaxTextLen(len2set)
136*b1cdbd2cSJim Jagielski    Out.Log("result of getMaxTextLen is: '" + oObj.getMaxTextLen() +"'. It sould be '"+len2set+"'")
137*b1cdbd2cSJim Jagielski    bOK = bOK AND (oObj.getMaxTextLen() = len2set)
138*b1cdbd2cSJim Jagielski    Test.MethodTested("getMaxTextLen()", bOK)
139*b1cdbd2cSJim Jagielski
140*b1cdbd2cSJim Jagielski    bCB1_textChanged = false
141*b1cdbd2cSJim Jagielski    bCB2_textChanged = false
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski    Test.StartMethod("addTextListener()")
144*b1cdbd2cSJim Jagielski    bOK = true
145*b1cdbd2cSJim Jagielski    oObj.addTextListener(oListener1)
146*b1cdbd2cSJim Jagielski    oObj.addTextListener(oListener2)
147*b1cdbd2cSJim Jagielski    oObj.setText("addTextListener")
148*b1cdbd2cSJim Jagielski    Wait(500)
149*b1cdbd2cSJim Jagielski    bOK = bOK AND bCB1_textChanged AND bCB2_textChanged
150*b1cdbd2cSJim Jagielski    Test.MethodTested("addTextListener()", bOK)
151*b1cdbd2cSJim Jagielski
152*b1cdbd2cSJim Jagielski    bCB1_textChanged = false
153*b1cdbd2cSJim Jagielski    bCB2_textChanged = false
154*b1cdbd2cSJim Jagielski
155*b1cdbd2cSJim Jagielski    Test.StartMethod("removeTextListener()")
156*b1cdbd2cSJim Jagielski    bOK = true
157*b1cdbd2cSJim Jagielski    oObj.removeTextListener(oListener1)
158*b1cdbd2cSJim Jagielski    oObj.setText("removeTextListener")
159*b1cdbd2cSJim Jagielski    Wait(500)
160*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT bCB1_textChanged AND bCB2_textChanged
161*b1cdbd2cSJim Jagielski    oObj.removeTextListener(oListener2)
162*b1cdbd2cSJim Jagielski    Test.MethodTested("removeTextListener()", bOK)
163*b1cdbd2cSJim Jagielski
164*b1cdbd2cSJim JagielskiExit Sub
165*b1cdbd2cSJim JagielskiErrHndl:
166*b1cdbd2cSJim Jagielski    Test.Exception()
167*b1cdbd2cSJim Jagielski    bOK = false
168*b1cdbd2cSJim Jagielski    resume next
169*b1cdbd2cSJim JagielskiEnd Sub
170*b1cdbd2cSJim Jagielski
171*b1cdbd2cSJim JagielskiSub CB1_disposing()
172*b1cdbd2cSJim JagielskiEnd Sub
173*b1cdbd2cSJim Jagielski
174*b1cdbd2cSJim JagielskiSub CB2_disposing()
175*b1cdbd2cSJim JagielskiEnd Sub
176*b1cdbd2cSJim Jagielski
177*b1cdbd2cSJim Jagielski' Listener call backs for com.sun.star.awt.XTextListener
178*b1cdbd2cSJim JagielskiSub CB1_textChanged
179*b1cdbd2cSJim Jagielski    Out.Log("CallBack for Listener1 textChanged was called.")
180*b1cdbd2cSJim Jagielski    bCB1_textChanged = true
181*b1cdbd2cSJim JagielskiEnd Sub
182*b1cdbd2cSJim JagielskiSub CB2_TextChanged
183*b1cdbd2cSJim Jagielski    Out.Log("CallBack for Listener2 textChanged was called.")
184*b1cdbd2cSJim Jagielski    bCB2_textChanged = true
185*b1cdbd2cSJim JagielskiEnd Sub
186*b1cdbd2cSJim Jagielski</script:module>
187