1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/* Fo
* fo-marker-parent.c: Formatting object that is parent of possible fo:marker
*
* Copyright (C) 2003 Sun Microsystems
* Copyright (C) 2007 Menteith Consulting Ltd
*
* See COPYING for the status of this software.
*/
#include "fo-marker-parent-private.h"
#include "fo-marker.h"
enum {
PROP_0
};
static void fo_marker_parent_class_init (FoMarkerParentClass *klass);
static void fo_marker_parent_finalize (GObject *object);
static gboolean fo_marker_parent_validate_content (FoFo *fo,
GError **error);
static void fo_marker_parent_debug_dump_properties (FoFo *fo, gint depth);
static gpointer parent_class;
GType
fo_marker_parent_get_type (void)
{
static GType object_type = 0;
if (!object_type)
{
static const GTypeInfo object_info =
{
sizeof (FoMarkerParentClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) fo_marker_parent_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (FoMarkerParent),
0, /* n_preallocs */
NULL, /* instance_init */
NULL /* value_table */
};
object_type = g_type_register_static (FO_TYPE_FO,
"FoMarkerParent",
&object_info,
G_TYPE_FLAG_ABSTRACT);
}
return object_type;
}
/**
* fo_marker_parent_class_init:
* @klass: #FoMarkerParentClass object to initialise.
*
* Implements #GClassInitFunc for #FoMarkerParent.
**/
void
fo_marker_parent_class_init (FoMarkerParentClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
FoFoClass *fo_fo_class = FO_FO_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = fo_marker_parent_finalize;
fo_fo_class->debug_dump_properties = fo_marker_parent_debug_dump_properties;
fo_fo_class->update_from_context = fo_marker_parent_update_from_context;
fo_fo_class->validate_content = fo_marker_parent_validate_content;
}
static void
fo_marker_parent_finalize (GObject *object)
{
FoMarkerParent *fo_marker_parent;
fo_marker_parent = FO_MARKER_PARENT (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* fo_marker_parent_new:
*
* Creates a new #FoMarkerParent initialized to default value.
*
* Return value: the new #FoMarkerParent.
**/
FoFo*
fo_marker_parent_new (void)
{
return FO_FO (g_object_new (fo_marker_parent_get_type (),
NULL));
}
void
fo_marker_parent_update_from_context (FoFo *fo, FoContext *context)
{
g_return_if_fail (fo != NULL);
g_return_if_fail (FO_IS_MARKER_PARENT (fo));
FO_FO_CLASS (parent_class)->update_from_context (fo, context);
}
/**
* fo_marker_parent_debug_dump_marker:
* @value:
* @data:
*
*
**/
static void
fo_marker_parent_debug_dump_marker (gpointer value,
gpointer data)
{
gchar *indent = g_strnfill (GPOINTER_TO_INT (data) * 2, ' ');
gchar *marker_sprintf;
marker_sprintf = fo_object_debug_sprintf (value);
g_log (G_LOG_DOMAIN,
G_LOG_LEVEL_DEBUG,
"%s%p",
indent, value);
g_free (marker_sprintf);
g_free (indent);
}
void
fo_marker_parent_debug_dump_properties (FoFo *fo, gint depth)
{
gchar *indent = g_strnfill (depth * 2, ' ');
g_return_if_fail (fo != NULL);
g_return_if_fail (FO_IS_MARKER_PARENT (fo));
g_log (G_LOG_DOMAIN,
G_LOG_LEVEL_DEBUG,
"%smarkers:",
indent);
if (FO_MARKER_PARENT (fo)->marker_list)
{
g_list_foreach (FO_MARKER_PARENT (fo)->marker_list,
fo_marker_parent_debug_dump_marker,
GINT_TO_POINTER (depth + 1));
}
else
{
g_log (G_LOG_DOMAIN,
G_LOG_LEVEL_DEBUG,
_("%s (none)"),
indent);
}
g_free (indent);
FO_FO_CLASS (parent_class)->debug_dump_properties (fo, depth + 1);
}
/**
* fo_marker_parent_validate_content:
* @fo: #FoBlock object to validate.
* @error: #GError indicating error condition, if any.
*
* Validate the content model, i.e., the structure, of the object.
* Return value matches #GNodeTraverseFunc model: FALSE indicates
* content model is correct, or TRUE indicates an error. When used
* with fo_node_traverse(), returning TRUE stops the traversal.
*
* Return value: FALSE if content model okay, TRUE if not.
**/
gboolean
fo_marker_parent_validate_content (FoFo *fo,
GError **error)
{
g_return_val_if_fail (FO_IS_MARKER_PARENT (fo), TRUE);
g_return_val_if_fail (error == NULL || *error == NULL, TRUE);
gboolean parent_result =
FO_FO_CLASS (parent_class)->validate_content (fo, error);
if (parent_result == TRUE)
{
return parent_result;
}
if (fo_node_n_children (FO_NODE (fo)) != 0)
{
FoNode *child_node = fo_node_first_child (FO_NODE (fo));
while (child_node)
{
FoNode *next_node = fo_node_next_sibling (child_node);
if (FO_IS_MARKER (child_node))
{
fo_node_unlink (child_node);
FO_MARKER_PARENT (fo)->marker_list =
g_list_append (FO_MARKER_PARENT (fo)->marker_list,
child_node);
}
child_node = next_node;
}
}
return FALSE;
}
|