
#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 <eindd.h>
#include "client.h"

char	*guiEgbPtr ,			// EGB のワークアドレス
		CLI_fileName[80] ;		// ファイル名

int userFunc(apliId, messId, info, data)
int	apliId;
int	messId;
int	info;
int	data;
{
	register int	ret;
	POINT	pt ;

	ret = ILLEGAL_FUNCTION;

	switch(messId)
	{
		case	GM_QUIT :
			MMI_SendMessage( CLI_winId , MM_ERASE , 0 ) ;
			ret = NOERR ;
			break;

		case	GM_WAKE :
			MMI_SendMessage( CLI_winId , MM_WAKE , 0 ) ;
			ret = NOERR ;
			break;

		case	GM_SLEEP :
			MMI_SendMessage( CLI_winId , MM_SLEEP , 0 ) ;
			ret = NOERR ;
			break;

		case GM_SENDDATA :
			// プールからファイル名を受け取る
			EINDD_receivePool( info , data , CLI_fileName , (int *)&pt ) ;
//			printf("%d %d\n" , pt.x , pt.y ) ;

			MMI_SendMessage( CLI_msgId[0] , MM_SETMSG , 1 ,
				 "                                        " ) ;
			MMI_SendMessage( CLI_msgId[0] , MM_SHOW, 0) ;
			MMI_SendMessage( CLI_msgId[0] , MM_SETMSG ,1,CLI_fileName ) ;
			MMI_SendMessage( CLI_msgId[0] , MM_SHOW, 0) ;

			ret = NOERR ;
			break ;
	}

	return ret ;
}

void main()
{
	static MMICTRL mmi ={
				SCREENUNUSED | SCREENIGNORE,	/* ページ0側解像度		*/
				SCREENUNUSED,		/* ページ1側解像度		*/
				0, 					/* 書き込みページ		*/
				SCREENAVAILABLE,	/* 表示ページ			*/
				0, 					/* 表示プライオリティ	*/
				SCREENAVAILABLE,	/* 色数					*/
				SCREENEXPAND, 		/* VRAMの横の長さ		*/
				0, 					/* メモリ領域の大きさ	*/
				NULL, 				/* メモリ領域のアドレス	*/
				0, 					/* ユーザ領域の大きさ	*/
				NULL, 				/* ユーザ領域のアドレス	*/
				0, 0, 				/* 画面枠	lupx,lupy	*/
				0, 0,				/*			rdwx,rdwy	*/
				-16384, -16384,		/* 移動枠	lupx,lupy	*/
				16383, 16383,		/*			rdwx,rdwy	*/
				15, 				/* 白色					*/
				8,  				/* 黒色					*/
				7,  				/* 灰色					*/
				7	 				/* 反転色				*/
	};

	extern int APL_init() ;

	if (MMI_Open( &mmi ) == NOERR)
	{
		if (APL_init() == NOERR)
		{
			MMI_ExecSystem() ;
		}
	}

	MMI_Close() ;
}

int APL_init()
{
	extern MMIINIT	initDataCLISET ;
	register int	ret ;

	guiEgbPtr = MMI_GetEgbPtr() ;

	if ((ret = MMI_initHyper()) < 0)			return ret ;
	if ((ret = MMI_initDialogL40()) < 0)		return ret ;
	if ((ret = MMI_initWindowL40()) < 0)		return ret ;
	if ((ret = MMI_initMessageL40()) < 0)		return ret ;

	if ((ret = MMI_Init(&initDataCLISET)) < 0)	return ret ;

	MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc);
	MMI_CallMessage(MMI_GetApliId(), GM_TITLE, (int)"メタクライアント", 0);
	MMI_SendMessage( CLI_winId , MM_WAKE , 0 ) ;
	MMI_SendMessage( CLI_winId , MM_ATTACH , 1 , MMI_GetBaseObj() ) ;
	MMI_SendMessage(MMI_GetBaseObj(), MM_SHOW, 0) ;

	return NOERR ;
}

