summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4afea2c)
raw | patch | inline | side by side (parent: 4afea2c)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Mon, 16 Feb 2009 00:23:40 +0000 (00:23 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Mon, 16 Feb 2009 00:23:40 +0000 (00:23 +0000) |
src/text-context.cpp | patch | blob | history | |
src/text-context.h | patch | blob | history | |
src/text-editing.cpp | patch | blob | history | |
src/text-editing.h | patch | blob | history |
diff --git a/src/text-context.cpp b/src/text-context.cpp
index 6e4b637b85d26b5163ec5821284f6d42850d99f7..b2efd0cc21dfbeb4b40fe2883a9603dd1bc19e82 100644 (file)
--- a/src/text-context.cpp
+++ b/src/text-context.cpp
#include "context-fns.h"
#include "verbs.h"
#include "shape-editor.h"
-
+#include "selection-chemistry.h"
#include "text-editing.h"
#include "text-context.h"
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.
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) {
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 {
_("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:
diff --git a/src/text-context.h b/src/text-context.h
index b9068e4976a12af2fafa9522899f72ac0be9265d..a6e2e8db7040652861328f2fdd1cc1aa0a4c6bd8 100644 (file)
--- a/src/text-context.h
+++ b/src/text-context.h
bool sp_text_paste_inline(SPEventContext *ec);
Glib::ustring sp_text_get_selected_text(SPEventContext const *ec);
+SPCSSAttr *sp_text_get_style_at_cursor(SPEventContext const *ec);
bool sp_text_delete_selection(SPEventContext *ec);
+void sp_text_context_place_cursor (SPTextContext *tc, SPObject *text, Inkscape::Text::Layout::iterator where);
+void sp_text_context_place_cursor_at (SPTextContext *tc, SPObject *text, Geom::Point const p);
+Inkscape::Text::Layout::iterator *sp_text_context_get_cursor_position(SPTextContext *tc, SPObject *text);
#endif
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index 2ccc9119520940f5812da48bb557867b66a3a494..5b9db13d4532a29c2926344b9f5e0322133afa45 100644 (file)
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
@@ -109,6 +109,14 @@ sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator co
}
SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position)
+{
+ SPObject const *pos_obj = sp_te_object_at_position(text, position);
+ if (pos_obj)
+ return SP_OBJECT_STYLE(pos_obj);
+ return NULL;
+}
+
+SPObject const * sp_te_object_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position)
{
Inkscape::Text::Layout const *layout = te_get_layout(text);
if (layout == NULL)
@@ -119,8 +127,8 @@ SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layo
pos_obj = SP_OBJECT(rawptr);
if (pos_obj == 0) pos_obj = text;
while (SP_OBJECT_STYLE(pos_obj) == NULL)
- pos_obj = SP_OBJECT_PARENT(pos_obj); // SPStrings don't have style
- return SP_OBJECT_STYLE(pos_obj);
+ pos_obj = SP_OBJECT_PARENT(pos_obj); // not interested in SPStrings
+ return pos_obj;
}
/*
diff --git a/src/text-editing.h b/src/text-editing.h
index b1fb6b200b04ce46d4408696cae774735f216354..83ddae77fc6e74781c8d9c78a79491e30170704e 100644 (file)
--- a/src/text-editing.h
+++ b/src/text-editing.h
void sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, Geom::Point &p0, Geom::Point &p1);
double sp_te_get_average_linespacing (SPItem *text);
-
SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position);
+SPObject const * sp_te_object_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position);
Inkscape::Text::Layout::iterator sp_te_insert(SPItem *item, Inkscape::Text::Layout::iterator const &position, gchar const *utf8);
Inkscape::Text::Layout::iterator sp_te_replace(SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, gchar const *utf8);