Code

Adding the lacking HSL bubbles transparent
[inkscape.git] / src / text-context.cpp
index 6e4b637b85d26b5163ec5821284f6d42850d99f7..538e13e433e1a57e4c5325c40bd96f0821c65446 100644 (file)
@@ -35,7 +35,6 @@
 #include "desktop.h"
 #include "desktop-style.h"
 #include "desktop-handles.h"
-#include "desktop-affine.h"
 #include "message-stack.h"
 #include "message-context.h"
 #include "pixmaps/cursor-text.xpm"
@@ -50,7 +49,7 @@
 #include "context-fns.h"
 #include "verbs.h"
 #include "shape-editor.h"
-
+#include "selection-chemistry.h"
 #include "text-editing.h"
 
 #include "text-context.h"
@@ -353,7 +352,7 @@ sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve
                         sp_text_context_update_cursor(tc);
                         sp_text_context_update_text_selection(tc);
                         tc->dragging = 1;
-                        sp_canvas_set_snap_delay_active(desktop->canvas, true);
+                        sp_event_context_snap_window_open(event_context);
                     }
                     ret = TRUE;
                 }
@@ -370,7 +369,7 @@ sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve
                     sp_text_context_update_cursor(tc);
                     sp_text_context_update_text_selection(tc);
                     tc->dragging = 2;
-                    sp_canvas_set_snap_delay_active(desktop->canvas, true);
+                    sp_event_context_snap_window_open(event_context);
                     ret = TRUE;
                 }
             }
@@ -382,14 +381,14 @@ sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve
                 sp_text_context_update_cursor(tc);
                 sp_text_context_update_text_selection(tc);
                 tc->dragging = 3;
-                sp_canvas_set_snap_delay_active(desktop->canvas, true);
+                sp_event_context_snap_window_open(event_context);
                 ret = TRUE;
             }
             break;
         case GDK_BUTTON_RELEASE:
             if (event->button.button == 1 && tc->dragging && !event_context->space_panning) {
                 tc->dragging = 0;
-                sp_canvas_set_snap_delay_active(desktop->canvas, false);
+                sp_event_context_snap_window_closed(event_context, false); //button release will also occur on a double-click; in that case suppress warnings
                 ret = TRUE;
             }
             break;
@@ -670,7 +669,7 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons
                     /* Button 1, set X & Y & new item */
                     sp_desktop_selection(desktop)->clear();
                     Geom::Point dtp = desktop->w2d(Geom::Point(event->button.x, event->button.y));
-                    tc->pdoc = sp_desktop_dt2doc_xy_point(desktop, dtp);
+                    tc->pdoc = desktop->dt2doc(dtp);
 
                     tc->show = TRUE;
                     tc->phase = 1;
@@ -1280,6 +1279,9 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons
                         }
                         Inkscape::Rubberband::get(desktop)->stop();
                     }
+                } else if ((group0_keyval == GDK_x || group0_keyval == GDK_X) && MOD__ALT_ONLY) {
+                    desktop->setToolboxFocusTo ("altx-text");
+                    return TRUE;
                 }
             }
             break;
@@ -1391,6 +1393,21 @@ sp_text_get_selected_text(SPEventContext const *ec)
     return sp_te_get_string_multiline(tc->text, tc->text_sel_start, tc->text_sel_end);
 }
 
+SPCSSAttr *
+sp_text_get_style_at_cursor(SPEventContext const *ec)
+{
+    if (!SP_IS_TEXT_CONTEXT(ec))
+        return NULL;
+    SPTextContext const *tc = SP_TEXT_CONTEXT(ec);
+    if (tc->text == NULL)
+        return NULL;
+
+    SPObject const *obj = sp_te_object_at_position(tc->text, tc->text_sel_end);
+    if (obj)
+        return take_style_from_item((SPItem *) obj);
+    return NULL;
+}
+
 /**
  Deletes the currently selected characters. Returns false if there is no
  text selection currently.
@@ -1574,6 +1591,8 @@ sp_text_context_update_cursor(SPTextContext *tc,  bool scroll_to_see)
         tc->show = TRUE;
         tc->phase = 1;
 
+        Inkscape::Text::Layout const *layout = te_get_layout(tc->text);
+        int const nChars = layout->iteratorToCharIndex(layout->end());
         if (SP_IS_FLOWTEXT(tc->text)) {
             SPItem *frame = SP_FLOWTEXT(tc->text)->get_frame (NULL); // first frame only
             if (frame) {
@@ -1583,9 +1602,9 @@ sp_text_context_update_cursor(SPTextContext *tc,  bool scroll_to_see)
                     SP_CTRLRECT(tc->frame)->setRectangle(*frame_bbox);
                 }
             }
-            SP_EVENT_CONTEXT(tc)->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Type flowed text; <b>Enter</b> to start new paragraph."));
+            SP_EVENT_CONTEXT(tc)->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("Type or edit flowed text (%d characters); <b>Enter</b> to start new paragraph."), nChars);
         } else {
-            SP_EVENT_CONTEXT(tc)->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Type text; <b>Enter</b> to start new line."));
+            SP_EVENT_CONTEXT(tc)->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("Type or edit text (%d characters); <b>Enter</b> to start new line."), nChars);
         }
 
     } else {
@@ -1706,6 +1725,29 @@ sptc_commit(GtkIMContext */*imc*/, gchar *string, SPTextContext *tc)
                      _("Type text"));
 }
 
+void
+sp_text_context_place_cursor (SPTextContext *tc, SPObject *text, Inkscape::Text::Layout::iterator where)
+{
+    SP_EVENT_CONTEXT_DESKTOP (tc)->selection->set (text);
+    tc->text_sel_start = tc->text_sel_end = where;
+    sp_text_context_update_cursor(tc);
+    sp_text_context_update_text_selection(tc);
+}
+
+void
+sp_text_context_place_cursor_at (SPTextContext *tc, SPObject *text, Geom::Point const p)
+{
+    SP_EVENT_CONTEXT_DESKTOP (tc)->selection->set (text);
+    sp_text_context_place_cursor (tc, text, sp_te_get_position_by_coords(tc->text, p));
+}
+
+Inkscape::Text::Layout::iterator *sp_text_context_get_cursor_position(SPTextContext *tc, SPObject *text)
+{
+    if (text != tc->text)
+        return NULL;
+    return &(tc->text_sel_end);
+}
+
 
 /*
   Local Variables: