1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski package mod._toolkit; 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski import com.sun.star.awt.XCheckBox; 26*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControlModel; 27*b1cdbd2cSJim Jagielski import com.sun.star.awt.XDevice; 28*b1cdbd2cSJim Jagielski import com.sun.star.awt.XGraphics; 29*b1cdbd2cSJim Jagielski import com.sun.star.awt.XToolkit; 30*b1cdbd2cSJim Jagielski import com.sun.star.awt.XWindow; 31*b1cdbd2cSJim Jagielski import com.sun.star.awt.XWindowPeer; 32*b1cdbd2cSJim Jagielski import com.sun.star.drawing.XControlShape; 33*b1cdbd2cSJim Jagielski import com.sun.star.drawing.XShape; 34*b1cdbd2cSJim Jagielski import com.sun.star.frame.XController; 35*b1cdbd2cSJim Jagielski import com.sun.star.frame.XFrame; 36*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 37*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextDocument; 38*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 39*b1cdbd2cSJim Jagielski import com.sun.star.uno.XInterface; 40*b1cdbd2cSJim Jagielski import com.sun.star.view.XControlAccess; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski import java.io.PrintWriter; 43*b1cdbd2cSJim Jagielski 44*b1cdbd2cSJim Jagielski import lib.StatusException; 45*b1cdbd2cSJim Jagielski import lib.TestCase; 46*b1cdbd2cSJim Jagielski import lib.TestEnvironment; 47*b1cdbd2cSJim Jagielski import lib.TestParameters; 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski import util.FormTools; 50*b1cdbd2cSJim Jagielski import util.SOfficeFactory; 51*b1cdbd2cSJim Jagielski import util.WriterTools; 52*b1cdbd2cSJim Jagielski import util.utils; 53*b1cdbd2cSJim Jagielski 54*b1cdbd2cSJim Jagielski 55*b1cdbd2cSJim Jagielski public class UnoControlCheckBox extends TestCase { 56*b1cdbd2cSJim Jagielski private static XTextDocument xTextDoc; 57*b1cdbd2cSJim Jagielski private static XTextDocument xTD2; 58*b1cdbd2cSJim Jagielski initialize(TestParameters Param, PrintWriter log)59*b1cdbd2cSJim Jagielski protected void initialize(TestParameters Param, PrintWriter log) { 60*b1cdbd2cSJim Jagielski SOfficeFactory SOF = SOfficeFactory.getFactory( 61*b1cdbd2cSJim Jagielski (XMultiServiceFactory) Param.getMSF()); 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski try { 64*b1cdbd2cSJim Jagielski log.println("creating a textdocument"); 65*b1cdbd2cSJim Jagielski xTextDoc = SOF.createTextDoc(null); 66*b1cdbd2cSJim Jagielski xTD2 = WriterTools.createTextDoc( 67*b1cdbd2cSJim Jagielski (XMultiServiceFactory) Param.getMSF()); 68*b1cdbd2cSJim Jagielski } catch (com.sun.star.uno.Exception e) { 69*b1cdbd2cSJim Jagielski // Some exception occures.FAILED 70*b1cdbd2cSJim Jagielski e.printStackTrace(log); 71*b1cdbd2cSJim Jagielski throw new StatusException("Couldn't create document", e); 72*b1cdbd2cSJim Jagielski } 73*b1cdbd2cSJim Jagielski } 74*b1cdbd2cSJim Jagielski cleanup(TestParameters tParam, PrintWriter log)75*b1cdbd2cSJim Jagielski protected void cleanup(TestParameters tParam, PrintWriter log) { 76*b1cdbd2cSJim Jagielski log.println(" disposing xTextDoc "); 77*b1cdbd2cSJim Jagielski 78*b1cdbd2cSJim Jagielski util.DesktopTools.closeDoc(xTextDoc); 79*b1cdbd2cSJim Jagielski util.DesktopTools.closeDoc(xTD2); 80*b1cdbd2cSJim Jagielski } 81*b1cdbd2cSJim Jagielski createTestEnvironment(TestParameters Param, PrintWriter log)82*b1cdbd2cSJim Jagielski protected TestEnvironment createTestEnvironment(TestParameters Param, 83*b1cdbd2cSJim Jagielski PrintWriter log) { 84*b1cdbd2cSJim Jagielski XInterface oObj = null; 85*b1cdbd2cSJim Jagielski XWindowPeer the_win = null; 86*b1cdbd2cSJim Jagielski XToolkit the_kit = null; 87*b1cdbd2cSJim Jagielski XDevice aDevice = null; 88*b1cdbd2cSJim Jagielski XGraphics aGraphic = null; 89*b1cdbd2cSJim Jagielski XWindow anotherWindow = null; 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski //Insert a ControlShape and get the ControlModel 92*b1cdbd2cSJim Jagielski XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 93*b1cdbd2cSJim Jagielski 4500, 15000, 94*b1cdbd2cSJim Jagielski 10000, 95*b1cdbd2cSJim Jagielski "CheckBox", 96*b1cdbd2cSJim Jagielski "UnoControlCheckBox"); 97*b1cdbd2cSJim Jagielski 98*b1cdbd2cSJim Jagielski WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 99*b1cdbd2cSJim Jagielski 100*b1cdbd2cSJim Jagielski XControlModel the_Model = aShape.getControl(); 101*b1cdbd2cSJim Jagielski 102*b1cdbd2cSJim Jagielski //Try to query XControlAccess 103*b1cdbd2cSJim Jagielski XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 104*b1cdbd2cSJim Jagielski XControlAccess.class, 105*b1cdbd2cSJim Jagielski xTextDoc.getCurrentController()); 106*b1cdbd2cSJim Jagielski 107*b1cdbd2cSJim Jagielski //get the CheckBoxControl for the needed Object relations 108*b1cdbd2cSJim Jagielski try { 109*b1cdbd2cSJim Jagielski oObj = the_access.getControl(the_Model); 110*b1cdbd2cSJim Jagielski the_win = the_access.getControl(the_Model).getPeer(); 111*b1cdbd2cSJim Jagielski the_kit = the_win.getToolkit(); 112*b1cdbd2cSJim Jagielski aDevice = the_kit.createScreenCompatibleDevice(200, 200); 113*b1cdbd2cSJim Jagielski aGraphic = aDevice.createGraphics(); 114*b1cdbd2cSJim Jagielski } catch (Exception e) { 115*b1cdbd2cSJim Jagielski log.println("Couldn't get CheckBoxControl"); 116*b1cdbd2cSJim Jagielski e.printStackTrace(log); 117*b1cdbd2cSJim Jagielski throw new StatusException("Couldn't get CheckBoxControl", e); 118*b1cdbd2cSJim Jagielski } 119*b1cdbd2cSJim Jagielski 120*b1cdbd2cSJim Jagielski log.println("creating a new environment for UnoControlCheckBox object"); 121*b1cdbd2cSJim Jagielski 122*b1cdbd2cSJim Jagielski TestEnvironment tEnv = new TestEnvironment(oObj); 123*b1cdbd2cSJim Jagielski 124*b1cdbd2cSJim Jagielski 125*b1cdbd2cSJim Jagielski //Adding ObjRelation for XView 126*b1cdbd2cSJim Jagielski tEnv.addObjRelation("GRAPHICS", aGraphic); 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski 129*b1cdbd2cSJim Jagielski //Adding ObjRelation for XControl 130*b1cdbd2cSJim Jagielski tEnv.addObjRelation("CONTEXT", xTextDoc); 131*b1cdbd2cSJim Jagielski tEnv.addObjRelation("WINPEER", the_win); 132*b1cdbd2cSJim Jagielski tEnv.addObjRelation("TOOLKIT", the_kit); 133*b1cdbd2cSJim Jagielski tEnv.addObjRelation("MODEL", the_Model); 134*b1cdbd2cSJim Jagielski 135*b1cdbd2cSJim Jagielski // adding object relation for XItemListener 136*b1cdbd2cSJim Jagielski ifc.awt._XItemListener.TestItemListener listener = 137*b1cdbd2cSJim Jagielski new ifc.awt._XItemListener.TestItemListener(); 138*b1cdbd2cSJim Jagielski XCheckBox check = (XCheckBox) UnoRuntime.queryInterface( 139*b1cdbd2cSJim Jagielski XCheckBox.class, oObj); 140*b1cdbd2cSJim Jagielski check.addItemListener(listener); 141*b1cdbd2cSJim Jagielski tEnv.addObjRelation("TestItemListener", listener); 142*b1cdbd2cSJim Jagielski 143*b1cdbd2cSJim Jagielski System.out.println("ImplementationName: " + utils.getImplName(oObj)); 144*b1cdbd2cSJim Jagielski 145*b1cdbd2cSJim Jagielski try { 146*b1cdbd2cSJim Jagielski XController aController = xTD2.getCurrentController(); 147*b1cdbd2cSJim Jagielski XFrame aFrame = aController.getFrame(); 148*b1cdbd2cSJim Jagielski anotherWindow = aFrame.getComponentWindow(); 149*b1cdbd2cSJim Jagielski } catch (Exception e) { 150*b1cdbd2cSJim Jagielski e.printStackTrace(log); 151*b1cdbd2cSJim Jagielski throw new StatusException("Couldn't create XWindow", e); 152*b1cdbd2cSJim Jagielski } 153*b1cdbd2cSJim Jagielski 154*b1cdbd2cSJim Jagielski 155*b1cdbd2cSJim Jagielski // Object Relation for XWindow 156*b1cdbd2cSJim Jagielski tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow); 157*b1cdbd2cSJim Jagielski 158*b1cdbd2cSJim Jagielski return tEnv; 159*b1cdbd2cSJim Jagielski } // finish method getTestEnvironment 160*b1cdbd2cSJim Jagielski } // finish class UnoControlCheckBox 161