任意のダイアログを非Basic(Java、C++、C#、Python、等)マクロまたは非マクロから呼び出して操作することができます。イベントたちはダイアログから受け取ることができます。
話題
About: UNO (Universal Network Objects)
About: LibreOffice
About: Apache OpenOffice
About: Javaプログラミング言語
About: C++
About: C#
About: Pythonプログラミング言語
この記事の目次
- 開始コンテキスト
- ターゲットコンテキスト
- オリエンテーション
- 本体
- 1: ダイアログを使用するのにBasicは必要ない
- 2: 任意のダイアログをデザインする
- 3: ダイアログを使用する
- 3-1: ダイアログたちプロバイダーを取得する
- 3-2: ダイアログをインスタンス化する
- 3-3: ダイアログを操作する
- 3-4: イベントリスナーたちをダイアログへ登録する
- 3-5: ダイアログを表示する
- 4: もしも、ダイアログはあなたにとって貧しすぎるなら
開始コンテキスト
- 読者は、Java、C++、C#、Pythonのいずれかの基本的知識を持っている。
- 読者は、UNOとは何か、UNOはLibreOfficeまたはApache OpenOfficeとどう関係しているかの知識を持っている。
- 読者は、UNOの基本的構成要素とそれらにこのシリーズで使われる用語体系の知識を持っている。
ターゲットコンテキスト
- 読者は、非Basicマクロまたは非マクロから任意のダイアログを呼び出して操作しダイアログからイベントたちを受け取る方法を知る。
オリエンテーション
任意の外部UNOクライアントを、単にコネクトする方法にて、Java、C++、C#、Pythonにて作成する方法についての記事があります。
任意の外部UNOクライアントを、コネクトアウェアな方法にて、Java、C++、C#、Pythonにて作成する方法についての記事があります。
LibreOffice/Apache OpenOfficeで、任意のユーザー/アプリケーション所有Pythonマクロを作成する方法についての記事があります。
LibreOffice/Apache OpenOfficeで、任意のドキュメント内Pythonマクロを作成する方法についての記事があります。
Pythonマクロたちを格納する任意のLibreOffice/Apache OpenOffice拡張機能を作成する方法についての記事があります。
LibreOffice/Apache OpenOfficeで、Basicの代わりにPythonを使用することについての記事があります。
本体
ト書きSpecial-Student-7、Lenard(Pythonプログラマー)、Jane(Pythonプログラマー)がコンピュータの前にいる。
1: ダイアログを使用するのにBasicは必要ない
Special-Student-7
私はしばしばLibreOfficeまたはApache OpenOfficeにBasicの代わりにPythonを使用するよう勧めますが、一部の人々はダイアログを使用するためにBasicを使う必要があると考えているかもしれません。
いいえ、そのためにBasicは必要ありません。
Lenard
おう?必要だと思ってたが。あれらはBasicダイアログですよね?
Special-Student-7
いいで、あれらは技術的に言うと特にBasicダイアログではありません、誤解を生むようにそういう範疇に入れられていますが。
Lenard
ダイアログたちはあのBasic IDEの中で管理されるじゃないか!
Jane
あのむさくるしいBasic IDEね . . .
Special-Student-7
それは、ダイアログたちはBasicだけのためのものであるかのようですが、いいえ、あれらは任意のUNOプログラミング言語から使用できます、Java、C++、C#、Pythonのような。
Jane
それはいいわね、私たちPythonの人たちはBasicを使いたくないからね。
2: 任意のダイアログをデザインする
Special-Student-7
多分、あなたはダイアログをBasic IDEを用いてデザインされるでしょう。
Jane
あのむさくるしいBasic IDE . . .
Special-Student-7
実のところ、ダイアログデザインは、あるXMLファイル内に格納されており、それをあなたはお気に入りのテキストエディターを使って編集することができます、しかし、私は通常、あなたがそれを無からテキストエディターで編集するとは予期しません。
Jane
えーと、もしも、仕様がちゃんとドキュメント化されていれば、私は試すかもしれない。
Special-Student-7
しかし、当該XMLファイルがどこにあるかをご存知であれば、それをあなたはどこへでもコピーすることができます、特にLibreOfficeまたはApache OpenOffice拡張機能の中へ。
Lenard
それがどこにあるのか教えてくれ、今すぐに!
Special-Student-7
そのダイアログをユーザー所有のものとして作成されたのであれば、当該XMLファイルは、Linuxでは'~/.config/libreoffice/4/user/basic/%ライブラリディレクトリ%'のようなディレクトリ内にまたはMicrosoft Windowsでは'C:\Users\%the user directory%\Appdata\Roaming\LibreOffice\4\user\basic\%ライブラリディレクトリ%'のようなディレクトリ内にあるでしょう。
同じディレクトリ内の'dialog.xlb'ファイルも必要です(コンテンツを変更する必要があるかもしれない)。
Lenard
どのように変更するのか?
Special-Student-7
ダイアログ名はそこで適切にセットされなければなりません。
3: ダイアログを使用する
Special-Student-7
ダイアログをJava、C++、C#、Pythonから使用しましょう。
オフィスインスタンスへのあるUNOオブジェクト群コンテキストが'l_underlyingRemoteUnoObjectsContextInXComponentContext'として取得されていると想定されています。もしも、外部UNOクライアントを作成されているのであれば、それを取得する方法についての記事があります、Java用(単にコネクトする方法にてまたはコネクションアウェアな方法にて)、C++用(単にコネクトする方法にてまたはコネクションアウェアな方法にて)、C#用(単にコネクトする方法にてまたはコネクションアウェアな方法にて)、Python用(単にコネクトする方法にてまたはコネクションアウェアな方法にて)に。
3-1: ダイアログたちプロバイダーを取得する
Special-Student-7
第1に、あるダイアログたちプロバイダーを取得しなければなりません。
実のところ、そうする方法は、対象ダイアログたちが非ドキュメント内のものであるかドキュメント内のものであるかに依存します。
以下は、任意の非ドキュメント内ダイアログたちのためにそうする方法です、各プログラミング言語にて。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~import com.sun.star.awt.XDialogProvider2;~import com.sun.star.uno.UnoRuntime;~public class Test1Test {~public static void main (String [] a_argumentsArray) {~~XDialogProvider2 l_underlyingUnoDialogProviderInXDialogProvider2 = UnoRuntime.queryInterface (XDialogProvider2.class, l_underlyingRemoteUnoObjectsContextInXComponentContext.getServiceManager ().createInstanceWithContext ("com.sun.star.awt.DialogProvider", l_underlyingRemoteUnoObjectsContextInXComponentContext));}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp Start~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {class Test1Test {~public:static int main (int const & a_argumentsNumber, char const * const a_argumentsArray []);};}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp End// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include <com/sun/star/awt/XDialogProvider2.hpp>~#include <com/sun/star/uno/Reference.hxx>~#include "theBiasPlanet/unoUtilities/stringsHandling/UnoExtendedStringHandler.hpp"~using namespace ::std;~using namespace ::com::sun::star::awt;~using namespace ::com::sun::star::uno;~using namespace ::theBiasPlanet::unoUtilities::stringsHandling;~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XDialogProvider2> l_underlyingUnoDialogProviderInXDialogProvider2 (l_underlyingRemoteUnoObjectsContextInXComponentContext->getServiceManager ()->createInstanceWithContext (UnoExtendedStringHandler::getOustring (string ("com.sun.star.awt.DialogProvider")), l_underlyingRemoteUnoObjectsContextInXComponentContext), UNO_QUERY);}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {using System;~using unoidl.com.sun.star.awt;~public class Test1Test {~public void main (String [] a_argumentsArray) {~~XDialogProvider2 l_underlyingUnoDialogProvider = (XDialogProvider2) (l_underlyingRemoteUnoObjectsContext.getServiceManager ().createInstanceWithContext ("com.sun.star.awt.DialogProvider", l_underlyingRemoteUnoObjectsContext));}}}}}
@Python ソースコード
from typing import cast~from com.sun.star.awt import XDialogProvider2~class Test1Test:~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_underlyingUnoDialogProviderInXDialogProvider2: XDialogProvider2 = cast (XDialogProvider2, l_underlyingRemoteUnoObjectsContextInXComponentContext.getServiceManager ().createInstanceWithContext ("com.sun.star.awt.DialogProvider", l_underlyingRemoteUnoObjectsContextInXComponentContext))
以下は、任意のドキュメント内ダイアログたちのためにそうする方法です、各プログラミング言語にて、ここで、'l_underlyingUnoDocumentInXModel'はドキュメントUNOオブジェクトの'com.sun.star.frame.XModel' UNOプロキシによるもの、'Standard'はライブラリ名、'Test1Dialog'はダイアログ名(そうです、この場合、ダイアログ型毎にダイアログたちプロバイダーを取得しなければなりません)。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~import com.sun.star.awt.XDialogProvider2;~import com.sun.star.beans.XPropertySet;~import com.sun.star.container.XNameAccess;import com.sun.star.container.XNameContainer;~import com.sun.star.io.XInputStreamProvider;~import com.sun.star.lang.EventObject;~import com.sun.star.lib.uno.helper.WeakBase;~import com.sun.star.reflection.InvocationTargetException;import com.sun.star.script.ScriptEvent;import com.sun.star.script.XLibraryContainer;import com.sun.star.script.XScriptListener;~import com.sun.star.uno.UnoRuntime;~public class Test1Test {private static class UnoScriptListener extends WeakBase implements XScriptListener {@Overridepublic void firing (ScriptEvent a_event) {System.out.println (String.format ("### UnoScriptListener.firing: %s", a_event));}@Overridepublic Object approveFiring (ScriptEvent a_event) throws InvocationTargetException {System.out.println (String.format ("### UnoScriptListener.approveFiring: %s", a_event));return null;}@Overridepublic void disposing (EventObject a_eventSource) {System.out.println (String.format ("### UnoScriptListener.disposing: %s", a_eventSource));}}~public static void main (String [] a_argumentsArray) {~~XDialogProvider2 l_underlyingUnoDialogProviderInXDialogProvider2 = null;~XNameAccess l_underlyingUnoDialogLibrariesInXNameAccess = UnoRuntime.queryInterface (XNameAccess.class, ( (com.sun.star.uno.Any) (UnoRuntime.queryInterface (XPropertySet.class, l_underlyingUnoDocumentInXModel).getPropertyValue ("DialogLibraries"))).getObject ());UnoRuntime.queryInterface (XLibraryContainer.class, l_underlyingUnoDialogLibrariesInXNameAccess).loadLibrary ("Standard");XNameAccess l_underlyingUnoDialogLibraryInXNameAccess = UnoRuntime.queryInterface (XNameAccess.class, ( (com.sun.star.uno.Any) l_underlyingUnoDialogLibrariesInXNameAccess.getByName ("Standard")).getObject ());XInputStreamProvider l_underlyingUnoDialogStreamInXInputStreamProvider = UnoRuntime.queryInterface (XInputStreamProvider.class, ( (com.sun.star.uno.Any) l_underlyingUnoDialogLibraryInXNameAccess.getByName ("Test1Dialog")).getObject ());Object [] l_unoServiceArguments = new Object [4];l_unoServiceArguments [0] = l_underlyingUnoDocumentInXModel;l_unoServiceArguments [1] = l_underlyingUnoDialogStreamInXInputStreamProvider.createInputStream ();l_unoServiceArguments [2] = UnoRuntime.queryInterface (XNameContainer.class, l_underlyingUnoDialogLibraryInXNameAccess);l_unoServiceArguments [3] = new UnoScriptListener ();l_underlyingUnoDialogProviderInXDialogProvider2 = UnoRuntime.queryInterface (XDialogProvider2.class, l_underlyingRemoteUnoObjectsContextInXComponentContext.getServiceManager ().createInstanceWithArgumentsAndContext ("com.sun.star.awt.DialogProvider", l_unoServiceArguments, l_underlyingRemoteUnoObjectsContextInXComponentContext));}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp Start#include <cppuhelper/compbase1.hxx>~#include <com/sun/star/lang/EventObject.hpp>~#include <com/sun/star/script/XScriptListener.hpp>~using namespace ::cppu;~using namespace ::com::sun::star::script;~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {class Test1Test {private:class UnoScriptListener: public WeakImplHelper1 <XScriptListener> {public:void firing (ScriptEvent const & a_event) override;Any approveFiring (ScriptEvent const & a_event) override;void disposing (::com::sun::star::lang::EventObject const & a_eventSource) override;};~public:static int main (int const & a_argumentsNumber, char const * const a_argumentsArray []);};}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp End// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include "theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp"#include <string>#include <com/sun/star/awt/XDialogProvider2.hpp>#include <com/sun/star/beans/XPropertySet.hpp>#include <com/sun/star/io/XInputStreamProvider.hpp>#include <com/sun/star/script/XLibraryContainer.hpp>#include <com/sun/star/script/XScriptListener.hpp>#include <com/sun/star/uno/Any.hxx>#include <com/sun/star/uno/Reference.hxx>~#include "theBiasPlanet/unoUtilities/stringsHandling/UnoExtendedStringHandler.hpp"~using namespace ::std;using namespace ::com::sun::star::awt;using namespace ::com::sun::star::beans;using namespace ::com::sun::star::io;using namespace ::com::sun::star::script;using namespace ::com::sun::star::uno;~using namespace ::theBiasPlanet::unoUtilities::stringsHandling;~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XNameAccess> l_underlyingUnoDialogLibrariesInXNameAccess (* ( (Reference <XInterface> *) (Reference <XPropertySet> (l_underlyingUnoDocumentInXModel, UNO_QUERY)->getPropertyValue (UnoExtendedStringHandler::getOustring (string ("DialogLibraries"))).getValue ())), UNO_QUERY);Reference <XLibraryContainer> (l_underlyingUnoDialogLibrariesInXNameAccess, UNO_QUERY)->loadLibrary (UnoExtendedStringHandler::getOustring (string ("Standard")));Reference <XNameAccess> l_underlyingUnoDialogLibraryInXNameAccess (* ( (Reference <XInterface> *) l_underlyingUnoDialogLibrariesInXNameAccess->getByName (UnoExtendedStringHandler::getOustring (string ("Standard"))).getValue ()), UNO_QUERY);Reference <XInputStreamProvider> l_underlyingUnoDialogStreamInXInputStreamProvider (* ( (Reference <XInterface> *) l_underlyingUnoDialogLibraryInXNameAccess->getByName (UnoExtendedStringHandler::getOustring (string ("Test1Dialog"))).getValue ()), UNO_QUERY);Sequence <Any> l_unoServiceArguments (4);l_unoServiceArguments [0] = Any (l_underlyingUnoDocumentInXModel);l_unoServiceArguments [1] = Any (l_underlyingUnoDialogStreamInXInputStreamProvider->createInputStream ());l_unoServiceArguments [2] = Any (Reference <XNameContainer> (l_underlyingUnoDialogLibraryInXNameAccess, UNO_QUERY));l_unoServiceArguments [3] = Any (Reference <XScriptListener> (new UnoScriptListener ()));Reference <XDialogProvider2> l_underlyingUnoDialogProviderInXDialogProvider2 (l_underlyingRemoteUnoObjectsContextInXComponentContext->getServiceManager ()->createInstanceWithArgumentsAndContext (UnoExtendedStringHandler::getOustring (string ("com.sun.star.awt.DialogProvider")), l_unoServiceArguments, l_underlyingRemoteUnoObjectsContextInXComponentContext), UNO_QUERY);}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {using System;~using unoidl.com.sun.star.awt;using unoidl.com.sun.star.beans;using unoidl.com.sun.star.container;using unoidl.com.sun.star.io;~using unoidl.com.sun.star.script;using unoidl.com.sun.star.uno;~public class Test1Test {private class UnoScriptListener: WeakBase, XScriptListener {public void firing (ScriptEvent a_event) {Console.Out.WriteLine (String.Format ("### UnoScriptListener.firing: %s", a_event));}public uno.Any approveFiring (ScriptEvent a_event) {Console.Out.WriteLine (String.Format ("### UnoScriptListener.approveFiring: %s", a_event));return new uno.Any ();}public void disposing (EventObject a_eventSource) {Console.Out.WriteLine (String.Format ("### UnoScriptListener.disposing: %s", a_eventSource));}}~public void main (String [] a_argumentsArray) {~~XDialogProvider2 l_underlyingUnoDialogProviderInXDialogProvider2 = null;~XNameAccess l_underlyingUnoDialogLibrariesInXNameAccess = (XNameAccess) ( (uno.Any) ( (XPropertySet) (l_underlyingUnoDocumentInXModel)).getPropertyValue ("DialogLibraries")).Value;( (XLibraryContainer) l_underlyingUnoDialogLibrariesInXNameAccess).loadLibrary ("Standard");XNameAccess l_underlyingUnoDialogLibraryInXNameAccess = (XNameAccess) ( (uno.Any) l_underlyingUnoDialogLibrariesInXNameAccess.getByName ("Standard")).Value;XInputStreamProvider l_underlyingUnoDialogStreamInXInputStreamProvider = (XInputStreamProvider) ( (uno.Any) l_underlyingUnoDialogLibraryInXNameAccess.getByName ("Test1Dialog")).Value;uno.Any [] l_unoServiceArguments = new uno.Any [4];l_unoServiceArguments [0] = new uno.Any (l_underlyingUnoDocumentInXModel.GetType (), l_underlyingUnoDocumentInXModel);l_unoServiceArguments [1] = new uno.Any (l_underlyingUnoDocumentInXModel.GetType (), l_underlyingUnoDialogStreamInXInputStreamProvider.createInputStream ());l_unoServiceArguments [2] = new uno.Any (l_underlyingUnoDocumentInXModel.GetType (), (XNameContainer) l_underlyingUnoDialogLibraryInXNameAccess);l_unoServiceArguments [3] = new uno.Any (l_underlyingUnoDocumentInXModel.GetType (), new UnoScriptListener ());l_underlyingUnoDialogProviderInXDialogProvider2 = (XDialogProvider2) l_underlyingRemoteUnoObjectsContextInXComponentContext.getServiceManager ().createInstanceWithArgumentsAndContext ("com.sun.star.awt.DialogProvider", l_unoServiceArguments, l_underlyingRemoteUnoObjectsContextInXComponentContext);}}}}}
@Python ソースコード
from typing import cast~from com.sun.star.awt import XDialogProvider2~from com.sun.star.container import XNameAccessfrom com.sun.star.container import XNameContainer~from com.sun.star.io import XInputStreamProviderfrom com.sun.star.lang import EventObjectfrom com.sun.star.script import ScriptEventfrom com.sun.star.script import XLibraryContainerfrom com.sun.star.script import XScriptListener~from uno import Any as UnoAnyclass Test1Test:class UnoScriptListener (UnoBase, XScriptListener):def firing (a_this: "Test1Test.UnoScriptListener", a_event: ScriptEvent)-> None:sys.stdout.write ("### UnoScriptListener.firing: {0:s}\n".format (str (a_event)))sys.stdout.flush ()def approveFiring (a_this: "Test1Test.UnoScriptListener", a_event: ScriptEvent)-> object:sys.stdout.write ("### UnoScriptListener.approveFiring: {0:s}\n".format (str (a_event)))sys.stdout.flush ()return Nonedef disposing (a_this: "Test1Test.UnoScriptListener", a_eventSource: EventObject)-> None:None~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_underlyingUnoDialogProviderInXDialogProvider2: XDialogProvider2 = None~l_underlyingUnoDialogLibrariesInXNameAccess: XNameAccess = cast (XNameAccess, cast (XPropertySet, l_underlyingUnoDocumentInXModel).getPropertyValue ("DialogLibraries"))cast (XLibraryContainer, l_underlyingUnoDialogLibrariesInXNameAccess).loadLibrary ("Standard")l_underlyingUnoDialogLibraryInXNameAccess: XNameAccess = cast (XNameAccess, l_underlyingUnoDialogLibrariesInXNameAccess.getByName ("Standard"))l_underlyingUnoDialogStreamInXInputStreamProvider: XInputStreamProvider = cast (XInputStreamProvider, l_underlyingUnoDialogLibraryInXNameAccess.getByName ("Test1Dialog"))l_unoServiceArguments: List [object] = [None] * 4l_unoServiceArguments [0] = l_underlyingUnoDocumentInXModell_unoServiceArguments [1] = l_underlyingUnoDialogStreamInXInputStreamProvider.createInputStream ()l_unoServiceArguments [2] = cast (XNameContainer, l_underlyingUnoDialogLibraryInXNameAccess)l_unoServiceArguments [3] = Test1Test.UnoScriptListener ()l_underlyingUnoDialogProviderInXDialogProvider2 = cast (XDialogProvider2, l_underlyingRemoteUnoObjectsContextInXComponentContext.getServiceManager ().createInstanceWithArgumentsAndContext ("com.sun.star.awt.DialogProvider", l_unoServiceArguments, l_underlyingRemoteUnoObjectsContextInXComponentContext))
3-2: ダイアログをインスタンス化する
Special-Student-7
各プログラミング言語にてダイアログをインスタンス化しましょう。
ここでも、そうする方法は、対象ダイアログたちが非ドキュメント内のものであるかドキュメント内のものであるかに依存します。
以下は、任意の非ドキュメント内ダイアログたちのためにそうする方法です、各プログラミング言語にて、ここで、'Standard'はライブラリ名、'Test1Dialog'はダイアログ名です。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~import com.sun.star.awt.XDialog;~public class Test1Test {~public static void main (String [] a_argumentsArray) {~~XDialog l_underlyingUnoDialogInXDialog = l_underlyingUnoDialogProviderInXDialogProvider2.createDialog ("vnd.sun.star.script:Standard.Test1Dialog?language=Basic&location=application");}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include <com/sun/star/awt/XDialog.hpp>~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XDialogProvider2> l_underlyingUnoDialogProviderInXDialogProvider2 (l_underlyingRemoteUnoObjectsContextInXComponentContext->getServiceManager ()->createInstanceWithContext (UnoExtendedStringHandler::getOustring (string ("com.sun.star.awt.DialogProvider")), l_underlyingRemoteUnoObjectsContextInXComponentContext), UNO_QUERY);Reference <XDialog> l_underlyingUnoDialogInXDialog (l_underlyingUnoDialogProviderInXDialogProvider2->createDialog (UnoExtendedStringHandler::getOustring (string ("vnd.sun.star.script:Standard.Test1Dialog?language=Basic&location=application"))));}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~public class Test1Test {~public void main (String [] a_argumentsArray) {~~XDialog l_underlyingUnoDialog = l_underlyingUnoDialogProvider.createDialog ("vnd.sun.star.script:Standard.Test1Dialog?language=Basic&location=application");}}}}}
@Python ソースコード
from com.sun.star.awt import XDialog~class Test1Test:~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_underlyingUnoDialogInXDialog: XDialog = l_underlyingUnoDialogProviderInXDialogProvider2.createDialog ("vnd.sun.star.script:Standard.Test1Dialog?language=Basic&location=application")
以下は、任意のドキュメント内ダイアログたちのためにそうする方法です、各プログラミング言語にて、ここで、ライブラリ名もダイアログ名も指定されていません、なぜなら、それらは既にダイアログたちプロバイダーに対して決定されているから。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~import com.sun.star.awt.XDialog;~public class Test1Test {~public static void main (String [] a_argumentsArray) {~~XDialog l_underlyingUnoDialogInXDialog = null;~~l_underlyingUnoDialogInXDialog = l_underlyingUnoDialogProviderInXDialogProvider2.createDialog ("");}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include <com/sun/star/awt/XDialog.hpp>~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XDialog> l_underlyingUnoDialogInXDialog;~l_underlyingUnoDialogInXDialog.set (l_underlyingUnoDialogProviderInXDialogProvider2->createDialog (UnoExtendedStringHandler::getOustring (string (""))));}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~public class Test1Test {~public void main (String [] a_argumentsArray) {~~XDialog l_underlyingUnoDialogInXDialog = null;~l_underlyingUnoDialogInXDialog = l_underlyingUnoDialogProviderInXDialogProvider2.createDialog ("");}}}}}
@Python ソースコード
from com.sun.star.awt import XDialog~class Test1Test:~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_underlyingUnoDialogInXDialog: XDialog = None~l_underlyingUnoDialogInXDialog = l_underlyingUnoDialogProviderInXDialogProvider2.createDialog ("");
Jane
えーと、"
3-3: ダイアログを操作する
Special-Student-7
"l_underlyingUnoDialogInXDialog"がダイアログインスタンスを代表しており、それを介してあなたは当該ダイアログインスタンスを操作できます。
通常、ダイアログ上のコントロールたちを操作したいことでしょう。
任意のコントロールは以下のようにして取得できます、ここで、"TextField1"はコントロール名です。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~import com.sun.star.awt.XControl;import com.sun.star.awt.XControlContainer;~public class Test1Test {~public static void main (String [] a_argumentsArray) {~~XControl l_underlyingUnoControlInXControl = null;~l_underlyingUnoControlInXControl = UnoRuntime.queryInterface (XControlContainer.class, l_underlyingUnoDialogInXDialog).getControl ("TextField1");}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include <com/sun/star/awt/XControl.hpp>#include <com/sun/star/awt/XControlContainer.hpp>~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XControl> l_underlyingUnoControlInXControl;~l_underlyingUnoControlInXControl = Reference <XControlContainer> (l_underlyingUnoDialogInXDialog, UNO_QUERY)->getControl ("TextField1");}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~public class Test1Test {~public void main (String [] a_argumentsArray) {~~XControl l_underlyingUnoControl = null;~l_underlyingUnoControl = ( (XControlContainer) l_underlyingUnoDialog).getControl ("TextField1");}}}}}
@Python ソースコード
from com.sun.star.awt import XControlfrom com.sun.star.awt import XControlContainer~class Test1Test:~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_underlyingUnoControlInXControl: XControl = None~l_underlyingUnoControlInXControl = (cast (XControlContainer, l_underlyingUnoDialogInXDialog)).getControl ("TextField1")
コントロールはいくつかのUNOインターフェイスたちを実装しています、それがどういう種類のコントロールであるかに依存して。
例えば、任意の'TextField'コントロールは以下のUNOインターフェイスたちを実装しています: 'com.sun.star.awt.XControl', 'com.sun.star.awt.XWindow2', 'com.sun.star.awt.XView', 'com.sun.star.beans.XPropertiesChangeListener', 'com.sun.star.lang.XServiceInfo', 'com.sun.star.accessibility.XAccessible', 'com.sun.star.util.XModeChangeBroadcaster', 'com.sun.star.awt.XUnitConversion', 'com.sun.star.awt.XStyleSettingsSupplier', 'com.sun.star.lang.XTypeProvider', 'com.sun.star.uno.XWeak', 'com.sun.star.uno.XAggregation', 'com.sun.star.awt.XTextComponent', 'com.sun.star.awt.XTextListener', 'com.sun.star.awt.XLayoutConstrains', 'com.sun.star.awt.XTextLayoutConstrains', and 'com.sun.star.lang.XTypeProvider'。
Jane
それじゃあ、私は各コントロールをそうしたUNOインターフェイスたちを介して操作できるわけね。
Special-Student-7
例えば、以下はある'TextField'コントロールのコンテンツを取得しセットします。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~import com.sun.star.awt.XTextComponent;~public class Test1Test {~public static void main (String [] a_argumentsArray) {~~UnoRuntime.queryInterface (XTextComponent.class, l_underlyingUnoControlInXControl).setText ("Hi, bro!");System.out.println (String.format ("### TextField1 text: %s", UnoRuntime.queryInterface (XTextComponent.class, l_underlyingUnoControlInXControl).getText ()));}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include <com/sun/star/awt/XTextComponent.hpp>~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XTextComponent> (l_underlyingUnoControlInXControl, UNO_QUERY)->setText (UnoExtendedStringHandler::getOustring (string ("Hi, bro!")));cout << "### TextField1 text: " << UnoExtendedStringHandler::getString (Reference <XTextComponent> (l_underlyingUnoControlInXControl, UNO_QUERY)->getText ()) << endl << flush;}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~public class Test1Test {~public void main (String [] a_argumentsArray) {~~( (XTextComponent) l_underlyingUnoControl).setText ("Hi, bro!");Console.Out.WriteLine (String.format ("### TextField1 text: {0:s}", ( (XTextComponent) l_underlyingUnoControl).getText ()));}}}}}
@Python ソースコード
from com.sun.star.uno import XComponentContext~class Test1Test:~@staticmethoddef main (a_arguments: List [str]) -> None:~~(cast (XTextComponent, l_underlyingUnoControlInXControl)).setText ("Hi, bro!")sys.stdout.write ("### TextField1 text: {0:s}\n".format ( (cast (XTextComponent, l_underlyingUnoControlInXControl)).getText ()))
Lenard
それは簡単に見えるけど、あなたは簡単な例を選んだだけだ。
別の種類のコントロールのコンテンツをどのようにセットできるのか、例えば、'Image'コントロールは?
Special-Student-7
本記事はダイアログを使うことの基本についてのものなので、様々な種類のコントロールたちのそうした詳細は次記述で学びます。
Lenard
'Option Button'も学ぶかなあ?
Special-Student-7
学びます。
Lenard
'Tree Control'も?
Special-Student-7
はい。
Lenard
'File Selection'も?
Special-Student-7
. . . Basic IDE内に見られる全ての種類のコントロールがいくつかの典型的な方法で操作されるでしょう、多分。
3-4: イベントリスナーたちをダイアログへ登録する
Jane
コントロールをただ能動的に操作するだけでは十分じゃないわよね; 私のプログラムはイベントたちを受け取らなくっちゃならない。
Special-Student-7
知っています; あなたはあるイベントリスナーを、当該コントロールに実装されている、'com.sun.star.awt.XButton'のような、あるUNOインターフェイスを介して登録できます。
例えば、以下はあるアクションリスナーをある'Button'コントロールへ登録します。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;import com.sun.star.awt.ActionEvent;~import com.sun.star.awt.XActionListener;~import com.sun.star.awt.XButton;~import com.sun.star.lang.EventObject;~import com.sun.star.lib.uno.helper.WeakBase;~public class Test1Test {~private static class UnoButtonEventsListener extends WeakBase implements XActionListener {@Overridepublic void actionPerformed (ActionEvent a_event) {System.out.println (String.format ("### UnoButtonEventsListener.actionPerformed: %s", a_event));}@Overridepublic void disposing (EventObject a_eventSource) {}}~public static void main (String [] a_argumentsArray) {~~UnoButtonEventsListener l_unoButtonEventsListener = new UnoButtonEventsListener ();~UnoRuntime.queryInterface (XButton.class, l_underlyingUnoControlInXControl).addActionListener (l_unoButtonEventsListener);}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp Start#include <cppuhelper/compbase1.hxx>#include <com/sun/star/awt/ActionEvent.hpp>~#include <com/sun/star/awt/XActionListener.hpp>~#include <com/sun/star/lang/EventObject.hpp>~using namespace ::cppu;~using namespace ::com::sun::star::lang;~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {class Test1Test {~class UnoButtonEventsListener: public WeakImplHelper1 <XActionListener> {public:void actionPerformed (ActionEvent const & a_event) override;void disposing (EventObject const & a_eventSource) override;};~};}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.hpp End// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Start#include <com/sun/star/awt/XButton.hpp>~namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~void Test1Test::UnoButtonEventsListener::actionPerformed (ActionEvent const & a_event) {cout << string ("### UnoButtonEventsListener.actionPerformed: ") << a_event.ActionCommand << endl << flush;}void Test1Test::UnoButtonEventsListener::disposing (EventObject const & a_eventSource) {}~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~Reference <XActionListener> l_unoButtonEventsListener (new UnoButtonEventsListener ());~Reference <XButton> (l_underlyingUnoControlInXControl, UNO_QUERY)->addActionListener (l_unoButtonEventsListener);}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~using uno;~using unoidl.com.sun.star.lang;~public class Test1Test {~private class UnoButtonEventsListener: WeakBase, XActionListener {public void actionPerformed (ActionEvent a_event) {Console.Out.WriteLine (String.Format ("### UnoButtonEventsListener.actionPerformed: {0:s}", a_event));}public void disposing (EventObject a_eventSource) {}}~public void main (String [] a_argumentsArray) {~~UnoButtonEventsListener l_unoButtonEventsListener = new UnoButtonEventsListener ();~( (XButton) l_underlyingUnoControl).addActionListener (l_unoButtonEventsListener);}}}}}
@Python ソースコード
from unohelper import Base as UnoBasefrom com.sun.star.awt import ActionEvent~from com.sun.star.awt import XActionListenerfrom com.sun.star.awt import XButton~from com.sun.star.lang import EventObject~class Test1Test:~class UnoButtonEventsListener (UnoBase, XActionListener):def actionPerformed (a_this: "Test1Test.UnoButtonEventsListener", a_event: ActionEvent)-> None:sys.stdout.write ("### UnoButtonEventsListener.actionPerformed: {0:s}\n".format (str (a_event)))sys.stdout.flush ()def disposing (a_this: "Test1Test.UnoButtonEventsListener", a_eventSource: EventObject)-> None:None~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_unoButtonEventsListener: "Test1Test.UnoButtonEventsListener" = Test1Test.UnoButtonEventsListener ()~(cast (XButton, l_underlyingUnoControlInXControl)).addActionListener (l_unoButtonEventsListener)
3-5: ダイアログを表示する
Special-Student-7
私たちは既にダイアログをインスタンス化しました、しかし、インスタンスはまだ表示されていません。
以下がインスタンスを表示します。
@Java ソースコード
package theBiasPlanet.unoUtilitiesTests.dialogInvokingTest1;~public class Test1Test {~public static void main (String [] a_argumentsArray) {~~l_underlyingUnoDialogInXDialog.execute ();}}
@C++ ソースコード
// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp Startnamespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~int Test1Test::main (int const & a_argumentsNumber, char const * const a_argumentsArray []) {~~l_underlyingUnoDialogInXDialog->execute ();}}}}// theBiasPlanet/unoUtilitiesTests/dialogInvokingTest1/Test1Test.cpp End
@C# ソースコード
namespace theBiasPlanet {namespace unoUtilitiesTests {namespace dialogInvokingTest1 {~public class Test1Test {~public void main (String [] a_argumentsArray) {~l_underlyingUnoDialog.execute ();}}}}}
@Python ソースコード
~class Test1Test:~@staticmethoddef main (a_arguments: List [str]) -> None:~~l_underlyingUnoDialogInXDialog.execute ()
Lenard
いいじゃないか実際!私はもうBasicを必要としない!
4: もしも、ダイアログはあなたにとって貧しすぎるなら
Jane
それは実際いいことね、でも、ダイアログ機能はそれほどリッチじゃない。
Special-Student-7
もしも、ダイアログ機能があなたにとって貧しすぎるならば、1つの方法はJava Swingを使用することです。
Jane
私たちはJavaプログラマーじゃないんだけどね。
Special-Student-7
知っています、でも、Python GUIシステムたちは、Pythonマクロから直接には使用できないでしょう、私が知る限り。
Jane
"直接には"というのは . . .
Special-Student-7
外部Pythonプロセスを呼び出して、それがGUIを表示するということは常にできます。
Jane
でも、マクロは、そのGUIを操作できないしイベントをリッスンすることもできないできないでしょう、その方法では?
Special-Student-7
UNOを介してリクエストたちやイベントたちをリレーすることは可能です、しかし、問題は、GUIはオフィスGUIの上に表示されると保証できないことです。
Jane
ああ、GUIはオフィスGUIの下に表示されるかもしれない、目に見えない状態で。
Special-Student-7
他方で、Java SwingはオフィスJVMから直接に使用することができます。
Jane
なんで、Python GUIはPythonマクロから直接に使用できないわけ?
Special-Student-7
それは、Python GUIシステムたちのイベントループはオフィスイベントループと干渉するからです。
Jane
なんで、Python GUIシステムたちだけが?
Special-Student-7
むしろ、Java Swingだけがオフィスイベントループと干渉しないということです。
Jane
いずれにせよ、私たちにどうしろと言ってるわけ?私たちはJavaプログラマーじゃない!
Special-Student-7
私が申し上げているのは、もしも、オフィスJVM内のあるJava UNOコンポーネント内にGUIを、あなたが用意するか、あるJavaプログラマーに用意させれば、それをあなたのPythonマクロはUNOを介して使用できるということです。
Jane
私のPythonマクロはイベントたちを受け取れる?
Special-Student-7
はい、受け取れます。
Jane
ふーむ . . .
Special-Student-7
その工夫は将来の記事で見ましょう。
Jane
"外部Pythonプロセスを呼び出して、それがGUIを表示する"ってやつは?
Special-Student-7
その工夫も将来の記事で見ましょう。