/**********************************************************************
 
	Copyright (C) 2003-2004
	Hirohisa MORI <joshua@nichibun.ac.jp>
	Tomoki SEKIYAMA <sekiyama@yahoo.co.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 "v/VGroupBox.h"
#include "machine/v_object.h"

extern "C" void set_styled_descriptor(
	const L_CHAR * descriptor,
	const LC_WRITING_STYLE * ws,
	int fsize,
	int vert_desc,
	VInfo * info,
	int is_bin);


VExError
VGroupBox::create_do(const VObjectStatus* s, int flags, 
			VObject * nmp,void * arg)
{
	info = v_serialized_exec_func(gtk_frame_new, "");
	v_serialized_exec_sub(g_object_ref, (void*)info);

	return return_create_do(this,nmp,&sts,s,flags);
}

void
VGroupBox::destroy_do(VObject * nmp)
{
	nmp->remove_child_do(this);
	v_serialized_exec_sub(gtk_widget_destroy, info);
	v_serialized_exec_sub(g_object_unref, (void*)info);
}

VGroupBox::~VGroupBox()
{
}

VExError
VGroupBox::get_status(VObjectStatus *s, int flags) const
{
	V_OP_START_EX
	VExError err = v_get_status_standard(s, &flags, info);
	VExError err2 = VObject::get_status(s,flags);
	if ( err2.code )
		err = merge_VExError_vstatus_type(err,err2);
	V_OP_END
	return err;
};

VExError
VGroupBox::set_status(const VObjectStatus *s, int flags)
{
	V_OP_START_EX
	VExError err = v_set_status_standard(s, flags, info);
	err = VObject::set_status(s,flags);
	if ( err.code ) {
		V_OP_END
		return err;
	}
	
	if ( flags & VSF_DESC ) {
		GtkWidget *label = v_serialized_exec_func(gtk_frame_get_label_widget, GTK_FRAME(info));
		set_styled_descriptor(sts.descriptor, sts.ws, sts.fsize, 0, label, 0);
		err.subcode1 &= ~VSF_DESC;
	}
	if ( flags & VSF_SPACING ) {
		v_serialized_exec_sub(gtk_container_border_width,
			GTK_CONTAINER(info), (unsigned)(s->spacing.w+s->spacing.h)/2); 
		err.subcode1 &= ~VSF_SPACING;
	}
	V_OP_END
	
	if ( flags & (VSF_ALIGN | VSF_PADDING ) ) {
		if ( sts.parent )
			sts.parent->child_status_changed(this, info);
		err.subcode1 &= ~(VSF_ALIGN | VSF_PADDING );
	}
	return err;
}

VExError
VGroupBox::add_child_do(VObject* child)
{
	v_serialized_exec_sub(gtk_container_add, GTK_CONTAINER(info),
		child->get_info_this());
	return initial_VExError(V_ER_NO_ERR,0,0);
}

void
VGroupBox::remove_child_do(VObject* child)
{
	v_serialized_exec_sub(gtk_container_remove, GTK_CONTAINER(info),
			child->get_info_this());
}

void
VGroupBox::child_status_changed(VObject *child, VInfo* cinfo)
{
	// do nothing
}

void
VGroupBox::redraw(VRect *rect) const
{
	// do nothing
}

