#ifndef _TK_TOP_LEVEL_H_
#define _TK_TOP_LEVEL_H_

#include "tk_container.h"
#include "tk_menu.h"

class IModule;

/**
 * \brief Common interface for window listener, handles "destroy" window event
 * \date 01-12-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo 
 *
 * \bug 
 *
 */
class TkTopLevelListener:public TObject
{
public:
	static const char* type;
	const char* getType() const;


	/**
	 * Called when window is being destroyed
	 * \param source window being destroyed
	 */
	virtual void onDestroy(TkTopLevel* source);
};


/**
 * \brief Rerpresent "toplevel" widget
 * \date 01-12-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo 
 *
 * \bug 
 *
 */
class TkTopLevel:public TkContainer
{
public:
	typedef map<string,TkTopLevel*> t_toplevel_map;
private:
	static t_toplevel_map topLevelMap;

	Ptr<TkMenu> menu;

	t_option_set bcWndOptSet;
	t_option_set wndOptSet;

	Ptr<TkTopLevelListener> listener;
protected:
	void baseClone(TkBase* obj);
	void doSerialize(TiXmlElement& element) const;
	void doDeserialize(const TiXmlElement& element);
public:
	static TXmlObject* newObject()
	{
		return new TkTopLevel(TclInterp::defaultInterp);
	}

	const static Ptr<TkOptionDef> OPT_BORDERWIDTH ;
	const static Ptr<TkOptionDef> OPT_CLASS ;
	const static Ptr<TkOptionDef> OPT_MENU ;
	const static Ptr<TkOptionDef> OPT_RELIEF ;
	const static Ptr<TkOptionDef> OPT_SCREEN ;
	const static Ptr<TkOptionDef> OPT_USE ;
	const static Ptr<TkOptionDef> OPT_BACKGROUND ;
	const static Ptr<TkOptionDef> OPT_COLORMAP ;
	const static Ptr<TkOptionDef> OPT_CONTAINER ;
	const static Ptr<TkOptionDef> OPT_CURSOR ;
	const static Ptr<TkOptionDef> OPT_HEIGHT ;
	const static Ptr<TkOptionDef> OPT_HIGHLIGHTBACKGROUND ;
	const static Ptr<TkOptionDef> OPT_HIGHLIGHTCOLOR ;
	const static Ptr<TkOptionDef> OPT_HIGHLIGHTTHICKNESS ;
	const static Ptr<TkOptionDef> OPT_PADX ;
	const static Ptr<TkOptionDef> OPT_PADY ;
	const static Ptr<TkOptionDef> OPT_TAKEFOCUS ;
	const static Ptr<TkOptionDef> OPT_VISUAL ;
	const static Ptr<TkOptionDef> OPT_WIDTH ;

	const static Ptr<TkOptionDef> WO_RESIZABLE;
	const static Ptr<TkOptionDef> WO_DESTROY;
	const static Ptr<TkOptionDef> WO_GEOMETRY;
	const static Ptr<TkOptionDef> WO_TITLE;
	const static Ptr<TkOptionDef> WO_STATE;

	const static Ptr<TkOptionDef> optAll[];
	const static char* type;
	const static char* tkClass;

	const Ptr<TkOptionDef>* getOptionAll() const;
	const char* getType() const;
	const char* getTkClass() const;

	TObject* clone();

	TkTopLevel(Ptr<TclInterp> interp);
	~TkTopLevel();

	static TkTopLevel* getTopLevelByGuid(const string& guid);
	static Ptr<TkTopLevel>& createMainWindow(TclInterp* interp);

	void setMenu(TkMenu* menu);
	void setTitle(const string& title);
	const char* getTitle() const;

	const TkRectOption& getBounds();
	Tcl_Obj* getWMOption(const Ptr<TkOptionDef>& def) const;
	const string& getStrWMOption(const Ptr<TkOptionDef>& def) const;

	void setWMOption(const Ptr<TkOptionDef>& def,TObject* option);
	
	bool isResizableWidth();
	bool isResizableHeight();
	void setResizable(bool resizeWidth,bool resizeHeight);

	void setBounds(int width,int height,int x,int y);
	void setWindowState(TkWinStateOption::opts state);

	Ptr<TkTopLevelListener>& getWindowListener();
	void setWindowListener(TkTopLevelListener* listener);

	void create();
	void destroy();

	void attachToModule(IModule* module);


	void setBackgroundColor(TkColorOption* color);
	Ptr<TkColorOption>& getBackgroundColor() const;
};

#endif/*_TK_TOPLEVEL_H_*/
