[futurebasic] Arrow Keys and Scroll Bars

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2007 : Group Archive : Group : All Groups

From: Charles Poole <pochas@...>
Date: Sat, 18 Aug 2007 14:07:27 -0400
To wrap this up, I was able to achieve exactly the effect I wanted by  
using a function I found by rummaging around the header files,  
namely, fn FixLinkedEditField( scrlHndl as ControlRef ).

The following code links the arrow keys to the scroll bars in any  
active window where the vertical scroll bar is numbered 1 and the  
horizontal scroll bar is numbered 2.  If the scroll bar is linked to  
an edit field, the FixLinkedEditField function must be called.  In a  
linked edit field the automatic behavior of the edit field is  
overridden as  follows.  Instead of moving the insertion carat, the  
up and down keys scroll the text by one line.  Left and right arrows  
still move the carat.  Page up, page down, home and end arrows work,  
and do not insert unreadable characters into the text.  Select, copy  
and paste functions still work via the mouse.

Paste enough text into the edit field to activate the scroll bar.

Pardon the coding style; I am not a professional.  Thanks to whoever  
wrote the FixLinkedEditField function.

Charles

'----------------------------------------
local fn scrlPage
dim cRefCon as ^^FBcontrolDescription
dim as long pagex
cRefCon = fn GetCRefCon(button&(1))
pagex = cRefCon..FBcontrolPage
end fn = pagex

local fn arrowKeys(theEvent as int, theKey as int)
dim as pointer btn1Ptr, btn2Ptr
dim btn1Val, btn2Val, keyFound
keyFound = _zTrue
btn1Ptr = button&(1)
long if btn1Ptr
btn1Val = fn GetControlValue(btn1Ptr)
select theKey
case 1'home
scroll button 1, 0
case 4'end
scroll button 1, 999
case 11'page
scroll button 1, btn1Val - fn scrlPage
case 12'page down
scroll button 1, btn1Val + fn scrlPage
case 30'up arrow
scroll button 1, btn1Val -1
case 31'down arrow
scroll button 1, btn1Val + 1
case else
keyFound = _false
end select
end if
long if keyFound = _false or btn1Ptr = 0
btn2Ptr = button&(2)
long if btn2Ptr
btn2Val = fn GetControlValue(btn2Ptr)
keyFound = _zTrue
select theKey
case 28'left arrow
scroll button 2, btn2Val - 1
case 29'right arrow
scroll button 2, btn2Val + 1
case else
keyFound = _false
end select
end if
end if
end fn = keyFound

local fn doEvent
dim as pointer ePtr
dim as long theEvent
ePtr = EVENT
theEvent = ePtr.evtNum%
long if theEvent
select theEvent
case _keyDwnEvt, _autoKeyEvt
long if fn arrowKeys(theEvent, ePtr.evtMessage& and 0xFF)
select window(_activeWnd)
case 1
fn FixLinkedEditField(button&(1))
end select
ePtr.evtNum% = _nullEvt
end if
end select
end if
end fn

local fn doMenu
dim menux
menux = menu(_menuID)
if menux = 1 then end
end fn

local fn buildMenus
menu 1, 0, _enable, "File"
menu 1, 1, _enable, "/QQuit"
edit menu 1
end fn

on event fn doEvent
on menu fn doMenu

fn buildMenus

window 1, "", (40,60)-(240,260)
edit field -1, "", (5,5)-(170,170)
scroll button -1, 1,1,100,10,,_scrollVert

do
handleevents
until 0
'------------------------------------------------------------