-- Script_Root_Object
-----------------------------------
-- CREATED:
-- 26.02.2010
--
-- DESCRIPTION:
--              This is the base script to use as ancestor for all parentscripts
--              It provides basic handlers for authoring and runtime functions
--
-- REQUIRES:
--              -
--
-- USAGE:
--              use this script as ancestor for scripts in order to incorporate some basic handlers
-----------------------------------

on _____________________PROPERTY_DECLARATION me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
property pMyScriptName
property pAlreadyDestroying

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____________________STANDARD_EVENTS me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on new me
  return me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____________________ENGINE_EVENTS me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDestroy me
  pAlreadyDestroying = 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mIsAlreadyDestroying me
  return pAlreadyDestroying
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ___________________PUBLIC_EVENTS me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetScriptName me, aScriptname
  -----------------------------------
  -- ACTION: Set the name of the script. This is typically the castmember name,
  --         so we can identify this script in the list of scripts attached to the node
  --         in order to for example get a reference or check, if the script is already present
  --         THIS IS TO BE USED, IF THIS SCRIPT IS USED AS AN ANCESTOR!
  -- INPUT: <aScriptname> ; string ; name of the script, which shall be used for 
  --                   * mGetScriptInstance()
  --                   * mGetScriptInstanceList()
  -- RETURNS: -
  -----------------------------------
  
  pMyScriptName = string(aScriptname)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetScriptName me
  -----------------------------------
  -- ACTION: Get the name of the script. This is typically the castmember name,
  --         so we can identify this script in the list of scripts attached to the node
  --         in order to for example get a reference or check, if the script is already present
  --         THIS IS TO BE USED, IF THIS SCRIPT IS USED AS AN ANCESTOR!
  -- INPUT: -
  -- RETURNS: string ; name of the script, which shall be used for 
  -----------------------------------
  
  return pMyScriptName
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetInterface me, string_keyword
  -----------------------------------
  -- CREATED: 20.03.2008
  -- ACTION: Get the "interface" of this script: all properties
  --               this is rather an AUTHORING FUNCTION! At runtime it is limited,
  --                                                         as we do not have scripttext
  --
  -- INPUT: <string_keyword> ; string ; optional filter to constrain the results
  --                       use "%" or "^" as the first char if the filter shall be =>
  --                                                     'word STARTS with <string_keyword>'
  --                       use "$" as the last char if the filter shall be =>
  --                                                     'word ENDS with <string_keyword>'
  --                       (HINT: if searching for the exact phrase use ^keyword$ as filter)
  --                       otherwise the string <string_keyword> may appear anywhere in the word =>
  --                                                     'word CONTAINS <string_keyword>'
  -- RETURNS: string
  -- EXAMPLE: put xscr().GetInterfaceList()
  -----------------------------------
  
  string_keyword = string(string_keyword)
  scrName = getReferenceString(me)
  props = "-- -- -- PROPERTIES:"
  str = "-- -- -- OBJECTS:"
  cnt = count(me)
  xscr = xscr()
  repeat with n = 1 to cnt
    propname = string(me.getPropAt(n))
    if ilk(me.getaProp(propname)) = #instance then
      instname = string(me.getPropAt(n))
      if xscr.mFilterString(instname, string_keyword) = 1 then
        put RETURN & scrName & "." & instname & RETURN after str
      end if
    else
      if xscr.mFilterString(propname, string_keyword) = 1 then
        put RETURN & scrName & "." & propname & RETURN after props
      end if
    end if
  end repeat
  
  hnd = "-- -- -- HANDLERS:"
  scriptTextParser = xscr(#scriptTextParser)
  if ilk(scriptTextParser) = #instance then
    hnd = scriptTextParser.handlerList(me, string_keyword, scrName)
  end if
  
  return RETURN & str & RETURN & RETURN & props & RETURN & RETURN & hnd & RETURN
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- just a shortcut to avoid typing "mGetInterface" into the message window all the time
on __iface me, string_keyword
  return mGetInterface(me, string_keyword)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on lingodoc me, string_keyword
  
  string_keyword = string(string_keyword)
  scrName = getReferenceString(me)
  
  scriptTextParser = xscr(#scriptTextParser)
  if ilk(scriptTextParser) = #instance then
    hnd = scriptTextParser.handlerList(me, string_keyword, scrName, 1, 1)
  end if
  
  return RETURN & hnd & RETURN
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on showInScript me, string_keyword
  
  if (the runmode contains "aut") then
    string_keyword = string(string_keyword)
    scrName = getReferenceString(me)
    
    scriptTextParser = xscr(#scriptTextParser)
    if ilk(scriptTextParser) = #instance then
      hndList = scriptTextParser.mGetInfoListForItem(me, string_keyword)
    end if
    
    if ilk(hndList) <> #proplist then exit
    
    memnum = hndList[#memberNumber]
    cnum = hndList[#castlibNumber]
    offs1 = 1
    offs2 = 1
    
    itms = hndList[#items]
    if listP(itms) then
      if count(itms) > 0 then
        thisHnd = itms[1]
        memnum = thisHnd[#memberInfo][#memberNumber]
        cnum = thisHnd[#memberInfo][#castlibNumber]
        offs = thisHnd[#charoffset]
        if listP(offs) then
          if count(offs) > 1 then
            offs1 = offs[1]
            offs2 = offs[2]
          end if
        end if
      end if
    end if
    
    activateScriptEditor memnum, cnum, offs1, offs2
    
  else
    alert "This function is only available in authoring"
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ___________________CALLBACK_EVENTS me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on ___________________PRIVATE_VENTS me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on getReferenceString me
  
  scrName = string(mGetScriptName())
  if length(scrName) < 1 then
    scrName = word 2 of string(me)
    delete char 1 of scrName
    delete the last char of scrName
  end if
  return "xscr(#" & xscr().mSymbolify(scrName) & ")"
end

