OOobbs/46
質問
前回は、お世話になりました。 今回もよろしくお願いします。 前回質問させていただいたコントロールの動的な配置をしていたら 配置する数が多すぎて表示しきれなくなったので コントロールを全て表示できるようにスクロールバーを使いたいのですが、 使い方が全くわかりません。 ご教示いただけないでしょうか? よろしくお願いします。 回答
例を書きかけです。 Dim oDialog As Object Dim oDialogModel As Object Dim oAdjustmentListener As Object Dim oScrollBar As Object Dim oButtonM1 As Object, oButtonM2 As Object Dim oButtonM3 As Object, oButtonM4 As Object Dim oButtonM5 As Object, oButtonM6 As Object Sub Main() Dialog() End Sub Sub Dialog() Dim oScrollBarM As Object Dim oManager As Object oManager = GetProcessServiceManager() oDialogModel = oManager.createInstance("com.sun.star.awt.UnoControlDialogModel") With oDialogModel .setPropertyValue("Name","Dialog") .setPropertyValue( "PositionX", 161 ) .setPropertyValue( "PositionY", 91 ) .setPropertyValue( "Height", 103 ) .setPropertyValue( "Width", 111 ) .setPropertyValue( "Title", "Dialog" ) End With oButtonM1 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM2 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM3 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM4 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM5 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM6 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") With oButtonM1 .setPropertyValue( "Name", "b1" ) .setPropertyValue( "PositionX", 10 ) .setPropertyValue( "PositionY", 12 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","1") End With With oButtonM2 .setPropertyValue( "Name", "b2" ) .setPropertyValue( "PositionX", 10 ) .setPropertyValue( "PositionY", 36 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","2") End With With oButtonM3 .setPropertyValue( "Name", "b3" ) .setPropertyValue( "PositionX", 10 ) .setPropertyValue( "PositionY", 60 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","3") End With With oButtonM4 .setPropertyValue( "Name", "b4" ) .setPropertyValue( "PositionX", 10 ) .setPropertyValue( "PositionY", 84 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","4") End With With oButtonM5 .setPropertyValue( "Name", "b5" ) .setPropertyValue( "PositionX", 10 ) .setPropertyValue( "PositionY", 108 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","5") End With With oButtonM6 .setPropertyValue( "Name", "b6" ) .setPropertyValue( "PositionX", 10 ) .setPropertyValue( "PositionY", 132 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","6") End With oScrollBarM = oDialogModel.createInstance("com.sun.star.awt.UnoControlScrollBarModel") With oScrollBarM .Name = "sb" .PositionX = 89 .PositionY = 10 .Width = 12 .Height = 86 .Orientation = com.sun.star.awt.ScrollBarOrientation.VERTICAL .ScrollValue = 0 .ScrollValueMax = 60 .BlockIncrement = 30 .LineIncrement = 30 End With With oDialogModel .insertByName("b1", oButtonM1) .insertByName("b2", oButtonM2) .insertByName("b3", oButtonM3) .insertByName("b4", oButtonM4) .insertByName("b5", oButtonM5) .insertByName("b6", oButtonM6) .insertByName("sb", oScrollBarM) End With oDialog = oManager.createInstance("com.sun.star.awt.UnoControlDialog") oDialog.setModel(oDialogModel) oAdjustmentListener = CreateUnoListener("Adjustment_", "com.sun.star.awt.XAdjustmentListener") oScrollBar = oDialog.getControl("sb") oScrollBar.addAdjustmentListener(oAdjustmentListener) oDialog.setVisible(true) oDialog.execute() End Sub Sub Adjustment_adjustmentValueChanged(oEvent) 'MsgBox oEvent.Dbg_Properties End Sub Sub Adjustment_disposing() End Sub スクロールバーモデルのサービスは com.sun.star.awt.UnoControlScrollBarModel です。 プロパティー値の設定としては, With oScrollBarM .Name = "sb" .PositionX = 89 .PositionY = 10 .Width = 12 .Height = 86 .Orientation = com.sun.star.awt.ScrollBarOrientation.VERTICAL .ScrollValue = 0 .ScrollValueMax = 60 .BlockIncrement = 30 .LineIncrement = 30 End With などが必要だと思います。スクロールバーモデルのプロパティー値については OOoBasic/Generic/obj/ScrollBarModel? を参考にしてください。 スクロールバーのスクロール値が変更されたときのリスナーは com.sun.star.awt.XAdjustmentListener です。メソッドはスクロール値が変更されたときに呼び出される adjustmentValueChanged と disposing のみです。 このリスナーをスクロールバーオブジェクト (oDialog から getControl メソッドで取得されるコントロールオブジェクト) の addAdjustmentListener メソッドで付け加えます。 このリスナーで adjustmentValueChanged が呼び出されたときにそれぞれのコントロールの位置 (縦方向に移動させるときには PositionY プロパティーを変更するような処理を記述します。 まだ,書きかけです。もうすこしお待ちください。
たとえば, Dim oDialog As Object Dim oDialogModel As Object Dim oAdjustmentListener As Object Dim oScrollBar As Object Dim oButtonM1 As Object, oButtonM2 As Object Dim oButtonM3 As Object, oButtonM4 As Object Dim oButtonM5 As Object, oButtonM6 As Object Sub Main() Dialog() End Sub Sub Dialog() Dim oScrollBarM As Object Dim oLabelModel As Object Dim oManager As Object oManager = GetProcessServiceManager() oDialogModel = oManager.createInstance("com.sun.star.awt.UnoControlDialogModel") With oDialogModel .setPropertyValue("Name","Dialog") .setPropertyValue( "PositionX", 86 ) .setPropertyValue( "PositionY", 67 ) .setPropertyValue( "Height", 121 ) .setPropertyValue( "Width", 82 ) .setPropertyValue( "Title", "Dialog" ) .Step = 1 End With oLabelModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel") With oLabelModel .setPropertyValue("Name","Label") .setPropertyValue( "PositionX", 6 ) .setPropertyValue( "PositionY", 10 ) .setPropertyValue( "Height", 14 ) .setPropertyValue( "Width", 67 ) .setPropertyValue( "Label", "Buttons" ) .Align = com.sun.star.awt.TextAlign.CENTER .Step = 0 End With oButtonM1 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM2 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM3 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM4 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM5 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") oButtonM6 = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel") With oButtonM1 .setPropertyValue( "Name", "b1" ) .setPropertyValue( "PositionX", 5 ) .setPropertyValue( "PositionY", 32 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","1") .Step = 1 End With With oButtonM2 .setPropertyValue( "Name", "b2" ) .setPropertyValue( "PositionX", 5 ) .setPropertyValue( "PositionY", 56 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","2") .Step = 1 End With With oButtonM3 .setPropertyValue( "Name", "b3" ) .setPropertyValue( "PositionX", 5 ) .setPropertyValue( "PositionY", 80 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","3") .Step = 1 End With With oButtonM4 .setPropertyValue( "Name", "b4" ) .setPropertyValue( "PositionX", 5 ) .setPropertyValue( "PositionY", 32 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","4") .Step = 2 End With With oButtonM5 .setPropertyValue( "Name", "b5" ) .setPropertyValue( "PositionX", 5 ) .setPropertyValue( "PositionY", 56 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","5") .Step = 2 End With With oButtonM6 .setPropertyValue( "Name", "b6" ) .setPropertyValue( "PositionX", 5 ) .setPropertyValue( "PositionY", 80 ) .setPropertyValue( "Width", 69 ) .setPropertyValue( "Height", 15 ) .setPropertyValue( "Label","6") .Step = 2 End With oScrollBarM = oDialogModel.createInstance("com.sun.star.awt.UnoControlScrollBarModel") With oScrollBarM .Name = "sb" .PositionX = 50 .PositionY = 103 .Width = 23 .Height = 13 .Orientation = com.sun.star.awt.ScrollBarOrientation.HORIZONTAL .ScrollValue = 0 .ScrollValueMax = 1 .BlockIncrement = 1 .LineIncrement = 1 .Step = 0 End With With oDialogModel .insertByName("Label",oLabelModel) .insertByName("b1", oButtonM1) .insertByName("b2", oButtonM2) .insertByName("b3", oButtonM3) .insertByName("b4", oButtonM4) .insertByName("b5", oButtonM5) .insertByName("b6", oButtonM6) .insertByName("sb", oScrollBarM) End With oDialog = oManager.createInstance("com.sun.star.awt.UnoControlDialog") oDialog.setModel(oDialogModel) oAdjustmentListener = CreateUnoListener("Adjustment_", "com.sun.star.awt.XAdjustmentListener") oScrollBar = oDialog.getControl("sb") oScrollBar.addAdjustmentListener(oAdjustmentListener) oDialog.setVisible(true) oDialog.execute() End Sub Sub Adjustment_adjustmentValueChanged(oEvent) 'MsgBox oEvent.Dbg_Properties If oDialogModel.Step = 1 Then oDialogModel.Step = 2 Else oDialogModel.Step = 1 End If End Sub Sub Adjustment_disposing() End Sub それぞれのコントロールの Step プロパティーを設定することで,ダイアログのステップで表示するコントロールを指定することができます。 また,この Step プロパティーが "0" のコントロールは全てのステップで表示されます。ここでは,一番上のラベルとスクロールバーです。 ダイアログの Step プロパティーを設定,変更することで表示するダイアログのステップを変更することができます。
Developer's Guide の Chapter 11 (の p.780) に ScrollBar を使用した例が載っています。スクロール値にしたがってコントロールの位置を計算して配置しているようです。
|