1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package mod._toolkit; 19 20 import com.sun.star.awt.XControl; 21 import com.sun.star.awt.XControlModel; 22 import com.sun.star.awt.XDevice; 23 import com.sun.star.awt.XGraphics; 24 import com.sun.star.awt.XToolkit; 25 import com.sun.star.awt.XWindow; 26 import com.sun.star.awt.XWindowPeer; 27 import com.sun.star.drawing.XControlShape; 28 import com.sun.star.text.XTextDocument; 29 import com.sun.star.uno.UnoRuntime; 30 import com.sun.star.uno.XInterface; 31 import com.sun.star.view.XControlAccess; 32 33 import java.io.PrintWriter; 34 35 import lib.TestCase; 36 import lib.TestEnvironment; 37 import lib.TestParameters; 38 import util.FormTools; 39 import util.WriterTools; 40 import util.utils; 41 42 43 public class UnoSpinButtonControl extends TestCase { 44 private static XTextDocument xTextDoc; 45 46 @Override initialize(TestParameters Param, PrintWriter log)47 protected void initialize(TestParameters Param, PrintWriter log) throws Exception { 48 log.println("creating a textdocument"); 49 xTextDoc = WriterTools.createTextDoc( 50 Param.getMSF()); 51 } 52 53 @Override cleanup(TestParameters tParam, PrintWriter log)54 protected void cleanup(TestParameters tParam, PrintWriter log) { 55 log.println(" disposing xTextDoc "); 56 57 util.DesktopTools.closeDoc(xTextDoc); 58 } 59 60 @Override createTestEnvironment(TestParameters Param, PrintWriter log)61 protected TestEnvironment createTestEnvironment(TestParameters Param, 62 PrintWriter log) throws Exception { 63 XInterface oObj = null; 64 XWindowPeer the_win = null; 65 XToolkit the_kit = null; 66 XDevice aDevice = null; 67 XGraphics aGraphic = null; 68 XControl aControl = null; 69 70 //Insert a ControlShape and get the ControlModel 71 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 72 4500, 15000, 73 10000, 74 "SpinButton", 75 "UnoControlSpinButton"); 76 77 WriterTools.getDrawPage(xTextDoc).add(aShape); 78 79 XControlModel the_Model = aShape.getControl(); 80 81 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 82 4500, 5000, 10000, 83 "TextField"); 84 85 WriterTools.getDrawPage(xTextDoc).add(aShape2); 86 87 XControlModel the_Model2 = aShape2.getControl(); 88 89 //Try to query XControlAccess 90 XControlAccess the_access = UnoRuntime.queryInterface( 91 XControlAccess.class, 92 xTextDoc.getCurrentController()); 93 94 //get the SpinButtonControl for the needed Object relations 95 oObj = the_access.getControl(the_Model); 96 aControl = the_access.getControl(the_Model2); 97 the_win = the_access.getControl(the_Model).getPeer(); 98 the_kit = the_win.getToolkit(); 99 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 100 aGraphic = aDevice.createGraphics(); 101 102 log.println( 103 "creating a new environment for UnoControlSpinButton object"); 104 105 TestEnvironment tEnv = new TestEnvironment(oObj); 106 107 108 //adding Object-Relation for XScrollBar 109 tEnv.addObjRelation("Document", xTextDoc); 110 111 112 //Adding ObjRelation for XView 113 tEnv.addObjRelation("GRAPHICS", aGraphic); 114 115 116 //Adding ObjRelation for XControl 117 tEnv.addObjRelation("CONTEXT", xTextDoc); 118 tEnv.addObjRelation("WINPEER", the_win); 119 tEnv.addObjRelation("TOOLKIT", the_kit); 120 tEnv.addObjRelation("MODEL", the_Model); 121 122 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class, 123 aControl); 124 125 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 126 127 tEnv.addObjRelation("Document", xTextDoc); 128 129 System.out.println("ImplementationName: " + utils.getImplName(oObj)); 130 131 return tEnv; 132 } // finish method getTestEnvironment 133 } 134