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/ui_event.h"
  11. #include "core/document.h"
  12.  
  13. static void _virtual_dom_ui_event_destroy(struct dom_event *evt);
  14.  
  15. static struct dom_event_private_vtable _event_vtable = {
  16.         _virtual_dom_ui_event_destroy
  17. };
  18.  
  19. /* Constructor */
  20. dom_exception _dom_ui_event_create(struct dom_document *doc,
  21.                 struct dom_ui_event **evt)
  22. {
  23.         *evt = malloc(sizeof(dom_ui_event));
  24.         if (*evt == NULL)
  25.                 return DOM_NO_MEM_ERR;
  26.        
  27.         ((struct dom_event *) *evt)->vtable = &_event_vtable;
  28.  
  29.         return _dom_ui_event_initialise(doc, *evt);
  30. }
  31.  
  32. /* Destructor */
  33. void _dom_ui_event_destroy(struct dom_ui_event *evt)
  34. {
  35.         _dom_ui_event_finalise(evt);
  36.  
  37.         free(evt);
  38. }
  39.  
  40. /* Initialise function */
  41. dom_exception _dom_ui_event_initialise(struct dom_document *doc,
  42.                 struct dom_ui_event *evt)
  43. {
  44.         evt->view = NULL;
  45.         return _dom_event_initialise(doc, &evt->base);
  46. }
  47.  
  48. /* Finalise function */
  49. void _dom_ui_event_finalise(struct dom_ui_event *evt)
  50. {
  51.         evt->view = NULL;
  52.         _dom_event_finalise(&evt->base);
  53. }
  54.  
  55. /* The virtual destroy function */
  56. void _virtual_dom_ui_event_destroy(struct dom_event *evt)
  57. {
  58.         _dom_ui_event_destroy((dom_ui_event *) evt);
  59. }
  60.  
  61. /*----------------------------------------------------------------------*/
  62. /* The public API */
  63.  
  64. /**
  65.  * Get the AbstractView inside this event
  66.  *
  67.  * \param evt   The Event object
  68.  * \param view  The returned AbstractView
  69.  * \return DOM_NO_ERR.
  70.  */
  71. dom_exception _dom_ui_event_get_view(dom_ui_event *evt,
  72.                 struct dom_abstract_view **view)
  73. {
  74.         *view = evt->view;
  75.  
  76.         return DOM_NO_ERR;
  77. }
  78.  
  79. /**
  80.  * Get the detail param of this event
  81.  *
  82.  * \param evt     The Event object
  83.  * \param detail  The detail object
  84.  * \return DOM_NO_ERR.
  85.  */
  86. dom_exception _dom_ui_event_get_detail(dom_ui_event *evt,
  87.                 int32_t *detail)
  88. {
  89.         *detail = evt->detail;
  90.  
  91.         return DOM_NO_ERR;
  92. }
  93.  
  94. /**
  95.  * Initialise the UIEvent
  96.  *
  97.  * \param evt         The Event object
  98.  * \param type        The type of this UIEvent
  99.  * \param bubble      Whether this event can bubble
  100.  * \param cancelable  Whether this event is cancelable
  101.  * \param view        The AbstractView of this UIEvent
  102.  * \param detail      The detail object
  103.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  104.  */
  105. dom_exception _dom_ui_event_init(dom_ui_event *evt, dom_string *type,
  106.                 bool bubble, bool cancelable, struct dom_abstract_view *view,
  107.                 int32_t detail)
  108. {
  109.         evt->view = view;
  110.         evt->detail = detail;
  111.  
  112.         return _dom_event_init(&evt->base, type, bubble, cancelable);
  113. }
  114.  
  115. /**
  116.  * Initialise the UIEvent with namespace
  117.  *
  118.  * \param evt         The Event object
  119.  * \param namespace   The namespace of this Event
  120.  * \param type        The type of this UIEvent
  121.  * \param bubble      Whether this event can bubble
  122.  * \param cancelable  Whether this event is cancelable
  123.  * \param view        The AbstractView of this UIEvent
  124.  * \param detail      The detail object
  125.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  126.  */
  127. dom_exception _dom_ui_event_init_ns(dom_ui_event *evt,
  128.                 dom_string *namespace, dom_string *type,
  129.                 bool bubble, bool cancelable, struct dom_abstract_view *view,
  130.                 int32_t detail)
  131. {
  132.         evt->view = view;
  133.         evt->detail = detail;
  134.  
  135.         return _dom_event_init_ns(&evt->base, namespace, type, bubble,
  136.                         cancelable);
  137. }
  138.  
  139.