1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoControlButton.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.awt
.XControlModel
;
33 import com
.sun
.star
.awt
.XDevice
;
34 import com
.sun
.star
.awt
.XGraphics
;
35 import com
.sun
.star
.awt
.XToolkit
;
36 import com
.sun
.star
.awt
.XWindow
;
37 import com
.sun
.star
.awt
.XWindowPeer
;
38 import com
.sun
.star
.drawing
.XControlShape
;
39 import com
.sun
.star
.drawing
.XShape
;
40 import com
.sun
.star
.frame
.XController
;
41 import com
.sun
.star
.frame
.XFrame
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XTextDocument
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
46 import com
.sun
.star
.view
.XControlAccess
;
48 import java
.io
.PrintWriter
;
50 import lib
.StatusException
;
52 import lib
.TestEnvironment
;
53 import lib
.TestParameters
;
55 import util
.FormTools
;
56 import util
.SOfficeFactory
;
57 import util
.WriterTools
;
61 public class UnoControlButton
extends TestCase
{
62 private static XTextDocument xTextDoc
;
63 private static XTextDocument xTD2
;
65 protected void initialize(TestParameters Param
, PrintWriter log
) {
66 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
67 (XMultiServiceFactory
) Param
.getMSF());
70 log
.println("creating a textdocument");
71 xTextDoc
= SOF
.createTextDoc(null);
72 xTD2
= WriterTools
.createTextDoc(
73 (XMultiServiceFactory
) Param
.getMSF());
74 } catch (com
.sun
.star
.uno
.Exception e
) {
75 // Some exception occures.FAILED
76 e
.printStackTrace(log
);
77 throw new StatusException("Couldn't create document", e
);
81 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
82 log
.println(" disposing xTextDoc ");
84 util
.DesktopTools
.closeDoc(xTextDoc
);
85 util
.DesktopTools
.closeDoc(xTD2
);
88 public TestEnvironment
createTestEnvironment(TestParameters Param
,
90 XInterface oObj
= null;
91 XWindowPeer the_win
= null;
92 XToolkit the_kit
= null;
93 XDevice aDevice
= null;
94 XGraphics aGraphic
= null;
95 XWindow anotherWindow
= null;
97 //Insert a ControlShape and get the ControlModel
98 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
104 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
106 XControlModel the_Model
= aShape
.getControl();
108 //Try to query XControlAccess
109 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
110 XControlAccess
.class,
111 xTextDoc
.getCurrentController());
113 //get the ButtonControl for the needed Object relations
115 oObj
= the_access
.getControl(the_Model
);
116 the_win
= the_access
.getControl(the_Model
).getPeer();
117 the_kit
= the_win
.getToolkit();
118 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
119 aGraphic
= aDevice
.createGraphics();
120 } catch (Exception e
) {
121 log
.println("Couldn't get ButtonControl");
122 e
.printStackTrace(log
);
123 throw new StatusException("Couldn't get ButtonControl", e
);
126 log
.println("creating a new environment for UnoControlButton object");
128 TestEnvironment tEnv
= new TestEnvironment(oObj
);
131 //Adding ObjRelation for XView
132 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
135 //Adding ObjRelation for XControl
136 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
137 tEnv
.addObjRelation("WINPEER", the_win
);
138 tEnv
.addObjRelation("TOOLKIT", the_kit
);
139 tEnv
.addObjRelation("MODEL", the_Model
);
141 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
144 XController aController
= xTD2
.getCurrentController();
145 XFrame aFrame
= aController
.getFrame();
146 anotherWindow
= aFrame
.getComponentWindow();
147 } catch (Exception e
) {
148 e
.printStackTrace(log
);
149 throw new StatusException("Couldn't create XWindow", e
);
153 // Object Relation for XWindow
154 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
155 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
158 } // finish method getTestEnvironment
159 } // finish class UnoControlButton