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
;
36 import java
.awt
.Dimension
;
37 import java
.awt
.Toolkit
;
38 import java
.io
.PrintWriter
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
43 import util
.FormTools
;
44 import util
.SOfficeFactory
;
45 import util
.WriterTools
;
49 public class UnoScrollBarControl
extends TestCase
{
50 private static XTextDocument xTextDoc
;
53 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
54 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
57 log
.println("creating a textdocument");
58 xTextDoc
= SOF
.createTextDoc(null);
60 log
.println("maximize the window size");
61 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
62 XFrame xFrame
= xModel
.getCurrentController().getFrame();
63 XWindow xWin
= xFrame
.getContainerWindow();
65 Toolkit
.getDefaultToolkit();
66 Dimension dim
= new Dimension(800, 600);
68 Rectangle newPosSize
= xWin
.getPosSize();
69 newPosSize
.Width
= (int) dim
.getWidth();
70 newPosSize
.Height
= (int) dim
.getHeight();
74 xWin
.setPosSize(newPosSize
.X
, newPosSize
.Y
, newPosSize
.Width
,
75 newPosSize
.Height
, com
.sun
.star
.awt
.PosSize
.POSSIZE
);
79 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
80 log
.println(" disposing xTextDoc ");
82 util
.DesktopTools
.closeDoc(xTextDoc
);
86 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
87 PrintWriter log
) throws Exception
{
88 XInterface oObj
= null;
89 XWindowPeer the_win
= null;
90 XToolkit the_kit
= null;
91 XDevice aDevice
= null;
92 XGraphics aGraphic
= null;
93 XControl aControl
= null;
95 //Insert a ControlShape and get the ControlModel
96 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
100 "UnoControlScrollBar");
102 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
104 XControlModel the_Model
= aShape
.getControl();
106 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
110 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
112 XControlModel the_Model2
= aShape2
.getControl();
114 //Try to query XControlAccess
115 XControlAccess the_access
= UnoRuntime
.queryInterface(
116 XControlAccess
.class,
117 xTextDoc
.getCurrentController());
119 //get the ScrollBarControl for the needed Object relations
120 oObj
= the_access
.getControl(the_Model
);
121 aControl
= the_access
.getControl(the_Model2
);
122 the_win
= the_access
.getControl(the_Model
).getPeer();
123 the_kit
= the_win
.getToolkit();
124 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
125 aGraphic
= aDevice
.createGraphics();
128 "creating a new environment for UnoControlScrollBar object");
130 TestEnvironment tEnv
= new TestEnvironment(oObj
);
133 //adding Object-Relation for XScrollBar
134 tEnv
.addObjRelation("Document", xTextDoc
);
137 //Adding ObjRelation for XView
138 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
141 //Adding ObjRelation for XControl
142 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
143 tEnv
.addObjRelation("WINPEER", the_win
);
144 tEnv
.addObjRelation("TOOLKIT", the_kit
);
145 tEnv
.addObjRelation("MODEL", the_Model
);
147 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
150 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
152 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
155 } // finish method getTestEnvironment