//-------------- Modification Log -------------------------------------------
// CPY 8/14/2007 QA70-10218 INI_DRAG_AND_DROP
// Hong QA80-11640 v8.0982b SUPPORT_DRAG_AND_DROP_THEME_FOR_EASY_SHARING
// CPY 12/6/06 QA70-12736 LT_NEED_MORE_CNTRL_ON_ALLOWING_OC_FUNCS
// Hong 01/13/09 v8.0995d FIX_DRAG_AND_DROP_XF_FAIL
// EJP 2009-01-13 v8.0996 QA80-12959 LABTALK_INSTALL_AND_UNINSTALL_OPX
// Sim 07-02-2009 QA80-13869 SUPPORT_DRAG_AND_DROP_OMC_FILE
// Kenny 11/10/2009 QA81-14624 SUPPORT_DRAG_AND_DROP_MULTIPLE_ORIGIN_FILES
// EJP 2010-01-13 QA81-14672 DRAG_DROP_OIF_FILE
//---------------------------------------------------------------------------

[OnOpenOPK]
dll -a OPack OPack; // temporary code

Opack.Unpack.Uninstall$=""; // SY 04-05-2004, reset "Uninstall" property before unpack an OPK file to avoid write junk into opkmlist.ini 
OPack.FileName$=%1;

OPack.TargetFolder$="*"; // unpack into temp folder
i = OPack.Unpack();
if( i != 0 ) // if unpack error
{
	Run.Section(,OnOPKError);
	return 1;
}
///i = OPack.FindFile(OPKSetup.ogs,Z);
i = OPack.FindSetup(Z);
if( i > 0 ) // if an OPKSetup.ogs was unpacked
{
	%a=OPack.TargetFolder$;
	i = Run.Section(%A%Z,OnBeforeSetup);
}
else
{
	i = 0; // continue setup
}

OPack.Undo(); // always remove temp folder

if( i == 1 ) // if installation should NOT continue
{
	return 1;
}

//OPack.TargetFolder$=""; // unpack into Origin folder - OnAfterSetup not running

OPack.TargetFolder$=%Y; // GJL & SDB 7/30/03: unpack into user folder - allows OnAfterSetup to run
i = OPack.Unpack();
if( i != 0 ) // if unpack error
{
	Run.Section(dofile,OnOPKError);
	return 1;
}
else
{
	type -b $OPK.UnpackSuccess;
}
//i = OPack.FindFile(OPKSetup.ogs,Z);
i = OPack.FindSetup(Z);
if( i > 0 ) // if an OPKSetup.ogs was unpacked
{
	%W=OPack.TargetFolder$;
	i = Run.Section(%W%Z);
	i = Run.Section(%W%Z,OnAfterSetup);
}

OPack.Reset();
File.Delete(%Y%Z); // Delete the OPKSetup file.

return 0; // success


[OnOPKError]
switch(i)
{
case 1:
	%a = OPack.FileName$;
	%z = $OPK.ErrUserAccess;
	break;
case 2:
	%a = OPack.FileName$;
	%z = $OPK.ErrFileIO;
	break;
case 3:
	%a = OPack.FileName$;
	%z = $OPK.ErrHeaderFile;
	break;
case 4:
	%a = OPack.ErrorFileName$;
	%z = $OPK.ErrExpandFile;
	break;
case 5:
	%a = OPack.FileName$;
	%z = $OPK.ErrInvalidFile;
	break;
case 6:
	%a = OPack.ErrorFileName$;
	%z = $OPK.ErrCreateFile;
	break;
default:
	%a = OPack.FileName$;
	%z = $OPK.ErrFileIO;
	break;
}

// The following 2 lines make a multi-line message.
%z=%z
%a;

type.msgBox(%z,OPack);
return 0;
//------ CPY 8/14/2007 QA70-10218 INI_DRAG_AND_DROP
// will think about this later
//[OnOpenINI]
//	string strPath$ = "%1";
//	type "Drag and drop from:" + strPath$;
//------


[OnOpenOPX]
	/// EJP 2009-01-13 v8.0996 QA80-12959 LABTALK_INSTALL_AND_UNINSTALL_OPX
	///	/// EJP 2007-06-21 v8.0647 QA70-9103 DRAG_DROP_OPX_NEED_NOTIFY_SUCCESS
	///	////// EJP 2006-10-17 v8.0497 INSTALL_OPX_ON_DRAGDROP
	///	///instOPX fname:="%1";
	///	////// end INSTALL_OPX_ON_DRAGDROP
	///	instOPX fname:="%1" verbose:=1;
	///	/// end DRAG_DROP_OPX_NEED_NOTIFY_SUCCESS
	run -opxi %1;
	/// end LABTALK_INSTALL_AND_UNINSTALL_OPX

[OnOpenOGS]
// ed is mapped to OLbTEdit in Origin.ini by default
	ed.open(%1);
	return 0;

[OnOpenCPP]
	ed.open(%1);
	return 0;

[OnOpenC]
	ed.open(%1);
	return 0;
	
[OnOpenH]
	ed.open(%1);
	return 0;

///---Sim 12-28-2006 USE_SPC_IMPORT_XF remove
//[OnOpenSPC]
	//%W=doc.DropWinName$;
	//i = exist(%W);
	//switch(i)
	//{
	//case 2:// wks
		//// we will always activate the window
		//win -o %W {
			//open -s %1;
		//}
		//break;
	//case 3: // graph
		//win -t Data Create;// create.otw is hidden
		//open -sn %1;
		//// select all
		//%A=%H;
		//// next we will plot all into layer, we need to make it active as well.
		//win -a %W;
		//if(doc.DropLayer>0)	// drop into particular layer
		//{
			//layer -o doc.DropLayer {
				//layer -w %A;
			//}
		//}
		//else
			//layer -w %A;	
		//break;
	//case 5: // matrix
		//if(doc.DropIndex > 1)
			//win -T Matrix;
		//else
			//win -a %W;
		//open -s %1;
		//break;
	//default:
		//win -t Data;
		//open -sn %1;
	//}
///---END USE_SPC_IMPORT_XF

[disable OnOpenBMP]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[disable OnOpenGIF]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[disable OnOpenJPG]
	Image.FileName$="%1";
	run.section(,IMGOpen);
	
[disable OnOpenPCX]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[disable OnOpenPNG]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[disable OnOpenPSD]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
	
[disable OnOpenTGA]
	Image.FileName$="%1";
	run.section(,IMGOpen);
	
[disable OnOpenTIF]
	Image.FileName$="%1";
	run.section(,IMGOpen);
	
[disable OnOpenWMF]
	Image.FileName$="%1";
	run.section(,IMGOpen);	

[disable OnOpenXPM]
	Image.FileName$="%1";
	run.section(,IMGOpen);	

[disable OnOpenXWD]
	Image.FileName$="%1";
	run.section(,IMGOpen);	
					
[ObsoleteOnOpenMPJ]
	%A = "%1";
	run.section(ORDMNTB,OnDrop);

[ObsoleteOnOpenMTW]
	%A = "%1";
	run.section(ORDMNTB,OnDrop);
					
[ObsoleteOnOpenJNB]
	%A = "%1";
	run.section(ORDJNB,OnDrop);
	
/// Kenny 11/10/2009 QA81-14624 SUPPORT_DRAG_AND_DROP_MULTIPLE_ORIGIN_FILES
[LoadDragNDrop]
	if(run.LoadOC(OriginLab\dragNdrop.c, 16) != 0)
	{
		type "failed to load dragNdrop.c, please contact Orignlab tech service about this problem.";
		return 0;
	}
	return 1;
/// End QA81-14624 SUPPORT_DRAG_AND_DROP_MULTIPLE_ORIGIN_FILES

[OnOpenFDF]
	/// Kenny 11/10/2009 QA81-14624 SUPPORT_DRAG_AND_DROP_MULTIPLE_ORIGIN_FILES
	//%A="%1";
	//dialog.start(Otools,SelectCat);
	rr = run.section(, LoadDragNDrop);
	if (rr == 0)
		return 0;
	run -oc HandleDragNDropFDF();
	/// End QA81-14624 SUPPORT_DRAG_AND_DROP_MULTIPLE_ORIGIN_FILES
	return 0;

[IMGOpen]
	//ty "Openning %1...";
	%W=doc.DropWinName$;
	i = exist(%W);
	if(doc.DropIndex > 1)
		i = 0;// cannot drop more than 1 into a matix, treat as drop into open space
	switch(i)
	{
	case 5:// matrix
		// we will activate the window if point to existing matrix
		win -a %W;
		run.section(ImgFile,LoadImageIntoMatrix);
		break;
	case 3: // graph
	case 11: // layout
		win -a %W;
		run.section(ImgFile,LoadImageIntoGrObject);
		break;
	default: // new matrix
		%A = System.Matrix.DefTemplate$;
		win -T Matrix "%A";
		run.section(ImgFile,LoadImageIntoMatrix);
	}

[FileTypeRegistration]
; set OGS = 1 to tell Origin to register this extension for LabTalk editor
; to open ogs script file
; set to 0 will tell Origin not to register it

;OGS=1
	 
SPC=1

; EJP 2006-09-13 v8.0481 QA70-8966 SUPPORT_DRAG_DROP_XFUNC
[OnOpenOXF]
	/// Hong 01/13/09 v8.0995d FIX_DRAG_AND_DROP_XF_FAIL
	//i = install_xfunction("%1");
	run -oc {i = install_xfunction("%1")};
	/// end FIX_DRAG_AND_DROP_XF_FAIL
	switch( i )
	{
	case 0: // xfunction installed
		type -b $XFunction.HasBeenInstalled;
		break;
	case 1: // user canceled installation
		type -b $XFunction.WasNotInstalled;
		break;
	default: // error
		type -b $XFunction.FailedToInstall;
		break;
	}

//----- Hong QA80-11640 v8.0982b SUPPORT_DRAG_AND_DROP_THEME_FOR_EASY_SHARING
[InstallTheme]
	//------ CPY 12/6/06 QA70-12736 LT_NEED_MORE_CNTRL_ON_ALLOWING_OC_FUNCS
	//i = install_theme("%1", %2);
	run -oc {i = install_theme("%1", %2)};
	//------
	switch ( i )
	{
	case 0: // xfunction installed
		type -b $Theme.HasBeenInstalled;
		break;
	case 1: // user canceled installation
		type -b $Theme.WasNotInstalled;
		break;
	default: // error
		string	strErr$ = $Theme.FailedToInstall;
		strErr$ += "%(CRLF)%1";
		type -v -b strErr$;
		break;
	}
	
[OnOpenOTH]
	//------ CPY 12/6/06 QA70-12736 LT_NEED_MORE_CNTRL_ON_ALLOWING_OC_FUNCS
	//i = get_page_theme_type("%1");
	run -oc {i = get_page_theme_type("%1")};
	//------
	if ( i > 0 ) // 0 == THTYPE_UNDEF
	{
		run.section(, InstallTheme, "%1" i);		
	}
	
	else
	{
		string	strErr$ = $Theme.FailedToInstall;
		strErr$ += "%(CRLF)%1";
		type -v -b strErr$;		
	}
	
[OnOpenOIS]
	run.section(, InstallTheme, "%1" 4); /* 4 = THTYPE_ANALYSIS */
	
//----- end SUPPORT_DRAG_AND_DROP_THEME_FOR_EASY_SHARING

///---Sim 07-02-2009 QA80-13869 SUPPORT_DRAG_AND_DROP_OMC_FILE
[OnOpenOMC]
	run -oc {i = install_customization_menu("%1")};
	switch( i )
	{
	case 0: // installed success
		type -b $CustomizationMenu.HasBeenInstalled;
		break;
	case 1: // user canceled installation
		type -b $CustomizationMenu.WasNotInstalled;
		break;
	case -1:
		type -b $CustomizationMenu.InvalidFileName;
		break;
	case -2:
		type -b $CustomizationMenu.InvalidFileExtension;
		break;
	case -3:
		type -b $CustomizationMenu.ReadOnly;
		break;
	case -4:
		type -b $CustomizationMenu.FailedCreatePath;
		break;
	default: // error
		type -b $CustomizationMenu.FailedToInstall;
		break;
	}
///---END QA80-13869 SUPPORT_DRAG_AND_DROP_OMC_FILE

/// EJP 2010-01-13 QA81-14672 DRAG_DROP_OIF_FILE
[OnOpenOIF]
	run -oc {i = install_filter("%1",1)};
	if (i < 0)
		type -b $File.FilterInstallFailed;
/// end DRAG_DROP_OIF_FILE
