2003-01-27 17:20:08 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* $RCSfile: UnoControlContainer.java,v $
|
|
|
|
* $Revision: 1.9 $
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2008-04-10 18:52:35 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
package mod._toolkit;
|
|
|
|
|
2004-05-03 07:49:10 +00:00
|
|
|
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;
|
2003-11-18 15:31:51 +00:00
|
|
|
import com.sun.star.awt.XControlContainer;
|
2003-01-27 17:20:08 +00:00
|
|
|
import com.sun.star.awt.XControlModel;
|
2003-11-18 15:31:51 +00:00
|
|
|
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;
|
2003-09-08 12:04:40 +00:00
|
|
|
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.view.XControlAccess;
|
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
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 {
|
2005-11-02 17:21:48 +00:00
|
|
|
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 {
|
2003-09-08 12:04:40 +00:00
|
|
|
log.println("creating a textdocument");
|
2004-01-05 19:45:38 +00:00
|
|
|
xTD2 = WriterTools.createTextDoc(
|
|
|
|
(XMultiServiceFactory) param.getMSF());
|
|
|
|
xTextDoc = WriterTools.createTextDoc(
|
|
|
|
(XMultiServiceFactory) param.getMSF());
|
2003-09-08 12:04:40 +00:00
|
|
|
} catch (Exception e) {
|
2003-01-27 17:20:08 +00:00
|
|
|
// Some exception occures.FAILED
|
2003-09-08 12:04:40 +00:00
|
|
|
e.printStackTrace(log);
|
|
|
|
throw new StatusException("Couldn't create document", e);
|
2003-01-27 17:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-08 12:04:40 +00:00
|
|
|
protected void cleanup(TestParameters tParam, PrintWriter log) {
|
|
|
|
log.println(" disposing xTextDoc ");
|
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
util.DesktopTools.closeDoc(xTextDoc);
|
|
|
|
util.DesktopTools.closeDoc(xTD2);
|
2003-01-27 17:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TestEnvironment createTestEnvironment(TestParameters param,
|
2003-09-08 12:04:40 +00:00
|
|
|
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-09-08 12:04:40 +00:00
|
|
|
|
2003-01-27 17:20:08 +00:00
|
|
|
// for XControl
|
|
|
|
XWindowPeer the_win = null;
|
|
|
|
XToolkit the_kit = null;
|
2003-09-08 12:04:40 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
XControlContainer ctrlCont = null;
|
2003-09-08 12:04:40 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
XGraphics aGraphic = null;
|
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
// create 3 XControls
|
2003-01-27 17:20:08 +00:00
|
|
|
// create first XControl
|
2003-09-08 12:04:40 +00:00
|
|
|
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();
|
2003-09-08 12:04:40 +00:00
|
|
|
access = (XControlAccess) UnoRuntime.queryInterface(
|
|
|
|
XControlAccess.class, xTextDoc.getCurrentController());
|
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
try {
|
|
|
|
xCtrl = access.getControl(model);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace(log);
|
|
|
|
throw new StatusException("Couldn't create XControl", e);
|
|
|
|
}
|
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
// 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);
|
2003-09-08 12:04:40 +00:00
|
|
|
} catch (Exception e) {
|
2003-01-27 17:20:08 +00:00
|
|
|
e.printStackTrace(log);
|
|
|
|
throw new StatusException("Couldn't create XControl", e);
|
|
|
|
}
|
2003-09-08 12:04:40 +00:00
|
|
|
|
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
// create third XControl
|
2003-09-08 12:04:40 +00:00
|
|
|
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();
|
2003-09-08 12:04:40 +00:00
|
|
|
access = (XControlAccess) UnoRuntime.queryInterface(
|
|
|
|
XControlAccess.class, xTextDoc.getCurrentController());
|
|
|
|
|
2003-01-27 17:20:08 +00:00
|
|
|
try {
|
|
|
|
xCtrl2 = access.getControl(model);
|
2003-09-08 12:04:40 +00:00
|
|
|
} catch (Exception e) {
|
2003-01-27 17:20:08 +00:00
|
|
|
e.printStackTrace(log);
|
|
|
|
throw new StatusException("Couldn't create XControl", e);
|
|
|
|
}
|
2003-09-08 12:04:40 +00:00
|
|
|
|
2003-01-27 17:20:08 +00:00
|
|
|
// create XToolkit, XWindowPeer, XDevice
|
|
|
|
//Insert a ControlShape and get the ControlModel
|
2003-09-08 12:04:40 +00:00
|
|
|
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-09-08 12:04:40 +00:00
|
|
|
|
2003-01-27 17:20:08 +00:00
|
|
|
XControlModel the_Model = aShape.getControl();
|
|
|
|
|
|
|
|
//Try to query XControlAccess
|
|
|
|
XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
|
2003-09-08 12:04:40 +00:00
|
|
|
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();
|
2004-01-05 19:45:38 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
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);
|
2003-09-08 12:04:40 +00:00
|
|
|
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();
|
2003-09-08 12:04:40 +00:00
|
|
|
} 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 {
|
2004-01-05 19:45:38 +00:00
|
|
|
oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance(
|
|
|
|
"com.sun.star.awt.UnoControlContainer");
|
2003-09-08 12:04:40 +00:00
|
|
|
|
|
|
|
XControl xCtrl = (XControl) UnoRuntime.queryInterface(
|
|
|
|
XControl.class, oObj);
|
2003-01-27 17:20:08 +00:00
|
|
|
xCtrl.setModel(the_Model);
|
2003-11-18 15:31:51 +00:00
|
|
|
|
|
|
|
ctrlCont = (XControlContainer) UnoRuntime.queryInterface(
|
|
|
|
XControlContainer.class, oObj);
|
2004-05-03 07:49:10 +00:00
|
|
|
ctrlCont.addControl("jupp", access.getControl(aShape.getControl()));
|
2003-09-08 12:04:40 +00:00
|
|
|
} catch (Exception e) {
|
2003-01-27 17:20:08 +00:00
|
|
|
e.printStackTrace(log);
|
|
|
|
throw new StatusException("Couldn't create UnoControlContainer", e);
|
|
|
|
}
|
|
|
|
|
2003-09-08 12:04:40 +00:00
|
|
|
log.println(
|
|
|
|
"creating a new environment for UnoControlContainer object");
|
|
|
|
|
|
|
|
TestEnvironment tEnv = new TestEnvironment(oObj);
|
2003-01-27 17:20:08 +00:00
|
|
|
|
2004-05-03 07:49:10 +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);
|
2003-09-08 12:04:40 +00:00
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
// Object relation for XContainer
|
|
|
|
tEnv.addObjRelation("XContainer.Container", ctrlCont);
|
|
|
|
tEnv.addObjRelation("INSTANCE", xCtrl);
|
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
|
2003-11-18 15:31:51 +00:00
|
|
|
//Adding ObjRelation for XView
|
|
|
|
tEnv.addObjRelation("GRAPHICS", aGraphic);
|
2003-09-08 12:04:40 +00:00
|
|
|
|
2004-01-05 19:45:38 +00:00
|
|
|
|
2003-01-27 17:20:08 +00:00
|
|
|
// Object Relation for XControlContainer
|
|
|
|
tEnv.addObjRelation("CONTROL1", xCtrl1);
|
|
|
|
tEnv.addObjRelation("CONTROL2", xCtrl2);
|
2003-09-08 12:04:40 +00:00
|
|
|
|
|
|
|
|
2003-01-27 17:20:08 +00:00
|
|
|
// Object Relation for XControl
|
|
|
|
tEnv.addObjRelation("CONTEXT", xTD2);
|
2003-09-08 12:04:40 +00:00
|
|
|
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);
|
2003-09-08 12:04:40 +00:00
|
|
|
System.out.println("ImplementationName: " + utils.getImplName(oObj));
|
2003-01-27 17:20:08 +00:00
|
|
|
|
|
|
|
return tEnv;
|
|
|
|
}
|
2009-05-07 06:54:56 +00:00
|
|
|
}
|