summaryrefslogtreecommitdiffstats
path: root/src/text-context.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-07-14 21:09:41 +0000
committerMarkus Engel <markus.engel@tum.de>2013-07-14 21:09:41 +0000
commitd32efb61f1c2c18d1018e510bbe9bafc04a03905 (patch)
treeb447bf9856baf1cf485e38c4ce55edb27285129e /src/text-context.cpp
parentMerged from trunk (r12305) (diff)
parentMinor C++ish refactoring pass. (diff)
downloadinkscape-d32efb61f1c2c18d1018e510bbe9bafc04a03905.tar.gz
inkscape-d32efb61f1c2c18d1018e510bbe9bafc04a03905.zip
Merged from trunk (r12419).
(bzr r11608.1.107)
Diffstat (limited to 'src/text-context.cpp')
-rw-r--r--src/text-context.cpp116
1 files changed, 69 insertions, 47 deletions
diff --git a/src/text-context.cpp b/src/text-context.cpp
index 1170f5129..254fafe6b 100644
--- a/src/text-context.cpp
+++ b/src/text-context.cpp
@@ -220,7 +220,7 @@ void SPTextContext::setup() {
ec->shape_editor = new ShapeEditor(ec->desktop);
SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
- if (item && SP_IS_FLOWTEXT (item) && SP_FLOWTEXT(item)->has_internal_frame()) {
+ if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
ec->shape_editor->set_item(item, SH_KNOTHOLDER);
}
@@ -309,6 +309,7 @@ gint SPTextContext::item_handler(SPItem* item, GdkEvent* event) {
gint ret = FALSE;
sp_text_context_validate_cursor_iterators(tc);
+ Inkscape::Text::Layout::iterator old_start = tc->text_sel_start;
switch (event->type) {
case GDK_BUTTON_PRESS:
@@ -321,7 +322,12 @@ gint SPTextContext::item_handler(SPItem* item, GdkEvent* event) {
// find out click point in document coordinates
Geom::Point p = desktop->w2d(Geom::Point(event->button.x, event->button.y));
// set the cursor closest to that point
- tc->text_sel_start = tc->text_sel_end = sp_te_get_position_by_coords(tc->text, p);
+ if (event->button.state & GDK_SHIFT_MASK) {
+ tc->text_sel_start = old_start;
+ tc->text_sel_end = sp_te_get_position_by_coords(tc->text, p);
+ } else {
+ tc->text_sel_start = tc->text_sel_end = sp_te_get_position_by_coords(tc->text, p);
+ }
// update display
sp_text_context_update_cursor(tc);
sp_text_context_update_text_selection(tc);
@@ -732,12 +738,12 @@ gint SPTextContext::root_handler(GdkEvent* event) {
// there is an active text object in this context, or a new object was just created
if (tc->unimode || !tc->imc
- || (MOD__CTRL && MOD__SHIFT) // input methods tend to steal this for unimode,
+ || (MOD__CTRL(event) && MOD__SHIFT(event)) // input methods tend to steal this for unimode,
// but we have our own so make sure they don't swallow it
|| !gtk_im_context_filter_keypress(tc->imc, (GdkEventKey*) event)) {
//IM did not consume the key, or we're in unimode
- if (!MOD__CTRL_ONLY && tc->unimode) {
+ if (!MOD__CTRL_ONLY(event) && tc->unimode) {
/* TODO: ISO 14755 (section 3 Definitions) says that we should also
accept the first 6 characters of alphabets other than the latin
alphabet "if the Latin alphabet is not used". The below is also
@@ -833,13 +839,13 @@ gint SPTextContext::root_handler(GdkEvent* event) {
switch (group0_keyval) {
case GDK_KEY_x:
case GDK_KEY_X:
- if (MOD__ALT_ONLY) {
+ if (MOD__ALT_ONLY(event)) {
desktop->setToolboxFocusTo ("altx-text");
return TRUE;
}
break;
case GDK_KEY_space:
- if (MOD__CTRL_ONLY) {
+ if (MOD__CTRL_ONLY(event)) {
/* No-break space */
if (!tc->text) { // printable key; create text if none (i.e. if nascent_object)
sp_text_context_setup_text(tc);
@@ -856,7 +862,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
break;
case GDK_KEY_U:
case GDK_KEY_u:
- if (MOD__CTRL_ONLY || (MOD__CTRL && MOD__SHIFT)) {
+ if (MOD__CTRL_ONLY(event) || (MOD__CTRL(event) && MOD__SHIFT(event))) {
if (tc->unimode) {
tc->unimode = false;
event_context->defaultMessageContext()->clear();
@@ -873,7 +879,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
break;
case GDK_KEY_B:
case GDK_KEY_b:
- if (MOD__CTRL_ONLY && tc->text) {
+ if (MOD__CTRL_ONLY(event) && tc->text) {
SPStyle const *style = sp_te_style_at_position(tc->text, std::min(tc->text_sel_start, tc->text_sel_end));
SPCSSAttr *css = sp_repr_css_attr_new();
if (style->font_weight.computed == SP_CSS_FONT_WEIGHT_NORMAL
@@ -895,7 +901,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
break;
case GDK_KEY_I:
case GDK_KEY_i:
- if (MOD__CTRL_ONLY && tc->text) {
+ if (MOD__CTRL_ONLY(event) && tc->text) {
SPStyle const *style = sp_te_style_at_position(tc->text, std::min(tc->text_sel_start, tc->text_sel_end));
SPCSSAttr *css = sp_repr_css_attr_new();
if (style->font_style.computed != SP_CSS_FONT_STYLE_NORMAL)
@@ -914,7 +920,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_A:
case GDK_KEY_a:
- if (MOD__CTRL_ONLY && tc->text) {
+ if (MOD__CTRL_ONLY(event) && tc->text) {
Inkscape::Text::Layout const *layout = te_get_layout(tc->text);
if (layout) {
tc->text_sel_start = layout->begin();
@@ -952,13 +958,21 @@ gint SPTextContext::root_handler(GdkEvent* event) {
bool noSelection = false;
- if (tc->text_sel_start == tc->text_sel_end) {
- tc->text_sel_start.prevCursorPosition();
+ if (MOD__CTRL(event)) {
+ tc->text_sel_start = tc->text_sel_end;
+ }
+
+ if (tc->text_sel_start == tc->text_sel_end) {
+ if (MOD__CTRL(event)) {
+ tc->text_sel_start.prevStartOfWord();
+ } else {
+ tc->text_sel_start.prevCursorPosition();
+ }
noSelection = true;
}
- iterator_pair bspace_pair;
- bool success = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end, bspace_pair);
+ iterator_pair bspace_pair;
+ bool success = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end, bspace_pair);
if (noSelection) {
if (success) {
@@ -986,8 +1000,16 @@ gint SPTextContext::root_handler(GdkEvent* event) {
if (tc->text) {
bool noSelection = false;
+ if (MOD__CTRL(event)) {
+ tc->text_sel_start = tc->text_sel_end;
+ }
+
if (tc->text_sel_start == tc->text_sel_end) {
- tc->text_sel_end.nextCursorPosition();
+ if (MOD__CTRL(event)) {
+ tc->text_sel_end.nextEndOfWord();
+ } else {
+ tc->text_sel_end.nextCursorPosition();
+ }
noSelection = true;
}
@@ -1016,10 +1038,10 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Left:
case GDK_KEY_KP_4:
if (tc->text) {
- if (MOD__ALT) {
+ if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(
get_group0_keyval(&event->key), 0); // with any mask
- if (MOD__SHIFT)
+ if (MOD__SHIFT(event))
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(mul*-10, 0));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(mul*-1, 0));
@@ -1028,7 +1050,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:left", SP_VERB_CONTEXT_TEXT,
_("Kern to the left"));
} else {
- if (MOD__CTRL)
+ if (MOD__CTRL(event))
tc->text_sel_end.cursorLeftWithControl();
else
tc->text_sel_end.cursorLeft();
@@ -1041,10 +1063,10 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Right:
case GDK_KEY_KP_6:
if (tc->text) {
- if (MOD__ALT) {
+ if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(
get_group0_keyval(&event->key), 0); // with any mask
- if (MOD__SHIFT)
+ if (MOD__SHIFT(event))
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(mul*10, 0));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(mul*1, 0));
@@ -1053,7 +1075,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:right", SP_VERB_CONTEXT_TEXT,
_("Kern to the right"));
} else {
- if (MOD__CTRL)
+ if (MOD__CTRL(event))
tc->text_sel_end.cursorRightWithControl();
else
tc->text_sel_end.cursorRight();
@@ -1066,10 +1088,10 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Up:
case GDK_KEY_KP_8:
if (tc->text) {
- if (MOD__ALT) {
+ if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(
get_group0_keyval(&event->key), 0); // with any mask
- if (MOD__SHIFT)
+ if (MOD__SHIFT(event))
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(0, mul*-10));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(0, mul*-1));
@@ -1078,7 +1100,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:up", SP_VERB_CONTEXT_TEXT,
_("Kern up"));
} else {
- if (MOD__CTRL)
+ if (MOD__CTRL(event))
tc->text_sel_end.cursorUpWithControl();
else
tc->text_sel_end.cursorUp();
@@ -1091,10 +1113,10 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Down:
case GDK_KEY_KP_2:
if (tc->text) {
- if (MOD__ALT) {
+ if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(
get_group0_keyval(&event->key), 0); // with any mask
- if (MOD__SHIFT)
+ if (MOD__SHIFT(event))
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(0, mul*10));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, Geom::Point(0, mul*1));
@@ -1103,7 +1125,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:down", SP_VERB_CONTEXT_TEXT,
_("Kern down"));
} else {
- if (MOD__CTRL)
+ if (MOD__CTRL(event))
tc->text_sel_end.cursorDownWithControl();
else
tc->text_sel_end.cursorDown();
@@ -1115,7 +1137,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_Home:
case GDK_KEY_KP_Home:
if (tc->text) {
- if (MOD__CTRL)
+ if (MOD__CTRL(event))
tc->text_sel_end.thisStartOfShape();
else
tc->text_sel_end.thisStartOfLine();
@@ -1126,7 +1148,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_End:
case GDK_KEY_KP_End:
if (tc->text) {
- if (MOD__CTRL)
+ if (MOD__CTRL(event))
tc->text_sel_end.nextStartOfShape();
else
tc->text_sel_end.thisEndOfLine();
@@ -1165,9 +1187,9 @@ gint SPTextContext::root_handler(GdkEvent* event) {
return TRUE;
case GDK_KEY_bracketleft:
if (tc->text) {
- if (MOD__ALT || MOD__CTRL) {
- if (MOD__ALT) {
- if (MOD__SHIFT) {
+ if (MOD__ALT(event) || MOD__CTRL(event)) {
+ if (MOD__ALT(event)) {
+ if (MOD__SHIFT(event)) {
// FIXME: alt+shift+[] does not work, don't know why
sp_te_adjust_rotation_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, -10);
} else {
@@ -1186,9 +1208,9 @@ gint SPTextContext::root_handler(GdkEvent* event) {
break;
case GDK_KEY_bracketright:
if (tc->text) {
- if (MOD__ALT || MOD__CTRL) {
- if (MOD__ALT) {
- if (MOD__SHIFT) {
+ if (MOD__ALT(event) || MOD__CTRL(event)) {
+ if (MOD__ALT(event)) {
+ if (MOD__SHIFT(event)) {
// FIXME: alt+shift+[] does not work, don't know why
sp_te_adjust_rotation_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, 10);
} else {
@@ -1208,16 +1230,16 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_less:
case GDK_KEY_comma:
if (tc->text) {
- if (MOD__ALT) {
- if (MOD__CTRL) {
- if (MOD__SHIFT)
+ if (MOD__ALT(event)) {
+ if (MOD__CTRL(event)) {
+ if (MOD__SHIFT(event))
sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, -10);
else
sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, -1);
DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:dec", SP_VERB_CONTEXT_TEXT,
_("Contract line spacing"));
} else {
- if (MOD__SHIFT)
+ if (MOD__SHIFT(event))
sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, -10);
else
sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, -1);
@@ -1233,16 +1255,16 @@ gint SPTextContext::root_handler(GdkEvent* event) {
case GDK_KEY_greater:
case GDK_KEY_period:
if (tc->text) {
- if (MOD__ALT) {
- if (MOD__CTRL) {
- if (MOD__SHIFT)
+ if (MOD__ALT(event)) {
+ if (MOD__CTRL(event)) {
+ if (MOD__SHIFT(event))
sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, 10);
else
sp_te_adjust_linespacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, 1);
DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:inc", SP_VERB_CONTEXT_TEXT,
_("Expand line spacing"));
} else {
- if (MOD__SHIFT)
+ if (MOD__SHIFT(event))
sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, 10);
else
sp_te_adjust_tspan_letterspacing_screen(tc->text, tc->text_sel_start, tc->text_sel_end, desktop, 1);
@@ -1260,7 +1282,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
}
if (cursor_moved) {
- if (!MOD__SHIFT)
+ if (!MOD__SHIFT(event))
tc->text_sel_start = tc->text_sel_end;
if (old_start != tc->text_sel_start || old_end != tc->text_sel_end) {
sp_text_context_update_cursor(tc);
@@ -1276,7 +1298,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
group0_keyval == GDK_KEY_Down ||
group0_keyval == GDK_KEY_KP_Up ||
group0_keyval == GDK_KEY_KP_Down )
- && !MOD__CTRL_ONLY) {
+ && !MOD__CTRL_ONLY(event)) {
return TRUE;
} else if (group0_keyval == GDK_KEY_Escape) { // cancel rubberband
if (tc->creating) {
@@ -1287,7 +1309,7 @@ gint SPTextContext::root_handler(GdkEvent* event) {
}
Inkscape::Rubberband::get(desktop)->stop();
}
- } else if ((group0_keyval == GDK_KEY_x || group0_keyval == GDK_KEY_X) && MOD__ALT_ONLY) {
+ } else if ((group0_keyval == GDK_KEY_x || group0_keyval == GDK_KEY_X) && MOD__ALT_ONLY(event)) {
desktop->setToolboxFocusTo ("altx-text");
return TRUE;
}
@@ -1459,7 +1481,7 @@ sp_text_context_selection_changed(Inkscape::Selection *selection, SPTextContext
ec->shape_editor->unset_item(SH_KNOTHOLDER);
SPItem *item = selection->singleItem();
- if (item && SP_IS_FLOWTEXT (item) && SP_FLOWTEXT(item)->has_internal_frame()) {
+ if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
ec->shape_editor->set_item(item, SH_KNOTHOLDER);
}