Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of libdom.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
  6.  */
  7.  
  8. #include <stdlib.h>
  9.  
  10. #include "events/mouse_wheel_event.h"
  11. #include "events/keyboard_event.h"
  12. #include "core/document.h"
  13.  
  14. #include "utils/utils.h"
  15.  
  16. static void _virtual_dom_mouse_wheel_event_destroy(struct dom_event *evt);
  17.  
  18. static struct dom_event_private_vtable _event_vtable = {
  19.         _virtual_dom_mouse_wheel_event_destroy
  20. };
  21.  
  22. /* Constructor */
  23. dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
  24.                 struct dom_mouse_wheel_event **evt)
  25. {
  26.         *evt = malloc(sizeof(dom_mouse_wheel_event));
  27.         if (*evt == NULL)
  28.                 return DOM_NO_MEM_ERR;
  29.        
  30.         ((struct dom_event *) *evt)->vtable = &_event_vtable;
  31.  
  32.         return _dom_mouse_wheel_event_initialise(doc,
  33.                         (dom_mouse_wheel_event *) *evt);
  34. }
  35.  
  36. /* Destructor */
  37. void _dom_mouse_wheel_event_destroy(struct dom_mouse_wheel_event *evt)
  38. {
  39.         _dom_mouse_wheel_event_finalise((dom_ui_event *) evt);
  40.  
  41.         free(evt);
  42. }
  43.  
  44. /* Initialise function */
  45. dom_exception _dom_mouse_wheel_event_initialise(struct dom_document *doc,
  46.                 struct dom_mouse_wheel_event *evt)
  47. {
  48.         return _dom_mouse_event_initialise(doc, (dom_mouse_event *) evt);
  49. }
  50.  
  51. /* The virtual destroy function */
  52. void _virtual_dom_mouse_wheel_event_destroy(struct dom_event *evt)
  53. {
  54.         _dom_mouse_wheel_event_destroy((dom_mouse_wheel_event *) evt);
  55. }
  56.  
  57. /*----------------------------------------------------------------------*/
  58. /* The public API */
  59.  
  60. /**
  61.  * Get wheelDelta
  62.  *
  63.  * \param evt  The Event object
  64.  * \param d    The wheelDelta
  65.  * \return DOM_NO_ERR.
  66.  */
  67. dom_exception _dom_mouse_wheel_event_get_wheel_delta(
  68.                 dom_mouse_wheel_event *evt, int32_t *d)
  69. {
  70.         *d = evt->delta;
  71.  
  72.         return DOM_NO_ERR;
  73. }
  74.  
  75. /**
  76.  * Intialise this event with namespace
  77.  *
  78.  * \param evt            The Event object
  79.  * \param namespace      The namespace of this event
  80.  * \param type           The event's type
  81.  * \param bubble         Whether this is a bubbling event
  82.  * \param cancelable     Whether this is a cancelable event
  83.  * \param view           The AbstractView associated with this event
  84.  * \param detail         The detail information of this mouse event
  85.  * \param screen_x       The x position of the mouse pointer in screen
  86.  * \param screen_y       The y position of the mouse pointer in screen
  87.  * \param client_x       The x position of the mouse pointer in client window
  88.  * \param client_y       The y position of the mouse pointer in client window
  89.  * \param button         The mouse button pressed
  90.  * \param et             The related target of this event, may be NULL
  91.  * \param modifier_list  The string contains the modifier identifier strings
  92.  * \param wheel_delta    The wheelDelta
  93.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  94.  */
  95. dom_exception _dom_mouse_wheel_event_init_ns(
  96.                 dom_mouse_wheel_event *evt, dom_string *namespace,
  97.                 dom_string *type,  bool bubble, bool cancelable,
  98.                 struct dom_abstract_view *view, int32_t detail, int32_t screen_x,
  99.                 int32_t screen_y, int32_t client_x, int32_t client_y,
  100.                 unsigned short button, dom_event_target *et,
  101.                 dom_string *modifier_list, int32_t wheel_delta)
  102. {
  103.         dom_exception err;
  104.         dom_mouse_event *e = (dom_mouse_event *) evt;
  105.         evt->delta = wheel_delta;
  106.  
  107.         err = _dom_parse_modifier_list(modifier_list, &e->modifier_state);
  108.         if (err != DOM_NO_ERR)
  109.                 return err;
  110.  
  111.         return _dom_mouse_event_init_ns(&evt->base, namespace, type, bubble,
  112.                         cancelable, view, detail ,screen_x, screen_y,
  113.                         client_x, client_y, false, false, false, false,
  114.                         button, et);
  115. }
  116.  
  117.