2003-01-27 17:20:08 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: UnoControlContainer.java,v $
|
|
|
|
*
|
2003-09-08 12:04:40 +00:00
|
|
|
* $Revision: 1.3 $
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
2003-09-08 12:04:40 +00:00
|
|
|
* last change:$Date: 2003-09-08 13:04:40 $
|
2003-01-27 17:20:08 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
package mod._toolkit;
|
|
|
|
|
2003-09-08 12:04:40 +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
|
|
|
import com.sun.star.awt.XControl;
|
|
|
|
import com.sun.star.awt.XControlModel;
|
|
|
|
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;
|
2003-09-08 12:04:40 +00:00
|
|
|
import com.sun.star.util.XCloseable;
|
2003-01-27 17:20:08 +00:00
|
|
|
import com.sun.star.view.XControlAccess;
|
|
|
|
|
|
|
|
|
|
|
|
public class UnoControlContainer extends TestCase {
|
|
|
|
XTextDocument xTextDoc;
|
|
|
|
XTextDocument xTD2;
|
|
|
|
XControl xCtrl1;
|
|
|
|
XControl xCtrl2;
|
|
|
|
|
|
|
|
protected void initialize(TestParameters param, PrintWriter log) {
|
|
|
|
try {
|
2003-09-08 12:04:40 +00:00
|
|
|
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
|
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 ");
|
|
|
|
|
|
|
|
try {
|
|
|
|
XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
|
|
|
|
XCloseable.class, xTextDoc);
|
|
|
|
closer.close(true);
|
|
|
|
|
|
|
|
closer = (XCloseable) UnoRuntime.queryInterface(XCloseable.class,
|
|
|
|
xTD2);
|
|
|
|
closer.close(true);
|
|
|
|
} catch (com.sun.star.util.CloseVetoException e) {
|
|
|
|
log.println("couldn't close document");
|
|
|
|
} catch (com.sun.star.lang.DisposedException e) {
|
|
|
|
log.println("couldn't close document");
|
|
|
|
}
|
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-01-27 17:20:08 +00:00
|
|
|
// create 2 XControls
|
|
|
|
// 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-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-01-27 17:20:08 +00:00
|
|
|
// create second 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();
|
2003-09-08 12:04:40 +00:00
|
|
|
//aDevice = the_kit.createScreenCompatibleDevice(200, 200);
|
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 {
|
2003-09-08 12:04:40 +00:00
|
|
|
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);
|
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
|
|
|
|
|
|
|
String objName = "UnoControlContainer";
|
|
|
|
tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
|
2003-09-08 12:04:40 +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;
|
|
|
|
}
|
2003-09-08 12:04:40 +00:00
|
|
|
}
|