
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include <egb.h>
#include <guidbg.h>
#include "fvimsg.h"

int	MSG_winId = -1 ;
int	MSG_drvSelBtnId[6] = -1 ;
int	MSG_redrawId[2] = -1 ;
int	MSG_selectForceId[2] = -1 ;
int	MSG_activateId[2] = -1 ;
int	MSG_forceRedrawTextId = -1 ;
int	MSG_forceRedrawBtnId[2] = -1 ;
int	MSG_ifRedrawTextId = -1 ;
int	MSG_ifRedrawBtnId = -1 ;

/*	initDataMSGSET:MSG_winId:MJ_WINDOWL40の呼び出し関数	*/
int	MSG_winFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	if ( messId == MM_ERASE )
	{
		MMI_SetHaltFlag( TRUE ) ;
	}

	return NOERR ;
}

/*	initDataMSGSET:MSG_drvSelBtnId[1]:MJ_ICONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_drvSelBtnId[2]:MJ_ICONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_drvSelBtnId[3]:MJ_ICONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_drvSelBtnId[4]:MJ_ICONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_drvSelBtnId[5]:MJ_ICONL40の呼び出し関数	*/
int	MSG_sendDriveFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	int		drvNum , fviId ;

	// どのドライブのボタンが押されたか
	for ( drvNum = 1 ; drvNum <= 7 ; drvNum++ )
	{
		if ( kobj == MSG_drvSelBtnId[drvNum] )		break ;
	}

	fviId = MSG_findFVI() ;		// FVI.EXG を探す
	if ( fviId > 0 )
	{
		// ドライブ指定再描画
		if ( MSG_forceNum == 0 )
		{
			MMI_CallMessage( fviId , GM_EXECUSER ,
								MTLFVI_LIST0 , drvNum + 0x40 ) ;
		}
		else if ( MSG_forceNum == 1 )
		{
			MMI_CallMessage( fviId , GM_EXECUSER ,
								MTLFVI_LIST1 , drvNum + 0x40 ) ;
		}
		MMI_CallMessage( MMI_GetApliId() , GM_WAKE ,0,0 ) ;
	}

	return NOERR ;
}

/*	initDataMSGSET:MSG_redrawId[0]:MJ_DBUTTONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_redrawId[1]:MJ_DBUTTONL40の呼び出し関数	*/
int	MSG_redrawFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	int		fviId ;

	fviId = MSG_findFVI() ;		// FVI.EXG を探す
	if ( fviId > 0 )
	{
		// 単純再描画
		if ( kobj == MSG_redrawId[0] )
		{
			MMI_CallMessage( fviId , GM_EXECUSER , MTLFVI_REDRAW , 0 ) ;
		}
		else if ( kobj == MSG_redrawId[1] )
		{
			MMI_CallMessage( fviId , GM_EXECUSER , MTLFVI_REDRAW , 1 ) ;
		}
		MMI_CallMessage( MMI_GetApliId() , GM_WAKE ,0,0 ) ;
	}

	return NOERR ;
}

/*	initDataMSGSET:MSG_selectForceId[0]:MJ_TICONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_selectForceId[1]:MJ_TICONL40の呼び出し関数	*/
int	MSG_selectForceFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	if ( kobj == MSG_selectForceId[0] )
	{
		if ( MTL_checkFlagObj( kobj , MS_TOGGLE ) )		// OFF -> ON
		{
			MSG_forceNum = 0 ;
			MTL_resetFlagObj( MSG_selectForceId[1]  , (~MS_TOGGLE) ) ;
		}
		else	// ON -> OFF はできない
		{
			MTL_setFlagObj( MSG_selectForceId[0]  , MS_TOGGLE ) ;
		}
	}
	else if ( kobj == MSG_selectForceId[1] )
	{
		if ( MTL_checkFlagObj( kobj , MS_TOGGLE ) )		// OFF -> ON
		{
			MSG_forceNum = 1 ;
			MTL_resetFlagObj( MSG_selectForceId[0]  , (~MS_TOGGLE) ) ;
		}
		else	// ON -> OFF はできない
		{
			MTL_setFlagObj( MSG_selectForceId[1]  , MS_TOGGLE ) ;
		}
	}

	MMI_SendMessage( MSG_selectForceId[0] , MM_SHOW , 0 ) ;
	MMI_SendMessage( MSG_selectForceId[1] , MM_SHOW , 0 ) ;

	return NOERR ;
}

/*	initDataMSGSET:MSG_activateId[0]:MJ_DBUTTONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_activateId[1]:MJ_DBUTTONL40の呼び出し関数	*/
int	MSG_activeFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	int		fviId ;

	fviId = MSG_findFVI() ;		// FVI.EXG を探す
	if ( fviId > 0 )
	{
		// アクティブリストの変更
		if ( kobj == MSG_activateId[0] )
		{
			MMI_CallMessage( fviId , GM_EXECUSER , MTLFVI_ACTIVE , 0 ) ;
		}
		else if ( kobj == MSG_activateId[1] )
		{
			MMI_CallMessage( fviId , GM_EXECUSER , MTLFVI_ACTIVE , 1 ) ;
		}
		MMI_CallMessage( MMI_GetApliId() , GM_WAKE ,0,0 ) ;
	}

	return NOERR ;
}

/*	initDataMSGSET:MSG_forceRedrawTextId:MJ_TEXTL40の呼び出し関数	*/
int	MSG_forceRedrawTextFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	return NOERR ;
}

/*	initDataMSGSET:MSG_forceRedrawBtnId[0]:MJ_DBUTTONL40の呼び出し関数	*/
/*	initDataMSGSET:MSG_forceRedrawBtnId[1]:MJ_DBUTTONL40の呼び出し関数	*/
int	MSG_forceRedrawFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	int		fviId ;
	char	path[128] ;

	path[0] = 0 ;
	MMI_SendMessage( MSG_forceRedrawTextId ,
				MM_GETTEXT , 3 , path , 12 , FALSE ) ;
	if ( path[0] == 0 )		return NOERR ;

	fviId = MSG_findFVI() ;		// FVI.EXG を探す
	if ( fviId > 0 )
	{
		// パス指定強制再描画
		if ( kobj == MSG_forceRedrawBtnId[0] )
		{
			MMI_CallMessage( fviId , GM_EXECUSER ,
									MTLFVI_FORCE0 , (int)path ) ;
		}
		else if ( kobj == MSG_forceRedrawBtnId[1] )
		{
			MMI_CallMessage( fviId , GM_EXECUSER ,
									MTLFVI_FORCE1 , (int)path ) ;
		}
		MMI_CallMessage( MMI_GetApliId() , GM_WAKE ,0,0 ) ;
	}

	return NOERR ;
}

/*	initDataMSGSET:MSG_ifRedrawTextId:MJ_TEXTL40の呼び出し関数	*/
int	MSG_ifRedrawTextFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	return NOERR ;
}

/*	initDataMSGSET:MSG_ifRedrawBtnId:MJ_DBUTTONL40の呼び出し関数	*/
int	MSG_ifRedrawFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	int		fviId ;
	char	path[128] ;

	path[0] = 0 ;
	MMI_SendMessage( MSG_ifRedrawTextId ,
								MM_GETTEXT , 3 , path , 12 , FALSE ) ;
	if ( path[0] == 0 )		return NOERR ;

	fviId = MSG_findFVI() ;		// FVI.EXG を探す
	if ( fviId > 0 )
	{
		// パスが表示されていたら再描画
		MMI_CallMessage( fviId , GM_EXECUSER ,
									MTLFVI_IFREDRAW , (int)path ) ;
		MMI_CallMessage( MMI_GetApliId() , GM_WAKE ,0,0 ) ;
	}

	return NOERR ;
}

int		MSG_findFVI()		// FVI.EXG を探す
{
	int		fviId ;

	fviId = MMI_CallMessage( MMI_GetApliId(), GM_QUERYID,
									QM_SAMEAS, ( int )"FVI.EXG" ) ;

	return fviId ;
}

