#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include "igo.h"
#include "banx.h"
#include "kiffile.h"
#include "title.h"

/*	使用する部品の宣言		*/
extern int	fsavedialogId;
extern int	fsave_messageId[2];

/*	About画面の変数の定義				*/

int	alertId = -1 ;
int	aboutMesId[2] = -1 ;
int	aboutBtnId = -1 ;

/*	背景画面の変数の定義	*/

int	backId = -1 ;
int	buttonId = -1 ;
int	deskTopId = -1 ;
int	deskTopBtnId[2] = -1 ;
int	menuBarId = -1 ;
int	mitemBarId[4] = -1 ;
int	menu0Id = -1 ;
int	mitem0Id = -1 ;
int	menu1Id = -1 ;
int	mitem1Id[7] = -1 ;
int	menu2Id = -1 ;
int	mitem2Id[13] = -1 ;
int	menu3Id = -1 ;
int	title_dispdialogId = -1 ;
int	title_messageId[12] = -1 ;
int	textcommentId[10] = -1 ;
int about_messageId = -1 ;

/*	initDataMIDESK:mitem0Id:MJ_MITEML40の呼び出し関数	*/
/*	Aboutを表示するための関数							*/
int	showAboutFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
int physicalMax;
int	logicalMax;
int	maxMemory;
static char string[80];

	physicalMax = TL_checkMemory(0);
	logicalMax = TL_checkMemory(2);
	maxMemory = (( physicalMax <logicalMax ) ? physicalMax : logicalMax )*4;

	sprintf( string, "残りメモリは%5dKバイトです", maxMemory );
	MMI_SendMessage( about_messageId , MM_SETMSG , 1, string);

	/*	オブジェクトをダイアログに取り付ける	*/
	MMI_SendMessage( alertId , MM_ATTACH , 1 , backId ) ;

	/*	alertIdで示されるオブジェクトを表示する	*/
	MMI_SendMessage( alertId , MM_SHOW , 0 ) ; 

	return NOERR ;
}

/*	initDataMIABOU:aboutBtnId:MJ_DBUTTONL40の呼び出し関数	*/
/*	Aboutを消去するための関数								*/
int	eraseAboutFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	/*	alertIdで示されるオブジェクトを消す		*/
	MMI_SendMessage( alertId , MM_ERASE , 0 ) ;

	/*	オブジェクトをダイアログから取り外す	*/
	MMI_SendMessage( alertId , MM_DETACH , 0 ) ;

	return NOERR ;
}

/*	initDataMIDESK:deskTopBtnId[1]:MJ_ICONL40の呼び出し関数	*/
/*	initDataMIDESK:mitem1Id[4]:MJ_MITEML40の呼び出し関数	*/
int	exitFunc(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	if(title_fsave_read()==ON){
		title_state_set(QUIT);

		MMI_SendMessage( fsave_messageId[0], MM_SETMSG, 1, 
					"棋譜デ−タが保存されておりません");
		MMI_SendMessage( fsave_messageId[1], MM_SETMSG, 1, 
					"デ−タを保存して終了を行いますか");

		/*	オブジェクトをダイアログに取り付ける	*/
		MMI_SendMessage( fsavedialogId , MM_ATTACH , 1 , backId ) ;

		/*	dialogId_handyでされるオブジェクトを表示する	*/
		MMI_SendMessage( fsavedialogId , MM_SHOW , 0 ) ; 

		/*	オブジェクトをダイアログから取り外す	*/
		MMI_SendMessage( deskTopId , MM_DETACH , 0 ) ;
		MMI_SendMessage( buttonId , MM_DETACH , 0 ) ;

	}else{
		MMI_SetHaltFlag( TRUE ) ;
	}

	return NOERR ;
}

