mathematical 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/mathematical/extconf.rb +14 -0
- data/ext/mathematical/itex2MML.h +63 -0
- data/ext/mathematical/lasemrender.c +257 -0
- data/ext/mathematical/lex.yy.c +6548 -0
- data/ext/mathematical/lsm.c +31 -0
- data/ext/mathematical/lsm.h +39 -0
- data/ext/mathematical/lsmattributes.c +279 -0
- data/ext/mathematical/lsmattributes.h +75 -0
- data/ext/mathematical/lsmcairo.c +598 -0
- data/ext/mathematical/lsmcairo.h +51 -0
- data/ext/mathematical/lsmdebug.c +183 -0
- data/ext/mathematical/lsmdebug.h +73 -0
- data/ext/mathematical/lsmdom.h +43 -0
- data/ext/mathematical/lsmdomcharacterdata.c +114 -0
- data/ext/mathematical/lsmdomcharacterdata.h +59 -0
- data/ext/mathematical/lsmdomdocument.c +255 -0
- data/ext/mathematical/lsmdomdocument.h +75 -0
- data/ext/mathematical/lsmdomdocumentfragment.c +81 -0
- data/ext/mathematical/lsmdomdocumentfragment.h +55 -0
- data/ext/mathematical/lsmdomelement.c +148 -0
- data/ext/mathematical/lsmdomelement.h +62 -0
- data/ext/mathematical/lsmdomentities.c +2166 -0
- data/ext/mathematical/lsmdomentities.h +35 -0
- data/ext/mathematical/lsmdomenumtypes.c +99 -0
- data/ext/mathematical/lsmdomenumtypes.h +26 -0
- data/ext/mathematical/lsmdomimplementation.c +82 -0
- data/ext/mathematical/lsmdomimplementation.h +41 -0
- data/ext/mathematical/lsmdomnamednodemap.c +118 -0
- data/ext/mathematical/lsmdomnamednodemap.h +64 -0
- data/ext/mathematical/lsmdomnode.c +737 -0
- data/ext/mathematical/lsmdomnode.h +122 -0
- data/ext/mathematical/lsmdomnodelist.c +70 -0
- data/ext/mathematical/lsmdomnodelist.h +58 -0
- data/ext/mathematical/lsmdomparser.c +461 -0
- data/ext/mathematical/lsmdomparser.h +54 -0
- data/ext/mathematical/lsmdomtext.c +82 -0
- data/ext/mathematical/lsmdomtext.h +55 -0
- data/ext/mathematical/lsmdomtypes.h +44 -0
- data/ext/mathematical/lsmdomview.c +422 -0
- data/ext/mathematical/lsmdomview.h +94 -0
- data/ext/mathematical/lsmitex.c +76 -0
- data/ext/mathematical/lsmitex.h +36 -0
- data/ext/mathematical/lsmmathml.h +66 -0
- data/ext/mathematical/lsmmathmlactionelement.c +93 -0
- data/ext/mathematical/lsmmathmlactionelement.h +57 -0
- data/ext/mathematical/lsmmathmlaligngroupelement.c +102 -0
- data/ext/mathematical/lsmmathmlaligngroupelement.h +56 -0
- data/ext/mathematical/lsmmathmlalignmarkelement.c +102 -0
- data/ext/mathematical/lsmmathmlalignmarkelement.h +56 -0
- data/ext/mathematical/lsmmathmlattributes.c +197 -0
- data/ext/mathematical/lsmmathmlattributes.h +126 -0
- data/ext/mathematical/lsmmathmldocument.c +304 -0
- data/ext/mathematical/lsmmathmldocument.h +61 -0
- data/ext/mathematical/lsmmathmlelement.c +491 -0
- data/ext/mathematical/lsmmathmlelement.h +107 -0
- data/ext/mathematical/lsmmathmlenums.c +429 -0
- data/ext/mathematical/lsmmathmlenums.h +182 -0
- data/ext/mathematical/lsmmathmlenumtypes.c +666 -0
- data/ext/mathematical/lsmmathmlenumtypes.h +90 -0
- data/ext/mathematical/lsmmathmlerrorelement.c +58 -0
- data/ext/mathematical/lsmmathmlerrorelement.h +56 -0
- data/ext/mathematical/lsmmathmlfencedelement.c +178 -0
- data/ext/mathematical/lsmmathmlfencedelement.h +65 -0
- data/ext/mathematical/lsmmathmlfractionelement.c +253 -0
- data/ext/mathematical/lsmmathmlfractionelement.h +62 -0
- data/ext/mathematical/lsmmathmlglyphtableams.c +597 -0
- data/ext/mathematical/lsmmathmlglyphtableams.h +45 -0
- data/ext/mathematical/lsmmathmlitexelement.c +187 -0
- data/ext/mathematical/lsmmathmlitexelement.h +60 -0
- data/ext/mathematical/lsmmathmllayoututils.c +191 -0
- data/ext/mathematical/lsmmathmllayoututils.h +58 -0
- data/ext/mathematical/lsmmathmlmathelement.c +204 -0
- data/ext/mathematical/lsmmathmlmathelement.h +81 -0
- data/ext/mathematical/lsmmathmloperatordictionary.c +3332 -0
- data/ext/mathematical/lsmmathmloperatordictionary.h +54 -0
- data/ext/mathematical/lsmmathmloperatorelement.c +307 -0
- data/ext/mathematical/lsmmathmloperatorelement.h +73 -0
- data/ext/mathematical/lsmmathmlpaddedelement.c +58 -0
- data/ext/mathematical/lsmmathmlpaddedelement.h +56 -0
- data/ext/mathematical/lsmmathmlphantomelement.c +71 -0
- data/ext/mathematical/lsmmathmlphantomelement.h +56 -0
- data/ext/mathematical/lsmmathmlpresentationcontainer.c +43 -0
- data/ext/mathematical/lsmmathmlpresentationcontainer.h +54 -0
- data/ext/mathematical/lsmmathmlpresentationtoken.c +303 -0
- data/ext/mathematical/lsmmathmlpresentationtoken.h +83 -0
- data/ext/mathematical/lsmmathmlradicalelement.c +266 -0
- data/ext/mathematical/lsmmathmlradicalelement.h +71 -0
- data/ext/mathematical/lsmmathmlrowelement.c +58 -0
- data/ext/mathematical/lsmmathmlrowelement.h +56 -0
- data/ext/mathematical/lsmmathmlscriptelement.c +282 -0
- data/ext/mathematical/lsmmathmlscriptelement.h +78 -0
- data/ext/mathematical/lsmmathmlsemanticselement.c +84 -0
- data/ext/mathematical/lsmmathmlsemanticselement.h +56 -0
- data/ext/mathematical/lsmmathmlspaceelement.c +142 -0
- data/ext/mathematical/lsmmathmlspaceelement.h +60 -0
- data/ext/mathematical/lsmmathmlstringelement.c +123 -0
- data/ext/mathematical/lsmmathmlstringelement.h +58 -0
- data/ext/mathematical/lsmmathmlstyle.c +130 -0
- data/ext/mathematical/lsmmathmlstyle.h +81 -0
- data/ext/mathematical/lsmmathmlstyleelement.c +307 -0
- data/ext/mathematical/lsmmathmlstyleelement.h +87 -0
- data/ext/mathematical/lsmmathmltablecellelement.c +122 -0
- data/ext/mathematical/lsmmathmltablecellelement.h +62 -0
- data/ext/mathematical/lsmmathmltableelement.c +545 -0
- data/ext/mathematical/lsmmathmltableelement.h +78 -0
- data/ext/mathematical/lsmmathmltablerowelement.c +120 -0
- data/ext/mathematical/lsmmathmltablerowelement.h +64 -0
- data/ext/mathematical/lsmmathmltraits.c +819 -0
- data/ext/mathematical/lsmmathmltraits.h +119 -0
- data/ext/mathematical/lsmmathmltypes.h +66 -0
- data/ext/mathematical/lsmmathmlunderoverelement.c +485 -0
- data/ext/mathematical/lsmmathmlunderoverelement.h +82 -0
- data/ext/mathematical/lsmmathmlutils.c +170 -0
- data/ext/mathematical/lsmmathmlutils.h +50 -0
- data/ext/mathematical/lsmmathmlview.c +1048 -0
- data/ext/mathematical/lsmmathmlview.h +164 -0
- data/ext/mathematical/lsmproperties.c +418 -0
- data/ext/mathematical/lsmproperties.h +85 -0
- data/ext/mathematical/lsmstr.c +231 -0
- data/ext/mathematical/lsmstr.h +114 -0
- data/ext/mathematical/lsmsvg.h +67 -0
- data/ext/mathematical/lsmsvgaelement.c +73 -0
- data/ext/mathematical/lsmsvgaelement.h +55 -0
- data/ext/mathematical/lsmsvgattributes.h +118 -0
- data/ext/mathematical/lsmsvgcircleelement.c +153 -0
- data/ext/mathematical/lsmsvgcircleelement.h +59 -0
- data/ext/mathematical/lsmsvgclippathelement.c +134 -0
- data/ext/mathematical/lsmsvgclippathelement.h +59 -0
- data/ext/mathematical/lsmsvgcolors.c +212 -0
- data/ext/mathematical/lsmsvgcolors.h +39 -0
- data/ext/mathematical/lsmsvgdefselement.c +74 -0
- data/ext/mathematical/lsmsvgdefselement.h +55 -0
- data/ext/mathematical/lsmsvgdocument.c +288 -0
- data/ext/mathematical/lsmsvgdocument.h +64 -0
- data/ext/mathematical/lsmsvgelement.c +373 -0
- data/ext/mathematical/lsmsvgelement.h +81 -0
- data/ext/mathematical/lsmsvgellipseelement.c +158 -0
- data/ext/mathematical/lsmsvgellipseelement.h +60 -0
- data/ext/mathematical/lsmsvgenums.c +544 -0
- data/ext/mathematical/lsmsvgenums.h +357 -0
- data/ext/mathematical/lsmsvgenumtypes.c +1083 -0
- data/ext/mathematical/lsmsvgenumtypes.h +111 -0
- data/ext/mathematical/lsmsvgfilterblend.c +105 -0
- data/ext/mathematical/lsmsvgfilterblend.h +58 -0
- data/ext/mathematical/lsmsvgfiltercomposite.c +109 -0
- data/ext/mathematical/lsmsvgfiltercomposite.h +58 -0
- data/ext/mathematical/lsmsvgfilterelement.c +266 -0
- data/ext/mathematical/lsmsvgfilterelement.h +66 -0
- data/ext/mathematical/lsmsvgfilterflood.c +86 -0
- data/ext/mathematical/lsmsvgfilterflood.h +55 -0
- data/ext/mathematical/lsmsvgfiltergaussianblur.c +114 -0
- data/ext/mathematical/lsmsvgfiltergaussianblur.h +57 -0
- data/ext/mathematical/lsmsvgfiltermerge.c +98 -0
- data/ext/mathematical/lsmsvgfiltermerge.h +55 -0
- data/ext/mathematical/lsmsvgfiltermergenode.c +87 -0
- data/ext/mathematical/lsmsvgfiltermergenode.h +57 -0
- data/ext/mathematical/lsmsvgfilteroffset.c +112 -0
- data/ext/mathematical/lsmsvgfilteroffset.h +58 -0
- data/ext/mathematical/lsmsvgfilterprimitive.c +168 -0
- data/ext/mathematical/lsmsvgfilterprimitive.h +66 -0
- data/ext/mathematical/lsmsvgfilterspecularlighting.c +127 -0
- data/ext/mathematical/lsmsvgfilterspecularlighting.h +60 -0
- data/ext/mathematical/lsmsvgfiltersurface.c +455 -0
- data/ext/mathematical/lsmsvgfiltersurface.h +66 -0
- data/ext/mathematical/lsmsvgfiltertile.c +102 -0
- data/ext/mathematical/lsmsvgfiltertile.h +57 -0
- data/ext/mathematical/lsmsvggelement.c +73 -0
- data/ext/mathematical/lsmsvggelement.h +55 -0
- data/ext/mathematical/lsmsvggradientelement.c +151 -0
- data/ext/mathematical/lsmsvggradientelement.h +68 -0
- data/ext/mathematical/lsmsvgimageelement.c +261 -0
- data/ext/mathematical/lsmsvgimageelement.h +67 -0
- data/ext/mathematical/lsmsvglength.c +152 -0
- data/ext/mathematical/lsmsvglength.h +65 -0
- data/ext/mathematical/lsmsvglineargradientelement.c +271 -0
- data/ext/mathematical/lsmsvglineargradientelement.h +60 -0
- data/ext/mathematical/lsmsvglineelement.c +153 -0
- data/ext/mathematical/lsmsvglineelement.h +60 -0
- data/ext/mathematical/lsmsvgmarkerelement.c +266 -0
- data/ext/mathematical/lsmsvgmarkerelement.h +74 -0
- data/ext/mathematical/lsmsvgmaskelement.c +232 -0
- data/ext/mathematical/lsmsvgmaskelement.h +64 -0
- data/ext/mathematical/lsmsvgmatrix.c +205 -0
- data/ext/mathematical/lsmsvgmatrix.h +59 -0
- data/ext/mathematical/lsmsvgpathelement.c +115 -0
- data/ext/mathematical/lsmsvgpathelement.h +59 -0
- data/ext/mathematical/lsmsvgpatternelement.c +398 -0
- data/ext/mathematical/lsmsvgpatternelement.h +69 -0
- data/ext/mathematical/lsmsvgpolygonelement.c +106 -0
- data/ext/mathematical/lsmsvgpolygonelement.h +57 -0
- data/ext/mathematical/lsmsvgpolylineelement.c +106 -0
- data/ext/mathematical/lsmsvgpolylineelement.h +57 -0
- data/ext/mathematical/lsmsvgradialgradientelement.c +323 -0
- data/ext/mathematical/lsmsvgradialgradientelement.h +61 -0
- data/ext/mathematical/lsmsvgrectelement.c +184 -0
- data/ext/mathematical/lsmsvgrectelement.h +62 -0
- data/ext/mathematical/lsmsvgstopelement.c +106 -0
- data/ext/mathematical/lsmsvgstopelement.h +57 -0
- data/ext/mathematical/lsmsvgstyle.c +560 -0
- data/ext/mathematical/lsmsvgstyle.h +217 -0
- data/ext/mathematical/lsmsvgsvgelement.c +260 -0
- data/ext/mathematical/lsmsvgsvgelement.h +71 -0
- data/ext/mathematical/lsmsvgswitchelement.c +103 -0
- data/ext/mathematical/lsmsvgswitchelement.h +55 -0
- data/ext/mathematical/lsmsvgsymbolelement.c +74 -0
- data/ext/mathematical/lsmsvgsymbolelement.h +55 -0
- data/ext/mathematical/lsmsvgtextelement.c +203 -0
- data/ext/mathematical/lsmsvgtextelement.h +60 -0
- data/ext/mathematical/lsmsvgtraits.c +1232 -0
- data/ext/mathematical/lsmsvgtraits.h +104 -0
- data/ext/mathematical/lsmsvgtransformable.c +106 -0
- data/ext/mathematical/lsmsvgtransformable.h +54 -0
- data/ext/mathematical/lsmsvgtspanelement.c +174 -0
- data/ext/mathematical/lsmsvgtspanelement.h +60 -0
- data/ext/mathematical/lsmsvgtypes.h +77 -0
- data/ext/mathematical/lsmsvguseelement.c +237 -0
- data/ext/mathematical/lsmsvguseelement.h +69 -0
- data/ext/mathematical/lsmsvgview.c +2583 -0
- data/ext/mathematical/lsmsvgview.h +179 -0
- data/ext/mathematical/lsmtraits.c +119 -0
- data/ext/mathematical/lsmtraits.h +49 -0
- data/ext/mathematical/lsmtypes.h +36 -0
- data/ext/mathematical/lsmutils.c +54 -0
- data/ext/mathematical/lsmutils.h +56 -0
- data/ext/mathematical/mathematical.c +145 -0
- data/ext/mathematical/y.tab.c +6179 -0
- data/ext/mathematical/y.tab.h +389 -0
- data/lib/mathematical/version.rb +1 -1
- data/mathematical.gemspec +8 -6
- data/test/mathematical/basic_test.rb +9 -0
- data/test/mathematical/fixtures/after/brackets_display.html +1 -0
- data/test/mathematical/fixtures/after/compliance_accents.html +17 -0
- data/test/mathematical/fixtures/after/compliance_arrows.html +71 -0
- data/test/mathematical/fixtures/after/compliance_colors.html +4 -0
- data/test/mathematical/fixtures/after/compliance_greek_letters.html +42 -0
- data/test/mathematical/fixtures/after/compliance_large_math.html +19 -0
- data/test/mathematical/fixtures/after/compliance_log_symbols.html +34 -0
- data/test/mathematical/fixtures/after/compliance_operators.html +262 -0
- data/test/mathematical/fixtures/after/dollar_sign_inline.html +1 -0
- data/test/mathematical/fixtures/after/equation_display.html +1 -0
- data/test/mathematical/fixtures/after/multiple_dollar_inline.html +1 -0
- data/test/mathematical/fixtures/after/parens_inline.html +1 -0
- data/test/mathematical/fixtures/before/brackets_display.text +1 -0
- data/test/mathematical/fixtures/before/compliance_accents.text +17 -0
- data/test/mathematical/fixtures/before/compliance_arrows.text +71 -0
- data/test/mathematical/fixtures/before/compliance_colors.text +4 -0
- data/test/mathematical/fixtures/before/compliance_greek_letters.text +42 -0
- data/test/mathematical/fixtures/before/compliance_large_math.text +19 -0
- data/test/mathematical/fixtures/before/compliance_log_symbols.text +34 -0
- data/test/mathematical/fixtures/before/compliance_operators.text +262 -0
- data/test/mathematical/fixtures/before/dollar_sign_inline.text +1 -0
- data/test/mathematical/fixtures/before/equation_display.text +1 -0
- data/test/mathematical/fixtures/before/multiple_dollar_inline.text +1 -0
- data/test/mathematical/fixtures/before/parens_inline.text +1 -0
- data/test/mathematical/fixtures/performance/big_file.text +1767 -0
- data/test/mathematical/fixtures_test.rb +45 -0
- data/test/mathematical/maliciousness_test.rb +45 -0
- data/test/mathematical/performance_test.rb +15 -0
- data/test/test_helper.rb +5 -0
- metadata +301 -14
- data/lib/mathematical.bundle +0 -0
- data/lib/mathematical/mathematical.bundle +0 -0
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
/* Lasem
|
|
2
|
+
*
|
|
3
|
+
* Copyright © 2007-2010 Emmanuel Pacaud
|
|
4
|
+
*
|
|
5
|
+
* This library is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
7
|
+
* License as published by the Free Software Foundation; either
|
|
8
|
+
* version 2 of the License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This library is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
+
* Lesser General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Lesser General
|
|
16
|
+
* Public License along with this library; if not, write to the
|
|
17
|
+
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
18
|
+
* Boston, MA 02111-1307, USA.
|
|
19
|
+
*
|
|
20
|
+
* Author:
|
|
21
|
+
* Emmanuel Pacaud <emmanuel@gnome.org>
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* SECTION:lsmdomnode
|
|
26
|
+
* @short_description: Base class for DOM nodes
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
#include <lsmdomnode.h>
|
|
30
|
+
#include <lsmdomnodelist.h>
|
|
31
|
+
#include <lsmdomdocument.h>
|
|
32
|
+
#include <lsmdebug.h>
|
|
33
|
+
#include <glib/gprintf.h>
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
|
|
36
|
+
/* LsmDomNodeChildList */
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
#define LSM_TYPE_DOM_NODE_CHILD_LIST (lsm_dom_node_child_list_get_type ())
|
|
40
|
+
#define LSM_DOM_NODE_CHILD_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_DOM_NODE_CHILD_LIST, LsmDomNodeChildList))
|
|
41
|
+
#define LSM_DOM_NODE_CHILD_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_DOM_NODE_CHILD_LIST, LsmDomNodeChildListClass))
|
|
42
|
+
#define LSM_IS_DOM_NODE_CHILD_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_DOM_NODE_CHILD_LIST))
|
|
43
|
+
#define LSM_IS_DOM_NODE_CHILD_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_DOM_NODE_CHILD_LIST))
|
|
44
|
+
#define LSM_DOM_NODE_CHILD_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_DOM_NODE_CHILD_LIST, LsmDomNodeChildListClass))
|
|
45
|
+
|
|
46
|
+
typedef struct _LsmDomNodeChildListClass LsmDomNodeChildListClass;
|
|
47
|
+
|
|
48
|
+
typedef struct {
|
|
49
|
+
LsmDomNodeList base;
|
|
50
|
+
|
|
51
|
+
LsmDomNode *parent_node;
|
|
52
|
+
} LsmDomNodeChildList;
|
|
53
|
+
|
|
54
|
+
struct _LsmDomNodeChildListClass {
|
|
55
|
+
LsmDomNodeListClass parent_class;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
GType lsm_dom_node_child_list_get_type (void);
|
|
59
|
+
|
|
60
|
+
static GObjectClass *child_list_parent_class = NULL;
|
|
61
|
+
|
|
62
|
+
static void
|
|
63
|
+
lsm_dom_node_child_list_weak_notify_cb (void *user_data, GObject *object)
|
|
64
|
+
{
|
|
65
|
+
LsmDomNodeChildList *list = user_data;
|
|
66
|
+
|
|
67
|
+
list->parent_node = NULL;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static LsmDomNode *
|
|
71
|
+
lsm_dom_node_child_list_get_item (LsmDomNodeList *list, unsigned int index)
|
|
72
|
+
{
|
|
73
|
+
LsmDomNodeChildList *child_list = LSM_DOM_NODE_CHILD_LIST (list);
|
|
74
|
+
LsmDomNode *iter;
|
|
75
|
+
unsigned int i = 0;
|
|
76
|
+
|
|
77
|
+
if (child_list->parent_node == NULL)
|
|
78
|
+
return NULL;
|
|
79
|
+
|
|
80
|
+
for (iter = child_list->parent_node->first_child; iter != NULL; iter = iter->next_sibling) {
|
|
81
|
+
if (i == index)
|
|
82
|
+
return iter;
|
|
83
|
+
i++;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return NULL;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static unsigned int
|
|
90
|
+
lsm_dom_node_child_list_get_length (LsmDomNodeList *list)
|
|
91
|
+
{
|
|
92
|
+
LsmDomNodeChildList *child_list = LSM_DOM_NODE_CHILD_LIST (list);
|
|
93
|
+
LsmDomNode *iter;
|
|
94
|
+
unsigned int length = 0;
|
|
95
|
+
|
|
96
|
+
if (child_list->parent_node == NULL)
|
|
97
|
+
return 0;
|
|
98
|
+
|
|
99
|
+
for (iter = child_list->parent_node->first_child; iter != NULL; iter = iter->next_sibling)
|
|
100
|
+
length++;
|
|
101
|
+
|
|
102
|
+
return length;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static LsmDomNodeList *
|
|
106
|
+
lsm_dom_node_child_list_new (LsmDomNode *parent_node)
|
|
107
|
+
{
|
|
108
|
+
LsmDomNodeChildList *list;
|
|
109
|
+
|
|
110
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (parent_node), NULL);
|
|
111
|
+
|
|
112
|
+
list = g_object_new (LSM_TYPE_DOM_NODE_CHILD_LIST, NULL);
|
|
113
|
+
list->parent_node = parent_node;
|
|
114
|
+
|
|
115
|
+
g_object_weak_ref (G_OBJECT (parent_node), lsm_dom_node_child_list_weak_notify_cb, list);
|
|
116
|
+
|
|
117
|
+
return LSM_DOM_NODE_LIST (list);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static void
|
|
121
|
+
lsm_dom_node_child_list_init (LsmDomNodeChildList *list)
|
|
122
|
+
{
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static void
|
|
126
|
+
lsm_dom_node_child_list_finalize (GObject *object)
|
|
127
|
+
{
|
|
128
|
+
LsmDomNodeChildList *list = LSM_DOM_NODE_CHILD_LIST (object);
|
|
129
|
+
|
|
130
|
+
if (list->parent_node != NULL) {
|
|
131
|
+
g_object_weak_unref (G_OBJECT (list->parent_node), lsm_dom_node_child_list_weak_notify_cb, list);
|
|
132
|
+
list->parent_node = NULL;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
child_list_parent_class->finalize (object);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static void
|
|
139
|
+
lsm_dom_node_child_list_class_init (LsmDomNodeChildListClass *klass)
|
|
140
|
+
{
|
|
141
|
+
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
142
|
+
LsmDomNodeListClass *node_list_class = LSM_DOM_NODE_LIST_CLASS (klass);
|
|
143
|
+
|
|
144
|
+
child_list_parent_class = g_type_class_peek_parent (klass);
|
|
145
|
+
|
|
146
|
+
object_class->finalize = lsm_dom_node_child_list_finalize;
|
|
147
|
+
|
|
148
|
+
node_list_class->get_item = lsm_dom_node_child_list_get_item;
|
|
149
|
+
node_list_class->get_length = lsm_dom_node_child_list_get_length;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
G_DEFINE_TYPE (LsmDomNodeChildList, lsm_dom_node_child_list, LSM_TYPE_DOM_NODE_LIST)
|
|
153
|
+
|
|
154
|
+
static GObjectClass *parent_class = NULL;
|
|
155
|
+
|
|
156
|
+
/* LsmDomNode implementation */
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* lsm_dom_node_get_node_name:
|
|
161
|
+
* @self: a #LsmDomNode
|
|
162
|
+
*
|
|
163
|
+
* Gets the node name.
|
|
164
|
+
*
|
|
165
|
+
* Return value: the node name.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
const char*
|
|
169
|
+
lsm_dom_node_get_node_name (LsmDomNode* self)
|
|
170
|
+
{
|
|
171
|
+
LsmDomNodeClass *node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
172
|
+
|
|
173
|
+
g_return_val_if_fail (node_class != NULL, NULL);
|
|
174
|
+
|
|
175
|
+
if (node_class->get_node_name)
|
|
176
|
+
return node_class->get_node_name (self);
|
|
177
|
+
|
|
178
|
+
return NULL;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* lsm_dom_node_get_node_value:
|
|
183
|
+
* @self: a #LsmDomNode
|
|
184
|
+
*
|
|
185
|
+
* Gets the node value.
|
|
186
|
+
*
|
|
187
|
+
* Return value: the node value.
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
const char*
|
|
191
|
+
lsm_dom_node_get_node_value (LsmDomNode* self)
|
|
192
|
+
{
|
|
193
|
+
LsmDomNodeClass *node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
194
|
+
|
|
195
|
+
g_return_val_if_fail (node_class != NULL, NULL);
|
|
196
|
+
|
|
197
|
+
if (node_class->get_node_value)
|
|
198
|
+
return node_class->get_node_value (self);
|
|
199
|
+
|
|
200
|
+
return NULL;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
void
|
|
204
|
+
lsm_dom_node_set_node_value (LsmDomNode* self, const char* new_value)
|
|
205
|
+
{
|
|
206
|
+
LsmDomNodeClass *node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
207
|
+
|
|
208
|
+
g_return_if_fail (node_class != NULL);
|
|
209
|
+
g_return_if_fail (new_value != NULL);
|
|
210
|
+
|
|
211
|
+
if (node_class->set_node_value)
|
|
212
|
+
node_class->set_node_value (self, new_value);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
LsmDomNodeType lsm_dom_node_get_node_type (LsmDomNode* self)
|
|
216
|
+
{
|
|
217
|
+
LsmDomNodeClass *node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
218
|
+
|
|
219
|
+
g_return_val_if_fail (node_class != NULL, 0);
|
|
220
|
+
|
|
221
|
+
if (node_class->get_node_type)
|
|
222
|
+
return node_class->get_node_type (self);
|
|
223
|
+
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* lsm_dom_node_get_parent_node:
|
|
229
|
+
* @self: a #LsmDomNode
|
|
230
|
+
*
|
|
231
|
+
* Returns: (transfer none): node parent
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
LsmDomNode*
|
|
235
|
+
lsm_dom_node_get_parent_node (LsmDomNode* self)
|
|
236
|
+
{
|
|
237
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
238
|
+
|
|
239
|
+
return self->parent_node;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* lsm_dom_node_get_child_nodes:
|
|
244
|
+
* @self: a #LsmDomNode
|
|
245
|
+
*
|
|
246
|
+
* Returns: (transfer none): node child list
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
LsmDomNodeList*
|
|
250
|
+
lsm_dom_node_get_child_nodes (LsmDomNode* self)
|
|
251
|
+
{
|
|
252
|
+
LsmDomNodeList *list;
|
|
253
|
+
|
|
254
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
255
|
+
|
|
256
|
+
list = g_object_get_data (G_OBJECT (self), "child-nodes");
|
|
257
|
+
|
|
258
|
+
if (list == NULL) {
|
|
259
|
+
list = lsm_dom_node_child_list_new (self);
|
|
260
|
+
g_object_set_data_full (G_OBJECT (self), "child-nodes", list, g_object_unref);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return list;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* lsm_dom_node_get_first_child:
|
|
268
|
+
* @self: a #LsmDomNode
|
|
269
|
+
*
|
|
270
|
+
* Returns: (transfer none): node first child
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
LsmDomNode*
|
|
274
|
+
lsm_dom_node_get_first_child (LsmDomNode* self)
|
|
275
|
+
{
|
|
276
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
277
|
+
|
|
278
|
+
return self->first_child;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* lsm_dom_node_get_last_child:
|
|
283
|
+
* @self: a #LsmDomNode
|
|
284
|
+
*
|
|
285
|
+
* Returns: (transfer none): node last child
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
LsmDomNode*
|
|
289
|
+
lsm_dom_node_get_last_child (LsmDomNode* self)
|
|
290
|
+
{
|
|
291
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
292
|
+
|
|
293
|
+
return self->last_child;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* lsm_dom_node_get_previous_sibling:
|
|
298
|
+
* @self: a #LsmDomNode
|
|
299
|
+
*
|
|
300
|
+
* Returns: (transfer none): node previous sibling
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
LsmDomNode*
|
|
304
|
+
lsm_dom_node_get_previous_sibling (LsmDomNode* self)
|
|
305
|
+
{
|
|
306
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
307
|
+
|
|
308
|
+
return self->previous_sibling;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* lsm_dom_node_get_next_sibling:
|
|
313
|
+
* @self: a #LsmDomNode
|
|
314
|
+
*
|
|
315
|
+
* Returns: (transfer none): node next sibling
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
LsmDomNode*
|
|
319
|
+
lsm_dom_node_get_next_sibling (LsmDomNode* self)
|
|
320
|
+
{
|
|
321
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
322
|
+
|
|
323
|
+
return self->next_sibling;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#if 0
|
|
327
|
+
LsmDomNamedNodeMap*
|
|
328
|
+
lsm_dom_node_get_attributes (LsmDomNode* self)
|
|
329
|
+
{
|
|
330
|
+
return LSM_DOM_NODE_GET_CLASS (self)->get_attributes (self);
|
|
331
|
+
}
|
|
332
|
+
#endif
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* lsm_dom_node_get_owner_document:
|
|
336
|
+
* @self: a #LsmDomNode
|
|
337
|
+
*
|
|
338
|
+
* Returns: (transfer none): node owner document
|
|
339
|
+
*/
|
|
340
|
+
|
|
341
|
+
LsmDomDocument *
|
|
342
|
+
lsm_dom_node_get_owner_document (LsmDomNode* self)
|
|
343
|
+
{
|
|
344
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
345
|
+
|
|
346
|
+
return self->owner_document;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* lsm_dom_node_insert_before:
|
|
351
|
+
* @self: a #LsmDomNode
|
|
352
|
+
* @new_child: (transfer full): node to insert
|
|
353
|
+
* @ref_child: (transfer none): reference node, i.e., the node before which the new node must be inserted.
|
|
354
|
+
*
|
|
355
|
+
* Inserts the node @new_child before the existing child node @ref_child. If
|
|
356
|
+
* @ref_child is null, insert @new_child at the end of the list of children.
|
|
357
|
+
* If the @new_child is already in the tree, it is first removed.
|
|
358
|
+
*
|
|
359
|
+
* Returns: (transfer none): the inserted node.
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
/* TODO:
|
|
363
|
+
* If @new_child is a #LsmDocumentFragment object, all of its children are inserted,
|
|
364
|
+
* in the same order, before @ref_child.
|
|
365
|
+
* Check if new_child is an ancestor of self.
|
|
366
|
+
*/
|
|
367
|
+
|
|
368
|
+
LsmDomNode*
|
|
369
|
+
lsm_dom_node_insert_before (LsmDomNode* self, LsmDomNode* new_child, LsmDomNode* ref_child)
|
|
370
|
+
{
|
|
371
|
+
LsmDomNodeClass *node_class;
|
|
372
|
+
|
|
373
|
+
if (ref_child == NULL)
|
|
374
|
+
return lsm_dom_node_append_child (self, new_child);
|
|
375
|
+
|
|
376
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (new_child), NULL);
|
|
377
|
+
|
|
378
|
+
if (new_child->parent_node != NULL)
|
|
379
|
+
lsm_dom_node_remove_child (self, new_child);
|
|
380
|
+
|
|
381
|
+
if (!LSM_IS_DOM_NODE (self)) {
|
|
382
|
+
g_critical ("%s: self is not a LsmDomNode", G_STRFUNC);
|
|
383
|
+
g_object_unref (new_child);
|
|
384
|
+
return NULL;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (self->owner_document != new_child->owner_document &&
|
|
388
|
+
self->owner_document != NULL) {
|
|
389
|
+
g_object_unref (new_child);
|
|
390
|
+
return NULL;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (!LSM_IS_DOM_NODE (ref_child)) {
|
|
394
|
+
g_critical ("%s: ref_child is not a LsmDomNode", G_STRFUNC);
|
|
395
|
+
g_object_unref (new_child);
|
|
396
|
+
return NULL;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (ref_child->parent_node != self) {
|
|
400
|
+
lsm_debug_dom ("[LsmDomNode::insert_before] Ref child '%s' doesn't belong to '%s'",
|
|
401
|
+
lsm_dom_node_get_node_name (ref_child),
|
|
402
|
+
lsm_dom_node_get_node_name (self));
|
|
403
|
+
g_object_unref (new_child);
|
|
404
|
+
return NULL;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!LSM_DOM_NODE_GET_CLASS (self)->can_append_child (self, new_child)) {
|
|
408
|
+
lsm_debug_dom ("[LsmDomNode::insert_before] Can't append '%s' to '%s'",
|
|
409
|
+
lsm_dom_node_get_node_name (new_child),
|
|
410
|
+
lsm_dom_node_get_node_name (self));
|
|
411
|
+
g_object_unref (new_child);
|
|
412
|
+
return NULL;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
new_child->parent_node = self;
|
|
416
|
+
new_child->next_sibling = ref_child;
|
|
417
|
+
new_child->previous_sibling = ref_child->previous_sibling;
|
|
418
|
+
|
|
419
|
+
if (ref_child->previous_sibling == NULL)
|
|
420
|
+
self->first_child = new_child;
|
|
421
|
+
else
|
|
422
|
+
ref_child->previous_sibling->next_sibling = new_child;
|
|
423
|
+
|
|
424
|
+
ref_child->previous_sibling = new_child;
|
|
425
|
+
|
|
426
|
+
node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
427
|
+
|
|
428
|
+
if (node_class->post_new_child)
|
|
429
|
+
node_class->post_new_child (self, new_child);
|
|
430
|
+
|
|
431
|
+
lsm_dom_node_changed (self);
|
|
432
|
+
|
|
433
|
+
return new_child;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* lsm_dom_node_replace_child:
|
|
438
|
+
* @self: a #LsmDomNode
|
|
439
|
+
* @new_child: (transfer full): a replacement node
|
|
440
|
+
* @old_child: (transfer none): node to replace
|
|
441
|
+
*
|
|
442
|
+
* Replaces the child node @old_child with @new_child in the list of children,
|
|
443
|
+
* and returns the @old_child node.
|
|
444
|
+
* If the @new_child is already in the tree, it is first removed.
|
|
445
|
+
*
|
|
446
|
+
* Returns: (transfer full): the replaced node.
|
|
447
|
+
*/
|
|
448
|
+
|
|
449
|
+
/* TODO:
|
|
450
|
+
* Check if new_child is an ancestor of self.
|
|
451
|
+
*/
|
|
452
|
+
|
|
453
|
+
LsmDomNode*
|
|
454
|
+
lsm_dom_node_replace_child (LsmDomNode* self, LsmDomNode* new_child, LsmDomNode* old_child)
|
|
455
|
+
{
|
|
456
|
+
LsmDomNode *next_sibling;
|
|
457
|
+
LsmDomNode *node;
|
|
458
|
+
|
|
459
|
+
if (new_child == NULL)
|
|
460
|
+
return lsm_dom_node_remove_child (self, old_child);
|
|
461
|
+
|
|
462
|
+
if (!LSM_IS_DOM_NODE (new_child)) {
|
|
463
|
+
g_critical ("%s: new_child is not a LsmDomNode", G_STRFUNC);
|
|
464
|
+
if (LSM_IS_DOM_NODE (old_child))
|
|
465
|
+
g_object_unref (old_child);
|
|
466
|
+
return NULL;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (new_child->parent_node != NULL)
|
|
470
|
+
lsm_dom_node_remove_child (self, new_child);
|
|
471
|
+
|
|
472
|
+
if (old_child == NULL) {
|
|
473
|
+
lsm_debug_dom ("[LsmDomNode::replace_child] old_child == NULL)");
|
|
474
|
+
g_object_unref (new_child);
|
|
475
|
+
return NULL;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (!LSM_IS_DOM_NODE (old_child)) {
|
|
479
|
+
g_critical ("%s: old_child is not a LsmDomNode", G_STRFUNC);
|
|
480
|
+
g_object_unref (new_child);
|
|
481
|
+
return NULL;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!LSM_IS_DOM_NODE (self)) {
|
|
485
|
+
g_critical ("%s: self is not a LsmDomNode", G_STRFUNC);
|
|
486
|
+
g_object_unref (new_child);
|
|
487
|
+
g_object_unref (old_child);
|
|
488
|
+
return NULL;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (self->owner_document != new_child->owner_document &&
|
|
492
|
+
self->owner_document != NULL) {
|
|
493
|
+
g_object_unref (new_child);
|
|
494
|
+
g_object_unref (old_child);
|
|
495
|
+
return NULL;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (old_child->parent_node != self) {
|
|
499
|
+
g_object_unref (new_child);
|
|
500
|
+
g_object_unref (old_child);
|
|
501
|
+
return NULL;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
next_sibling = old_child->next_sibling;
|
|
505
|
+
|
|
506
|
+
node = lsm_dom_node_remove_child (self, old_child);
|
|
507
|
+
if (node != old_child) {
|
|
508
|
+
g_object_unref (new_child);
|
|
509
|
+
g_object_unref (old_child);
|
|
510
|
+
return NULL;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (next_sibling == NULL)
|
|
514
|
+
lsm_dom_node_append_child (self, new_child);
|
|
515
|
+
else
|
|
516
|
+
lsm_dom_node_insert_before (self, new_child, next_sibling);
|
|
517
|
+
|
|
518
|
+
return old_child;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* lsm_dom_node_remove_child:
|
|
523
|
+
* @self: a #LsmDomNode
|
|
524
|
+
* @old_child: (transfer none): node to remove.
|
|
525
|
+
*
|
|
526
|
+
* Removes the child node indicated by @old_child from the list of children, and returns it.
|
|
527
|
+
*
|
|
528
|
+
* Returns: (transfer full): the removed node.
|
|
529
|
+
*/
|
|
530
|
+
|
|
531
|
+
LsmDomNode*
|
|
532
|
+
lsm_dom_node_remove_child (LsmDomNode* self, LsmDomNode* old_child)
|
|
533
|
+
{
|
|
534
|
+
LsmDomNode *node;
|
|
535
|
+
LsmDomNodeClass *node_class;
|
|
536
|
+
|
|
537
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), NULL);
|
|
538
|
+
|
|
539
|
+
if (old_child == NULL)
|
|
540
|
+
return NULL;
|
|
541
|
+
|
|
542
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (old_child), NULL);
|
|
543
|
+
|
|
544
|
+
for (node = self->first_child;
|
|
545
|
+
node != NULL && node != old_child;
|
|
546
|
+
node = node->next_sibling);
|
|
547
|
+
|
|
548
|
+
if (node == NULL)
|
|
549
|
+
return NULL;
|
|
550
|
+
|
|
551
|
+
node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
552
|
+
|
|
553
|
+
if (node_class->pre_remove_child)
|
|
554
|
+
node_class->pre_remove_child (self, old_child);
|
|
555
|
+
|
|
556
|
+
if (self->first_child == old_child)
|
|
557
|
+
self->first_child = old_child->next_sibling;
|
|
558
|
+
if (self->last_child == old_child)
|
|
559
|
+
self->last_child = old_child->previous_sibling;
|
|
560
|
+
|
|
561
|
+
if (old_child->next_sibling != NULL)
|
|
562
|
+
old_child->next_sibling->previous_sibling = old_child->previous_sibling;
|
|
563
|
+
if (old_child->previous_sibling != NULL)
|
|
564
|
+
old_child->previous_sibling->next_sibling = old_child->next_sibling;
|
|
565
|
+
|
|
566
|
+
old_child->parent_node = NULL;
|
|
567
|
+
old_child->next_sibling = NULL;
|
|
568
|
+
old_child->previous_sibling = NULL;
|
|
569
|
+
|
|
570
|
+
lsm_dom_node_changed (self);
|
|
571
|
+
|
|
572
|
+
return old_child;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* lsm_dom_node_append_child:
|
|
577
|
+
* @self: a #LsmDomNode
|
|
578
|
+
* @new_child: (transfer full): node to append
|
|
579
|
+
*
|
|
580
|
+
* Adds the node @new_child to the end of the list of children of this node.
|
|
581
|
+
* If the @new_child is already in the tree, it is first removed.
|
|
582
|
+
*
|
|
583
|
+
* Returns: (transfer none): the added node.
|
|
584
|
+
*/
|
|
585
|
+
|
|
586
|
+
LsmDomNode *
|
|
587
|
+
lsm_dom_node_append_child (LsmDomNode* self, LsmDomNode* new_child)
|
|
588
|
+
{
|
|
589
|
+
LsmDomNodeClass *node_class;
|
|
590
|
+
|
|
591
|
+
if (new_child == NULL)
|
|
592
|
+
return NULL;
|
|
593
|
+
|
|
594
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (new_child), NULL);
|
|
595
|
+
|
|
596
|
+
if (!LSM_IS_DOM_NODE (self)) {
|
|
597
|
+
g_critical ("%s: self is not a LsmDomNode", G_STRFUNC);
|
|
598
|
+
g_object_unref (new_child);
|
|
599
|
+
return NULL;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (self->owner_document != new_child->owner_document &&
|
|
603
|
+
self->owner_document != NULL) {
|
|
604
|
+
g_object_unref (new_child);
|
|
605
|
+
return NULL;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (new_child->parent_node != NULL)
|
|
609
|
+
lsm_dom_node_remove_child (self, new_child);
|
|
610
|
+
|
|
611
|
+
if (!LSM_DOM_NODE_GET_CLASS (self)->can_append_child (self, new_child)) {
|
|
612
|
+
lsm_debug_dom ("[LsmDomNode::append_child] Can't append '%s' to '%s'",
|
|
613
|
+
lsm_dom_node_get_node_name (new_child),
|
|
614
|
+
lsm_dom_node_get_node_name (self));
|
|
615
|
+
g_object_unref (new_child);
|
|
616
|
+
return NULL;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (self->first_child == NULL)
|
|
620
|
+
self->first_child = new_child;
|
|
621
|
+
if (self->last_child != NULL)
|
|
622
|
+
self->last_child->next_sibling = new_child;
|
|
623
|
+
|
|
624
|
+
new_child->parent_node = self;
|
|
625
|
+
new_child->next_sibling = NULL;
|
|
626
|
+
new_child->previous_sibling = self->last_child;
|
|
627
|
+
self->last_child = new_child;
|
|
628
|
+
|
|
629
|
+
node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
630
|
+
|
|
631
|
+
if (node_class->post_new_child)
|
|
632
|
+
node_class->post_new_child (self, new_child);
|
|
633
|
+
|
|
634
|
+
lsm_dom_node_changed (self);
|
|
635
|
+
|
|
636
|
+
return new_child;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
static gboolean
|
|
640
|
+
lsm_dom_node_can_append_child_default (LsmDomNode *self, LsmDomNode* new_child)
|
|
641
|
+
{
|
|
642
|
+
return FALSE;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
void
|
|
646
|
+
lsm_dom_node_changed (LsmDomNode *self)
|
|
647
|
+
{
|
|
648
|
+
LsmDomNode *parent_node;
|
|
649
|
+
LsmDomNode *child_node;
|
|
650
|
+
LsmDomNodeClass *node_class;
|
|
651
|
+
|
|
652
|
+
g_return_if_fail (LSM_IS_DOM_NODE (self));
|
|
653
|
+
|
|
654
|
+
node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
655
|
+
|
|
656
|
+
if (node_class->changed)
|
|
657
|
+
node_class->changed (self);
|
|
658
|
+
|
|
659
|
+
child_node = self;
|
|
660
|
+
for (parent_node = self->parent_node;
|
|
661
|
+
parent_node != NULL;
|
|
662
|
+
parent_node = parent_node->parent_node) {
|
|
663
|
+
node_class = LSM_DOM_NODE_GET_CLASS (parent_node);
|
|
664
|
+
if (node_class->child_changed == NULL ||
|
|
665
|
+
!node_class->child_changed (parent_node, child_node))
|
|
666
|
+
break;
|
|
667
|
+
child_node = parent_node;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
gboolean
|
|
672
|
+
lsm_dom_node_has_child_nodes (LsmDomNode* self)
|
|
673
|
+
{
|
|
674
|
+
g_return_val_if_fail (LSM_IS_DOM_NODE (self), FALSE);
|
|
675
|
+
|
|
676
|
+
return self->first_child != NULL;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
static void
|
|
680
|
+
lsm_dom_node_write_to_stream_default (LsmDomNode *self, GOutputStream *stream, GError **error)
|
|
681
|
+
{
|
|
682
|
+
LsmDomNode *child;
|
|
683
|
+
|
|
684
|
+
for (child = self->first_child; child != NULL; child = child->next_sibling)
|
|
685
|
+
lsm_dom_node_write_to_stream (child, stream, error);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
void
|
|
689
|
+
lsm_dom_node_write_to_stream (LsmDomNode *self, GOutputStream *stream, GError **error)
|
|
690
|
+
{
|
|
691
|
+
LsmDomNodeClass *node_class;
|
|
692
|
+
|
|
693
|
+
g_return_if_fail (LSM_IS_DOM_NODE (self));
|
|
694
|
+
g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
|
|
695
|
+
|
|
696
|
+
node_class = LSM_DOM_NODE_GET_CLASS (self);
|
|
697
|
+
if (node_class->write_to_stream != NULL)
|
|
698
|
+
node_class->write_to_stream (self, stream, error);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
static void
|
|
702
|
+
lsm_dom_node_init (LsmDomNode *node)
|
|
703
|
+
{
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
static void
|
|
707
|
+
lsm_dom_node_finalize (GObject *object)
|
|
708
|
+
{
|
|
709
|
+
LsmDomNode *node = LSM_DOM_NODE (object);
|
|
710
|
+
LsmDomNode *child, *next_child;
|
|
711
|
+
|
|
712
|
+
child = node->first_child;
|
|
713
|
+
while (child != NULL) {
|
|
714
|
+
next_child = child->next_sibling;
|
|
715
|
+
g_object_unref (child);
|
|
716
|
+
child = next_child;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
parent_class->finalize (object);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/* LsmDomNode class */
|
|
723
|
+
|
|
724
|
+
static void
|
|
725
|
+
lsm_dom_node_class_init (LsmDomNodeClass *node_class)
|
|
726
|
+
{
|
|
727
|
+
GObjectClass *object_class = G_OBJECT_CLASS (node_class);
|
|
728
|
+
|
|
729
|
+
parent_class = g_type_class_peek_parent (node_class);
|
|
730
|
+
|
|
731
|
+
object_class->finalize = lsm_dom_node_finalize;
|
|
732
|
+
|
|
733
|
+
node_class->can_append_child = lsm_dom_node_can_append_child_default;
|
|
734
|
+
node_class->write_to_stream = lsm_dom_node_write_to_stream_default;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
G_DEFINE_ABSTRACT_TYPE (LsmDomNode, lsm_dom_node, G_TYPE_OBJECT)
|