/*====================================================
                      ARTemis
                   (version 1.3)
             FM-TOWNS 用ペイントツール

                 by 松内 良介 1994
====================================================*/

/*
	IMGBOX.C  :  IMGBOX(イメージボックス)型部品・実現モジュール
	
	外部関数:
		int MMI_initImageBox(void)
*/

#define	MODULE_IMGBOX

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include "art.h"

int		MJ_IMGBOX = -1;

/*	表示処理	*/

	static int ML_IMGBOXdisp(kobj, messId, argc)
	int		kobj ;
	int		messId ;
	int		argc ;
	{
		register IMGBOX *plbl ;  IMGBOX lbl ;
		lbl = *(plbl = ((IMGBOX *)(TL_getObjectPtr(kobj)->data))) ;
		if (lbl.func == (int(*)())NULL)
			return NOERR;
	  /* 部品の位置を得る */
		MG_CorrectPositionL40(&(lbl.fr), (HYPER *)plbl) ;
	  /* 最描画する必要があるか? */
		if (MMI_CheckUpdateFrame(&(lbl.fr)))
		{
			POINT new,old;
			MG_mosDisp(2) ;
			new.x = new.y = 0;
			MG_PushOrigin(&new, &old);
			(*lbl.func)(kobj, MM_SHOW, 0);
			MG_PopOrigin(&old);
			MG_mosDisp(3) ;
		}
	  /* おわり */
		return NOERR ;
	}
	
/*	再描画関数の登録 */
	
	static int ML_IMGBOXsetexec(kobj, messId, argc, func)
	int		kobj ;
	int		messId ;
	int		argc ;
	int		(*func)();
	{
		IMGBOX *plbl ;
		plbl = (IMGBOX *) ( TL_getObjectPtr(kobj) -> data ) ;
		plbl->func = func ;
		return NOERR ;
	}

/* メッセージに対する関数の対応 */

	#define	NMET_IMGBOX	2
	
	static int (*MF_IMGBOXmethod[NMET_IMGBOX])() = {
		ML_IMGBOXdisp,
		ML_IMGBOXsetexec
	} ;
	
	static char *MM_IMGBOXmessage[NMET_IMGBOX] = {
		MT_SHOW,
		MT_SETEXEC
	};

/* 初期化関数 */

	int MMI_initImageBox(void)
	{
		MJ_IMGBOX = MMI_AddType(MJ_HYPER, NMET_IMGBOX,
								sizeof(IMGBOX),
								MF_IMGBOXmethod,
								MM_IMGBOXmessage) ;
		if (MJ_IMGBOX < NOERR)
			return MJ_IMGBOX ;
		return NOERR ;
	}

/* 部品のひな型を作る関数 */

	#define ALIGN	4
	#define OFFSET(type) \
	        (sizeof(MMIPACKET) + (sizeof(type)+ALIGN-1)/ALIGN*ALIGN)

	int IMGBOX_makePrototype(int *objId)
	{
		static int tempId;
		static MMIINIT initDataIMGBOX = { "MmiInit",   1, 0 } ;
		static MMIPACKET d001 = { &tempId, NULL, &MJ_IMGBOX,
		                          OFFSET(IMGBOX), MS_NONE };
		static IMGBOX    d001d = {	MS_DSPONLYL40, 0,0,47,47, 0,0,0,
		                            MS_NONEL40, (int(*)())NULL };
		int ret;
		if ((ret = MMI_Init(&initDataIMGBOX)) < NOERR)
			return ret ;
		*objId = tempId;
		return NOERR;
	}
