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
.text
.XTextDocument
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
33 import com
.sun
.star
.view
.XControlAccess
;
35 import java
.io
.PrintWriter
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
40 import util
.FormTools
;
41 import util
.SOfficeFactory
;
42 import util
.WriterTools
;
46 public class UnoControlFormattedField
extends TestCase
{
47 private static XTextDocument xTextDoc
;
50 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
54 log
.println("creating a textdocument");
55 xTextDoc
= SOF
.createTextDoc(null);
59 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
60 log
.println(" disposing xTextDoc ");
62 util
.DesktopTools
.closeDoc(xTextDoc
);
66 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
67 PrintWriter log
) throws Exception
{
68 XInterface oObj
= null;
69 XWindowPeer the_win
= null;
70 XToolkit the_kit
= null;
71 XDevice aDevice
= null;
72 XGraphics aGraphic
= null;
73 XControl aControl
= null;
75 //Insert a ControlShape and get the ControlModel
76 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
79 "DatabaseFormattedField",
80 "UnoControlFormattedField");
82 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
84 XControlModel the_Model
= aShape
.getControl();
86 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
90 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
92 XControlModel the_Model2
= aShape2
.getControl();
94 XPropertySet xPS
= UnoRuntime
.queryInterface(
95 XPropertySet
.class, the_Model
);
97 //Try to query XControlAccess
98 XControlAccess the_access
= UnoRuntime
.queryInterface(
100 xTextDoc
.getCurrentController());
102 //get the EditControl for the needed Object relations
103 oObj
= the_access
.getControl(the_Model
);
104 aControl
= the_access
.getControl(the_Model2
);
105 the_win
= the_access
.getControl(the_Model
).getPeer();
106 the_kit
= the_win
.getToolkit();
107 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
108 aGraphic
= aDevice
.createGraphics();
110 xPS
.setPropertyValue("Spin", Boolean
.TRUE
);
112 log
.println("creating a new environment for UnoControlEdit object");
114 TestEnvironment tEnv
= new TestEnvironment(oObj
);
117 //Adding ObjRelation for XView
118 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
121 //Adding ObjRelation for XControl
122 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
123 tEnv
.addObjRelation("WINPEER", the_win
);
124 tEnv
.addObjRelation("TOOLKIT", the_kit
);
125 tEnv
.addObjRelation("MODEL", the_Model
);
127 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
130 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
131 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
133 // Adding relation for XTextListener
134 ifc
.awt
._XTextListener
.TestTextListener listener
=
135 new ifc
.awt
._XTextListener
.TestTextListener();
136 XTextComponent textComp
= UnoRuntime
.queryInterface(
137 XTextComponent
.class, oObj
);
138 textComp
.addTextListener(listener
);
139 tEnv
.addObjRelation("TestTextListener", listener
);
141 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
144 } // finish method getTestEnvironment