* ドッキングウィンドウ [#bdab32b1] ドキュメントのウィンドウ上に表示されているダイアログがウィンドウにドッキングできるウィンドウを作成します。 &ref(dockingexample.oxt); コンポーネントの実装と設定が必要ですが、一般的なコンポーネントを含む拡張機能と基本的には同じです。 以下のコードで表示と非表示を切り替えられます。 #code(basic){{ ' Switch through layout manager. const RESOURCE_URL = "private:resource/dockingwindow/9809" Sub SwitchDockingWindow layoutmgr = ThisComponent.getCurrentController().getFrame().LayoutManager if layoutmgr.isElementVisible(RESOURCE_URL) then layoutmgr.hideElement(RESOURCE_URL) else layoutmgr.requestElement(RESOURCE_URL) end if End Sub }} 説明は拡張機能パッケージを解凍した中に入っている factory.py ファイルにあります。 ** リソース名 [#b202d3e4] ドッキングウィンドウは独自の名前を持っていなければいけません。リソース名は private:resource/dockingwindow/ で始まり、ウィンドウ名を 9800 - 9809 間の数値で指定します。 このリソース名はドッキングウィンドウをレイアウトマネージャから表示したり、見つけるために使用します。 ここでは 9809 をドッキングウィンドウ名とし、リソース名は private:resource/dockingwindow/9809 です。 ** ファクトリ登録 [#b7697d0b] /org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories 以下に、コンポーネントの実装名を oor:name 属性として持つノードを追加して必要な情報を記載します。 - Type: dockingwindow - Name: ドッキングウィンドウ名。リソース名の一部 - FactoryImplementation: css.awt.XWindow インターフェースを返すコンポーネントの実装名。コンポーネントは css.lang.XSingleComponentFactory インターフェースを実装している必要があります。 ** コンポーネント [#sb6d736b] コンポーネントは登録された実装名を持ち、css.lang.XSingleComponentFactory インターフェースを実装していなければいけません。XSingleComponentFactory インターフェースの createInstanceWithArgumentsAndContext メソッドが呼び出されると、css.awt.XWindow インターフェースを返すように実装します。返したウィンドウがドッキングウィンドウになります。 #code(python){{ import uno import unohelper from com.sun.star.lang import (XSingleComponentFactory, XServiceInfo) class Factory(unohelper.Base, XSingleComponentFactory, XServiceInfo): """ This factory instantiate new window content. Registration of this class have to be there under /org.openoffice.Office.UI/WindowContentFactories/Registered/ContentFactories. See its schema for detail. """ # Implementation name should be match with name of # the configuration node and FactoryImplementation value. IMPLE_NAME = "mytools.window.DockingWindowFactory" SERVICE_NAMES = IMPLE_NAME, @classmethod def get_imple(klass): return klass, klass.IMPLE_NAME, klass.SERVICE_NAMES def __init__(self, ctx, *args): self.ctx = ctx print("init") # XSingleComponentFactory def createInstanceWithContext(self, ctx): # No way to get the parent frame, not called return self.createInstanceWithArgumentsAndContext((), ctx) def createInstanceWithArgumentsAndContext(self, args, ctx): try: return create_window(ctx, args) except Exception as e: print(e) # XServiceInfo def supportedServiceNames(self): return self.SERVICE_NAMES def supportsService(self, name): return name in self.SERVICE_NAMES def getImplementationName(self): return self.IMPLE_NAME g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(*Factory.get_imple()) }} 示したのは実装の一部です。create_window 関数については拡張機能ファイル内のコードを参照してください。 createInstanceWithArgumentsAndContext メソッドに渡される引数は css.beans.PropertyValues のタプルで、以下の要素を含みます。 - ResourceURL: 要求のあったリソース名。ここで作成するリソースを確認します。 - Frame: ドッキングウィンドウを開くドキュメントフレームオブジェクト。ドキュメントへのアクセスが必要な場合、これを保持しておく必要があります。 ** その他 [#l840ff04] 拡張機能パッケージ内のファイルを参照してください。 |