// ---------------------------------------------------------------------------
// 
//   Lily Engine alpha
// 
//   Copyright (c) 2010 Clifford Jolly
//     http://cliffjolly.com
//     cliff@cliffjolly.com
// 
// ---------------------------------------------------------------------------
// 
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//  
//   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. See the GNU
//   General Public License for more details.
// 
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//   USA
// -------------------------- END HEADER -------------------------------------

#ifndef WIDGETMULTIPARENT_H
#define WIDGETMULTIPARENT_H

#include "widget.h"

/// A WidgetMultiParent is a Widget that contains more that one child.
/// It's an abstract class, and doesn't do much on its own. Drawing is
/// left up to classes that extend this. Event handling is up to the
/// child class except for focus-related events, which are handled by
/// this.
LUA_WRAP class WidgetMultiParent : public Widget {
	public:
	
		// Unique stuff
		/// Add a child to the end of the list of child Widgets.
		LUA_WRAP void addChild(Widget *child);
		
		/// Remove a child from container. Higher-index Widgets will be
		/// shifted back to fill the gap.
		LUA_WRAP void removeChild(Widget *child);
	
		/// Remove a child without deleting it.
		LUA_WRAP void disconnectSpecificChild(Widget *child);

		/// Switch focus from one child to another. Sends appropriate
		/// focus events to the children it involves. Parameter is an
		/// index into the list of children.
		LUA_WRAP virtual void switchFocus(int newFocus);
	
		/// Destroys all child Widgets.
		LUA_WRAP virtual void clearChildren(void);
		
		/// Get the number of child Widgets.
		LUA_WRAP virtual int getNumChildren(void);
	
		/// Get the currently focused child Widget, or NULL if none.
		LUA_WRAP Widget *getFocusedChild(void);

		/// Get a child from a specific index in the list.
		LUA_WRAP virtual Widget *getChildInSlot(int slot);
		
		// Inherited stuff.
		bool handleEvent(const WidgetEvent *event);
		bool needsMouseEvents(void);
		Widget *findChildByName(const std::string &name);

		// Constructor/destructor.
		WidgetMultiParent(void);
		WidgetMultiParent(TiXmlElement *xml);
		virtual ~WidgetMultiParent(void);
		// TODO: XML constructor.
		
	protected:
	
		/// See if any child needs mouse events.
		virtual bool childNeedsMouseEvents(void);
		
		/// Index of the currently focused child.
		int focusedChild;

		/// std::vector of all the child Widgets to this.
		std::vector<Widget*> children;
};

#endif
