1<?xml version="1.0" encoding="UTF-8"?> 2<!--*********************************************************** 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 * 21 ***********************************************************--> 22<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ScrollBar" script:language="StarBasic">REM ***** BASIC ***** 24 25Dim oDialog As Object 26Const Border = 5 27 28Sub Main() 29 30 Dim oLibContainer As Object, oLib As Object 31 Dim oInputStreamProvider As Object 32 Dim oDialogModel As Object 33 Dim oScrollBarModel As Object 34 Dim oLabelModel As Object 35 Dim sLabel As String 36 Dim VisibleSize As Double 37 38 Const sLibName = "ToolkitControls" 39 Const sDialogName = "ScrollBarDlg" 40 41 REM load/get library and input stream provider 42 oLibContainer = DialogLibraries 43 oLibContainer.loadLibrary( sLibName ) 44 oLib = oLibContainer.getByName( sLibName ) 45 oInputStreamProvider = oLib.getByName( sDialogName ) 46 47 REM create dialog control 48 oDialog = CreateUnoDialog( oInputStreamProvider ) 49 50 REM set the label 51 sLabel = "This Text exceeds the visible area of the dialog and can be" 52 sLabel = sLabel + " scrolled horizontally by clicking on the scroll bar." 53 oDialogModel = oDialog.Model 54 oLabelModel = oDialogModel.Label1 55 oLabelModel.Label = sLabel 56 57 REM scroll bar settings 58 oScrollBarModel = oDialog.Model.ScrollBar1 59 oScrollBarModel.ScrollValueMax = 100 60 VisibleSize = (oDialogModel.Width - Border - oLabelModel.PositionX) / oLabelModel.Width 61 VisibleSize = VisibleSize * oScrollBarModel.ScrollValueMax 62 oScrollBarModel.VisibleSize = VisibleSize 63 oScrollBarModel.BlockIncrement = oScrollBarModel.VisibleSize 64 oScrollBarModel.LineIncrement = oScrollBarModel.BlockIncrement / 20 65 66 REM show the dialog 67 oDialog.execute() 68 69End Sub 70 71Sub AdjustmentHandler() 72 73 Dim oLabelModel As Object 74 Dim oScrollBarModel As Object 75 Dim ScrollValue As Long, ScrollValueMax As Long 76 Dim VisibleSize As Long 77 Dim Factor As Double 78 79 Static bInit As Boolean 80 Static PositionX0 As Long 81 Static Offset As Long 82 83 REM get the model of the label control 84 oLabelModel = oDialog.Model.Label1 85 86 REM on initialization remember the position of the label control and calculate offset 87 If bInit = False Then 88 bInit = True 89 PositionX0 = oLabelModel.PositionX 90 OffSet = PositionX0 + oLabelModel.Width - (oDialog.Model.Width - Border) 91 End If 92 93 REM get the model of the scroll bar control 94 oScrollBarModel = oDialog.Model.ScrollBar1 95 96 REM get the actual scroll value 97 ScrollValue = oScrollBarModel.ScrollValue 98 99 REM calculate and set new position of the label control 100 ScrollValueMax = oScrollBarModel.ScrollValueMax 101 VisibleSize = oScrollBarModel.VisibleSize 102 Factor = Offset / (ScrollValueMax - VisibleSize) 103 oLabelModel.PositionX = PositionX0 - Factor * ScrollValue 104 105End Sub 106</script:module>