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