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