2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.FormTools
;
28 import util
.SOfficeFactory
;
29 import util
.WriterTools
;
31 import com
.sun
.star
.awt
.XControlModel
;
32 import com
.sun
.star
.awt
.XDevice
;
33 import com
.sun
.star
.awt
.XGraphics
;
34 import com
.sun
.star
.awt
.XListBox
;
35 import com
.sun
.star
.awt
.XToolkit
;
36 import com
.sun
.star
.awt
.XWindow
;
37 import com
.sun
.star
.awt
.XWindowPeer
;
38 import com
.sun
.star
.drawing
.XControlShape
;
39 import com
.sun
.star
.lang
.XMultiServiceFactory
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
43 import com
.sun
.star
.util
.XCloseable
;
44 import com
.sun
.star
.view
.XControlAccess
;
46 public class OListBoxControl
extends TestCase
{
48 XTextDocument xTextDoc
;
50 protected void initialize ( TestParameters Param
, PrintWriter log
) {
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory( ((XMultiServiceFactory
) Param
.getMSF()) );
54 log
.println( "creating a textdocument" );
55 xTextDoc
= SOF
.createTextDoc( null );
56 } catch ( com
.sun
.star
.uno
.Exception e
) {
57 // Some exception occurs.FAILED
58 e
.printStackTrace( log
);
59 throw new StatusException( "Couldn't create document", e
);
63 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
64 log
.println(" disposing xTextDoc ");
67 XCloseable closer
= UnoRuntime
.queryInterface(
68 XCloseable
.class, xTextDoc
);
70 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
71 log
.println("couldn't close document");
72 } catch (com
.sun
.star
.lang
.DisposedException e
) {
73 log
.println("couldn't close document");
77 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
78 XInterface oObj
= null;
79 Object anotherCtrl
= null ;
80 XWindowPeer the_win
= null;
81 XToolkit the_kit
= null;
82 XDevice aDevice
= null;
83 XGraphics aGraphic
= null;
84 //Insert a ControlShape and get the ControlModel
85 XControlShape aShape
= FormTools
.createControlShape(
86 xTextDoc
,3000,4500,15000,10000,"ListBox");
88 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
90 XControlModel the_Model
= aShape
.getControl();
92 XControlShape aShape2
= FormTools
.createControlShape(
93 xTextDoc
,3000,4500,5000,10000,"TextField");
95 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
97 XControlModel the_Model2
= aShape2
.getControl();
99 //Try to query XControlAccess
100 XControlAccess the_access
= UnoRuntime
.queryInterface(
101 XControlAccess
.class,xTextDoc
.getCurrentController());
103 //now get the OListBoxControl
105 oObj
= the_access
.getControl(the_Model
);
106 anotherCtrl
= the_access
.getControl(the_Model2
);
107 the_win
= the_access
.getControl(the_Model
).getPeer();
108 the_kit
= the_win
.getToolkit();
109 aDevice
= the_kit
.createScreenCompatibleDevice(200,200);
110 aGraphic
= aDevice
.createGraphics();
111 } catch (Exception e
) {
112 log
.println("Couldn't get OListBoxControl");
113 e
.printStackTrace(log
);
114 throw new StatusException("Couldn't get OListBoxControl", e
);
117 log
.println( "creating a new environment for OListBoxControl object" );
118 TestEnvironment tEnv
= new TestEnvironment( oObj
);
120 //Adding ObjRelation for XView
121 tEnv
.addObjRelation("GRAPHICS",aGraphic
);
123 //Adding ObjRelation for XControl
124 tEnv
.addObjRelation("CONTEXT",xTextDoc
);
125 tEnv
.addObjRelation("WINPEER",the_win
);
126 tEnv
.addObjRelation("TOOLKIT",the_kit
);
127 tEnv
.addObjRelation("MODEL",the_Model
);
129 // Adding relation for XItemListener
130 ifc
.awt
._XItemListener
.TestItemListener listener
=
131 new ifc
.awt
._XItemListener
.TestItemListener() ;
132 final XListBox box
= UnoRuntime
.queryInterface(XListBox
.class, oObj
) ;
133 box
.addItemListener(listener
) ;
134 tEnv
.addObjRelation("TestItemListener", listener
) ;
136 // Adding relation for XWindow
137 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class, anotherCtrl
);
139 XWindow objWin
= UnoRuntime
.queryInterface(XWindow
.class, oObj
);
141 tEnv
.addObjRelation("XWindow.AnotherWindow",forObjRel
);
142 tEnv
.addObjRelation("XWindow.ControlShape",aShape
);
144 tEnv
.addObjRelation("Win1",objWin
);
145 tEnv
.addObjRelation("Win2",forObjRel
);
147 tEnv
.addObjRelation("CONTROL",anotherCtrl
);
149 // adding relation for XChangeBroadcaster
150 box
.addItem("Item1", (short) 0);
151 box
.addItem("Item2", (short) 1);
153 tEnv
.addObjRelation("XChangeBroadcaster.Changer",
154 new ifc
.form
._XChangeBroadcaster
.Changer() {
155 public void change(){
156 box
.addItem("Item1", (short) 0);
157 box
.addItem("Item2", (short) 1);
158 box
.selectItemPos((short) 0, true);
159 box
.selectItemPos((short) 1, true);
165 } // finish method getTestEnvironment
167 } // finish class OListBoxControl