]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/CanvasEvent.hxx
Update for OpenSceneGraph 3.3.2 API changes.
[simgear.git] / simgear / canvas / CanvasEvent.hxx
index c3121269e90c90435e16eab424bac5f34c3ab5d1..23da1048c2ef28a1d4a876a8b6804a78a9c97ebf 100644 (file)
@@ -1,4 +1,5 @@
-// Canvas Event for event model similar to DOM Level 3 Event Model
+/// @file
+/// Canvas Event for event model similar to DOM Level 3 Event Model
 //
 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
 //
 #define CANVAS_EVENT_HXX_
 
 #include "canvas_fwd.hxx"
+#include <boost/bimap.hpp>
 
 namespace simgear
 {
 namespace canvas
 {
 
-  class Event
+  /**
+   * Base class for all Canvas events.
+   *
+   * The event system is closely following the specification of the DOM Level 3
+   * Event Model.
+   */
+  class Event:
+    public SGReferenced
   {
     public:
 
+      /// Event type identifier
       enum Type
       {
         UNKNOWN,
-#       define ENUM_MAPPING(name, str) name,
+#       define ENUM_MAPPING(name, str, class_name)\
+                 name, /*!< class_name (type=str) */
 #         include "CanvasEventTypes.hxx"
 #       undef ENUM_MAPPING
-        USER_TYPE ///<! first unused id to be used for user defined types (not
-                  ///   implemented yet)
+        CUSTOM_EVENT ///< First event type id available for user defined event
+                     ///  type.
+                     /// @see CustomEvent
       };
 
-      Type              type;
+      int               type;
       ElementWeakPtr    target,
                         current_target;
       double            time;
-      bool              propagation_stopped;
+      bool              propagation_stopped,
+                        default_prevented;
 
       Event();
 
@@ -52,17 +65,64 @@ namespace canvas
       // of the actual event instances.
       virtual ~Event();
 
-      Type getType() const;
+      /**
+       * Get whether this events support bubbling
+       */
+      virtual bool canBubble() const;
+
+      /**
+       * Set type of event.
+       *
+       * If no such type exists it is registered.
+       */
+      void setType(const std::string& type);
+
+      int getType() const;
       std::string getTypeString() const;
 
       ElementWeakPtr getTarget() const;
       ElementWeakPtr getCurrentTarget() const;
 
+      /**
+       * Get time at which the event was generated.
+       */
       double getTime() const;
 
+      /**
+       * Prevent further propagation of the event during event flow.
+       *
+       * @note This does not prevent calling further event handlers registered
+       *       on the current event target.
+       */
       void stopPropagation();
 
-      static Type strToType(const std::string& str);
+      /**
+       * Cancel any default action normally taken as result of this event.
+       *
+       * @note For event handlers registered on the DesktopGroup (Nasal:
+       *       canvas.getDesktop()) this stops the event from being further
+       *       propagated to the normal FlightGear input event handling code.
+       */
+      void preventDefault();
+
+      /**
+       * Get if preventDefault() has been called.
+       */
+      bool defaultPrevented() const;
+
+      static int getOrRegisterType(const std::string& type);
+      static int strToType(const std::string& type);
+      static std::string typeToStr(int type);
+
+    protected:
+      struct name {};
+      struct id {};
+      typedef boost::bimaps::bimap<
+        boost::bimaps::tagged<std::string, name>,
+        boost::bimaps::tagged<int, id>
+      > TypeMap;
+
+      static TypeMap& getTypeMap();
 
   };