Subroutine SRP_Redirect_OLE_Events(void)
/******************************************************************************************************** 

    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 Redirect OLE Events

    Description :
    
	Tags		:	[SRP]

    Parameters  :

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

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

$insert SRP_APP_INSERTS

// Loop through all the controls in the window
Ctrls = Get_Property(@Window, "CTRLMAP")
NumCtrls = Count(Ctrls, @FM) + (Ctrls NE "")
For Loop = 1 to NumCtrls
	Ctrl = Ctrls<Loop>
	Type = Get_Property(Ctrl, "TYPE")
	GoSub Find_App_Promoted_Event
	
	If Type EQ "OLECONTROL" then
		// Redirect the OLE event to the win level promoted event
		Qualify = ""
		Qualify<1> = 1
		
		If Get_Property(@Window, "@DIALOG_BOX") EQ 1 then
			// Modal Dialog Boxes cannot process synchronous events so the asynchronous flag must be used.
			// There is no way to programmatically detect if the current window is running as a dialog box.
			// Therefore the CREATE event in the current window's commuter module should set this UDP in
			//  order for this to be set correctly here.
			Qualify<4> = 0	; // Asynchronous event processing
		end else
			Qualify<4> = 2	; // Synchronous event processing
		end
	
		If EventExists then
			Qualify<2> = 13:"*":EventKey
		end
		Send_Message(Ctrl, "QUALIFY_EVENT", "ALL_OLES", Qualify)
		
		// Qualify EditTable LostFocus and GotFocus events as asynchronous. This worksaround a known bug where
		// clicking away from a window with an EditTable and then back causes a double-click to fire.
		Qualify<4> = 0
		Send_Message(Ctrl, "QUALIFY_EVENT", "OLE.LostFocus", Qualify)
		Send_Message(Ctrl, "QUALIFY_EVENT", "OLE.GotFocus", Qualify)
		
		// Turn on the WS_CLIPCHILDREN style but to avoid OLE control flicker when windows
		// are being resized. This is a problem introduced in OpenInsight 7.1
		Style = Get_Property(Ctrl, "STYLE")
		If Style[1, 2] _EQC "0x" then
			Convert @LOWER.CASE to @UPPER.CASE in Style
			Style = IConv(Style[3, 99], "MX")
		end
		Style = BitOr(Style, WS_CLIPCHILDREN$)
		Set_Property(Ctrl, "STYLE", Style)
		
	end
			
Next Loop
	
// Turn on the FlickerFree property for the OLE_TAB control (if it exists on the form. If not, then this won't do anything.)
Set_Property(@Window:".OLE_TAB", "OLE.FlickerFree", Yes$)

Return


Find_App_Promoted_Event:
	EventExists = No$ ; // Assume no for now
	
	NumApps = Count(@APPID, @FM) + (@APPID NE "")
	For i = 1 to NumApps
		EventKey = @APPID<i>:"*..OIWIN*"
		EventExists = Xlate("SYSREPOSEVENTEXES", EventKey, 0, "X")
	Until EventExists
	Next i
return
