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
.text
.XTextDocument
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.view
.XControlAccess
;
35 import java
.awt
.Dimension
;
36 import java
.awt
.Toolkit
;
38 import java
.io
.PrintWriter
;
40 import lib
.StatusException
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
45 import util
.FormTools
;
46 import util
.SOfficeFactory
;
47 import util
.WriterTools
;
51 public class UnoScrollBarControl
extends TestCase
{
52 private static XTextDocument xTextDoc
;
55 protected void initialize(TestParameters Param
, PrintWriter log
) {
56 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
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
);
88 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
89 log
.println(" disposing xTextDoc ");
91 util
.DesktopTools
.closeDoc(xTextDoc
);
95 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
97 XInterface oObj
= null;
98 XWindowPeer the_win
= null;
99 XToolkit the_kit
= null;
100 XDevice aDevice
= null;
101 XGraphics aGraphic
= null;
102 XControl aControl
= null;
104 //Insert a ControlShape and get the ControlModel
105 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
109 "UnoControlScrollBar");
111 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
113 XControlModel the_Model
= aShape
.getControl();
115 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
119 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
121 XControlModel the_Model2
= aShape2
.getControl();
123 //Try to query XControlAccess
124 XControlAccess the_access
= UnoRuntime
.queryInterface(
125 XControlAccess
.class,
126 xTextDoc
.getCurrentController());
128 //get the ScrollBarControl for the needed Object relations
130 oObj
= the_access
.getControl(the_Model
);
131 aControl
= the_access
.getControl(the_Model2
);
132 the_win
= the_access
.getControl(the_Model
).getPeer();
133 the_kit
= the_win
.getToolkit();
134 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
135 aGraphic
= aDevice
.createGraphics();
136 } catch (Exception e
) {
137 log
.println("Couldn't get ScrollBarControl");
138 e
.printStackTrace(log
);
139 throw new StatusException("Couldn't get ScrollBarControl", e
);
143 "creating a new environment for UnoControlScrollBar object");
145 TestEnvironment tEnv
= new TestEnvironment(oObj
);
148 //adding Object-Relation for XScrollBar
149 tEnv
.addObjRelation("Document", xTextDoc
);
152 //Adding ObjRelation for XView
153 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
156 //Adding ObjRelation for XControl
157 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
158 tEnv
.addObjRelation("WINPEER", the_win
);
159 tEnv
.addObjRelation("TOOLKIT", the_kit
);
160 tEnv
.addObjRelation("MODEL", the_Model
);
162 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
165 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
167 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
170 } // finish method getTestEnvironment