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
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.util
.XCloseable
;
43 import com
.sun
.star
.view
.XControlAccess
;
45 public class OListBoxControl
extends TestCase
{
47 XTextDocument xTextDoc
;
50 protected void initialize ( TestParameters Param
, PrintWriter log
) {
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (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
);
64 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
65 log
.println(" disposing xTextDoc ");
68 XCloseable closer
= UnoRuntime
.queryInterface(
69 XCloseable
.class, xTextDoc
);
71 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
72 log
.println("couldn't close document");
73 } catch (com
.sun
.star
.lang
.DisposedException e
) {
74 log
.println("couldn't close document");
79 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
80 XInterface oObj
= null;
81 Object anotherCtrl
= null ;
82 XWindowPeer the_win
= null;
83 XToolkit the_kit
= null;
84 XDevice aDevice
= null;
85 XGraphics aGraphic
= null;
86 //Insert a ControlShape and get the ControlModel
87 XControlShape aShape
= FormTools
.createControlShape(
88 xTextDoc
,3000,4500,15000,10000,"ListBox");
90 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
92 XControlModel the_Model
= aShape
.getControl();
94 XControlShape aShape2
= FormTools
.createControlShape(
95 xTextDoc
,3000,4500,5000,10000,"TextField");
97 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
99 XControlModel the_Model2
= aShape2
.getControl();
101 //Try to query XControlAccess
102 XControlAccess the_access
= UnoRuntime
.queryInterface(
103 XControlAccess
.class,xTextDoc
.getCurrentController());
105 //now get the OListBoxControl
107 oObj
= the_access
.getControl(the_Model
);
108 anotherCtrl
= the_access
.getControl(the_Model2
);
109 the_win
= the_access
.getControl(the_Model
).getPeer();
110 the_kit
= the_win
.getToolkit();
111 aDevice
= the_kit
.createScreenCompatibleDevice(200,200);
112 aGraphic
= aDevice
.createGraphics();
113 } catch (Exception e
) {
114 log
.println("Couldn't get OListBoxControl");
115 e
.printStackTrace(log
);
116 throw new StatusException("Couldn't get OListBoxControl", e
);
119 log
.println( "creating a new environment for OListBoxControl object" );
120 TestEnvironment tEnv
= new TestEnvironment( oObj
);
122 //Adding ObjRelation for XView
123 tEnv
.addObjRelation("GRAPHICS",aGraphic
);
125 //Adding ObjRelation for XControl
126 tEnv
.addObjRelation("CONTEXT",xTextDoc
);
127 tEnv
.addObjRelation("WINPEER",the_win
);
128 tEnv
.addObjRelation("TOOLKIT",the_kit
);
129 tEnv
.addObjRelation("MODEL",the_Model
);
131 // Adding relation for XItemListener
132 ifc
.awt
._XItemListener
.TestItemListener listener
=
133 new ifc
.awt
._XItemListener
.TestItemListener() ;
134 final XListBox box
= UnoRuntime
.queryInterface(XListBox
.class, oObj
) ;
135 box
.addItemListener(listener
) ;
136 tEnv
.addObjRelation("TestItemListener", listener
) ;
138 // Adding relation for XWindow
139 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class, anotherCtrl
);
141 XWindow objWin
= UnoRuntime
.queryInterface(XWindow
.class, oObj
);
143 tEnv
.addObjRelation("XWindow.AnotherWindow",forObjRel
);
144 tEnv
.addObjRelation("XWindow.ControlShape",aShape
);
146 tEnv
.addObjRelation("Win1",objWin
);
147 tEnv
.addObjRelation("Win2",forObjRel
);
149 tEnv
.addObjRelation("CONTROL",anotherCtrl
);
151 // adding relation for XChangeBroadcaster
152 box
.addItem("Item1", (short) 0);
153 box
.addItem("Item2", (short) 1);
155 tEnv
.addObjRelation("XChangeBroadcaster.Changer",
156 new ifc
.form
._XChangeBroadcaster
.Changer() {
157 public void change(){
158 box
.addItem("Item1", (short) 0);
159 box
.addItem("Item2", (short) 1);
160 box
.selectItemPos((short) 0, true);
161 box
.selectItemPos((short) 1, true);
167 } // finish method getTestEnvironment
169 } // finish class OListBoxControl