void gog_object_set_arg (char const *name, char const *val, GogObject *obj) { GParamSpec *pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), name); GType prop_type; GValue res = { 0 }; gboolean success = TRUE; if (pspec == NULL) { g_warning ("unknown property `%s' for class `%s'", name, G_OBJECT_TYPE_NAME (obj)); return; } prop_type = G_PARAM_SPEC_VALUE_TYPE (pspec); if (val == NULL && G_TYPE_FUNDAMENTAL (prop_type) != G_TYPE_BOOLEAN) { g_warning ("could not convert NULL to type `%s' for property `%s'", g_type_name (prop_type), pspec->name); return; } if (!gsf_xml_gvalue_from_str (&res, prop_type, val)) success = FALSE; if (!success) { g_warning ("could not convert string to type `%s' for property `%s'", g_type_name (prop_type), pspec->name); } else g_object_set_property (G_OBJECT (obj), name, &res); g_value_unset (&res); }
void GOComponentView::loadBuffer(const UT_ConstByteBufPtr & sGOComponentData, const char *_mime_type) { if (!component) { mime_type = _mime_type; component = go_component_new_by_mime_type (_mime_type); } UT_return_if_fail (component); go_component_set_inline (component, true); go_component_set_use_font_from_app (component, true); g_signal_connect (G_OBJECT (component), "changed", G_CALLBACK (changed_cb), this); if (component == NULL) { // we should do something intelligent in that case return; } go_component_set_default_size (component, 2.5, 2.5, 0.); if (sGOComponentData->getLength () > 0) { if (m_pRun) { PP_AttrProp const *Props = m_pRun->getSpanAP (); GParamSpec *prop_spec; int i = 0; GValue res = G_VALUE_INIT; gchar const *szName, *szValue; while (Props->getNthProperty (i++, szName, szValue)) { prop_spec = g_object_class_find_property ( G_OBJECT_GET_CLASS (component), szName); if (prop_spec && (prop_spec->flags & GO_PARAM_PERSISTENT) && gsf_xml_gvalue_from_str (&res, G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (prop_spec)), szValue)) { g_object_set_property (G_OBJECT (component), szName, &res); g_value_unset (&res); } } } go_component_set_data (component, (char const*) sGOComponentData->getPointer (0), (int) sGOComponentData->getLength ()); } else go_component_edit (component); width = 0; // force pixbuf update // update ascent and descent now, otherwise it will not be updated when loading double _ascent, _descent; g_object_get (G_OBJECT (component), "ascent", &_ascent, "descent", &_descent, NULL); ascent = (UT_sint32) rint (_ascent * UT_LAYOUT_RESOLUTION); descent = (UT_sint32) rint (_descent * UT_LAYOUT_RESOLUTION); }
static void gogo_prop_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *unknown) { GogXMLReadState *state = (GogXMLReadState *)xin->user_state; char const *content = xin->content->str; GType prop_type, prop_ftype; GValue val = { 0 }; if (state->obj == NULL || state->prop_spec == NULL) return; prop_type = G_PARAM_SPEC_VALUE_TYPE (state->prop_spec); prop_ftype = G_TYPE_FUNDAMENTAL (prop_type); if (prop_ftype == G_TYPE_OBJECT) { GogObject *obj = state->obj; if (!state->prop_pushed_obj) return; state->obj = state->obj_stack->data; state->obj_stack = g_slist_remove (state->obj_stack, state->obj); state->prop_pushed_obj = FALSE; g_value_init (&val, prop_type); g_value_set_object (&val, G_OBJECT (obj)); g_object_unref (obj); } else { if (content == NULL && prop_ftype != G_TYPE_BOOLEAN) { g_warning ("could not convert NULL to type `%s' for property `%s'", g_type_name (prop_type), state->prop_spec->name); return; } if (!gsf_xml_gvalue_from_str (&val, prop_type, content)) { g_warning ("could not convert string to type `%s' for property `%s'", g_type_name (prop_type), state->prop_spec->name); return; } } g_object_set_property (G_OBJECT (state->obj), state->prop_spec->name, &val); g_value_unset (&val); }