text-context.cpp revision a6235dd0ae24eff3d072a3baf9448fced32338aa
#define __SP_TEXT_CONTEXT_C__
/*
* SPTextContext
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2005 authors
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gdk/gdkkeysyms.h>
#include <display/sp-ctrlline.h>
#include <display/sodipodi-ctrlrect.h>
#include <display/sp-ctrlquadr.h>
#include <gtk/gtkimmulticontext.h>
#include <gtkmm/clipboard.h>
#include "macros.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "document.h"
#include "sp-namedview.h"
#include "style.h"
#include "selection.h"
#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"
#include "pixmaps/cursor-text-insert.xpm"
#include "object-edit.h"
#include "xml/node-event-vector.h"
#include "prefs-utils.h"
#include "rubberband.h"
#include "sp-metrics.h"
#include "context-fns.h"
#include "text-editing.h"
#include "text-context.h"
static gint sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
static void sp_text_context_selection_modified(Inkscape::Selection *selection, guint flags, SPTextContext *tc);
static SPEventContextClass *parent_class;
{
if (!type) {
sizeof(SPTextContextClass),
sizeof(SPTextContext),
4,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
event_context->xp = 0;
event_context->yp = 0;
event_context->tolerance = 0;
event_context->within_tolerance = false;
tc->nascent_object = 0;
}
static void
{
}
}
if (ec->shape_knot_holder) {
}
ec->shape_repr = 0;
}
}
NULL, /* child_added */
NULL, /* child_removed */
NULL, /* content_changed */
NULL /* order_changed */
};
static void
{
/* im preedit handling is very broken in inkscape for
* multi-byte characters. See bug 1086769.
* We need to let the IM handle the preediting, and
* just take in the characters when they're finished being
* entered.
*/
if (GTK_WIDGET_HAS_FOCUS(canvas)) {
}
}
if (shape_repr) {
}
}
);
);
);
);
ec->enableSelectionCue();
}
ec->enableGrDrag();
}
}
static void
{
ec->enableGrDrag(false);
}
}
}
}
}
}
}
}
static gint
{
case GDK_BUTTON_PRESS:
// find out clicked item, disregarding groups
// find out click point in document coordinates
// set the cursor closest to that point
// update display
}
}
}
break;
case GDK_2BUTTON_PRESS:
if (layout) {
}
}
break;
case GDK_3BUTTON_PRESS:
}
break;
case GDK_BUTTON_RELEASE:
}
break;
case GDK_MOTION_NOTIFY:
if (!layout) break;
// find out click point in document coordinates
// set the cursor closest to that point
// double-click dragging: go by word
} else
// triple-click dragging: go by line
else
}
// update display
}
break;
}
// find out item under mouse, disregarding groups
if (SP_IS_TEXT (item_ungrouped)) {
desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to edit the text, <b>drag</b> to select part of the text."));
} else {
desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to edit the flowed text, <b>drag</b> to select part of the text."));
}
}
break;
default:
break;
}
if (!ret) {
}
return ret;
}
static void
{
/* Create <text> */
/* Set style */
/* Create <tspan> */
/* Create TEXT */
/* fixme: Is selection::changed really immediate? */
/* yes, it's immediate .. why does it matter? */
text_item->transform = SP_ITEM(ec->desktop->currentRoot())->getRelativeTransform(ec->desktop->currentLayer());
text_item->updateRepr();
}
/**
* Insert the character indicated by tc.uni to replace the current selection,
*
*/
static void
{
unsigned int uv;
&& !(g_unichar_validate(static_cast<gunichar>(uv)) && (g_unichar_type(static_cast<gunichar>(uv)) == G_UNICODE_PRIVATE_USE) ) ) {
// This may be due to bad input, so it goes to statusbar.
_("Non-printable character"));
} else {
}
gchar u[10];
u[len] = '\0';
tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, u);
}
}
static void
{
unsigned int uv;
uv = 0xfffd;
}
}
static void
{
char utf8[10];
/* Status bar messages are in pango markup, so we need xml escaping. */
switch(utf8[0]) {
default: break;
}
}
} else {
}
}
static gint
{
case GDK_BUTTON_PRESS:
return TRUE;
}
// save drag origin
ec->within_tolerance = true;
/* Processed */
return TRUE;
}
break;
case GDK_MOTION_NOTIFY:
// update cursor and statusbar: we are not over a text object now
}
if ( ec->within_tolerance
break; // do not drag if we're within tolerance from origin
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to draw, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
ec->within_tolerance = false;
// status text
GString *xs = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[NR::X]), desktop->namedview->getDefaultMetric());
GString *ys = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[NR::Y]), desktop->namedview->getDefaultMetric());
ec->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>Flowed text frame</b>: %s × %s"), xs->str, ys->str);
}
break;
case GDK_BUTTON_RELEASE:
}
/* Button 1, set X & Y & new item */
/* Cursor */
// Cursor height is defined by the new text object's font size; it needs to be set
// articifically here, for the text object does not exist yet:
ec->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Type text; <b>Enter</b> to start new line.")); // FIXME:: this is a copy of a string from _update_cursor below, do not desync
ec->within_tolerance = false;
// otherwise even one line won't fit; most probably a slip of hand (even if bigger than tolerance)
} else {
ec->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The frame is <b>too small</b> for the current font size. Flowed text not created."));
}
}
return TRUE;
}
break;
case GDK_KEY_PRESS: {
if (group0_keyval == GDK_KP_Add ||
group0_keyval == GDK_KP_Subtract) {
break; // otherwise pass on keypad +/- so they can zoom
}
// there is an active text object in this context, or a new object was just created
// but we have our own so make sure they don't swallow it
//IM did not consume the key, or we're in 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
reasonable (viz. hope that the user's keyboard includes latin
characters and force latin interpretation -- just as we do for our
keyboard shortcuts), but differs from the ISO 14755
recommendation. */
switch (group0_keyval) {
case GDK_space:
case GDK_KP_Space: {
}
/* Stay in unimode. */
return TRUE;
}
case GDK_BackSpace: {
}
return TRUE;
}
case GDK_Return:
case GDK_KP_Enter: {
}
/* Exit unimode. */
return TRUE;
}
case GDK_Escape: {
// Cancel unimode.
return TRUE;
}
case GDK_Shift_L:
case GDK_Shift_R:
break;
default: {
if (g_ascii_isxdigit(group0_keyval)) {
/* This behaviour is partly to allow us to continue to
use a fixed-length buffer for tc->uni. Reason for
choosing the number 8 is that it's the length of
``canonical form'' mentioned in the ISO 14755 spec.
An advantage over choosing 6 is that it allows using
backspace for typos & misremembering when entering a
6-digit number. */
}
return TRUE;
} else {
/* The intent is to ignore but consume characters that could be
typos for hex digits. Gtk seems to ignore & consume all
non-hex-digits, and we do similar here. Though note that some
shortcuts (like keypad +/- for zoom) get processed before
reaching this code. */
return TRUE;
}
}
}
}
/* Neither unimode nor IM consumed key; process text tool shortcuts */
switch (group0_keyval) {
case GDK_space:
if (MOD__CTRL_ONLY) {
/* No-break space */
}
tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, "\302\240");
return TRUE;
}
break;
case GDK_U:
case GDK_u:
if (MOD__CTRL_ONLY) {
} else {
}
}
return TRUE;
}
break;
case GDK_B:
case GDK_b:
SPStyle const *style = sp_te_style_at_position(tc->text, std::min(tc->text_sel_start, tc->text_sel_end));
else
return TRUE;
}
break;
case GDK_I:
case GDK_i:
SPStyle const *style = sp_te_style_at_position(tc->text, std::min(tc->text_sel_start, tc->text_sel_end));
else
return TRUE;
}
break;
case GDK_A:
case GDK_a:
if (layout) {
return TRUE;
}
}
break;
case GDK_Return:
case GDK_KP_Enter:
}
tc->text_sel_start = tc->text_sel_end = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end);
return TRUE;
case GDK_BackSpace:
if (tc->text) { // if nascent_object, do nothing, but return TRUE; same for all other delete and move keys
tc->text_sel_start = tc->text_sel_end = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end);
}
return TRUE;
case GDK_Delete:
case GDK_KP_Delete:
tc->text_sel_start = tc->text_sel_end = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end);
}
return TRUE;
case GDK_Left:
case GDK_KP_Left:
case GDK_KP_4:
if (MOD__ALT) {
if (MOD__SHIFT)
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(-10, 0));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(-1, 0));
} else {
break;
}
}
return TRUE;
case GDK_Right:
case GDK_KP_Right:
case GDK_KP_6:
if (MOD__ALT) {
if (MOD__SHIFT)
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(10, 0));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(1, 0));
} else {
break;
}
}
return TRUE;
case GDK_Up:
case GDK_KP_Up:
case GDK_KP_8:
if (MOD__ALT) {
if (MOD__SHIFT)
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(0, -10));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(0, -1));
} else {
break;
}
}
return TRUE;
case GDK_Down:
case GDK_KP_Down:
case GDK_KP_2:
if (MOD__ALT) {
if (MOD__SHIFT)
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(0, 10));
else
sp_te_adjust_kerning_screen(tc->text, tc->text_sel_start, tc->text_sel_end, ec->desktop, NR::Point(0, 1));
} else {
break;
}
}
return TRUE;
case GDK_Home:
case GDK_KP_Home:
if (MOD__CTRL)
else
break;
}
return TRUE;
case GDK_End:
case GDK_KP_End:
if (MOD__CTRL)
else
break;
}
return TRUE;
case GDK_Escape:
}
} else {
}
return TRUE;
case GDK_bracketleft:
if (MOD__ALT) {
if (MOD__SHIFT) {
// FIXME: alt+shift+[] does not work, don't know why
} else {
}
} else {
}
return TRUE;
}
}
break;
case GDK_bracketright:
if (MOD__ALT) {
if (MOD__SHIFT) {
// FIXME: alt+shift+[] does not work, don't know why
} else {
}
} else {
}
return TRUE;
}
}
break;
case GDK_less:
case GDK_comma:
if (MOD__ALT) {
if (MOD__CTRL) {
if (MOD__SHIFT)
else
} 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);
}
return TRUE;
}
}
break;
case GDK_greater:
case GDK_period:
if (MOD__ALT) {
if (MOD__CTRL) {
if (MOD__SHIFT)
else
} 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);
}
return TRUE;
}
}
break;
default:
break;
}
if (cursor_movement_operator) {
if (!MOD__SHIFT)
}
return TRUE;
}
} else return TRUE; // return the "I took care of it" value if it was consumed by the IM
} else { // do nothing if there's no object to type in - the key will be sent to parent context,
if ((group0_keyval == GDK_Up ||
group0_keyval == GDK_Down ||
group0_keyval == GDK_KP_Up ||
group0_keyval == GDK_KP_Down )
&& !MOD__CTRL_ONLY) {
return TRUE;
}
}
}
}
break;
}
case GDK_KEY_RELEASE:
return TRUE;
}
break;
default:
break;
}
// if nobody consumed it so far
if (((SPEventContextClass *) parent_class)->root_handler) { // and there's a handler in parent context,
} else {
return FALSE; // return "I did nothing" value so that global shortcuts can be activated
}
}
/**
Attempts to paste system clipboard into the currently edited text, returns true on success
*/
bool
{
if (!SP_IS_TEXT_CONTEXT(ec))
return false;
// there is an active text object in this context, or a new object was just created
}
// using indices is slow in ustrings. Whatever.
for ( ; ; ) {
tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, text.substr(begin).c_str());
break;
}
tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, text.substr(begin, end - begin).c_str());
}
return true;
}
} // FIXME: else create and select a new object under cursor!
return false;
}
/**
Gets the raw characters that comprise the currently selected text, converting line
breaks into lf characters.
*/
{
if (!SP_IS_TEXT_CONTEXT(ec))
return "";
return "";
}
/**
Deletes the currently selected characters. Returns false if there is no
text selection currently.
*/
{
if (!SP_IS_TEXT_CONTEXT(ec))
return false;
return false;
return false;
tc->text_sel_start = tc->text_sel_end = sp_te_delete(tc->text, tc->text_sel_start, tc->text_sel_end);
return true;
}
/**
* \param selection Should not be NULL.
*/
static void
{
}
ec->shape_repr = 0;
}
if (shape_repr) {
}
}
}
if (layout)
} else {
}
// we update cursor without scrolling, because this position may not be final;
// item_handler moves cusros to the point of click immediately
sp_text_context_update_cursor(tc, false);
}
static void
{
}
static bool
{
return false;
return false; // will get picked up by the parent and applied to the whole text object
return true;
}
static int
{
return QUERY_STYLE_NOTHING;
return QUERY_STYLE_NOTHING;
} else {
}
if (!begin_it.prevCharacter())
}
return result;
}
static void
{
return;
if (layout) { // undo can change the text length without us knowing it
}
}
static void
{
// scroll to show cursor
if (scroll_to_see) {
// unlike mouse moves, here we must scroll all the way at first shot, so we override the autoscrollspeed
}
/* fixme: ... need another transformation to get canvas widget coordinate space? */
if (frame) {
}
SP_EVENT_CONTEXT(tc)->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Type flowed text; <b>Enter</b> to start new paragraph."));
} else {
SP_EVENT_CONTEXT(tc)->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Type text; <b>Enter</b> to start new line."));
}
} else {
if (!tc->nascent_object) {
SP_EVENT_CONTEXT(tc)->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to select or create text, <b>drag</b> to create flowed text; then type.")); // FIXME: this is a copy of string from tools-switch, do not desync
}
}
}
}
{
for (std::vector<SPCanvasItem*>::iterator it = tc->text_selection_quads.begin() ; it != tc->text_selection_quads.end() ; it++) {
}
quads = sp_te_create_selection_quads(tc->text, tc->text_sel_start, tc->text_sel_end, sp_item_i2d_affine(tc->text));
sp_ctrlquadr_set_coords(SP_CTRLQUADR(quad_canvasitem), quads[i], quads[i+1], quads[i+2], quads[i+3]);
}
}
static gint
{
} else {
}
}
return TRUE;
}
static void
{
/* We have to set it to zero,
* or selection changed signal messes everything up */
// the repr may already have been unparented
// if we were called e.g. as the result of
// an undo or the element being removed from
// the XML editor
}
}
}
{
return FALSE;
}
{
return FALSE;
}
static void
{
}
tc->text_sel_start = tc->text_sel_end = sp_te_replace(tc->text, tc->text_sel_start, tc->text_sel_end, string);
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :