Ejemplo n.º 1
0
void
LivePathEffectEditor::setDesktop(SPDesktop *desktop)
{
    Panel::setDesktop(desktop);

    if ( desktop == current_desktop ) {
        return;
    }

    if (current_desktop) {
        selection_changed_connection.disconnect();
        selection_modified_connection.disconnect();
    }

    lpe_list_locked = false;
    current_desktop = desktop;
    if (desktop) {
        Inkscape::Selection *selection = sp_desktop_selection(desktop);
        selection_changed_connection = selection->connectChanged(
            sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) );
        selection_modified_connection = selection->connectModified(
            sigc::bind (sigc::ptr_fun(&lpeeditor_selection_modified), this ) );

        onSelectionChanged(selection);
    } else {
        onSelectionChanged(NULL);
    }
}
Ejemplo n.º 2
0
void
LivePathEffectEditor::onApply()
{
    Inkscape::Selection *sel = _getSelection();
    if ( sel && !sel->isEmpty() ) {
        SPItem *item = sel->singleItem();
        if ( item && SP_IS_LPE_ITEM(item) ) {
            SPDocument *doc = current_desktop->doc();

            const Util::EnumData<LivePathEffect::EffectType>* data = combo_effecttype.get_active_data();
            if (!data) return;

            // If item is a SPRect, convert it to path first:
            if ( SP_IS_RECT(item) ) {
                sp_selected_path_to_curves(current_desktop, false);
                item = sel->singleItem(); // get new item
            }

            LivePathEffect::Effect::createAndApply(data->key.c_str(), doc, item);

            sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
                     _("Create and apply path effect"));

            lpe_list_locked = false;
            onSelectionChanged(sel);
        }
    }
}
Ejemplo n.º 3
0
void
ExecutionEnv::reselect (void) {
    if (_doc == NULL) {
        return;
    }
    SPDocument * doc = _doc->doc();
    if (doc == NULL) {
        return;
    }

    SPDesktop *desktop = (SPDesktop *)_doc;
    sp_namedview_document_from_window(desktop);

    if (desktop == NULL) {
        return;
    }

    Inkscape::Selection * selection = desktop->getSelection();

    for (std::list<Glib::ustring>::iterator i = _selected.begin(); i != _selected.end(); ++i) {
        SPObject * obj = doc->getObjectById(i->c_str());
        if (obj != NULL) {
            selection->add(obj);
        }
    }

    return;
}
Ejemplo n.º 4
0
//FIXME: must work with text selection
void
text_remove_all_kerns()
{
    SPDesktop *desktop = SP_ACTIVE_DESKTOP;

    Inkscape::Selection *selection = sp_desktop_selection(desktop);

    if (selection->isEmpty()) {
        sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>text(s)</b> to remove kerns from."));
        return;
    }

    bool did = false;

    for (GSList *items = g_slist_copy((GSList *) selection->itemList());
         items != NULL;
         items = items->next) {
        SPObject *obj = SP_OBJECT(items->data);

        if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) {
            continue;
        }

        text_remove_all_kerns_recursively(obj);
        obj->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
        did = true;
    }

    if (!did) {
        sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("Select <b>text(s)</b> to remove kerns from."));
    } else {
        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, 
                         _("Remove manual kerns"));
    }
}
Ejemplo n.º 5
0
void LpeTool::setup() {
    PenTool::setup();

    Inkscape::Selection *selection = this->desktop->getSelection();
    SPItem *item = selection->singleItem();

    this->sel_changed_connection.disconnect();
    this->sel_changed_connection =
        selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_lpetool_context_selection_changed), (gpointer)this));

    this->shape_editor = new ShapeEditor(this->desktop);

    lpetool_context_switch_mode(this, Inkscape::LivePathEffect::INVALID_LPE);
    lpetool_context_reset_limiting_bbox(this);
    lpetool_create_measuring_items(this);

// TODO temp force:
    this->enableSelectionCue();
    
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();

    if (item) {
        this->shape_editor->set_item(item);
    }

    if (prefs->getBool("/tools/lpetool/selcue")) {
        this->enableSelectionCue();
    }
}
Ejemplo n.º 6
0
static void mesh_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBase* ec, GObject* holder)
{
    static sigc::connection c_selection_changed;
    static sigc::connection c_selection_modified;
    static sigc::connection c_subselection_changed;
    static sigc::connection c_defs_release;
    static sigc::connection c_defs_modified;

    if (SP_IS_MESH_CONTEXT(ec)) {
        // connect to selection modified and changed signals
        Inkscape::Selection *selection = desktop->getSelection();
        SPDocument *document = desktop->getDocument();

        c_selection_changed = selection->connectChanged(sigc::bind(sigc::ptr_fun(&ms_tb_selection_changed), holder));
        c_selection_modified = selection->connectModified(sigc::bind(sigc::ptr_fun(&ms_tb_selection_modified), holder));
        c_subselection_changed = desktop->connectToolSubselectionChanged(sigc::bind(sigc::ptr_fun(&ms_drag_selection_changed), holder));

        c_defs_release = document->getDefs()->connectRelease(sigc::bind<1>(sigc::ptr_fun(&ms_defs_release), holder));
        c_defs_modified = document->getDefs()->connectModified(sigc::bind<2>(sigc::ptr_fun(&ms_defs_modified), holder));
        ms_tb_selection_changed(selection, holder);
    } else {
        if (c_selection_changed)
            c_selection_changed.disconnect();
        if (c_selection_modified)
            c_selection_modified.disconnect();
        if (c_subselection_changed)
            c_subselection_changed.disconnect();
        if (c_defs_release)
            c_defs_release.disconnect();
        if (c_defs_modified)
            c_defs_modified.disconnect();
    }
}
Ejemplo n.º 7
0
static void
sp_spiral_context_setup(SPEventContext *ec)
{
    SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec);

    if (((SPEventContextClass *) parent_class)->setup)
        ((SPEventContextClass *) parent_class)->setup(ec);

    sp_event_context_read(ec, "expansion");
    sp_event_context_read(ec, "revolution");
    sp_event_context_read(ec, "t0");

    ec->shape_editor = new ShapeEditor(ec->desktop);

    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
    if (item) {
        ec->shape_editor->set_item(item, SH_KNOTHOLDER);
    }

    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
    sc->sel_changed_connection.disconnect();
    sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_spiral_context_selection_changed), (gpointer)sc));

    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    if (prefs->getBool("/tools/shapes/selcue")) {
        ec->enableSelectionCue();
    }
    if (prefs->getBool("/tools/shapes/gradientdrag")) {
        ec->enableGrDrag();
    }

    sc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
}
void
FontSubstitution::show(Glib::ustring out, GSList *l)
{
   Gtk::MessageDialog warning(_("\nSome fonts are not available and have been substituted."),
                       false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, true);
   warning.set_resizable(true);
   warning.set_title(_("Font substitution"));

   GtkWidget *dlg = GTK_WIDGET(warning.gobj());
   sp_transientize(dlg);

   Gtk::TextView * textview = new Gtk::TextView();
   textview->set_editable(false);
   textview->set_wrap_mode(Gtk::WRAP_WORD);
   textview->show();
   textview->get_buffer()->set_text(_(out.c_str()));

   Gtk::ScrolledWindow * scrollwindow = new Gtk::ScrolledWindow();
   scrollwindow->add(*textview);
   scrollwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
   scrollwindow->set_shadow_type(Gtk::SHADOW_IN);
   scrollwindow->set_size_request(0, 100);
   scrollwindow->show();

   Gtk::CheckButton *cbSelect = new Gtk::CheckButton();
   cbSelect->set_label(_("Select all the affected items"));
   cbSelect->set_active(true);
   cbSelect->show();

   Gtk::CheckButton *cbWarning = new Gtk::CheckButton();
   cbWarning->set_label(_("Don't show this warning again"));
   cbWarning->show();

#if GTK_CHECK_VERSION(3,0,0)
   Gtk::Box * box = warning.get_content_area();
#else
   Gtk::Box * box = warning.get_vbox();
#endif
   box->set_spacing(2);
   box->pack_start(*scrollwindow, true, true, 4);
   box->pack_start(*cbSelect, false, false, 0);
   box->pack_start(*cbWarning, false, false, 0);

   warning.run();

   if (cbWarning->get_active()) {
       Inkscape::Preferences *prefs = Inkscape::Preferences::get();
       prefs->setInt("/options/font/substitutedlg", 0);
   }

   if (cbSelect->get_active()) {

       SPDesktop *desktop = SP_ACTIVE_DESKTOP;
       Inkscape::Selection *selection = sp_desktop_selection (desktop);
       selection->clear();
       selection->setList(l);
   }

}
Ejemplo n.º 9
0
/**
    \brief  This actually draws the grid.
    \param  module   The effect that was called (unused)
    \param  document What should be edited.
*/
void
Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache * /*docCache*/)
{
    Inkscape::Selection * selection     = ((SPDesktop *)document)->selection;

    Geom::Rect bounding_area = Geom::Rect(Geom::Point(0,0), Geom::Point(100,100));
    if (selection->isEmpty()) {
        /* get page size */
        SPDocument * doc = document->doc();
        bounding_area = Geom::Rect(  Geom::Point(0,0),
                                     Geom::Point(doc->getWidth(), doc->getHeight())  );
    } else {
        Geom::OptRect bounds = selection->visualBounds();
        if (bounds) {
            bounding_area = *bounds;
        }

        gdouble doc_height  =  (document->doc())->getHeight();
        Geom::Rect temprec = Geom::Rect(Geom::Point(bounding_area.min()[Geom::X], doc_height - bounding_area.min()[Geom::Y]),
                                    Geom::Point(bounding_area.max()[Geom::X], doc_height - bounding_area.max()[Geom::Y]));

        bounding_area = temprec;
    }

    float spacings[2] = { module->get_param_float("xspacing"),
                          module->get_param_float("yspacing") };
    float line_width = module->get_param_float("lineWidth");
    float offsets[2] = { module->get_param_float("xoffset"),
                         module->get_param_float("yoffset") };

    Glib::ustring path_data("");

    path_data = build_lines(bounding_area,
                                 offsets, spacings);
    Inkscape::XML::Document * xml_doc = document->doc()->getReprDoc();

    //XML Tree being used directly here while it shouldn't be.
    Inkscape::XML::Node * current_layer = static_cast<SPDesktop *>(document)->currentLayer()->getRepr();
    Inkscape::XML::Node * path = xml_doc->createElement("svg:path");

    path->setAttribute("d", path_data.c_str());

    Glib::ustring style("fill:none;fill-opacity:0.75000000;fill-rule:evenodd;stroke:#000000;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000");
    style += ";stroke-width:";
    gchar floatstring[64];
    std::ostringstream stringstream;
    stringstream << line_width;
    sprintf(floatstring, "%s", stringstream.str().c_str());
    style += floatstring;
    style += "pt";
    path->setAttribute("style", style.c_str());

    current_layer->appendChild(path);
		Inkscape::GC::release(path);

    return;
}
Ejemplo n.º 10
0
void
sp_selected_path_reverse(SPDesktop *desktop)
{
    Inkscape::Selection *selection = desktop->getSelection();
    std::vector<SPItem*> items = selection->itemList();

    if (items.empty()) {
        desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse."));
        return;
    }


    // set "busy" cursor
    desktop->setWaitingCursor();

    bool did = false;
    desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths..."));

    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i){

        SPPath *path = dynamic_cast<SPPath *>(*i);
        if (!path) {
            continue;
        }

        did = true;

        SPCurve *rcurve = path->get_curve_reference()->create_reverse();

        gchar *str = sp_svg_write_path(rcurve->get_pathvector());
        if ( path->hasPathEffectRecursive() ) {
            path->getRepr()->setAttribute("inkscape:original-d", str);
        } else {
            path->getRepr()->setAttribute("d", str);
        }
        g_free(str);

        rcurve->unref();

        // reverse nodetypes order (Bug #179866)
        gchar *nodetypes = g_strdup(path->getRepr()->attribute("sodipodi:nodetypes"));
        if ( nodetypes ) {
            path->getRepr()->setAttribute("sodipodi:nodetypes", g_strreverse(nodetypes));
            g_free(nodetypes);
        }
    }

    desktop->clearWaitingCursor();

    if (did) {
        DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_REVERSE,
                           _("Reverse path"));
    } else {
        desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection."));
    }
}
Ejemplo n.º 11
0
void
sp_selected_path_reverse(SPDesktop *desktop)
{
    Inkscape::Selection *selection = sp_desktop_selection(desktop);
    GSList *items = (GSList *) selection->itemList();

    if (!items) {
        sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse."));
        return;
    }


    // set "busy" cursor
    desktop->setWaitingCursor();

    bool did = false;
    desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths..."));

    for (GSList *i = items; i != NULL; i = i->next) {

        if (!SP_IS_PATH(i->data)) {
            continue;
        }

        did = true;
        SPPath *path = SP_PATH(i->data);

        SPCurve *rcurve = path->get_curve_reference()->create_reverse();

        gchar *str = sp_svg_write_path(rcurve->get_pathvector());
        if ( path->hasPathEffectRecursive() ) {
            path->getRepr()->setAttribute("inkscape:original-d", str);
        } else {
            path->getRepr()->setAttribute("d", str);
        }
        g_free(str);

        rcurve->unref();

        // reverse nodetypes order (Bug #179866)
        gchar *nodetypes = g_strdup(path->getRepr()->attribute("sodipodi:nodetypes"));
        if ( nodetypes ) {
            path->getRepr()->setAttribute("sodipodi:nodetypes", g_strreverse(nodetypes));
            g_free(nodetypes);
        }
    }

    desktop->clearWaitingCursor();

    if (did) {
        DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE,
                           _("Reverse path"));
    } else {
        sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection."));
    }
}
Ejemplo n.º 12
0
void
OriginalPathParam::on_select_original_button_click()
{
    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
    SPItem *original = ref.getObject();
    if (desktop == NULL || original == NULL) {
        return;
    }
    Inkscape::Selection *selection = sp_desktop_selection(desktop);
    selection->clear();
    selection->set(original);
}
Ejemplo n.º 13
0
/*
 * Attempts to perform the construction of the given type (i.e., to apply the corresponding LPE) to
 * a single selected item. Returns whether we succeeded.
 */
bool
lpetool_try_construction(LpeTool *lc, Inkscape::LivePathEffect::EffectType const type)
{
    Inkscape::Selection *selection = lc->desktop->getSelection();
    SPItem *item = selection->singleItem();

    // TODO: should we check whether type represents a valid geometric construction?
    if (item && SP_IS_LPE_ITEM(item) && Inkscape::LivePathEffect::Effect::acceptsNumClicks(type) == 0) {
        Inkscape::LivePathEffect::Effect::createAndApply(type, lc->desktop->getDocument(), item);
        return true;
    }
    return false;
}
Ejemplo n.º 14
0
void LivePathEffectEditor::onDown()
{
    Inkscape::Selection *sel = _getSelection();
    if ( sel && !sel->isEmpty() ) {
        SPItem *item = sel->singleItem();
        if ( item && SP_IS_LPE_ITEM(item) ) {
            sp_lpe_item_down_current_path_effect(SP_LPE_ITEM(item));

            sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
                               _("Move path effect down") );

            effect_list_reload(SP_LPE_ITEM(item));
        }
    }
}
Ejemplo n.º 15
0
void sp_find_dialog_find(GObject *, GObject *dlg)
{
    SPDesktop *desktop = SP_ACTIVE_DESKTOP;

    bool hidden = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_object_get_data (GTK_OBJECT (dlg), "includehidden")));
    bool locked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_object_get_data (GTK_OBJECT (dlg), "includelocked")));

    GSList *l = NULL;
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_object_get_data (GTK_OBJECT (dlg), "inselection")))) {
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_object_get_data (GTK_OBJECT (dlg), "inlayer")))) {
            l = all_selection_items (desktop->selection, l, desktop->currentLayer(), hidden, locked);
        } else {
            l = all_selection_items (desktop->selection, l, NULL, hidden, locked);
        }
    } else {
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_object_get_data (GTK_OBJECT (dlg), "inlayer")))) {
            l = all_items (desktop->currentLayer(), l, hidden, locked);
        } else {
            l = all_items (SP_DOCUMENT_ROOT (sp_desktop_document (desktop)), l, hidden, locked);
        }
    }
    guint all = g_slist_length (l);

    bool exact = true;
    GSList *n = NULL;
    n = filter_list (l, dlg, exact);
    if (n == NULL) {
        exact = false;
        n = filter_list (l, dlg, exact);
    }

    if (n != NULL) {
        int count = g_slist_length (n);
        desktop->messageStack()->flashF(Inkscape::NORMAL_MESSAGE,
                                        // TRANSLATORS: "%s" is replaced with "exact" or "partial" when this string is displayed
                                        ngettext("<b>%d</b> object found (out of <b>%d</b>), %s match.",
                                                 "<b>%d</b> objects found (out of <b>%d</b>), %s match.",
                                                 count),
                                        count, all, exact? _("exact") : _("partial"));

        Inkscape::Selection *selection = sp_desktop_selection (desktop);
        selection->clear();
        selection->setList(n);
        scroll_to_show_item (desktop, SP_ITEM(n->data));
    } else {
        desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No objects found"));
    }
}
static void 
gradient_selection_changed (Inkscape::Selection *, gpointer data)
{
    SPGradientContext *rc = (SPGradientContext *) data;

    GrDrag *drag = rc->_grdrag;
    Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop);
    guint n_obj = g_slist_length((GSList *) selection->itemList());

    if (!drag->isNonEmpty() || selection->isEmpty())
        return;
    guint n_tot = drag->numDraggers();
    guint n_sel = drag->numSelected();

    //The use of ngettext in the following code is intentional even if the English singular form would never be used
    if (n_sel == 1) {
        if (drag->singleSelectedDraggerNumDraggables() == 1) {
		gchar * message = g_strconcat(
			//TRANSLATORS: %s will be substituted with the point name (see previous messages); This is part of a compound message
			_("%s selected"),
			//TRANSLATORS: Mind the space in front. This is part of a compound message
			ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
			ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
            	rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
			message,_(gr_handle_descr[drag->singleSelectedDraggerSingleDraggableType()]), n_tot, n_obj);
        } else {
		gchar * message = g_strconcat(
			//TRANSLATORS: This is a part of a compound message (out of two more indicating: grandint handle count & object count)
			ngettext("One handle merging %d stop (drag with <b>Shift</b> to separate) selected",
				"One handle merging %d stops (drag with <b>Shift</b> to separate) selected",drag->singleSelectedDraggerNumDraggables()),
			ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
			ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
		rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
        }
    } else if (n_sel > 1) {
	//TRANSLATORS: The plural refers to number of selected gradient handles. This is part of a compound message (part two indicates selected object count)
	gchar * message = g_strconcat(ngettext("<b>%d</b> gradient handle selected out of %d","<b>%d</b> gradient handles selected out of %d",n_sel),
				      //TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message
				      ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
        rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message, n_sel, n_tot, n_obj);
    } else if (n_sel == 0) {
        rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
		//TRANSLATORS: The plural refers to number of selected objects
                ngettext("<b>No</b> gradient handles selected out of %d on %d selected object",
			 "<b>No</b> gradient handles selected out of %d on %d selected objects",n_obj), n_tot, n_obj);
    }
}
Ejemplo n.º 17
0
static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name,
                                 void (SPRect::*setter)(gdouble))
{
    SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));

    UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
    Unit const *unit = tracker->getActiveUnit();
    g_return_if_fail(unit != NULL);

    if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
        prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name,
            Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
    }

    // quit if run by the attr_changed listener
    if (g_object_get_data( tbl, "freeze" ) || tracker->isUpdating()) {
        return;
    }

    // in turn, prevent listener from responding
    g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));

    bool modmade = false;
    Inkscape::Selection *selection = desktop->getSelection();
    std::vector<SPItem*> itemlist=selection->itemList();
    for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){
        if (SP_IS_RECT(*i)) {
            if (gtk_adjustment_get_value(adj) != 0) {
                (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
            } else {
                (*i)->getRepr()->setAttribute(value_name, NULL);
            }
            modmade = true;
        }
    }

    sp_rtb_sensitivize( tbl );

    if (modmade) {
        DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_RECT,
                           _("Change rectangle"));
    }

    g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
Ejemplo n.º 18
0
std::set<VanishingPoint*, less_ptr>
VPDragger::VPsOfSelectedBoxes() {
    std::set<VanishingPoint*, less_ptr> sel_vps;
    VanishingPoint *vp;
    // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference.
    Inkscape::Selection *sel = sp_desktop_selection(inkscape_active_desktop());
    for (GSList const* i = sel->itemList(); i != NULL; i = i->next) {
        if (!SP_IS_BOX3D(i->data))
            continue;
        SPBox3D *box = SP_BOX3D(i->data);
        vp = this->findVPWithBox(box);
        if (vp) {
            sel_vps.insert (vp);
        }
    }
    return sel_vps;
}
Ejemplo n.º 19
0
static bool sp_spray_dilate(SPSprayContext *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse)
{
    Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop);
    SPDesktop *desktop = SP_EVENT_CONTEXT(tc)->desktop;

    if (selection->isEmpty()) {
        return false;
    }

    bool did = false;
    double radius = get_dilate_radius(tc);
    double path_force = get_path_force(tc);
    if (radius == 0 || path_force == 0) {
        return false;
    }
    double path_mean = get_path_mean(tc);
    if (radius == 0 || path_mean == 0) {
        return false;
    }
    double path_standard_deviation = get_path_standard_deviation(tc);
    if (radius == 0 || path_standard_deviation == 0) {
        return false;
    }
    double move_force = get_move_force(tc);
    double move_mean = get_move_mean(tc);
    double move_standard_deviation = get_move_standard_deviation(tc);

    for (GSList *items = g_slist_copy((GSList *) selection->itemList());
         items != NULL;
         items = items->next) {

        SPItem *item = (SPItem *) items->data;

        if (is_transform_modes(tc->mode)) {
            if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, move_force, tc->population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib))
                did = true;
        } else {
            if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, path_force, tc->population, tc->scale, tc->scale_variation, reverse, path_mean, path_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib))
                did = true;
        }
    }

    return did;
}
Ejemplo n.º 20
0
static void rect_toolbox_watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBase* ec, GObject* holder)
{
    static sigc::connection changed;

    // use of dynamic_cast<> seems wrong here -- we just need to check the current tool

    if (dynamic_cast<Inkscape::UI::Tools::RectTool *>(ec)) {
        Inkscape::Selection *sel = desktop->getSelection();

        changed = sel->connectChanged(sigc::bind(sigc::ptr_fun(sp_rect_toolbox_selection_changed), holder));

        // Synthesize an emission to trigger the update
        sp_rect_toolbox_selection_changed(sel, holder);
    } else {
        if (changed) {
            changed.disconnect();
            purge_repr_listener(NULL, holder);
        }
    }
}
Ejemplo n.º 21
0
void spdc_endpoint_snap_free(ToolBase const * const ec, Geom::Point& p, boost::optional<Geom::Point> &start_of_line, guint const /*state*/)
{
    SPDesktop *dt = ec->desktop;
    SnapManager &m = dt->namedview->snap_manager;
    Inkscape::Selection *selection = dt->getSelection();

    // selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping)
    // TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment

    m.setup(dt, true, selection->singleItem());
    Inkscape::SnapCandidatePoint scp(p, Inkscape::SNAPSOURCE_NODE_HANDLE);
    if (start_of_line) {
        scp.addOrigin(*start_of_line);
    }

    Inkscape::SnappedPoint sp = m.freeSnap(scp);
    p = sp.getPoint();

    m.unSetup();
}
static void sp_gradient_context_setup(SPEventContext *ec)
{
    SPGradientContext *rc = SP_GRADIENT_CONTEXT(ec);

    if (((SPEventContextClass *) parent_class)->setup) {
        ((SPEventContextClass *) parent_class)->setup(ec);
    }

    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    if (prefs->getBool("/tools/gradient/selcue", true)) {
        ec->enableSelectionCue();
    }

    ec->enableGrDrag();
    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);

    rc->_message_context = new Inkscape::MessageContext(sp_desktop_message_stack(ec->desktop));

    rc->selcon = new sigc::connection (selection->connectChanged( sigc::bind (sigc::ptr_fun(&gradient_selection_changed), rc)));
    rc->subselcon = new sigc::connection (ec->desktop->connectToolSubselectionChanged(sigc::bind (sigc::ptr_fun(&gradient_subselection_changed), rc)));
    gradient_selection_changed(selection, rc);
}
Ejemplo n.º 23
0
/// Setup, taking the list of items to ignore from the desktop's selection.
void SnapManager::setupIgnoreSelection(SPDesktop const *desktop,
                                      bool snapindicator,
                                      std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes,
                                      SPGuide *guide_to_ignore)
{
    g_assert(desktop != NULL);
    if (_desktop != NULL) {
        // Someone has been naughty here! This is dangerous
        g_warning("The snapmanager has been set up before, but unSetup() hasn't been called afterwards. It possibly held invalid pointers");
    }
    _desktop = desktop;
    _snapindicator = snapindicator;
    _unselected_nodes = unselected_nodes;
    _guide_to_ignore = guide_to_ignore;
    _rotation_center_source_items.clear();
    _items_to_ignore.clear();

    Inkscape::Selection *sel = _desktop->selection;
    std::vector<SPItem*> const items = sel->itemList();
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i) {
        _items_to_ignore.push_back(*i);
    }
}
Ejemplo n.º 24
0
void
text_remove_from_path()
{
    SPDesktop *desktop = SP_ACTIVE_DESKTOP;

    Inkscape::Selection *selection = sp_desktop_selection(desktop);

    if (selection->isEmpty()) {
        sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text on path</b> to remove it from path."));
        return;
    }

    bool did = false;

    for (GSList *items = g_slist_copy((GSList *) selection->itemList());
         items != NULL;
         items = items->next) {

        if (!SP_IS_TEXT_TEXTPATH(SP_OBJECT(items->data))) {
            continue;
        }

        SPObject *tp = sp_object_first_child(SP_OBJECT(items->data));

        did = true;

        sp_textpath_to_text(tp);
    }

    if (!did) {
        sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No texts-on-paths</b> in the selection."));
    } else {
        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, 
                         _("Remove text from path"));
        selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description
    }
}
Ejemplo n.º 25
0
static void
sp_lpetool_context_setup(SPEventContext *ec)
{
    SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec);

    if (((SPEventContextClass *) lpetool_parent_class)->setup)
        ((SPEventContextClass *) lpetool_parent_class)->setup(ec);

    Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
    SPItem *item = selection->singleItem();

    lc->sel_changed_connection.disconnect();
    lc->sel_changed_connection =
        selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_lpetool_context_selection_changed), (gpointer)lc));

    lc->shape_editor = new ShapeEditor(ec->desktop);

    lpetool_context_switch_mode(lc, Inkscape::LivePathEffect::INVALID_LPE);
    lpetool_context_reset_limiting_bbox(lc);
    lpetool_create_measuring_items(lc);

// TODO temp force:
    ec->enableSelectionCue();
    
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();

    if (item) {
        lc->shape_editor->set_item(item, SH_NODEPATH);
        lc->shape_editor->set_item(item, SH_KNOTHOLDER);
    }

    if (prefs->getBool("/tools/lpetool/selcue")) {
        ec->enableSelectionCue();
    }

    lc->_lpetool_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
}
Ejemplo n.º 26
0
/**
 * Checks the current tool and connects gradient aux toolbox signals if it happens to be the gradient tool.
 * Called every time the current tool changes by signal emission.
 */
static void gradient_toolbox_check_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBase* ec, GObject* holder)
{
    static sigc::connection connChanged;
    static sigc::connection connModified;
    static sigc::connection connSubselectionChanged;
    static sigc::connection connDefsRelease;
    static sigc::connection connDefsModified;

    if (SP_IS_GRADIENT_CONTEXT(ec)) {
        Inkscape::Selection *selection = sp_desktop_selection(desktop);
        SPDocument *document = sp_desktop_document(desktop);

        // connect to selection modified and changed signals
        connChanged = selection->connectChanged(sigc::bind(sigc::ptr_fun(&gr_tb_selection_changed), holder));
        connModified = selection->connectModified(sigc::bind(sigc::ptr_fun(&gr_tb_selection_modified), holder));
        connSubselectionChanged = desktop->connectToolSubselectionChanged(sigc::bind(sigc::ptr_fun(&gr_drag_selection_changed), holder));

        // Is this necessary? Couldn't hurt.
        gr_tb_selection_changed(selection, holder);

        // connect to release and modified signals of the defs (i.e. when someone changes gradient)
        connDefsRelease = document->getDefs()->connectRelease(sigc::bind<1>(sigc::ptr_fun(&gr_defs_release), GTK_WIDGET(holder)));
        connDefsModified = document->getDefs()->connectModified(sigc::bind<2>(sigc::ptr_fun(&gr_defs_modified), GTK_WIDGET(holder)));
    } else {
        if (connChanged)
            connChanged.disconnect();
        if (connModified)
            connModified.disconnect();
        if (connSubselectionChanged)
            connSubselectionChanged.disconnect();
        if (connDefsRelease)
            connDefsRelease.disconnect();
        if (connDefsModified)
            connDefsModified.disconnect();
    }
}
Ejemplo n.º 27
0
static void
gr_tb_selection_changed (Inkscape::Selection *, gpointer data)
{
    GtkWidget *widget = (GtkWidget *) data;

    SPDesktop *desktop = (SPDesktop *) g_object_get_data (G_OBJECT(widget), "desktop");
    if (!desktop)
        return;

    Inkscape::Selection *selection = sp_desktop_selection (desktop); // take from desktop, not from args
    if (!selection)
        return;

    SPEventContext *ev = sp_desktop_event_context (desktop);

    GtkWidget *om = (GtkWidget *) g_object_get_data (G_OBJECT (widget), "menu");
    if (om) gtk_widget_destroy (om);

    SPGradient *gr_selected = NULL;
    bool gr_multi = false;

    SPGradientSpread spr_selected = (SPGradientSpread) INT_MAX; // meaning undefined
    bool spr_multi = false;

    gr_read_selection (selection, ev? ev->get_drag() : NULL, &gr_selected, &gr_multi, &spr_selected, &spr_multi);

    om = gr_vector_list (desktop, selection->isEmpty(), gr_selected, gr_multi);
    g_object_set_data (G_OBJECT (widget), "menu", om);

    GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(widget), "buttons");
    gtk_widget_set_sensitive (buttons, (gr_selected && !gr_multi));

    gtk_box_pack_start (GTK_BOX (widget), om, TRUE, TRUE, 0);

    gtk_widget_show_all (widget);
}
Ejemplo n.º 28
0
/** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */
void sp_selected_to_lpeitems(SPDesktop *desktop)
{
    Inkscape::Selection *selection = desktop->getSelection();

    if (selection->isEmpty()) {
        return;
    }

    std::vector<SPItem*> selected(selection->itemList());
    std::vector<Inkscape::XML::Node*> to_select;
    selection->clear();
    std::vector<SPItem*> items(selected);


    sp_item_list_to_curves(items, selected, to_select, true);

    selection->setReprList(to_select);
    selection->addList(selected);
}
Ejemplo n.º 29
0
/* This function is an entry point from GUI */
void
sp_selected_path_to_curves(SPDesktop *desktop, bool interactive)
{
    Inkscape::Selection *selection = sp_desktop_selection(desktop);

    if (selection->isEmpty()) {
        if (interactive)
            sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to path."));
        return;
    }

    bool did = false;
    if (interactive) {
        desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Converting objects to paths..."));
        // set "busy" cursor
        desktop->setWaitingCursor();
    }

    GSList *selected = g_slist_copy((GSList *) selection->itemList());
    GSList *to_select = NULL;
    selection->clear();
    GSList *items = g_slist_copy(selected);

    did = sp_item_list_to_curves(items, &selected, &to_select);

    g_slist_free (items);
    selection->setReprList(to_select);
    selection->addList(selected);
    g_slist_free (to_select);
    g_slist_free (selected);

    if (interactive) {
        desktop->clearWaitingCursor();
        if (did) {
            sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_TO_CURVE, 
                             _("Object to path"));
        } else {
            sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection."));
            return;
        }
    }
}
Ejemplo n.º 30
0
/** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */
void sp_selected_to_lpeitems(SPDesktop *desktop)
{
    Inkscape::Selection *selection = sp_desktop_selection(desktop);

    if (selection->isEmpty()) {
        return;
    }

    bool did = false;

    GSList *selected = g_slist_copy((GSList *) selection->itemList());
    GSList *to_select = NULL;
    selection->clear();
    GSList *items = g_slist_copy(selected);

    did = sp_item_list_to_curves(items, &selected, &to_select, true);

    g_slist_free (items);
    selection->setReprList(to_select);
    selection->addList(selected);
    g_slist_free (to_select);
    g_slist_free (selected);
}