Files
libreoffice/qadevOOo/tests/java/mod/_toolkit/UnoControlContainer.java

261 lines
9.6 KiB
Java
Raw Normal View History

2003-01-27 17:20:08 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2003-01-27 17:20:08 +00:00
*
* $RCSfile: UnoControlContainer.java,v $
2003-01-27 17:20:08 +00:00
*
* $Revision: 1.8 $
2003-01-27 17:20:08 +00:00
*
* last change: $Author: kz $ $Date: 2005-11-02 18:21:48 $
2003-01-27 17:20:08 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2003-01-27 17:20:08 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2003-01-27 17:20:08 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2003-01-27 17:20:08 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2003-01-27 17:20:08 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2003-01-27 17:20:08 +00:00
*
************************************************************************/
package mod._toolkit;
import com.sun.star.awt.PosSize;
import com.sun.star.awt.Rectangle;
2003-01-27 17:20:08 +00:00
import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlContainer;
2003-01-27 17:20:08 +00:00
import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XDevice;
import com.sun.star.awt.XGraphics;
2003-01-27 17:20:08 +00:00
import com.sun.star.awt.XToolkit;
import com.sun.star.awt.XWindow;
import com.sun.star.awt.XWindowPeer;
import com.sun.star.drawing.XControlShape;
import com.sun.star.drawing.XShape;
import com.sun.star.frame.XController;
import com.sun.star.frame.XFrame;
import com.sun.star.lang.XMultiServiceFactory;
2003-01-27 17:20:08 +00:00
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.XCloseable;
2003-01-27 17:20:08 +00:00
import com.sun.star.view.XControlAccess;
import java.io.PrintWriter;
import lib.StatusException;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.FormTools;
import util.WriterTools;
import util.utils;
2003-01-27 17:20:08 +00:00
public class UnoControlContainer extends TestCase {
private static XTextDocument xTextDoc;
private static XTextDocument xTD2;
private static XControl xCtrl;
private static XControl xCtrl1;
private static XControl xCtrl2;
2003-01-27 17:20:08 +00:00
protected void initialize(TestParameters param, PrintWriter log) {
try {
log.println("creating a textdocument");
xTD2 = WriterTools.createTextDoc(
(XMultiServiceFactory) param.getMSF());
xTextDoc = WriterTools.createTextDoc(
(XMultiServiceFactory) param.getMSF());
} catch (Exception e) {
2003-01-27 17:20:08 +00:00
// Some exception occures.FAILED
e.printStackTrace(log);
throw new StatusException("Couldn't create document", e);
2003-01-27 17:20:08 +00:00
}
}
protected void cleanup(TestParameters tParam, PrintWriter log) {
log.println(" disposing xTextDoc ");
util.DesktopTools.closeDoc(xTextDoc);
util.DesktopTools.closeDoc(xTD2);
2003-01-27 17:20:08 +00:00
}
public TestEnvironment createTestEnvironment(TestParameters param,
PrintWriter log) {
2003-01-27 17:20:08 +00:00
// create Object Relations -------------------------------------------
XInterface oObj = null;
XControlShape shape = null;
XControlModel model = null;
XControlAccess access = null;
XWindow anotherWindow = null;
2003-01-27 17:20:08 +00:00
// for XControl
XWindowPeer the_win = null;
XToolkit the_kit = null;
XControlContainer ctrlCont = null;
XGraphics aGraphic = null;
// create 3 XControls
2003-01-27 17:20:08 +00:00
// create first XControl
shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
10000, "TextField");
2003-01-27 17:20:08 +00:00
WriterTools.getDrawPage(xTextDoc).add((XShape) shape);
model = shape.getControl();
access = (XControlAccess) UnoRuntime.queryInterface(
XControlAccess.class, xTextDoc.getCurrentController());
try {
xCtrl = access.getControl(model);
} catch (Exception e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create XControl", e);
}
// create second XControl
shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
10000, "TextField");
WriterTools.getDrawPage(xTextDoc).add((XShape) shape);
model = shape.getControl();
access = (XControlAccess) UnoRuntime.queryInterface(
XControlAccess.class, xTextDoc.getCurrentController());
2003-01-27 17:20:08 +00:00
try {
xCtrl1 = access.getControl(model);
} catch (Exception e) {
2003-01-27 17:20:08 +00:00
e.printStackTrace(log);
throw new StatusException("Couldn't create XControl", e);
}
// create third XControl
shape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
10000, "CommandButton");
2003-01-27 17:20:08 +00:00
WriterTools.getDrawPage(xTextDoc).add((XShape) shape);
model = shape.getControl();
access = (XControlAccess) UnoRuntime.queryInterface(
XControlAccess.class, xTextDoc.getCurrentController());
2003-01-27 17:20:08 +00:00
try {
xCtrl2 = access.getControl(model);
} catch (Exception e) {
2003-01-27 17:20:08 +00:00
e.printStackTrace(log);
throw new StatusException("Couldn't create XControl", e);
}
2003-01-27 17:20:08 +00:00
// create XToolkit, XWindowPeer, XDevice
//Insert a ControlShape and get the ControlModel
XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
4500, 15000,
10000,
"CommandButton",
"UnoControlButton");
2003-01-27 17:20:08 +00:00
WriterTools.getDrawPage(xTD2).add((XShape) aShape);
2003-01-27 17:20:08 +00:00
XControlModel the_Model = aShape.getControl();
//Try to query XControlAccess
XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
XControlAccess.class,
xTD2.getCurrentController());
2003-01-27 17:20:08 +00:00
//get the ButtonControl for the needed Object relations
try {
the_win = the_access.getControl(the_Model).getPeer();
the_kit = the_win.getToolkit();
XDevice aDevice = the_kit.createScreenCompatibleDevice(200, 200);
aGraphic = aDevice.createGraphics();
2003-01-27 17:20:08 +00:00
} catch (Exception e) {
log.println("Couldn't get ButtonControl");
e.printStackTrace(log);
throw new StatusException("Couldn't get ButtonControl", e);
2003-01-27 17:20:08 +00:00
}
try {
XController aController = xTD2.getCurrentController();
XFrame aFrame = aController.getFrame();
anotherWindow = aFrame.getComponentWindow();
} catch (Exception e) {
2003-01-27 17:20:08 +00:00
e.printStackTrace(log);
throw new StatusException("Couldn't create XWindow", e);
}
// finished create Object Relations -----------------------------------
// create the UnoControlContainer
try {
oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance(
"com.sun.star.awt.UnoControlContainer");
XControl xCtrl = (XControl) UnoRuntime.queryInterface(
XControl.class, oObj);
2003-01-27 17:20:08 +00:00
xCtrl.setModel(the_Model);
ctrlCont = (XControlContainer) UnoRuntime.queryInterface(
XControlContainer.class, oObj);
ctrlCont.addControl("jupp", access.getControl(aShape.getControl()));
} catch (Exception e) {
2003-01-27 17:20:08 +00:00
e.printStackTrace(log);
throw new StatusException("Couldn't create UnoControlContainer", e);
}
log.println(
"creating a new environment for UnoControlContainer object");
TestEnvironment tEnv = new TestEnvironment(oObj);
2003-01-27 17:20:08 +00:00
XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, oObj);
Rectangle ps = xWindow.getPosSize();
xWindow.setPosSize(ps.X+10, ps.Y+10, ps.Width+10, ps.Height+10, PosSize.POSSIZE);
2003-01-27 17:20:08 +00:00
String objName = "UnoControlContainer";
tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
// Object relation for XContainer
tEnv.addObjRelation("XContainer.Container", ctrlCont);
tEnv.addObjRelation("INSTANCE", xCtrl);
//Adding ObjRelation for XView
tEnv.addObjRelation("GRAPHICS", aGraphic);
2003-01-27 17:20:08 +00:00
// Object Relation for XControlContainer
tEnv.addObjRelation("CONTROL1", xCtrl1);
tEnv.addObjRelation("CONTROL2", xCtrl2);
2003-01-27 17:20:08 +00:00
// Object Relation for XControl
tEnv.addObjRelation("CONTEXT", xTD2);
tEnv.addObjRelation("WINPEER", the_win);
tEnv.addObjRelation("TOOLKIT", the_kit);
tEnv.addObjRelation("MODEL", the_Model);
2003-01-27 17:20:08 +00:00
// Object Relation for XWindow
tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
System.out.println("ImplementationName: " + utils.getImplName(oObj));
2003-01-27 17:20:08 +00:00
return tEnv;
}
}