/*! Parse stream contents into the document \param stream Stream to import from This code is used for both files and the clipboard */ UT_Error IE_Imp_Object::_parseStream(ImportStream * pStream) { UT_return_val_if_fail(pStream, UT_ERROR); XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView()); UT_UCSChar c; unsigned char uc; while (pStream->getChar(c)) { uc = static_cast<unsigned char>(c); m_pByteBuf->append(&uc,1); } const char* mimetypeGOChart = "application/x-goffice-graph"; const char * szProps="embed-type: GOChart"; PT_DocPosition pos = pView->getPoint(); pView->cmdInsertEmbed(m_pByteBuf,pView->getPoint(),mimetypeGOChart,szProps); pView->cmdSelect(pos,pos+1); return UT_OK; }
static void changed_cb (GOComponent *component, gpointer data) { if (data != NULL) { GOComponentView * pGOComponentView = static_cast<GOComponentView*> (data); pGOComponentView->update (); } else { XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView()); UT_Byte *buf; int length; void (*clearfunc) (gpointer); gpointer user_data = NULL; if (go_component_get_data (component, (void**) &buf, &length, &clearfunc, &user_data)) { if (buf && length) { UT_ByteBufPtr myByteBuf(new UT_ByteBuf); myByteBuf->append(buf, length); UT_String Props="embed-type: GOComponent"; guint i, nbprops; GType prop_type; GValue value = G_VALUE_INIT; char *prop = NULL; GParamSpec **specs = g_object_class_list_properties ( G_OBJECT_GET_CLASS (component), &nbprops); for (i = 0; i < nbprops; i++) { if (specs[i]->flags & GO_PARAM_PERSISTENT) { prop_type = G_PARAM_SPEC_VALUE_TYPE (specs[i]); memset(&value, 0, sizeof(value)); g_value_init (&value, prop_type); g_object_get_property (G_OBJECT (component), specs[i]->name, &value); if (!g_param_value_defaults (specs[i], &value)) switch (G_TYPE_FUNDAMENTAL (prop_type)) { case G_TYPE_CHAR: case G_TYPE_UCHAR: case G_TYPE_BOOLEAN: case G_TYPE_INT: case G_TYPE_UINT: case G_TYPE_LONG: case G_TYPE_ULONG: case G_TYPE_FLOAT: case G_TYPE_DOUBLE: { GValue str; memset(&str, 0, sizeof(str)); g_value_init (&str, G_TYPE_STRING); g_value_transform (&value, &str); prop = g_strdup (g_value_get_string (&str)); g_value_unset (&str); break; } case G_TYPE_STRING: { prop = g_strdup (g_value_get_string (&value)); break; } default: prop = NULL; break; } g_value_unset (&value); if (prop) { Props += UT_String_sprintf("; %s:%s", specs[i]->name, prop); g_free (prop); prop = NULL; } } } PT_DocPosition pos = pView->getPoint(); pView->cmdInsertEmbed(myByteBuf, pView->getPoint(), component->mime_type, Props.c_str ()); pView->cmdSelect(pos,pos+1); } if (clearfunc) clearfunc ((user_data)? user_data: buf); } g_object_unref (component); // destroy since we created a new one this will close the editor } }