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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.FormTools
;
27 import util
.SOfficeFactory
;
28 import util
.WriterTools
;
31 import com
.sun
.star
.awt
.XControl
;
32 import com
.sun
.star
.awt
.XControlModel
;
33 import com
.sun
.star
.awt
.XDevice
;
34 import com
.sun
.star
.awt
.XGraphics
;
35 import com
.sun
.star
.awt
.XTextComponent
;
36 import com
.sun
.star
.awt
.XToolkit
;
37 import com
.sun
.star
.awt
.XWindow
;
38 import com
.sun
.star
.awt
.XWindowPeer
;
39 import com
.sun
.star
.drawing
.XControlShape
;
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
.view
.XControlAccess
;
46 public class UnoControlComboBox
extends TestCase
{
47 private static 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 ");
67 util
.DesktopTools
.closeDoc(xTextDoc
);
71 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
73 XInterface oObj
= null;
74 XWindowPeer the_win
= null;
75 XToolkit the_kit
= null;
76 XDevice aDevice
= null;
77 XGraphics aGraphic
= null;
78 XControl aControl
= null;
80 //Insert a ControlShape and get the ControlModel
81 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
85 "UnoControlComboBox");
87 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
89 XControlModel the_Model
= aShape
.getControl();
91 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
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,
102 xTextDoc
.getCurrentController());
104 //get the ComboBoxControl for the needed Object relations
106 oObj
= the_access
.getControl(the_Model
);
107 aControl
= the_access
.getControl(the_Model2
);
108 the_win
= the_access
.getControl(the_Model
).getPeer();
109 the_kit
= the_win
.getToolkit();
110 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
111 aGraphic
= aDevice
.createGraphics();
112 } catch (Exception e
) {
113 log
.println("Couldn't get ComboBoxControl");
114 e
.printStackTrace(log
);
115 throw new StatusException("Couldn't get ComboBoxControl", e
);
118 log
.println("creating a new environment for UnoControlComboBox object");
120 TestEnvironment tEnv
= new TestEnvironment(oObj
);
123 //Adding ObjRelation for XView
124 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
127 //Adding ObjRelation for XControl
128 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
129 tEnv
.addObjRelation("WINPEER", the_win
);
130 tEnv
.addObjRelation("TOOLKIT", the_kit
);
131 tEnv
.addObjRelation("MODEL", the_Model
);
133 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
136 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
137 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
139 // Adding relation for XTextListener
140 ifc
.awt
._XTextListener
.TestTextListener listener
=
141 new ifc
.awt
._XTextListener
.TestTextListener();
142 XTextComponent textComp
= UnoRuntime
.queryInterface(
143 XTextComponent
.class, oObj
);
144 textComp
.addTextListener(listener
);
145 tEnv
.addObjRelation("TestTextListener", listener
);
147 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
150 } // finish method getTestEnvironment
151 } // finish class UnoControlComboBox