#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 "kifuctrl.h"
#include "kiffile.h"
#include "title.h"

int	dialogId_title = -1 ;
int	messageId_title[24] = -1 ;
int	blacknameId = -1 ;
int	whitenameId = -1 ;
int	numboxId[12] = -1 ;
int	dbId[2] = -1 ;
int	placeId = -1 ;
int	listMenuId[3] = -1 ;
/*	initDataMITITLE:dbId[0]:MJ_DBUTTONL40の呼び出し関数	*/
int	igo_titleset(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{

	static char tptr[21];
	char    t[35];
	int 	delay , komi_id, komi_number, hanmoku_id, vicdef_id, vicdef_number;
	int		min, max, delta, ptColum ;
	int		plitem, maxRow, maxColum, lastRow, lastColumn;
	YMDHM	play_start, play_end;

	MMI_SendMessage( blacknameId, MM_GETTEXT, 3, tptr, 21, FALSE);
	tptr[20] = '\0';
	title_blacknameset( tptr);
	
	MMI_SendMessage( whitenameId, MM_GETTEXT, 3, tptr, 21, FALSE);
	tptr[20] = '\0';
	title_whitenameset( tptr);
	
	MMI_SendMessage( placeId, MM_GETTEXT, 3, tptr, 21, FALSE);
	tptr[20] = '\0';
	title_playspaceset( tptr);
	
	/*	数値入力パネルの読み取り	*/
	MMI_SendMessage(numboxId[0], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_start.year = delay;
	MMI_SendMessage(numboxId[1], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_start.month = delay;
	MMI_SendMessage(numboxId[2], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_start.day = delay;
	MMI_SendMessage(numboxId[3], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_start.hour = delay;
	MMI_SendMessage(numboxId[4], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_start.minute = delay;
	title_playstart_time_set( play_start);
	

	MMI_SendMessage(numboxId[5], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_end.year = delay;
	MMI_SendMessage(numboxId[6], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_end.month = delay;
	MMI_SendMessage(numboxId[7], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_end.day = delay;
	MMI_SendMessage(numboxId[8], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_end.hour = delay;
	MMI_SendMessage(numboxId[9], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	play_end.minute = delay;
	title_playend_time_set( play_end);

	/*  コミの読み取り */
	/*	リストメニューの読み取り	*/
	MMI_SendMessage(listMenuId[0], MM_GETLMENUPTR, 5, 
						&plitem, &maxRow, &maxColum, &lastRow, &lastColumn) ;
	komi_id = lastRow;
	MMI_SendMessage(numboxId[10], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
	komi_number = delay;
	MMI_SendMessage(listMenuId[1], MM_GETLMENUPTR, 5, 
						&plitem, &maxRow, &maxColum, &lastRow, &lastColumn) ;
	hanmoku_id = lastRow;
	title_komiset( komi_id, komi_number, hanmoku_id);

	/*  勝敗の読み取り */
	/*	リストメニューの読み取り	*/
	MMI_SendMessage(listMenuId[2], MM_GETLMENUPTR, 5, 
						&plitem, &maxRow, &maxColum, &lastRow, &lastColumn) ;
	switch(lastRow ){
		case 0: 
			vicdef_id=0;
			MMI_SendMessage(numboxId[11], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
			vicdef_number = delay;
			break;
		case 1:
			vicdef_id=1;
			MMI_SendMessage(numboxId[11], MM_GETNUMBOX, 5,
							&delay, &min, &max, &delta, &ptColum) ;
			vicdef_number = delay;
			break;
		case 2:
			vicdef_id=2;
			vicdef_number=0;
			break;
		case 3:
			vicdef_id=0;
			vicdef_number=-1;
			break;
		case 4:
			vicdef_id=1;
			vicdef_number=-1;
			break;
		default:
			break;
	}
	
	title_issueset( vicdef_id, vicdef_number);
	title_fsave_on();

	/*	リストメニューワークメモリの解放	*/
	MMI_SendMessage(listMenuId[0], MM_SETMAXROWCOLUM, 2, 0, 0) ;
	MMI_SendMessage(listMenuId[1], MM_SETMAXROWCOLUM, 2, 0, 0) ;
	MMI_SendMessage(listMenuId[2], MM_SETMAXROWCOLUM, 2, 0, 0) ;

	/*	dialogId_titleで示されるオブジェクトを消す		*/
	MMI_SendMessage( dialogId_title , MM_ERASE , 0 ) ;

	/*	オブジェクトをダイアログから取り外す	*/
	MMI_SendMessage( dialogId_title , MM_DETACH , 0 ) ;
	/*  ダイアログを消した後でないと表示されないことがある */
	title_dispFunc();
	

	retunrInitMenuFunc();

	return NOERR ;
}

/*	initDataMITITLE:dbId[1]:MJ_DBUTTONL40の呼び出し関数	*/
int	igo_titlecancel(kobj, messId, argc, pev, trigger)
int		kobj ;
int		messId ;
int		argc ;
EVENT	*pev ;
int		trigger ;
{
	/*	dialogId_titleで示されるオブジェクトを消す		*/
	MMI_SendMessage( dialogId_title , MM_ERASE , 0 ) ;

	/*	オブジェクトをダイアログから取り外す	*/
	MMI_SendMessage( dialogId_title , MM_DETACH , 0 ) ;

	retunrInitMenuFunc();

	return NOERR ;
}
