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 com
.sun
.star
.awt
.XControl
;
21 import com
.sun
.star
.awt
.XControlModel
;
22 import com
.sun
.star
.awt
.XDevice
;
23 import com
.sun
.star
.awt
.XGraphics
;
24 import com
.sun
.star
.awt
.XTextComponent
;
25 import com
.sun
.star
.awt
.XToolkit
;
26 import com
.sun
.star
.awt
.XWindow
;
27 import com
.sun
.star
.awt
.XWindowPeer
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.drawing
.XControlShape
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XTextDocument
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.view
.XControlAccess
;
36 import java
.io
.PrintWriter
;
38 import lib
.StatusException
;
40 import lib
.TestEnvironment
;
41 import lib
.TestParameters
;
43 import util
.FormTools
;
44 import util
.SOfficeFactory
;
45 import util
.WriterTools
;
49 public class UnoControlFormattedField
extends TestCase
{
50 private static XTextDocument xTextDoc
;
52 protected void initialize(TestParameters Param
, PrintWriter log
) {
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
54 (XMultiServiceFactory
) Param
.getMSF());
57 log
.println("creating a textdocument");
58 xTextDoc
= SOF
.createTextDoc(null);
59 } catch (com
.sun
.star
.uno
.Exception e
) {
60 // Some exception occurs.FAILED
61 e
.printStackTrace(log
);
62 throw new StatusException("Couldn't create document", e
);
66 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
67 log
.println(" disposing xTextDoc ");
69 util
.DesktopTools
.closeDoc(xTextDoc
);
72 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
74 XInterface oObj
= null;
75 XWindowPeer the_win
= null;
76 XToolkit the_kit
= null;
77 XDevice aDevice
= null;
78 XGraphics aGraphic
= null;
79 XControl aControl
= null;
81 //Insert a ControlShape and get the ControlModel
82 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
85 "DatabaseFormattedField",
86 "UnoControlFormattedField");
88 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
90 XControlModel the_Model
= aShape
.getControl();
92 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
96 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
98 XControlModel the_Model2
= aShape2
.getControl();
100 XPropertySet xPS
= UnoRuntime
.queryInterface(
101 XPropertySet
.class, the_Model
);
103 //Try to query XControlAccess
104 XControlAccess the_access
= UnoRuntime
.queryInterface(
105 XControlAccess
.class,
106 xTextDoc
.getCurrentController());
108 //get the EditControl for the needed Object relations
110 oObj
= the_access
.getControl(the_Model
);
111 aControl
= the_access
.getControl(the_Model2
);
112 the_win
= the_access
.getControl(the_Model
).getPeer();
113 the_kit
= the_win
.getToolkit();
114 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
115 aGraphic
= aDevice
.createGraphics();
117 xPS
.setPropertyValue("Spin", new Boolean(true));
118 } catch (com
.sun
.star
.uno
.Exception e
) {
119 log
.println("Couldn't get EditControl");
120 e
.printStackTrace(log
);
121 throw new StatusException("Couldn't get EditControl", e
);
124 log
.println("creating a new environment for UnoControlEdit object");
126 TestEnvironment tEnv
= new TestEnvironment(oObj
);
129 //Adding ObjRelation for XView
130 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
133 //Adding ObjRelation for XControl
134 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
135 tEnv
.addObjRelation("WINPEER", the_win
);
136 tEnv
.addObjRelation("TOOLKIT", the_kit
);
137 tEnv
.addObjRelation("MODEL", the_Model
);
139 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
142 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
143 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
145 // Adding relation for XTextListener
146 ifc
.awt
._XTextListener
.TestTextListener listener
=
147 new ifc
.awt
._XTextListener
.TestTextListener();
148 XTextComponent textComp
= UnoRuntime
.queryInterface(
149 XTextComponent
.class, oObj
);
150 textComp
.addTextListener(listener
);
151 tEnv
.addObjRelation("TestTextListener", listener
);
153 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
156 } // finish method getTestEnvironment