Code

fix by dvlierop2 for snapping bugs 1579556 and 1579587
[inkscape.git] / src / text-context.cpp
index 5f4bbdba7e62835bcdbbdb2350cd226cce6c82e9..b65bcf19fa55a3cba768f4a977a5e83e532a536c 100644 (file)
@@ -48,6 +48,7 @@
 #include "rubberband.h"
 #include "sp-metrics.h"
 #include "context-fns.h"
+#include "verbs.h"
 
 #include "text-editing.h"
 
@@ -208,17 +209,17 @@ sp_text_context_setup(SPEventContext *ec)
     SPTextContext *tc = SP_TEXT_CONTEXT(ec);
     SPDesktop *desktop = ec->desktop;
 
-    tc->cursor = sp_canvas_item_new(SP_DT_CONTROLS(desktop), SP_TYPE_CTRLLINE, NULL);
+    tc->cursor = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLLINE, NULL);
     sp_ctrlline_set_coords(SP_CTRLLINE(tc->cursor), 100, 0, 100, 100);
     sp_ctrlline_set_rgba32(SP_CTRLLINE(tc->cursor), 0x000000ff);
     sp_canvas_item_hide(tc->cursor);
 
-    tc->indicator = sp_canvas_item_new(SP_DT_CONTROLS(desktop), SP_TYPE_CTRLRECT, NULL);
+    tc->indicator = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLRECT, NULL);
     SP_CTRLRECT(tc->indicator)->setRectangle(NR::Rect(NR::Point(0, 0), NR::Point(100, 100)));
     SP_CTRLRECT(tc->indicator)->setColor(0x0000ff7f, false, 0);
     sp_canvas_item_hide(tc->indicator);
 
-    tc->frame = sp_canvas_item_new(SP_DT_CONTROLS(desktop), SP_TYPE_CTRLRECT, NULL);
+    tc->frame = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLRECT, NULL);
     SP_CTRLRECT(tc->frame)->setRectangle(NR::Rect(NR::Point(0, 0), NR::Point(100, 100)));
     SP_CTRLRECT(tc->frame)->setColor(0x0000ff7f, false, 0);
     sp_canvas_item_hide(tc->frame);
@@ -227,7 +228,7 @@ sp_text_context_setup(SPEventContext *ec)
 
     tc->imc = gtk_im_multicontext_new();
     if (tc->imc) {
-        GtkWidget *canvas = GTK_WIDGET(SP_DT_CANVAS(desktop));
+        GtkWidget *canvas = GTK_WIDGET(sp_desktop_canvas(desktop));
 
         /* im preedit handling is very broken in inkscape for
          * multi-byte characters.  See bug 1086769.
@@ -250,7 +251,7 @@ sp_text_context_setup(SPEventContext *ec)
     if (((SPEventContextClass *) parent_class)->setup)
         ((SPEventContextClass *) parent_class)->setup(ec);
 
-    SPItem *item = SP_DT_SELECTION(ec->desktop)->singleItem();
+    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
     if (item && SP_IS_FLOWTEXT (item) && SP_FLOWTEXT(item)->has_internal_frame()) {
         ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
         Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(SP_FLOWTEXT(item)->get_frame(NULL));
@@ -258,14 +259,13 @@ sp_text_context_setup(SPEventContext *ec)
             ec->shape_repr = shape_repr;
             Inkscape::GC::anchor(shape_repr);
             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
-            sp_repr_synthesize_events(shape_repr, &ec_shape_repr_events, ec);
         }
     }
 
-    tc->sel_changed_connection = SP_DT_SELECTION(desktop)->connectChanged(
+    tc->sel_changed_connection = sp_desktop_selection(desktop)->connectChanged(
         sigc::bind(sigc::ptr_fun(&sp_text_context_selection_changed), tc)
         );
-    tc->sel_modified_connection = SP_DT_SELECTION(desktop)->connectModified(
+    tc->sel_modified_connection = sp_desktop_selection(desktop)->connectModified(
         sigc::bind(sigc::ptr_fun(&sp_text_context_selection_modified), tc)
         );
     tc->style_set_connection = desktop->connectSetStyle(
@@ -275,7 +275,7 @@ sp_text_context_setup(SPEventContext *ec)
         sigc::bind(sigc::ptr_fun(&sp_text_context_style_query), tc)
         );
 
-    sp_text_context_selection_changed(SP_DT_SELECTION(desktop), tc);
+    sp_text_context_selection_changed(sp_desktop_selection(desktop), tc);
 
     if (prefs_get_int_attribute("tools.text", "selcue", 0) != 0) {
         ec->enableSelectionCue();
@@ -290,6 +290,10 @@ sp_text_context_finish(SPEventContext *ec)
 {
     SPTextContext *tc = SP_TEXT_CONTEXT(ec);
 
+    if (ec->desktop) {
+        sp_signal_disconnect_by_data(sp_desktop_canvas(ec->desktop), tc);
+    }
+
     ec->enableGrDrag(false);
 
     tc->style_set_connection.disconnect();
@@ -330,10 +334,6 @@ sp_text_context_finish(SPEventContext *ec)
         gtk_object_destroy(*it);
     }
     tc->text_selection_quads.clear();
-
-    if (ec->desktop) {
-        sp_signal_disconnect_by_data(SP_DT_CANVAS(ec->desktop), tc);
-    }
 }
 
 
@@ -354,7 +354,7 @@ sp_text_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
                 // find out clicked item, disregarding groups
                 item_ungrouped = desktop->item_at_point(NR::Point(event->button.x, event->button.y), TRUE);
                 if (SP_IS_TEXT(item_ungrouped) || SP_IS_FLOWTEXT(item_ungrouped)) {
-                    SP_DT_SELECTION(ec->desktop)->set(item_ungrouped);
+                    sp_desktop_selection(ec->desktop)->set(item_ungrouped);
                     if (tc->text) {
                         // find out click point in document coordinates
                         NR::Point p = ec->desktop->w2d(NR::Point(event->button.x, event->button.y));
@@ -473,7 +473,8 @@ sp_text_context_setup_text(SPTextContext *tc)
     SPEventContext *ec = SP_EVENT_CONTEXT(tc);
 
     /* Create <text> */
-    Inkscape::XML::Node *rtext = sp_repr_new("svg:text");
+    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DESKTOP(ec)->doc());
+    Inkscape::XML::Node *rtext = xml_doc->createElement("svg:text");
     rtext->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create
 
     /* Set style */
@@ -483,23 +484,24 @@ sp_text_context_setup_text(SPTextContext *tc)
     sp_repr_set_svg_double(rtext, "y", tc->pdoc[NR::Y]);
 
     /* Create <tspan> */
-    Inkscape::XML::Node *rtspan = sp_repr_new("svg:tspan");
+    Inkscape::XML::Node *rtspan = xml_doc->createElement("svg:tspan");
     rtspan->setAttribute("sodipodi:role", "line"); // otherwise, why bother creating the tspan?
     rtext->addChild(rtspan, NULL);
     Inkscape::GC::release(rtspan);
 
     /* Create TEXT */
-    Inkscape::XML::Node *rstring = sp_repr_new_text("");
+    Inkscape::XML::Node *rstring = xml_doc->createTextNode("");
     rtspan->addChild(rstring, NULL);
     Inkscape::GC::release(rstring);
     SPItem *text_item = SP_ITEM(ec->desktop->currentLayer()->appendChildRepr(rtext));
     /* fixme: Is selection::changed really immediate? */
     /* yes, it's immediate .. why does it matter? */
-    SP_DT_SELECTION(ec->desktop)->set(text_item);
+    sp_desktop_selection(ec->desktop)->set(text_item);
     Inkscape::GC::release(rtext);
     text_item->transform = SP_ITEM(ec->desktop->currentRoot())->getRelativeTransform(ec->desktop->currentLayer());
     text_item->updateRepr();
-    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                     _("Create text"));
 }
 
 /**
@@ -537,7 +539,8 @@ insert_uni_char(SPTextContext *const tc)
         tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, u);
         sp_text_context_update_cursor(tc);
         sp_text_context_update_text_selection(tc);
-        sp_document_done(SP_DT_DOCUMENT(tc->desktop));
+        sp_document_done(sp_desktop_document(tc->desktop), SP_VERB_DIALOG_TRANSFORM, 
+                         _("Insert Unicode character"));
     }
 }
 
@@ -572,9 +575,9 @@ show_curr_uni_char(SPTextContext *const tc)
             }
         }
         tc->defaultMessageContext()->setF(Inkscape::NORMAL_MESSAGE,
-                                          _("Unicode: %s: %s"), tc->uni, utf8);
+                                          _("Unicode (<b>Enter</b> to finish): %s: %s"), tc->uni, utf8);
     } else {
-        tc->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Unicode: "));
+        tc->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Unicode (<b>Enter</b> to finish): "));
     }
 }
 
@@ -611,7 +614,7 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                 Inkscape::Rubberband::get()->start(desktop, tc->p0);
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                     GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK |
-                                        GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK,
+                                        GDK_POINTER_MOTION_MASK,
                                     NULL, event->button.time);
                 tc->grabbed = SP_CANVAS_ITEM(desktop->acetate);
                 tc->creating = 1;
@@ -669,7 +672,7 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
 
                 if (tc->creating && ec->within_tolerance) {
                     /* Button 1, set X & Y & new item */
-                    SP_DT_SELECTION(desktop)->clear();
+                    sp_desktop_selection(desktop)->clear();
                     NR::Point dtp = ec->desktop->w2d(NR::Point(event->button.x, event->button.y));
                     tc->pdoc = sp_desktop_dt2root_xy_point(ec->desktop, dtp);
 
@@ -693,9 +696,10 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                     if (fabs(p1[NR::Y] - tc->p0[NR::Y]) > cursor_height) {
                         // otherwise even one line won't fit; most probably a slip of hand (even if bigger than tolerance)
                         SPItem *ft = create_flowtext_with_internal_frame (desktop, tc->p0, p1);
-                        SP_DT_SELECTION(desktop)->set(ft);
+                        sp_desktop_selection(desktop)->set(ft);
                         ec->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Flowed text is created."));
-                        sp_document_done(SP_DT_DOCUMENT(desktop));
+                        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, 
+                                         _("Create flowed text"));
                     } else {
                         ec->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The frame is <b>too small</b> for the current font size. Flowed text not created."));
                     }
@@ -806,6 +810,13 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
 
                         /* Neither unimode nor IM consumed key; process text tool shortcuts */
                         switch (group0_keyval) {
+                            case GDK_x:
+                            case GDK_X:
+                                if (MOD__ALT_ONLY) {
+                                    desktop->setToolboxFocusTo ("altx-text");
+                                    return TRUE;
+                                }
+                                break;
                             case GDK_space:
                                 if (MOD__CTRL_ONLY) {
                                     /* No-break space */
@@ -817,20 +828,21 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                     sp_text_context_update_cursor(tc);
                                     sp_text_context_update_text_selection(tc);
                                     ec->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("No-break space"));
-                                    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                                    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                                                     _("Insert no-break space"));
                                     return TRUE;
                                 }
                                 break;
                             case GDK_U:
                             case GDK_u:
-                                if (MOD__CTRL_ONLY) {
+                                if (MOD__CTRL_ONLY || (MOD__CTRL && MOD__SHIFT)) {
                                     if (tc->unimode) {
                                         tc->unimode = false;
                                         ec->defaultMessageContext()->clear();
                                     } else {
                                         tc->unimode = true;
                                         tc->unipos = 0;
-                                        ec->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Unicode: "));
+                                        ec->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Unicode (<b>Enter</b> to finish): "));
                                     }
                                     if (tc->imc) {
                                         gtk_im_context_reset(tc->imc);
@@ -853,7 +865,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                         sp_repr_css_set_property(css, "font-weight", "normal");
                                     sp_te_apply_style(tc->text, tc->text_sel_start, tc->text_sel_end, css);
                                     sp_repr_css_attr_unref(css);
-                                    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                                    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                                                     _("Make bold"));
                                     sp_text_context_update_cursor(tc);
                                     sp_text_context_update_text_selection(tc);
                                     return TRUE;
@@ -870,7 +883,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                         sp_repr_css_set_property(css, "font-style", "normal");
                                     sp_te_apply_style(tc->text, tc->text_sel_start, tc->text_sel_end, css);
                                     sp_repr_css_attr_unref(css);
-                                    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                                    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                                                     _("Make italic"));
                                     sp_text_context_update_cursor(tc);
                                     sp_text_context_update_text_selection(tc);
                                     return TRUE;
@@ -901,7 +915,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                 tc->text_sel_start = tc->text_sel_end = sp_te_insert_line(tc->text, tc->text_sel_start);
                                 sp_text_context_update_cursor(tc);
                                 sp_text_context_update_text_selection(tc);
-                                sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                                sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                                                 _("New line"));
                                 return TRUE;
                             case GDK_BackSpace:
                                 if (tc->text) { // if nascent_object, do nothing, but return TRUE; same for all other delete and move keys
@@ -910,7 +925,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                     tc->text_sel_start = tc->text_sel_end = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end);
                                     sp_text_context_update_cursor(tc);
                                     sp_text_context_update_text_selection(tc);
-                                    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                                    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                                                     _("Backspace"));
                                 }
                                 return TRUE;
                             case GDK_Delete:
@@ -921,7 +937,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                     tc->text_sel_start = tc->text_sel_end = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end);
                                     sp_text_context_update_cursor(tc);
                                     sp_text_context_update_text_selection(tc);
-                                    sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+                                    sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                                                     _("Delete"));
                                 }
                                 return TRUE;
                             case GDK_Left:
@@ -935,7 +952,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                             sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(-1, 0));
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
-                                        sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "kern:left");
+                                        sp_document_maybe_done(sp_desktop_document(ec->desktop), "kern:left", SP_VERB_CONTEXT_TEXT, 
+                                                               _("Kern to the left"));
                                     } else {
                                         cursor_movement_operator = MOD__CTRL ? &Inkscape::Text::Layout::iterator::cursorLeftWithControl
                                                                              : &Inkscape::Text::Layout::iterator::cursorLeft;
@@ -954,7 +972,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                             sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(1, 0));
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
-                                        sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "kern:right");
+                                        sp_document_maybe_done(sp_desktop_document(ec->desktop), "kern:right", SP_VERB_CONTEXT_TEXT, 
+                                                               _("Kern to the right"));
                                     } else {
                                         cursor_movement_operator = MOD__CTRL ? &Inkscape::Text::Layout::iterator::cursorRightWithControl
                                                                              : &Inkscape::Text::Layout::iterator::cursorRight;
@@ -973,7 +992,9 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                             sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(0, -1));
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
-                                        sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "kern:up");
+                                        sp_document_maybe_done(sp_desktop_document(ec->desktop), "kern:up", SP_VERB_CONTEXT_TEXT, 
+                                                               _("Kern up"));
+
                                     } else {
                                         cursor_movement_operator = MOD__CTRL ? &Inkscape::Text::Layout::iterator::cursorUpWithControl
                                                                              : &Inkscape::Text::Layout::iterator::cursorUp;
@@ -992,7 +1013,9 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                             sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(0, 1));
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
-                                        sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "kern:down");
+                                        sp_document_maybe_done(sp_desktop_document(ec->desktop), "kern:down", SP_VERB_CONTEXT_TEXT, 
+                                                               _("Kern down"));
+
                                     } else {
                                         cursor_movement_operator = MOD__CTRL ? &Inkscape::Text::Layout::iterator::cursorDownWithControl
                                                                              : &Inkscape::Text::Layout::iterator::cursorDown;
@@ -1029,8 +1052,9 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                     }
                                     Inkscape::Rubberband::get()->stop();
                                 } else {
-                                    SP_DT_SELECTION(ec->desktop)->clear();
+                                    sp_desktop_selection(ec->desktop)->clear();
                                 }
+                                tc->nascent_object = FALSE;
                                 return TRUE;
                             case GDK_bracketleft:
                                 if (tc->text) {
@@ -1045,7 +1069,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                         } else {
                                             sp_te_adjust_rotation(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, -90);
                                         }
-                                        sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "textrot:ccw");
+                                        sp_document_maybe_done(sp_desktop_document(ec->desktop), "textrot:ccw", SP_VERB_CONTEXT_TEXT, 
+                                                               _("Rotate counterclockwise"));
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
                                         return TRUE;
@@ -1065,7 +1090,8 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                         } else {
                                             sp_te_adjust_rotation(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, 90);
                                         }
-                                        sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "textrot:cw");
+                                        sp_document_maybe_done(sp_desktop_document(ec->desktop), "textrot:cw", SP_VERB_CONTEXT_TEXT, 
+                                                                _("Rotate clockwise"));
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
                                         return TRUE;
@@ -1081,13 +1107,17 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                                 sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, -10);
                                             else
                                                 sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, -1);
-                                            sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "linespacing:dec");
+                                            sp_document_maybe_done(sp_desktop_document(ec->desktop), "linespacing:dec", SP_VERB_CONTEXT_TEXT, 
+                                                                    _("Contract line spacing"));
+
                                         } else {
                                             if (MOD__SHIFT)
                                                 sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, -10);
                                             else
                                                 sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, -1);
-                                            sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "letterspacing:dec");
+                                            sp_document_maybe_done(sp_desktop_document(ec->desktop), "letterspacing:dec", SP_VERB_CONTEXT_TEXT, 
+                                                                    _("Contract letter spacing"));
+
                                         }
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
@@ -1104,13 +1134,17 @@ sp_text_context_root_handler(SPEventContext *const ec, GdkEvent *const event)
                                                 sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, 10);
                                             else
                                                 sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, 1);
-                                            sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "linespacing:inc");
+                                            sp_document_maybe_done(sp_desktop_document(ec->desktop), "linespacing:inc", SP_VERB_CONTEXT_TEXT, 
+                                                                    _("Expand line spacing"));
+
                                         } else {
                                             if (MOD__SHIFT)
                                                 sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, 10);
                                             else
                                                 sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, 1);
-                                            sp_document_maybe_done(SP_DT_DOCUMENT(ec->desktop), "letterspacing:inc");
+                                            sp_document_maybe_done(sp_desktop_document(ec->desktop), "letterspacing:inc", SP_VERB_CONTEXT_TEXT, 
+                                                                    _("Expand letter spacing"));
+
                                         }
                                         sp_text_context_update_cursor(tc);
                                         sp_text_context_update_text_selection(tc);
@@ -1212,7 +1246,8 @@ sp_text_paste_inline(SPEventContext *ec)
                 tc->text_sel_start = tc->text_sel_end = sp_te_insert_line(tc->text, tc->text_sel_start);
                 begin = end + 1;
             }
-            sp_document_done(SP_DT_DOCUMENT(ec->desktop));
+            sp_document_done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, 
+                             _("Paste text"));
 
             return true;
         }
@@ -1286,7 +1321,6 @@ sp_text_context_selection_changed(Inkscape::Selection *selection, SPTextContext
             ec->shape_repr = shape_repr;
             Inkscape::GC::anchor(shape_repr);
             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
-            sp_repr_synthesize_events(shape_repr, &ec_shape_repr_events, ec);
         }
     }
 
@@ -1326,7 +1360,8 @@ sp_text_context_style_set(SPCSSAttr const *css, SPTextContext *tc)
         return false;    // will get picked up by the parent and applied to the whole text object
 
     sp_te_apply_style(tc->text, tc->text_sel_start, tc->text_sel_end, css);
-    sp_document_done(SP_DT_DOCUMENT(tc->desktop));
+    sp_document_done(sp_desktop_document(tc->desktop), SP_VERB_CONTEXT_TEXT, 
+                     _("Set text style"));
     sp_text_context_update_cursor(tc);
     sp_text_context_update_text_selection(tc);
 
@@ -1357,9 +1392,11 @@ sp_text_context_style_query(SPStyle *style, int property, SPTextContext *tc)
         if (!begin_it.prevCharacter())
             end_it.nextCharacter();
     for (Inkscape::Text::Layout::iterator it = begin_it ; it < end_it ; it.nextStartOfSpan()) {
-        SPObject const *pos_obj = NULL;
-        layout->getSourceOfCharacter(it, (void**)&pos_obj);
-        if (pos_obj == NULL) continue;
+        SPObject const *pos_obj = 0;
+        void *rawptr = 0;
+        layout->getSourceOfCharacter(it, &rawptr);
+        pos_obj = SP_OBJECT(rawptr);
+        if (pos_obj == 0) continue;
         while (SP_OBJECT_STYLE(pos_obj) == NULL && SP_OBJECT_PARENT(pos_obj))
             pos_obj = SP_OBJECT_PARENT(pos_obj);   // SPStrings don't have style
         styles_list = g_slist_prepend(styles_list, (gpointer)pos_obj);
@@ -1388,6 +1425,10 @@ sp_text_context_update_cursor(SPTextContext *tc,  bool scroll_to_see)
 {
     GdkRectangle im_cursor = { 0, 0, 1, 1 };
 
+    // due to interruptible display, tc may already be destroyed during a display update before
+    // the cursor update (can't do both atomically, alas)
+    if (!tc->desktop) return;
+
     if (tc->text) {
         NR::Point p0, p1;
         sp_te_get_cursor_coords(tc->text, tc->text_sel_end, p0, p1);
@@ -1441,6 +1482,10 @@ sp_text_context_update_cursor(SPTextContext *tc,  bool scroll_to_see)
 
 static void sp_text_context_update_text_selection(SPTextContext *tc)
 {
+    // due to interruptible display, tc may already be destroyed during a display update before
+    // the selection update (can't do both atomically, alas)
+    if (!tc->desktop) return;
+
     for (std::vector<SPCanvasItem*>::iterator it = tc->text_selection_quads.begin() ; it != tc->text_selection_quads.end() ; it++) {
         sp_canvas_item_hide(*it);
         gtk_object_destroy(*it);
@@ -1452,7 +1497,7 @@ static void sp_text_context_update_text_selection(SPTextContext *tc)
         quads = sp_te_create_selection_quads(tc->text, tc->text_sel_start, tc->text_sel_end, sp_item_i2d_affine(tc->text));
     for (unsigned i = 0 ; i < quads.size() ; i += 4) {
         SPCanvasItem *quad_canvasitem;
-        quad_canvasitem = sp_canvas_item_new(SP_DT_CONTROLS(tc->desktop), SP_TYPE_CTRLQUADR, NULL);
+        quad_canvasitem = sp_canvas_item_new(sp_desktop_controls(tc->desktop), SP_TYPE_CTRLQUADR, NULL);
         sp_ctrlquadr_set_rgba32(SP_CTRLQUADR(quad_canvasitem), 0x000000ff);
         sp_ctrlquadr_set_coords(SP_CTRLQUADR(quad_canvasitem), quads[i], quads[i+1], quads[i+2], quads[i+3]);
         sp_canvas_item_show(quad_canvasitem);
@@ -1522,7 +1567,8 @@ sptc_commit(GtkIMContext *imc, gchar *string, SPTextContext *tc)
     sp_text_context_update_cursor(tc);
     sp_text_context_update_text_selection(tc);
 
-    sp_document_done(SP_OBJECT_DOCUMENT(tc->text));
+    sp_document_done(SP_OBJECT_DOCUMENT(tc->text), SP_VERB_CONTEXT_TEXT, 
+                     _("Type text"));
 }