#ifndef _TK_CONTAINER_H_
#define _TK_CONTAINER_H_

#include "tk_base.h"
#include "tk_layout.h"

#include <vector>

using namespace std;

class TkLayout;

/**
 * \brief Base widget container.
 * 
 * \date 01-12-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo 
 *
 * \bug 
 *
 */
class TkContainer:public TkBase
{
private:
	typedef map<string,Ptr<TclStringVar> > t_groups;

	t_groups radioGroups;
	Ptr<TkLayout> manager;
	void addChild(TkBase* object);
protected:
	typedef vector<Ptr<TkBase> > t_child_vector;
	t_child_vector childs;

	void baseClone(TkBase* obj);
	void doSerialize(TiXmlElement& element) const;
	void doDeserialize(const TiXmlElement& element);
public:
	TkContainer(Ptr<TclInterp> interp):TkBase(interp)
	{
	}
	~TkContainer()
	{
		radioGroups.clear();
		childs.clear();
	}


	/**
	 * Returns pointer to widget at coordinates [rootX,rootY]
	 * \param rootX x coordinate
	 * \param rootY y coordinate
	 * \return pointer to widget
	 */
	TkBase* getChildByCoord(int rootX,int rootY);


	/**
	 * Returns pointer to widget with user-defined name name
	 * \param name name of widget
	 * \return pointer to widget or NULL if no such widget exist
	 */
	TkBase* getChildByName(const string& name);
	
	
	/**
	 * Add child widget to conteiner
	 * \param object child widget
	 * \param constraints layout constraints for this widget
	 */
	void addChild(TkBase* object,TObject* constraints);
	
	void create();
	
	/**
	 * Start doing layout (layout manager must be set) 
	 */
	void doLayout();


	/**
	 * Remove all child widgets
	 */
	void removeAll();


	/**
	 * Remove specific child widget
	 * \param object widget to remove
	 */
	void removeChild(TkBase* object);


	/**
	 * Sets layout manager
	 * \param manager layout manager
	 */
	void setLayoutManager(TkLayout* manager);

	/**
	 * Returns active layout manager
	 * \return layout manager
	 */
	TkLayout* getLayoutManager();
	
	
	/**
	 * Returns (or create) shell variable, representing radiobutton group
	 * \param name name of group
	 * \return reference to variable
	 */
	Ptr<TclStringVar>& getRadioGroupByName(const string& name);
};

#endif/*_TK_CONTAINER_H_*/
