2010-02-18 04:23:15 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GimpTextTool
|
2010-02-18 04:39:33 +08:00
|
|
|
* Copyright (C) 2002-2010 Sven Neumann <sven@gimp.org>
|
|
|
|
* Daniel Eddeland <danedde@svn.gnome.org>
|
|
|
|
* Michael Natterer <mitch@gimp.org>
|
2010-02-18 04:23:15 +08:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
2010-03-02 07:12:27 +08:00
|
|
|
#include "core/gimp.h"
|
2010-02-28 21:20:56 +08:00
|
|
|
#include "core/gimpimage.h"
|
2011-03-18 19:58:32 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2010-02-28 21:20:56 +08:00
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
#include "text/gimptext.h"
|
|
|
|
#include "text/gimptextlayout.h"
|
|
|
|
|
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2016-11-25 20:26:08 +08:00
|
|
|
#include "widgets/gimpdockcontainer.h"
|
2010-02-24 08:36:10 +08:00
|
|
|
#include "widgets/gimpoverlaybox.h"
|
2010-06-13 05:49:55 +08:00
|
|
|
#include "widgets/gimpoverlayframe.h"
|
2010-02-26 00:41:10 +08:00
|
|
|
#include "widgets/gimptextbuffer.h"
|
2010-02-18 04:23:15 +08:00
|
|
|
#include "widgets/gimptexteditor.h"
|
|
|
|
#include "widgets/gimptextproxy.h"
|
2010-02-26 08:36:31 +08:00
|
|
|
#include "widgets/gimptextstyleeditor.h"
|
2014-05-02 09:01:23 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
2014-10-01 06:26:48 +08:00
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
#include "gimptextoptions.h"
|
|
|
|
#include "gimptexttool.h"
|
|
|
|
#include "gimptexttool-editor.h"
|
|
|
|
|
2010-02-18 16:39:25 +08:00
|
|
|
#include "gimp-log.h"
|
2010-02-18 04:23:15 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2015-06-23 04:52:33 +08:00
|
|
|
static void gimp_text_tool_ensure_proxy (GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_move_cursor (GimpTextTool *text_tool,
|
|
|
|
GtkMovementStep step,
|
|
|
|
gint count,
|
|
|
|
gboolean extend_selection);
|
|
|
|
static void gimp_text_tool_insert_at_cursor (GimpTextTool *text_tool,
|
|
|
|
const gchar *str);
|
|
|
|
static void gimp_text_tool_delete_from_cursor (GimpTextTool *text_tool,
|
|
|
|
GtkDeleteType type,
|
|
|
|
gint count);
|
|
|
|
static void gimp_text_tool_backspace (GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_toggle_overwrite (GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_select_all (GimpTextTool *text_tool,
|
|
|
|
gboolean select);
|
|
|
|
static void gimp_text_tool_change_size (GimpTextTool *text_tool,
|
|
|
|
gdouble amount);
|
|
|
|
static void gimp_text_tool_change_baseline (GimpTextTool *text_tool,
|
|
|
|
gdouble amount);
|
|
|
|
static void gimp_text_tool_change_kerning (GimpTextTool *text_tool,
|
|
|
|
gdouble amount);
|
|
|
|
|
|
|
|
static void gimp_text_tool_options_notify (GimpTextOptions *options,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_editor_dialog (GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_editor_destroy (GtkWidget *dialog,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_enter_text (GimpTextTool *text_tool,
|
|
|
|
const gchar *str);
|
|
|
|
static void gimp_text_tool_xy_to_iter (GimpTextTool *text_tool,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkTextIter *iter);
|
|
|
|
|
2016-06-05 22:23:50 +08:00
|
|
|
static void gimp_text_tool_im_preedit_start (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool);
|
2015-06-23 04:52:33 +08:00
|
|
|
static void gimp_text_tool_im_preedit_end (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_im_preedit_changed (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static void gimp_text_tool_im_commit (GtkIMContext *context,
|
|
|
|
const gchar *str,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static gboolean gimp_text_tool_im_retrieve_surrounding
|
|
|
|
(GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static gboolean gimp_text_tool_im_delete_surrounding
|
|
|
|
(GtkIMContext *context,
|
|
|
|
gint offset,
|
|
|
|
gint n_chars,
|
|
|
|
GimpTextTool *text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2016-06-05 06:04:01 +08:00
|
|
|
static void gimp_text_tool_im_delete_preedit (GimpTextTool *text_tool);
|
|
|
|
|
2016-07-16 22:28:35 +08:00
|
|
|
static void gimp_text_tool_editor_copy_selection_to_clipboard
|
|
|
|
(GimpTextTool *text_tool);
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_tool_editor_init (GimpTextTool *text_tool)
|
|
|
|
{
|
2010-02-18 16:51:45 +08:00
|
|
|
text_tool->im_context = gtk_im_multicontext_new ();
|
|
|
|
text_tool->needs_im_reset = FALSE;
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
text_tool->preedit_string = NULL;
|
2010-02-18 16:51:45 +08:00
|
|
|
text_tool->preedit_cursor = 0;
|
2010-02-18 04:23:15 +08:00
|
|
|
text_tool->overwrite_mode = FALSE;
|
2010-02-18 16:51:45 +08:00
|
|
|
text_tool->x_pos = -1;
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2016-06-05 22:23:50 +08:00
|
|
|
g_signal_connect (text_tool->im_context, "preedit-start",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_preedit_start),
|
|
|
|
text_tool);
|
2010-02-20 22:13:14 +08:00
|
|
|
g_signal_connect (text_tool->im_context, "preedit-end",
|
2010-02-21 06:33:58 +08:00
|
|
|
G_CALLBACK (gimp_text_tool_im_preedit_end),
|
2010-02-20 22:13:14 +08:00
|
|
|
text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
g_signal_connect (text_tool->im_context, "preedit-changed",
|
2010-02-21 06:33:58 +08:00
|
|
|
G_CALLBACK (gimp_text_tool_im_preedit_changed),
|
2010-02-18 04:23:15 +08:00
|
|
|
text_tool);
|
2015-06-23 04:52:33 +08:00
|
|
|
g_signal_connect (text_tool->im_context, "commit",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_commit),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "retrieve-surrounding",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_retrieve_surrounding),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "delete-surrounding",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_delete_surrounding),
|
|
|
|
text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_tool_editor_finalize (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
if (text_tool->im_context)
|
|
|
|
{
|
|
|
|
g_object_unref (text_tool->im_context);
|
|
|
|
text_tool->im_context = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_tool_editor_start (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
|
|
|
|
gtk_im_context_set_client_window (text_tool->im_context,
|
|
|
|
gtk_widget_get_window (shell->canvas));
|
|
|
|
|
2010-02-19 23:05:48 +08:00
|
|
|
text_tool->needs_im_reset = TRUE;
|
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
gtk_im_context_focus_in (text_tool->im_context);
|
|
|
|
|
|
|
|
if (options->use_editor)
|
|
|
|
gimp_text_tool_editor_dialog (text_tool);
|
|
|
|
|
|
|
|
g_signal_connect (options, "notify::use-editor",
|
|
|
|
G_CALLBACK (gimp_text_tool_options_notify),
|
|
|
|
text_tool);
|
2010-02-26 08:36:31 +08:00
|
|
|
|
|
|
|
if (! text_tool->style_overlay)
|
|
|
|
{
|
2010-03-02 07:12:27 +08:00
|
|
|
Gimp *gimp = GIMP_CONTEXT (options)->gimp;
|
|
|
|
gdouble xres = 1.0;
|
|
|
|
gdouble yres = 1.0;
|
2010-02-28 21:20:56 +08:00
|
|
|
|
2010-06-13 05:49:55 +08:00
|
|
|
text_tool->style_overlay = gimp_overlay_frame_new ();
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (text_tool->style_overlay),
|
|
|
|
4);
|
2010-02-26 08:36:31 +08:00
|
|
|
gimp_display_shell_add_overlay (shell,
|
|
|
|
text_tool->style_overlay,
|
2010-02-28 21:48:47 +08:00
|
|
|
0, 0,
|
2010-10-19 02:13:09 +08:00
|
|
|
GIMP_HANDLE_ANCHOR_CENTER, 0, 0);
|
2010-02-26 08:36:31 +08:00
|
|
|
gimp_overlay_box_set_child_opacity (GIMP_OVERLAY_BOX (shell->canvas),
|
|
|
|
text_tool->style_overlay, 0.7);
|
|
|
|
|
2010-02-28 21:20:56 +08:00
|
|
|
if (text_tool->image)
|
|
|
|
gimp_image_get_resolution (text_tool->image, &xres, &yres);
|
|
|
|
|
2010-03-02 07:12:27 +08:00
|
|
|
text_tool->style_editor = gimp_text_style_editor_new (gimp,
|
2011-03-19 04:16:53 +08:00
|
|
|
text_tool->proxy,
|
2010-03-02 07:12:27 +08:00
|
|
|
text_tool->buffer,
|
|
|
|
gimp->fonts,
|
2010-02-28 21:20:56 +08:00
|
|
|
xres, yres);
|
2010-02-26 08:36:31 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (text_tool->style_overlay),
|
|
|
|
text_tool->style_editor);
|
|
|
|
gtk_widget_show (text_tool->style_editor);
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:10:03 +08:00
|
|
|
gimp_text_tool_editor_position (text_tool);
|
2010-02-26 08:36:31 +08:00
|
|
|
gtk_widget_show (text_tool->style_overlay);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
|
2010-02-26 09:10:03 +08:00
|
|
|
void
|
|
|
|
gimp_text_tool_editor_position (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
if (text_tool->style_overlay)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
GtkRequisition requisition;
|
2017-06-28 21:40:38 +08:00
|
|
|
gdouble x, y;
|
2010-02-26 09:10:03 +08:00
|
|
|
|
|
|
|
gtk_widget_size_request (text_tool->style_overlay, &requisition);
|
|
|
|
|
2017-06-28 21:40:38 +08:00
|
|
|
g_object_get (text_tool->widget,
|
2010-02-26 09:10:03 +08:00
|
|
|
"x1", &x,
|
|
|
|
"y1", &y,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_display_shell_move_overlay (shell,
|
|
|
|
text_tool->style_overlay,
|
2010-02-28 21:48:47 +08:00
|
|
|
x, y,
|
2010-10-19 02:13:09 +08:00
|
|
|
GIMP_HANDLE_ANCHOR_SOUTH_WEST, 4, 12);
|
2010-02-28 21:20:56 +08:00
|
|
|
|
|
|
|
if (text_tool->image)
|
|
|
|
{
|
|
|
|
gdouble xres, yres;
|
|
|
|
|
|
|
|
gimp_image_get_resolution (text_tool->image, &xres, &yres);
|
|
|
|
|
|
|
|
g_object_set (text_tool->style_editor,
|
|
|
|
"resolution-x", xres,
|
|
|
|
"resolution-y", yres,
|
|
|
|
NULL);
|
|
|
|
}
|
2010-02-26 09:10:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
void
|
|
|
|
gimp_text_tool_editor_halt (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
|
|
|
|
|
2010-02-26 08:36:31 +08:00
|
|
|
if (text_tool->style_overlay)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (text_tool->style_overlay);
|
|
|
|
text_tool->style_overlay = NULL;
|
|
|
|
text_tool->style_editor = NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
gimp_text_tool_options_notify,
|
|
|
|
text_tool);
|
|
|
|
|
2010-02-18 16:51:45 +08:00
|
|
|
if (text_tool->editor_dialog)
|
2010-02-22 01:59:51 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (text_tool->editor_dialog,
|
|
|
|
gimp_text_tool_editor_destroy,
|
|
|
|
text_tool);
|
|
|
|
gtk_widget_destroy (text_tool->editor_dialog);
|
|
|
|
}
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
if (text_tool->proxy_text_view)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (text_tool->offscreen_window);
|
|
|
|
text_tool->offscreen_window = NULL;
|
|
|
|
text_tool->proxy_text_view = NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-19 23:05:48 +08:00
|
|
|
text_tool->needs_im_reset = TRUE;
|
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
gtk_im_context_focus_out (text_tool->im_context);
|
|
|
|
|
|
|
|
gtk_im_context_set_client_window (text_tool->im_context, NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-21 06:19:10 +08:00
|
|
|
void
|
|
|
|
gimp_text_tool_editor_button_press (GimpTextTool *text_tool,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GimpButtonPressType press_type)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-02-21 06:19:10 +08:00
|
|
|
GtkTextIter cursor;
|
|
|
|
GtkTextIter selection;
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
gimp_text_tool_xy_to_iter (text_tool, x, y, &cursor);
|
2010-02-21 06:19:10 +08:00
|
|
|
|
|
|
|
selection = cursor;
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
text_tool->select_start_iter = cursor;
|
|
|
|
text_tool->select_words = FALSE;
|
|
|
|
text_tool->select_lines = FALSE;
|
2010-02-21 06:19:10 +08:00
|
|
|
|
|
|
|
switch (press_type)
|
|
|
|
{
|
2016-06-29 00:15:52 +08:00
|
|
|
GtkTextIter start, end;
|
|
|
|
|
2010-02-21 06:19:10 +08:00
|
|
|
case GIMP_BUTTON_PRESS_NORMAL:
|
2016-06-29 00:15:52 +08:00
|
|
|
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end) ||
|
|
|
|
gtk_text_iter_compare (&start, &cursor))
|
|
|
|
gtk_text_buffer_place_cursor (buffer, &cursor);
|
2010-02-21 06:19:10 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BUTTON_PRESS_DOUBLE:
|
|
|
|
text_tool->select_words = TRUE;
|
|
|
|
|
|
|
|
if (! gtk_text_iter_starts_word (&cursor))
|
|
|
|
gtk_text_iter_backward_visible_word_starts (&cursor, 1);
|
|
|
|
|
|
|
|
if (! gtk_text_iter_ends_word (&selection) &&
|
|
|
|
! gtk_text_iter_forward_visible_word_ends (&selection, 1))
|
|
|
|
gtk_text_iter_forward_to_line_end (&selection);
|
|
|
|
|
|
|
|
gtk_text_buffer_select_range (buffer, &cursor, &selection);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BUTTON_PRESS_TRIPLE:
|
|
|
|
text_tool->select_lines = TRUE;
|
|
|
|
|
|
|
|
gtk_text_iter_set_line_offset (&cursor, 0);
|
|
|
|
gtk_text_iter_forward_to_line_end (&selection);
|
|
|
|
|
|
|
|
gtk_text_buffer_select_range (buffer, &cursor, &selection);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_tool_editor_button_release (GimpTextTool *text_tool)
|
|
|
|
{
|
2016-07-16 22:28:35 +08:00
|
|
|
gimp_text_tool_editor_copy_selection_to_clipboard (text_tool);
|
2010-02-21 06:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_tool_editor_motion (GimpTextTool *text_tool,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-03-02 19:23:29 +08:00
|
|
|
GtkTextIter old_cursor;
|
|
|
|
GtkTextIter old_selection;
|
2010-02-21 06:19:10 +08:00
|
|
|
GtkTextIter cursor;
|
|
|
|
GtkTextIter selection;
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &old_cursor,
|
2010-02-21 06:19:10 +08:00
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2010-03-02 19:23:29 +08:00
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &old_selection,
|
2010-02-21 06:19:10 +08:00
|
|
|
gtk_text_buffer_get_selection_bound (buffer));
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
gimp_text_tool_xy_to_iter (text_tool, x, y, &cursor);
|
|
|
|
selection = text_tool->select_start_iter;
|
2010-02-21 06:19:10 +08:00
|
|
|
|
|
|
|
if (text_tool->select_words ||
|
|
|
|
text_tool->select_lines)
|
|
|
|
{
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
if (gtk_text_iter_compare (&cursor, &selection) < 0)
|
2010-02-21 06:19:10 +08:00
|
|
|
{
|
|
|
|
start = cursor;
|
|
|
|
end = selection;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = selection;
|
|
|
|
end = cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text_tool->select_words)
|
|
|
|
{
|
|
|
|
if (! gtk_text_iter_starts_word (&start))
|
|
|
|
gtk_text_iter_backward_visible_word_starts (&start, 1);
|
|
|
|
|
|
|
|
if (! gtk_text_iter_ends_word (&end) &&
|
|
|
|
! gtk_text_iter_forward_visible_word_ends (&end, 1))
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
}
|
|
|
|
else if (text_tool->select_lines)
|
|
|
|
{
|
|
|
|
gtk_text_iter_set_line_offset (&start, 0);
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
}
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
if (gtk_text_iter_compare (&cursor, &selection) < 0)
|
2010-02-21 06:19:10 +08:00
|
|
|
{
|
|
|
|
cursor = start;
|
|
|
|
selection = end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selection = start;
|
|
|
|
cursor = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
if (! gtk_text_iter_equal (&cursor, &old_cursor) ||
|
|
|
|
! gtk_text_iter_equal (&selection, &old_selection))
|
2010-02-21 06:19:10 +08:00
|
|
|
{
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
|
|
|
|
gtk_text_buffer_select_range (buffer, &cursor, &selection);
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
gboolean
|
|
|
|
gimp_text_tool_editor_key_press (GimpTextTool *text_tool,
|
2010-02-21 06:19:10 +08:00
|
|
|
GdkEventKey *kevent)
|
2010-02-18 04:23:15 +08:00
|
|
|
{
|
2012-11-10 05:06:51 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter cursor;
|
|
|
|
GtkTextIter selection;
|
|
|
|
gboolean retval = TRUE;
|
|
|
|
|
|
|
|
if (! gtk_widget_has_focus (shell->canvas))
|
|
|
|
{
|
|
|
|
/* The focus is in the floating style editor, and the event
|
|
|
|
* was not handled there, focus the canvas.
|
|
|
|
*/
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_KEY_Tab:
|
|
|
|
case GDK_KEY_KP_Tab:
|
|
|
|
case GDK_KEY_ISO_Left_Tab:
|
|
|
|
case GDK_KEY_Escape:
|
|
|
|
gtk_widget_grab_focus (shell->canvas);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
if (gtk_im_context_filter_keypress (text_tool->im_context, kevent))
|
|
|
|
{
|
|
|
|
text_tool->needs_im_reset = TRUE;
|
|
|
|
text_tool->x_pos = -1;
|
|
|
|
|
2012-11-10 05:06:51 +08:00
|
|
|
return TRUE;
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_text_tool_ensure_proxy (text_tool);
|
|
|
|
|
|
|
|
if (gtk_bindings_activate_event (GTK_OBJECT (text_tool->proxy_text_view),
|
|
|
|
kevent))
|
|
|
|
{
|
2010-02-18 16:39:25 +08:00
|
|
|
GIMP_LOG (TEXT_EDITING, "binding handled event");
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &selection,
|
|
|
|
gtk_text_buffer_get_selection_bound (buffer));
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Return:
|
|
|
|
case GDK_KEY_KP_Enter:
|
|
|
|
case GDK_KEY_ISO_Enter:
|
2010-02-18 04:23:15 +08:00
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
2010-02-19 23:05:48 +08:00
|
|
|
gimp_text_tool_enter_text (text_tool, "\n");
|
2010-02-18 04:23:15 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Tab:
|
|
|
|
case GDK_KEY_KP_Tab:
|
|
|
|
case GDK_KEY_ISO_Left_Tab:
|
2010-02-18 04:23:15 +08:00
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
2010-02-19 23:05:48 +08:00
|
|
|
gimp_text_tool_enter_text (text_tool, "\t");
|
2010-02-18 04:23:15 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Escape:
|
2010-02-18 04:23:15 +08:00
|
|
|
gimp_tool_control (GIMP_TOOL (text_tool), GIMP_TOOL_ACTION_HALT,
|
|
|
|
GIMP_TOOL (text_tool)->display);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
retval = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-10 05:06:51 +08:00
|
|
|
text_tool->x_pos = -1;
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-19 03:50:37 +08:00
|
|
|
gboolean
|
|
|
|
gimp_text_tool_editor_key_release (GimpTextTool *text_tool,
|
2010-02-21 06:19:10 +08:00
|
|
|
GdkEventKey *kevent)
|
2010-02-19 03:50:37 +08:00
|
|
|
{
|
|
|
|
if (gtk_im_context_filter_keypress (text_tool->im_context, kevent))
|
|
|
|
{
|
|
|
|
text_tool->needs_im_reset = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_text_tool_ensure_proxy (text_tool);
|
|
|
|
|
|
|
|
if (gtk_bindings_activate_event (GTK_OBJECT (text_tool->proxy_text_view),
|
|
|
|
kevent))
|
|
|
|
{
|
|
|
|
GIMP_LOG (TEXT_EDITING, "binding handled event");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-02-19 23:05:48 +08:00
|
|
|
void
|
|
|
|
gimp_text_tool_reset_im_context (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
if (text_tool->needs_im_reset)
|
|
|
|
{
|
|
|
|
text_tool->needs_im_reset = FALSE;
|
|
|
|
gtk_im_context_reset (text_tool->im_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 22:23:50 +08:00
|
|
|
void
|
|
|
|
gimp_text_tool_abort_im_context (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
|
|
|
|
text_tool->needs_im_reset = TRUE;
|
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
|
|
|
|
2016-06-06 20:28:55 +08:00
|
|
|
/* Making sure preedit text is removed. */
|
|
|
|
gimp_text_tool_im_delete_preedit (text_tool);
|
|
|
|
|
2016-06-05 22:23:50 +08:00
|
|
|
/* the following lines seem to be the only way of really getting
|
|
|
|
* rid of any ongoing preedit state, please somebody tell me
|
|
|
|
* a clean way... mitch
|
|
|
|
*/
|
|
|
|
|
|
|
|
gtk_im_context_focus_out (text_tool->im_context);
|
|
|
|
gtk_im_context_set_client_window (text_tool->im_context, NULL);
|
|
|
|
|
2016-06-06 20:51:15 +08:00
|
|
|
g_object_unref (text_tool->im_context);
|
|
|
|
text_tool->im_context = gtk_im_multicontext_new ();
|
2016-06-05 22:23:50 +08:00
|
|
|
gtk_im_context_set_client_window (text_tool->im_context,
|
|
|
|
gtk_widget_get_window (shell->canvas));
|
|
|
|
gtk_im_context_focus_in (text_tool->im_context);
|
2016-06-06 20:51:15 +08:00
|
|
|
g_signal_connect (text_tool->im_context, "preedit-start",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_preedit_start),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "preedit-end",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_preedit_end),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "preedit-changed",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_preedit_changed),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "commit",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_commit),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "retrieve-surrounding",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_retrieve_surrounding),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect (text_tool->im_context, "delete-surrounding",
|
|
|
|
G_CALLBACK (gimp_text_tool_im_delete_surrounding),
|
|
|
|
text_tool);
|
2016-06-05 22:23:50 +08:00
|
|
|
}
|
|
|
|
|
2010-02-20 22:13:14 +08:00
|
|
|
void
|
|
|
|
gimp_text_tool_editor_get_cursor_rect (GimpTextTool *text_tool,
|
2010-10-14 08:45:32 +08:00
|
|
|
gboolean overwrite,
|
2010-03-07 07:11:05 +08:00
|
|
|
PangoRectangle *cursor_rect)
|
2010-02-18 04:39:33 +08:00
|
|
|
{
|
2010-03-07 07:11:05 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
PangoLayout *layout;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
GtkTextIter cursor;
|
|
|
|
gint cursor_index;
|
2010-02-18 04:39:33 +08:00
|
|
|
|
2010-02-20 22:13:14 +08:00
|
|
|
g_return_if_fail (GIMP_IS_TEXT_TOOL (text_tool));
|
|
|
|
g_return_if_fail (cursor_rect != NULL);
|
2010-02-18 04:39:33 +08:00
|
|
|
|
2010-02-20 22:13:14 +08:00
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2010-03-01 23:27:34 +08:00
|
|
|
cursor_index = gimp_text_buffer_get_iter_index (text_tool->buffer, &cursor,
|
|
|
|
TRUE);
|
2010-02-18 04:39:33 +08:00
|
|
|
|
2010-03-07 07:11:05 +08:00
|
|
|
gimp_text_tool_ensure_layout (text_tool);
|
|
|
|
|
|
|
|
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
|
|
|
|
|
|
|
|
gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
|
|
|
|
|
2010-10-14 08:45:32 +08:00
|
|
|
if (overwrite)
|
|
|
|
pango_layout_index_to_pos (layout, cursor_index, cursor_rect);
|
|
|
|
else
|
|
|
|
pango_layout_get_cursor_pos (layout, cursor_index, cursor_rect, NULL);
|
|
|
|
|
2010-02-20 22:13:14 +08:00
|
|
|
gimp_text_layout_transform_rect (text_tool->layout, cursor_rect);
|
2010-02-18 04:39:33 +08:00
|
|
|
|
2010-03-07 07:11:05 +08:00
|
|
|
cursor_rect->x = PANGO_PIXELS (cursor_rect->x) + offset_x;
|
|
|
|
cursor_rect->y = PANGO_PIXELS (cursor_rect->y) + offset_y;
|
2010-02-20 22:13:14 +08:00
|
|
|
cursor_rect->width = PANGO_PIXELS (cursor_rect->width);
|
|
|
|
cursor_rect->height = PANGO_PIXELS (cursor_rect->height);
|
2010-02-18 04:39:33 +08:00
|
|
|
}
|
|
|
|
|
2014-10-01 06:26:48 +08:00
|
|
|
void
|
2016-04-16 21:12:42 +08:00
|
|
|
gimp_text_tool_editor_update_im_cursor (GimpTextTool *text_tool)
|
2014-10-01 06:26:48 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
PangoRectangle rect = { 0, };
|
2017-06-28 21:40:38 +08:00
|
|
|
gdouble off_x, off_y;
|
2014-10-01 06:26:48 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_TEXT_TOOL (text_tool));
|
|
|
|
|
|
|
|
shell = gimp_display_get_shell (GIMP_TOOL (text_tool)->display);
|
|
|
|
|
|
|
|
if (text_tool->text)
|
|
|
|
gimp_text_tool_editor_get_cursor_rect (text_tool,
|
|
|
|
text_tool->overwrite_mode,
|
|
|
|
&rect);
|
|
|
|
|
2017-06-28 21:40:38 +08:00
|
|
|
g_object_get (text_tool->widget,
|
|
|
|
"x1", &off_x,
|
|
|
|
"y1", &off_y,
|
|
|
|
NULL);
|
|
|
|
|
2014-10-01 06:26:48 +08:00
|
|
|
rect.x += off_x;
|
|
|
|
rect.y += off_y;
|
|
|
|
|
|
|
|
gimp_display_shell_transform_xy (shell, rect.x, rect.y, &rect.x, &rect.y);
|
|
|
|
|
|
|
|
gtk_im_context_set_cursor_location (text_tool->im_context,
|
|
|
|
(GdkRectangle *) &rect);
|
|
|
|
}
|
|
|
|
|
2010-02-18 04:39:33 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_ensure_proxy (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
|
|
|
|
if (text_tool->offscreen_window &&
|
|
|
|
gtk_widget_get_screen (text_tool->offscreen_window) !=
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (shell)))
|
|
|
|
{
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (text_tool->offscreen_window),
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (shell)));
|
|
|
|
gtk_window_move (GTK_WINDOW (text_tool->offscreen_window), -200, -200);
|
|
|
|
}
|
|
|
|
else if (! text_tool->offscreen_window)
|
|
|
|
{
|
|
|
|
text_tool->offscreen_window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (text_tool->offscreen_window),
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (shell)));
|
|
|
|
gtk_window_move (GTK_WINDOW (text_tool->offscreen_window), -200, -200);
|
|
|
|
gtk_widget_show (text_tool->offscreen_window);
|
|
|
|
|
|
|
|
text_tool->proxy_text_view = gimp_text_proxy_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (text_tool->offscreen_window),
|
|
|
|
text_tool->proxy_text_view);
|
|
|
|
gtk_widget_show (text_tool->proxy_text_view);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "move-cursor",
|
|
|
|
G_CALLBACK (gimp_text_tool_move_cursor),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "insert-at-cursor",
|
|
|
|
G_CALLBACK (gimp_text_tool_insert_at_cursor),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "delete-from-cursor",
|
|
|
|
G_CALLBACK (gimp_text_tool_delete_from_cursor),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "backspace",
|
|
|
|
G_CALLBACK (gimp_text_tool_backspace),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "cut-clipboard",
|
|
|
|
G_CALLBACK (gimp_text_tool_cut_clipboard),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "copy-clipboard",
|
|
|
|
G_CALLBACK (gimp_text_tool_copy_clipboard),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "paste-clipboard",
|
|
|
|
G_CALLBACK (gimp_text_tool_paste_clipboard),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "toggle-overwrite",
|
|
|
|
G_CALLBACK (gimp_text_tool_toggle_overwrite),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "select-all",
|
|
|
|
G_CALLBACK (gimp_text_tool_select_all),
|
|
|
|
text_tool);
|
2010-03-29 03:38:31 +08:00
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "change-size",
|
|
|
|
G_CALLBACK (gimp_text_tool_change_size),
|
|
|
|
text_tool);
|
2010-02-27 20:14:28 +08:00
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "change-baseline",
|
|
|
|
G_CALLBACK (gimp_text_tool_change_baseline),
|
|
|
|
text_tool);
|
2010-03-03 17:48:42 +08:00
|
|
|
g_signal_connect_swapped (text_tool->proxy_text_view, "change-kerning",
|
|
|
|
G_CALLBACK (gimp_text_tool_change_kerning),
|
2010-02-27 20:14:28 +08:00
|
|
|
text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_move_cursor (GimpTextTool *text_tool,
|
|
|
|
GtkMovementStep step,
|
|
|
|
gint count,
|
|
|
|
gboolean extend_selection)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-02-18 04:23:15 +08:00
|
|
|
GtkTextIter cursor;
|
|
|
|
GtkTextIter selection;
|
|
|
|
GtkTextIter *sel_start;
|
|
|
|
gboolean cancel_selection = FALSE;
|
|
|
|
gint x_pos = -1;
|
|
|
|
|
2016-06-06 02:53:02 +08:00
|
|
|
if (text_tool->pending)
|
|
|
|
{
|
|
|
|
/* If there are any pending text commits, there would be
|
|
|
|
* inconsistencies between the text_tool->buffer and layout.
|
|
|
|
* This could result in crashes. See bug 751333.
|
|
|
|
* Therefore we apply them first.
|
|
|
|
*/
|
|
|
|
gimp_text_tool_apply (text_tool, TRUE);
|
|
|
|
}
|
2010-02-18 16:39:25 +08:00
|
|
|
GIMP_LOG (TEXT_EDITING, "%s count = %d, select = %s",
|
|
|
|
g_enum_get_value (g_type_class_ref (GTK_TYPE_MOVEMENT_STEP),
|
|
|
|
step)->value_name,
|
|
|
|
count,
|
|
|
|
extend_selection ? "TRUE" : "FALSE");
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &selection,
|
|
|
|
gtk_text_buffer_get_selection_bound (buffer));
|
|
|
|
|
|
|
|
if (extend_selection)
|
|
|
|
{
|
|
|
|
sel_start = &selection;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* when there is a selection, moving the cursor without
|
|
|
|
* extending it should move the cursor to the end of the
|
|
|
|
* selection that is in moving direction
|
|
|
|
*/
|
|
|
|
if (count > 0)
|
|
|
|
gtk_text_iter_order (&selection, &cursor);
|
|
|
|
else
|
|
|
|
gtk_text_iter_order (&cursor, &selection);
|
|
|
|
|
|
|
|
sel_start = &cursor;
|
|
|
|
|
|
|
|
/* if we actually have a selection, just move *to* the beginning/end
|
|
|
|
* of the selection and not *from* there on LOGICAL_POSITIONS
|
|
|
|
* and VISUAL_POSITIONS movement
|
|
|
|
*/
|
|
|
|
if (! gtk_text_iter_equal (&cursor, &selection))
|
|
|
|
cancel_selection = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (step)
|
|
|
|
{
|
|
|
|
case GTK_MOVEMENT_LOGICAL_POSITIONS:
|
|
|
|
if (! cancel_selection)
|
|
|
|
gtk_text_iter_forward_visible_cursor_positions (&cursor, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_VISUAL_POSITIONS:
|
|
|
|
if (! cancel_selection)
|
|
|
|
{
|
2010-10-14 07:01:33 +08:00
|
|
|
PangoLayout *layout;
|
2012-02-09 19:36:43 +08:00
|
|
|
const gchar *text;
|
2010-10-14 07:01:33 +08:00
|
|
|
|
2010-10-14 17:01:16 +08:00
|
|
|
if (! gimp_text_tool_ensure_layout (text_tool))
|
|
|
|
break;
|
2010-10-14 07:01:33 +08:00
|
|
|
|
|
|
|
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
|
2012-02-09 19:36:43 +08:00
|
|
|
text = pango_layout_get_text (layout);
|
2010-10-14 07:01:33 +08:00
|
|
|
|
|
|
|
while (count != 0)
|
|
|
|
{
|
2012-02-09 19:36:43 +08:00
|
|
|
const gunichar word_joiner = 8288; /*g_utf8_get_char(WORD_JOINER);*/
|
2010-10-14 17:01:16 +08:00
|
|
|
gint index;
|
2012-02-09 19:36:43 +08:00
|
|
|
gint trailing = 0;
|
2010-10-14 08:45:32 +08:00
|
|
|
gint new_index;
|
|
|
|
|
2010-10-14 17:01:16 +08:00
|
|
|
index = gimp_text_buffer_get_iter_index (text_tool->buffer,
|
|
|
|
&cursor, TRUE);
|
|
|
|
|
2011-12-05 02:24:33 +08:00
|
|
|
if (count > 0)
|
2010-10-14 07:01:33 +08:00
|
|
|
{
|
2012-02-09 19:36:43 +08:00
|
|
|
if (g_utf8_get_char (text + index) == word_joiner)
|
2012-05-23 15:44:51 +08:00
|
|
|
pango_layout_move_cursor_visually (layout, TRUE,
|
|
|
|
index, 0, 1,
|
2012-02-09 19:36:43 +08:00
|
|
|
&new_index, &trailing);
|
|
|
|
else
|
|
|
|
new_index = index;
|
|
|
|
|
2012-05-23 15:44:51 +08:00
|
|
|
pango_layout_move_cursor_visually (layout, TRUE,
|
|
|
|
new_index, trailing, 1,
|
2010-10-14 08:45:32 +08:00
|
|
|
&new_index, &trailing);
|
2010-10-14 07:01:33 +08:00
|
|
|
count--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-23 15:44:51 +08:00
|
|
|
pango_layout_move_cursor_visually (layout, TRUE,
|
|
|
|
index, 0, -1,
|
2010-10-14 08:45:32 +08:00
|
|
|
&new_index, &trailing);
|
2012-02-09 19:36:43 +08:00
|
|
|
|
2012-05-23 15:44:51 +08:00
|
|
|
if (new_index != -1 && new_index != G_MAXINT &&
|
|
|
|
g_utf8_get_char (text + new_index) == word_joiner)
|
|
|
|
{
|
|
|
|
pango_layout_move_cursor_visually (layout, TRUE,
|
|
|
|
new_index, trailing, -1,
|
|
|
|
&new_index, &trailing);
|
|
|
|
}
|
|
|
|
|
2010-10-14 07:01:33 +08:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2011-12-05 02:24:33 +08:00
|
|
|
if (new_index != G_MAXINT && new_index != -1)
|
|
|
|
index = new_index;
|
|
|
|
else
|
|
|
|
break;
|
2010-10-14 17:01:16 +08:00
|
|
|
|
2011-12-05 02:24:33 +08:00
|
|
|
gimp_text_buffer_get_iter_at_index (text_tool->buffer,
|
|
|
|
&cursor, index, TRUE);
|
|
|
|
gtk_text_iter_forward_chars (&cursor, trailing);
|
2010-10-14 17:01:16 +08:00
|
|
|
}
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_WORDS:
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
gtk_text_iter_backward_visible_word_starts (&cursor, -count);
|
|
|
|
}
|
|
|
|
else if (count > 0)
|
|
|
|
{
|
2016-04-17 02:08:13 +08:00
|
|
|
if (! gtk_text_iter_forward_visible_word_ends (&cursor, count))
|
|
|
|
gtk_text_iter_forward_to_line_end (&cursor);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_DISPLAY_LINES:
|
|
|
|
{
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
gint cursor_index;
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoLayoutLine *layout_line;
|
|
|
|
PangoLayoutIter *layout_iter;
|
|
|
|
PangoRectangle logical;
|
|
|
|
gint line;
|
|
|
|
gint trailing;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
|
|
|
|
2010-02-26 00:49:33 +08:00
|
|
|
cursor_index = gimp_text_buffer_get_iter_index (text_tool->buffer,
|
2010-03-01 23:27:34 +08:00
|
|
|
&cursor, TRUE);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2010-10-14 17:01:16 +08:00
|
|
|
if (! gimp_text_tool_ensure_layout (text_tool))
|
|
|
|
break;
|
2010-02-24 06:14:09 +08:00
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
|
|
|
|
|
|
|
|
pango_layout_index_to_line_x (layout, cursor_index, FALSE,
|
|
|
|
&line, &x_pos);
|
|
|
|
|
|
|
|
layout_iter = pango_layout_get_iter (layout);
|
|
|
|
for (i = 0; i < line; i++)
|
|
|
|
pango_layout_iter_next_line (layout_iter);
|
|
|
|
|
|
|
|
pango_layout_iter_get_line_extents (layout_iter, NULL, &logical);
|
|
|
|
|
2010-02-21 05:18:38 +08:00
|
|
|
x_pos += logical.x;
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
pango_layout_iter_free (layout_iter);
|
|
|
|
|
|
|
|
/* try to go to the remembered x_pos if it exists *and* we are at
|
|
|
|
* the beginning or at the end of the current line
|
|
|
|
*/
|
|
|
|
if (text_tool->x_pos != -1 && (x_pos <= logical.x ||
|
2010-02-21 05:18:38 +08:00
|
|
|
x_pos >= logical.x + logical.width))
|
2010-02-18 04:23:15 +08:00
|
|
|
x_pos = text_tool->x_pos;
|
|
|
|
|
|
|
|
line += count;
|
|
|
|
|
|
|
|
if (line < 0)
|
|
|
|
{
|
|
|
|
cursor = start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (line >= pango_layout_get_line_count (layout))
|
|
|
|
{
|
|
|
|
cursor = end;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout_iter = pango_layout_get_iter (layout);
|
|
|
|
for (i = 0; i < line; i++)
|
|
|
|
pango_layout_iter_next_line (layout_iter);
|
|
|
|
|
|
|
|
layout_line = pango_layout_iter_get_line_readonly (layout_iter);
|
|
|
|
pango_layout_iter_get_line_extents (layout_iter, NULL, &logical);
|
|
|
|
|
|
|
|
pango_layout_iter_free (layout_iter);
|
|
|
|
|
2010-02-21 05:18:38 +08:00
|
|
|
pango_layout_line_x_to_index (layout_line, x_pos - logical.x,
|
2010-02-18 04:23:15 +08:00
|
|
|
&cursor_index, &trailing);
|
|
|
|
|
2010-03-01 23:27:34 +08:00
|
|
|
gimp_text_buffer_get_iter_at_index (text_tool->buffer, &cursor,
|
|
|
|
cursor_index, TRUE);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
while (trailing--)
|
|
|
|
gtk_text_iter_forward_char (&cursor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_PAGES: /* well... */
|
|
|
|
case GTK_MOVEMENT_BUFFER_ENDS:
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &cursor);
|
|
|
|
}
|
|
|
|
else if (count > 0)
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &cursor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_PARAGRAPH_ENDS:
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
gtk_text_iter_set_line_offset (&cursor, 0);
|
|
|
|
}
|
|
|
|
else if (count > 0)
|
|
|
|
{
|
|
|
|
if (! gtk_text_iter_ends_line (&cursor))
|
|
|
|
gtk_text_iter_forward_to_line_end (&cursor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
gtk_text_iter_set_line_offset (&cursor, 0);
|
|
|
|
}
|
|
|
|
else if (count > 0)
|
|
|
|
{
|
|
|
|
if (! gtk_text_iter_ends_line (&cursor))
|
|
|
|
gtk_text_iter_forward_to_line_end (&cursor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_tool->x_pos = x_pos;
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
|
2010-02-19 23:05:48 +08:00
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
gtk_text_buffer_select_range (buffer, &cursor, sel_start);
|
2016-07-16 22:28:35 +08:00
|
|
|
gimp_text_tool_editor_copy_selection_to_clipboard (text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_insert_at_cursor (GimpTextTool *text_tool,
|
|
|
|
const gchar *str)
|
|
|
|
{
|
2010-02-26 09:34:01 +08:00
|
|
|
gimp_text_buffer_insert (text_tool->buffer, str);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_whitespace (gunichar ch,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
return (ch == ' ' || ch == '\t');
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_not_whitespace (gunichar ch,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
return ! is_whitespace (ch, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_whitepace_region (const GtkTextIter *center,
|
|
|
|
GtkTextIter *start,
|
|
|
|
GtkTextIter *end)
|
|
|
|
{
|
|
|
|
*start = *center;
|
|
|
|
*end = *center;
|
|
|
|
|
|
|
|
if (gtk_text_iter_backward_find_char (start, is_not_whitespace, NULL, NULL))
|
|
|
|
gtk_text_iter_forward_char (start); /* we want the first whitespace... */
|
|
|
|
|
|
|
|
if (is_whitespace (gtk_text_iter_get_char (end), NULL))
|
|
|
|
gtk_text_iter_forward_find_char (end, is_not_whitespace, NULL, NULL);
|
|
|
|
|
|
|
|
return ! gtk_text_iter_equal (start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_delete_from_cursor (GimpTextTool *text_tool,
|
|
|
|
GtkDeleteType type,
|
|
|
|
gint count)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-02-18 04:23:15 +08:00
|
|
|
GtkTextIter cursor;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
2010-02-18 16:39:25 +08:00
|
|
|
GIMP_LOG (TEXT_EDITING, "%s count = %d",
|
|
|
|
g_enum_get_value (g_type_class_ref (GTK_TYPE_DELETE_TYPE),
|
|
|
|
type)->value_name,
|
|
|
|
count);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2010-02-19 23:05:48 +08:00
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
end = cursor;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GTK_DELETE_CHARS:
|
|
|
|
if (gtk_text_buffer_get_has_selection (buffer))
|
|
|
|
{
|
|
|
|
gtk_text_buffer_delete_selection (buffer, TRUE, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_text_iter_forward_cursor_positions (&end, count);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_WORD_ENDS:
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
if (! gtk_text_iter_starts_word (&cursor))
|
|
|
|
gtk_text_iter_backward_visible_word_starts (&cursor, 1);
|
|
|
|
}
|
|
|
|
else if (count > 0)
|
|
|
|
{
|
|
|
|
if (! gtk_text_iter_ends_word (&end) &&
|
|
|
|
! gtk_text_iter_forward_visible_word_ends (&end, 1))
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_WORDS:
|
|
|
|
if (! gtk_text_iter_starts_word (&cursor))
|
|
|
|
gtk_text_iter_backward_visible_word_starts (&cursor, 1);
|
|
|
|
|
|
|
|
if (! gtk_text_iter_ends_word (&end) &&
|
|
|
|
! gtk_text_iter_forward_visible_word_ends (&end, 1))
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_DISPLAY_LINES:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_DISPLAY_LINE_ENDS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_PARAGRAPH_ENDS:
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
gtk_text_iter_set_line_offset (&cursor, 0);
|
|
|
|
}
|
|
|
|
else if (count > 0)
|
|
|
|
{
|
|
|
|
if (! gtk_text_iter_ends_line (&end))
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
else
|
|
|
|
gtk_text_iter_forward_cursor_positions (&end, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_PARAGRAPHS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DELETE_WHITESPACE:
|
|
|
|
find_whitepace_region (&cursor, &cursor, &end);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! gtk_text_iter_equal (&cursor, &end))
|
|
|
|
{
|
2010-03-01 23:03:48 +08:00
|
|
|
gtk_text_buffer_delete_interactive (buffer, &cursor, &end, TRUE);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_backspace (GimpTextTool *text_tool)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2010-02-19 23:05:48 +08:00
|
|
|
gimp_text_tool_reset_im_context (text_tool);
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
if (gtk_text_buffer_get_has_selection (buffer))
|
|
|
|
{
|
|
|
|
gtk_text_buffer_delete_selection (buffer, TRUE, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTextIter cursor;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
|
|
|
|
gtk_text_buffer_backspace (buffer, &cursor, TRUE, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_toggle_overwrite (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
|
|
|
|
text_tool->overwrite_mode = ! text_tool->overwrite_mode;
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_select_all (GimpTextTool *text_tool,
|
|
|
|
gboolean select)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
|
|
|
|
if (select)
|
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
|
|
|
gtk_text_buffer_select_range (buffer, &start, &end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTextIter cursor;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
2016-04-17 02:08:13 +08:00
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2010-02-18 04:23:15 +08:00
|
|
|
gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
|
|
|
|
}
|
|
|
|
|
2010-03-29 03:38:31 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_change_size (GimpTextTool *text_tool,
|
|
|
|
gdouble amount)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
if (! gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_iter_order (&start, &end);
|
|
|
|
gimp_text_buffer_change_size (text_tool->buffer, &start, &end,
|
|
|
|
amount * PANGO_SCALE);
|
|
|
|
}
|
|
|
|
|
2010-02-27 20:14:28 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_change_baseline (GimpTextTool *text_tool,
|
2010-03-09 04:57:29 +08:00
|
|
|
gdouble amount)
|
2010-02-27 20:14:28 +08:00
|
|
|
{
|
2010-02-28 00:54:36 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
if (! gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &end);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_iter_order (&start, &end);
|
|
|
|
gimp_text_buffer_change_baseline (text_tool->buffer, &start, &end,
|
2010-03-09 04:57:29 +08:00
|
|
|
amount * PANGO_SCALE);
|
2010-02-27 20:14:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-03 17:48:42 +08:00
|
|
|
gimp_text_tool_change_kerning (GimpTextTool *text_tool,
|
2010-03-09 04:57:29 +08:00
|
|
|
gdouble amount)
|
2010-02-27 20:14:28 +08:00
|
|
|
{
|
2010-02-28 00:54:36 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
if (! gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2010-02-28 20:58:08 +08:00
|
|
|
end = start;
|
2010-03-01 00:56:20 +08:00
|
|
|
gtk_text_iter_forward_char (&end);
|
2010-02-28 00:54:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_iter_order (&start, &end);
|
2010-03-03 17:48:42 +08:00
|
|
|
gimp_text_buffer_change_kerning (text_tool->buffer, &start, &end,
|
2010-03-09 04:57:29 +08:00
|
|
|
amount * PANGO_SCALE);
|
2010-02-27 20:14:28 +08:00
|
|
|
}
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_options_notify (GimpTextOptions *options,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
const gchar *param_name = g_param_spec_get_name (pspec);
|
|
|
|
|
|
|
|
if (! strcmp (param_name, "use-editor"))
|
|
|
|
{
|
|
|
|
if (options->use_editor)
|
|
|
|
{
|
2012-10-22 05:28:30 +08:00
|
|
|
gimp_text_tool_editor_dialog (text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-18 16:51:45 +08:00
|
|
|
if (text_tool->editor_dialog)
|
|
|
|
gtk_widget_destroy (text_tool->editor_dialog);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_editor_dialog (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
|
2016-11-25 20:26:08 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
GimpImageWindow *image_window;
|
2010-02-18 04:23:15 +08:00
|
|
|
GimpDialogFactory *dialog_factory;
|
|
|
|
GtkWindow *parent = NULL;
|
2011-03-18 19:58:32 +08:00
|
|
|
gdouble xres = 1.0;
|
|
|
|
gdouble yres = 1.0;
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2010-02-18 16:51:45 +08:00
|
|
|
if (text_tool->editor_dialog)
|
2010-02-18 04:23:15 +08:00
|
|
|
{
|
2010-02-18 16:51:45 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (text_tool->editor_dialog));
|
2010-02-18 04:23:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-25 20:26:08 +08:00
|
|
|
image_window = gimp_display_shell_get_window (shell);
|
|
|
|
dialog_factory = gimp_dock_container_get_dialog_factory (GIMP_DOCK_CONTAINER (image_window));
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2011-03-18 19:58:32 +08:00
|
|
|
if (text_tool->image)
|
|
|
|
gimp_image_get_resolution (text_tool->image, &xres, &yres);
|
|
|
|
|
2010-02-18 16:51:45 +08:00
|
|
|
text_tool->editor_dialog =
|
2011-03-18 19:58:32 +08:00
|
|
|
gimp_text_options_editor_new (parent, tool->tool_info->gimp, options,
|
2010-02-18 16:51:45 +08:00
|
|
|
gimp_dialog_factory_get_menu_factory (dialog_factory),
|
|
|
|
_("GIMP Text Editor"),
|
2011-03-19 04:16:53 +08:00
|
|
|
text_tool->proxy, text_tool->buffer,
|
|
|
|
xres, yres);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2010-02-18 16:51:45 +08:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (text_tool->editor_dialog),
|
|
|
|
(gpointer) &text_tool->editor_dialog);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
|
|
|
gimp_dialog_factory_add_foreign (dialog_factory,
|
|
|
|
"gimp-text-tool-dialog",
|
2014-05-02 09:01:23 +08:00
|
|
|
text_tool->editor_dialog,
|
2016-11-25 20:26:08 +08:00
|
|
|
gtk_widget_get_screen (GTK_WIDGET (image_window)),
|
|
|
|
gimp_widget_get_monitor (GTK_WIDGET (image_window)));
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2010-02-22 01:59:51 +08:00
|
|
|
g_signal_connect (text_tool->editor_dialog, "destroy",
|
|
|
|
G_CALLBACK (gimp_text_tool_editor_destroy),
|
|
|
|
text_tool);
|
|
|
|
|
2010-02-18 16:51:45 +08:00
|
|
|
gtk_widget_show (text_tool->editor_dialog);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
|
2010-02-22 01:59:51 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_editor_destroy (GtkWidget *dialog,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
|
|
|
|
|
|
|
|
g_object_set (options,
|
|
|
|
"use-editor", FALSE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_enter_text (GimpTextTool *text_tool,
|
|
|
|
const gchar *str)
|
|
|
|
{
|
2010-02-26 00:49:33 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2010-02-18 04:23:15 +08:00
|
|
|
gboolean had_selection;
|
|
|
|
|
|
|
|
had_selection = gtk_text_buffer_get_has_selection (buffer);
|
|
|
|
|
app: fix text tool drawing for good this time (hopefully)
Earlier I claimed that drawing would work now because we make sure
that buffer and layout are always in sync. This was nonsense. In fact,
we constantly ran into the sutiation where the buffer was modified,
and we were drawing with the previous layout. It's unclear why this
didn't cause drawing artifacts, but it did cause e.g. the cursor
temporarily jumping to the next position while editing in the middle
of text (especially visible at line ends).
Several underlying problems existed: first, we now modify the buffer
from outside the text tool (from GimpTextStyleEditor) where we can't
pause the tool; second, proxy changes are handled asymetrically
(property changes are queued and processed all together in an idle
function) so we can't pause/resume drawing across the entire operation
because it has many beginnings and only one end.
Therefore:
- add gimp_text_tool_block_drawing()/unblock_drawing(), where block()
can be called as many times as needed, and a single unblock()
enables drawing again. block() also clears the layout, because it
served its purpose (it was just used to pause drawing, and we know
the buffer will change, so kill it).
- connect to GtkTextBuffer::begin-user-action and call block() from
the callback, so we undraw stuff and kill the cached layout before
any buffer change happens.
- call unblock() at the end of gimp_text_tool_apply() because then
the text and the buffer are in sync again, the tool is undrawn and
we can safely create the layout again to draw our stuff.
- also call block()/unblock() from some other places, like when a
new text layer is created.
- get rid of *all* calls to draw_tool_pause()/resume() around buffer
modifications, they are not needed any longer.
- add calls to begin/end_user_action() where they were missing.
2010-03-05 06:47:23 +08:00
|
|
|
gtk_text_buffer_begin_user_action (buffer);
|
2010-02-20 23:18:41 +08:00
|
|
|
|
2010-02-18 04:23:15 +08:00
|
|
|
gimp_text_tool_delete_selection (text_tool);
|
|
|
|
|
|
|
|
if (! had_selection && text_tool->overwrite_mode && strcmp (str, "\n"))
|
|
|
|
{
|
|
|
|
GtkTextIter cursor;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
|
|
|
|
if (! gtk_text_iter_ends_line (&cursor))
|
|
|
|
gimp_text_tool_delete_from_cursor (text_tool, GTK_DELETE_CHARS, 1);
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:34:01 +08:00
|
|
|
gimp_text_buffer_insert (text_tool->buffer, str);
|
2010-02-20 23:18:41 +08:00
|
|
|
|
app: fix text tool drawing for good this time (hopefully)
Earlier I claimed that drawing would work now because we make sure
that buffer and layout are always in sync. This was nonsense. In fact,
we constantly ran into the sutiation where the buffer was modified,
and we were drawing with the previous layout. It's unclear why this
didn't cause drawing artifacts, but it did cause e.g. the cursor
temporarily jumping to the next position while editing in the middle
of text (especially visible at line ends).
Several underlying problems existed: first, we now modify the buffer
from outside the text tool (from GimpTextStyleEditor) where we can't
pause the tool; second, proxy changes are handled asymetrically
(property changes are queued and processed all together in an idle
function) so we can't pause/resume drawing across the entire operation
because it has many beginnings and only one end.
Therefore:
- add gimp_text_tool_block_drawing()/unblock_drawing(), where block()
can be called as many times as needed, and a single unblock()
enables drawing again. block() also clears the layout, because it
served its purpose (it was just used to pause drawing, and we know
the buffer will change, so kill it).
- connect to GtkTextBuffer::begin-user-action and call block() from
the callback, so we undraw stuff and kill the cached layout before
any buffer change happens.
- call unblock() at the end of gimp_text_tool_apply() because then
the text and the buffer are in sync again, the tool is undrawn and
we can safely create the layout again to draw our stuff.
- also call block()/unblock() from some other places, like when a
new text layer is created.
- get rid of *all* calls to draw_tool_pause()/resume() around buffer
modifications, they are not needed any longer.
- add calls to begin/end_user_action() where they were missing.
2010-03-05 06:47:23 +08:00
|
|
|
gtk_text_buffer_end_user_action (buffer);
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_xy_to_iter (GimpTextTool *text_tool,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkTextIter *iter)
|
2010-02-21 06:19:10 +08:00
|
|
|
{
|
2010-03-07 07:11:05 +08:00
|
|
|
PangoLayout *layout;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gint index;
|
|
|
|
gint trailing;
|
2010-02-21 06:19:10 +08:00
|
|
|
|
2010-02-24 06:14:09 +08:00
|
|
|
gimp_text_tool_ensure_layout (text_tool);
|
|
|
|
|
2010-02-21 06:19:10 +08:00
|
|
|
gimp_text_layout_untransform_point (text_tool->layout, &x, &y);
|
|
|
|
|
2010-03-07 07:11:05 +08:00
|
|
|
gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
|
|
|
|
x -= offset_x;
|
|
|
|
y -= offset_y;
|
2010-02-21 06:19:10 +08:00
|
|
|
|
2010-03-07 07:11:05 +08:00
|
|
|
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
|
2010-02-21 06:19:10 +08:00
|
|
|
|
|
|
|
pango_layout_xy_to_index (layout,
|
|
|
|
x * PANGO_SCALE,
|
|
|
|
y * PANGO_SCALE,
|
2010-03-02 19:23:29 +08:00
|
|
|
&index, &trailing);
|
2010-02-21 06:19:10 +08:00
|
|
|
|
2010-03-02 19:23:29 +08:00
|
|
|
gimp_text_buffer_get_iter_at_index (text_tool->buffer, iter, index, TRUE);
|
|
|
|
|
|
|
|
if (trailing)
|
|
|
|
gtk_text_iter_forward_char (iter);
|
2010-02-21 06:19:10 +08:00
|
|
|
}
|
|
|
|
|
2016-06-05 22:23:50 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_im_preedit_start (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GIMP_LOG (TEXT_EDITING, "preedit start");
|
|
|
|
|
|
|
|
text_tool->preedit_active = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-20 22:13:14 +08:00
|
|
|
static void
|
2010-02-21 06:33:58 +08:00
|
|
|
gimp_text_tool_im_preedit_end (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool)
|
2010-02-20 22:13:14 +08:00
|
|
|
{
|
2016-04-16 21:12:42 +08:00
|
|
|
gimp_text_tool_delete_selection (text_tool);
|
2016-06-05 22:23:50 +08:00
|
|
|
|
|
|
|
text_tool->preedit_active = FALSE;
|
|
|
|
|
|
|
|
GIMP_LOG (TEXT_EDITING, "preedit end");
|
2010-02-20 22:13:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-02-21 06:33:58 +08:00
|
|
|
gimp_text_tool_im_preedit_changed (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool)
|
2010-02-18 04:23:15 +08:00
|
|
|
{
|
2016-04-16 21:12:42 +08:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
2016-05-09 06:35:19 +08:00
|
|
|
PangoAttrList *attrs;
|
2016-04-16 21:12:42 +08:00
|
|
|
|
2016-06-05 22:23:50 +08:00
|
|
|
GIMP_LOG (TEXT_EDITING, "preedit changed");
|
|
|
|
|
|
|
|
gtk_text_buffer_begin_user_action (buffer);
|
|
|
|
|
2016-06-05 06:04:01 +08:00
|
|
|
gimp_text_tool_im_delete_preedit (text_tool);
|
2010-02-18 04:23:15 +08:00
|
|
|
|
2016-04-16 21:12:42 +08:00
|
|
|
gimp_text_tool_delete_selection (text_tool);
|
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
gtk_im_context_get_preedit_string (context,
|
|
|
|
&text_tool->preedit_string, &attrs,
|
|
|
|
&text_tool->preedit_cursor);
|
2016-06-05 06:04:01 +08:00
|
|
|
|
2015-06-23 04:52:33 +08:00
|
|
|
if (text_tool->preedit_string && *text_tool->preedit_string)
|
|
|
|
{
|
2016-05-09 06:35:19 +08:00
|
|
|
PangoAttrIterator *attr_iter;
|
|
|
|
GtkTextIter iter;
|
|
|
|
gint i;
|
2015-06-23 04:52:33 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
/* Save the preedit start position. */
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
|
2016-04-16 21:12:42 +08:00
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2016-05-09 06:35:19 +08:00
|
|
|
text_tool->preedit_start = gtk_text_buffer_create_mark (buffer,
|
|
|
|
"preedit-start",
|
|
|
|
&iter, TRUE);
|
2016-04-16 21:12:42 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
/* Loop through chunks of preedit text with different attributes. */
|
|
|
|
attr_iter = pango_attr_list_get_iterator (attrs);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gint attr_start;
|
|
|
|
gint attr_end;
|
2016-04-16 21:12:42 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
pango_attr_iterator_range (attr_iter, &attr_start, &attr_end);
|
|
|
|
if (attr_start < strlen (text_tool->preedit_string))
|
|
|
|
{
|
|
|
|
GSList *attrs_pos;
|
|
|
|
GtkTextMark *start_mark;
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
start_mark = gtk_text_buffer_create_mark (buffer,
|
|
|
|
NULL,
|
|
|
|
&start, TRUE);
|
|
|
|
|
|
|
|
gtk_text_buffer_begin_user_action (buffer);
|
|
|
|
|
|
|
|
/* Insert the preedit chunk at current cursor position. */
|
|
|
|
gtk_text_buffer_insert_at_cursor (GTK_TEXT_BUFFER (text_tool->buffer),
|
|
|
|
text_tool->preedit_string + attr_start,
|
|
|
|
attr_end - attr_start);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
start_mark);
|
|
|
|
gtk_text_buffer_delete_mark (buffer, start_mark);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &end,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
|
|
|
|
/* Apply text attributes to preedit text. */
|
|
|
|
attrs_pos = pango_attr_iterator_get_attrs (attr_iter);
|
|
|
|
while (attrs_pos)
|
|
|
|
{
|
|
|
|
PangoAttribute *attr = attrs_pos->data;
|
|
|
|
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
switch (attr->klass->type)
|
|
|
|
{
|
|
|
|
case PANGO_ATTR_UNDERLINE:
|
|
|
|
gtk_text_buffer_apply_tag (buffer,
|
2016-06-01 23:02:21 +08:00
|
|
|
text_tool->buffer->preedit_underline_tag,
|
2016-05-09 06:35:19 +08:00
|
|
|
&start, &end);
|
|
|
|
break;
|
|
|
|
case PANGO_ATTR_BACKGROUND:
|
|
|
|
case PANGO_ATTR_FOREGROUND:
|
|
|
|
{
|
|
|
|
PangoAttrColor *color_attr = (PangoAttrColor *) attr;
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
color.r = (gdouble) color_attr->color.red / 65535.0;
|
|
|
|
color.g = (gdouble) color_attr->color.green / 65535.0;
|
|
|
|
color.b = (gdouble) color_attr->color.blue / 65535.0;
|
|
|
|
|
|
|
|
if (attr->klass->type == PANGO_ATTR_BACKGROUND)
|
|
|
|
{
|
2016-06-01 23:34:28 +08:00
|
|
|
gimp_text_buffer_set_preedit_bg_color (text_tool->buffer,
|
|
|
|
&start, &end,
|
|
|
|
&color);
|
2016-05-09 06:35:19 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-01 23:34:28 +08:00
|
|
|
gimp_text_buffer_set_preedit_color (text_tool->buffer,
|
|
|
|
&start, &end,
|
|
|
|
&color);
|
2016-05-09 06:35:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unsupported tags. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-06-05 06:04:01 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
attrs_pos = attrs_pos->next;
|
|
|
|
}
|
2016-06-05 06:04:01 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
gtk_text_buffer_end_user_action (buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (pango_attr_iterator_next (attr_iter));
|
|
|
|
|
|
|
|
/* Save the preedit end position. */
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
|
2016-04-16 21:12:42 +08:00
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2016-05-09 06:35:19 +08:00
|
|
|
text_tool->preedit_end = gtk_text_buffer_create_mark (buffer,
|
|
|
|
"preedit-end",
|
2016-06-06 05:09:47 +08:00
|
|
|
&iter, FALSE);
|
2016-04-16 21:12:42 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
/* Move the cursor to the expected location. */
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter, text_tool->preedit_start);
|
|
|
|
for (i = 0; i < text_tool->preedit_cursor; i++)
|
|
|
|
gtk_text_iter_forward_char (&iter);
|
|
|
|
gtk_text_buffer_place_cursor (buffer, &iter);
|
|
|
|
|
|
|
|
pango_attr_iterator_destroy (attr_iter);
|
2015-06-23 04:52:33 +08:00
|
|
|
}
|
2016-06-05 06:04:01 +08:00
|
|
|
|
2016-05-09 06:35:19 +08:00
|
|
|
pango_attr_list_unref (attrs);
|
2016-06-05 22:23:50 +08:00
|
|
|
|
|
|
|
gtk_text_buffer_end_user_action (buffer);
|
2015-06-23 04:52:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_im_commit (GtkIMContext *context,
|
|
|
|
const gchar *str,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
2016-06-06 03:49:30 +08:00
|
|
|
gboolean preedit_active = text_tool->preedit_active;
|
|
|
|
|
2016-06-05 06:04:01 +08:00
|
|
|
gimp_text_tool_im_delete_preedit (text_tool);
|
2016-05-09 06:35:19 +08:00
|
|
|
|
2016-06-06 03:49:30 +08:00
|
|
|
/* Some IMEs would emit a preedit-commit before preedit-end.
|
|
|
|
* To keep undo consistency, we fake and end then immediate restart of
|
|
|
|
* preediting.
|
|
|
|
*/
|
|
|
|
if (preedit_active)
|
|
|
|
gimp_text_tool_im_preedit_end (context, text_tool);
|
|
|
|
|
2015-06-23 04:52:33 +08:00
|
|
|
gimp_text_tool_enter_text (text_tool, str);
|
2016-06-06 03:49:30 +08:00
|
|
|
|
|
|
|
if (preedit_active)
|
|
|
|
gimp_text_tool_im_preedit_start (context, text_tool);
|
2015-06-23 04:52:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_text_tool_im_retrieve_surrounding (GtkIMContext *context,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
gint pos;
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
pos = gtk_text_iter_get_line_index (&start);
|
|
|
|
gtk_text_iter_set_line_offset (&start, 0);
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
|
|
|
|
text = gtk_text_iter_get_slice (&start, &end);
|
|
|
|
gtk_im_context_set_surrounding (context, text, -1, pos);
|
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_text_tool_im_delete_surrounding (GtkIMContext *context,
|
|
|
|
gint offset,
|
|
|
|
gint n_chars,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
gtk_text_iter_forward_chars (&start, offset);
|
|
|
|
gtk_text_iter_forward_chars (&end, offset + n_chars);
|
|
|
|
|
|
|
|
gtk_text_buffer_delete_interactive (buffer, &start, &end, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
2010-02-18 04:23:15 +08:00
|
|
|
}
|
2016-06-05 06:04:01 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_im_delete_preedit (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
if (text_tool->preedit_string)
|
|
|
|
{
|
|
|
|
if (*text_tool->preedit_string)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &start,
|
|
|
|
text_tool->preedit_start);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &end,
|
|
|
|
text_tool->preedit_end);
|
|
|
|
|
|
|
|
gtk_text_buffer_delete_interactive (buffer, &start, &end, TRUE);
|
|
|
|
|
|
|
|
gtk_text_buffer_delete_mark (buffer, text_tool->preedit_start);
|
|
|
|
gtk_text_buffer_delete_mark (buffer, text_tool->preedit_end);
|
|
|
|
text_tool->preedit_start = NULL;
|
|
|
|
text_tool->preedit_end = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (text_tool->preedit_string);
|
|
|
|
text_tool->preedit_string = NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-07-16 22:28:35 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_editor_copy_selection_to_clipboard (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
|
|
|
|
|
|
|
|
if (! text_tool->editor_dialog &&
|
|
|
|
gtk_text_buffer_get_has_selection (buffer))
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
GtkClipboard *clipboard;
|
|
|
|
|
|
|
|
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (shell),
|
|
|
|
GDK_SELECTION_PRIMARY);
|
|
|
|
|
|
|
|
gtk_text_buffer_copy_clipboard (buffer, clipboard);
|
|
|
|
}
|
|
|
|
}
|