/**********************************************************************
 
	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	<stdlib.h>
#include	<string.h>


extern "C" {

#include	"task.h"
#include	"pri_level.h"
#include	"rcache.h"

}

#include	"v/v.h"

extern "C" {


void
call_window_function(char * win)
{
extern XLISP_ENV * vobj_env;
VObjectStatus sts;
XL_SEXP * id_list;
XL_SEXP * me;
VObject * obj;
XL_SEXP * sym;

	gc_push(0,0,"call_window_function");
printf("CALL WINDOW\n");
	sym = n_get_symbol(win);
	set_attribute(sym,
		l_string(std_cm,"visible"),
		l_string(std_cm,"0"));
	id_list = eval(vobj_env,
		List(sym,-1));
	switch ( get_type(id_list) ) {
	case XLT_PAIR:
		break;
	case XLT_ERROR:
	default:
		print_sexp(s_stdout,id_list,0);
		ss_printf("\n");
		goto err;
	}
	me = get_el(car(id_list),1);
	if ( get_type(me) != XLT_INTEGER ) {
		ss_printf("invalid type for ID\n");
		print_sexp(s_stdout,me,0);
		ss_printf("\n");
		goto err;
	}
	obj = VObject::get_object_by_id(me->integer.data);
	if ( obj == 0 ) {
		ss_printf("invalid object ID = %i\n",me->integer.data);
		goto err;
	}
	sts.visible = 1;
	obj->set_status(&sts,VSF_VISIBLE);
err:
	gc_pop(0,0);
}

void
event_task()
{

	fprintf(stderr,"event_task = %i\n",get_tid());

	change_pri(0,PRI_USER_INTERFACE);

	vobject_main();

}

}
