/**
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Input Library
 *
 * The iWear Framework 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 as in version 2 of the License.

 * 
 * The iWear Framework 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
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __MENUMOUSEINPUTFUNCTOR_H
#define __MENUMOUSEINPUTFUNCTOR_H

#ifndef __FUNCTOR_H
#include <iwear/functor.h>
#endif

#ifndef __THREAD_H
#include <iwear/thread.h>
#endif

#ifndef __MOUSEINPUTDATA_H
#include <iwear_input/mouseinputdata.h>
#endif

#include <iwear/utility.h>
#include <iwear/debugstream.h>

using namespace iwear::input;

namespace iwear {
namespace uiservices {

// Forward decleration of the Menu class
class Menu;

/** 
 * This functor is derived from the functor class and handles all
 * mouse inputs.
 */
class MenuMouseInputFunctor 
    : public Functor<MouseInputData> ,
      public Thread
{

 public:

    /**
     * Constructor
     */
    MenuMouseInputFunctor(Menu* menu, EventDispatcher& ed);

    /**
     * Destrcutor
     */
    ~MenuMouseInputFunctor( void );

    /**
     * Operator
     */
    void operator()(const MouseInputData& mouse_input_data);

protected:

    inline void set_done_flag(bool value = true)
    {
	ThreadLocker tl(Mutex);
	this->done = value;
    }

    inline const bool& get_done_flag(void)
    {
	ThreadLocker tl(Mutex);
	return this->done;
    }


    inline const int32_t get_mouse_width(void)
    {
	//d_dbg << ANSI_GREEN << "(" << this << ") " 
	//      << ANSI_NORMAL << "Waiting to get mouse width"<< endl;	
	ThreadLocker tl(Mutex);
	//d_dbg << ANSI_GREEN << "(" << this << ") " 
	//      << ANSI_NORMAL << "Getting new mouse width (" << this->mouse_width
	//      << ")" << endl;
	return this->mouse_width;
    }

    inline void set_mouse_width(int32_t mouse_width)
    {
	ThreadLocker tl(Mutex);
	//d_dbg << ANSI_GREEN << "(" << this << ") "
	//      << ANSI_NORMAL << "Setting new mouse width (" << this->mouse_width
	//      << ")" << endl;
	this->mouse_width = mouse_width;
    }


    virtual void Run(void);

 private:

    Menu* menu;

    int32_t screen_width;

    int32_t mouse_width;

    int32_t time2sleep;

    bool done;

};

} // uiservices
} // iwear

#endif	//__MENUMOUSEINPUTFUNCTOR_H

