property callback -- The handler to call when the ¬
-- password has been entered
property proxyChar -- The dummy char to use
property password -- The actual password keyed in
property fieldMember -- The name of the field
property spriteNum -- The sprite channel number
property clipboard -- Private clipboard storage
-- Initialise the password entry box
on beginSprite me
-- Get the member reference of the field
set memberRef = the member of sprite spriteNum
-- Get the name of the field
set fieldMember = the name of memberRef
-- Clear the field
put "" into field fieldMember
-- Clear the password property
set password = ""
end
-- Handle keyDown events in the field
on keyDown me
-- Stores the key and the keyCode into local
-- variables for protection
set theKey = the key
set theKeyCode = the keyCode
-- Check to see if there was a command key combo
if the commandDown then
-- Make sure the shift key isn't down
if not the shiftDown then
-- Check for key combo
case theKey of
"x": -- Cut shortcut combo
cutText me
"c": -- Copy shortcut combo
copyText me
"v": -- Paste shortcut combo
pasteText me
end case
end if
-- We don't handle the command key combo but
-- a global handler might so we pass the event
pass
else
-- The command key wasn't down so we trap the event
case theKey of
RETURN: -- Do callback handler
doPasswordCheck me
otherwise
-- Check for the cursor and delete keys
case theKeyCode of
51: -- Delete
deleteText me
123: -- Left
if the selStart = the selEnd then
-- We have a flashing 'I' insertion
-- point so we move it to the left
set the selStart = the selStart - 1
set the selEnd = the selStart
else
-- We have a selection so we switch
-- to an flashing 'I' insertion point
-- at the left side of the selection
set the selEnd = the selStart
end if
124: -- Right
if the selStart = the selEnd then
-- We have a flashing 'I' insertion
-- point so we move it to the right
set the selEnd = the selEnd + 1
set the selStart = the selEnd
else
-- We have a selection so we switch
-- to an flashing 'I' insertion point
-- at the right side of the selection
set the selStart = the selEnd
end if
125: -- Down
-- Move to the end of the field
set the selEnd = length(password)
set the selStart = the selEnd
126: -- Up
-- Move to the beginning of the field
set the selStart = 0
set the selEnd = 0
otherwise
-- Normal char so we add it to the password
addCharToPassword me, theKey
-- Add a dummy char to the field
putProxyCharInField me
end case
end case
end if
end
-- Call the global password checking handler
on doPasswordCheck me
do callback && "password"
end
-- Add a dummy char to the field
on putProxyCharInField me
if the selStart = the selEnd then
-- We have an insertion point so just insert the dummy char
put proxyChar after char the selStart of field fieldMember
-- Move the insertion point along
set the selEnd = the selEnd + 1
set the selStart = the selStart + 1
else
-- We have a selection so delete the selection first
delete char the selStart + 1 to the selEnd of field fieldMember
-- Insert dummy char
put proxyChar after char the selStart of field fieldMember
-- If all of the field was selected then put the
-- insertion point at the end, otherwise put after
-- the inserted char
if length(password) = 1 then
-- Put the insertion point at the end
set the selEnd = 1
set the selStart = 1
else
-- Put the insertion point after the new char
set the selStart = the selEnd
end if
end if
end
-- Add a char to the password
on addCharToPassword me, theChar
if the selStart = the selEnd then
-- We have an insertion point so just insert the char
put theChar after char the selStart of password
else
-- We have a selection so delete the selection first
delete char the selStart + 1 to the selEnd of password
-- Insert the char into the password
put theChar after char the selStart of password
end if
end
-- Cut a selection to the private clipboard
on cutText me
-- Check to see if there is a selection
if the selStart <> the selEnd then
-- Copy the chars of the password to the clipboard
set clipboard = char the selStart + 1 to the selEnd of password
-- Delete the slection from the password
delete char the selStart + 1 to the selEnd of password
-- Delete the slection from the field
delete char the selStart + 1 to the selEnd of field fieldMember
-- Set the insertion point to the beginning of the selection
set the selEnd = the selStart
end if
end
-- Copy a selection to the private clipboard
on copyText me
-- Check to see if there is a selection
if the selStart <> the selEnd then
-- Copy the chars of the password to the clipboard
set clipboard = char the selStart + 1 to the selEnd of password
end if
end
-- Paste text from the clipboard
on pasteText me
if the selStart = the selEnd then
-- We have an insertion point so just insert the clipboard
put clipboard after char the selStart of password
-- Insert a string of dummy chars into the field
put buildRepeatString(me,proxyChar,length(clipboard)) after ¬
char the selStart of field fieldMember
-- Set the insertion point to the end of the inserted text
set the selEnd = the selEnd + length(clipboard)
set the selStart = the selEnd
else
-- We have a selection so delete the text first
delete char the selStart + 1 to the selEnd of password
delete char the selStart + 1 to the selEnd of field fieldMember
-- Set the insertion point to the beginning of the selection
set the selStart = the selEnd
-- Insert the clipboard into the password
put clipboard after char the selStart of password
-- Insert a string of dummy chars into the field
put buildRepeatString(me,proxyChar,length(clipboard)) after ¬
char the selStart of field fieldMember
-- Set the insertion point to the end of the inserted text
set the selEnd = the selEnd + length(clipboard) - 1
set the selStart = the selEnd
end if
end
-- Delete text
on deleteText me
-- Check to see if we're at the beginning of the field
if the selEnd > 0 then
if the selStart <> the selEnd then
-- We have a selection so delete the selection
delete char the selStart + 1 to the selEnd of password
delete char the selStart + 1 to the selEnd of field fieldMember
-- Set the insertion point to the beginning of the selection
set the selEnd = the selStart
else
-- We have an insertion point
if the selEnd = length(password) then
-- We are at the end of the field so delete the last char
delete char the selStart of password
delete char the selStart of field fieldMember
-- Set the insertion point to the end of the field
set the selEnd = the selStart
else
-- We are in the middle of the field so delete the
-- the preceding char from the field and password
delete char the selStart of password
delete char the selStart of field fieldMember
-- Move the insertion point to the left
set the selStart = the selStart - 1
set the selEnd = the selStart
end if
end if
end if
end
-- Return a string of identical chars
on buildRepeatString me, theChar, theLength
-- Initialise the string
set theString = ""
-- Repeat for theLength times
repeat with i = 1 to theLength
-- Add another char
set theString = theString & theChar
end repeat
-- Return the string of multiple chars
return theString
end
-- Build the custom properties dialog
on getPropertyDescriptionList
-- Initialise the property list
set propList = [:]