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
.XCheckBox
;
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
.frame
.XController
;
29 import com
.sun
.star
.frame
.XFrame
;
30 import com
.sun
.star
.text
.XTextDocument
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
33 import com
.sun
.star
.view
.XControlAccess
;
35 import java
.io
.PrintWriter
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
40 import util
.FormTools
;
41 import util
.SOfficeFactory
;
42 import util
.WriterTools
;
46 public class UnoControlCheckBox
extends TestCase
{
47 private static XTextDocument xTextDoc
;
48 private static XTextDocument xTD2
;
51 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
55 log
.println("creating a textdocument");
56 xTextDoc
= SOF
.createTextDoc(null);
57 xTD2
= WriterTools
.createTextDoc(
62 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
63 log
.println(" disposing xTextDoc ");
65 util
.DesktopTools
.closeDoc(xTextDoc
);
66 util
.DesktopTools
.closeDoc(xTD2
);
70 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
71 PrintWriter log
) throws Exception
{
72 XInterface oObj
= null;
73 XWindowPeer the_win
= null;
74 XToolkit the_kit
= null;
75 XDevice aDevice
= null;
76 XGraphics aGraphic
= null;
77 XWindow anotherWindow
= null;
79 //Insert a ControlShape and get the ControlModel
80 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
84 "UnoControlCheckBox");
86 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
88 XControlModel the_Model
= aShape
.getControl();
90 //Try to query XControlAccess
91 XControlAccess the_access
= UnoRuntime
.queryInterface(
93 xTextDoc
.getCurrentController());
95 //get the CheckBoxControl for the needed Object relations
96 oObj
= the_access
.getControl(the_Model
);
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();
102 log
.println("creating a new environment for UnoControlCheckBox object");
104 TestEnvironment tEnv
= new TestEnvironment(oObj
);
107 //Adding ObjRelation for XView
108 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
111 //Adding ObjRelation for XControl
112 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
113 tEnv
.addObjRelation("WINPEER", the_win
);
114 tEnv
.addObjRelation("TOOLKIT", the_kit
);
115 tEnv
.addObjRelation("MODEL", the_Model
);
117 // adding object relation for XItemListener
118 ifc
.awt
._XItemListener
.TestItemListener listener
=
119 new ifc
.awt
._XItemListener
.TestItemListener();
120 XCheckBox check
= UnoRuntime
.queryInterface(
121 XCheckBox
.class, oObj
);
122 check
.addItemListener(listener
);
123 tEnv
.addObjRelation("TestItemListener", listener
);
125 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
127 XController aController
= xTD2
.getCurrentController();
128 XFrame aFrame
= aController
.getFrame();
129 anotherWindow
= aFrame
.getComponentWindow();
132 // Object Relation for XWindow
133 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
136 } // finish method getTestEnvironment
137 } // finish class UnoControlCheckBox