#include <stdio.h>

#include "concorde.h"
#include "ysmaze2.h"
#include "mzedit.h"
#include "YsMacro.h"
#include "ysgui.h"

#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include <wgb.h>


extern int mzAtrDia;
extern int mzAtrLx;
extern int mzAtrLy;
extern int mzAtrBl;
extern int mzAtrBh;
extern int mzAtrSet;
extern int mzAtrCancel;


extern int ActiveWin;
extern MAZEWIN mzWin[MAZEWIN_NUM];
extern int Ys11Id;
extern int MenuBarDlg;



static void SetNumBox(int id,int num);
static int stf,bl,bh,lx,ly;

/*	initDataMZEDIT:pdEtcSize:MJ_MITEML40の呼び出し関数	*/
int	InputMazeAttribute()
{
	int i,active;
	MAZEMAP *mz;

	active=ActiveWin;

	if(mzWin[active].openflag==FALSE)
	{
		YsConfirm(Ys11Id,"アクティブなウィンドウがありません.",NULL);
		return NOERR;
	}

	mz=&mzWin[active].map;

	MTL_setAtrObj(MenuBarDlg,MS_INACTIVEL40);
	for(i=0; i<MAZEWIN_NUM; i++)
	{
		MTL_setAtrObj(mzWin[i].win,MS_INACTIVEL40);
	}

	SetNumBox(mzAtrBl,mz->bl);
	SetNumBox(mzAtrBh,mz->bh);
	SetNumBox(mzAtrLx,mz->lx);
	SetNumBox(mzAtrLy,mz->ly);

	MMI_SendMessage(mzAtrDia, MM_ATTACH, 1 ,Ys11Id);
	MMI_SendMessage(mzAtrDia, MM_SHOW, 0);
	MMI_ExecSystem();
	MMI_SendMessage(mzAtrDia, MM_ERASE, 0);
	MMI_SendMessage(mzAtrDia, MM_DETACH, 0);

	MTL_resetAtrObj(MenuBarDlg,~MS_INACTIVEL40);
	for(i=0; i<MAZEWIN_NUM; i++)
	{
		MTL_resetAtrObj(mzWin[i].win,~MS_INACTIVEL40);
	}

	if(stf==TRUE)
	{
		mz->bl=bl;
		mz->bh=bh;
		ResizeMaze(mz,lx,ly);

		MMI_SendMessage(mzWin[active].win,MM_ERASE,0);
		ResetWindow(active);
		YsRepaintWindow(mzWin[active].win);
		MMI_SendMessage(mzWin[active].win,MM_WAKE,0);
	}

	return NOERR ;
}

/*	initDataMZATR:mzAtrSet:MJ_DBUTTONL40の呼び出し関数	*/
/*	initDataMZATR:mzAtrCancel:MJ_DBUTTONL40の呼び出し関数	*/
int	SetMazeAttributeFunc(int kobj)
{
	int dmy;

	if(kobj==mzAtrSet)
	{
		stf=TRUE;
		MMI_SendMessage(mzAtrBh, MM_GETNUMBOX, 5,&bh, &dmy,&dmy,&dmy,&dmy);
		MMI_SendMessage(mzAtrBl, MM_GETNUMBOX, 5,&bl, &dmy,&dmy,&dmy,&dmy);
		MMI_SendMessage(mzAtrLx, MM_GETNUMBOX, 5,&lx, &dmy,&dmy,&dmy,&dmy);
		MMI_SendMessage(mzAtrLy, MM_GETNUMBOX, 5,&ly, &dmy,&dmy,&dmy,&dmy);
	}
	else
	{
		stf=FALSE;
	}

	MMI_SetHaltFlag(TRUE);

	return NOERR ;
}

static void SetNumBox(int id,int num)
{
	int dmy,min,max,dlt,clm;

	MMI_SendMessage(id, MM_GETNUMBOX, 5, &dmy,&min,&max,&dlt,&clm);
	MMI_SendMessage(id, MM_SETNUMBOX, 5,  num, min, max, dlt, clm);
}
