set maxLines to the number of lines in the pDataFileDirectoryContents of gObj5
set vLoc to the locV of sprite mySprite + ((15 + the height of the member of sprite 10 + 10) * active)
set bugFix to the left of sprite mySprite
set topOfBarOffset to the height of the member of sprite upBtnSprite
set pScrollBarHeight to the height of sprite mySprite - (topOfBarOffset * 2) - the height of the member of sprite indicatorSprite + 2
set lineHite to the textHeight of member myField
set lineMax to the height of sprite mySprite / lineHite
if maxLines > lineMax then
set moreThanMax to 1
set IndicatorOffset to pScrollBarHeight * 1.0 / (maxLines - lineMax)
else
if maxLines = 1 then
if the pDataFileDirectoryContents of gObj5 = EMPTY then
set maxLines to 0
else
set moreThanMax to 0
end if
else
set moreThanMax to 0
end if
end if
if maxLines then
set alphabeticIndex to []
repeat with i = 1 to maxLines
add(alphabeticIndex, symbol(char 1 of line i of the pDataFileDirectoryContents of gObj5))
end repeat
sort(alphabeticIndex)
end if
set clickTimer to the ticks
end
on updateIndicator me, nosound
if not moreThanMax then
set newLoc to 9000
else
set newLoc to vLoc + topOfBarOffset + integer(scrollTopValue / lineHite * IndicatorOffset)
if not (the locV of sprite indicatorSprite = newLoc) and not nosound then
puppetSound(1, "clickSnd")
end if
end if
set the locV of sprite indicatorSprite to newLoc
set the locV of sprite (indicatorSprite + 1) to newLoc
end
on updateHilite me
set newHiliteLoc to ((activeLine - 1) * lineHite) + vLoc + 2 - scrollTopValue
if not ((newHiliteLoc > vLoc) and (newHiliteLoc < (vLoc + (lineHite * lineMax)))) then
set newHiliteLoc to 9000
end if
set the locV of sprite (mySprite + 1) to newHiliteLoc
set the locV of sprite (mySprite + 3) to newHiliteLoc
end
on scrollField me, fromWhichSprite, direction
set scrollTopValue to max(0, min(scrollTopValue + (lineHite * direction), (maxLines - lineMax) * lineHite))
set the scrollTop of member myField to scrollTopValue
if active then
updateHilite()
end if
updateIndicator()
updateStage()
end
on mouseDown me
if not maxLines or not active then
exit
end if
set whichLine to ((the locV of the clickLoc - 2 - vLoc + (lineHite * 10)) / lineHite) - 10
set activeLine to whichLine + 1 + (scrollTopValue / lineHite)
moveHilite(me, 0)
if (activeLine = (whichLine + 1 + (scrollTopValue / lineHite))) and (clickTimer > the ticks) then
set defaultSprite to the defaultBtn of script "DialogScripts"
terminateDialog(script "DialogScripts", the myAction of sprite(defaultSprite), the myObj of sprite(defaultSprite), the myParams of sprite(defaultSprite))
exit
else
set clickTimer to the ticks + 17
end if
set lastLine to whichLine
repeat while the mouseDown
set mouseV to the mouseV - 2
set whichLine to ((mouseV - vLoc + (lineHite * 10)) / lineHite) - 10
if (mouseV < vLoc) or (mouseV > (vLoc + ((lineHite * 10) - 1))) then
set offLimits to 1
else
set offLimits to 0
end if
if not (whichLine = lastLine) or offLimits then
set activeLine to whichLine + 1 + (scrollTopValue / lineHite)
moveHilite(me, 0)
set lastLine to whichLine
if offLimits then
Del(2)
end if
end if
end repeat
set the myParams of sprite(4) to activeLine
end
on dragIndicator me, theSprite
set offset to the locV of the clickLoc - the locV of sprite theSprite
set oldLoc to the locV of the clickLoc
repeat while the mouseDown
set newLoc to min(vLoc + pScrollBarHeight + topOfBarOffset, max(vLoc + topOfBarOffset, the mouseV - offset))
if not (newLoc = oldLoc) then
set newScrollTopValue to integer((newLoc - vLoc - topOfBarOffset) / IndicatorOffset) * lineHite
if not (newScrollTopValue = scrollTopValue) then
set scrollTopValue to newScrollTopValue
set the scrollTop of member myField to scrollTopValue
if active then
updateHilite()
end if
puppetSound(1, "clickSnd")
end if
set the locV of sprite theSprite to newLoc
set the locV of sprite (theSprite + 1) to newLoc
updateStage()
set oldLoc to newLoc
end if
end repeat
updateIndicator(me, 1)
updateStage()
end
on moveHilite me, direction
set activeLine to max(1, min(maxLines, activeLine + direction))
set the myParams of sprite(4) to activeLine
set scrollMin to scrollTopValue / lineHite
set diff to activeLine - scrollMin
if diff > lineMax then
set scrollTopValue to (scrollMin + diff - lineMax) * lineHite
else
if diff < 1 then
set scrollTopValue to (scrollMin + diff - 1) * lineHite
end if
end if
set the scrollTop of member myField to scrollTopValue
updateHilite()
updateIndicator()
updateStage()
end
on processKey me, theKey
if theKey = "" then
if not maxLines then
exit
end if
moveHilite(me, -1)
else
if theKey = "" then
if not maxLines then
exit
end if
moveHilite(me, 1)
else
if theKey = "" then
scrollPage(me, 1)
else
if theKey = "" then
scrollPage(me, -1)
else
if theKey = "" then
scrollPage(me, -1000)
else
if theKey = "" then
scrollPage(me, 1000)
else
if (theKey = RETURN) or (theKey = ENTER) then
handleDefaultKeyDown(script 1)
else
set activeLine to findPosNear(alphabeticIndex, symbol(theKey))
moveHilite(me, 0)
end if
end if
end if
end if
end if
end if
end if
end
on scrollPage me, direction
set scrollTopValue to max(0, min(the scrollTop of member myField + (lineHite * (direction * (lineMax - 1))), (maxLines - lineMax) * lineHite))
set the scrollTop of member myField to scrollTopValue