| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 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/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 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 . |
| 17 |
*/ |
| 18 |
package com.sun.star.script.framework.provider; |
| 19 |
|
| 20 |
import com.sun.star.document.XScriptInvocationContext; |
| 21 |
|
| 22 |
import com.sun.star.frame.XDesktop; |
| 23 |
import com.sun.star.frame.XModel; |
| 24 |
|
| 25 |
import com.sun.star.script.provider.XScriptContext; |
| 26 |
|
| 27 |
import com.sun.star.uno.UnoRuntime; |
| 28 |
import com.sun.star.uno.XComponentContext; |
| 29 |
|
| 30 |
public class EditorScriptContext implements XScriptContext { |
| 31 |
|
| 32 |
private final XDesktop m_xDeskTop; |
| 33 |
private final XComponentContext m_xComponentContext; |
| 34 |
|
| 35 |
public EditorScriptContext(XComponentContext xmComponentContext, |
| 36 |
XDesktop xDesktop) { |
| 37 |
this.m_xComponentContext = xmComponentContext; |
| 38 |
this.m_xDeskTop = xDesktop; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
Obtain the document reference on which the script can operate |
| 43 |
|
| 44 |
@return XModel interface |
| 45 |
*/ |
| 46 |
public XModel getDocument() { |
| 47 |
|
| 48 |
XModel xModel = |
| 49 |
UnoRuntime.queryInterface(XModel.class, m_xDeskTop.getCurrentComponent()); |
| 50 |
|
| 51 |
return xModel; |
| 52 |
} |
| 53 |
|
| 54 |
public XScriptInvocationContext getInvocationContext() { |
| 55 |
|
| 56 |
XScriptInvocationContext xContext = |
| 57 |
UnoRuntime.queryInterface(XScriptInvocationContext.class, getDocument()); |
| 58 |
|
| 59 |
return xContext; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
Obtain the desktop reference on which the script can operate |
| 64 |
|
| 65 |
@return XDesktop interface |
| 66 |
*/ |
| 67 |
public XDesktop getDesktop() { |
| 68 |
return m_xDeskTop; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
Obtain the component context which the script can use to create other uno components |
| 73 |
|
| 74 |
@return XComponentContext interface |
| 75 |
*/ |
| 76 |
public XComponentContext getComponentContext() { |
| 77 |
return m_xComponentContext; |
| 78 |
} |
| 79 |
} |