#include ONCE "window9.bi"

Sub ResizeWindow(hw as HWND ,  x as long  = FB_IGNORE, y as long = FB_IGNORE, width_ as long  = FB_IGNORE, height as long = FB_IGNORE) export
	
	dim as gint iX, iY, iFrameX, iFrameY , iBorder , iCaption
	
	dim as any ptr gdkwin = gtk_widget_get_window(hw)
	
	gdk_window_get_origin(gdkwin, @iX, @iY)
	
	gdk_window_get_root_origin(gdkwin, @iFrameX, @iFrameY)
	
	iBorder = abs(iX - iFrameX)

	iCaption = abs(iY - iFrameY) - iBorder	
	
	if x = FB_IGNORE then x = cint(g_object_get_data (cast(any ptr, hw), "X_SIZE")) 
	
	if y = FB_IGNORE then y = cint(g_object_get_data (cast(any ptr, hw), "Y_SIZE"))
	
	if width_ = FB_IGNORE then width_ = cint(g_object_get_data (cast(any ptr, hw), "W_SIZE"))
	
	if height = FB_IGNORE then height = cint(g_object_get_data (cast(any ptr, hw), "H_SIZE"))
	
	g_object_set_data (cast(any ptr, hw), "X_SIZE" , CAST(ANY PTR,CINT(x)))
	
	g_object_set_data (cast(any ptr, hw), "Y_SIZE" , CAST(ANY PTR,CINT(y)))
	
	g_object_set_data (cast(any ptr, hw), "W_SIZE" , CAST(ANY PTR,CINT(width_)))
	
	g_object_set_data (cast(any ptr, hw), "H_SIZE" , CAST(ANY PTR,CINT(height)))	
	
	width_ = width_-iBorder*2
	
	height = height -(iBorder*2+iCaption)

	if width_<0 then  width_=1
	
	if height<0 then  height=1
	
	gtk_window_move(GTK_WINDOW(hw), x , y )
	
	gtk_window_resize(GTK_WINDOW(hw) , width_ ,	height)
	
End Sub