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/custom_event.h"
  11.  
  12. #include "core/document.h"
  13.  
  14. static void _virtual_dom_custom_event_destroy(struct dom_event *evt);
  15.  
  16. static struct dom_event_private_vtable _event_vtable = {
  17.         _virtual_dom_custom_event_destroy
  18. };
  19.  
  20. /* Constructor */
  21. dom_exception _dom_custom_event_create(struct dom_document *doc,
  22.                 struct dom_custom_event **evt)
  23. {
  24.         *evt = malloc(sizeof(dom_custom_event));
  25.         if (*evt == NULL)
  26.                 return DOM_NO_MEM_ERR;
  27.        
  28.         ((struct dom_event *) *evt)->vtable = &_event_vtable;
  29.  
  30.         return _dom_custom_event_initialise(doc, *evt);
  31. }
  32.  
  33. /* Destructor */
  34. void _dom_custom_event_destroy(struct dom_custom_event *evt)
  35. {
  36.         _dom_custom_event_finalise(evt);
  37.  
  38.         free(evt);
  39. }
  40.  
  41. /* Initialise function */
  42. dom_exception _dom_custom_event_initialise(struct dom_document *doc,
  43.                 struct dom_custom_event *evt)
  44. {
  45.         evt->detail = NULL;
  46.         return _dom_event_initialise(doc, &evt->base);
  47. }
  48.  
  49. /* Finalise function */
  50. void _dom_custom_event_finalise(struct dom_custom_event *evt)
  51. {
  52.         evt->detail = NULL;
  53.         _dom_event_finalise(&evt->base);
  54. }
  55.  
  56. /* The virtual destroy function */
  57. void _virtual_dom_custom_event_destroy(struct dom_event *evt)
  58. {
  59.         _dom_custom_event_destroy((dom_custom_event *) evt);
  60. }
  61.  
  62. /*----------------------------------------------------------------------*/
  63. /* The public API */
  64.  
  65. /**
  66.  * Get the detail object of this custom event
  67.  *
  68.  * \param evt     The Event object
  69.  * \param detail  The returned detail object
  70.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  71.  */
  72. dom_exception _dom_custom_event_get_detail(dom_custom_event *evt,
  73.                 void **detail)
  74. {
  75.         *detail = evt->detail;
  76.  
  77.         return DOM_NO_ERR;
  78. }
  79.  
  80. /**
  81.  * Initialise this custom event
  82.  *
  83.  * \param evt         The Event object
  84.  * \param namespace   The namespace of this new Event
  85.  * \param type        The Event type
  86.  * \param bubble      Whether this event can bubble
  87.  * \param cancelable  Whether this event is cancelable
  88.  * \param detail      The detail object of this custom event
  89.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  90.  */
  91. dom_exception _dom_custom_event_init_ns(dom_custom_event *evt,
  92.                 dom_string *namespace, dom_string *type,
  93.                 bool bubble, bool cancelable, void *detail)
  94. {
  95.         evt->detail = detail;
  96.         return _dom_event_init_ns(&evt->base, namespace, type, bubble,
  97.                         cancelable);
  98. }
  99.  
  100.