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
;
37 import lib
.StatusException
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
42 import util
.FormTools
;
43 import util
.SOfficeFactory
;
44 import util
.WriterTools
;
48 public class UnoControlCheckBox
extends TestCase
{
49 private static XTextDocument xTextDoc
;
50 private static XTextDocument xTD2
;
53 protected void initialize(TestParameters Param
, PrintWriter log
) {
54 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
58 log
.println("creating a textdocument");
59 xTextDoc
= SOF
.createTextDoc(null);
60 xTD2
= WriterTools
.createTextDoc(
62 } catch (com
.sun
.star
.uno
.Exception e
) {
63 // Some exception occurs.FAILED
64 e
.printStackTrace(log
);
65 throw new StatusException("Couldn't create document", e
);
70 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
71 log
.println(" disposing xTextDoc ");
73 util
.DesktopTools
.closeDoc(xTextDoc
);
74 util
.DesktopTools
.closeDoc(xTD2
);
78 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
80 XInterface oObj
= null;
81 XWindowPeer the_win
= null;
82 XToolkit the_kit
= null;
83 XDevice aDevice
= null;
84 XGraphics aGraphic
= null;
85 XWindow anotherWindow
= null;
87 //Insert a ControlShape and get the ControlModel
88 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
92 "UnoControlCheckBox");
94 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
96 XControlModel the_Model
= aShape
.getControl();
98 //Try to query XControlAccess
99 XControlAccess the_access
= UnoRuntime
.queryInterface(
100 XControlAccess
.class,
101 xTextDoc
.getCurrentController());
103 //get the CheckBoxControl for the needed Object relations
105 oObj
= the_access
.getControl(the_Model
);
106 the_win
= the_access
.getControl(the_Model
).getPeer();
107 the_kit
= the_win
.getToolkit();
108 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
109 aGraphic
= aDevice
.createGraphics();
110 } catch (Exception e
) {
111 log
.println("Couldn't get CheckBoxControl");
112 e
.printStackTrace(log
);
113 throw new StatusException("Couldn't get CheckBoxControl", e
);
116 log
.println("creating a new environment for UnoControlCheckBox object");
118 TestEnvironment tEnv
= new TestEnvironment(oObj
);
121 //Adding ObjRelation for XView
122 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
125 //Adding ObjRelation for XControl
126 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
127 tEnv
.addObjRelation("WINPEER", the_win
);
128 tEnv
.addObjRelation("TOOLKIT", the_kit
);
129 tEnv
.addObjRelation("MODEL", the_Model
);
131 // adding object relation for XItemListener
132 ifc
.awt
._XItemListener
.TestItemListener listener
=
133 new ifc
.awt
._XItemListener
.TestItemListener();
134 XCheckBox check
= UnoRuntime
.queryInterface(
135 XCheckBox
.class, oObj
);
136 check
.addItemListener(listener
);
137 tEnv
.addObjRelation("TestItemListener", listener
);
139 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
142 XController aController
= xTD2
.getCurrentController();
143 XFrame aFrame
= aController
.getFrame();
144 anotherWindow
= aFrame
.getComponentWindow();
145 } catch (Exception e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't create XWindow", e
);
151 // Object Relation for XWindow
152 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
155 } // finish method getTestEnvironment
156 } // finish class UnoControlCheckBox