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
;
37 import lib
.StatusException
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
42 import util
.FormTools
;
43 import util
.SOfficeFactory
;
44 import util
.WriterTools
;
48 public class UnoControlFormattedField
extends TestCase
{
49 private static XTextDocument xTextDoc
;
52 protected void initialize(TestParameters Param
, PrintWriter log
) {
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
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
);
67 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
68 log
.println(" disposing xTextDoc ");
70 util
.DesktopTools
.closeDoc(xTextDoc
);
74 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
76 XInterface oObj
= null;
77 XWindowPeer the_win
= null;
78 XToolkit the_kit
= null;
79 XDevice aDevice
= null;
80 XGraphics aGraphic
= null;
81 XControl aControl
= null;
83 //Insert a ControlShape and get the ControlModel
84 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
87 "DatabaseFormattedField",
88 "UnoControlFormattedField");
90 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
92 XControlModel the_Model
= aShape
.getControl();
94 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
98 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
100 XControlModel the_Model2
= aShape2
.getControl();
102 XPropertySet xPS
= UnoRuntime
.queryInterface(
103 XPropertySet
.class, the_Model
);
105 //Try to query XControlAccess
106 XControlAccess the_access
= UnoRuntime
.queryInterface(
107 XControlAccess
.class,
108 xTextDoc
.getCurrentController());
110 //get the EditControl for the needed Object relations
112 oObj
= the_access
.getControl(the_Model
);
113 aControl
= the_access
.getControl(the_Model2
);
114 the_win
= the_access
.getControl(the_Model
).getPeer();
115 the_kit
= the_win
.getToolkit();
116 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
117 aGraphic
= aDevice
.createGraphics();
119 xPS
.setPropertyValue("Spin", Boolean
.TRUE
);
120 } catch (com
.sun
.star
.uno
.Exception e
) {
121 log
.println("Couldn't get EditControl");
122 e
.printStackTrace(log
);
123 throw new StatusException("Couldn't get EditControl", e
);
126 log
.println("creating a new environment for UnoControlEdit object");
128 TestEnvironment tEnv
= new TestEnvironment(oObj
);
131 //Adding ObjRelation for XView
132 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
135 //Adding ObjRelation for XControl
136 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
137 tEnv
.addObjRelation("WINPEER", the_win
);
138 tEnv
.addObjRelation("TOOLKIT", the_kit
);
139 tEnv
.addObjRelation("MODEL", the_Model
);
141 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
144 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
145 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
147 // Adding relation for XTextListener
148 ifc
.awt
._XTextListener
.TestTextListener listener
=
149 new ifc
.awt
._XTextListener
.TestTextListener();
150 XTextComponent textComp
= UnoRuntime
.queryInterface(
151 XTextComponent
.class, oObj
);
152 textComp
.addTextListener(listener
);
153 tEnv
.addObjRelation("TestTextListener", listener
);
155 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
158 } // finish method getTestEnvironment