/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/



#include	"gbview.h"
#include	"xlerror.h"

XL_SEXP *
setup_info_cmd(GBVIEW_FLAME * gf,WF_ID wfid,RESOURCE * r,int code,XL_SEXP * info);

XL_SEXP *
dgb_information(XLISP_ENV * e,XL_SEXP * s,
	XLISP_ENV * a,XL_SYM_FIELD * sf)
{
RESOURCE * r;
XL_SEXP * ret,*_ret;
int code;
WFID_INCLUDE_RESOURCE * wir, * wir_p;
	r = get_resource_ptr(&ret,e,s->h.file,s->h.line);
	if ( r == 0 )
		return ret;
	if ( r->h.type != RT_DRAW_GB )
		er_panic("dgb_polygon2d(2)");
	code = 0;
	for ( ; sf ; sf = sf->next ) {
		if ( l_strcmp(sf->name,l_string(std_cm,"code")) == 0 ) {
			sscanf(n_string(std_cm,sf->data),"%i",&code);
		}
	}
	lock_pdb_lock(r,0);

	if ( r->draw_gb.type == DGT_TILE )
		code = _get_tile_id(r,code);

	r->draw_gb.flags |= DGF_INFO;

	unlock_pdb_lock(r);

	wir = wf_search_wfid_include_resource(r);
	ret = 0;
	for ( wir_p = wir ; wir_p ; wir_p = wir_p->next ) {
		_ret = setup_info_cmd(wir_p->gf,wir_p->id,r,code,s);
		if ( get_type(_ret) == XLT_ERROR )
			ret = _ret;
	}
	if ( wir == 0 ) {
		_ret = setup_info_cmd(0,0,r,code,s);
		if ( get_type(_ret) == XLT_ERROR )
			ret = _ret;
	}
	free_wfid_include_resource(wir);
	return ret;
/*
no_obj:
	return get_error(
		s->h.file,
		s->h.line,
		XLE_PROTO_UNDEF_NAME,
		l_string(std_cm,"set-color-palette"),
		list(n_get_string("no object"),0));
*/
}
