Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

SPDocument * Inkscape::UI::ClipboardManagerImpl::_retrieveClipboard ( Glib::ustring  required_target = "" ) [private]

Retrieve the clipboard contents as a document.

Returns:
Clipboard contents converted to SPDocument, or NULL if no suitable content was present

Definition at line 1000 of file clipboard.cpp.

References _clipboard, _getBestTarget(), and Inkscape::Extension::db.

Referenced by getFirstObjectID(), getPathParameter(), getShapeOrTextObjectId(), paste(), pastePathEffect(), pasteSize(), and pasteStyle().

{
    Glib::ustring best_target;
    if ( required_target == "" )
        best_target = _getBestTarget();
    else
        best_target = required_target;

    if ( best_target == "" ) {
        return NULL;
    }

    // FIXME: Temporary hack until we add memory input.
    // Save the clipboard contents to some file, then read it
    gchar *filename = g_build_filename( g_get_tmp_dir(), "inkscape-clipboard-import", NULL );

    bool file_saved = false;
    Glib::ustring target = best_target;

#ifdef WIN32
    if (best_target == CLIPBOARD_WIN32_EMF_TARGET)
    {   // Try to save clipboard data as en emf file (using win32 api)
        if (OpenClipboard(NULL)) {
            HGLOBAL hglb = GetClipboardData(CF_ENHMETAFILE);
            if (hglb) {
                HENHMETAFILE hemf = CopyEnhMetaFile((HENHMETAFILE) hglb, filename);
                if (hemf) {
                    file_saved = true;
                    target = CLIPBOARD_WIN32_EMF_MIME;
                    DeleteEnhMetaFile(hemf);
                }
            }
            CloseClipboard();
        }
    }
#endif

    if (!file_saved) {
        if ( !_clipboard->wait_is_target_available(best_target) ) {
            return NULL;
        }

        // doing this synchronously makes better sense
        // TODO: use another method because this one is badly broken imo.
        // from documentation: "Returns: A SelectionData object, which will be invalid if retrieving the given target failed."
        // I don't know how to check whether an object is 'valid' or not, unusable if that's not possible...
        Gtk::SelectionData sel = _clipboard->wait_for_contents(best_target);
        target = sel.get_target();  // this can crash if the result was invalid of last function. No way to check for this :(

        // FIXME: Temporary hack until we add memory input.
        // Save the clipboard contents to some file, then read it
        g_file_set_contents(filename, (const gchar *) sel.get_data(), sel.get_length(), NULL);
    }

    // there is no specific plain SVG input extension, so if we can paste the Inkscape SVG format,
    // we use the image/svg+xml mimetype to look up the input extension
    if(target == "image/x-inkscape-svg")
        target = "image/svg+xml";

    Inkscape::Extension::DB::InputList inlist;
    Inkscape::Extension::db.get_input_list(inlist);
    Inkscape::Extension::DB::InputList::const_iterator in = inlist.begin();
    for (; in != inlist.end() && target != (*in)->get_mimetype() ; ++in){};
    if ( in == inlist.end() )
        return NULL; // this shouldn't happen unless _getBestTarget returns something bogus

    SPDocument *tempdoc = NULL;
    try {
        tempdoc = (*in)->open(filename);
    } catch (...) {
    }
    g_unlink(filename);
    g_free(filename);

    return tempdoc;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index