/*  $Id: menu_item_generic.cpp,v 1.4 2004/02/19 13:48:35 sphair Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library 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.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
**
*/

#include "precomp.h"
#include "menu_item_generic.h"
#include "API/Core/XML/dom_element.h"

/////////////////////////////////////////////////////////////////////////////
// Construction:

CL_MenuItem_Generic::CL_MenuItem_Generic(
	CL_MenuItem *self,
	const std::string &_text)
:
	toggling(false),
	selected(false),
	use_icon(true),
	menu_item(self)
{
	text = _text;

	slots.connect( menu_item->sig_set_options(), this, &CL_MenuItem_Generic::on_set_options);
	slots.connect( menu_item->sig_mouse_down(), this, &CL_MenuItem_Generic::on_mouse_down);
}

void CL_MenuItem_Generic::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("text"))
		text = options.get_attribute("text");
}

void CL_MenuItem_Generic::on_mouse_down(const CL_InputEvent &event)
{
	if( toggling && menu_item->get_parent()->is_enabled(false) )
		selected = !selected;
}
