/**********************************************************************
 
	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>

#ifndef WIN32
#include	<X11/Xatom.h>
#else
#include	<windows.h>
#endif

#include	"machine/msequence.h"
#include	"memory_debug.h"
#include	"v.h"

extern char szWindowClass[];

VWINDOW *v_open_win(VERROR * err,VDISPLAY * d,int x,int y,int w,int h)
{
	VWINDOW * win;
	win = d_alloc(sizeof(*win));
	win->d = d;
	win->w = CreateWindow(szWindowClass, "cosmos", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
		x,y,
		w+GetSystemMetrics(SM_CXFRAME)*2,
		GetSystemMetrics(SM_CYCAPTION)+h+GetSystemMetrics(SM_CYFRAME)*2, 
		NULL, NULL, d->d->hinst, NULL);
	ghWnd = win->w;
	//ANG08
	/* win->gc=GetDC(win->w);*/
	win->next = d->win_list;
	d->win_list = win;
	win->obj_list = 0;
	err->err1 = E_OK;
	ShowWindow( win->w,  SW_SHOW );
//	UpdateWindow( win->w );
	return win;
}

//ANG08
void v_get_window_attributes(VERROR * err,VWINDOW_ATTRIBUTES * attr,	VWINDOW * win)
{
	RECT rect;
	HWND hwnd=win->w;
	GetClientRect(hwnd,&rect);
	attr->w = rect.right-rect.left;
	attr->h = rect.bottom-rect.top;
	attr->x = rect.left;
	attr->y = rect.top;
	err->err1 = E_OK;
	return;
}

typedef struct v_clear_window_contents_s {
        VERROR * err;
        VWINDOW * win;
} V_CLEAR_WINDOW_CONTENT_S;

int
_v_clear_window_content(V_CLEAR_WINDOW_CONTENT_S *v)
{
/*
	Window w = v->win->w;
	Display *d = v->win->d->d;
	XSetWindowBackground(d,w,BlackPixel(d,0));
	XClearWindow(d,w);
	v->err->err1 = E_OK;
*/
	UpdateWindow(v->win->w);
	return 0;
}


void
v_clear_window_content(VERROR * err, VWINDOW *win)
{
V_CLEAR_WINDOW_CONTENT_S v;
        v.err = err;
        v.win = win;
        ms_do(_v_clear_window_content,&v,"v_clear_window_content");
}


