Logo Search packages:      
Sourcecode: inkscape version File versions

static void sp_export_area_toggled ( GtkToggleButton *  tb,
GtkObject *  base 
) [static]

Called when one of the selection buttons was toggled.

Todo:
This returns wrong values if the document has a viewBox.

Definition at line 809 of file export.cpp.

References Inkscape::XML::Node::attribute(), Inkscape::Selection::reprList(), SELECTION_CUSTOM, SELECTION_DRAWING, selection_names, SELECTION_PAGE, SELECTION_SELECTION, sp_export_set_area(), and sp_export_value_set().

Referenced by sp_export_selection_changed().

{
    if (gtk_object_get_data (base, "update"))
        return;

    selection_type key, old_key;
    key = (selection_type)(GPOINTER_TO_INT(gtk_object_get_data (GTK_OBJECT (tb), "key")));
    old_key = (selection_type)(GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(base), "selection-type")));

    /* Ignore all "turned off" events unless we're the only active button */
    if (!gtk_toggle_button_get_active (tb) ) {

        /* Don't let the current selection be deactived - but rerun the
           activate to allow the user to renew the values */
        if (key == old_key) {
            gtk_toggle_button_set_active ( tb, TRUE );
        }

        return;
    }

    /* Turn off the currently active button unless it's us */
    gtk_object_set_data(GTK_OBJECT(base), "selection-type", (gpointer)key);

    if (old_key != key) {
        gtk_toggle_button_set_active
            ( GTK_TOGGLE_BUTTON ( gtk_object_get_data (base, selection_names[old_key])),
              FALSE );
    }

    if ( SP_ACTIVE_DESKTOP )
    {
        SPDocument *doc;
        NR::Maybe<NR::Rect> bbox;
        doc = sp_desktop_document (SP_ACTIVE_DESKTOP);

        /* Notice how the switch is used to 'fall through' here to get
           various backups.  If you modify this without noticing you'll
           probabaly screw something up. */
        switch (key) {
            case SELECTION_SELECTION:
                if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false)
                {
                    bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds();
                    /* Only if there is a selection that we can set
                       do we break, otherwise we fall through to the
                       drawing */
                    // std::cout << "Using selection: SELECTION" << std::endl;
                    key = SELECTION_SELECTION;
                    break;
                }
            case SELECTION_DRAWING:
                /** \todo
                 * This returns wrong values if the document has a viewBox.
                 */
                bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));
                /* If the drawing is valid, then we'll use it and break
                   otherwise we drop through to the page settings */
                if (bbox) {
                    // std::cout << "Using selection: DRAWING" << std::endl;
                    key = SELECTION_DRAWING;
                    break;
                }
            case SELECTION_PAGE:
                bbox = NR::Rect(NR::Point(0.0, 0.0),
                                NR::Point(sp_document_width(doc), sp_document_height(doc))
                                );

                // std::cout << "Using selection: PAGE" << std::endl;
                key = SELECTION_PAGE;
                break;
            case SELECTION_CUSTOM:
            default:
                break;
        } // switch

        // remember area setting
        prefs_set_string_attribute ( "dialogs.export.exportarea",
                                     "value", selection_names[key]);

        if ( key != SELECTION_CUSTOM && bbox ) {
            sp_export_set_area (base, bbox->min()[NR::X],
                                      bbox->min()[NR::Y],
                                      bbox->max()[NR::X],
                                      bbox->max()[NR::Y]);
        }

    } // end of if ( SP_ACTIVE_DESKTOP )


    if (SP_ACTIVE_DESKTOP && !gtk_object_get_data(GTK_OBJECT(base), "filename-modified")) {
        GtkWidget * file_entry;
        const gchar * filename = NULL;
        float xdpi = 0.0, ydpi = 0.0;

        file_entry = (GtkWidget *)gtk_object_get_data (base, "filename");

        switch (key) {
            case SELECTION_PAGE:
            case SELECTION_DRAWING: {
                SPDocument * doc = SP_ACTIVE_DOCUMENT;
                sp_document_get_export_hints (doc, &filename, &xdpi, &ydpi);

                if (filename == NULL) {
                    if (doc_export_name != NULL) {
                        filename = g_strdup(doc_export_name);
                    } else {
                        filename = g_strdup("");
                    }
                }
                break;
            }
            case SELECTION_SELECTION:
                if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {

                    sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), &filename, &xdpi, &ydpi);

                    /* If we still don't have a filename -- let's build
                       one that's nice */
                    if (filename == NULL) {
                        const gchar * id = NULL;
                        const GSList * reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
                        for(; reprlst != NULL; reprlst = reprlst->next) {
                            Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data;
                            if (repr->attribute("id")) {
                                id = repr->attribute("id");
                                break;
                            }
                        }

                        filename = create_filepath_from_id (id, gtk_entry_get_text(GTK_ENTRY(file_entry)));
                    }
                }
                break;
            case SELECTION_CUSTOM:
            default:
                break;
        }

        if (filename != NULL) {
            g_free(original_name);
            original_name = g_strdup(filename);
            gtk_entry_set_text(GTK_ENTRY(file_entry), filename);
        }

        if (xdpi != 0.0) {
            sp_export_value_set(base, "xdpi", xdpi);
        }

        /* These can't be separate, and setting x sets y, so for
           now setting this is disabled.  Hopefully it won't be in
           the future */
        if (FALSE && ydpi != 0.0) {
            sp_export_value_set(base, "ydpi", ydpi);
        }
    }

    return;
} // end of sp_export_area_toggled()


Generated by  Doxygen 1.6.0   Back to index