#include "tk_resizeoption.h"
#include "tk_booloption.h"

const char* TkResizeOption::type="TkResizeOption";

const char* TkResizeOption::getType() const
{
	return type;
}

void TkResizeOption::doSerialize(TiXmlElement& element) const
{
	element.SetAttribute("resizeWidth",resizeWidth?1:0);
	element.SetAttribute("resizeHeight",resizeHeight?1:0);
}

void TkResizeOption::doDeserialize(const TiXmlElement& element)
{
	int intResizeWidth;
	int intResizeHeight;

	element.Attribute("intResizeWidth",&intResizeWidth);
	element.Attribute("intResizeHeight",&intResizeHeight);

	this->resizeHeight=(intResizeHeight!=0);
	this->resizeWidth=(intResizeWidth!=0);
}

TkResizeOption::TkResizeOption()
{
	this->resizeWidth=true;
	this->resizeHeight=true;
}

TkResizeOption::TkResizeOption(bool resizeWidth,bool resizeHeight)
{
	this->resizeWidth=resizeWidth;
	this->resizeHeight=resizeHeight;
}

const string& TkResizeOption::toString() const
{
	string& res=*(new string());
	res.append(resizeWidth?(TkBoolOption::TRUE_VALUE):(TkBoolOption::FALSE_VALUE));
	res.append(" ");
	res.append(resizeHeight?(TkBoolOption::TRUE_VALUE):(TkBoolOption::FALSE_VALUE));
	
	return res;
}

void TkResizeOption::fromObject(Tcl_Obj* object)
{
	int intResizeWidth;
	int intResizeHeight;

	sscanf(Tcl_GetString(object),"%d %d",&intResizeWidth,&intResizeHeight);
	resizeWidth=(intResizeWidth!=0);
	resizeHeight=(intResizeHeight!=0);
}

