/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *
 * This file is part of NMM. 
 * 
 * NMM 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; only version 2 of the License.      
 * 
 * NMM 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 NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_IDisplayEvents_HPP
#define NMM_IDisplayEvents_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/Interface.hpp"
#include "nmm/comm/messaging/Event.hpp"
#include "nmm/comm/messaging/IllegalStateException.hpp"
#include <memory>


#include "visibility.hpp"

namespace NMM
{
  /**
   * Display events.
   * Defines events that can be sent by the display nodes and caught by the application.
   * The most common use is for capturing keyboard and mouse events by the application.
   *
   * The application should only register itself for the events of this interface it is
   * actually interested in. Some implementations might check for which events listeners
   * have been registered to optimize event handling.
   */

  class DLLEXPORT IDisplayEvents : virtual public NMM::Interface { 
  public:    /**
     * Mouse buttons.
     * These are identifiers for the three mouse buttons and bitmasks for the mouse
     * button state.
     */

  enum MouseButtons { 
    MOUSE_BUTTON_LEFT = 1 , 
    MOUSE_BUTTON_RIGHT = 2 , 
    MOUSE_BUTTON_MIDDLE = 4  };

    IDisplayEvents() : NMM::Interface(IDisplayEvents::IDisplayEvents_type, "NMM") { };

    IDisplayEvents(NMM::NMMObject& parent) : NMM::Interface (parent, IDisplayEvents::IDisplayEvents_type, "NMM") { };

    virtual ~IDisplayEvents() {};

    static const char* IDisplayEvents_type;

    virtual  string getInterfaceType() const { return IDisplayEvents_type; }

    NMM::Interface* copy() const { return new IDisplayEvents(*this); }
    static void used(); 
    static const char* keyPressed_event;
    static NMM::Event* create_keyPressed(const string& key);
    static const char* keyReleased_event;
    static NMM::Event* create_keyReleased(const string& key);
    static const char* keysym_keyPressed_event;
    static NMM::Event* create_keysym_keyPressed(const nmm_uint32& keysym);
    static const char* keysym_keyReleased_event;
    static NMM::Event* create_keysym_keyReleased(const nmm_uint32& keysym);
    static const char* mouseButtonPressed_event;
    static NMM::Event* create_mouseButtonPressed(const nmm_int32& button, const nmm_int32& x, const nmm_int32& y, const nmm_int32& buttons, const nmm_bool& shift);
    static const char* mouseButtonReleased_event;
    static NMM::Event* create_mouseButtonReleased(const nmm_int32& button, const nmm_int32& x, const nmm_int32& y, const nmm_int32& buttons, const nmm_bool& shift);
    static const char* mouseMoved_event;
    static NMM::Event* create_mouseMoved(const nmm_int32& x, const nmm_int32& y, const nmm_int32& buttons, const nmm_bool& shift);
    static const char* windowExposed_event;
    static NMM::Event* create_windowExposed();
    static const char* windowClosed_event;
    static NMM::Event* create_windowClosed();
    static const char* windowResized_event;
    static NMM::Event* create_windowResized(const nmm_int32& xsize, const nmm_int32& ysize);
  /* instream (protected) and non-instream (public) */        /**
     * Key was pressed.
     * Sent by the display to notify the application that a key was pressed in the context of
     * the display window.
     * @param key the identifier of the pressed key
     */

    virtual Result keyPressed(const string& key) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * Key was released.
     * Sent by the display to notify the application that a key was released in the context of
     * the display window.
     * @param key the identifier of the pressed key
     */

    virtual Result keyReleased(const string& key) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * Key was pressed.
     * Sent by the display to notify the application that a key was pressed in the context of
     * the display window.
     * @param key the KeySym of the pressed key
     */

    virtual Result keysym_keyPressed(const nmm_uint32& keysym) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * Key was released.
     * Sent by the display to notify the application that a key was released in the context of
     * the display window.
     * @param key the KeySym of the pressed key
     */

    virtual Result keysym_keyReleased(const nmm_uint32& keysym) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * Mouse button was pressed.
     * Sent by the display to notify the application that a mouse button was pressed in the context of
     * the display window.
     * @param button identifies the mouse button
     * @param x x coordinate of mouse pointer
     * @param y y coordinate of mouse pointer
     * @param buttons mouse button state bitmask
     * @param shift shift key is held down
     */

    virtual Result mouseButtonPressed(const nmm_int32& button, const nmm_int32& x, const nmm_int32& y, const nmm_int32& buttons, const nmm_bool& shift) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * Mouse button was released.
     * Sent by the display to notify the application that a mouse button was released in the context of
     * the display window.
     * @param button identifies the mouse button
     * @param x x coordinate of mouse pointer
     * @param y y coordinate of mouse pointer
     * @param buttons mouse button state bitmask
     * @param shift shift key is held down
     */

    virtual Result mouseButtonReleased(const nmm_int32& button, const nmm_int32& x, const nmm_int32& y, const nmm_int32& buttons, const nmm_bool& shift) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * Mouse was moved
     * Sent by the display to notify the application that th mouse was moved over
     * the display window.
     * @param x x coordinate of mouse pointer
     * @param y y coordinate of mouse pointer
     * @param buttons mouse button state bitmask
     * @param shift shift key is held down
     */

    virtual Result mouseMoved(const nmm_int32& x, const nmm_int32& y, const nmm_int32& buttons, const nmm_bool& shift) /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * The display window was exposed.
     * Sent by the display to notify the application that the user exposed
     * the display window.
     */

    virtual Result windowExposed() /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * The display window was closed.
     * Sent by the display to notify the application that the user closed
     * the display window.
     */

    virtual Result windowClosed() /* in-stream */ 
      throw(const NMM::SerializedException&);
        /**
     * The display window was resized.
     * Sent by the display to notify the application that the user resized
     * the display window.
     * @param xsize new x size of window
     * @param ysize new y size of window
     */

    virtual Result windowResized(const nmm_int32& xsize, const nmm_int32& ysize) /* in-stream */ 
      throw(const NMM::SerializedException&);


  };

  typedef auto_ptr<IDisplayEvents> IDisplayEvents_var;

  DLLEXPORT NMM::OValueStream& operator<<(NMM::OValueStream& ov, const IDisplayEvents::MouseButtons& t);
  DLLEXPORT NMM::IValueStream& operator>>(NMM::IValueStream& iv, IDisplayEvents::MouseButtons& t);



}

#include "nmm/nmm_suffix.hpp"

#endif
