Can you actually see it?
Peter Brigham
pmbrig at comcast.net
Mon Aug 14 22:31:57 EDT 2006
I thought I'd contribute a couple of functions others might find
useful, having recently (with a bit of difficulty, as usual) solved a
problem. I wanted the user to be able to select a data field by
clicking on it. I wanted to limit the choices to fields with
sharedtext = false that are actually visible to the user, which
seemed straightforward at first, until I realized that the visible of
a field can be true but the field might be hidden by another object,
or its visible could be true but it could be a part of a group whose
visible is false -- or that group might be part of a larger group
whose visible is false, etc. So I came up with a function
isActuallyVisible(), and a function chooseField() that cycles through
the list of controls from topmost down and pinpoints whether the user
clicked on a valid field. It returns the long id of the clicked
field, or exits to top if the user didn't click on a data field.
I'm using this as the front end for a custom "find" function that
allows the user to choose to limit a "find" to one field in a stack
that has multiple fields in multiple groups (some nested), many of
which are hidden depending on which background or group is visible.
Hopefully these solutions will be useful to someone at some point....
(watch linewraps)
function chooseField
answer "Click on the field to search in. Command-period to exit."
as sheet
put the allowInterrupts into oldAllowInterrrupts
set the allowInterrupts to true
set the cursor to 1579 -- or whatever custom cursor
select empty
wait until the mouseclick
put the clickloc into cloc
set the cursor to arrow
set the allowInterrupts to oldAllowInterrrupts
put the number of controls into nbr
repeat with c = nbr down to 1
put the long id of control c into cName
if not (cloc is within the rect of control c) then next repeat
if not isActuallyVisible(cName) then next repeat
-- now the click is within an actually visible control
if "field" is not in cName then -- but it's not a field, so exit
answer "You must click on a field!" as sheet
exit to top
end if
if the sharedText of control c then -- it's not a data field, so
exit
answer "You must click on a data field!" as sheet
exit to top
end if
if the dontsearch of control c then -- it's not searchable, so exit
answer "This field doesn't contain searchable data!" as sheet
exit to top
end if
return cName
end repeat
-- went all the way down the list and didn't locate anything valid
answer "You must click on a data field!" as sheet
exit to top
end chooseField
function isActuallyVisible theObject
put the visible of theObject into v1
if not v1 then return false
-- at least theObject is visible
put the owner of theObject into onr
if onr contains "card" then
return true
else
return isActuallyVisible(onr)
end if
end isActuallyVisible
*****************************
-- Peter
Peter M. Brigham
pmbrig at comcast.net
http://home.comcast.net/~pmbrig/
~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~
I'm stuck in that awkward stage between birth and death.
More information about the use-livecode
mailing list