-- Manager for DrawTable Parentscript used on Bitmap sprites and 3-D Sprites
-- Alex da Franca c2002  alex@farbflash.de
-- Use this behavior on any dummy sprite to display a scrolling table with selectable items, text (fixed and editable) and images.
-- It creates a temporary bitmap member, which is used to display the table on the stage.
-- Specify the contents and appearance of the table in two property lists, which you pass to the mShowTable handler
-- Use a copy of the parentscript "TableOptionsliste" to build these two lists and receive events from the table


-- Version 19.06.03
-- mit blend anim =>itanium CD

-- 21.06.03
-- added mTableCellHighLightEvent() and mDeselectTableCell()

-- 04.08.03
-- added functionality to handle submenus
-- unlimited hierarchical depth in case of 3-D,
-- in case of seperate sprites -> 2-D => hierarchical depth limited by the number of sprites with this behavior attached
-- if you want to have 6 levels depth you have to provide 6 dummy sprites with this "TableManager" behavior attached in higher channels


-- Version 14.08.03
-- added column sorting and filtering stuff:
-- sendSprite(mGetKanal(#tabelle), #mChangeSortBy, 1) --> sort alphabetically with column <col> as base according to the sortorder stored in <pSortOrder>
-- sendSprite(mGetKanal(#tabelle), #mReverse) --> reverse alphabetical ordering top -> bottom (pSortOrder = 0 => default) / bottom -> top (pSortOrder = 1)
-- sendSprite(mGetKanal(#tabelle), #mFilterColumn, [[1, "b"], [3, "2"]])


-- Version 01.09.03
-- -- changed the following point later again back (it has shown to be better to always add the name for the sprite instead of defaulting):
-- the name of the sprite (mGetKanal()) is now always #tablekanal, so that related scripts, will always find it.
-- this works with 3-D sprites, which may have already another name as well as with more than one table sprite (2-D with submenus)


-- Version 12.09.03:
-- added handler to get tab delimited text from current view (fuer rainer) mGetCurrentViewList()

-- Version 13.09.03
-- added the handlers to insert and delete rows and columns and reposition and resize columns

-- Version 19.09.03:
-- fixed a bug with mousUpOutside not being called
-- -- mouseUp after a 'repeat while the mousedown' loop is called even if a mouseUpOutside would be appropriate ?!
-- added new accessor handlers:
-- mGetCurrentLinesList() -- get a list with only the lines which are really shown after constraining and sorting
-- mGetCurrentColumnWidths()
-- mSelectCell() -- 'mimic' mouse selection by script
-- mHighLightCell() -- 'mimic' mouse rollover by script
-- mGetCellByIndex()

-- mInsertCol() and mInsertRow() now return success status

-- version 24.10.03:
-- added resizing handler (mSendResizeEvent) to be notified when the table is resized by dragging the lower right corner
-- it is only needed, if other tables (header table) or sprites (e.g. titlebar or dragthumb) depend of the tables rect

-- version 25.10.03
-- added mGetLineByIndex(lineNum) to get the whole list of an entire line

-- 03.11.03
-- added new method: mConvertToConstrained(absline) to get the current visible position of a line, when it is constrained or sorted

-- 21.12.03
-- doofe woody function reingeschrieben, wegen der timeouts (MX 2004 compatibility with timeouts... ;-)

-- 29.12.03
-- do not set the regpoint on image refresh, since it causes a huge delay for updatestage. simply setting the sprite rect is enough

-- 16.01.04
-- added <recalc> parameter to the mSetCellContent() function for faster cell content replacement without recalculating the whole table, if recalc = 0

-- 19.01.04
-- added 'if voidP(pKanal) then mInitProperties me' to prevent errors when using this behavior before it got its beginsprite


-- 22.01.04
-- added mHideTableEvent sent to caller (for menu sprites to be aware when to unhilite the button, which triggers the menu and may want to stay hilited uintil the dismiss of the menu)

-- 23.02.04
-- added additional parameter to mSuspendMouseEvents() => exception to disable mouseevents on all tables EXCEPT sprite(<exception>) => modal menus

-- alex am 29.03.2004 um 01:15
-- added handler: mGetScriptObject() to get a reference to the scriptobject

-- alex am Dienstag, 11. Mai 2004
-- refined the submenuhandling in the enterframe event and the mStopEvent event

-- alex am Donnerstag, 13. Mai 2004
-- in case mInitProperties() is called before the beginsprite it now checks if it has already been called before beginsprite
-- so that the variable set do not get overwritten

-- alex am Sonntag, 16. Mai 2004
-- added the missing fade out, the missing reverse animation is still missing, too lazy today... :-(

-- alex am Montag, 24. Mai 2004
-- keydownscript now gets set right after showing the table and not on mouseDown

-- alex am Montag, 31. Mai 2004
-- this script now can be used as parent script to render the image for use in a VM environment
-- just pass a reference to the instance you want the image to be sent to to the handler "mInitProperties" in the parameter "pipeline"
-- then this reference gets the updated image objects with the event: "mUpdateVMImage me, theImage, theRect, theName"
-- the event "mRemoveTableFromScreen me, tabname" tells when the table has to be deleted from the image
-- sure the mouseEvents (mouseDown, mouseUp and mouseWithin) must be called from outside with the corrected (translated to local) mouse coordinates
-- also provide the handler mGetAbsolutMouse in your instance to pass the corrected mouselocation here into
-- this whole implementation seems complicated, but allows to use a table on any image for example for a texture...

-- alex am Mittwoch, 2. Juni 2004
-- fixed some problems with animations


-- alex am 2. August 2004 um 08:04
-- added mEnableCell() to enable/disable cells => button cells

-- alex am 3. August 2004 um 09:03
-- added handler: mForceKeyDownScript


-- alex am 6. August 2004 um 07:42
-- added mGetCurrentTargRect() to get the rect of the table without the scrollbars
-- unfortunately the scrollbars get appended to the initial defined rect, that was not very clever from little alex
-- so I must always subtract the width of the scrollbars IF ANY :-(


---------------------------------
-- alex am 27. August 2004 um 09:37
-- added mDeSelectSingleCell me, whichCell to deselect a specific cell 'by hand'


-- alex am 8. Oktober 2004 um 10:31
-- new tempmember handling due to a bug in director


---------------------------------
-- alex am 13. Januar 2005 um 09:38
-- mSelectCell now accepts another parameter: whichModifier to mimic shift select. can be: #commandselect and #shiftselect
-- (note that multiple selection must be enabled, which can be enabled temporarely also)

-- added new function: #mSetSelection me, newSelection, tabname
-- accepts a linear list with cells to be selected


---------------------------------
-- alex am 18. Januar 2005 um 11:54
-- added handler: mCheckIfMouseIsOverAnyTable, which return true or false and if provided with a tablename checks if the mouse is over a table
-- and if called without parameter checks if the mouse is over any table
-- useful to prevent mouse events below a table


---------------------------------
-- Scriptmarker (04.04.2005 at 19:14 Uhr): Alex da Franca: Aenderung // Scriptmarker
-- added property #texrenderformat to override the standard rgba4444
-- use r.g. tableformatlist[#texrenderformat] = #rgba8888


---------------------------------
-- Scriptmarker (04.11.2005 at 10:48 Uhr): Alex da Franca: Change // Scriptmarker
-- added property: pStageRectMargin


---------------------------------
-- Scriptmarker (13.04.2006 at 17:23 Uhr): changes alex // Scriptmarker
-- in 2-D mode we remove the dummy sprite from the stage
-- sometimes it is nice to be able to define the rect via the sprite rect
-- so here the original can be looked up

-- added new public handler:  mGetOriginalSpriteRect

-- // changes  from 13.04.2006 at 17:23)
---------------------------------

---------------------------------
-- Scriptmarker (14.04.2006 at 18:31 Uhr): changes alex // Scriptmarker
-- added property pSeeThru to handle mouseOver events even, when another sprite is obscuring the table
-- the default is false, as the default should be to NOT receive the events if something other is over the table
-- // changes  from 14.04.2006 at 18:31)
---------------------------------

--  ---------------------------------
--  -- Scriptmarker (15.04.2006 at 07:51 Uhr): changes alex // Scriptmarker
-- removed the keydownscript forcing on showtable
-- now it gets the key focus only if clicked on. I can't remember why I had set it up like so.


---------------------------------
-- Scriptmarker (10.05.2006 at 09:50 Uhr): changes alex // Scriptmarker
-- added method "mMapPointToStage" to "translate" local coords to absolute coords

---------------------------------
-- Scriptmarker (19.05.2006 at 19:29 Uhr): changes alex // Scriptmarker
-- added #readyToGo property for tables, as the Rect sometimes get set to 0 in order to force an update

---------------------------------
-- Scriptmarker: changes alex (24.07.2006 at 09:19 Uhr) // Scriptmarker

-- added mRemoveTableFromScreen event
-- added property isModal for modal tables to surpress further key and mouse eventy for other tables (in case of using in 3-D)
-- added property to specify the 3-D camera to use for the overlays


---------------------------------
-- Scriptmarker: changes alex (24.08.2006 at 09:47 Uhr) // Scriptmarker
-- added a new property "pDontReplaceMember" to draw into the sprite member in case of running as sprite
-- so the image of the table can persist, if the movie is stopped, instead of deleting it
-- in the default case you don't see a table, when the movie is not running,
-- but all scripts can share a tiny 1 bit 1 pixel bitmap as the image will be created at runtime
-- this is a tad annoying in authoring, because you don't see things, if the movie is not running
-- but it yields very small movies, when publishing

-- if you want to keep the image of the table after stopping the movie set this property to true
-- and make sure, that each table sprite uses its own member.


-- added handler: mAXTable_GetCurrentRadioGroupSelection(me, groupname, tabname) in order to get the current selection of a given radio group


---------------------------------
-- Scriptmarker (15.04.2008 at 11:44 Uhr): changes alex // Scriptmarker
-- added property #animationStatusCallBack to TableFormatlist to store informations for animation callback objects
-- (actually this has been in here for quite some time, but was not used appearantly)
-- add a linear list to TableFormatlist[#animationStatusCallBack] with callback objects with the following properties:
-- #calltime => #float => percent done of animation ; required ; so in order to receive an event at 50% of the animation specify 0.5 for #calltime
-- #callHandler => #symbol ; required ; handler to be called in callback object
-- #callback => #object ; required ; object the event #callHandler is sent to
-- #params => any type ; optional ; optional paremeters


---------------------------------
-- Scriptmarker (17.09.2008 at 14:25 Uhr): changes alex  // Scriptmarker
-- added new public handler to temporarely disable/enable the table => mEnableTable. It has three modi:
-- -- 0 => disabled
-- -- 1 => enabled
-- -- 2 => only user interaction disabled, but still script interaction working

---------------------------------
-- Scriptmarker (16.10.2008): changes alex  // Scriptmarker
-- added handler "mGetOverallScrollDistance" to get the distance in pixels, which is hidden and can be scrolled
-- this is the difference between the width/height of the entire table and the width/height of the visible area

-- added handler "mGetOverallTableRect" to get the overall rect of the table including the parts, which are not visible


---------------------------------
-- Scriptmarker (27.10.2008 at 11:40 Uhr): changes alex // Scriptmarker

-- added support for ease settings using EasingTweenPS
-- changed the easeMode to use my script "EasingTweenPS" to do the easing, as long as it is present.
-- if it isn't it falls back to the old version of easing
-- #animationDynamic can now be a value, which script "EasingTweenPS" "understands" and
-- there can now be additional #easeParam1 and #easeParam2 parameters


---------------------------------
-- Scriptmarker (31.10.2008 um 8:57 Uhr): changes alex  // Scriptmarker
-- added new function: mSetAutoHide
-- enable, disable or change the autohide value after the tablke was created
-- takes an integer as parameter:
--       0 or void means "disable autohide function"
--       negativ values mean "there is no timeout, but a click outside the table dismisses it"
--       other values are the time in milliseconds without interaction until the table is automatically dismissed

---------------------------------
-- Scriptmarker: changes alex (18.09.2009 at 10:00 Uhr) // Scriptmarker
-- added handler mChangeTableBackGroundImage to change the background image of a showing table. (experimental, I'd rather suggest to build a new table, which is much safer)


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx PROPERTIES
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

property pKanal, pMember
property pOldKeyDown
property pMyScriptObject
property pAktiv
property pDreiDModus

property pSuspendMouseEvents

-- 2-D properties:
property pSavedMember, pSavedRect
--
property pSubmenuHandling -- How do we handle submenus in 2-D ?
-- there are 3 options:
-- 1.) display them in another sprite, which can
-- -- a.) be predefined with a dummy sprite for each possible submenu -> submenu depth
-- -- b.) allocated at runtime into any empty sprite (but since dynamically allocated sprites may cause problems, I vote for a.))
-- 2.) extending this sprites image to display all submenus in one big image with alpha
-- 3.) draw to the stage directly without the need of a sprite (I don't know why, but I try to avoid this option after all the mouseevent handling is much more difficult)


-- 3-D properties:
property pTableList, pTextureBaseName

property pAnimationList

-- stopevent for enterframe-ish rollover test :-(
-- needed for eventhandling of menus, which cover each others
property pStopOverEvent


property pWoody -- flag for new timeout syntax in woody

-- Scriptmarker (04.11.2005 at 10:48 Uhr): Alex da Franca: Change // Scriptmarker
-- define via gpdl the "available" stage area -> it only applies if the table is set to "forceToStage" -> default
-- this property is sunstracted form the stage.rect => (the stage).rect.inflate(-pStageRectMargin, -pStageRectMargin)
property pStageRectMargin

property pSeeThru

property pPowerOfTwoList


property pDontReplaceMember

property pTweenScript


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____INTERFACE
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- on handler me
--end

-- on handlers me
--end

on interface me
  str = "TableManager Script  by alex da franca c2003 -- alex@farbflash.de -- all rigths reserved"
  put RETURN & "version 3.0" after str
  put RETURN & "Please refer to the docs for information on the usage" after str
  put RETURN & "--------------------------------------------------------" after str
  put RETURN & "--------------------------------------------------------" after str
  
  put RETURN after str
  
  put RETURN & "----- invoke the table by calling the handler mShowTable" after str
  put " <itemlist> and <tableformatlist> specify the values and properties of the table. these lists can be composed on the fly" after str
  put " or the values can be stored in a container (see my script 'sampleTableList' for details)" after str
  
  
  put RETURN & "----- if you want to compose the table only without to show it right away => prepare or preprocess it, then set the onlyPrepare flag" after str
  put " since it can take some time to compose huge tables, especially if the text must be renderend, instead of images" after str
  put " or if you need to know the dimension of the table in case of setting  the #adjustToFit property to #none" after str
  put " (which may change the dimension of the displayrect according to the contents), before displaying the table" after str
  
  put RETURN & "----- optional you can specify a callbackhandler to get an event as soon as the table is prepared," after str
  put " if left out, the mTablePrepared() handler of this script receives the event, which then can be changed by you" after str
  
  put RETURN & "----- if you have specified a callbackhandler you can also specify an instance which receives the call" after str
  put " if left out, the callbackhandler is called on moviescript level with 'do'" after str
  put " so if you specify a custom callbackhandler without callbackInstance, make sure the handler does exist to avoid script errors" after str
  put " as soon as callbackInstance is specified, a missing callBackHandler won't cause errors, but just fails silently" after str
  
  put RETURN & "on mShowTable object me, list_itemlist, list_tableformatlist, string_tabname, boolean_onlyPrepare, symbolOrString_callBackHandler, instance_callbackInstance, boolean_dontForceToStage" after str
  put RETURN & "------------------- RETURNS integer spritenum" after str
  
  put RETURN & " - display a table which was composed/prepared before with mShowTable() and the <onlyPrepare> flag set" after str
  put RETURN & "on mShowPreparedTable me, string_tabname" after str
  put RETURN & "on mHideTable me, string_tabname" after str
  put RETURN & "-- -- Hide the table" after str
  put RETURN & " mSuspendMouseEvents me, boolean_val, exception" after str
  put RETURN & " mSuspendMouseEvents2 me, val" after str
  put RETURN & "on mResetAutoHide me, string_tabname, object_senderTable" after str
  
  put RETURN after str
  put RETURN & " -- in 2-D mode we remove the dummy sprite from the stage" after str
  put RETURN & " -- sometimes it is nice to be able to define the rect via the sprite rect" after str
  put RETURN & " -- so here the original can be looked up" after str
  put RETURN & "on mGetOriginalSpriteRect me" after str
  put RETURN after str
  
  put RETURN after str
  put RETURN & " -- set property pSeeThru to handle mouseOver events even, when another sprite is obscuring the table" after str
  put RETURN & " -- the default is false, as the default should be to NOT receive the events if something other is over the table" after str
  put RETURN & "on mSetSeeThru me, boolean_val" after str
  put RETURN after str
  
  
  put RETURN & "on mGetScriptObject me, string_tabname" after str
  put RETURN & "on mSetCellContent me, integer_row, integer_column, stringORimage_newVal, booelan_relativ, boolean_recalc, string_tabname" after str
  put RETURN & "on mGetCellContent me, integer_row, integer_column, string_tabname" after str
  put RETURN & "on mGetCellByName me, string_aName, string_tabname" after str
  put RETURN & "on mGetCurrentSelection me, string_tabname" after str
  put RETURN & "on mAXTable_GetCurrentRadioGroupSelection me, groupname, tabname" after str
  put RETURN & "on mGetLineByIndex me, integer_lineNum, string_tabname" after str
  put RETURN & "on mSetSelection me, list_newSelection, string_tabname" after str
  put RETURN & "on mDeSelectSingleCell me, proplist_whichCell, string_tabname" after str
  put RETURN & "on mSelectCell me, proplist_whichCell, integer_scrollToTop, string_tabname, symbol_whichModifier" after str
  put RETURN & " - values for 'scrolltop' are: 0 = dont scroll, 1 = scroll only vertical to top or bottom, 2 = scroll only horizontal to left or right, 3 = scroll vertical AND horizontal to top or bottom and left opr right" after str
  put RETURN & " - 4 = scroll only vertical to centerV, 5 = scroll only horizontal to centerH, 6 = scroll vertical AND horizontal to center" after str
  put RETURN & " - <whichModifier> to mimic shift select. can be: #commandselect or #shiftselect or <void> (any other value)" after str
  put RETURN & " - (note that multiple selection must be enabled, which can be enabled temporarely also -> mGetScriptObject(me).pTableformatlist.setaprop(#multipleSelection, <1 or 2>))" after str
  put RETURN & "on mHighLightCell me, proplist_whichCell, string_tabname" after str
  put RETURN & "on mEnableCell me, proplist_whichCell, booelan_enabledState, string_tabname" after str
  put RETURN & "on mGetCellByIndex me, list_indexList, string_tabname" after str
  put RETURN & "on mGetCurrentPrintListe me, string_tabname" after str
  put RETURN & "on mGetCurrentRect me, string_tabname, boolean_withoutShadow" after str
  put RETURN & "on mGetCurrentTargRect me, string_tabname" after str
  put RETURN & "on mSetCurrentRect me, rect_newRect, string_tabname, boolean_relativ, boolean_forceUpdate" after str
  put RETURN & "on mMoveTable me, point_delta, string_tabname" after str
  put RETURN & "on mReverse me, boolean_sortOrder, string_tabname" after str
  put RETURN & "on mChangeSortBy me, integer_column, string_tabname" after str
  put RETURN & "on mFilterColumn me, list_filterListe, string_tabname" after str
  put RETURN & "on mChangeScrollOffset me, point_relVal, string_tabname" after str
  put RETURN & "on mSetScrollOffset me, point_absVal, string_tabname" after str
  put RETURN & "on mGetCurrentViewList me, string_tabname" after str
  put RETURN & "-- -- -- tab delimted text of current view" after str
  put RETURN & "on mInsertRow me, list_newValueList, integer_posIndex, string_tabname" after str
  put RETURN & "on mDeleteRow me, integer_posIndex, integer_toPos, boolean_relativ, string_tabname" after str
  put RETURN & "on mInsertCol me, integer_posIndex, list_colList, list_newValueList, string_tabname" after str
  put RETURN & "on mDeleteCol me, integer_whichCol, string_tabname" after str
  put RETURN & "on mChangeColumnWidth me, integer_col, integer_neuebreite, string_tabname, boolean_dontUpdate" after str
  put RETURN & "on mChangeColumnPosition me, integer_fromPos, integer_toPos, string_tabname" after str
  put RETURN & "on mGetCurrentLinesList me, string_tabname" after str
  put RETURN & "on mGetCurrentColumnWidths me, string_tabname" after str
  put RETURN & "on mConvertToConstrained me, integer_absLine, string_tabname" after str
  put RETURN & "on mMapPointToStage me, integer_thePoint, string_tabname" after str
  put RETURN & " -- -- translate local coords to absolute coords" after str
  put RETURN & " _____INCOMING_EVENTS_FROM_TABLESCRIPT" after str
  put RETURN & " mTableCellHighLightEvent me, targrect, whichMode, string_tabname, callerRef, whichcell" after str
  put RETURN & " mTableBlur me, targrect, whichMode, string_tabname, callerRef, whichcell" after str
  put RETURN & " mDeselectTableCell me, whichMode, string_tabname, replaced, callerRef, whichcell" after str
  put RETURN & " mCharAddEvent me, cellRef, caller, string_tabname" after str
  put RETURN & " mTableScrollEvent me, newScrollOffset, relativ, string_tabname, caller" after str
  put RETURN & " mSendColResize me, whichColumn, string_tabname, caller" after str
  put RETURN & " mSendColDrag me, whichColumn, allowDelete, string_tabname, caller" after str
  put RETURN & " mSendColChange me, oldPos, newPos, string_tabname, caller" after str
  put RETURN & " mTableFinishEvent me, string_tabname, caller" after str
  put RETURN & " mSendResizeEvent me, lastrect, newRect, string_tabname, caller" after str
  put RETURN & " mRefreshSpriteRectAfterStageChange me, newSpriteRect, recentrect" after str
  
  
  return str
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____EVENTS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on beginsprite me
  mInitProperties me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on new me
  return me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mInitProperties me, pipeline
  
  -- alex am Donnerstag, 13. Mai 2004
  if not voidP(pKanal) then exit
  --/ alex am Donnerstag, 13. Mai 2004
  
  pSeeThru = 0
  
  if voidP(pipeline) then
    pKanal = sprite(me.spritenum)
  else
    pKanal = 0
  end if
  
  pAnimationList = []
  
  --  if mGetKanal(#tablekanal) < 1 then mMeldeKanalname(#tablekanal, me.spritenum)
  
  pStopOverEvent = 0
  
  pSuspendMouseEvents = 0
  
  pTextureBaseName = mGetTexname(me)
  
  if voidP(pipeline) then
    if pKanal.member.type = #shockwave3d then -- 3-D mode
      pDreiDModus = 1
      
      pMember = pKanal.member
      
      pSubmenuHandling = #dreiD
      
    else
      
      pSubmenuHandling = #seperateSprites
      
      pSavedMember = pKanal.member
      pSavedRect = pKanal.rect
      
      if pDontReplaceMember then
        pMember = pSavedMember
      else
        -- alex am 8. Oktober 2004 um 10:32
        --      pMember = new(#bitmap)
        pMember = call(#mGetNewMember, mGetXScript(), #bitmap)
        --/ alex am 8. Oktober 2004 um 10:32
      end if
      
      pKanal.member = pMember
      pKanal.locV = -1000
    end if
    
  else
    
    pDreiDModus = 0
    
    pMember = pipeline
    
    pSubmenuHandling = #dreiD
    
  end if
  
  pTableList = [:]
  pAktiv = 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mStopMovieWasCalled me
  if the runmode <> #author then pAktiv = 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on endsprite me
  
  --  if mGetKanal(#tablekanal) = me.spritenum then mMeldeAbKanalname(#tablekanal, me.spritenum)
  
  -- first kill hide animations if there are any -- the hard way
  repeat with n = pAnimationList.count down to 1
    -- alex am Mittwoch, 2. Juni 2004
    thisAnim = pAnimationList[n].getaprop(#myAnimation)
    --/ alex am Mittwoch, 2. Juni 2004
    if thisAnim.getaprop(#animationType) = #dissappear then
      
      if thisAnim.getaprop(#dreiDmode) = 1 or pAnimationList[n].getaprop(#dreiDmode) = 1 then
        moname = string(pAnimationList[n].getaprop(#useModel))
        if moname.length then
          mRemove3DModel me, moname, pAnimationList[n]
        else
          mRemove3DOverlay me, pAnimationList[n].getaprop(#myName), pAnimationList[n].getaprop(#myCamera)
        end if
        
        if (count(pTableList) < 1) then
          if pKanal <> 0 then sendSprite(me.spritenum, #mRemoveFromEventList, me)
        end if
        
      else
        
        if ilk(pMember) = #instance then
          call(#mRemoveTableFromScreen, [pMember], pAnimationList[n].getaprop(#myName))
          
        else if thisAnim.getaprop(#removeAll) or (count(pTableList) < 1) then
          
          if pKanal <> 0 then
            pKanal.locV = -1000
            pKanal.blend = 100
          end if
          
          -- release the memory for the #bitmap:
          if ilk(pMember) = #member then
            if pMember.type = #bitmap then
              pMember.image = image(1,1,1)
            end if
          end if
          
        end if
        
      end if
      
      
      pAnimationList.deleteAt(n)
    end if
  end repeat
  pAnimationList = []
  --/ hide animations
  
  (the actorlist).deleteOne(me)
  
  -- ullala changed for Woody - to 
  if ilk(timeOut(pTextureBaseName&"_cleanup")) = #timeout then timeout(pTextureBaseName&"_cleanup").forget()
  -- ullala changed for woody - to end --
  
  if not voidP(pOldKeyDown) then the keyDownscript = pOldKeyDown
  
  if pDreiDModus then
    
    repeat with n = pTableList.count down to 1
      
      if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#mDestroy, pTableList[n].getaprop(#myScriptObject))
      
      if pAktiv <> 0 then
        camObj = pTableList[n].getaprop(#myCamera)
        if voidP(camObj) then camObj = pKanal.camera
        tex = pMember.texture(pTextureBaseName&"_"&pTableList[n].getaprop(#myName))
        olayIndex = mGetOlayIndex(me, camObj, tex)
        if olayIndex > 0 then
          camObj.removeoverlay(olayIndex)
          pMember.deleteTexture(tex.name)
        end if
      end if
      
    end repeat
    
    sendSprite(me.spritenum, #mRemoveFromEventList, me)
    
  else
    
    repeat with n = pTableList.count down to 1
      if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#mDestroy, pTableList[n].getaprop(#myScriptObject))
    end repeat
    
    if pKanal <> 0 then
      
      if pSavedMember <> pMember then
        pKanal.member = pSavedMember
        pKanal.rect = pSavedRect
        
        -- alex am 8. Oktober 2004 um 10:32
        --      pMember.erase()
        call(#mEraseMember, mGetXScript(), pMember)
        -- alex am 8. Oktober 2004 um 10:32
        
      end if
      
    end if
    
  end if
  
  pTableList = [:]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mouseDown me
  if pDreiDModus or (pKanal = 0) then
    pass
    exit
  end if
  
  if not pAktiv then exit
  
  if pSuspendMouseEvents then exit
  
  sendAllSprites(#mResetKeyDownScript)
  
  ml = the clickloc
  
  if (pTableList.count > 1) and (pSubmenuHandling = #singleSprite) then
    repeat with n = pTableList.count down to 1
      theRect = pTableList[n].getaprop(#myRect)
      if ilk(theRect) = #rect then
        if (ml).inside(theRect) then
          
          if  the keyDownscript <> "sendSprite("&me.spritenum&", #myKeyDown, the key, the keycode, "&QUOTE&pTableList[n].getaprop(#myName)&QUOTE&")" then
            pOldKeyDown = the keyDownscript
          end if
          the keyDownscript = "sendSprite("&me.spritenum&", #myKeyDown, the key, the keycode, "&QUOTE&pTableList[n].getaprop(#myName)&QUOTE&")"
          
          if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#myMouseDown, pTableList[n].getaprop(#myScriptObject), ml)
          exit repeat
        end if
      end if
    end repeat
    
  else
    
    if the keyDownscript <> "sendSprite("&me.spritenum&", #myKeyDown, the key, the keycode)" then
      pOldKeyDown = the keyDownscript
    end if
    the keyDownscript = "sendSprite("&me.spritenum&", #myKeyDown, the key, the keycode)"
    
    if ilk(pTableList[1].getaprop(#myScriptObject)) = #instance then call(#myMouseDown, pTableList[1].getaprop(#myScriptObject), ml)
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mouseUp me
  if pDreiDModus or (pKanal = 0) then
    pass
    exit
  end if
  
  if not pAktiv then exit
  if pSuspendMouseEvents then exit
  
  ml = the mouseloc
  
  if (pTableList.count > 1) and (pSubmenuHandling = #singleSprite) then
    repeat with n = pTableList.count down to 1
      theRect = pTableList[n].getaprop(#myRect)
      if ilk(theRect) = #rect then
        if (ml).inside(theRect) then
          if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#myMouseUp, pTableList[n].getaprop(#myScriptObject), ml)
          exit repeat
        end if
      end if
    end repeat
    
  else
    
    -- mouseUp after a 'repeat while the mousedown' loop is called even if a mouseUpOutside would be appropriate ?!
    
    theRect = pTableList[1].getaprop(#myRect)
    if ilk(theRect) = #rect then
      if (ml).inside(theRect) then
        if ilk(pTableList[1].getaprop(#myScriptObject)) = #instance then
          call(#myMouseUp, pTableList[1].getaprop(#myScriptObject), ml)
        end if
      else
        if ilk(pTableList[1].getaprop(#myScriptObject)) = #instance then call(#myMouseUpOutside, pTableList[1].getaprop(#myScriptObject))
      end if
    end if
    
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mouseUpOutside me
  if pDreiDModus or (pKanal = 0) then
    pass
    exit
  end if
  
  if not pAktiv then exit
  if pSuspendMouseEvents then exit
  
  if (pTableList.count > 1) and (pSubmenuHandling = #singleSprite) then
    repeat with n = pTableList.count down to 1
      if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#myMouseUpOutside, pTableList[n].getaprop(#myScriptObject))
    end repeat
    
  else
    
    if ilk(pTableList[1].getaprop(#myScriptObject)) = #instance then call(#myMouseUpOutside, pTableList[1].getaprop(#myScriptObject))
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on rightMouseUp me
  if pDreiDModus or (pKanal = 0) then
    pass
    exit
  end if
  
  if not pAktiv then exit
  if pSuspendMouseEvents then exit
  
  ml = the mouseloc
  
  if (pTableList.count > 1) and (pSubmenuHandling = #singleSprite) then
    repeat with n = pTableList.count down to 1
      theRect = pTableList[n].getaprop(#myRect)
      if ilk(theRect) = #rect then
        if (ml).inside(theRect) then
          if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#myMouseUp, pTableList[n].getaprop(#myScriptObject), ml, 1)
          exit repeat
        end if
      end if
    end repeat
    
  else
    
    if ilk(pTableList[1].getaprop(#myScriptObject)) = #instance then call(#myMouseUp, pTableList[1].getaprop(#myScriptObject), ml, 1)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


-- used for mouseOver/enter/leave tracking, if necessary -> pSuspendMouseEvents <> 1
on enterframe me
  if pKanal <> 0 then mMyEnterFrame me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMyEnterFrame me, cl
  if pSuspendMouseEvents then exit
  
  if not pStopOverEvent then
    repeat with n = pTableList.count down to 1
      scr = pTableList[n].getaprop(#myScriptObject)
      if ilk(scr) = #instance then
        if ilk(cl) <> #point then ml = mGetAbsolutMouse(me, scr, 0, pTableList.getPropAt(n))
        else ml = cl
        
        
        if (pSubmenuHandling = #seperateSprites) and (pKanal <> 0) then
          if pSeeThru then
            erg = rollover(me.spritenum)
          else
            erg = (the rollover = me.spritenum)
          end if
        else
          erg = 1
        end if
        if erg = 1 then erg = call(#mMausOver, scr, ml)
        else erg = call(#mMausOver, scr, ml, 1) -- with <forceOut> set to true, just to handle mouseLeave events in the object
        
        if listP(erg) then
          
          if pSubmenuHandling = #seperateSprites then
            sendAllSprites(#mStopEvent, erg)
            pStopOverEvent = 0
          else
            
            if count(erg) > 1 then
              dername = erg[2]
              table = pTableList.getaprop(dername)
              if objectP(table) then
                scr = table.getaprop(#myScriptObject)
                if ilk(scr) = #instance then
                  if ilk(cl) <> #point then ml = mGetAbsolutMouse(me, scr, 0, dername)
                  else ml = cl
                  erg = call(#mMausOver, scr, ml)
                end if
              end if
            end if
            
          end if
          
          exit repeat
        else
          if erg > 0 then
            if pSubmenuHandling = #seperateSprites then
              sendAllSprites(#mStopEvent, erg)
              pStopOverEvent = 0
            end if
            
            exit repeat
          end if
        end if
        
      end if
      
      if pTableList[n].getaprop(#isModal) then exit
      
    end repeat
  else
    pStopOverEvent = 0
  end if
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mStopEvent me, ausnahme
  
  if listP(ausnahme) then
    if count(ausnahme) > 1 then ausnahme = ausnahme[1]
  end if
  
  if pKanal <> 0 then sprnum = me.spritenum
  else sprnum = 0
  
  if sprnum <> ausnahme then
    pStopOverEvent = 1
  else
    repeat with n = pTableList.count down to 1
      scr = pTableList[n].getaprop(#myScriptObject)
      if ilk(scr) = #instance then
        ml = mGetAbsolutMouse(me, scr, 0, pTableList.getPropAt(n))
        erg = call(#mMausOver, scr, ml)
        -- alex am Mittwoch, 2. Juni 2004
        if listP(erg) then exit repeat
        --/ alex am Mittwoch, 2. Juni 2004
        if erg > 0 then
          exit repeat
        end if
      end if
    end repeat
    pStopOverEvent = 1
    --    put "ausnahme" && ausnahme
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- used for the animation on show or hide
on stepframe me
  if not pAnimationList.count then (the actorlist).deleteOne(me)
  
  repeat with n = pAnimationList.count down to 1
    if pAnimationList[n].getaprop(#myAnimation).getaprop(#animationType) = #dissappear then mProcessHideAnimation me, pAnimationList[n]
    else mProcessAnimation me, pAnimationList[n]
  end repeat
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on getPropertyDescriptionList
  
  retliste = [:]
  
  retliste[#pStageRectMargin] = [#format:#integer, #default:0, comment:"Margin for visible stage area"]
  retliste[#pDontReplaceMember] = [#format:#boolean, #default:0, comment:"Keep image (each sprite has own member)"]
  
  return retliste
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____PUBIC_HANDLERS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Invoke the table    (STARTING POINT)
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- invoke the table by calling the following handler:
-- <itemlist> and <tableformatlist> specify the values and properties of the table. these lists can be composed on the fly
-- or the values can be stored in a container (see my script "sampleTableList" for details)


-- if you want to compose the table only without to show it right away => prepare or preprocess it, then set the onlyPrepare flag
-- since it can take some time to compose huge tables, especially if the text must be renderend, instead of images
-- or if you need to know the dimension of the table in case of setting  the #adjustToFit property to #none
-- (which may change the dimension of the displayrect according to the contents), before displaying the table

-- optional you can specify a callbackhandler to get an event as soon as the table is prepared,
-- if left out, the mTablePrepared() handler of this script receives the event, which then can be changed by you

-- if you have specified a callbackhandler you can also specify an instance which receives the call
-- if left out, the callbackhandler is called on moviescript level with 'do'
-- so if you specify a custom callbackhandler without callbackInstance, make sure the handler does exist to avoid script errors
-- as soon as callbackInstance is specified, a missing callBackHandler won't cause errors, but just fails silently


on mShowTable me, itemlist, tableformatlist, tabname, onlyPrepare, callBackHandler, callbackInstance, dontForceToStage, isModal, instantRender
  
  if voidP(pKanal) then mInitProperties me
  
  if ilk(tableformatlist) <> #proplist then
    put "Script: TableManager ; Handler: mShowTable ; WARNING: Something is wrong here: tableformatlist is not a property list"
    exit
  end if
  
  targrect = tableformatlist.getaprop(#targrect)
  if ilk(targrect) <> #rect then
    put "Script: TableManager ; Handler: mShowTable ; WARNING: Something is wrong here: tableformatlist.targrect is not a rect"
    exit
  end if
  if targrect.width < 1 then
    put "Script: TableManager ; Handler: mShowTable ; WARNING: Something is wrong here: tableformatlist.targrect.width < 1"
    exit
  end if
  if targrect.height < 1 then
    put "Script: TableManager ; Handler: mShowTable ; WARNING: Something is wrong here: tableformatlist.targrect.height < 1"
    exit
  end if
  
  
  -- first kill hide animations if there are any -- the hard way
  repeat with n = pAnimationList.count down to 1
    -- alex am Mittwoch, 2. Juni 2004
    thisAnim = pAnimationList[n].getaprop(#myAnimation)
    
    if thisAnim.getaprop(#animationType) = #dissappear then
      
      if thisAnim.getaprop(#dreiDmode) = 1 or pAnimationList[n].getaprop(#dreiDmode) = 1 then
        moname = string(pAnimationList[n].getaprop(#useModel))
        if moname.length then
          mRemove3DModel me, moname, pAnimationList[n]
        else
          mRemove3DOverlay me, pAnimationList[n].getaprop(#myName), pAnimationList[n].getaprop(#myCamera)
        end if
        
        if (count(pTableList) < 1) then
          if pKanal <> 0 then sendSprite(me.spritenum, #mRemoveFromEventList, me)
        end if
        
      else
        
        if ilk(pMember) = #instance then
          call(#mRemoveTableFromScreen, [pMember], pAnimationList[n].getaprop(#myName))
          
          --/ alex am Mittwoch, 2. Juni 2004
          
        else if thisAnim.getaprop(#removeAll) or (count(pTableList) < 1) then
          if pKanal <> 0 then
            pKanal.locV = -1000
            pKanal.blend = 100
          end if
          
          -- release the memory for the #bitmap:
          if ilk(pMember) = #member then
            if pMember.type = #bitmap then
              pMember.image = image(1,1,1)
            end if
          end if
          
        end if
        
      end if
      
      callback = pAnimationList[n].getaprop(#callbackinstance)
      if ilk(callback) = #instance then call(#mRemoveTableFromScreen, [callback], pAnimationList[n].getaprop(#myName))
      
      pAnimationList.deleteAt(n)
    end if
  end repeat
  --/ hide animations
  
  
  if voidP(tabname) then -- Sonderfall: ohne name loescht ALLE vorherigen tabellen
    tabname = "tabelle1"
    ind = 1
    
    --    if pDreiDModus then camObj = pKanal.camera
    
    repeat with n = pTableList.count down to 2
      if ilk(pTableList[n].getaprop(#myScriptObject)) = #instance then call(#mDismissTable, pTableList[n].getaprop(#myScriptObject))
      
      if pDreiDModus then
        
        tex = pMember.texture(pTextureBaseName&"_"&pTableList[n].getaprop(#myName))
        moname = string(pTableList[n].getaprop(#useModel))
        if moname = "" then
          
          camObj = pTableList[n].getaprop(#myCamera)
          if voidP(camObj) then camObj = pKanal.camera
          
          olayIndex = mGetOlayIndex(me, camObj, tex)
          if olayIndex > 0 then
            camObj.removeoverlay(olayIndex)
            pMember.deleteTexture(tex.name)
          end if
          
        else
          
          theModel = pMember.model(moname)
          if not voidP(theModel) then
            if not voidP(tex) then
              repeat with m = theModel.shaderlist.count down to 1
                if theModel.shaderlist[m].texture = tex then pMember.deleteShader(theModel.shaderlist[m].name)
              end repeat
              pMember.deleteTexture(tex.name)
            end if
            if theModel.name = pTextureBaseName&"_"&pTableList[n].getaprop(#myName) then pMember.deleteModel(theModel.name)
          end if
        end if
        
      end if
      
    end repeat
    
  else
    if (pSubmenuHandling = #seperateSprites) and (pAktiv = 1) and (voidP(pTableList.getaprop(tabname))) then
      letzter = the lastchannel
      repeat with spr = (me.spritenum + 1) to letzter
        erg = sendSprite(spr, #mShowTable, itemlist, tableformatlist, tabname, onlyPrepare, callBackHandler, callbackInstance, dontForceToStage, isModal, instantRender)
        if not voidP(erg) then return erg
      end repeat
      return 0
      
    end if
    
  end if
  
  --  if count(pTableList) < 1 then
  if pDreiDModus then
    moname = string(tableformatlist.getaprop(#useModel))
    if length(moname) < 1 then
      sendSprite(me.spritenum, #mAddToEventList, me, 1)
    else
      
      theModel = pMember.model(moname)
      if not voidP(theModel) then sendSprite(me.spritenum, #mEventRouter_AddToRollOverList, theModel)
      
    end if
  else
    tableformatlist.setaprop(#useModel, "")
  end if
  --  end if
  
  thisTable = pTableList.getaprop(tabname)
  if ilk(thisTable) <> #proplist and ilk(thisTable) <> #instance then
    thisTable = [:]
    pTableList.setaprop(tabname, thisTable)
  end if
  
  if not objectP(thisTable.getaprop(#myScriptObject)) then
    
    tscr = mGetXScript(#DrawTableParent)
    if not(listP(tscr)) then
      if ilk(tscr) = #instance then tscr = tscr.script
      tscr =  new(tscr)
    end if
    
    thisTable[#myScriptObject] = tscr
  end if
  
  
  if ilk(thisTable.getaprop(#myScriptObject)) <> #instance then
    -- we did not succed in initializing a table parent script (only fails if the LDM tableScripts.dcr isn't present at this time in the score))
    put "Unable to create required scriptobject (DrawTableParent). Make sure the LDM tableScripts.dcr is present as sprite in the score"
    return 0
  end if
  
  
  thisTable[#myRect] = 0
  thisTable[#myName] = tabname
  thisTable[#readyToGo] = 0
  thisTable[#myImg] = 0
  thisTable[#deletionMark] = 0
  
  if onlyPrepare then
    thisTable[#prepareFlag] = 1
    
    thisTable[#callBackHandler] = callBackHandler
    
    if voidP(callbackInstance) then callbackInstance = #moviescript
    thisTable[#callbackInstance] = callbackInstance
    
  else
    if ilk(callbackInstance) = #instance then thisTable[#callbackInstance] = callbackInstance
    thisTable[#prepareFlag] = 0
  end if
  
  
  val = string(tableformatlist.getaprop(#useModel))
  thisTable.setaprop(#useModel, val)
  thisTable.setaprop(#isModal, isModal)
  
  if pDreiDModus then
    
    texrenderformat = tableformatlist.getaprop(#texrenderformat)
    if not voidP(texrenderformat) then thisTable[#texrenderformat] = texrenderformat
    
    mo = pMember.model(val)
    if not(voidP(mo)) then
      
      thisTable.setaprop(#shaderListIndex, tableformatlist.getaprop(#shaderListIndex))
      thisTable.setaprop(#textureListIndex, tableformatlist.getaprop(#textureListIndex))
      thisTable.setaprop(#textureblendfunction, tableformatlist.getaprop(#textureblendfunction))
      thisTable.setaprop(#blendsourcelist, tableformatlist.getaprop(#blendsourcelist))
      
      
      scrili = xscr().mGetParentScriptList(mo)
      if scrili.getPos(me) < 1 then scrili.add(me)
      
      
    else
      thisTable.setaprop(#useModel, "")
      tableformatlist.setaprop(#useModel, "")
      
      myCamera = tableformatlist.getaprop(#overlayCameraObject)
      
      if stringP(myCamera) then
        myCamera = pKanal.member.camera(myCamera)
      end if
      if voidP(myCamera) then myCamera = pKanal.camera
      if not voidP(myCamera) then thisTable[#myCamera] = myCamera
      
    end if
    
    
    -- if we are in 3-D mode, we don't want to exceed 504 pixels:
    r = tableformatlist.getaprop(#targrect)
    if ilk(r) = #rect then
      if tableformatlist.getaprop(#shadowStyle) = #shadow then
        shdow = (tableformatlist[#shadowDistance] + tableformatlist[#shadowBlur]) * 2
      else
        shdow = 0
      end if
      
      maxW = mGetNextPowerOfTwo(me, the maxinteger) - shdow
      animstyle = tableformatlist.getaprop(#animationStyle)
      if r.width > maxW then
        case animstyle of
          #wipeRL, #pushRL, #scaleRL, #scaleRT, #scaleRB:
            tableformatlist.setaprop(#targrect, rect(r.right-maxW, r.top, r.right, r.bottom))
          otherwise
            tableformatlist.setaprop(#targrect, rect(r.left, r.top, r.left + maxW, r.bottom))
        end case
        
      end if
      
      r = tableformatlist.getaprop(#targrect)
      if r.height > maxW then
        case animstyle of
          #wipeBT, #pushBT, #scaleBT, #scaleLB, #scaleRB, #zoomBT:
            tableformatlist.setaprop(#targrect, rect(r.left, r.bottom-maxW, r.right, r.bottom))
          otherwise
            tableformatlist.setaprop(#targrect, rect(r.left, r.top, r.right, r.top+maxW))
        end case
      end if
      
    end if
    
    
  end if
  
  
  -- setup animation properties:
  doAnim = 0
  animList = [:]
  
  animationTime = tableformatlist.getaprop(#animationTime)
  if ilk(animationTime) <> #integer then animationTime = 300
  
  if animationTime > 0 then
    
    animationStyle = tableformatlist.getaprop(#animationStyle)
    if ilk(animationStyle) = #symbol then
      if [#incremental, #threadRendering, #threadRenderingDeep, #none].getPos(animationStyle) < 1 then
        animList[#animationStyle] = animationStyle
        
        animList[#animationTime] = animationTime
        
        animList[#animationDynamic] = tableformatlist.getaprop(#animationDynamic)
        animList[#easeParam1] = tableformatlist.getaprop(#easeParam1)
        animList[#easeParam2] = tableformatlist.getaprop(#easeParam2)
        animList[#animationOnHide] = tableformatlist.getaprop(#animationOnHide)
        
        if animationStyle = #transition then
          val = tableformatlist.getaprop(#startpoint)
          if ilk(val) = #point then animList[#startwert] = val
          else animList[#startwert] = #linksoben
        end if
        
        doAnim = 1
      end if
    end if
    
    theFadeIn = tableformatlist.getaprop(#fadeIn)
    if listP(theFadeIn) then
      if theFadeIn.count > 1 then
        animList[#startBlend] = min(100, max(0, theFadeIn[1]))
        animList[#fullBlend] = min(100, max(0, theFadeIn[2]))
        
        if not doAnim then
          animList[#animationTime] = animationTime
        end if
        
        doAnim = 1
      end if
    end if
    
    theFadeOut = tableformatlist.getaprop(#fadeOut)
    if ilk(theFadeOut) = #integer then
      if theFadeOut >= 0 then animList[#endBlend] = min(100, max(0, theFadeOut))
      
      if not doAnim then
        animList[#animationTime] = animationTime
      end if
      
    end if
    
  end if
  
  if animList.count then
    animationStatusCallBack = tableformatlist.getaprop(#animationStatusCallBack)
    if listP(animationStatusCallBack) then
      tableformatlist.deleteProp(#animationStatusCallBack)
      animList[#callList] = animationStatusCallBack
    end if
    
    thisTable[#myAnimation] = animList
  end if
  
  --    if doAnim then onlyPrepare = 1
  
  --/animation
  
  pAktiv = 1
  
  if not dontForceToStage then 
    sr = mGetStageBoundRect(me, string(tableformatlist.getaprop(#useModel)))
    tr = tableformatlist.getaprop(#targrect)
    if ilk(tr) = #rect then
      
      offsH = sr.right - tr.right
      if offsH > 0 then
        offsH = max(0, (sr.left - tr.left))
      end if
      
      offsV = (sr.bottom - tr.top)
      if offsV > 0 then
        offsV = max(0, (sr.top - tr.top))
      end if
      
      if ((offsH <> 0) or (offsV <> 0)) then tableformatlist[#targrect] = tableformatlist.targrect.offset(offsH, offsV)
      tableformatlist[#targrect][4] = min(tableformatlist[#targrect][4], sr.bottom)
    end if
  end if
  
  
  call(#mDisplayTable, thisTable.myScriptObject, itemlist, tableformatlist, me, onlyPrepare, tabname, instantRender)
  
  
  --  ---------------------------------
  --  -- Scriptmarker (15.04.2006 at 07:51 Uhr): changes alex // Scriptmarker
  --  pOldKeyDown = the keyDownscript
  --  if pKanal <> 0 then
  --    the keyDownscript = "sendSprite("&me.spritenum&", #myKeyDown, the key, the keycode, "&QUOTE&tabname&QUOTE&")"
  --  end if
  --  -- // changes  from 15.04.2006 at 07:51)
  --  ---------------------------------
  
  
  if pKanal <> 0 then return me.spritenum
  else return me
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- display a table which was composed/prepared before with mShowTable() and the <onlyPrepare> flag set

on mShowPreparedTable me, tabname
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  if table.getaprop(#prepareFlag) then
    table[#prepareFlag] = 0
    call(#mDisplayPreparedTable, table.getaprop(#myScriptObject))
    return 1
  end if
  
  return 0
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Hide the table
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHideTable me, tabname, instantHide
  if not listP(pTableList) then exit
  if count(pTableList) < 1 then exit
  
  tabname = string(tabname)
  theTable = pTableList.getaprop(tabname)
  
  if ilk(theTable) <> #proplist then
    if length(tabname) > 1 then exit
    theTable = pTableList[1]
    tabname = theTable.getaprop(#myName)
    removeAll = 1
  else
    removeAll = 0
  end if
  
  tblcnt = 0
  repeat with n = pTableList.count down to 1
    if (pTableList[n].count) and (pTableList[n].getaprop(#myName) <> tabname) then tblcnt = tblcnt + 1
  end repeat
  
  if removeAll or (tblcnt = 0) then
    removeAll = 1
  end if
  
  if not voidP(pOldKeyDown) then
    the keyDownscript = pOldKeyDown
    pOldKeyDown = void
  end if
  
  --end if
  
  pos = pAnimationList.getPos(theTable)
  if pos > 0 then pAnimationList.deleteAt(pos)
  
  
  ---------------------------------
  -- Scriptmarker: changes alex (25.08.2006 at 15:27 Uhr) // Scriptmarker
  
  if not(instantHide) then
    -- alex am Sonntag, 16. Mai 2004
    animation = theTable.getaprop(#myAnimation)
    if not voidP(animation) then
      if animation.getaprop(#animationOnHide) or (animation.getaprop(#endblend) > -1) then
        animation[#starttime] = the milliseconds
        animation[#animationType] = #dissappear
        --      animation[#endRect] = theRect
        
        -- alex am Mittwoch, 2. Juni 2004
        pAnimationList.add(theTable)
        --/ alex am Mittwoch, 2. Juni 2004
        
        if ((the actorlist).getPos(me) < 1) then (the actorlist).add(me)
        doAnim = 1
      end if
    end if
    --/ alex am Sonntag, 16. Mai 2004
  end if
  -- // changes  from 25.08.2006 at 15:27)
  ---------------------------------
  
  theTable[#deletionMark] = 1
  
  if ilk(theTable.getaprop(#myScriptObject)) = #instance then call(#mDismissTable, theTable.getaprop(#myScriptObject))
  
  if (tblcnt = 0) then pAktiv = 0
  
  if doAnim then
    
    if pDreiDModus then
      animation[#dreiDmode] = 1
      
      moname = string(theTable.getaprop(#useModel))
      
      if moname.length then
        animation[#useModel] = moname
      else
        animation[#myName] = theTable.getaprop(#myName)
      end if
      
    else -- 2-D mode
      animation[#removeAll] = removeAll
    end if
    
    callback = theTable.getaprop(#callbackInstance)
    if ilk(callback) = #instance then
      call(#mHideTableEvent, [callback], tabname)
    end if
    
  else -- no animation to dissapear
    
    if pDreiDModus then
      moname = string(theTable.getaprop(#useModel))
      
      if moname.length then
        
        mRemove3DModel me, moname, theTable
        
      else
        
        mRemove3DOverlay me, theTable.getaprop(#myName), theTable.getaprop(#myCamera)
        
      end if
      
      if (tblcnt = 0) then sendSprite(me.spritenum, #mRemoveFromEventList, me)
      
      callback = theTable.getaprop(#callbackInstance)
      if ilk(callback) = #instance then
        call(#mHideTableEvent, [callback], tabname)
        call(#mRemoveTableFromScreen, [callback], tabname)
      end if
      
    else
      if ilk(pMember) = #instance then
        
        callback = theTable.getaprop(#callbackInstance)
        if ilk(callback) = #instance then
          call(#mHideTableEvent, [callback], tabname)
        end if
        
        call(#mRemoveTableFromScreen, [pMember], theTable.getaprop(#myName))
        
      else if removeAll or (tblcnt = 0) then
        if pKanal <> 0 then
          pKanal.locV = -1000
          pKanal.blend = 100
        end if
        
        -- release the memory for the #bitmap:
        if ilk(pMember) = #member then
          if pMember.type = #bitmap then
            pMember.image = image(1,1,1)
          end if
        end if
        
        callback = theTable.getaprop(#callbackInstance)
        if ilk(callback) = #instance then
          call(#mHideTableEvent, [callback], tabname)
          call(#mRemoveTableFromScreen, [callback], tabname)
        end if
        
      end if
      
    end if
    
  end if
  
  
  if not voidP(pTableList.getaprop(tabname)) then
    
    --    if theTable[#deletionMark] = 1 then
    --      -- this is just a flag, as sometimes the end event of one table leads to create a new one instead with the same name
    --      -- that would mean, that we now deleted the newly created table
    --      pTableList.deleteprop(tabname)
    --    end if
    --    
    --    exit
    
    
    if theTable[#deletionMark] = 1 then
      pTableList.setaprop(tabname, [:]) -- don't remove it from within this event, it may be invoked by a chain of the same handler and may break a repeat loop
      -- (although I don't believe there are scenarios where this could happen, but one never knows...)
      -- instead put the removal into a seperate, indepandant event
      
    end if
    
    dto = mCreateTimeout(me, pTextureBaseName&"_cleanup", 10, #mRemoveEmptyListEntries, me)
    
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- this is on old handler which is left here for compatibility reasons for my own old movies
-- use mHideTable() instead
on mABoxVerschwinde me
  mHideTable me
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Public Handlers to change, control or get the table contents and properties
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSuspendMouseEvents me, val, exception
  
  if pKanal <> 0 then
    if me.spritenum = exception then exit
  end if
  
  
  pSuspendMouseEvents = val
  
  repeat with n = pTableList.count down to 1
    scr = pTableList[n].getaprop(#myScriptObject)
    if objectP(scr) then call(#mPauseTable, scr, not(val))
  end repeat
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSuspendMouseEvents2 me, val
  
  pSuspendMouseEvents = val
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- val => integer can be 0 => disable table, 1 => enable table or 2 => disable only user interaction

on mEnableTable me, val, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mEnableTable, scr, val)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mResetAutoHide me, tabname, senderTable
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then
    if scr <> senderTable then
      retval = call(#mResetAutoHide, scr)
    end if
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetAutoHide me, autoHideValue, tabname
  -----------------------------------
  -- CREATED: 31.10.2008
  -- ACTION:  enable, disable or change the autohide value after the table was created
  --          takes an integer as parameter:
  --            * 0 or void means "disable autohide function"
  --            * negativ values mean "there is no timeout, but a click outside the table dismisses it"
  --            * other values are the time in milliseconds without interaction until the table is automatically dismissed
  -- INPUT: <autoHideValue> ; integer ; time in milliseconds ; 0 => disable ; optional, if void then 0 is assumed
  --        <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: -
  -- EXAMPLE: sendSprite(xscr().mGetKanal(#tableSprite), #mSetAutoHide, 3000, "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mSetAutoHide, scr, autoHideValue)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- in 2-D mode we remove the dummy sprite from the stage
-- sometimes it is nice to be able to define the rect via the sprite rect
-- so here the original can be looked up

on mGetOriginalSpriteRect me
  return pSavedRect
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- set property pSeeThru to handle mouseOver events even, when another sprite is obscuring the table
-- the default is false, as the default should be to NOT receive the events if something other is over the table

on mSetSeeThru me, val
  pSeeThru = (val=1)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- just get a reference to this scriptinstance, so we can communicate
-- implemented for script "ILT_TableBuilder"

on mGetTableManagerObject me
  return me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetScriptObject me, tabname
  if count(pTableList) < 1 then return ""
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return ""
  return table.getaprop(#myScriptObject)
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- replace a whole cell instead of the content only => we need this to exchange objectcells

-- this handler does not yet work.
-- I've left it here for later review...
-- meanwhile I prefer to mDeleteRow and mInsertRow in order to replace whole cells

--on mReplaceEntireCell me, whichCell, newCell, keepOldCell, tabname

--  if count(pTableList) < 1 then exit
--  
--  if not voidP(tabname) then
--    table = pTableList.getaprop(tabname)
--  else
--    table = pTableList[1]
--  end if
--  if ilk(table) <> #proplist then return 0
--  
--  scr = table.getaprop(#myScriptObject)
--  if objectP(scr) then return call(#mReplaceEntireCell, scr, whichCell, newCell, keepOldCell)
--  else return 0
--  
--end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetCellContent me, row, column, newVal, relativ, recalc, tabname
  -----------------------------------
  -- ACTION: Replace the content of a single cell
  -- INPUT: <row> ; integer or object ; can be either the row number (see comments for <relativ>)
  --                                    or a cell object itself
  --                                    or a linear list of two integers => [row, column]
  --                                    or a string => name of the cell
  --        <column> ; integer ; integer for the column number, only if <row> is an integer, otherwise ignored.
  --        <newVal> ; <any> ; the new content of the cell. if the cell is a buttoncell it may have different images
  --                           for different states, rollover etc. In that case provide a list of images like in the below example
  --        <relativ> ; boolean (integer) ; defines if <row> and <column> are treated:
  --                                          a) absolut (all rows, no sortorder) or
  --                                          b.) relativ (visible rows, defined by filter in the current sort order)
  --                                     however, if you have a reference to the cell you wish to change you can pass 0 or void as <relativ>
  --                                     and take the values from the cell reference:
  --                                     sendSprite(x, #mSetCellContent, cellref.row, cellref.column, "newVal" {, 0, "tabname"})
  --        <recalc> ; boolean (integer) ; whether the column widths shall be re calculated to match the new content (in case of an image e.g.)
  --                                       defaults to false, as it is time consumptive. It only makes sense, if you replace an image cell
  --                                            and have the image cell properties set to adjust the column width
  --        <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: returns 1 for success and 0 for failure
  -- EXAMPLES: success = sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellContent, 2, 3, "new content", 0, 0, "myTable")
  --                         -- set the content of cell 3 in row 2 to "new content"
  --           success = sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellContent, [2,3], void, "new content", 0, 0, "myTable")
  --                         -- the same as above
  --           success = sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellContent, cellReference, void, "new content", 0, 0, "myTable")
  --                         -- set the content of cell <cellReference> to "new content"
  --
  --           butList = mGetDefaultButtonList("Layout")
  --           buttonImgs = call(#mGetButtonImages, xscr(#ButtonImageCreator), "new content", butList)
  --           success = sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellContent, cellReference, void, buttonImgs, 0, 0, "myTable")
  --                         -- set the content of the button cell <cellReference> to "new content"
  
  -----------------------------------
  
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mSetCellContent, scr, row, column, newVal, relativ, recalc)
  else return 0
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCellContent me, row, column, tabname
  if count(pTableList) < 1 then return ""
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return ""
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCellContent, scr, row, column)
  
  if voidP(retval) then retval = ""
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCellByName me, aName, tabname
  if count(pTableList) < 1 then return []
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return []
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCellByName, scr, aName)
  
  if voidP(retval) then retval = []
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentSelection me, tabname
  if count(pTableList) < 1 then return []
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return []
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCurrentSelection, scr)
  
  if voidP(retval) then retval = []
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mAXTable_GetCurrentRadioGroupSelection me, groupname, tabname
  if count(pTableList) < 1 then return [:]
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return [:]
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCurrentRadioGroupSelection, scr, groupname)
  
  if voidP(retval) then retval = [:]
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mAXTable_RefreshItem me, cellObject, refreshBackGround, tabname
    -----------------------------------
  -- ACTION: Render a single cell
  --         render only one single cell, after changing its properties (e.g. #selected) NOT the #content property !!!
  --         ALWAYS change the content of a cell ONLY with the handler: mSetCellContent() 
  --            to take a change of lineheight into consideration
  --         of course, if you change the content of a cell and don't want the dimension of the cell to change
  --            you can go with this function, much faster..
  -- INPUT: <cellObject> ; object ; can be:
  --                                    a cell object itself
  --                                    or a linear list of two integers => [row, column]
  --                                    or a string => name of the cell
  --        <refreshBackGround> ; boolean (integer) ; whether to referesh the background as well
  --                                                  (only relevant for cells with a transparent background e.g. an image for the whole table)
  --        <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: -
  -- EXAMPLES: sendSprite(xscr().mGetKanal(#tableSprite), #mAXTable_RefreshItem, cellRef, 0, "myTable")
  --                         -- refresh cell 3 in row 2
  --           sendSprite(xscr().mGetKanal(#tableSprite), #mAXTable_RefreshItem, [2, 3], 0, "myTable")
  --                         -- the same as above
  --           sendSprite(xscr().mGetKanal(#tableSprite), #mAXTable_RefreshItem, "cellName", 0, "myTable")
  --                         -- the same as above
  -----------------------------------
  
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then exit
  scr = table.getaprop(#myScriptObject)
  
  if objectP(scr) then
    if ilk(cellObject) = #string then
      cellObject = mGetCellByName(me, cellObject, tabname)
    else
      if ilk(cellObject) = #list then cellObject = mGetCellByIndex(me, cellObject, tabname)
    end if
  
    if objectP(cellObject) then call(#mRefreshItem, scr, cellObject, refreshBackGround)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetCellProperty me, cellObject, symbol_propname, any_propvalue, tabname
  -----------------------------------
  -- ACTION: Change a property (e.g. #myFontColor) NOT the #content of a single cell and render that single cell
  --         ALWAYS change the content of a cell ONLY with the handler: mSetCellContent() 
  --            to take a change of lineheight into consideration
  --         of course, if you change the content of a cell and don't want the dimension of the cell to change
  --            you can go with this function, much faster..
  --         If you use mSetCellContent, you can change any other cell property before that call,
  --            as it will re-render the whole cell anyway
  -- INPUT: <cellObject> ; object ; can be:
  --                                    a cell object itself
  --                                    or a linear list of two integers => [row, column]
  --                                    or a string => name of the cell
  --        <symbol_propname> ; symbol ; one of several cell properties EXCEPT #content
  --        <any_propvalue> ; new value for the above property
  --        <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: -
  -- EXAMPLES: sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellProperty, cellRef, #myBGColor, rgb(200, 200, 220), "myTable")
  --                         -- refresh cell 3 in row 2
  --           sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellProperty, [2, 3], #myBGColor, rgb(200, 200, 220), "myTable")
  --                         -- the same as above
  --           sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellProperty, "cellName", #myBGColor, rgb(200, 200, 220), "myTable")
  --                         -- the same as above
  -----------------------------------


  if ilk(cellObject) = #string then
    cellObject = mGetCellByName(me, cellObject, tabname)
  else
    if ilk(cellObject) = #list then cellObject = mGetCellByIndex(me, cellObject, tabname)
  end if

  if objectP(cellObject) then
    cellObject[symbol_propname] = any_propvalue
    mAXTable_RefreshItem(me, cellObject, 1, tabname)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetCellProperties me, cellObject, proplist_newProps, tabname
  -----------------------------------
  -- ACTION: Bulk change several properties (e.g. #myFontColor, NOT the #content or font properties, size and font and antialias)
  --            of a single cell and render that single cell
  --         ALWAYS change the content of a cell ONLY with the handler: mSetCellContent() 
  --            to take a change of lineheight into consideration
  --         of course, if you change the content of a cell and don't want the dimension of the cell to change
  --            you can go with this function, much faster..
  --         If you use mSetCellContent, you can change any other cell property before that call,
  --            as it will re-render the whole cell anyway
  -- INPUT: <cellObject> ; object ; can be:
  --                                    a cell object itself
  --                                    or a linear list of two integers => [row, column]
  --                                    or a string => name of the cell
  --        <proplist_newProps> ; proplist ; property list with new values for the specified properties
  --        <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: -
  -- EXAMPLES: sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellProperties, cellRef, [#myBGColor: rgb(200, 200, 220), #myFontColor: rgb(20, 30, 40)], "myTable")
  --                         -- refresh cell 3 in row 2
  --           sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellProperties, [2, 3], [#myBGColor: rgb(200, 200, 220), #myFontColor: rgb(20, 30, 40)], "myTable")
  --                         -- the same as above
  --           sendSprite(xscr().mGetKanal(#tableSprite), #mSetCellProperties, "cellName", [#myBGColor: rgb(200, 200, 220), #myFontColor: rgb(20, 30, 40)], "myTable")
  --                         -- the same as above
  -----------------------------------
  
  if not(objectP(proplist_newProps)) then exit
  
  if ilk(cellObject) = #string then
    cellObject = mGetCellByName(me, cellObject, tabname)
  else
    if ilk(cellObject) = #list then cellObject = mGetCellByIndex(me, cellObject, tabname)
  end if

  if objectP(cellObject) then
    repeat with n = count(proplist_newProps) down to 1
      cellObject[proplist_newProps.getPropAt(n)] = proplist_newProps[n]
    end repeat
    
    mAXTable_RefreshItem(me, cellObject, 1, tabname)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetLineByIndex me, lineNum, tabname
  if count(pTableList) < 1 then return []
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return []
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetLineByIndex, scr, lineNum)
  
  if voidP(retval) then retval = []
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetSelection me, newSelection, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mSetSelection, scr, newSelection)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDeSelectSingleCell me, whichCell, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mDeSelectSingleCell, scr, whichCell)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- changed the valuerange for scrollToTop in 'mSelectCell me, whichCell, sendEvent, scrollToTop'
-- values are: 0 = dont scroll, 1 = scroll only vertical to top or bottom, 2 = scroll only horizontal to left or right, 3 = scroll vertical AND horizontal to top or bottom and left opr right
-- 4 = scroll only vertical to centerV, 5 = scroll only horizontal to centerH, 6 = scroll vertical AND horizontal to center

-- <whichModifier> to mimic shift select. can be: #commandselect or #shiftselect or <void> (any other value)
-- (note that multiple selection must be enabled, which can be enabled temporarely also -> mGetScriptObject(me).pTableformatlist.setaprop(#multipleSelection, <1 or 2>))

on mSelectCell me, whichCell, scrollToTop, tabname, whichModifier
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mSelectCell, scr, whichCell, 0, scrollToTop, whichModifier)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHighLightCell me, whichCell, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mHighLightCell, scr, whichCell) 
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mEnableCell me, whichCell, enabledState, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mEnableCell, scr, whichCell, enabledState)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCellByIndex me, indexList, tabname
  if count(pTableList) < 1 then return [:]
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return [:]
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetCellByIndex, scr, indexList)
  else return [:]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentPrintListe me, tabname
  if count(pTableList) < 1 then return []
  
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return []
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCurrentPrintListe, scr)
  
  if voidP(retval) then retval = []
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentRect me, tabname, withoutShadow
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCurrentRect, scr, withoutShadow)
  
  if voidP(retval) then retval = 0
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentTargRect me, tabname
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetCurrentTargRect, scr)
  
  if voidP(retval) then retval = 0
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetCurrentRect me, newRect, tabname, relativ, forceUpdate, useInnerRect
  if count(pTableList) < 1 then return 1
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mSetCurrentRect, scr, newRect, useInnerRect, relativ, forceUpdate)
  
  return 1
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetOverallTableRect me, tabname
  -----------------------------------
  -- CREATED: 16.10.2008
  -- ACTION:  get the overall rect of the table including the parts, which are not visible
  -- INPUT:   <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: rect ; if tableFormatList[#noBuffer] = 0 then this is the rect of the image of the whole table
  --                 if tableFormatList[#noBuffer] = 1 there is not a big image holding the entire table
  --                   (-> which is recommende to save memory), so this is the rect, which WOULD be the entire image
  -- EXAMPLE: overallTableRect = sendSprite(xscr().mGetKanal(#tableSprite), #mGetOverallTableRect, "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then retval = call(#mGetOverallTableRect, scr)
  
  if voidP(retval) then retval = 0
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMoveAllTables me, delta
  repeat with n = count(pTableList) down to 1
    mMoveTable me, delta, pTableList.getPropAt(n)
  end repeat
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMoveTable me, delta, tabname
  if count(pTableList) < 1 then return 1
  if ilk(delta) <> #point then return 1
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  if pDreiDModus then
    moname = string(table.getaprop(#useModel))
    if moname.length then
      mo = pMember.model(moname)
      if ilk(mo) = #model then
        shd = mo.shaderlist[1]
        shd.texturetransformlist[2].position = shd.texturetransformlist[2].position + vector(delta[1] / 10, delta[2] / 10, 0)
      end if
    else
      
      camObj = table.getaprop(#myCamera)
      if voidP(camObj) then camObj = pKanal.camera
      
      tex = pMember.texture(pTextureBaseName&"_"&table.getaprop(#myName))
      olayIndex = mGetOlayIndex(me, camObj, tex)
      if olayIndex > 0 then
        theRect = table.getaprop(#myRect)
        if (ilk(theRect) = #rect) then
          theRect = theRect.offset(delta[1], delta[2])
          table[#myRect] = theRect
          camObj.overlay[olayIndex].loc = point(theRect.left, theRect.top)
        else
          camObj.overlay[olayIndex].loc = camObj.overlay[olayIndex].loc + delta
        end if
      end if
      
    end if
    
  else
    if pKanal <> 0 then
      pKanal.loc = pKanal.loc + delta
    else
      if ilk(pMember) = #instance then call(#mMoveTable, [pMember], delta, tabname)
    end if
  end if
  
  doMoveChildObjectsAsWell = 1
  forceRectUpdate = 0
  
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mMoveTable, scr, delta, forceRectUpdate, doMoveChildObjectsAsWell)
  else return 0
  
  return 1 -- this is only, if the caller needs to know, if the move command was handled
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mReverse me, sortOrder, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mReverse, scr, sortOrder)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeSortBy me, column, sortorder, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mChangeSortBy, scr, column, sortorder)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mFilterColumn me, filterListe, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mFilterColumn, scr, filterListe)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeScrollOffset me, relVal, tabname
  if ilk(relVal) <> #point then exit
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mChangeScrollOffset, scr, relVal)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetScrollOffset me, absVal, tabname
  if ilk(absVal) <> #point then exit
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mSetScrollOffset, scr, absVal)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mAttemptToScroll me, relVal, doSendScrollEvent, tabname
  -----------------------------------
  -- CREATED: 2008-10-10 at 10:57
  -- ACTION: Try to scroll the table content by a relative scrollvalue
  -- INPUT:  <relVal> ; point (or integer) ; the relative values for horizontal and vertical scrollchange in pixels
  --                                         if an integer is used instead of a point only vertical scrolling happens
  --         <doSendScrollEvent> ; boolean (integer) ; whether the action shall trigger scrollvenets to the listeners
  --                                                   (an object can receive events, whenever the scrolloffset changed
  --                                                    in order to react on scroll events => e.g. enable/disable buttons)
  --         <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: point => the scroll change, which effectively took place, if it is point(0,0) no scroll change happened
  --                                if one of the values is smaller, than the value which was provided, then 
  --                                the scroll-end in the given direction was reached
  -- EXAMPLE:  scrollChange = point(0, 10)
  --           RealScrollChange = sendSprite(xscr().mGetKanal(#tableSprite), #mAttemptToScroll, point(0, 10), 0, "myTable")
  --           if scrollChange[1] < 0 then disableHorizontal = (scrollChange[1] < RealScrollChange[1])
  --           else disableHorizontal = (scrollChange[1] > RealScrollChange[1])
  --          if scrollChange[2] < 0 then disableVertical = (scrollChange[2] < RealScrollChange[2])
  --           else disableVertical = (scrollChange[2] > RealScrollChange[2])
  -----------------------------------
  
  if count(pTableList) < 1 then return point(0,0)
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return point(0,0)
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mAttemptToScroll, scr, relVal, doSendScrollEvent)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentScrollOffset me, tabname
  -----------------------------------
  -- CREATED: 2008-10-10 at 11:06
  -- ACTION: Get the current scrolloffset
  -- INPUT:  <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: point ; the current scrolloffset
  -- EXAMPLE: currentScrollOffset = sendSprite(xscr().mGetKanal(#tableSprite), #mGetCurrentScrollOffset, "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then return point(0,0)
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return point(0,0)
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetCurrentScrollOffset, scr)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCellUnderLoc me, theLoc, tabname
  -----------------------------------
  -- CREATED: 3.11.2009
  -- ACTION: Get the cell under loc
  -- INPUT:  <theLoc>  ; point  ; the loc at which we want to search the cell
  --         <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: proplist ; the cellref
  -- EXAMPLE: cellUnderLoc = sendSprite(xscr().mGetKanal(#tableSprite), #mGetCellUnderLoc, point(0, 100), "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then return [:]
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return [:]
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetCellUnderLoc, scr, theLoc)
  return [:]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetLineNumberAtScrollTop me, absolute, tabname
  -----------------------------------
  -- CREATED: 3.11.2009
  -- ACTION: Get the line which is currently the first visible (at the scrolltop)
  -- INPUT:  <absolute> ; boolean (integer) ; if true the absolute linenumber is returned and NOT
  --                           the current relative line number (these both differ, if for example the sortorder
  --                           or a filter is applied), therefore relative is the default
  --         <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: integer ; linenumber
  -- EXAMPLE: topLineNumber = sendSprite(xscr().mGetKanal(#tableSprite), #mGetCellUnderLoc, point(0, 100), "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then return 1
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 1
  scr = table.getaprop(#myScriptObject)
  
  if objectP(scr) then
    scro = call(#mGetCurrentScrollOffset, scr)
    if ilk(scro) = #point then
      topCell = call(#mGetCellUnderLoc, scr, point(1, scro[2]))
      if objectP(topCell) then
        theRow = topCell[#row]
        if absolute = 1 then
          return theRow
        else
          lineList = call(#mGetCurrentLinesList, scr)
          return lineList.getPos(theRow)
        end if
      end if
    end if
  end if
  
  return 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mScrollToLine me, whichLineNumber, tabname
  -----------------------------------
  -- CREATED: 03.11.2009
  -- ACTION: Get the line which is currently the first visible (at the scrolltop)
  -- INPUT:  <whichLineNumber> ; integer line which shall appear at scrolltop
  --         <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: -
  -- EXAMPLE: sendSprite(xscr().mGetKanal(#tableSprite), #mScrollToLine, 4, "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then return 1
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 1
  scr = table.getaprop(#myScriptObject)
  
  if objectP(scr) then
    theLine = call(#mGetLineByIndex, scr, whichLineNumber)
    
    cnt = count(theLine)
    repeat with n = 1 to cnt
      rs = theLine[n][#rowspan]
      if voidP(rs) or rs = 1 then
        exit repeat
      end if
    end repeat
    n = min(cnt, n)
    theRect = theLine[n][#myRect]
    
    curr = call(#mGetCurrentScrollOffset, scr)
    call(#mSetScrollOffset, scr, point(curr[1], theRect.top))
    
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mScrollByLine me, howManyLines, tabname
  -----------------------------------
  -- CREATED: 03.11.2009
  -- ACTION: Get the line which is currently the first visible (at the scrolltop)
  -- INPUT:  <howManyLines> ; integer ; can be positive or negative
  --         <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: -
  -- EXAMPLE: sendSprite(xscr().mGetKanal(#tableSprite), #mScrollByLine, 3, "myTable")
  -----------------------------------
  
  toplineNum = mGetLineNumberAtScrollTop(me, 1, tabname)
  mScrollToLine me, toplineNum + howManyLines, tabname
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetOverallScrollDistance me, tabname
  -----------------------------------
  -- CREATED: 16.10.2008
  -- ACTION:  get the distance in pixels, which is hidden and can be scrolled
  --          this is the difference between the width/height of the entire table
  --          and the width/height of the visible area
  -- INPUT:   <tabname> ; string ; name of the table, which shall be addressed,
  --                              if empty, the first table in the list of tables is used
  -- RETURNS: point ; scrolldistance horizontal and scrolldistance vertical
  -- EXAMPLE: overallScrollDistance = sendSprite(xscr().mGetKanal(#tableSprite), #mGetOverallScrollDistance, "myTable")
  -----------------------------------
  
  if count(pTableList) < 1 then return point(0,0)
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return point(0,0)
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetOverallScrollDistance, scr)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- tab delimted text of current view:

on mGetCurrentViewList me, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetCurrentViewList, scr)
  else return [:]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mInsertRow me, newValueList, posIndex, tabname
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  --  if ilk(table.getaprop(#myRect)) <> #rect then return 0
  if table.getaprop(#readyToGo) <> 1 then return 0
  
  
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mInsertRow, scr, newValueList, posIndex)
  else return 0
  
  return 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDeleteRow me, posIndex, toPos, relativ, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mDeleteRow, scr, posIndex, toPos, relativ)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mInsertCol me, posIndex, colList, newValueList, tabname
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  --  if ilk(table.getaprop(#myRect)) <> #rect then return 0
  if table.getaprop(#readyToGo) <> 1 then return 0
  
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mInsertCol, scr, posIndex, colList, newValueList)
  else return 0
  
  return 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDeleteCol me, whichCol, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mDeleteCol, scr, whichCol)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeColumnWidth me, col, neuebreite, tabname, dontUpdate
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mChangeColumnWidth, scr, col, neuebreite, dontUpdate)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeColumnPosition me, fromPos, toPos, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mChangeColumnPosition, scr, fromPos, toPos)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeTableBackGroundImage me, newBackground, tabname
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then call(#mChangeTableBackGroundImage, scr, newBackground)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentLinesList me, tabname
  if count(pTableList) < 1 then return []
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetCurrentLinesList, scr)
  else return [:]
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetCurrentLinesList me, newList, tabname
  if count(pTableList) < 1 then return []
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mSetCurrentLinesList, scr, newList)
  else return [:]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetCurrentColumnWidths me, tabname
  if count(pTableList) < 1 then return []
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mGetCurrentColumnWidths, scr)
  else return []
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mConvertToConstrained me, absLine, tabname
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mConvertToConstrained, scr, absLine)
  return 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mConvertToAbsolute me, relativeLine, tabname
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mConvertToAbsolute, scr, relativeLine)
  return 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--
--on mGetCurrentColumnWidths me, tabname
--  if count(pTableList) < 1 then return []
--  
--  if not voidP(tabname) then table = pTableList.getaprop(tabname)
--  else table = 0
--  if ilk(table) <> #proplist then table = pTableList[1]
--  scr = table.getaprop(#myScriptObject)
--  if objectP(scr) then return call(#mGetCurrentColumnWidths, scr)
--  else return []
--end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- this is kind of a hack: without the table even "knowing", we change the blend of the sprite or the overlay
-- this is for temporarely hide/unhide or fade the whole table, without any other change
-- provide a name and a new blend value (0-100)

on mSetTableOverallBlend me, newBlend, tabname
  
  if count(pTableList) < 1 then return 0
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  newBlend = max(0, min(100, newBlend))
  
  mChangeBlend me, newBlend, table
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMapPointToStage me, thePoint, tabname
  if count(pTableList) < 1 then return thePoint
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return thePoint
  scr = table.getaprop(#myScriptObject)
  if objectP(scr) then return call(#mMapPointToStage, scr, thePoint)
  return point(0,0)
end


----------- I have NO IDEA, how it can happen, that we do not appear in the models scriptlist after showtable, must debug that later
----------- for now I just force this instance to enter itself in the scriptlist

on mForeceAddToModelScriptList me, theModel
  if voidP(theModel) then exit
  scrili = xscr().mGetParentScriptList(theModel)
  if scrili.getPos(me) < 1 then scrili.add(me)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mIsModalTableOnScreen me
  repeat with n = pTableList.count down to 1
    if pTableList[n].getaprop(#isModal) then return 1
  end repeat
  return 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____INCOMING_EVENTS_FROM_TABLESCRIPT
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- these are dummy event handlers, which can be used as starting point to get events from the script
-- these handlers are only send here, if the table property <tableformatlist.getaprop(#CallerRef)> is not an #instance
-- the 'standard' way certainly is to have an object #CallerRef which manages these scripts and handles these events
-- since these events are sent via call(#event, [CallerRef]), they won't cause an error, if not found in CallerRef (not the brackets around CallerRef)


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- the standard event, which gets called if no other is specified as soon as a prepared table is ready to display:

on mTablePrepared me, tabname, newRect, caller
  --  put newRect
  
  --  call(#mShowPreparedTable, [caller], tabname)
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mTableMouseDown me, cellref, caller, tabName, rightMouse
  -- do what you want here, when a cell got a mousedown event
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeSelection me, cellref, caller, tabName, rightMouse
  -- do what you want here, when a cell got a select event
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mTableCellHighLightEvent me, targrect, whichMode, tabname, callerRef, whichcell
  -- do what you want here, when a cell got a highlight or select event
  
  --  mHighLightTableCell targrect, whichMode, tabname
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mTableBlur me, targrect, whichMode, tabname, callerRef, whichcell
  -- do what you want here, when a cell got a highlight or select event
  --  mHighLightTableCell targrect, whichMode, tabname
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mDeselectTableCell me, whichMode, tabname, replaced, callerRef, whichcell
  -- do what you want here, when a cell got a highlight or select event
  
  --  mDeselectTableCell whichMode, tabname, replaced
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCharAddEvent me, cellRef, caller, tabname
  -- do what you want here, when a char was added to a edittext field
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mTableScrollEvent me, newScrollOffset, relativ, tabname, caller
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSendColResize me, whichColumn, tabname, caller
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSendColDrag me, whichColumn, allowDelete, tabname, caller
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSendColChange me, oldPos, newPos, tabname, caller
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mTableFinishEvent me, tabname, caller
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSendResizeEvent me, lastrect, newRect, tabname, caller
  return 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mRefreshSpriteRectAfterStageChange me, newSpriteRect, recentrect
  if not listP(pTableList) then exit
  if pKanal <> 0 then
    if sendSprite(me.spritenum, #mGetOffscreenState) = 1 then exit
    if pDreiDModus = 1 then exit
    mSetCurrentRect me, newSpriteRect
  end if
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____SEMI_PUBLIC_HANDLERS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- these are public handlers, since they are called from outside, but normally only from another table scriptopbject
-- to synchronize resizing or dragging across more than one tables (for example the header table, which doesn't scroll vertical, but horizontal in synch with others)

on mStartColResize me, whichColumn, tabname
  if ilk(whichColumn) <> #integer then exit
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  call(#mStartColResize, table.getaprop(#myScriptObject), whichColumn)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mStartDragColumn me, whichColumn, allowDelete, tabname
  if ilk(whichColumn) <> #integer then exit
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  call(#mStartDragColumn, table.getaprop(#myScriptObject), whichColumn, allowDelete)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mWheelMouseEvent me, theVal
  
  ml = the mouseloc
  repeat with n = pTableList.count down to 1
    theRect = pTableList[n].getaprop(#myRect)
    if ilk(theRect) = #rect then
      if (ml).inside(theRect) then
        locMl = ml - point(theRect.left, theRect.top)
        call(#mTryToScroll, pTableList[n].getaprop(#myScriptObject), point(0, theVal/-10.0), locMl)
        exit repeat
      end if
    end if
  end repeat
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mSetReadyFlag me, tabname, caller
  if count(pTableList) < 1 then exit
  
  if not voidP(tabname) then
    table = pTableList.getaprop(tabname)
  else
    table = pTableList[1]
  end if
  if ilk(table) <> #proplist then return 0
  
  table.setaprop(#readyToGo, 1)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- nested table objects
-- tables in tables or tables as a cell content handle the coordinate system entirely relative
-- therefore we need a way to decide, whether to transform the mouse location for the events
-- a table uses this handler to tell if it is a nested table itself
-- (only in this case the coords, which it sends (relays) to its own nested objects are translated)

on mIsNestedTableObject me
  return (pKanal = 0)
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetVirtualTableHost me
  if pKanal = 0 then return pMember
  return void
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____PRIVATE_HANDLERS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- this handler is used to determine if this behavior is already attached to a models "sil"

on mGetScriptInstanceList me, sil
  sil.add("TableManager")
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGibLaut me, scrName -- the check if this instance is already added to a models userdata
  if not voidP(scrName) then return (scrName = "TableManager")
  return 1
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mRemoveEmptyListEntries me
  if ilk(timeout(pTextureBaseName&"_cleanup")) = #timeout then timeout(pTextureBaseName&"_cleanup").forget()
  repeat with n = pTableList.count down to 1
    if not(pTableList[n].count) then pTableList.deleteAt(n)
  end repeat
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- this needed for the submenus
-- since the table script itself, doesn't know, if it is running in a 3-D member and if so can't draw beyond the bounds of the 3-D sprite
-- it simply gets here the bounding rect it can draw to => this is simply like calling:
-- if I am running 3-D give me the 3-D sprite bounding rect otherwise give me the stage rect
on mGetStageBoundRect me, modelName
  
  if ilk(pStageRectMargin) <> #integer then pStageRectMargin = 0
  
  if pDreiDModus then
    --    return pKanal.rect
    ar = pKanal.rect
    
    -- Scriptmarker (27.11.2005 at 9:37 Uhr): Alex da Franca: Change // Scriptmarker
    if length(string(modelName)) > 0 then
      return rect(0, 0, ar.width, ar.height).inflate(-pStageRectMargin, -pStageRectMargin)
    else
      return ar.inflate(-pStageRectMargin, -pStageRectMargin)
    end if
    -- // Change
    
  else
    if pKanal <> 0 then
      --      return (the activewindow).drawrect
      ar = (the activewindow).rect
      return rect(0, 0, ar.width, ar.height).inflate(-pStageRectMargin, -pStageRectMargin)
    else
      if ilk(pMember) = #instance then r = call(#mGetStageBoundRect, [pMember])
      --      if ilk(r) <> #rect then r = (the activewindow).drawrect
      if ilk(r) <> #rect then
        ar = (the activewindow).rect
        r = rect(0, 0, ar.width, ar.height).inflate(-pStageRectMargin, -pStageRectMargin)
      end if
      return r
    end if
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Update the sprite/overlay image

on mUpdateImage me, theImage, caller, renderingInProgress, tabname
  
  
  --  
  --  repeat with n = pTableList.count down to 1
  --    theTable = pTableList[n].getaprop(#myScriptObject)
  --    if theTable = caller then exit repeat
  --  end repeat
  --  if n = 0 then exit
  
  --  theTable = pTableList[n]
  
  --  call(#mEnablePut, mGetXScript(), 1)
  --  call(#mPut, mGetXScript(), theImage)
  
  theTable = pTableList.getaprop(tabname)
  if voidP(theTable) then exit
  
  -- update the rect if neccessary
  
  theRect = theTable.getaprop(#myRect)
  if ilk(theRect) <> #rect then
    theRect = call(#mGetCurrentRect, caller)
    if pDreiDModus then
      moname = string(theTable.getaprop(#useModel))
      if moname = "" then theRect = theRect.offset(-pKanal.left, -pKanal.top)
    end if
    theTable[#myRect] = theRect
    theTable[#readyToGo] = 1
    
    --    xscr().mPut(theImage)
    
    
    --    ----------------------- this would record the current rect, but I don't know if this is really a good idea
    --    if pDontReplaceMember then
    --      if the runmode contains "aut" then
    --        oldfr = the frame
    --        stf = pKanal.startframe
    --        endfr = pkanal.endframe
    --        r = pKanal.rect
    --        go stf
    --        theMember = pKanal.member
    --        theColor = pkanal.color
    --        theBGColor = pkanal.bgcolor
    --        beginrecording
    --          repeat while the frame <= endfr
    --            pKanal.member = theMember
    --            pKanal.rect = theR
    --            pKanal.color = theColor
    --            pKanal.bgcolor = theBGColor
    --            pKanal.tweened = 1
    --            
    --            updateframe
    --          end repeat
    --        endrecording
    --        go oldfr
    --      end if
    --    end if
    
    
  end if
  
  
  if ilk(theRect) = #rect then
    
    if theTable.getaprop(#prepareFlag) then
      
      callback = theTable.getaprop(#callbackInstance)
      if callback = 0 then exit -- already came here and called, now we wait until the prepareFlag is turned off
      
      callbackHandler = theTable.getaprop(#callbackHandler)
      if ilk(callbackHandler) <> #symbol then
        mTablePrepared me, tabname, theRect
      else
        
        if ilk(callback) = #instance then
          call(callbackHandler, [callback], tabname, theRect, me)
        else
          doStr = string(callbackHandler)&&QUOTE&tabname&QUOTE&","&&theRect&", me"
          do doStr
        end if
        
      end if
      
      theTable[#callbackInstance] = 0 -- release object reference
      
    else -- not only preparing
      
      
      animation = theTable.getaprop(#myAnimation)
      if not voidP(animation) then
        if voidP(animation.getaprop(#starttime)) then
          animation[#starttime] = the milliseconds
          animation[#endRect] = theRect
          pAnimationList.add(theTable)
          if ((the actorlist).getPos(me) < 1) then (the actorlist).add(me)
        end if
        doAnim = ((animation.getaprop(#starttime) + animation.getaprop(#animationTime)) > the milliseconds)
      end if
      
      
      if pDreiDModus then
        
        if ilk(theImage) = #image then
          
          -- update the texture:
          
          mUpdate3DImage me, theImage, theTable, theRect
          
          
          if doAnim then mProcessAnimation me, theTable
          
        end if
        
      else
        
        if doAnim then
          
          if pKanal <> 0 then
            if ilk(theImage) = #image then
              pMember.image = theImage
              pMember.regpoint = point(0,0)
              pKanal.rect = theRect
            end if
            
          else
            mSendImageToVM me, theImage, theRect, theTable.getaprop(#myName)
          end if
          
          mProcessAnimation me, theTable
          
        else
          if ilk(theImage) = #image then
            
            if pKanal <> 0 then
              pMember.image = theImage
              
              -- setting the regpoint of the bitmap causes a huge delay on updatestage, setting the sprite rect is enough here
              --                          pMember.regpoint = point(0,0)
              
              pKanal.rect = theRect
              
            else
              mSendImageToVM me, theImage, theRect, theTable.getaprop(#myName)
            end if
            
          end if
        end if
        
      end if -- / if 3 - D
      
    end if -- / if only prepare
    
  end if -- / if rect
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mSendImageToVM me, theImage, theRect, tabname
  if ilk(pMember) = #instance then
    call(#mUpdateVMImage, [pMember], theImage, theRect, tabname)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mUpdate3DImage me, theImage, theTable, theRect
  
  
  if not pAktiv then exit
  
  
  tex = pMember.texture(pTextureBaseName&"_"&theTable.getaprop(#myName))
  
  createNew = voidP(tex)
  
  if not createNew then createNew = ((tex.width < theImage.width) or (tex.height < theImage.height))
  
  if not createNew then
    if ((theImage.width = tex.width) and (theImage.height = tex.height)) then
      tex.image = theImage
      -- theTable[#myImg] = theImage
    else
      
      if ilk(theTable.getaprop(#myImg)) <> #image then
        createNew = 1
      else
        theTable.myImg.copyPixels(theImage, theImage.rect, theImage.rect, [#usealpha:0])
        
        if ilk(theTable.getaprop(#myMaskImg)) = #image then
          
          theTable.myMaskImg.fill(theTable.myMaskImg.rect, rgb(255, 255, 255))
          if theImage.useAlpha = 1 then
            theTable.myMaskImg.copyPixels(theImage.extractAlpha(), theImage.rect, theImage.rect)
          else
            theTable.myMaskImg.fill(theImage.rect, rgb(0,0,0))
          end if
          
          theTable.myImg.setAlpha(theTable.myMaskImg)
        end if
        
        tex.image = theTable.myImg
      end if
      
    end if
  end if
  
  --          if voidP(tex) then mCreateOverlay me, theImage, theTable
  if createNew then
    mCreateOverlay me, theImage, theTable
    
  else
    
    moname = string(theTable.getaprop(#useModel))
    if moname = "" then
      
      camObj = theTable.getaprop(#myCamera)
      if voidP(camObj) then camObj = pKanal.camera
      
      olayIndex = mGetOlayIndex(me, camObj, tex)
      if olayIndex > 0 then
        
        if ilk(theRect) <> #rect then
          theRect = theTable.getaprop(#myRect)
          if ilk(theRect) <> #rect then
            theRect = call(#mGetCurrentRect, theTable.getaprop(#myScriptObject))
            if ilk(theRect) <> #rect then
              theImage = theTable.getaprop(#myImg)
              if ilk(theImage) = #image then
                theRect = theImage.rect
              end if
            else
              theTable[#myRect] = theRect
            end if
          end if
        end if
        
        if ilk(theRect) = #rect then
          if camObj.overlay[olayIndex].loc <> point(theRect.left, theRect.top) then camObj.overlay[olayIndex].loc = point(theRect.left, theRect.top)
        end if
        
      end if
    end if
  end if
  
  sendSprite(me.spritenum, #mSuspendAliasing)
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on mForceRectUpdate me, caller, tabname
  
  if ilk(tabname) <> #string then
    
    repeat with n = pTableList.count down to 1
      theTable = pTableList[n].getaprop(#myScriptObject)
      if theTable = caller then exit repeat
    end repeat
    if n = 0 then exit
    
    theTable = pTableList[n]
    
  else
    
    theTable = pTableList.getaprop(tabname)
    if voidP(theTable) then exit
    
  end if
  
  theTable[#myRect] = 0
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Custom Input Event Handling
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____Custom_Mouse_Events
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMouseDown me, theModel, theMUList
  mProcessEventFromRouter me, #myMouseDown, theModel, theMUList
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMouseUp me, theModel, theMUList
  mProcessEventFromRouter me, #myMouseUp, theModel, theMUList
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mMouseUpOutside me, theModel
  mProcessEventFromRouter me, #myMouseUpOutside, theModel
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mProcessEventFromRouter me, whichEvent, theModel, theMUList
  repeat with n = pTableList.count down to 1
    theTable = pTableList[n]
    if string(theTable.getaprop(#useModel)) = theModel.name then
      
      if voidP(theMUList) then
        if whichEvent = #mouseUpOutside then
          mID = theTable.getaprop(#shaderListIndex)
        else
          mID = 0
        end if
      else
        mID = theMUList.getaprop(#meshID)
      end if
      
      if theTable.getaprop(#shaderListIndex) = mID then
        
        
        scr = theTable.getaprop(#myScriptObject)
        
        if not voidP(theMUList) then
          
          theImage = theTable.getaprop(#myImg)
          if ilk(theImage) = #image then
            
            p = mMapPointToTexture(me, theMUList, theImage, theTable.getaprop(#textureListIndex))
            
            theRect = theTable.getaprop(#myRect)
            if ilk(theRect) = #rect then
              p = p + point(theRect.left, theRect.top)
            end if
            
          else
            p = 0 -- dummy used for mouseUpOutside
            
          end if
          
        else
          p = 0 -- dummy used for mouseUpOutside
          
        end if
        
        call(whichEvent, [theTable.getaprop(#myScriptObject)], p)
        
        exit repeat
      end if
      
    end if
  end repeat
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetAbsolutMouse me, caller, forInsideCheck, tabname, baseLoc
  
  if ilk(baseLoc) = #point then retval = baseLoc
  else retval = the mouseloc
  
  if pDreiDModus then
    --    repeat with n = pTableList.count down to 1
    theTable = pTableList.getaprop(tabname)
    --    scr = pTableList[n].getaprop(#myScriptObject)
    --    if scr = caller then
    if not(voidP(theTable)) then
      --      theTable = pTableList[n]
      moname = string(theTable.getaprop(#useModel))
      if moname.length then
        mul = sendSprite(me.spritenum, #mGetLatestModelUnderLocList)
        
        
        if count(mul) > 0 then
          
          mo = pMember.model(moname)
          repeat with m = 1 to mul.count
            thisList = mul[m]
            if thisList.getaprop(#model) = mo then exit repeat
          end repeat
          
          if m <= mul.count then
            
            theImage = theTable.getaprop(#myImg)
            if ilk(theImage) = #image then
              
              p = mMapPointToTexture(me, thisList, theImage, theTable.getaprop(#textureListIndex))
              theRect = theTable.getaprop(#myRect)
              if ilk(theRect) = #rect then
                
                if forInsideCheck then return (p.inside(theRect))
                
                return p + point(theRect.left, theRect.top)
              end if
              
            end if
            
            
          else
            -- maybe the event router behavior just didn't scan deep enough ?? try it again with 6 models depth:
            --------- !!!!!!!!!!! BIN ICH TOTAL ANGEHIRNT ????
            
            
            
            --            anzCam = pKanal.cameraCount()
            --            cl = retval - point(pKanal.left, pKanal.top)
            --            repeat with c = anzCam down to 1
            --              currCam = pKanal.camera(c)
            --              if cl.inside(currCam.rect) then
            --                
            --                
            --                mul = currCam.modelsUnderLoc(cl, 6, #detailed)
            --                if mul.count then
            --                  
            --                  repeat with m = 1 to mul.count
            --                    thisList = mul[m]
            --                    if thisList.getaprop(#model) = mo then exit repeat
            --                  end repeat
            --                  
            --                  if m <= mul.count then
            --                    
            --                    theImage = theTable.getaprop(#myImg)
            --                    if ilk(theImage) = #image then
            --                      
            --                      p = mMapPointToTexture(me, thisList, theImage)
            --                      theRect = theTable.getaprop(#myRect)
            --                      if ilk(theRect) = #rect then
            --                        
            --                        if forInsideCheck then return (p.inside(theRect))
            --                        
            --                        return p + point(theRect.left, theRect.top)
            --                      end if
            --                    end if
            --                    
            --                  end if
            --                  
            --                end if
            --                
            --              end if
            --            end repeat
            
            
            
            
          end if
          
        end if
        
        if forInsideCheck then return 0
        
        -- if we didn't "return" before, we are outside, so we set the mouseloc to *something* outside
        r = theTable.getaprop(#myRect)
        if ilk(r) = #rect then
          retval = point(r.left - 1, r.top - 1)
        else
          retval = point(-1, -1)
        end if
        
      end if
    end if
    
    --    end repeat
  end if
  
  if pKanal = 0 then
    if ilk(pMember) = #instance then
      p = call(#mGetAbsolutMouse, [pMember], caller, forInsideCheck, tabname, retval)
      if ilk(p) = #point then retval = p
    end if
  end if
  
  return retval
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckMouseInside me, caller, tabname
  absmaus = the mouseloc
  ml = mGetAbsolutMouse(me, caller, 1, tabname)
  if ilk(ml) <> #point then return ml
  
  if (pTableList.count > 1) and ((pSubmenuHandling = #singleSprite) or (pSubmenuHandling = #dreiD)) then
    --    repeat with n = pTableList.count down to 1
    theTable = pTableList.getaprop(tabname)
    --    scr = pTableList[n].getaprop(#myScriptObject)
    --    if scr = caller then
    if not(voidP(theTable)) then
      --      theTable = pTableList[n]
      
      theRect = theTable.getaprop(#myRect)
      if ilk(theRect) = #rect then
        if pDreiDModus then
          moname = string(theTable.getaprop(#useModel))
          if moname = "" then theRect = theRect.offset(pKanal.left, pKanal.top)
        end if
        return (ml).inside(theRect)
      else
        return 0
      end if
    end if    
    --end repeat
    
  else
    --    scr = pTableList[1].getaprop(#myScriptObject)
    --    if scr = caller then
    if pTableList.count then
      theRect = pTableList[1].getaprop(#myRect)
      if ilk(theRect) = #rect then return (ml).inside(theRect)
    end if
    --    end if
  end if
  
  return 0
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckIfMouseIsOverAnyTable me, tabname
  
  absmaus = the mouseloc
  ml = mGetAbsolutMouse(me, void, 1, tabname)
  if ilk(ml) <> #point then return 0
  
  if voidP(tabname) then
    repeat with n = pTableList.count down to 1
      theTable = pTableList[n]
      
      if pDreiDModus then
        if length(string(theTable.getaprop(#useModel))) > 0 then next repeat
      end if
      
      theRect = theTable.getaprop(#myRect)
      if ilk(theRect) = #rect then
        if pDreiDModus then
          moname = string(theTable.getaprop(#useModel))
          if moname = "" then theRect = theRect.offset(pKanal.left, pKanal.top)
        end if
        if (ml).inside(theRect) then return 1
      end if
      
    end repeat
    
  else
    theTable = pTableList.getaprop(tabname)
    if not(voidP(theTable)) then
      
      if pDreiDModus then
        if length(string(theTable.getaprop(#useModel))) > 0 then return 0
      end if
      
      theRect = theTable.getaprop(#myRect)
      if ilk(theRect) = #rect then
        if pDreiDModus then
          moname = string(theTable.getaprop(#useModel))
          if moname = "" then theRect = theRect.offset(pKanal.left, pKanal.top)
        end if
        return (ml).inside(theRect)
      end if
    end if
    
  end if
  
  return 0
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHandleMouseWithinEvent me, cl
  retval = 0
  if (pAktiv = 1) then -- and pDreiDModus then
    repeat with n = pTableList.count down to 1
      
      if count(pTableList) < n then next repeat
      -- we only want to process overlays, models would get mMouse-XY events form the event router
      moname = string(pTableList[n].getaprop(#useModel))
      if moname.length then next repeat
      
      theRect = pTableList[n].getaprop(#myRect)
      if ilk(theRect) = #rect then
        if cl.inside(theRect) then return 1
      end if
      
      if count(pTableList) < n then next repeat
      if pTableList[n].getaprop(#isModal) then return 1
      
    end repeat
  end if
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHandleMouseDownEvent me, cl
  if pSuspendMouseEvents then exit
  
  retval = 0
  if (pAktiv = 1) then -- and pDreiDModus then
    repeat with n = pTableList.count down to 1
      
      if count(pTableList) < n then next repeat
      
      -- we only want to process overlays, models would get mMouse-XY events form the event router
      moname = string(pTableList[n].getaprop(#useModel))
      if moname.length then next repeat
      
      theRect = pTableList[n].getaprop(#myRect)
      if ilk(theRect) = #rect then
        if cl.inside(theRect) then
          
          sendAllSprites(#mResetKeyDownScript)
          
          if pKanal <> 0 then sprnum = me.spritenum
          else sprnum = 0
          
          if the keyDownscript <> "sendSprite("&sprnum&", #myKeyDown, the key, the keycode, "&QUOTE&pTableList[n].getaprop(#myName)&QUOTE&")" then
            pOldKeyDown = the keyDownscript
          end if
          if pKanal <> 0 then
            the keyDownscript = "sendSprite("&sprnum&", #myKeyDown, the key, the keycode, "&QUOTE&pTableList[n].getaprop(#myName)&QUOTE&")"
            
            cl = cl + point(pKanal.left, pKanal.top)
          end if
          
          call(#myMouseDown, pTableList[n].getaprop(#myScriptObject), cl)
          return 1
        end if
      end if
      
      if count(pTableList) < n then next repeat
      if pTableList[n].getaprop(#isModal) then return 1
    end repeat
  end if
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHandleMouseUpEvent me, cl
  if pSuspendMouseEvents then exit
  
  retval = 0
  if (pAktiv = 1) then -- and pDreiDModus then
    repeat with n = pTableList.count down to 1
      
      if count(pTableList) < n then next repeat
      -- we only want to process overlays, models would get mMouse-XY events form the event router
      moname = string(pTableList[n].getaprop(#useModel))
      if moname.length then next repeat
      
      
      theRect = pTableList[n].getaprop(#myRect)
      if ilk(theRect) = #rect then
        if cl.inside(theRect) and retval <> 1 then
          
          if pKanal <> 0 then cl = cl + point(pKanal.left, pKanal.top)
          
          call(#myMouseUp, pTableList[n].getaprop(#myScriptObject), cl)
          retval = 1
          
        else
          call(#myMouseUpOutside, pTableList[n].getaprop(#myScriptObject))
          
        end if
        
      else
        scr = pTableList[n].getaprop(#myScriptObject)
        if objectP(scr) then call(#myMouseUpOutside, scr)
        
      end if
      
      if count(pTableList) < n then next repeat
      if pTableList[n].getaprop(#isModal) then retval = 1
      
    end repeat
  end if
  return retval
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mHandleMouseUpOutsideEvent me
  
  retval = 0
  if (pAktiv = 1) then -- and pDreiDModus then
    repeat with n = pTableList.count down to 1
      
      if count(pTableList) < n then next repeat
      -- we only want to process overlays, models would get mMouse-XY events form the event router
      moname = string(pTableList[n].getaprop(#useModel))
      if moname.length then next repeat
      
      obj = pTableList[n].getaprop(#myScriptObject)
      if objectP(obj) then call(#myMouseUpOutside, obj)
      
    end repeat
  end if
  return retval
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx Key Events
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx route the key events to the parentscript
-- (I would rather have this in the parentscript, but I dunno how to set the keydownscript, that the parent script receives the key events :-()

on myKeyDown me, tk, kc, theName
  
  if call(#mHandleKeyEvent, mGetXScript(), tk, kc) then exit -- this is a movielevel handler, which gets keyevents first for example to quit the movie
  
  if not pAktiv then exit
  
  if voidP(theName) then
    repeat with n = pTableList.count down to 1
      if count(pTableList) < n then next repeat
      obj = pTableList[n].getaprop(#myScriptObject)
      if objectP(obj) then call(#mKeyDown, obj, tk, kc)
    end repeat
  else
    theTable = pTableList.getaprop(theName)
    if objectP(theTable) then
      obj = theTable.getaprop(#myScriptObject)
      if objectP(obj) then call(#mKeyDown, obj, tk, kc)
    end if
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- a mouseDown sends this call to all sprites, before setting the keydownscript to send only the clicked sprite the keyevents
on mResetKeyDownScript me
  if not(voidP(pOldKeyDown)) then
    the keyDownscript = pOldKeyDown
    pOldKeyDown = void
  end if
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- force set the key event to this sprite
-- this is only necessary in very few cases, where more than one tables are active
-- and under certain circumstances steal each other the keyboardfocus => refresh another table upon keyboard entrty in the first table
-- send a mouseUpOutside to 'the other table' after the refresh event and then set the focus back to the first with this handler

on mForceKeyDownScript me, tabname
  if count(pTableList) < 1 then exit
  
  if voidP(tabname) then tabname = pTableList[1].getaprop(#myName)
  
  sendAllSprites(#mResetKeyDownScript)
  
  if pKanal <> 0 then sprnum = me.spritenum
  else sprnum = 0
  
  if the keyDownscript <> "sendSprite("&sprnum&", #myKeyDown, the key, the keycode, "&QUOTE&tabname&QUOTE&")" then
    pOldKeyDown = the keyDownscript
  end if
  
  if pKanal <> 0 then
    the keyDownscript = "sendSprite("&me.spritenum&", #myKeyDown, the key, the keycode, "&QUOTE&tabname&QUOTE&")"
  end if
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____Animation_Handling
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mProcessAnimation me, theTable
  now = the milliseconds
  
  theAnimList = theTable.getaprop(#myAnimation)
  
  if objectP(theAnimList) then
    
    proz = (now - theAnimList.getaprop(#starttime)) / float(theAnimList.getaprop(#animationTime))
    
    if proz > 1 or proz = 1 then
      perc = 1
      
    else
      dynamic = theAnimList.getaprop(#animationDynamic)
      
      if symbolP(dynamic) then
        if dynamic <> #linear then
          if ilk(pTweenScript) <> #instance then pTweenScript = xscr().mGetInstance("EasingTweenPS")
          if ilk(pTweenScript) = #instance then
            
            ----------- convert the old style to new style
            if [#easeIn, #easeOut, #easeInOut].getPos(dynamic) then
              dynamic = symbol("m" & dynamic)
            end if
            ----------- // convert
            
            perc = call(dynamic, [pTweenScript], proz, theAnimList.getaprop(#easeParam1), theAnimList.getaprop(#easeParam2))
            if voidP(perc) then perc = proz
            
          else
            
            case dynamic of
              #easeOut:
                perc = mApplyDynamic(me, proz, #sinus)
              #easeIn:
                perc = mApplyDynamic(me, proz, #cosinus)
            end case
            
          end if
        end if
      end if
      
    end if
    
    
    dertyp = theAnimList.getaprop(#animationStyle)
    
    update3Dimage = []
    
    case dertyp of
      #transition:
        startpunkt = theAnimList.getaprop(#startwert)
        if ilk(startpunkt) <> #point then
          startpunkt = theTable.getaprop(#myRect)
          if ilk(startpunkt) <> #rect then startpunkt = rect(0,0,100,100)
          startpunkt = point(-startpunkt.width, -startpunkt.height)
          theAnimList[#startwert] = startpunkt
        end if
        
        endpunkt = theAnimList.getaprop(#endwert)
        if ilk(endpunkt) <> #point then
          endpunkt = theAnimList.getaprop(#endRect)
          if ilk(endpunkt) = #rect then
            endpunkt = point(endpunkt.left, endpunkt.top)
            theAnimList[#endwert] = endpunkt
          else
            endpunkt = point(0,0)
          end if
        end if
        
        --        if proz >= 1 then
        if proz > 1 or proz = 1 then
          derwert = endpunkt
        else
          derwert = startpunkt + ((endpunkt - startpunkt) * perc)
        end if
        
        mChangeLoc me, derwert, theTable, theAnimList
        
        
      #wipeTB, #wipeBT, #wipeLR, #wipeRL, #pushTB, #pushBT, #pushLR, #pushRL:
        
        --        proz = min(1.0, proz)
        
        theImage = theTable.getaprop(#myImg)
        if ilk(theImage) <> #image then
          if ilk(pMember) <> #member then exit
          if pMember.type <> #bitmap then exit
          theImage = pMember.image.duplicate()
          theTable[#myImg] = theImage
        end if
        
        theMaskImage = theTable.getaprop(#myMaskImg)
        if ilk(theMaskImage) <> #image then
          theMaskImage = theImage.extractAlpha()
          if ilk(theMaskImage) = #image then
            theTable[#myMaskImg] = theMaskImage
          else
            i = image(theImage.width, theImage.height, 32, 1)
            i.copyPixels(theImage, theImage.rect, theImage.rect)
            theImage = i
            theTable[#myImg] = theImage
            theMaskImage = theImage.extractAlpha()
            theTable[#myMaskImg] = theMaskImage
          end if
        end if
        
        theRect = theAnimList.getaprop(#endRect)
        if ilk(theRect) <> #rect then theRect = theImage.rect.offset(pKanal.left, pKanal.top)
        
        case dertyp of
          #pushTB:
            offs = point(0, (theRect.height * (perc - 1)))
          #wipeTB:
            offs = point(0, (theRect.height * perc))
          #pushBT:
            offs = point(0, (theRect.height * (1 - perc)))
          #wipeBT:
            offs = point(0, (theRect.height * -perc))
          #pushLR:
            offs = point((theRect.width * (perc - 1)), 0)
          #wipeLR:
            offs = point((theRect.width * perc), 0)
          #pushRL:
            offs = point((theRect.width * (1 - perc)), 0)
          #wipeRL:
            offs = point((theRect.width * -perc), 0)
        end case
        
        if [#pushTB, #pushBT, #pushLR, #pushRL].getPos(dertyp) > 0 then
          if pDreiDModus then
            i = theImage.duplicate()
            i.copyPixels(theImage, theImage.rect.offset(offs[1], offs[2]), theImage.rect)
          else
            if pKanal <> 0 then
              pMember.image.copyPixels(theImage, theImage.rect.offset(offs[1], offs[2]), theImage.rect)
              --              mPut pMember.image
            else
              if ilk(pMember) = #instance then call(#mDoCPIntoImage, [pMember],theImage, theImage.rect.offset(offs[1], offs[2]), theImage.rect)
            end if
          end if
          
          m = image(theMaskImage.width, theMaskImage.height, theMaskImage.depth, 0, theMaskImage.paletteRef)
          m.copyPixels(theMaskImage, theMaskImage.rect.offset(offs[1], offs[2]), theMaskImage.rect)
          
        else
          
          --          m = image(theMaskImage.width, theMaskImage.height, theMaskImage.depth, 0, theMaskImage.paletteRef)
          --          m.copyPixels(theMaskImage, theMaskImage.rect.offset(offs[1], offs[2]), theMaskImage.rect)
          
          m = theMaskImage.duplicate()
          m.fill(theMaskImage.rect.offset(offs[1], offs[2]), rgb(255, 255, 255))
          
        end if
        
        if pDreiDModus then
          i.setAlpha(m)
          update3Dimage.add(i)
          update3Dimage.add(theTable)
          update3Dimage.add(theRect)
        else
          if pKanal <> 0 then
            pMember.image.setAlpha(m)
            if not pMember.image.useAlpha then pMember.image.useAlpha = 1
            --            mPut m
          else
            if ilk(pMember) = #instance then call(#mSetAlphaImage, [pMember], m)
          end if
        end if
        
        
      #scaleTB, #scaleBT, #scaleLR, #scaleRL, #scaleLT, #scaleRT, #scaleLB, #scaleRB, #zoomTB, #zoomBT, #zoom:
        
        --        proz = min(1.0, max(0.01, proz))
        perc = max(0.01, perc)
        
        theRect = theAnimList.getaprop(#endRect)
        if ilk(theRect) <> #rect then
          theRect = pMember.image.rect.offset(pKanal.left, pKanal.top)
        end if
        
        
        if pDreiDModus then
          
          moname = string(theTable.getaprop(#useModel))
          if moname.length then -- model modus:
            case dertyp of
              #scaleTB, #scaleBT:
                v = vector(1, perc, 1)
              #scaleLR, #scaleRL: 
                v = vector(perc, 1, 1)
              otherwise
                v = vector(perc, perc, perc)
            end case
            mo = pMember.model(moname)
            
            if ilk(mo) = #model then mo.scale = v
            
          else -- overlay modus:
            
            camObj = theTable.getaprop(#myCamera)
            if voidP(camObj) then camObj = pKanal.camera
            
            tex = pMember.texture(pTextureBaseName&"_"&theTable.getaprop(#myName))
            olayIndex = mGetOlayIndex(me, camObj, tex)
            
            if olayIndex > 0 then
              versH = theRect.width/2.0
              versV = theRect.height/2.0
              
              case dertyp of
                #scaleTB, #zoomTB:
                  v = point((versH * (1 - perc)), 0)
                #scaleBT, #zoomBT:
                  v = point((versH * (1 - perc)), (versV * (1 - perc) * 2))
                #zoom:
                  v = point((versH * (1 - perc)), (versV * (1 - perc)))
                #scaleLR: 
                  v = point(0, (versV * (1 - perc)))
                #scaleRL:
                  v = point((versH * (1 - perc) * 2), (versV * (1 - perc)))
                #scaleRT:
                  v = point((versH * (1 - perc) * 2), 0)
                #scaleLB:
                  v = point(0, (versV * (1 - perc) * 2))
                #scaleRB:
                  v = point((versH * (1 - perc) * 2), (versV * (1 - perc) * 2))
                otherwise
                  v = point(0, 0) -- LT
              end case
              
              camObj.overlay[olayIndex].scale = perc
              camObj.overlay[olayIndex].loc = point(theRect.left, theRect.top) + v
              
            end if
            
          end if
          
        else -- 2-D modus
          if pKanal <> 0 then -- diese animation gibts ganz schlicht und ergreifend nicht im VM modus
            
            case dertyp of
              #scaleTB, #scaleBT:
                r = rect(0, 0, pMember.image.width, pMember.image.height * perc)
              #scaleLR, #scaleRL:
                r = rect(0, 0, pMember.image.width * perc, pMember.image.height)
              otherwise
                r = pMember.image.rect * perc
            end case
            
            versH = theRect.width/2.0
            versV = theRect.height/2.0
            
            case dertyp of
              #zoomTB:
                v = point((versH * (1 - perc)), 0)
              #zoomBT:
                v = point((versH * (1 - perc)), (versV * (1 - perc) * 2))
              #zoom:
                v = point((versH * (1 - perc)), (versV * (1 - perc)))
              #scaleRT, #scaleRL:
                v = point((versH * (1 - perc) * 2), 0)
              #scaleBT, #scaleLB:
                v = point(0, (versV * (1 - perc) * 2))
              #scaleRB:
                v = point((versH * (1 - perc) * 2), (versV * (1 - perc) * 2))
              otherwise
                v = point(0, 0) -- LT
            end case
            
            pKanal.rect = r.offset((theRect.left + v[1]), (theRect.top + v[2]))
            
          end if
          
        end if
        
        
    end case
    
    if update3Dimage.count > 2 then mUpdate3DImage me, update3Dimage[1], update3Dimage[2], update3Dimage[3]-- theImage, theTable, theRect
    
    
    -- now do the blend animation:
    delta = theAnimList.getaprop(#fullblend) - theAnimList.getaprop(#startblend)
    if delta <> 0 then
      --      if proz >= 1 then
      if proz > 1 or proz = 1 then
        mChangeBlend me, theAnimList.getaprop(#fullblend), theTable
      else
        derwert = theAnimList.getaprop(#startblend) + (delta * perc)
        mChangeBlend me, derwert, theTable
      end if
    end if
    
    
    -- call callback, if any specified for this state of animation
    callList = theAnimList.getaprop(#callList)
    if listP(callList) then
      anzCBacks = callList.count
      dellist = []
      repeat with nnn = 1 to anzCBacks
        thisCallbackList = callList[nnn]
        targetProz = thisCallbackList.getaprop(#calltime)
        if targetProz <= proz then
          theHandler = symbol(thisCallbackList.getaprop(#callHandler))
          if ilk(theHandler) = #symbol then
            call(theHandler, [thisCallbackList.getaprop(#callback)], thisCallbackList.getaprop(#params))
          end if
          dellist.add(nnn)
        end if
      end repeat
      
      repeat with nnn = dellist.count down to 1
        callList.deleteAt(dellist[nnn])
      end repeat
      
    end if
    
    -- -- SCHEISSNDRECK BUG !
    --    if proz >= 1 then
    if proz = 1 or proz > 1 then
      -- ready -> clean up
      pAnimationList.deleteOne(theTable)
    end if
    
  end if
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- alex am Mittwoch, 2. Juni 2004
on mProcessHideAnimation me, theTable
  
  theAnimList = theTable.getaprop(#myAnimation)
  -- alex am Mittwoch, 2. Juni 2004
  
  now = the milliseconds
  
  if objectP(theAnimList) then
    
    proz = (now - theAnimList.getaprop(#starttime)) / float(theAnimList.getaprop(#animationTime))
    perc = proz
    
    if proz > 1 or proz = 1 then
      perc = 1
      
    else
      
      dynamic = theAnimList.getaprop(#animationDynamic)
      
      if symbolP(dynamic) then
        if dynamic <> #linear then
          if ilk(pTweenScript) <> #instance then pTweenScript = xscr().mGetInstance("EasingTweenPS")
          if ilk(pTweenScript) = #instance then
            
            ----------- convert the old style to new style
            if [#easeIn, #easeOut, #easeInOut].getPos(dynamic) then
              dynamic = symbol("m" & dynamic)
            end if
            ----------- // convert
            
            perc = call(dynamic, [pTweenScript], proz, theAnimList.getaprop(#easeParam1), theAnimList.getaprop(#easeParam2))
            if voidP(perc) then perc = proz
            
          else
            
            case dynamic of
              #easeOut:
                perc = mApplyDynamic(me, proz, #sinus)
              #easeIn:
                perc = mApplyDynamic(me, proz, #cosinus)
            end case
            
          end if
        end if
      end if
      
    end if
    
    
    -- -- currently not implemented the backward animation...
    --    dertyp = theAnimList.getaprop(#animationStyle)
    -- .....
    
    
    -- now do the blend animation:
    delta = theAnimList.getaprop(#fullblend) - theAnimList.getaprop(#endblend)
    if delta <> 0 then
      
      --      if proz >= 1 then
      if proz > 1 or proz = 1 then
        
        mChangeBlend me, theAnimList.getaprop(#endblend), theTable
      else
        derwert = theAnimList.getaprop(#endblend) + (delta * (1 - perc))
        mChangeBlend me, derwert, theTable
      end if
    end if
    
    --    if proz >= 1 or integer(proz) = 1  then
    if proz = 1 or proz > 1 then
      
      -- ready -> clean up
      
      callback = theTable.getaprop(#callbackInstance)
      
      if theAnimList.getaprop(#dreiDmode) = 1 then
        
        moname = string(theAnimList.getaprop(#useModel))
        if moname.length then
          mRemove3DModel me, moname, theAnimList
        else
          mRemove3DOverlay me, theTable.getaprop(#myName), theTable.getaprop(#myCamera)
        end if
        
        if (count(pTableList) < 1) then
          if pKanal <> 0 then sendSprite(me.spritenum, #mRemoveFromEventList, me)
        end if
        
        if ilk(callback) = #instance then call(#mRemoveTableFromScreen, [callback], theTable.getaprop(#myName))
        
      else
        --        if pKanal <> 0 then pKanal.locV = -1000
        
        if ilk(pMember) = #instance then
          call(#mRemoveTableFromScreen, [pMember], theTable.getaprop(#myName))
          
        else if theAnimList.getaprop(#removeAll) or (count(pTableList) < 1) then
          if pKanal <> 0 then pKanal.locV = -1000
          pKanal.blend = 100
          
          -- release the memory for the #bitmap:
          if ilk(pMember) = #member then
            if pMember.type = #bitmap then
              pMember.image = image(1,1,1)
            end if
          end if
          
          if ilk(callback) = #instance then call(#mRemoveTableFromScreen, [callback], theTable.getaprop(#myName))
          
        end if
        
      end if
      
      pAnimationList.deleteOne(theTable)
    end if
    
  end if
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mChangeBlend me, newBlend, table
  
  if pDreiDModus then
    
    moname = string(table.getaprop(#useModel))
    if moname.length then -- model modus:
      
      mo = pMember.model(moname)
      if ilk(mo) = #model then mo.shaderlist[1].blend = newBlend
      
    else -- overlay modus:
      
      camObj = table.getaprop(#myCamera)
      if voidP(camObj) then camObj = pKanal.camera
      
      tex = pMember.texture(pTextureBaseName&"_"&table.getaprop(#myName))
      olayIndex = mGetOlayIndex(me, camObj, tex)
      if olayIndex > 0 then camObj.overlay[olayIndex].blend = newBlend
      
    end if
    
    sendSprite(me.spritenum, #mSuspendAliasing)
    
  else -- 2-D modus
    if pKanal <> 0 then
      pKanal.blend = newBlend
    else if ilk(pMember) = #instance then
      call(#mSetTableBlendValue, [pMember], newBlend, table.getaprop(#myName))
    end if
  end if
  
end

on mChangeLoc me, newLoc, table, animList
  
  if pDreiDModus then
    
    moname = string(table.getaprop(#useModel))
    if moname.length then -- model modus:
      
      mo = pMember.model(moname)
      if ilk(mo) = #model then
        -- still to do:
        -- translate 2-D position in 3-D coords and move model
        
      end if
      
    else -- overlay modus:
      
      camObj = table.getaprop(#myCamera)
      if voidP(camObj) then camObj = pKanal.camera
      
      tex = pMember.texture(pTextureBaseName&"_"&table.getaprop(#myName))
      olayIndex = mGetOlayIndex(me, camObj, tex)
      if olayIndex > 0 then camObj.overlay[olayIndex].loc = newLoc
      
    end if
    
  else -- 2-D modus
    --    r = table.myImg
    
    if pKanal <> 0 then
      r = animList.getaprop(#endRect)
      if ilk(r) <> #rect then r = pKanal.rect
      pKanal.rect = rect(newLoc[1], newLoc[2], (newLoc[1] + r.width), (newLoc[2] + r.height))
      
    else if ilk(pMember) = #instance then
      call(#mSetTableLoc, [pMember], newLoc, table, animList)
      
    end if
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCheckWoody me
  if voidP(pWoody) then
    prodVers = the productVersion
    offs = offset(".", prodVers)
    if offs > 0 then prodVers = char 1 to offs-1 of prodVers
    prodVers = integer(prodVers)
    pWoody = (prodVers >= 10)
  end if
  return pWoody
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCreateTimeout me, theName, theDuration, theHandler, theTarget
  
  return call(#mCreateTimeout, mGetXScript(), theName, theDuration, theHandler, theTarget)
  
  if mCheckWoody(me) = 1 then
    return timeout().new(theName, theDuration, theHandler, theTarget)
  else
    return timeout(theName).new(theDuration, theHandler, theTarget)
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on _____3_D_FUNCTIONS
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCreateOverlay me, whichImg, theTable
  if pMember.type <> #shockwave3d then return 0
  
  if ilk(whichImg) <> #image then return 0
  
  texname = theTable.getaprop(#myName)
  if voidP(texname) then texname = "tabelle1"
  texname = pTextureBaseName&"_"&texname
  
  breite = whichImg.width
  hoehe = whichImg.height
  powerbreite = mGetNextPowerOfTwo(me, breite)
  powerhoehe = mGetNextPowerOfTwo(me, hoehe)
  
  if (powerbreite <> breite) or (powerhoehe <> hoehe) then
    listOfImageAndMask = mCreatePowerImg(me, whichImg, powerbreite, powerhoehe)
    whichImg = listOfImageAndMask[1]
    theTable[#myImg] = whichImg
    theTable[#myMaskImg] = listOfImageAndMask[2]
  else
    
    -- alex am 22.02.07 um 18:35:52
    --------------------------------------------------------
    theTable[#myImg] = whichImg
    if whichImg.useAlpha = 1 then
      theTable[#myMaskImg] = whichImg.extractAlpha()
    else
      mimg = image(whichImg.width, whichImg.height, 8, 0, #grayscale)
      mimg.fill(mimg.rect, rgb(0,0,0))
      theTable[#myMaskImg] = mimg
    end if
    
    -- theTable.deleteProp(#myImg)
    
    -- // alex am 22.02.07 um 18:35:52
    --------------------------------------------------------
    
  end if
  
  tex = pMember.texture(texname)
  if voidP(tex) then tex = pMember.newTexture(texname, #fromImageObject, whichImg)
  else tex.image = whichImg
  
  texform = theTable.getaprop(#texrenderformat)
  if not voidP(texform) then
    tex.renderformat = mGetTextureRenderFormat(me, texform)
  else
    if whichImg.depth = 32 then
      if whichImg.usealpha = 1 then
        tex.renderformat = mGetTextureRenderFormat(me, #rgba8888)
      else
        tex.renderformat = #rgba8880
      end if
    end if
    --  else tex.renderformat = getRendererServices().textureRenderFormat -- default
  end if
  
  tex.quality = #low
  
  moname = string(theTable.getaprop(#useModel))
  if moname.length then
    
    mo = pMember.model(moname)
    if ilk(mo) = #model then
      
      tex.quality = #high
      
      shlindex = theTable.getaprop(#shaderListIndex)
      if voidP(shlindex) then
        shlindex = 1
        theTable.setaprop(#shaderListIndex, shlindex)
      end if
      shd = mo.shaderlist[shlindex]
      
      texindex = theTable.getaprop(#textureListIndex)
      if voidP(texindex) then texindex = 2
      
      shd.texturelist[texindex] = tex
      
      shd.texturerepeatlist[texindex] = 0
      
      texblendfunction = theTable.getaprop(#textureblendfunction)
      if voidP(texblendfunction) then texblendfunction = #blend
      shd.blendFunctionList[texindex] = texblendfunction
      if texblendfunction = #blend then shd.blendConstantList[texindex] = 100
      
      theblendsourcelist = theTable.getaprop(#blendsourcelist)
      if ilk(theblendsourcelist) = #symbol then
        if [#alpha, #constant].getPos(theblendsourcelist) > 0 then
          shd.blendsourcelist[texindex] = theblendsourcelist
        end if
      end if
      
    end if
    
  else
    
    camObj = theTable.getaprop(#myCamera)
    if voidP(camObj) then camObj = pKanal.camera
    
    olayIndex = mGetOlayIndex(me, camObj, tex)
    
    theRect = theTable.getaprop(#myRect)
    if ilk(theRect) <> #rect then
      theRect = call(#mGetCurrentRect, theTable.getaprop(#myScriptObject))
      if ilk(theRect) <> #rect then
        theRect = whichImg.rect
      else
        theTable[#myRect] = theRect
      end if
    end if
    
    if olayIndex = 0 then
      camObj.addoverlay(tex, point(theRect.left, theRect.top), 0)
    else
      camObj.overlay[olayIndex].loc = point(theRect.left, theRect.top)
    end if
    
    --    olayIndex = mGetOlayIndex(me, camObj, tex)
    --    if olayIndex > 0 then camObj.overlay[olayIndex].blend = 76
    
    --  sendSprite(me.spritenum, #mAddToEventList, me, 0)
    
  end if
  
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mCreatePowerImg me, whichImg, powerbreite, powerhoehe
  i = image(powerbreite, powerhoehe, 32, 1)
  maske = image(powerbreite, powerhoehe, 8, 0, #grayscale)
  maske.fill(whichImg.rect, rgb(0,0,0))
  
  if whichImg.useAlpha = 1 then
    maske.copyPixels(whichImg.extractalpha(), whichImg.rect, whichImg.rect)
    
    i.copyPixels(whichImg, whichImg.rect, whichImg.rect, [#usealpha:0])
    
  else
    i.copyPixels(whichImg, whichImg.rect, whichImg.rect) 
  end if
  
  i.setAlpha(maske)
  
  i.useAlpha = 1
  
  
  return [i, maske]
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetOlayIndex me, camObj, tex
  olaycnt = camObj.overlay.count
  repeat with olayIndex = 1 to olaycnt
    if camObj.overlay[olayIndex].source = tex then exit repeat
  end repeat
  if olayIndex > olaycnt then return 0
  else return olayIndex
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetTexname me
  ich = string(me)
  return "TDD_OT_"&ich.word[ich.word.count]
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mRemove3DModel me, moname, theTable
  if ilk(theTable) <> #proplist then exit
  
  mo = pMember.model(moname)
  if ilk(mo) = #model then
    
    shlindex = theTable.getaprop(#shaderListIndex)
    if voidP(shlindex) then shlindex = 1
    shd = mo.shaderlist[shlindex]
    
    texindex = theTable.getaprop(#textureListIndex)
    if voidP(texindex) then texindex = 2
    
    tex = shd.texturelist[texindex]
    
    shd.texturelist[texindex] = void
    
    if ilk(tex) = #texture then
      pMember.deleteTexture(tex.name)
    end if
    
    sendSprite(me.spritenum, #mEventRouter_RemoveFromRollOverList, mo)
    
    ud = mo.userdata
    scr = ud.getaprop(#myParentScript)
    if listP(scr) then scr.deleteOne(me)
    
    sendSprite(me.spritenum, #mSuspendAliasing)
    
  end if
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mRemove3DOverlay me, tabName, camObj
  if voidP(camObj) then camObj = pKanal.camera
  
  tex = pMember.texture(pTextureBaseName&"_"&tabName)
  olayIndex = mGetOlayIndex(me, camObj, tex)
  if olayIndex > 0 then
    camObj.removeoverlay(olayIndex)
    pMember.deleteTexture(tex.name)
    
    sendSprite(me.spritenum, #mSuspendAliasing)
    
  end if
end


-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- xxxxxxxxxxxxxxxxxx map clickloc to 2-D image coordinates:

on mMapPointToTexture me, iSectList, anImage, tTextureLayer --------------------------------------
  -- Many Thanks to James Newton <james.newton@openspark.com> for sharing this handler !
  
  -- RETURNS the point in the Bitmap member used by the texture
  -- defined implicitly in <iSectList>
  --
  -- INPUT:
  -- <iSectList> should be a property list of the format:
  --   [#model:         model("model name"),
  --    #distance:      <float>,
  --    #isectPosition: <vector>,
  --    #isectNormal:   <vector>,
  --    #meshID:        <integer>,
  --    #faceID:        <integer>,
  --    #vertices:     [<vector>, <vector>, <vector>],
  --    #uvCoord:      [#u: <float>, #v: <float>]]
  --
  -- When you use aCamera.modelsUnderLoc(aLoc, #detailed) or
  -- aMember.modelsUnderRay(aPoint, aVector, #detailed), the result is
  -- a linear list of lists with this format.
  ---------------------------------------------------------------------
  
  tModel    = iSectList.model
  if voidP(tModel) then return #modelWasDeleted
  
  
  tResource = tModel.resource
  
  isMesh = (tResource.type = #mesh)
  
  if not isMesh then
    -- We need to use the mesh deform modifier to get texture data
    if not((tModel.modifier).getPos(#meshdeform))then
      -- Add mesh deform modifier... but remember to remove it later
      tModel.addModifier(#meshdeform)
      isModified = TRUE
    end if
  end if
  
  tShader  = tModel.shaderList[iSectList.meshID]
  
  if voidP(tTextureLayer) then tTextureLayer = 1
  tTexture = tShader.textureList[tTextureLayer]
  
  if voidP(tTexture) then
    return 0
  end if
  
  case tTexture.type of
    #importedFromFile:
      -- Exercise left to the reader
      return #importedFromFile
      
    #fromImageObject:
      -- You may be able to continue if you have kept a copy of the
      -- image, or, at the very least, its initial dimensions
      case ilk(anImage) of
        #image:
          tWidth  = anImage.width
          tHeight = anImage.height
          
        #propList, #instance:
          -- Check whether we can extract width and height properties
          tWidth  = anImage[#width]
          if integerP(tWidth) then
            tHeight = anImage[#height]
          end if
          
          if not integerP(tHeight) then
            -- No width or height data is available
            return #fromImageObject
          end if
          
        otherwise:
          return #fromImageObject
      end case
      
      
    #fromCastMember:
      tMember = tTexture.member
      tWidth  = tMember.width
      tHeight = tMember.height
  end case
  
  tFace      = iSectList.faceID
  tUVCoord   = iSectList.uvCoord
  
  -- Determine how the iSect data maps to this particular face
  if isMesh then
    tCoordList = tResource.textureCoordinateList
    tFaceList  = tResource.face[tFace].textureCoordinates
    
  else
    -- tCoordList = tModel.meshdeform.mesh[iSectList.meshID].textureCoordinateList
    tCoordList = tModel.meshdeform.mesh[iSectList.meshID].textureLayer[tTextureLayer].textureCoordinateList
    tFaceList  = tModel.meshdeform.mesh[iSectList.meshID].face[tFace]
    if isModified then
      -- Remove the modifier now that it has done its job
      tModel.removeModifier(#meshdeform)
    end if
  end if
  
  -- tCoordList will be a list of lists, each containing two floating-
  -- point numbers between 0.0 and 1.0.  The first number defines the
  -- relative horizontal position of a point in the texture, the
  -- second number defines the relative vertical point.  The origin
  -- point [0.0, 0.0] is in the bottom left hand corner.
  --
  -- tFaceList will be a list with three integer values [a, b, c]
  -- These values determine which entry in tCoordList is used by the
  -- chosen face.  The first entry <a> defines the origin.  The u
  -- value increases from <a> to <b>.  Any point on the line between
  -- <a> and <b> will have a v value of zero.  The v value increases
  -- from <a> to <c>.  Any point on the line between <a> and <b> will
  -- have a v value of zero.
  
  -- Calculate the position of the points <a>, <b> and <c> within the
  -- Bitmap member.
  
  tLocA = tCoordList[tFaceList[1]] -- [<float>, <float>]
  tLocA = point(tLocA[1] * tWidth, (1 - tLocA[2]) * tHeight)
  
  tLocB = tCoordList[tFaceList[2]] -- [<float>, <float>]
  tLocB = point(tLocB[1] * tWidth, (1 - tLocB[2]) * tHeight)
  
  tLocC = tCoordList[tFaceList[3]] -- [<float>, <float>]
  tLocC = point(tLocC[1] * tWidth, (1 - tLocC[2]) * tHeight)
  
  tUVector = (tLocB - tLocA) * tUVCoord.u -- actually a 2D point...
  tVVector = (tLocC - tLocA) * tUVCoord.v -- ... rather than a vector
  
  -- Start from the origin <a>, move first in the u direction then in
  -- the v direction to end up at the point in the texture
  
  --  return tLocA + tUVector + tVVector
  P = tLocA + tUVector + tVVector
  repeat while P[1] > tWidth
    P[1] = P[1] - tWidth
  end repeat
  repeat while P[2] > tHeight
    P[2] = P[2] - tHeight
  end repeat
  return P
end



-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- check if rgba8888 is available and if not try if rgba4444 is possible

on mGetTextureRenderFormat me, val
  if val <> #rgba8888 then RETURN val
  
  globs = call(#mGetGlobalList, mGetXScript())
  GHI = globs.getAProp(#supTexRenderFormats)
  if not(listP(GHI)) then 
    GHIL = getRendererServices().getHardwareInfo()
    GHI = GHIL[#supportedTextureRenderFormats]
    globs[#supTexRenderFormats] = GHI
  end if
  
  if getPos(GHI, val) = 0 then
    if getPos(GHI, #rgba4444) then
      RETURN #rgba4444
    end if
  end if
  
  RETURN val
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- xxxxxxxxxxxxxxxxxx Ease in, Ease out with sin() and cos()
on mApplyDynamic me, proz, methode
  proz = min(1.0, max(0.0, proz))
  
  case methode of
    #easeIn:
      return 1 - cos(pi()/2 * proz)
    #easeOut:
      return sin(pi()/2 * proz)
    #easeInOut:
      return (1 - ((cos(pi() * proz) + 1) / 2.0))
  end case
  
  return proz
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mGetNextPowerOfTwo me, breite
  if ilk(pPowerOfTwoList) <> #list then
    pPowerOfTwoList = [2,4,8,16,32,64,128,256,512,1024]
    pPowerOfTwoList.sort()
  end if
  retval = pPowerOfTwoList.findPosNear(integer(breite))
  return pPowerOfTwoList[min(retval, pPowerOfTwoList.count)]
end

