2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
20 import com
.sun
.star
.awt
.Rectangle
;
21 import com
.sun
.star
.awt
.XControl
;
22 import com
.sun
.star
.awt
.XControlModel
;
23 import com
.sun
.star
.awt
.XDevice
;
24 import com
.sun
.star
.awt
.XGraphics
;
25 import com
.sun
.star
.awt
.XToolkit
;
26 import com
.sun
.star
.awt
.XWindow
;
27 import com
.sun
.star
.awt
.XWindowPeer
;
28 import com
.sun
.star
.drawing
.XControlShape
;
29 import com
.sun
.star
.frame
.XFrame
;
30 import com
.sun
.star
.frame
.XModel
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.text
.XTextDocument
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import com
.sun
.star
.view
.XControlAccess
;
36 import java
.awt
.Dimension
;
37 import java
.awt
.Toolkit
;
39 import java
.io
.PrintWriter
;
41 import lib
.StatusException
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
46 import util
.FormTools
;
47 import util
.SOfficeFactory
;
48 import util
.WriterTools
;
52 public class UnoScrollBarControl
extends TestCase
{
53 private static XTextDocument xTextDoc
;
55 protected void initialize(TestParameters Param
, PrintWriter log
) {
56 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
57 (XMultiServiceFactory
) Param
.getMSF());
60 log
.println("creating a textdocument");
61 xTextDoc
= SOF
.createTextDoc(null);
63 log
.println("maximize the window size");
64 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
65 XFrame xFrame
= xModel
.getCurrentController().getFrame();
66 XWindow xWin
= xFrame
.getContainerWindow();
68 Toolkit
.getDefaultToolkit();
69 Dimension dim
= new Dimension(800, 600);
71 Rectangle newPosSize
= xWin
.getPosSize();
72 newPosSize
.Width
= new Double(dim
.getWidth()).intValue();
73 newPosSize
.Height
= new Double(dim
.getHeight()).intValue();
77 xWin
.setPosSize(newPosSize
.X
, newPosSize
.Y
, newPosSize
.Width
,
78 newPosSize
.Height
, com
.sun
.star
.awt
.PosSize
.POSSIZE
);
80 } catch (com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occurs.FAILED
82 e
.printStackTrace(log
);
83 throw new StatusException("Couldn't create document", e
);
87 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
88 log
.println(" disposing xTextDoc ");
90 util
.DesktopTools
.closeDoc(xTextDoc
);
93 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
95 XInterface oObj
= null;
96 XWindowPeer the_win
= null;
97 XToolkit the_kit
= null;
98 XDevice aDevice
= null;
99 XGraphics aGraphic
= null;
100 XControl aControl
= null;
102 //Insert a ControlShape and get the ControlModel
103 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
107 "UnoControlScrollBar");
109 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
111 XControlModel the_Model
= aShape
.getControl();
113 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
117 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
119 XControlModel the_Model2
= aShape2
.getControl();
121 //Try to query XControlAccess
122 XControlAccess the_access
= UnoRuntime
.queryInterface(
123 XControlAccess
.class,
124 xTextDoc
.getCurrentController());
126 //get the ScrollBarControl for the needed Object relations
128 oObj
= the_access
.getControl(the_Model
);
129 aControl
= the_access
.getControl(the_Model2
);
130 the_win
= the_access
.getControl(the_Model
).getPeer();
131 the_kit
= the_win
.getToolkit();
132 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
133 aGraphic
= aDevice
.createGraphics();
134 } catch (Exception e
) {
135 log
.println("Couldn't get ScrollBarControl");
136 e
.printStackTrace(log
);
137 throw new StatusException("Couldn't get ScrollBarControl", e
);
141 "creating a new environment for UnoControlScrollBar object");
143 TestEnvironment tEnv
= new TestEnvironment(oObj
);
146 //adding Object-Relation for XScrollBar
147 tEnv
.addObjRelation("Document", xTextDoc
);
150 //Adding ObjRelation for XView
151 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
154 //Adding ObjRelation for XControl
155 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
156 tEnv
.addObjRelation("WINPEER", the_win
);
157 tEnv
.addObjRelation("TOOLKIT", the_kit
);
158 tEnv
.addObjRelation("MODEL", the_Model
);
160 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
163 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
165 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
168 } // finish method getTestEnvironment