1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.script.framework.provider; 24 25 import com.sun.star.frame.XModel; 26 import com.sun.star.frame.XDesktop; 27 import com.sun.star.uno.XComponentContext; 28 import com.sun.star.uno.UnoRuntime; 29 import com.sun.star.document.XScriptInvocationContext; 30 31 import com.sun.star.script.provider.XScriptContext; 32 33 34 /** 35 * Description of the Class 36 * 37 * @author Noel Power 38 * @created August 2, 2002 39 */ 40 public class EditorScriptContext implements XScriptContext 41 { 42 private XDesktop m_xDeskTop; 43 private XComponentContext m_xComponentContext; 44 private XDesktop m_xCtx; EditorScriptContext( XComponentContext xmComponentContext, XDesktop xDesktop )45 public EditorScriptContext( XComponentContext xmComponentContext, 46 XDesktop xDesktop ) 47 { 48 this.m_xComponentContext = xmComponentContext; 49 this.m_xDeskTop = xDesktop; 50 } 51 52 //---------------------------------------------------------------------- 53 /** 54 Obtain the document reference on which the script can operate 55 56 @returns 57 XModel interface 58 */ getDocument()59 public XModel getDocument() 60 { 61 XModel xModel = ( XModel ) UnoRuntime.queryInterface( XModel.class, 62 m_xDeskTop.getCurrentComponent() ); 63 64 return xModel; 65 } 66 getInvocationContext()67 public XScriptInvocationContext getInvocationContext() 68 { 69 XScriptInvocationContext xContext = ( XScriptInvocationContext ) UnoRuntime.queryInterface( 70 XScriptInvocationContext.class, getDocument() ); 71 return xContext; 72 } 73 74 /** 75 Obtain the desktop reference on which the script can operate 76 77 @returns 78 XDesktop interface 79 */ getDesktop()80 public XDesktop getDesktop() 81 { 82 return m_xDeskTop; 83 } 84 85 /** 86 Obtain the component context which the script can use to create other uno components 87 88 @returns 89 XComponentContext interface 90 */ getComponentContext()91 public XComponentContext getComponentContext() 92 { 93 return m_xComponentContext; 94 } 95 96 } 97