gimp r26359 - in branches/soc-2008-text: . app/actions app/display app/menus app/tools menus
- From: danedde svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26359 - in branches/soc-2008-text: . app/actions app/display app/menus app/tools menus
- Date: Sun, 3 Aug 2008 21:23:07 +0000 (UTC)
Author: danedde
Date: Sun Aug 3 21:23:07 2008
New Revision: 26359
URL: http://svn.gnome.org/viewvc/gimp?rev=26359&view=rev
Log:
2008-08-03 Daniel Eddeland <danedde svn gnome org>
* app/tools/gimptoolcontrol.h
* app/tools/gimptexttool.c
* app/tools/gimptexttool.h
* app/tools/gimptoolcontrol.c
* app/menus/menus.c
* app/actions/actions.c
* app/actions/Makefile.am
* app/display/gimpdisplayshell-callbacks.c
* app/actions/text-tool-actions.c
* app/actions/text-tool-actions.h
* app/actions/text-tool-commands.c
* app/actions/text-tool-commands.h
* menus/Makefile.am: added a context-sensitive right-click menu for
text-tool. Still work in progress
Added:
branches/soc-2008-text/app/actions/text-tool-actions.c
branches/soc-2008-text/app/actions/text-tool-actions.h
branches/soc-2008-text/app/actions/text-tool-commands.c
branches/soc-2008-text/app/actions/text-tool-commands.h
branches/soc-2008-text/menus/text-tool-menu.xml
Modified:
branches/soc-2008-text/ChangeLog
branches/soc-2008-text/app/actions/Makefile.am
branches/soc-2008-text/app/actions/actions.c
branches/soc-2008-text/app/display/gimpdisplayshell-callbacks.c
branches/soc-2008-text/app/menus/menus.c
branches/soc-2008-text/app/tools/gimptexttool.c
branches/soc-2008-text/app/tools/gimptexttool.h
branches/soc-2008-text/app/tools/gimptoolcontrol.c
branches/soc-2008-text/app/tools/gimptoolcontrol.h
branches/soc-2008-text/menus/Makefile.am
Modified: branches/soc-2008-text/app/actions/Makefile.am
==============================================================================
--- branches/soc-2008-text/app/actions/Makefile.am (original)
+++ branches/soc-2008-text/app/actions/Makefile.am Sun Aug 3 21:23:07 2008
@@ -133,6 +133,10 @@
text-editor-actions.h \
text-editor-commands.c \
text-editor-commands.h \
+ text-tool-actions.c \
+ text-tool-actions.h \
+ text-tool-commands.c \
+ text-tool-commands.h \
tool-options-actions.c \
tool-options-actions.h \
tool-options-commands.c \
Modified: branches/soc-2008-text/app/actions/actions.c
==============================================================================
--- branches/soc-2008-text/app/actions/actions.c (original)
+++ branches/soc-2008-text/app/actions/actions.c Sun Aug 3 21:23:07 2008
@@ -79,6 +79,7 @@
#include "select-actions.h"
#include "templates-actions.h"
#include "text-editor-actions.h"
+#include "text-tool-actions.h"
#include "tool-options-actions.h"
#include "tools-actions.h"
#include "vectors-actions.h"
@@ -190,6 +191,9 @@
{ "templates", N_("Templates"), GIMP_STOCK_TEMPLATE,
templates_actions_setup,
templates_actions_update },
+ { "text-tool", N_("Text Tool"), GTK_STOCK_EDIT,
+ text_tool_actions_setup,
+ text_tool_actions_update },
{ "text-editor", N_("Text Editor"), GTK_STOCK_EDIT,
text_editor_actions_setup,
text_editor_actions_update },
Added: branches/soc-2008-text/app/actions/text-tool-actions.c
==============================================================================
--- (empty file)
+++ branches/soc-2008-text/app/actions/text-tool-actions.c Sun Aug 3 21:23:07 2008
@@ -0,0 +1,112 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "widgets/gimpactiongroup.h"
+#include "widgets/gimptexteditor.h"
+#include "widgets/gimphelp-ids.h"
+
+#include "text-tool-actions.h"
+#include "text-tool-commands.h"
+
+#include "gimp-intl.h"
+
+
+static const GimpActionEntry text_tool_actions[] =
+{
+ { "text-tool-popup", NULL,
+ N_("Text Tool Popup"), NULL, NULL, NULL,
+ GIMP_HELP_TEXT_EDITOR_DIALOG },
+
+ { "text-tool-cut", NULL,
+ N_("Cut"), NULL, NULL,
+ NULL, NULL },
+
+ { "text-tool-copy", NULL,
+ N_("Copy"), NULL, NULL,
+ NULL, NULL },
+
+ { "text-tool-paste", NULL,
+ N_("Paste"), NULL, NULL,
+ NULL, NULL },
+
+ { "text-tool-delete", NULL,
+ N_("Delete"), NULL, NULL,
+ NULL, NULL },
+
+ { "text-tool-load", NULL,
+ N_("Open"), NULL,
+ N_("Load text from file"),
+ G_CALLBACK (text_tool_load_cmd_callback),
+ NULL },
+
+ { "text-tool-clear", NULL,
+ N_("Clear"), "",
+ N_("Clear all text"),
+ G_CALLBACK (text_tool_clear_cmd_callback),
+ NULL },
+
+ { "text-tool-input-methods", NULL,
+ N_("Input Methods"), NULL, NULL, NULL,
+ GIMP_HELP_TEXT_EDITOR_DIALOG }
+};
+
+static const GimpRadioActionEntry text_tool_direction_actions[] =
+{
+ { "text-tool-direction-ltr", GIMP_STOCK_TEXT_DIR_LTR,
+ N_("LTR"), "",
+ N_("From left to right"),
+ GIMP_TEXT_DIRECTION_LTR,
+ NULL },
+
+ { "text-tool-direction-rtl", GIMP_STOCK_TEXT_DIR_RTL,
+ N_("RTL"), "",
+ N_("From right to left"),
+ GIMP_TEXT_DIRECTION_RTL,
+ NULL }
+};
+
+
+void
+text_tool_actions_setup (GimpActionGroup *group)
+{
+ gimp_action_group_add_actions (group,
+ text_tool_actions,
+ G_N_ELEMENTS (text_tool_actions));
+
+ gimp_action_group_add_radio_actions (group,
+ text_tool_direction_actions,
+ G_N_ELEMENTS (text_tool_direction_actions),
+ NULL,
+ GIMP_TEXT_DIRECTION_LTR,
+ G_CALLBACK (text_tool_direction_cmd_callback));
+}
+
+void
+text_tool_actions_update (GimpActionGroup *group,
+ gpointer data)
+{
+ /* Things will be added here soon*/
+}
Added: branches/soc-2008-text/app/actions/text-tool-actions.h
==============================================================================
--- (empty file)
+++ branches/soc-2008-text/app/actions/text-tool-actions.h Sun Aug 3 21:23:07 2008
@@ -0,0 +1,28 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __TEXT_TOOL_ACTIONS_H__
+#define __TEXT_TOOL_ACTIONS_H__
+
+
+void text_tool_actions_setup (GimpActionGroup *group);
+void text_tool_actions_update (GimpActionGroup *group,
+ gpointer data);
+
+
+#endif /* __TEXT_TOOL_ACTIONS_H__ */
Added: branches/soc-2008-text/app/actions/text-tool-commands.c
==============================================================================
--- (empty file)
+++ branches/soc-2008-text/app/actions/text-tool-commands.c Sun Aug 3 21:23:07 2008
@@ -0,0 +1,158 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "libgimpbase/gimpbase.h"
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "core/gimp.h"
+
+#include "widgets/gimptexteditor.h"
+#include "widgets/gimphelp-ids.h"
+#include "widgets/gimpuimanager.h"
+#include "widgets/gimpwidgets-utils.h"
+
+#include "text-tool-commands.h"
+
+#include "gimp-intl.h"
+
+
+/* local function prototypes */
+
+static void text_tool_load_response (GtkWidget *dialog,
+ gint response_id,
+ GimpTextEditor *editor);
+
+
+/* public functions */
+
+void
+text_tool_load_cmd_callback (GtkAction *action,
+ gpointer data)
+{
+ GimpTextEditor *editor = GIMP_TEXT_EDITOR (data);
+ GtkFileChooser *chooser;
+
+ if (editor->file_dialog)
+ {
+ gtk_window_present (GTK_WINDOW (editor->file_dialog));
+ return;
+ }
+
+ editor->file_dialog =
+ gtk_file_chooser_dialog_new (_("Open Text File (UTF-8)"),
+ GTK_WINDOW (editor),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+
+ NULL);
+
+ chooser = GTK_FILE_CHOOSER (editor->file_dialog);
+
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (editor->file_dialog),
+ GTK_RESPONSE_OK,
+ GTK_RESPONSE_CANCEL,
+ -1);
+
+ g_object_add_weak_pointer (G_OBJECT (chooser),
+ (gpointer) &editor->file_dialog);
+
+ gtk_window_set_role (GTK_WINDOW (chooser), "gimp-text-load-file");
+ gtk_window_set_position (GTK_WINDOW (chooser), GTK_WIN_POS_MOUSE);
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_OK);
+
+ g_signal_connect (chooser, "response",
+ G_CALLBACK (text_tool_load_response),
+ editor);
+ g_signal_connect (chooser, "delete-event",
+ G_CALLBACK (gtk_true),
+ NULL);
+
+ gtk_widget_show (GTK_WIDGET (chooser));
+}
+
+void
+text_tool_clear_cmd_callback (GtkAction *action,
+ gpointer data)
+{
+ GimpTextEditor *editor = GIMP_TEXT_EDITOR (data);
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->view));
+
+ gtk_text_buffer_set_text (buffer, "", 0);
+}
+
+void
+text_tool_direction_cmd_callback (GtkAction *action,
+ GtkAction *current,
+ gpointer data)
+{
+ GimpTextEditor *editor = GIMP_TEXT_EDITOR (data);
+ gint value;
+
+ value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
+
+ /*
+ gimp_text_tool_set_direction (editor, (GimpTextDirection) value);
+ */
+}
+
+
+/* private functions */
+
+static void
+text_tool_load_response (GtkWidget *dialog,
+ gint response_id,
+ GimpTextEditor *editor)
+{
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ GtkTextBuffer *buffer;
+ gchar *filename;
+ GError *error = NULL;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->view));
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ if (! gimp_text_buffer_load (buffer, filename, &error))
+ {
+ gimp_message (editor->ui_manager->gimp, G_OBJECT (dialog),
+ GIMP_MESSAGE_ERROR,
+ _("Could not open '%s' for reading: %s"),
+ gimp_filename_to_utf8 (filename),
+ error->message);
+ g_clear_error (&error);
+ g_free (filename);
+ return;
+ }
+
+ g_free (filename);
+ }
+
+ gtk_widget_destroy (dialog);
+}
Added: branches/soc-2008-text/app/actions/text-tool-commands.h
==============================================================================
--- (empty file)
+++ branches/soc-2008-text/app/actions/text-tool-commands.h Sun Aug 3 21:23:07 2008
@@ -0,0 +1,32 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __TEXT_TOOL_COMMANDS_H__
+#define __TEXT_TOOL_COMMANDS_H__
+
+
+void text_tool_load_cmd_callback (GtkAction *action,
+ gpointer data);
+void text_tool_clear_cmd_callback (GtkAction *action,
+ gpointer data);
+void text_tool_direction_cmd_callback (GtkAction *action,
+ GtkAction *current,
+ gpointer data);
+
+
+#endif /* __TEXT_TOOL_COMMANDS_H__ */
Modified: branches/soc-2008-text/app/display/gimpdisplayshell-callbacks.c
==============================================================================
--- branches/soc-2008-text/app/display/gimpdisplayshell-callbacks.c (original)
+++ branches/soc-2008-text/app/display/gimpdisplayshell-callbacks.c Sun Aug 3 21:23:07 2008
@@ -839,10 +839,17 @@
case 3:
state |= GDK_BUTTON3_MASK;
- gimp_ui_manager_ui_popup (shell->popup_manager,
- "/dummy-menubar/image-popup",
- GTK_WIDGET (shell),
- NULL, NULL, NULL, NULL);
+ if(gimp_tool_control_get_show_context_menu (active_tool->control))
+ {
+ g_signal_emit_by_name (active_tool, "show-popup", &image_coords);
+ }
+ else
+ {
+ gimp_ui_manager_ui_popup (shell->popup_manager,
+ "/dummy-menubar/image-popup",
+ GTK_WIDGET (shell),
+ NULL, NULL, NULL, NULL);
+ }
break;
default:
@@ -1234,10 +1241,10 @@
GdkEventKey *kevent = (GdkEventKey *) event;
if(gimp_tool_control_get_wants_all_key_events (active_tool->control))
- {
- tool_manager_key_press_active (gimp, kevent, display);
- return TRUE;
- }
+ {
+ tool_manager_key_press_active (gimp, kevent, display);
+ return TRUE;
+ }
GIMP_LOG (TOOL_EVENTS, "event (display %p): KEY_PRESS (%d, %s)",
display, kevent->keyval,
Modified: branches/soc-2008-text/app/menus/menus.c
==============================================================================
--- branches/soc-2008-text/app/menus/menus.c (original)
+++ branches/soc-2008-text/app/menus/menus.c Sun Aug 3 21:23:07 2008
@@ -337,6 +337,14 @@
NULL,
NULL);
+ gimp_menu_factory_manager_register (global_menu_factory, "<TextTool>",
+ "text-tool",
+ NULL,
+ "/text-tool-popup",
+ "text-tool-menu.xml",
+ NULL,
+ NULL);
+
gimp_menu_factory_manager_register (global_menu_factory, "<CursorInfo>",
"cursor-info",
NULL,
Modified: branches/soc-2008-text/app/tools/gimptexttool.c
==============================================================================
--- branches/soc-2008-text/app/tools/gimptexttool.c (original)
+++ branches/soc-2008-text/app/tools/gimptexttool.c Sun Aug 3 21:23:07 2008
@@ -41,12 +41,14 @@
#include "core/gimpimage-undo-push.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimplist.h"
+#include "core/gimpmarshal.h"
#include "core/gimptoolinfo.h"
#include "core/gimpundostack.h"
#include "text/gimptext.h"
#include "text/gimptext-vectors.h"
#include "text/gimptextlayer.h"
+#include "text/gimptextlayout.h"
#include "text/gimptextundo.h"
#include "text/gimptext-private.h"
@@ -54,10 +56,12 @@
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimphelp-ids.h"
+#include "widgets/gimpmenufactory.h"
#include "widgets/gimptexteditor.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
#include "gimpeditselectiontool.h"
#include "gimprectangletool.h"
@@ -154,6 +158,10 @@
static void gimp_text_tool_draw (GimpDrawTool *draw_tool);
+static void gimp_text_tool_update_layout (GimpTextTool *text_tool);
+
+static void gimp_text_tool_show_context_menu (GimpTextTool *text_tool, GimpCoords *coords);
+
/* IM Context Callbacks
*/
static void gimp_text_tool_commit_cb (GtkIMContext *context,
@@ -168,8 +176,6 @@
const gchar *str);
static void gimp_text_tool_delete_text (GimpTextTool *text_tool);
-static void gimp_text_tool_update_layout (GimpTextTool *text_tool);
-
G_DEFINE_TYPE_WITH_CODE (GimpTextTool, gimp_text_tool,
GIMP_TYPE_DRAW_TOOL,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_RECTANGLE_TOOL,
@@ -212,13 +218,21 @@
tool_class->control = gimp_text_tool_control;
tool_class->button_press = gimp_text_tool_button_press;
- tool_class->motion = gimp_rectangle_tool_motion;
+ tool_class->motion = gimp_text_tool_motion;
tool_class->button_release = gimp_text_tool_button_release;
tool_class->key_press = gimp_text_tool_key_press;
tool_class->oper_update = gimp_rectangle_tool_oper_update;
tool_class->cursor_update = gimp_text_tool_cursor_update;
draw_tool_class->draw = gimp_text_tool_draw;
+
+ g_signal_new ("show-popup",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ gimp_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_INT);
}
static void
@@ -359,6 +373,9 @@
GimpDrawable *drawable;
GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (tool);
+ gint cx, cy;
+ gint x1, y1;
+ gint x2, y2;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
@@ -371,9 +388,27 @@
text_tool->x1 = coords->x;
text_tool->y1 = coords->y;
- gimp_rectangle_tool_button_press (tool, coords, time, state, display);
+ g_object_get (rect_tool,
+ "x1", &x1,
+ "y1", &y1,
+ "x2", &x2,
+ "y2", &y2,
+ NULL);
+
+ cx = coords->x;
+ cy = coords->y;
+
+ if (x1 <= cx && x2 >= cx && y1 <= cy && y2 >= cy)
+ {
+ text_tool->text_cursor_changing = TRUE;
+ gimp_tool_control_activate (tool->control);
+ }
+ else
+ {
+ text_tool->text_cursor_changing = FALSE;
+ gimp_rectangle_tool_button_press (tool, coords, time, state, display);
+ }
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
/* bail out now if the rectangle is narrow and the button
press is outside the layer */
@@ -385,9 +420,14 @@
gdouble y = coords->y - item->offset_y;
if (x < 0 || x > item->width || y < 0 || y > item->height)
+ {
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
return;
+ }
}
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+
drawable = gimp_image_get_active_drawable (display->image);
gimp_text_tool_set_drawable (text_tool, drawable, FALSE);
@@ -406,39 +446,41 @@
{
/* did the user click on a text layer? */
- if (text_tool->layout)
- {
- GtkTextIter cursor, start, end;
- gint offset;
- gint trailing;
- gchar *string;
-
- gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
-
- string = gtk_text_buffer_get_text (text_tool->text_buffer, &start, &end, TRUE);
-
- pango_layout_xy_to_index (text_tool->layout->layout, x * PANGO_SCALE, y * PANGO_SCALE, &offset, &trailing);
-
- offset = g_utf8_pointer_to_offset (string, (string + offset));
-
- g_free (string);
-
- gtk_text_buffer_get_iter_at_offset (text_tool->text_buffer, &cursor, offset);
- gtk_text_buffer_place_cursor (text_tool->text_buffer, &cursor);
- }
if (gimp_text_tool_set_drawable (text_tool, drawable, TRUE))
{
- /* on second click, open the text editor */
- /*
- if (text && text_tool->text == text)
- gimp_text_tool_editor (text_tool);
- */
/*enable keyboard-handling for the text*/
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
if (text && text_tool->text == text)
+ {
gimp_text_tool_canvas_editor (text_tool);
+ gtk_text_buffer_set_text (text_tool->text_buffer, text_tool->text->text, -1);
+
+ if (text_tool->layout)
+ {
+ gimp_text_tool_update_layout (text_tool);
+ }
+ }
+
+ if (text_tool->layout)
+ {
+ GtkTextIter cursor, start, end;
+ gint offset;
+ gint trailing;
+ gchar *string;
+
+ gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
+ string = gtk_text_buffer_get_text (text_tool->text_buffer, &start, &end, TRUE);
+ pango_layout_xy_to_index (text_tool->layout->layout, x * PANGO_SCALE, y * PANGO_SCALE, &offset, &trailing);
+ offset = g_utf8_pointer_to_offset (string, (string + offset)) + trailing;
+
+ g_free (string);
+
+ gtk_text_buffer_get_iter_at_offset (text_tool->text_buffer, &cursor, offset);
+ gtk_text_buffer_place_cursor (text_tool->text_buffer, &cursor);
+ }
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
return;
-
}
}
}
@@ -447,6 +489,10 @@
text_tool->text_box_fixed = FALSE;
gimp_text_tool_connect (text_tool, NULL, NULL);
gimp_text_tool_canvas_editor (text_tool);
+ if (text_tool->text)
+ gtk_text_buffer_set_text (text_tool->text_buffer, text_tool->text->text, -1);
+ else
+ gtk_text_buffer_set_text (text_tool->text_buffer, "", -1);
}
#define MIN_LAYER_WIDTH 20
@@ -478,13 +524,15 @@
GimpText *text = text_tool->text;
gint x1, y1, x2, y2;
- g_object_get (rect_tool,
+ g_object_get (text_tool,
"x1", &x1,
"y1", &y1,
"x2", &x2,
"y2", &y2,
NULL);
+ text_tool->text_cursor_changing = FALSE;
+
if (text && text_tool->text == text)
{
if (gimp_rectangle_tool_rectangle_is_new (rect_tool))
@@ -496,11 +544,13 @@
gimp_rectangle_tool_frame_item (rect_tool,
GIMP_ITEM (text_tool->layer));
text_tool->handle_rectangle_change_complete = TRUE;
+
return;
}
else
{
/* user has modified shape of an existing text layer */
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
if (text_tool->layout)
{
GimpItem *item = GIMP_ITEM (text_tool->layer);
@@ -523,6 +573,7 @@
gtk_text_buffer_get_iter_at_offset (text_tool->text_buffer, &cursor, offset);
gtk_text_buffer_move_mark_by_name (text_tool->text_buffer, "selection_bound", &cursor);
}
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
}
else if (y2 - y1 < MIN_LAYER_WIDTH)
@@ -547,17 +598,47 @@
void
gimp_text_tool_motion (GimpTool *tool,
- GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpDisplay *display)
+ GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpDisplay *display)
{
gdouble snapped_x;
gdouble snapped_y;
gint snap_x, snap_y;
- /*This function will do more things soon*/
- gimp_rectangle_tool_motion (tool, coords, time, state, display);
+ GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
+ if (text_tool->text_cursor_changing)
+ {
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
+ if (text_tool->layout)
+ {
+ GimpItem *item = GIMP_ITEM (text_tool->layer);
+ gdouble x = coords->x - item->offset_x;
+ gdouble y = coords->y - item->offset_y;
+ GtkTextIter cursor, start, end;
+ gint offset, trailing;
+ gchar *string;
+
+ gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
+
+ string = gtk_text_buffer_get_text (text_tool->text_buffer, &start, &end, TRUE);
+
+ pango_layout_xy_to_index (text_tool->layout->layout, x * PANGO_SCALE, y * PANGO_SCALE, &offset, &trailing);
+
+ offset = g_utf8_pointer_to_offset (string, (string + offset)) + trailing;
+
+ g_free (string);
+
+ gtk_text_buffer_get_iter_at_offset (text_tool->text_buffer, &cursor, offset);
+ gtk_text_buffer_move_mark_by_name (text_tool->text_buffer, "selection_bound", &cursor);
+ }
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+ }
+ else
+ {
+ gimp_rectangle_tool_motion (tool, coords, time, state, display);
+ }
}
static gboolean
@@ -572,13 +653,8 @@
if (gtk_im_context_filter_keypress ( text_tool->im_context, kevent))
{
- /* if (!text_tool->layout) */
- /*gimp_text_tool_update_layout (text_tool);*/
return TRUE;
}
-/*
- gtk_text_buffer_get_selection_bounds (text_tool->text_buffer, &cursor, &selection);
-*/
gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer, &cursor,
gtk_text_buffer_get_insert (text_tool->text_buffer));
gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer, &selection,
@@ -667,7 +743,36 @@
{
/* FIXME: should do something fancy here... */
- gimp_rectangle_tool_cursor_update (tool, coords, state, display);
+ GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
+
+ if (tool->display == display)
+ {
+ gint x, y;
+
+ gint x1, y1;
+ gint x2, y2;
+
+ x = coords->x;
+ y = coords->y;
+
+ g_object_get (G_OBJECT (tool),
+ "x1", &x1,
+ "y1", &y1,
+ "x2", &x2,
+ "y2", &y2,
+ NULL);
+
+ if (x1 <= x && x2 >= x && y1 <= y && y2 >= y)
+ {
+ GimpCursorType cursor = GDK_XTERM;
+ gimp_tool_control_set_cursor (tool->control, cursor);
+ }
+ else
+ {
+ gimp_rectangle_tool_cursor_update (tool, coords, state, display);
+ }
+ }
+
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
@@ -1150,17 +1255,35 @@
gimp_text_tool_canvas_editor (GimpTextTool *text_tool)
{
GimpTool *tool = GIMP_TOOL (text_tool);
+ GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool);
+ GimpDialogFactory *dialog_factory;
+ GtkWindow *parent = NULL;
+ GtkWidget *im_menu;
if (gimp_tool_control_get_wants_all_key_events (tool->control))
return;
gimp_tool_control_set_wants_all_key_events (tool->control, TRUE);
+
+ gimp_tool_control_set_show_context_menu (tool->control, TRUE);
+
+ dialog_factory = gimp_dialog_factory_from_name ("toplevel");
+ text_tool->ui_manager = gimp_menu_factory_manager_new (dialog_factory->menu_factory,
+ "<TextTool>",
+ text_tool, FALSE);
+
+ im_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget (GTK_UI_MANAGER (text_tool->ui_manager),
+ "/text-tool-popup/text-tool-input-methods") ));
+
+ gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (text_tool->im_context), GTK_MENU_SHELL (im_menu));
g_signal_connect (text_tool->im_context, "commit",
G_CALLBACK (gimp_text_tool_commit_cb), text_tool);
g_signal_connect (text_tool->im_context, "preedit_changed",
G_CALLBACK (gimp_text_tool_preedit_changed_cb), text_tool);
+ g_signal_connect (text_tool, "show-popup",
+ G_CALLBACK (gimp_text_tool_show_context_menu), NULL);
}
static void
@@ -1231,7 +1354,7 @@
{
GtkTextIter start, end;
gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
- return g_strdup( gtk_text_buffer_get_text(text_tool->text_buffer, &start, &end, TRUE) );
+ return gtk_text_buffer_get_text(text_tool->text_buffer, &start, &end, TRUE);
}
static void
@@ -1764,9 +1887,8 @@
gimp_text_tool_enter_text (text_tool, str);
}
-/* TODO: This function does nothing right now.
- * Check what it really does, possibly
- * something with advanced input methods. */
+/* TODO: This function does nothing right now,
+ * but it will be used for special Input Methods */
static void
gimp_text_tool_preedit_changed_cb (GtkIMContext *context,
const gchar *str,
@@ -1776,9 +1898,9 @@
gchar *string;
gint cursor;
-
+/*
gtk_im_context_get_preedit_string (text_tool->im_context, &string, NULL, &cursor);
-
+*/
}
static void
@@ -1786,7 +1908,9 @@
{
GtkTextIter cursor, start, end;
- gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer, &cursor, gtk_text_buffer_get_insert (text_tool->text_buffer));
+ gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer,
+ &cursor,
+ gtk_text_buffer_get_insert (text_tool->text_buffer));
if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
@@ -1796,8 +1920,13 @@
if (text_tool->text)
{
+ gchar *string;
+
gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
- g_object_set (text_tool->proxy, "text", gtk_text_buffer_get_text ( text_tool->text_buffer, &start, &end, TRUE) , NULL);
+ string = gtk_text_buffer_get_text (text_tool->text_buffer, &start, &end, TRUE);
+ g_object_set (text_tool->proxy, "text",
+ string, NULL);
+ g_free (string);
}
else
{
@@ -1816,8 +1945,13 @@
if (text_tool->text)
{
+ gchar *string;
+
gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
- g_object_set (text_tool->proxy, "text", gtk_text_buffer_get_text ( text_tool->text_buffer, &start, &end, TRUE) , NULL);
+ string = gtk_text_buffer_get_text (text_tool->text_buffer, &start, &end, TRUE);
+ g_object_set (text_tool->proxy, "text",
+ string, NULL);
+ g_free (string);
}
else
{
@@ -1839,3 +1973,38 @@
text_tool->layout = gimp_text_layout_new (text_tool->layer->text, image);
}
+
+static void
+gimp_text_tool_show_context_menu (GimpTextTool *text_tool, GimpCoords *coords)
+{
+ GimpTool *tool;
+ GimpDisplayShell *shell;
+ gint cx, cy;
+ gint x1, y1, x2, y2;
+
+ tool = GIMP_TOOL (text_tool);
+
+ shell = GIMP_DISPLAY_SHELL (tool->display->shell);
+ g_object_get (text_tool,
+ "x1", &x1,
+ "y1", &y1,
+ "x2", &x2,
+ "y2", &y2,
+ NULL);
+
+ cx = coords->x;
+ cy = coords->y;
+
+ if (x1 > cx || x2 < cx || y1 > cy || y2 < cy)
+ {
+ gimp_ui_manager_ui_popup (shell->popup_manager,
+ "/dummy-menubar/image-popup",
+ GTK_WIDGET (shell),
+ NULL, NULL, NULL, NULL);
+ return;
+ }
+ gimp_ui_manager_ui_popup (text_tool->ui_manager,
+ "/text-tool-popup",
+ GTK_WIDGET (shell),
+ NULL, NULL, NULL, NULL);
+}
Modified: branches/soc-2008-text/app/tools/gimptexttool.h
==============================================================================
--- branches/soc-2008-text/app/tools/gimptexttool.h (original)
+++ branches/soc-2008-text/app/tools/gimptexttool.h Sun Aug 3 21:23:07 2008
@@ -54,10 +54,12 @@
GtkWidget *editor;
GtkWidget *confirm_dialog;
+ GtkWidget *ui_manager;
GtkIMContext *im_context;
gboolean handle_rectangle_change_complete;
gboolean text_box_fixed;
+ gboolean text_cursor_changing;
GimpTextLayout *layout;
};
Modified: branches/soc-2008-text/app/tools/gimptoolcontrol.c
==============================================================================
--- branches/soc-2008-text/app/tools/gimptoolcontrol.c (original)
+++ branches/soc-2008-text/app/tools/gimptoolcontrol.c Sun Aug 3 21:23:07 2008
@@ -64,6 +64,8 @@
control->wants_all_key_events = FALSE;
+ control->show_context_menu = NULL;
+
control->cursor = GIMP_CURSOR_MOUSE;
control->tool_cursor = GIMP_TOOL_CURSOR_NONE;
control->cursor_modifier = GIMP_CURSOR_MODIFIER_NONE;
@@ -290,6 +292,21 @@
}
void
+gimp_tool_control_set_show_context_menu (GimpToolControl *control,
+ gboolean show_context_menu)
+{
+ g_return_val_if_fail (GIMP_IS_TOOL_CONTROL (control), FALSE);
+ control->show_context_menu = show_context_menu;
+}
+
+gboolean
+gimp_tool_control_get_show_context_menu (GimpToolControl *control)
+{
+ g_return_val_if_fail (GIMP_IS_TOOL_CONTROL (control), FALSE);
+ return control->show_context_menu;
+}
+
+void
gimp_tool_control_set_snap_offsets (GimpToolControl *control,
gint offset_x,
gint offset_y,
Modified: branches/soc-2008-text/app/tools/gimptoolcontrol.h
==============================================================================
--- branches/soc-2008-text/app/tools/gimptoolcontrol.h (original)
+++ branches/soc-2008-text/app/tools/gimptoolcontrol.h Sun Aug 3 21:23:07 2008
@@ -61,6 +61,8 @@
gboolean wants_all_key_events;
+ gboolean show_context_menu;
+
GimpCursorType cursor;
GimpToolCursorType tool_cursor;
GimpCursorModifier cursor_modifier;
@@ -125,6 +127,10 @@
gboolean snap_to);
gboolean gimp_tool_control_get_wants_all_key_events (GimpToolControl *control);
+void gimp_tool_control_set_show_context_menu (GimpToolControl *control,
+ gboolean show_context_menu);
+gboolean gimp_tool_control_get_show_context_menu (GimpToolControl *control);
+
void gimp_tool_control_set_snap_offsets (GimpToolControl *control,
gint offset_x,
gint offset_y,
Modified: branches/soc-2008-text/menus/Makefile.am
==============================================================================
--- branches/soc-2008-text/menus/Makefile.am (original)
+++ branches/soc-2008-text/menus/Makefile.am Sun Aug 3 21:23:07 2008
@@ -31,6 +31,7 @@
selection-menu.xml \
templates-menu.xml \
text-editor-toolbar.xml \
+ text-tool-menu.xml \
tool-options-menu.xml \
tools-menu.xml \
undo-menu.xml \
Added: branches/soc-2008-text/menus/text-tool-menu.xml
==============================================================================
--- (empty file)
+++ branches/soc-2008-text/menus/text-tool-menu.xml Sun Aug 3 21:23:07 2008
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE ui SYSTEM "gtkuimanager.dtd">
+
+<ui>
+ <popup action="text-tool-popup">
+ <menuitem action="text-tool-cut" />
+ <menuitem action="text-tool-copy" />
+ <menuitem action="text-tool-paste" />
+ <menuitem action="text-tool-delete" />
+ <separator />
+ <menuitem action="text-tool-load" />
+ <menuitem action="text-tool-clear" />
+ <separator />
+ <menuitem action="text-tool-direction-ltr" />
+ <menuitem action="text-tool-direction-rtl" />
+ <separator />
+ <menu action="text-tool-input-methods">
+ <menuitem action="text-tool-load" />
+ </menu>
+ </popup>
+</ui>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]