tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OListBoxControl.java
blob03dac5b1a20b28c9c21548964d6644314f841289
1 /*
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 .
19 package mod._forms;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
30 import com.sun.star.awt.XControlModel;
31 import com.sun.star.awt.XDevice;
32 import com.sun.star.awt.XGraphics;
33 import com.sun.star.awt.XListBox;
34 import com.sun.star.awt.XToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.awt.XWindowPeer;
37 import com.sun.star.drawing.XControlShape;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.util.XCloseable;
42 import com.sun.star.view.XControlAccess;
44 public class OListBoxControl extends TestCase {
46 XTextDocument xTextDoc;
48 @Override
49 protected void initialize ( TestParameters Param, PrintWriter log) throws Exception {
50 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF() );
51 log.println( "creating a textdocument" );
52 xTextDoc = SOF.createTextDoc( null );
55 @Override
56 protected void cleanup(TestParameters tParam, PrintWriter log) {
57 log.println(" disposing xTextDoc ");
59 try {
60 XCloseable closer = UnoRuntime.queryInterface(
61 XCloseable.class, xTextDoc);
62 closer.close(true);
63 } catch (com.sun.star.util.CloseVetoException e) {
64 log.println("couldn't close document");
65 } catch (com.sun.star.lang.DisposedException e) {
66 log.println("couldn't close document");
70 @Override
71 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
72 XInterface oObj = null;
73 Object anotherCtrl = null ;
74 XWindowPeer the_win = null;
75 XToolkit the_kit = null;
76 XDevice aDevice = null;
77 XGraphics aGraphic = null;
78 //Insert a ControlShape and get the ControlModel
79 XControlShape aShape = FormTools.createControlShape(
80 xTextDoc,3000,4500,15000,10000,"ListBox");
82 WriterTools.getDrawPage(xTextDoc).add(aShape);
84 XControlModel the_Model = aShape.getControl();
86 XControlShape aShape2 = FormTools.createControlShape(
87 xTextDoc,3000,4500,5000,10000,"TextField");
89 WriterTools.getDrawPage(xTextDoc).add(aShape2);
91 XControlModel the_Model2 = aShape2.getControl();
93 //Try to query XControlAccess
94 XControlAccess the_access = UnoRuntime.queryInterface(
95 XControlAccess.class,xTextDoc.getCurrentController());
97 //now get the OListBoxControl
98 oObj = the_access.getControl(the_Model);
99 anotherCtrl = the_access.getControl(the_Model2);
100 the_win = the_access.getControl(the_Model).getPeer();
101 the_kit = the_win.getToolkit();
102 aDevice = the_kit.createScreenCompatibleDevice(200,200);
103 aGraphic = aDevice.createGraphics();
105 log.println( "creating a new environment for OListBoxControl object" );
106 TestEnvironment tEnv = new TestEnvironment( oObj );
108 //Adding ObjRelation for XView
109 tEnv.addObjRelation("GRAPHICS",aGraphic);
111 //Adding ObjRelation for XControl
112 tEnv.addObjRelation("CONTEXT",xTextDoc);
113 tEnv.addObjRelation("WINPEER",the_win);
114 tEnv.addObjRelation("TOOLKIT",the_kit);
115 tEnv.addObjRelation("MODEL",the_Model);
117 // Adding relation for XItemListener
118 ifc.awt._XItemListener.TestItemListener listener =
119 new ifc.awt._XItemListener.TestItemListener() ;
120 final XListBox box = UnoRuntime.queryInterface(XListBox.class, oObj) ;
121 box.addItemListener(listener) ;
122 tEnv.addObjRelation("TestItemListener", listener) ;
124 // Adding relation for XWindow
125 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class, anotherCtrl);
127 XWindow objWin = UnoRuntime.queryInterface(XWindow.class, oObj);
129 tEnv.addObjRelation("XWindow.AnotherWindow",forObjRel);
130 tEnv.addObjRelation("XWindow.ControlShape",aShape);
132 tEnv.addObjRelation("Win1",objWin);
133 tEnv.addObjRelation("Win2",forObjRel);
135 tEnv.addObjRelation("CONTROL",anotherCtrl);
137 // adding relation for XChangeBroadcaster
138 box.addItem("Item1", (short) 0);
139 box.addItem("Item2", (short) 1);
141 tEnv.addObjRelation("XChangeBroadcaster.Changer",
142 new ifc.form._XChangeBroadcaster.Changer() {
143 public void change(){
144 box.addItem("Item1", (short) 0);
145 box.addItem("Item2", (short) 1);
146 box.selectItemPos((short) 0, true);
147 box.selectItemPos((short) 1, true);
152 return tEnv;
153 } // finish method getTestEnvironment
155 } // finish class OListBoxControl