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
.XControlModel
;
21 import com
.sun
.star
.awt
.XDevice
;
22 import com
.sun
.star
.awt
.XGraphics
;
23 import com
.sun
.star
.awt
.XTextComponent
;
24 import com
.sun
.star
.awt
.XToolkit
;
25 import com
.sun
.star
.awt
.XWindow
;
26 import com
.sun
.star
.awt
.XWindowPeer
;
27 import com
.sun
.star
.drawing
.XControlShape
;
28 import com
.sun
.star
.frame
.XController
;
29 import com
.sun
.star
.frame
.XFrame
;
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 UnoControlDateField
extends TestCase
{
47 private static XTextDocument xTextDoc
;
48 private static XTextDocument xTD2
;
51 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
55 log
.println("creating a textdocument");
56 xTextDoc
= SOF
.createTextDoc(null);
57 xTD2
= WriterTools
.createTextDoc(
62 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
63 log
.println(" disposing xTextDoc ");
65 util
.DesktopTools
.closeDoc(xTextDoc
);
66 util
.DesktopTools
.closeDoc(xTD2
);
70 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
71 PrintWriter log
) throws Exception
{
72 XInterface oObj
= null;
73 XWindowPeer the_win
= null;
74 XToolkit the_kit
= null;
75 XDevice aDevice
= null;
76 XGraphics aGraphic
= null;
77 XWindow anotherWindow
= null;
79 //Insert a ControlShape and get the ControlModel
80 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
84 "UnoControlDateField");
86 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
88 XControlModel the_Model
= aShape
.getControl();
90 //Try to query XControlAccess
91 XControlAccess the_access
= UnoRuntime
.queryInterface(
93 xTextDoc
.getCurrentController());
95 //get the DateFieldControl for the needed Object relations
96 oObj
= the_access
.getControl(the_Model
);
97 the_win
= the_access
.getControl(the_Model
).getPeer();
98 the_kit
= the_win
.getToolkit();
99 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
100 aGraphic
= aDevice
.createGraphics();
103 "creating a new environment for UnoControlDateField object");
105 TestEnvironment tEnv
= new TestEnvironment(oObj
);
108 //Adding ObjRelation for XView
109 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
112 //Adding ObjRelation for XControl
113 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
114 tEnv
.addObjRelation("WINPEER", the_win
);
115 tEnv
.addObjRelation("TOOLKIT", the_kit
);
116 tEnv
.addObjRelation("MODEL", the_Model
);
118 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
120 XController aController
= xTD2
.getCurrentController();
121 XFrame aFrame
= aController
.getFrame();
122 anotherWindow
= aFrame
.getComponentWindow();
125 // Object Relation for XWindow
126 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
127 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
129 // Adding relation for XTextListener
130 ifc
.awt
._XTextListener
.TestTextListener listener
=
131 new ifc
.awt
._XTextListener
.TestTextListener();
132 XTextComponent textComp
= UnoRuntime
.queryInterface(
133 XTextComponent
.class, oObj
);
134 textComp
.addTextListener(listener
);
135 tEnv
.addObjRelation("TestTextListener", listener
);
138 } // finish method getTestEnvironment
139 } // finish class UnoControlDateField