merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlFixedText.java
blob8010c278f707a6ff136b8d8f05390cb2008a1cfa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoControlFixedText.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._toolkit;
32 import com.sun.star.awt.XControl;
33 import com.sun.star.awt.XControlModel;
34 import com.sun.star.awt.XDevice;
35 import com.sun.star.awt.XGraphics;
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.drawing.XShape;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.view.XControlAccess;
47 import java.io.PrintWriter;
49 import lib.StatusException;
50 import lib.TestCase;
51 import lib.TestEnvironment;
52 import lib.TestParameters;
54 import util.FormTools;
55 import util.SOfficeFactory;
56 import util.WriterTools;
57 import util.utils;
60 public class UnoControlFixedText extends TestCase {
61 private static XTextDocument xTextDoc;
63 protected void initialize(TestParameters Param, PrintWriter log) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory(
65 (XMultiServiceFactory) Param.getMSF());
67 try {
68 log.println("creating a textdocument");
69 xTextDoc = SOF.createTextDoc(null);
70 } catch (com.sun.star.uno.Exception e) {
71 // Some exception occures.FAILED
72 e.printStackTrace(log);
73 throw new StatusException("Couldn't create document", e);
77 protected void cleanup(TestParameters tParam, PrintWriter log) {
78 log.println(" disposing xTextDoc ");
80 util.DesktopTools.closeDoc(xTextDoc);
83 protected TestEnvironment createTestEnvironment(TestParameters Param,
84 PrintWriter log) {
85 XInterface oObj = null;
86 XWindowPeer the_win = null;
87 XToolkit the_kit = null;
88 XDevice aDevice = null;
89 XGraphics aGraphic = null;
90 XControl aControl = null;
92 //Insert a ControlShape and get the ControlModel
93 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
94 4500, 15000,
95 10000,
96 "FixedText",
97 "UnoControlFixedText");
99 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
101 XControlModel the_Model = aShape.getControl();
103 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
104 4500, 5000, 10000,
105 "TextField");
107 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
109 XControlModel the_Model2 = aShape2.getControl();
111 //Try to query XControlAccess
112 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
113 XControlAccess.class,
114 xTextDoc.getCurrentController());
116 //get the FixedTextControl for the needed Object relations
117 try {
118 oObj = the_access.getControl(the_Model);
119 aControl = the_access.getControl(the_Model2);
120 the_win = the_access.getControl(the_Model).getPeer();
121 the_kit = the_win.getToolkit();
122 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
123 aGraphic = aDevice.createGraphics();
124 } catch (Exception e) {
125 log.println("Couldn't get FixedTextControl");
126 e.printStackTrace(log);
127 throw new StatusException("Couldn't get FixedTextControl", e);
130 log.println(
131 "creating a new environment for UnoControlFixedText object");
133 TestEnvironment tEnv = new TestEnvironment(oObj);
136 //Adding ObjRelation for XView
137 tEnv.addObjRelation("GRAPHICS", aGraphic);
140 //Adding ObjRelation for XControl
141 tEnv.addObjRelation("CONTEXT", xTextDoc);
142 tEnv.addObjRelation("WINPEER", the_win);
143 tEnv.addObjRelation("TOOLKIT", the_kit);
144 tEnv.addObjRelation("MODEL", the_Model);
146 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
147 aControl);
149 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
151 System.out.println("ImplementationName: " + utils.getImplName(oObj));
153 return tEnv;
154 } // finish method getTestEnvironment
155 } // finish class UnoControlFixedText