Horizontal/Vertical Scroll Bar

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 12:03, 1 November 2007 by Jsc (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



If the visible area in a dialog is smaller than the displayable content, the scroll bar control com.sun.star.awt.UnoControlScrollBar provides navigation through the content by scrolling horizontally or vertically. In addition, the scroll bar control is used to provide scrolling to controls that do not have a built-in scroll bar.

The orientation of a scroll bar is specified by the Orientation property and can be horizontal or vertical. A scroll bar has a thumb (scroll box) that the user can drag with the mouse to any position along the scroll bar. The position of the thumb is controlled by the ScrollValue property. For a horizontal scroll bar, the left-most position corresponds to the minimum scroll value of 0 and the right-most position to the maximum scroll value defined by the ScrollValueMax property. A scroll bar also has arrows at its end that when clicked or held, incrementally moves the thumb along the scroll bar to increase or decrease the scroll value. The change of the scroll value per mouse click on an arrow is specified by the LineIncrement property. When clicking in a scroll bar in the region between the thumb and the arrows, the scroll value increases or decreases by the value set for the BlockIncrement property. The thumb position represents the portion of the displayable content that is currently visible in a dialog. The visible size of the thumb is set by the VisibleSize property and represents the percentage of the currently visible content and the total displayable content.

 oScrollBarModel = oDialog.Model.ScrollBar1
 oScrollBarModel.ScrollValueMax = 100
 oScrollBarModel.BlockIncrement = 20
 oScrollBarModel.LineIncrement = 5
 oScrollBarModel.VisibleSize = 20

The scroll bar control uses the adjustment event com.sun.star.awt.AdjustmentEvent to monitor the movement of the thumb along the scroll bar. In an event handler for adjustment events the developer may change the position of the visible content on the dialog as a function of the ScrollValue property. In the following example, the size of a label field exceeds the size of the dialog. Each time the user clicks on the scrollbar, the macro AdjustmentHandler() is called and the position of the label field in the dialog is changed according to the scroll value.

 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
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools