1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package mod._toolkit; 28 29 import com.sun.star.awt.XControl; 30 import com.sun.star.awt.XControlModel; 31 import com.sun.star.awt.XDevice; 32 import com.sun.star.awt.XGraphics; 33 import com.sun.star.awt.XToolkit; 34 import com.sun.star.awt.XWindow; 35 import com.sun.star.awt.XWindowPeer; 36 import com.sun.star.drawing.XControlShape; 37 import com.sun.star.drawing.XShape; 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.XInterface; 42 import com.sun.star.view.XControlAccess; 43 44 import java.io.PrintWriter; 45 46 import lib.StatusException; 47 import lib.TestCase; 48 import lib.TestEnvironment; 49 import lib.TestParameters; 50 51 import util.FormTools; 52 import util.WriterTools; 53 import util.utils; 54 55 56 public class UnoSpinButtonControl extends TestCase { 57 private static XTextDocument xTextDoc; 58 59 protected void initialize(TestParameters Param, PrintWriter log) { 60 log.println("creating a textdocument"); 61 xTextDoc = WriterTools.createTextDoc( 62 (XMultiServiceFactory) Param.getMSF()); 63 } 64 65 protected void cleanup(TestParameters tParam, PrintWriter log) { 66 log.println(" disposing xTextDoc "); 67 68 util.DesktopTools.closeDoc(xTextDoc); 69 } 70 71 protected TestEnvironment createTestEnvironment(TestParameters Param, 72 PrintWriter log) { 73 XInterface oObj = null; 74 XWindowPeer the_win = null; 75 XToolkit the_kit = null; 76 XDevice aDevice = null; 77 XGraphics aGraphic = null; 78 XControl aControl = null; 79 80 //Insert a ControlShape and get the ControlModel 81 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 82 4500, 15000, 83 10000, 84 "SpinButton", 85 "UnoControlSpinButton"); 86 87 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 88 89 XControlModel the_Model = aShape.getControl(); 90 91 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 92 4500, 5000, 10000, 93 "TextField"); 94 95 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 96 97 XControlModel the_Model2 = aShape2.getControl(); 98 99 //Try to query XControlAccess 100 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 101 XControlAccess.class, 102 xTextDoc.getCurrentController()); 103 104 //get the SpinButtonControl for the needed Object relations 105 try { 106 oObj = the_access.getControl(the_Model); 107 aControl = the_access.getControl(the_Model2); 108 the_win = the_access.getControl(the_Model).getPeer(); 109 the_kit = the_win.getToolkit(); 110 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 111 aGraphic = aDevice.createGraphics(); 112 } catch (Exception e) { 113 log.println("Couldn't get SpinButtonControl"); 114 e.printStackTrace(log); 115 throw new StatusException("Couldn't get SpinButtonControl", e); 116 } 117 118 log.println( 119 "creating a new environment for UnoControlSpinButton object"); 120 121 TestEnvironment tEnv = new TestEnvironment(oObj); 122 123 124 //adding Object-Relation for XScrollBar 125 tEnv.addObjRelation("Document", xTextDoc); 126 127 128 //Adding ObjRelation for XView 129 tEnv.addObjRelation("GRAPHICS", aGraphic); 130 131 132 //Adding ObjRelation for XControl 133 tEnv.addObjRelation("CONTEXT", xTextDoc); 134 tEnv.addObjRelation("WINPEER", the_win); 135 tEnv.addObjRelation("TOOLKIT", the_kit); 136 tEnv.addObjRelation("MODEL", the_Model); 137 138 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 139 aControl); 140 141 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 142 143 tEnv.addObjRelation("Document", xTextDoc); 144 145 System.out.println("ImplementationName: " + utils.getImplName(oObj)); 146 147 return tEnv; 148 } // finish method getTestEnvironment 149 } 150