Debian Codegraph @

libgdome/events/gdome-evt-mevent.c

raw
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
2 /* gdome-xml-mevent.c
3 *
4 * Copyright (C) 1999 Raph Levien <[email protected]>
5 * Copyright (C) 2000 Mathieu Lacage <[email protected]>
6 * Copyright (C) 2001 Paolo Casarini <[email protected]>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26 #include <string.h>
27 #include "gdome.h"
28 #include "gdome-events.h"
29 #include "gdome-refdebug.h"
30 #include "gdome-evt-util.h"
31 #include "gdome-xml-node.h"
32 #include "gdome-xml-str.h"
33 #include "gdome-evt-event.h"
34 #include "gdome-evt-eventl.h"
35 #include "gdome-evt-mevent.h"
36
37 const GdomeMutationEventVtab gdome_evt_mevnt_vtab =
38 {
39 {
40 gdome_evt_evnt_ref,
41 gdome_evt_mevnt_unref,
42 gdome_evt_mevnt_query_interface,
43 gdome_evt_evnt_bubbles,
44 gdome_evt_evnt_cancelable,
45 gdome_evt_evnt_currentTarget,
46 gdome_evt_evnt_eventPhase,
47 gdome_evt_evnt_target,
48 gdome_evt_evnt_timeStamp,
49 gdome_evt_evnt_type,
50 gdome_evt_evnt_initEvent,
51 gdome_evt_evnt_preventDefault,
52 gdome_evt_evnt_stopPropagation,
53 },
54 gdome_evt_mevnt_attrChange,
55 gdome_evt_mevnt_attrName,
56 gdome_evt_mevnt_newValue,
57 gdome_evt_mevnt_prevValue,
58 gdome_evt_mevnt_relatedNode,
59 gdome_evt_mevnt_initMutationEvent
60 };
61
62 /**
63 * gdome_evt_mevnt_mkref:
64 *
65 * Returns: a new allocated #GdomeMutationEvent.
66 */
67 GdomeMutationEvent *
68 gdome_evt_mevnt_mkref (void) {
69 Gdome_evt_MutationEvent *result = NULL;
70
71 result = g_new (Gdome_evt_MutationEvent, 1);
72 #ifdef DEBUG_REFCNT
73 gdome_refdbg_addRef ((void *)result, GDOME_REFDBG_EVENT);
74 #endif
75 memset(result, 0, sizeof(Gdome_evt_MutationEvent));
76 result->vtab = &gdome_evt_mevnt_vtab;
77 result->etype = GDOME_MUTATION_EVENT;
78 result->refcnt = 1;
79 result->super.user_data = NULL;
80
81 return (GdomeMutationEvent *)result;
82 }
83
84 /**
85 * gdome_evt_mevnt_unref:
86 * @self: MutationEvent Object ref
87 * @exc: Exception Object ref
88 *
89 * Decrease the reference count of the specified MutationEvent. Free the
90 * MutationEvent structure if the MutationEvent will have zero reference.
91 */
92 void
93 gdome_evt_mevnt_unref (GdomeEvent *self, GdomeException *exc)
94 {
95 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
96
97 g_return_if_fail (priv != NULL);
98 g_return_if_fail (GDOME_XML_IS_EVNT (priv));
99 g_return_if_fail (exc != NULL);
100
101 if (--priv->refcnt == 0) {
102 if (priv->attrName != NULL)
103 gdome_xml_str_unref (priv->attrName);
104 if (priv->newValue != NULL)
105 gdome_xml_str_unref (priv->newValue);
106 if (priv->prevValue != NULL)
107 gdome_xml_str_unref (priv->prevValue);
108 if (priv->relatedNode != NULL)
109 gdome_xml_n_unref (priv->relatedNode, exc);
110 #ifdef DEBUG_REFCNT
111 gdome_refdbg_delRef ((void *)self, GDOME_REFDBG_EVENT);
112 #endif
113 g_free (self);
114 }
115 }
116
117 /**
118 * gdome_evt_mevnt_query_interface:
119 * @self: Event Object ref
120 * @interface: name of the Interface needed.
121 * @exc: Exception Object ref
122 *
123 * Returns: a reference to the object that implements the interface needed or
124 * %NULL if this object doesn't implement the interface specified.
125 */
126 void *
127 gdome_evt_mevnt_query_interface (GdomeEvent *self, const char *interface, GdomeException *exc)
128 {
129 Gdome_evt_Event *priv = (Gdome_evt_Event *)self;
130
131 g_return_val_if_fail (priv != NULL, NULL);
132 g_return_val_if_fail (GDOME_XML_IS_EVNT (priv), NULL);
133 g_return_val_if_fail (interface != NULL, NULL);
134 g_return_val_if_fail (exc != NULL, NULL);
135
136 if (!strcmp (interface, "Event") ||
137 !strcmp (interface, "MutationEvent")) {
138 priv->refcnt++;
139 return self;
140 }
141 else
142 return NULL;
143 }
144
145
146 /**
147 * gdome_evt_mevnt_attrChange:
148 * @self: MutationEvent Object ref
149 * @exc: Exception Object ref
150 *
151 * Returns: the type of change which triggered the DOMAttrModified event.
152 * The values can be %MODIFICATION, %ADDITION, or %REMOVAL. If an error
153 * occur, %0 is returned.
154 */
155 gushort
156 gdome_evt_mevnt_attrChange (GdomeMutationEvent *self, GdomeException *exc)
157 {
158 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
159
160 g_return_val_if_fail (self != NULL, 0);
161 g_return_val_if_fail (exc != NULL, 0);
162
163 return priv->attrChange;
164 }
165
166 /**
167 * gdome_evt_mevnt_attrName:
168 * @self: MutationEvent Object ref
169 * @exc: Exception Object ref
170 *
171 * Returns: the name of the changed Attr node in a DOMAttrModified event.
172 */
173 GdomeDOMString *
174 gdome_evt_mevnt_attrName (GdomeMutationEvent *self, GdomeException *exc)
175 {
176 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
177
178 g_return_val_if_fail (self != NULL, NULL);
179 g_return_val_if_fail (exc != NULL, NULL);
180 if (priv->attrName != NULL) gdome_str_ref(priv->attrName);
181
182 return priv->attrName;
183 }
184
185 /**
186 * gdome_evt_mevnt_newValue:
187 * @self: MutationEvent Object ref
188 * @exc: Exception Object ref
189 *
190 * Returns: the new value of the Attr node in DOMAttrModified events,
191 * and of the CharacterData node in DOMCharDataModified events.
192 */
193 GdomeDOMString *
194 gdome_evt_mevnt_newValue (GdomeMutationEvent *self, GdomeException *exc)
195 {
196 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
197
198 g_return_val_if_fail (self != NULL, NULL);
199 g_return_val_if_fail (exc != NULL, NULL);
200 if (priv->newValue != NULL) gdome_str_ref(priv->newValue);
201
202 return priv->newValue;
203 }
204
205 /**
206 * gdome_evt_mevnt_prevValue:
207 * @self: MutationEvent Object ref
208 * @exc: Exception Object ref
209 *
210 * Returns: the previous value of the Attr node in DOMAttrModified events,
211 * and of the CharacterData node in DOMCharDataModified events.
212 */
213 GdomeDOMString *
214 gdome_evt_mevnt_prevValue (GdomeMutationEvent *self, GdomeException *exc)
215 {
216 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
217
218 g_return_val_if_fail (self != NULL, NULL);
219 g_return_val_if_fail (exc != NULL, NULL);
220 if (priv->prevValue != NULL) gdome_str_ref(priv->prevValue);
221
222 return priv->prevValue;
223 }
224
225 /**
226 * gdome_evt_mevnt_relatedNode:
227 * @self: MutationEvent Object ref
228 * @exc: Exception Object ref
229 *
230 * Returns: a secondary node related to a mutation event. For example, if a
231 * mutation event is dispatched to a node indicating that its parent has
232 * changed, the relatedNode is the changed parent. If an event is instead
233 * dispatched to a subtree indicating a node was changed within it, the
234 * relatedNode is the changed node. In the case of the DOMAttrModified event
235 * it indicates the Attr node which was modified, added, or removed.
236 */
237 GdomeNode *
238 gdome_evt_mevnt_relatedNode (GdomeMutationEvent *self, GdomeException *exc)
239 {
240 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
241
242 g_return_val_if_fail (self != NULL, NULL);
243 g_return_val_if_fail (exc != NULL, NULL);
244 if (priv->relatedNode != NULL) gdome_n_ref(priv->relatedNode, exc);
245
246 return priv->relatedNode;
247 }
248
249 /**
250 * gdome_evt_mevnt_initMutationEventByCode:
251 *
252 * see documentation for gdome_evt_mevnt_initMutationEvent
253 */
254 void
255 gdome_evt_mevnt_initMutationEventByCode (GdomeMutationEvent *self,
256 guint32 typeArg,
257 GdomeBoolean canBubbleArg,
258 GdomeBoolean cancelableArg,
259 GdomeNode *relatedNodeArg,
260 GdomeDOMString *prevValueArg,
261 GdomeDOMString *newValueArg,
262 GdomeDOMString *attrNameArg,
263 gushort attrChangeArg,
264 GdomeException *exc)
265 {
266 Gdome_evt_MutationEvent *priv = (Gdome_evt_MutationEvent *)self;
267
268 g_return_if_fail (self != NULL);
269 g_return_if_fail (exc != NULL);
270
271 gdome_evt_evnt_initEventByCode ((GdomeEvent *)self, typeArg, canBubbleArg, cancelableArg, exc);
272 priv->attrChange = attrChangeArg;
273 if (attrNameArg != NULL) {
274 gdome_xml_str_ref (attrNameArg);
275 priv->attrName = attrNameArg;
276 }
277 if (newValueArg != NULL) {
278 gdome_xml_str_ref (newValueArg);
279 priv->newValue = newValueArg;
280 }
281 if (prevValueArg != NULL) {
282 gdome_xml_str_ref (prevValueArg);
283 priv->prevValue = prevValueArg;
284 }
285 if (relatedNodeArg != NULL) {
286 gdome_xml_n_ref (relatedNodeArg, exc);
287 priv->relatedNode = relatedNodeArg;
288 }
289 }
290
291 /**
292 * gdome_evt_mevnt_initMutationEvent:
293 * @self: MutationEvent Object ref
294 * @typeArg: Specifies the event type.
295 * @canBubbleArg: Specifies whether or not the event can bubble.
296 * @cancelableArg: Specifies whether or not the event's default action
297 * can be prevented.
298 * @relatedNodeArg: Specifies the Event's related Node. This value may
299 * be %NULL.
300 * @prevValueArg: Specifies the Event's prevValue attribute. This value
301 * may be %NULL.
302 * @newValueArg: Specifies the Event's newValue attribute. This value
303 * may be %NULL.
304 * @attrNameArg: Specifies the Event's attrName attribute. This value
305 * may be null.
306 * @attrChangeArg: Specifies the Event's attrChange attribute
307 * @exc: Exception Object ref
308 *
309 * The initMutationEvent method is used to initialize the value of a
310 * #GdomeMutationEvent created through the DocumentEvent interface. This
311 * method may only be called before the MutationEvent has been dispatched
312 * via the dispatchEvent method, though it may be called multiple times
313 * during that phase if necessary. If called multiple times, the final
314 * invocation takes precedence.
315 */
316 void
317 gdome_evt_mevnt_initMutationEvent (GdomeMutationEvent *self,
318 GdomeDOMString *typeArg,
319 GdomeBoolean canBubbleArg,
320 GdomeBoolean cancelableArg,
321 GdomeNode *relatedNodeArg,
322 GdomeDOMString *prevValueArg,
323 GdomeDOMString *newValueArg,
324 GdomeDOMString *attrNameArg,
325 gushort attrChangeArg,
326 GdomeException *exc)
327 {
328 g_return_if_fail (typeArg != NULL);
329 gdome_evt_mevnt_initMutationEventByCode (self,
330 gdome_evt_evnt_codeOfName (typeArg->str),
331 canBubbleArg,
332 cancelableArg,
333 relatedNodeArg,
334 prevValueArg,
335 newValueArg,
336 attrNameArg,
337 attrChangeArg,
338 exc);
339 }