//
// $Id: Widget.h,v 1.1 2003/07/24 20:00:30 sarfata Exp $
//
// Copyright vNET Project <vnet@vnet-project.org>
//
// 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; see the file COPYING.  If not, write to:
//   The Free Software Foundation, Inc.
//   59 Temple Place, Suite 330
//   Boston, MA 02111 USA
//


class Widget;

#include "Client.h"

#ifndef __WIDGET_H__
#define __WIDGET_H__

#include <vector>
#include <deque>
#include <algorithm>

namespace VGUI
{
  class Widget
  {
  protected:
    mutable int mouse_inside;
    int x;
    int y;
    Client *client;
    bool dead;
    std::deque<Widget*> children;
  public:
    bool visible;
    void hide(){visible=false;};
    void show(){visible=true;};
    bool isdead(){return dead;};
    void slide(int xdep,int ydep){x += xdep;y += ydep;};
    Widget(Client *client,int x,int y);
    virtual ~Widget();
    void move_to(int x,int y){this->x = x;this->y = y;};
    void attach(Widget* newchild);
	void attachend(Widget* newchild);
	void detach(Widget* todestroy)
	{
    std::deque<Widget* >::iterator i;
		if((i = std::find(children.begin(),children.end(),todestroy))!=children.end())
		{
			delete (*i);
			children.erase(i);
		}
	};
    virtual int isinside(int x,int y){return 0;};
    virtual void onkeydown(SDL_keysym *keysym){};
	virtual void onmousedown(int x,int y,Uint8 button);
	virtual void onmouseup(int x,int y,Uint8 button);
  void sethelp(const std::string& h){ _help = h;};
  const std::string& onhelp(int x, int y)
  {
    std::deque<Widget* >::iterator i;
		for(i = children.begin(); i !=children.end(); i++)
		{
      if((*i)->isinside(x,y))
        return (*i)->onhelp(x,y);
    }
    return _help;
  };
    std::string _help;
    void update(float TimeElapsed);
    virtual void draw(float TimeElapsed)=0;
  };
}
#endif