Function SRP_Promoted_Events(CtrlEntId, Event, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15)
/******************************************************************************************************** 

    This program is proprietary and is not to be used by or disclosed to others, nor is it to
    be copied without written permission from SRP Computer Solutions, Inc.

    Name        :   SRP Promoted Events

    Description :	Not the same as the normal FrameWorks version - will only execute for specific
					windows.  All other windows will move through with no additional processing.
    
	Tags		:	[SRP]

    Parameters  :

    History (Date, Initials, Notes)
        09/08/09    fjt     Initial development

********************************************************************************************************/

$insert SRP_APP_INSERTS
$insert SRP_EVENT_SETUP
$insert SRP_LSL2_INSERTS
$insert FORM_METRICS_EQUATES

Declare function   Database_Services, Datetime
Declare subroutine Database_Services

EventFlow = Get_Property(@Window, "@EVENTFLOW")
If EventFlow EQ "" then EventFlow = EVENT_CONTINUE$

* If Event EQ 'CREATE' then
*    // Log form use metrics
*    EventTime = Datetime()
*    Database_Services('WriteDataRow', 'FORM_METRICS', Window:'*':@User4:'*':EventTime, '', True$, False$, False$)
* end
* Begin Case
* 	Case Window[1,3] EQ "DBW"
*	    // Having to skip this as it is crashing DBW windows
*	    If @User4 NE 'DANIEL_ST' then
*            If EventType EQ "OLE" then GoSub Transfer_Params
*            GoSub Commuter_Module
*            If EventType EQ "OLE" then GoSub Restore_Params
*	    end
* End Case

* If EventFlow EQ EVENT_CONTINUE_NO_SYSTEM$ then EventFlow = EVENT_STOP$

Return EventFlow



Commuter_Module:
	// Pass event on to the window's commuter module if it exists.
	// Note: It is critical that commuter modules be named in this format: WindowName_EVENTS
	// Also, this code will not execute commuter modules for SYSPROG based windows.
	
	// Requires that a commuter module ALWAYS exists
	ObjExists = Yes$
	SysObjKey = "$":Window:"_EVENTS":"*":@APPID<1>
	
* 	NumApps = Count(@APPID, @FM) + (@APPID NE "")
* 	For i = 1 to NumApps
*		SysObjKey = "$":Window:"_EVENTS":"*":@APPID<i>
*		ObjExists = (Index(CommuterList, SysObjKey, 1) GT 0)
* 	Until ObjExists
* 	Next i

* 	If Not(ObjExists) then
*		For i = 1 to NumApps
*			SysObjKey = "$":Window:"_EVENTS":"*":@APPID<i>
*			ObjExists = (Xlate("SYSOBJ", SysObjKey, 0, "X") GT "")
*		Until ObjExists
*		Next i
*		If (ObjExists) then CommuterList<-1> = SysObjKey
* 	end
	
	If (ObjExists) then
		CommuterModule = Window:"_EVENTS"
		Transfer EventFlow to OrigEventFlow ; // Save the current event flow.
		EventFlow = Function(@CommuterModule(CtrlEntId, Event, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15))
		// If the commuter module returned EVENT_CONTINUE, then this means no special event flow was returned. Therefore, restore the event flow that existed before the commuter module call.
		If EventFlow EQ EVENT_CONTINUE$ then Transfer OrigEventFlow to EventFlow
	end
return


Transfer_Params:
	// ActiveX controls pass their own event names through Param1. Modify the parameter values
	// so they conform to OpenInsight event parameter values. This will allow commuter modules
	// to be structured the same for OpenInsight event and ActiveX (OLE) events.
	Transfer Param1  to Event
	Transfer Param2  to Param1
	Transfer Param3  to Param2
	Transfer Param4  to Param3
	Transfer Param5  to Param4
	Transfer Param6  to Param5
	Transfer Param7  to Param6
	Transfer Param8  to Param7
	Transfer Param9  to Param8
	Transfer Param10 to Param9
	Transfer Param11 to Param10
	Transfer Param12 to Param11
	Transfer Param13 to Param12
	Transfer Param14 to Param13
	Transfer Param15 to Param14
return


Restore_Params:
	// Restore the event parameters so the rest of the event chain will see the parameter values
	// as they were originally created by OpenInsight. This will also prevent the parameter values
	// from being transferred multiple times in case there are multiple OLE promoted event handlers
	// (e.g. APPNAME*..OIWIN* and APPNAME*OLE..OIWIN*).
	Transfer Param14 to Param15
	Transfer Param13 to Param14
	Transfer Param12 to Param13
	Transfer Param11 to Param12
	Transfer Param10 to Param11
	Transfer Param9  to Param10
	Transfer Param8  to Param9 
	Transfer Param7  to Param8 
	Transfer Param6  to Param7
	Transfer Param5  to Param6
	Transfer Param4  to Param5
	Transfer Param3  to Param4
	Transfer Param2  to Param3
	Transfer Param1  to Param2
	Transfer Event   to Param1
	Event			  = EventType
return
