-- Popup menu behavior that uses Anti-aliased Text members
-- works in Director 7 and 8
--******************************************************************
-- version 1.2 April 2000
-- (c) Mare (Mark Reijnders) mare@peghole.com
-- http://www.peghole.com
-- A demo movie can be found at http://www.peghole.com/lingo/txtpopup2.zip
-- if used please give credit
--******************************************************************
on GetBehaviorDescription
return "Generic Popupmenu behavior" & RETURN & ¬
"This behavior displays a popup menu (also called dropdown menu) that consists of anti aliased text.¬
The behavior should be attached to a single line text member. In the score there should¬
be three more sprites populated with the following members:¬
An optional outline (Quickdraw shape member), the complete popup text cast member, and the hilite member, a filled quickdraw shape. ¬
The sprite order should be outlinemember, normal (1 line) member, expanded member, hiliteline member" & RETURN & ¬
"Words that should not trigger any change EG 'Select..' can be given as an option." & RETURN & ¬
"Separators should be made with the underscore character" & RETURN & ¬
"Optional Lingo handler that will be executed at mouseup with the selected line as a parameter"
set p_list = [¬
#pMouseUpCommand: [#comment:"Lingo for MouseUp:", #format:#string, #default: "handlePopUp"], ¬
#pExcludedWords: [#comment:"Words in popUp that should not trigger actions:", #format:#string, #default:""]]
on getBehaviorTooltip me
return¬
"Use with Text members." & RETURN & RETURN & ¬
"Displays a popup menu (also called dropdown menu) that consists of anti aliased text."
end getBehaviorTooltip
on isOKToAttach (me, aSpriteType, aSpriteNum)
case aSpriteType of
#graphic:
return getPos([#text], sprite(aSpriteNum).member.type) <> 0
#script:
return FALSE
end case
end isOKToAttach
on PopupMouseDown me
-- Do all stuf not in a normal mouseDown handler so it can be called from a button
-- Eg sendsprite(12, #PopupMouseDown)
myText = pNormalMember.text
--check contents of text
myText = pNormalMember.text
case (true) of
(pExcludedWords contains myText) : -- don't do anything because popup is 'frozen'
pSelectedLine = 0
return
(myText contains "Don't select") : -- add other words or chunks here to exclude more items
pSelectedLine = 0
return
end case
--exchange members
sprite(pPopUpSpriteNum).loc = sprite(pNormalSpriteNum).loc
-- get properties of popup; they might be changed
scrollTop = pPopUpMember.scrollTop
spriteHeight = (sprite(pPopUpSpriteNum).rect).height
memberHeight = (pNormalMember.rect).height
memberWidth = (pPopUpMember.rect).width
popUpHeight = abs(scrolltop - spriteHeight)
pLinecount = popUpHeight / max(memberHeight, 1)
pLineHeight = popUpHeight/pLinecount
-- highlight the right line
repeat while the mouseDown
myline = pointToLine(sprite pPopUpSpriteNum, the mouseLoc)
if myline = -1 then -- no line selected
sprite(pHiliteSpriteNum).locv = -1000
updatestage
next repeat
end if
-- here we handle what to do on mouseUp
pSelectedline = myLine
--Exclude words or characters here If the text of the selected line of your popup are one of these words or ¬
phrases you can do special things. Of course you'll have to change these lines.
mylinecount = (pPopUpMember.text).line.count
if mylinecount > 2 then
lastline = mylinecount
if lastline <> myline then
newPopUpText = newPopUpText & RETURN & pPopUpMember.text.line[(myline + 1)..lastline]
end if
end if
pPopUpMember.text = newPopUpText
if pMouseUpCommand <> "" then
-- execute chosen handler with two parameters
do pMouseUpCommand & QUOTE & pSelectedLine & QUOTE && "," && curOrderPos
end if
end if
--This is an example of a movie script that works together with this behavior
--copy it to a moviescript
on handlePopUp selectedText, orderInList
-- selectedText is a string with the currently chosen popup or a 0 if nothing is chosen
-- orderInList is an integer that tells which line was selected from the original order of the popUpmember
member("feedback").text = "You selected" & RETURN & string(selectedText) & RETURN & "This was line" && orderInList && "of the original popupmember."
end handlePopUp
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA