document-interface.cpp revision 0edb5724a18d57406606f3a54d9fcfa494506c27
1949N/A * This is where the implementation of the DBus based document API lives. 855N/A * All the methods in here (except in the helper section) are 855N/A * has the methods used to connect to the bus and get a document instance. 855N/A * which is the "gold standard" as to how the interface should work. 855N/A * Soren Berg <Glimmer07@gmail.com> 855N/A * Copyright (C) 2009 Soren Berg 855N/A * Released under GNU GPL, read the file 'COPYING' for more information 1816N/A/**************************************************************************** 855N/A HELPER / SHORTCUT FUNCTIONS 855N/A****************************************************************************/ 855N/A * This function or the one below it translates the user input for an object 855N/A * into Inkscapes internal representation. It is called by almost every 855N/A * method so it should be as fast as possible. 855N/A * (eg turns "rect2234" to an SPObject or Inkscape::XML::Node) 855N/A * If the internal representation changes (No more 'id' attributes) this is the * place to adjust things. /* ALTERNATIVE (is this faster if only repr is needed?) Inkscape::XML::Node *node = sp_repr_lookup_name((doc->root)->repr, name); * See comment for get_repr_by_name, above. * Tests for NULL strings and throws an appropriate error. * Every method that takes a string parameter (other than the * name of an object, that's tested seperatly) should call this. * This is used to return object values to the user * Some verbs (cut, paste) only work on the active layer. * This makes sure that the document that is about to recive a command is active. * This function is used along with selection_restore to * take advantage of functionality provided by a selection * It saves the current selection and sets the selection to * the object specified. Any selection verb can be used on the * object and then selection_restore is called, restoring the * This should be mostly transparent to the user who need never * know we never bothered to implement it seperatly. Although * they might see the selection box flicker if used in a loop. * See selection_swap, above * Shortcut for creating a Node. * Called by the shape creation functions. Gets the default style for the doc * or sets it arbitrarily if none. * There is probably a better way to do this (use the shape tools default styles) newNode->
setAttribute(
"style",
"fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none",
TRUE);
//document_interface_pause_updates(object, error); * This is the code used internally to call all the verbs. * It handles error reporting and update pausing (which needs some work.) * This is a good place to improve efficiency as it is called a lot. * document_interface_call_verb is similar but is called by the user. //document_interface_pause_updates (object, error); //document_interface_pause_updates (object, error); /**************************************************************************** DOCUMENT INTERFACE CLASS STUFF ****************************************************************************/ * To add a new error type, edit here and in the .h InkscapeError enum. /**************************************************************************** ****************************************************************************/ /**************************************************************************** ****************************************************************************/ // Not sure why this works. out <<
"m " << x <<
"," << y <<
" " <<
x2 - x <<
"," <<
y2 - y;
//FIXME: Not selectable (aka broken). Needs to be rewritten completely. //document_interface_pause_updates(object, error); /**************************************************************************** ****************************************************************************/ /**************************************************************************** ****************************************************************************/ /* ALTERNATIVE (is this faster?) Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); //FIXME: This should merge transformations. // Doesn't like non-variable strings for some reason. if (r<0 || r>
255 || g<0 || g>
255 || b<0 || b>
255)
//FIXME: Needs lot's of work. Inkscape::XML::Node *shapenode = get_repr_by_name (object->desk, shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { char * path = strdup(shapenode->attribute("d")); printf("PATH: %s\n", path); Geom::parse_svg_path (path); /**************************************************************************** ****************************************************************************/ //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); //SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, "Document saved."); document_interface_print_to_file (DocumentInterface *object, GError **error) SPDocument * doc = sp_desktop_document(object->desk); /**************************************************************************** PROGRAM CONTROL FUNCTIONS ****************************************************************************/ /**************************************************************************** FIXME: This would work better by adding a flag to SPDesktop to prevent updating but that would be very intrusive so for now there is a workaround. Need to make sure it plays well with verbs because they are used so much. ****************************************************************************/ //object->desk->canvas->need_redraw = 0; //object->desk->canvas->need_repick = 0; //sp_desktop_document(object->desk)->root->uflags = FALSE; //sp_desktop_document(object->desk)->root->mflags = FALSE; //object->desk->canvas->need_redraw = 1; //object->desk->canvas->need_repick = 1; //sp_desktop_document(object->desk)->root->uflags = TRUE; //sp_desktop_document(object->desk)->root->mflags = TRUE; //sp_desktop_document(object->desk)->_updateDocument(); //FIXME: use better verb than rect. //sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); /**************************************************************************** SELECTION FUNCTIONS FIXME: use call_verb where appropriate (once update system is tested.) ****************************************************************************/ //sp_selection_delete (object->desk); //sp_edit_select_all (object->desk); //sp_edit_select_all_in_all_layers (object->desk); //sp_edit_invert (object->desk); //sp_selection_group (object->desk); //sp_selection_ungroup (object->desk); //desktop_ensure_active (object->desk); //sp_selection_cut (object->desk); //desktop_ensure_active (object->desk); document_interface_selection_paste (DocumentInterface *object, GError **error) desktop_ensure_active (object->desk); document_interface_pause_updates (object, error); sp_selection_paste (object->desk, TRUE); document_interface_pause_updates (object, error); //return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); //FIXME: does not paste in new layer. // This needs to use lower level cut_impl and paste_impl (messy) // See the built-in sp_selection_to_next_layer and duplicate. // check if something is selected /**************************************************************************** ****************************************************************************/