summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/BasicAndDialogs/ToolkitControls/ToolkitControls/ScrollBar.xba
blob: db2dd7cdd16287245f9b60a50272332b402f8333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ScrollBar" script:language="StarBasic">REM  *****  BASIC  *****

Dim oDialog As Object
Const Border = 5

Sub Main()

	Dim oLibContainer As Object, oLib As Object
	Dim oInputStreamProvider As Object
	Dim oDialogModel As Object
	Dim oScrollBarModel As Object
	Dim oLabelModel As Object
	Dim sLabel As String
	Dim VisibleSize As Double

	Const sLibName = &quot;ToolkitControls&quot;
	Const sDialogName = &quot;ScrollBarDlg&quot;

	REM load/get library and input stream provider
	oLibContainer = DialogLibraries	
	oLibContainer.loadLibrary( sLibName )
	oLib = oLibContainer.getByName( sLibName )	
	oInputStreamProvider = oLib.getByName( sDialogName )

	REM create dialog control
	oDialog = CreateUnoDialog( oInputStreamProvider )

	REM set the label
	sLabel = &quot;This Text exceeds the visible area of the dialog and can be&quot;
	sLabel = sLabel + &quot; scrolled horizontally by clicking on the scroll bar.&quot;	
	oDialogModel = oDialog.Model
	oLabelModel = oDialogModel.Label1
	oLabelModel.Label = sLabel

	REM scroll bar settings
	oScrollBarModel = oDialog.Model.ScrollBar1
	oScrollBarModel.ScrollValueMax = 100		
	VisibleSize = (oDialogModel.Width - Border - oLabelModel.PositionX) / oLabelModel.Width 
	VisibleSize = VisibleSize * oScrollBarModel.ScrollValueMax
	oScrollBarModel.VisibleSize = VisibleSize	
	oScrollBarModel.BlockIncrement = oScrollBarModel.VisibleSize
	oScrollBarModel.LineIncrement = oScrollBarModel.BlockIncrement / 20
				
	REM show the dialog
	oDialog.execute()
		
End Sub

Sub AdjustmentHandler()

	Dim oLabelModel As Object
	Dim oScrollBarModel As Object	
	Dim ScrollValue As Long, ScrollValueMax As Long
	Dim VisibleSize As Long
	Dim Factor As Double

	Static bInit As Boolean
	Static PositionX0 As Long
	Static Offset As Long
		
	REM get the model of the label control
	oLabelModel = oDialog.Model.Label1

	REM on initialization remember the position of the label control and calculate offset
	If bInit = False Then
		bInit = True
		PositionX0 = oLabelModel.PositionX
		OffSet = PositionX0 + oLabelModel.Width - (oDialog.Model.Width - Border)
	End If	

	REM get the model of the scroll bar control
	oScrollBarModel = oDialog.Model.ScrollBar1

	REM get the actual scroll value
    ScrollValue = oScrollBarModel.ScrollValue

	REM calculate and set new position of the label control
	ScrollValueMax = oScrollBarModel.ScrollValueMax
	VisibleSize = oScrollBarModel.VisibleSize	    
	Factor = Offset / (ScrollValueMax - VisibleSize)
	oLabelModel.PositionX = PositionX0 - Factor * ScrollValue
		
End Sub
</script:module>