1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-03-22 23:19:19 +08:00
|
|
|
* GimpTextTool
|
|
|
|
* Copyright (C) 2002-2004 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
1997-11-25 06:05:25 +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 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2002-10-13 16:45:00 +08:00
|
|
|
#include <stdio.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2002-10-15 06:07:39 +08:00
|
|
|
#include <string.h>
|
2002-10-12 01:42:26 +08:00
|
|
|
#include <errno.h>
|
1999-05-05 06:18:13 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-19 07:12:26 +08:00
|
|
|
|
2003-02-05 16:45:26 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "core/gimp.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
2004-03-20 07:08:24 +08:00
|
|
|
#include "core/gimpimage-undo-push.h"
|
2004-01-20 01:21:53 +08:00
|
|
|
#include "core/gimplayer-floating-sel.h"
|
2001-11-21 07:00:47 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2004-03-22 07:14:21 +08:00
|
|
|
#include "core/gimpundo.h"
|
|
|
|
#include "core/gimpundostack.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2003-01-30 06:20:09 +08:00
|
|
|
#include "text/gimptext.h"
|
2003-07-24 21:10:27 +08:00
|
|
|
#include "text/gimptext-vectors.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "text/gimptextlayer.h"
|
2004-03-22 07:14:21 +08:00
|
|
|
#include "text/gimptextundo.h"
|
2003-01-30 06:20:09 +08:00
|
|
|
|
2003-06-27 22:26:04 +08:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2004-03-12 02:47:37 +08:00
|
|
|
#include "widgets/gimptexteditor.h"
|
2004-03-20 00:29:36 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
2001-05-26 00:04:54 +08:00
|
|
|
|
2005-03-10 00:58:54 +08:00
|
|
|
#include "vectors/gimpvectors-warp.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2004-06-05 01:51:32 +08:00
|
|
|
#include "gimpeditselectiontool.h"
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "gimptextoptions.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimptexttool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2001-01-23 21:01:48 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
|
2001-08-12 01:24:47 +08:00
|
|
|
|
2004-03-22 07:14:21 +08:00
|
|
|
#define TEXT_UNDO_TIMEOUT 3
|
|
|
|
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2004-03-15 01:54:23 +08:00
|
|
|
static void gimp_text_tool_class_init (GimpTextToolClass *klass);
|
|
|
|
static void gimp_text_tool_init (GimpTextTool *tool);
|
|
|
|
static GObject * gimp_text_tool_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
static void gimp_text_tool_dispose (GObject *object);
|
|
|
|
static void gimp_text_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_text_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_text_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_text_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
static void gimp_text_tool_connect (GimpTextTool *text_tool,
|
2004-03-22 22:32:47 +08:00
|
|
|
GimpTextLayer *layer,
|
2004-03-15 01:54:23 +08:00
|
|
|
GimpText *text);
|
2004-03-22 22:32:47 +08:00
|
|
|
static void gimp_text_tool_layer_notify (GimpTextLayer *layer,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool);
|
2004-03-20 21:26:02 +08:00
|
|
|
static void gimp_text_tool_proxy_notify (GimpText *text,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool);
|
2004-03-18 23:27:23 +08:00
|
|
|
static void gimp_text_tool_text_notify (GimpText *text,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool);
|
2004-03-15 02:48:00 +08:00
|
|
|
static gboolean gimp_text_tool_idle_apply (GimpTextTool *text_tool);
|
2004-03-16 08:16:52 +08:00
|
|
|
static void gimp_text_tool_apply (GimpTextTool *text_tool);
|
2004-03-15 01:54:23 +08:00
|
|
|
|
|
|
|
static void gimp_text_tool_create_vectors (GimpTextTool *text_tool);
|
2005-03-10 00:58:54 +08:00
|
|
|
static void gimp_text_tool_create_vectors_warped
|
|
|
|
(GimpTextTool *text_tool);
|
2004-03-20 00:29:36 +08:00
|
|
|
static void gimp_text_tool_create_layer (GimpTextTool *text_tool,
|
|
|
|
GimpText *text);
|
2004-03-15 01:54:23 +08:00
|
|
|
|
|
|
|
static void gimp_text_tool_editor (GimpTextTool *text_tool);
|
2004-03-22 23:19:19 +08:00
|
|
|
static void gimp_text_tool_editor_update (GimpTextTool *text_tool);
|
2004-03-15 01:54:23 +08:00
|
|
|
static void gimp_text_tool_text_changed (GimpTextEditor *editor,
|
|
|
|
GimpTextTool *text_tool);
|
2003-02-02 05:50:21 +08:00
|
|
|
|
2005-02-20 03:10:33 +08:00
|
|
|
static void gimp_text_tool_layer_changed (GimpImage *image,
|
|
|
|
GimpTextTool *text_tool);
|
2004-03-19 04:55:00 +08:00
|
|
|
static void gimp_text_tool_set_image (GimpTextTool *text_tool,
|
|
|
|
GimpImage *image);
|
2004-03-20 00:29:36 +08:00
|
|
|
static gboolean gimp_text_tool_set_drawable (GimpTextTool *text_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gboolean confirm);
|
2004-03-19 04:55:00 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* local variables */
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2004-02-12 08:03:42 +08:00
|
|
|
static GimpToolClass *parent_class = NULL;
|
1998-10-07 16:59:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
/* public functions */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_text_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_TEXT_TOOL,
|
2003-02-05 22:39:40 +08:00
|
|
|
GIMP_TYPE_TEXT_OPTIONS,
|
|
|
|
gimp_text_options_gui,
|
2004-03-12 02:47:37 +08:00
|
|
|
GIMP_CONTEXT_FOREGROUND_MASK | GIMP_CONTEXT_FONT_MASK,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-text-tool",
|
2002-11-01 07:06:09 +08:00
|
|
|
_("Text"),
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Add text to the image"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("Te_xt"), "T",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_TEXT,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_TEXT,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
GType
|
2001-02-25 05:06:48 +08:00
|
|
|
gimp_text_tool_get_type (void)
|
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
static GType tool_type = 0;
|
2001-02-25 05:06:48 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
sizeof (GimpTextToolClass),
|
2004-06-05 07:08:29 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_text_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpTextTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_text_tool_init,
|
2001-02-25 05:06:48 +08:00
|
|
|
};
|
|
|
|
|
2004-02-12 08:03:42 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
|
2004-06-05 07:08:29 +08:00
|
|
|
"GimpTextTool",
|
2001-08-11 23:35:16 +08:00
|
|
|
&tool_info, 0);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static void
|
2001-02-25 05:06:48 +08:00
|
|
|
gimp_text_tool_class_init (GimpTextToolClass *klass)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2004-03-15 01:54:23 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2004-03-15 01:54:23 +08:00
|
|
|
object_class->constructor = gimp_text_tool_constructor;
|
|
|
|
object_class->dispose = gimp_text_tool_dispose;
|
|
|
|
object_class->finalize = gimp_text_tool_finalize;
|
|
|
|
|
2003-07-25 00:40:22 +08:00
|
|
|
tool_class->control = gimp_text_tool_control;
|
|
|
|
tool_class->button_press = gimp_text_tool_button_press;
|
2004-06-13 02:41:52 +08:00
|
|
|
tool_class->key_press = gimp_edit_selection_tool_key_press;
|
2003-07-25 00:40:22 +08:00
|
|
|
tool_class->cursor_update = gimp_text_tool_cursor_update;
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_init (GimpTextTool *text_tool)
|
|
|
|
{
|
2002-10-11 02:37:12 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
2003-02-01 02:57:10 +08:00
|
|
|
|
2004-03-15 01:54:23 +08:00
|
|
|
text_tool->proxy = NULL;
|
2004-03-15 02:48:00 +08:00
|
|
|
text_tool->pending = NULL;
|
2004-03-15 01:54:23 +08:00
|
|
|
text_tool->idle_id = 0;
|
|
|
|
|
|
|
|
text_tool->text = NULL;
|
|
|
|
text_tool->layer = NULL;
|
2004-03-19 04:55:00 +08:00
|
|
|
text_tool->image = NULL;
|
2003-02-01 02:57:10 +08:00
|
|
|
|
2005-04-07 18:33:58 +08:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_TOOL_CURSOR_TEXT);
|
2005-03-05 03:05:40 +08:00
|
|
|
gimp_tool_control_set_action_object_1 (tool->control,
|
|
|
|
"context/context-font-select-set");
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
2004-03-15 01:54:23 +08:00
|
|
|
static GObject *
|
|
|
|
gimp_text_tool_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GimpTextTool *text_tool;
|
|
|
|
GimpTextOptions *options;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
text_tool = GIMP_TEXT_TOOL (object);
|
|
|
|
options = GIMP_TEXT_OPTIONS (GIMP_TOOL (text_tool)->tool_info->tool_options);
|
|
|
|
|
|
|
|
text_tool->proxy = g_object_new (GIMP_TYPE_TEXT, NULL);
|
|
|
|
|
|
|
|
gimp_text_options_connect_text (options, text_tool->proxy);
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
g_signal_connect_object (text_tool->proxy, "notify",
|
2004-03-20 21:26:02 +08:00
|
|
|
G_CALLBACK (gimp_text_tool_proxy_notify),
|
|
|
|
text_tool, 0);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-15 01:54:23 +08:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_dispose (GObject *object)
|
|
|
|
{
|
2004-03-19 04:55:00 +08:00
|
|
|
GimpTextTool *text_tool = GIMP_TEXT_TOOL (object);
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_set_drawable (text_tool, NULL, FALSE);
|
2004-03-15 01:54:23 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpTextTool *text_tool = GIMP_TEXT_TOOL (object);
|
|
|
|
|
|
|
|
if (text_tool->proxy)
|
|
|
|
{
|
|
|
|
g_object_unref (text_tool->proxy);
|
|
|
|
text_tool->proxy = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2003-03-11 09:22:57 +08:00
|
|
|
gimp_text_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-05 00:52:35 +08:00
|
|
|
GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
|
2004-01-20 01:21:53 +08:00
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
|
|
|
case RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_set_drawable (text_tool, NULL, FALSE);
|
2001-02-25 05:06:48 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-11 09:22:57 +08:00
|
|
|
gimp_text_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2004-02-05 00:52:35 +08:00
|
|
|
GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
|
2004-03-20 00:29:36 +08:00
|
|
|
GimpText *text = text_tool->text;
|
2003-02-01 02:57:10 +08:00
|
|
|
GimpDrawable *drawable;
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-11 09:22:57 +08:00
|
|
|
text_tool->x1 = coords->x;
|
|
|
|
text_tool->y1 = coords->y;
|
2001-08-12 02:41:47 +08:00
|
|
|
|
2003-02-01 02:57:10 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_set_drawable (text_tool, drawable, FALSE);
|
2003-07-25 00:40:22 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
if (GIMP_IS_LAYER (drawable))
|
2004-03-19 04:55:00 +08:00
|
|
|
{
|
2004-03-20 00:29:36 +08:00
|
|
|
GimpItem *item = GIMP_ITEM (drawable);
|
2003-02-01 02:57:10 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
coords->x -= item->offset_x;
|
|
|
|
coords->y -= item->offset_y;
|
2004-02-11 22:44:01 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
if (coords->x > 0 && coords->x < item->width &&
|
|
|
|
coords->y > 0 && coords->y < item->height)
|
|
|
|
{
|
|
|
|
/* did the user click on a text layer? */
|
|
|
|
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);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-03-13 08:47:31 +08:00
|
|
|
}
|
2004-03-20 00:29:36 +08:00
|
|
|
|
|
|
|
/* create a new text layer */
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (text_tool, NULL, NULL);
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_editor (text_tool);
|
2003-03-11 09:22:57 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2003-03-11 09:22:57 +08:00
|
|
|
gimp_text_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-03-12 02:47:37 +08:00
|
|
|
/* FIXME: should do something fancy here... */
|
|
|
|
|
2002-02-05 01:43:01 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
static void
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (GimpTextTool *text_tool,
|
|
|
|
GimpTextLayer *layer,
|
|
|
|
GimpText *text)
|
2004-03-15 02:48:00 +08:00
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
g_return_if_fail (text == NULL || (layer != NULL && layer->text == text));
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
if (! text && text_tool->editor)
|
|
|
|
gtk_widget_destroy (text_tool->editor);
|
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (text_tool->text != text)
|
2004-03-15 02:48:00 +08:00
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
GimpTextOptions *options;
|
|
|
|
GtkWidget *button;
|
2005-03-10 00:58:54 +08:00
|
|
|
GtkWidget *button2;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
options = GIMP_TEXT_OPTIONS (tool->tool_info->tool_options);
|
2005-03-10 00:58:54 +08:00
|
|
|
button = g_object_get_data (G_OBJECT (options), "gimp-text-to-vectors");
|
|
|
|
button2 = g_object_get_data (G_OBJECT (options), "gimp-text-to-vectors-warped");
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (text_tool->text)
|
2004-03-15 02:48:00 +08:00
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (text_tool->text,
|
|
|
|
gimp_text_tool_text_notify,
|
2004-03-15 02:48:00 +08:00
|
|
|
text_tool);
|
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (text_tool->pending)
|
|
|
|
gimp_text_tool_apply (text_tool);
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
g_signal_handlers_disconnect_by_func (button,
|
|
|
|
gimp_text_tool_create_vectors,
|
|
|
|
text_tool);
|
|
|
|
}
|
|
|
|
|
2005-03-10 00:58:54 +08:00
|
|
|
if (button2)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (button2, FALSE);
|
|
|
|
g_signal_handlers_disconnect_by_func (button2,
|
|
|
|
gimp_text_tool_create_vectors_warped,
|
|
|
|
text_tool);
|
|
|
|
}
|
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
g_object_unref (text_tool->text);
|
|
|
|
text_tool->text = NULL;
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-25 17:02:28 +08:00
|
|
|
g_object_set (text_tool->proxy, "text", NULL, NULL);
|
2004-03-22 22:32:47 +08:00
|
|
|
}
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_context_define_property (GIMP_CONTEXT (options),
|
|
|
|
GIMP_CONTEXT_PROP_FOREGROUND,
|
|
|
|
text != NULL);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (text)
|
|
|
|
{
|
2005-04-07 18:33:58 +08:00
|
|
|
gimp_config_sync (G_OBJECT (text), G_OBJECT (text_tool->proxy), 0);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
text_tool->text = g_object_ref (text);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
g_signal_connect (text, "notify",
|
|
|
|
G_CALLBACK (gimp_text_tool_text_notify),
|
|
|
|
text_tool);
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (gimp_text_tool_create_vectors),
|
|
|
|
text_tool);
|
|
|
|
gtk_widget_set_sensitive (button, TRUE);
|
|
|
|
}
|
2004-03-22 23:19:19 +08:00
|
|
|
|
2005-03-10 00:58:54 +08:00
|
|
|
if (button2)
|
|
|
|
{
|
|
|
|
g_signal_connect_swapped (button2, "clicked",
|
|
|
|
G_CALLBACK (gimp_text_tool_create_vectors_warped),
|
|
|
|
text_tool);
|
|
|
|
gtk_widget_set_sensitive (button2, TRUE);
|
|
|
|
}
|
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
if (text_tool->editor)
|
|
|
|
gimp_text_tool_editor_update (text_tool);
|
2004-03-22 22:32:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text_tool->layer != layer)
|
|
|
|
{
|
|
|
|
if (text_tool->layer)
|
2004-03-15 02:48:00 +08:00
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (text_tool->layer,
|
|
|
|
gimp_text_tool_layer_notify,
|
|
|
|
text_tool);
|
|
|
|
text_tool->layer = NULL;
|
2004-03-15 02:48:00 +08:00
|
|
|
}
|
2004-03-22 22:32:47 +08:00
|
|
|
|
|
|
|
text_tool->layer = layer;
|
|
|
|
|
|
|
|
if (layer)
|
|
|
|
g_signal_connect_object (text_tool->layer, "notify::modified",
|
|
|
|
G_CALLBACK (gimp_text_tool_layer_notify),
|
|
|
|
text_tool, 0);
|
2004-03-15 02:48:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_layer_notify (GimpTextLayer *layer,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
if (layer->modified)
|
|
|
|
gimp_text_tool_connect (text_tool, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
static void
|
2004-03-20 21:26:02 +08:00
|
|
|
gimp_text_tool_proxy_notify (GimpText *text,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool)
|
2004-03-15 02:48:00 +08:00
|
|
|
{
|
|
|
|
if (! text_tool->text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((pspec->flags & G_PARAM_READWRITE) == G_PARAM_READWRITE)
|
|
|
|
{
|
|
|
|
text_tool->pending = g_list_append (text_tool->pending, pspec);
|
|
|
|
|
|
|
|
if (text_tool->idle_id)
|
|
|
|
g_source_remove (text_tool->idle_id);
|
|
|
|
|
|
|
|
text_tool->idle_id =
|
|
|
|
g_idle_add_full (G_PRIORITY_LOW,
|
|
|
|
(GSourceFunc) gimp_text_tool_idle_apply, text_tool,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_text_notify (GimpText *text,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
g_return_if_fail (text == text_tool->text);
|
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
if ((pspec->flags & G_PARAM_READWRITE) == G_PARAM_READWRITE)
|
2004-03-20 21:26:02 +08:00
|
|
|
{
|
2004-03-22 23:19:19 +08:00
|
|
|
GValue value = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&value, pspec->value_type);
|
2004-03-20 21:26:02 +08:00
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
g_object_get_property (G_OBJECT (text), pspec->name, &value);
|
2004-03-20 21:26:02 +08:00
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
g_signal_handlers_block_by_func (text_tool->proxy,
|
|
|
|
gimp_text_tool_proxy_notify,
|
2004-03-20 21:26:02 +08:00
|
|
|
text_tool);
|
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
g_object_set_property (G_OBJECT (text_tool->proxy), pspec->name, &value);
|
2004-03-20 21:26:02 +08:00
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
g_signal_handlers_unblock_by_func (text_tool->proxy,
|
|
|
|
gimp_text_tool_proxy_notify,
|
2004-03-20 21:26:02 +08:00
|
|
|
text_tool);
|
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
g_value_unset (&value);
|
2004-03-20 21:26:02 +08:00
|
|
|
}
|
2004-03-22 23:19:19 +08:00
|
|
|
|
|
|
|
if (text_tool->editor && strcmp (pspec->name, "text") == 0)
|
|
|
|
gimp_text_tool_editor_update (text_tool);
|
2004-03-18 23:27:23 +08:00
|
|
|
}
|
|
|
|
|
2004-03-16 08:16:52 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_text_tool_idle_apply (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
text_tool->idle_id = 0;
|
|
|
|
|
|
|
|
gimp_text_tool_apply (text_tool);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_apply (GimpTextTool *text_tool)
|
|
|
|
{
|
2004-03-21 01:21:48 +08:00
|
|
|
const GParamSpec *pspec = NULL;
|
|
|
|
GimpImage *image;
|
2004-03-22 22:32:47 +08:00
|
|
|
GimpTextLayer *layer;
|
2004-03-21 01:21:48 +08:00
|
|
|
GObject *src;
|
|
|
|
GObject *dest;
|
|
|
|
GList *list;
|
2004-04-11 02:11:00 +08:00
|
|
|
gboolean push_undo = TRUE;
|
|
|
|
gboolean undo_group = FALSE;
|
2004-03-15 02:48:00 +08:00
|
|
|
|
|
|
|
if (text_tool->idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove (text_tool->idle_id);
|
|
|
|
text_tool->idle_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_if_fail (text_tool->text != NULL);
|
2004-03-20 03:26:18 +08:00
|
|
|
g_return_if_fail (text_tool->layer != NULL);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
layer = text_tool->layer;
|
|
|
|
image = gimp_item_get_image (GIMP_ITEM (layer));
|
2004-03-20 07:08:24 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
g_return_if_fail (layer->text == text_tool->text);
|
2004-03-20 07:08:24 +08:00
|
|
|
|
2004-03-21 01:21:48 +08:00
|
|
|
/* Walk over the list of changes and figure out if we are changing
|
|
|
|
* a single property or need to push a full text undo.
|
|
|
|
*/
|
|
|
|
for (list = text_tool->pending;
|
|
|
|
list && list->next && list->next->data == list->data;
|
|
|
|
list = list->next)
|
|
|
|
/* do nothing */;
|
|
|
|
|
|
|
|
if (g_list_length (list) == 1)
|
|
|
|
pspec = list->data;
|
|
|
|
|
2004-07-13 01:10:34 +08:00
|
|
|
/* If we are changing a single property, we don't need to push
|
|
|
|
* an undo if all of the following is true:
|
|
|
|
* - the redo stack is empty
|
|
|
|
* - the last item on the undo stack is a text undo
|
|
|
|
* - the last undo changed the same text property on the same layer
|
|
|
|
* - the last undo happened less than TEXT_UNDO_TIMEOUT seconds ago
|
|
|
|
*/
|
2004-08-03 22:09:49 +08:00
|
|
|
if (pspec)
|
2004-03-22 07:14:21 +08:00
|
|
|
{
|
2004-08-03 22:09:49 +08:00
|
|
|
GimpUndo *undo = gimp_image_undo_can_compress (image, GIMP_TYPE_TEXT_UNDO,
|
|
|
|
GIMP_UNDO_TEXT_LAYER);
|
2004-03-22 07:14:21 +08:00
|
|
|
|
2004-08-03 22:09:49 +08:00
|
|
|
if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (layer))
|
2004-03-22 07:14:21 +08:00
|
|
|
{
|
|
|
|
GimpTextUndo *text_undo = GIMP_TEXT_UNDO (undo);
|
2004-03-20 07:08:24 +08:00
|
|
|
|
2004-08-03 22:09:49 +08:00
|
|
|
if (text_undo->pspec == pspec)
|
2004-03-22 07:14:21 +08:00
|
|
|
{
|
|
|
|
guint now = time (NULL);
|
|
|
|
|
2004-07-13 01:10:34 +08:00
|
|
|
if (now >= undo->time &&
|
|
|
|
now - undo->time < TEXT_UNDO_TIMEOUT)
|
2004-03-22 07:14:21 +08:00
|
|
|
{
|
|
|
|
push_undo = FALSE;
|
2004-07-13 01:10:34 +08:00
|
|
|
undo->time = now;
|
2004-03-22 07:14:21 +08:00
|
|
|
gimp_undo_refresh_preview (undo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (push_undo)
|
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
if (layer->modified)
|
2004-04-01 22:51:58 +08:00
|
|
|
{
|
2004-04-11 02:11:00 +08:00
|
|
|
undo_group = TRUE;
|
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TEXT, NULL);
|
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
gimp_image_undo_push_text_layer_modified (image, NULL, layer);
|
2004-04-11 02:11:00 +08:00
|
|
|
gimp_image_undo_push_drawable_mod (image,
|
|
|
|
NULL, GIMP_DRAWABLE (layer));
|
2004-04-01 22:51:58 +08:00
|
|
|
}
|
2004-03-22 07:14:21 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_image_undo_push_text_layer (image, NULL, layer, pspec);
|
2004-03-22 07:14:21 +08:00
|
|
|
}
|
2004-03-20 07:08:24 +08:00
|
|
|
|
2004-03-16 08:16:52 +08:00
|
|
|
src = G_OBJECT (text_tool->proxy);
|
|
|
|
dest = G_OBJECT (text_tool->text);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
g_signal_handlers_block_by_func (dest,
|
|
|
|
gimp_text_tool_text_notify, text_tool);
|
|
|
|
|
2004-03-16 08:16:52 +08:00
|
|
|
g_object_freeze_notify (dest);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-21 01:21:48 +08:00
|
|
|
for (; list; list = list->next)
|
2004-03-15 02:48:00 +08:00
|
|
|
{
|
2004-03-21 01:21:48 +08:00
|
|
|
GValue value = { 0, };
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-16 08:16:52 +08:00
|
|
|
/* look ahead and compress changes */
|
|
|
|
if (list->next && list->next->data == list->data)
|
|
|
|
continue;
|
|
|
|
|
2004-03-21 01:21:48 +08:00
|
|
|
pspec = list->data;
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
g_value_init (&value, pspec->value_type);
|
|
|
|
|
2004-03-16 08:16:52 +08:00
|
|
|
g_object_get_property (src, pspec->name, &value);
|
|
|
|
g_object_set_property (dest, pspec->name, &value);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
|
2004-03-20 07:08:24 +08:00
|
|
|
g_list_free (text_tool->pending);
|
|
|
|
text_tool->pending = NULL;
|
|
|
|
|
2004-03-16 08:16:52 +08:00
|
|
|
g_object_thaw_notify (dest);
|
2004-03-15 02:48:00 +08:00
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
g_signal_handlers_unblock_by_func (dest,
|
|
|
|
gimp_text_tool_text_notify, text_tool);
|
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
if (push_undo)
|
|
|
|
{
|
|
|
|
g_object_set (layer, "modified", FALSE, NULL);
|
|
|
|
|
2004-04-11 02:11:00 +08:00
|
|
|
if (undo_group)
|
|
|
|
gimp_image_undo_group_end (image);
|
2004-04-01 22:51:58 +08:00
|
|
|
}
|
2004-03-16 01:53:55 +08:00
|
|
|
|
2004-03-22 07:14:21 +08:00
|
|
|
gimp_image_flush (image);
|
2004-03-15 02:48:00 +08:00
|
|
|
}
|
|
|
|
|
2003-07-24 21:10:27 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_create_vectors (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
|
|
|
|
2004-03-21 04:10:05 +08:00
|
|
|
if (! text_tool->text || ! text_tool->image)
|
2003-07-24 21:10:27 +08:00
|
|
|
return;
|
|
|
|
|
2004-03-21 04:10:05 +08:00
|
|
|
vectors = gimp_text_vectors_new (text_tool->image, text_tool->text);
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2004-03-13 08:47:31 +08:00
|
|
|
if (text_tool->layer)
|
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
gimp_item_offsets (GIMP_ITEM (text_tool->layer), &x, &y);
|
|
|
|
gimp_item_translate (GIMP_ITEM (vectors), x, y, FALSE);
|
|
|
|
}
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2004-03-21 04:10:05 +08:00
|
|
|
gimp_image_add_vectors (text_tool->image, vectors, -1);
|
2003-07-25 01:07:05 +08:00
|
|
|
|
2004-03-21 04:10:05 +08:00
|
|
|
gimp_image_flush (text_tool->image);
|
2003-07-24 21:10:27 +08:00
|
|
|
}
|
|
|
|
|
2005-03-10 00:58:54 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors0;
|
|
|
|
GimpVectors *vectors;
|
|
|
|
GimpText *text = text_tool->text;
|
|
|
|
gdouble box_height;
|
|
|
|
|
|
|
|
if (! text || ! text_tool->image || ! text_tool->layer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
box_height = gimp_item_height (GIMP_ITEM (text_tool->layer));
|
|
|
|
|
|
|
|
vectors0 = gimp_image_get_active_vectors (text_tool->image);
|
|
|
|
if (! vectors0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vectors = gimp_text_vectors_new (text_tool->image, text_tool->text);
|
|
|
|
|
|
|
|
gimp_vectors_warp_vectors (vectors0, vectors, 0.5 * box_height);
|
|
|
|
|
|
|
|
gimp_image_add_vectors (text_tool->image, vectors, -1);
|
2005-03-11 00:37:55 +08:00
|
|
|
gimp_image_set_active_vectors (text_tool->image, vectors);
|
|
|
|
gimp_item_set_visible (GIMP_ITEM (vectors), TRUE, FALSE);
|
2005-03-10 00:58:54 +08:00
|
|
|
|
|
|
|
gimp_image_flush (text_tool->image);
|
|
|
|
}
|
|
|
|
|
2003-03-11 09:22:57 +08:00
|
|
|
static void
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_create_layer (GimpTextTool *text_tool,
|
|
|
|
GimpText *text)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-03-15 01:54:23 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GimpImage *image;
|
|
|
|
GimpLayer *layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
text = gimp_config_duplicate (GIMP_CONFIG (text));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-13 16:59:10 +08:00
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = gimp_text_editor_get_text (GIMP_TEXT_EDITOR (text_tool->editor));
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
g_object_set (text_tool->proxy,
|
2004-07-13 16:59:10 +08:00
|
|
|
"text", str,
|
2004-03-20 00:29:36 +08:00
|
|
|
NULL);
|
2003-02-01 02:57:10 +08:00
|
|
|
|
2004-07-13 16:59:10 +08:00
|
|
|
g_free (str);
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
text = gimp_config_duplicate (GIMP_CONFIG (text_tool->proxy));
|
|
|
|
}
|
2001-08-14 21:49:21 +08:00
|
|
|
|
2004-03-13 11:19:53 +08:00
|
|
|
image = tool->gdisp->gimage;
|
|
|
|
layer = gimp_text_layer_new (image, text);
|
2004-03-15 01:54:23 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
g_object_unref (text);
|
|
|
|
|
2004-01-20 01:21:53 +08:00
|
|
|
if (! layer)
|
2002-10-11 01:07:46 +08:00
|
|
|
return;
|
2001-08-14 21:49:21 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (text_tool, GIMP_TEXT_LAYER (layer), text);
|
2004-01-20 01:21:53 +08:00
|
|
|
|
2004-03-13 11:19:53 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TEXT,
|
2003-02-13 19:23:50 +08:00
|
|
|
_("Add Text Layer"));
|
1998-02-22 18:45:12 +08:00
|
|
|
|
2004-03-13 11:19:53 +08:00
|
|
|
if (gimp_image_floating_sel (image))
|
2005-02-20 03:10:33 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (image,
|
|
|
|
gimp_text_tool_layer_changed,
|
|
|
|
text_tool);
|
|
|
|
|
|
|
|
floating_sel_anchor (gimp_image_floating_sel (image));
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (image,
|
|
|
|
gimp_text_tool_layer_changed,
|
|
|
|
text_tool);
|
|
|
|
}
|
2004-01-20 01:21:53 +08:00
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
GIMP_ITEM (layer)->offset_x = text_tool->x1;
|
|
|
|
GIMP_ITEM (layer)->offset_y = text_tool->y1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-13 11:19:53 +08:00
|
|
|
gimp_image_add_layer (image, layer, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-13 11:19:53 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2002-10-11 01:07:46 +08:00
|
|
|
|
2004-03-13 11:19:53 +08:00
|
|
|
gimp_image_flush (image);
|
2004-03-13 08:47:31 +08:00
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
gimp_text_tool_set_drawable (text_tool, GIMP_DRAWABLE (layer), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
static void
|
2003-03-11 09:22:57 +08:00
|
|
|
gimp_text_tool_editor (GimpTextTool *text_tool)
|
2002-10-11 02:37:12 +08:00
|
|
|
{
|
2004-11-23 00:03:54 +08:00
|
|
|
GimpTextOptions *options;
|
|
|
|
GimpDialogFactory *dialog_factory;
|
2002-10-11 02:37:12 +08:00
|
|
|
|
|
|
|
if (text_tool->editor)
|
|
|
|
{
|
2002-10-25 09:11:24 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (text_tool->editor));
|
2002-10-11 02:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
options = GIMP_TEXT_OPTIONS (GIMP_TOOL (text_tool)->tool_info->tool_options);
|
2002-10-11 02:37:12 +08:00
|
|
|
|
2004-11-23 00:03:54 +08:00
|
|
|
dialog_factory = gimp_dialog_factory_from_name ("toplevel");
|
|
|
|
|
2003-03-31 23:10:15 +08:00
|
|
|
text_tool->editor = gimp_text_options_editor_new (options,
|
2004-11-23 00:03:54 +08:00
|
|
|
dialog_factory->menu_factory,
|
2003-03-31 23:10:15 +08:00
|
|
|
_("GIMP Text Editor"));
|
2002-10-12 01:42:26 +08:00
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (text_tool->editor),
|
2003-02-02 05:50:21 +08:00
|
|
|
(gpointer *) &text_tool->editor);
|
2002-10-11 02:37:12 +08:00
|
|
|
|
2004-11-23 00:03:54 +08:00
|
|
|
gimp_dialog_factory_add_foreign (dialog_factory,
|
2003-06-27 22:26:04 +08:00
|
|
|
"gimp-text-tool-dialog",
|
|
|
|
text_tool->editor);
|
|
|
|
|
2004-03-12 08:36:17 +08:00
|
|
|
if (text_tool->text)
|
|
|
|
gimp_text_editor_set_text (GIMP_TEXT_EDITOR (text_tool->editor),
|
|
|
|
text_tool->text->text, -1);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect_object (text_tool->editor, "text-changed",
|
2004-03-12 08:36:17 +08:00
|
|
|
G_CALLBACK (gimp_text_tool_text_changed),
|
|
|
|
text_tool, 0);
|
2004-03-12 02:47:37 +08:00
|
|
|
|
|
|
|
gtk_widget_show (text_tool->editor);
|
2002-10-11 02:37:12 +08:00
|
|
|
}
|
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_editor_update (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
gchar *str = NULL;
|
|
|
|
|
|
|
|
if (! text_tool->editor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (text_tool->text)
|
|
|
|
g_object_get (text_tool->text, "text", &str, NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (text_tool->editor,
|
|
|
|
gimp_text_tool_text_changed, text_tool);
|
|
|
|
|
|
|
|
gimp_text_editor_set_text (GIMP_TEXT_EDITOR (text_tool->editor),
|
|
|
|
str, str ? -1 : 0);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (text_tool->editor,
|
|
|
|
gimp_text_tool_text_changed, text_tool);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
static void
|
2004-03-12 02:47:37 +08:00
|
|
|
gimp_text_tool_text_changed (GimpTextEditor *editor,
|
|
|
|
GimpTextTool *text_tool)
|
2002-10-11 02:37:12 +08:00
|
|
|
{
|
2004-03-12 02:47:37 +08:00
|
|
|
if (text_tool->text)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
text = gimp_text_editor_get_text (GIMP_TEXT_EDITOR (text_tool->editor));
|
|
|
|
|
2004-03-15 01:54:23 +08:00
|
|
|
g_object_set (text_tool->proxy, "text", text, NULL);
|
2004-03-12 02:47:37 +08:00
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_create_layer (text_tool, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RESPONSE_NEW 1
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_confirm_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
GimpTextLayer *layer = text_tool->layer;
|
2004-03-20 00:29:36 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (widget);
|
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (layer && layer->text)
|
2004-03-20 00:29:36 +08:00
|
|
|
{
|
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case RESPONSE_NEW:
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_create_layer (text_tool, layer->text);
|
2004-03-20 00:29:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_OK:
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (text_tool, layer, layer->text);
|
2004-03-22 23:19:19 +08:00
|
|
|
gimp_text_tool_editor (text_tool);
|
2004-03-20 00:29:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_confirm_dialog (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
g_return_if_fail (text_tool->layer != NULL);
|
|
|
|
|
|
|
|
if (text_tool->confirm_dialog)
|
|
|
|
{
|
|
|
|
gtk_window_present (GTK_WINDOW (text_tool->confirm_dialog));
|
|
|
|
return;
|
2004-03-12 02:47:37 +08:00
|
|
|
}
|
2004-03-20 00:29:36 +08:00
|
|
|
|
|
|
|
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (text_tool->layer),
|
|
|
|
_("Confirm Text Editing"),
|
|
|
|
"gimp-text-tool-confirm",
|
|
|
|
GIMP_STOCK_TEXT_LAYER,
|
|
|
|
_("Confirm Text Editing"),
|
|
|
|
tool->gdisp->shell,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
tool->tool_info->help_id,
|
2005-09-28 02:51:44 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
GTK_STOCK_NEW, RESPONSE_NEW,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2005-09-19 21:07:24 +08:00
|
|
|
GTK_STOCK_EDIT, GTK_RESPONSE_OK,
|
2005-09-28 02:51:44 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
NULL);
|
|
|
|
|
2005-02-10 19:00:46 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-09-28 02:51:44 +08:00
|
|
|
RESPONSE_NEW,
|
2005-02-10 19:00:46 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gimp_text_tool_confirm_response),
|
|
|
|
text_tool);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
2004-05-26 21:39:23 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
2004-03-20 00:29:36 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
|
|
|
|
vbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
label = gtk_label_new (_("The layer you selected is a text layer but "
|
|
|
|
"it has been modified using other tools. "
|
|
|
|
"Editing the layer with the text tool will "
|
|
|
|
"discard these modifications."
|
|
|
|
"\n\n"
|
|
|
|
"You can edit the layer or create a new "
|
|
|
|
"text layer from its text attributes."));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
|
|
|
text_tool->confirm_dialog = dialog;
|
|
|
|
g_signal_connect_swapped (dialog, "destroy",
|
|
|
|
G_CALLBACK (g_nullify_pointer),
|
|
|
|
&text_tool->confirm_dialog);
|
2002-10-12 01:42:26 +08:00
|
|
|
}
|
2004-01-14 03:08:16 +08:00
|
|
|
|
2004-03-13 08:47:31 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_layer_changed (GimpImage *image,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
2004-03-20 00:29:36 +08:00
|
|
|
GimpLayer *layer = gimp_image_get_active_layer (image);
|
|
|
|
|
|
|
|
gimp_text_tool_set_drawable (text_tool, GIMP_DRAWABLE (layer), FALSE);
|
2004-03-13 08:47:31 +08:00
|
|
|
}
|
|
|
|
|
2004-03-19 04:55:00 +08:00
|
|
|
static void
|
|
|
|
gimp_text_tool_set_image (GimpTextTool *text_tool,
|
|
|
|
GimpImage *image)
|
2004-01-14 03:08:16 +08:00
|
|
|
{
|
2004-03-19 04:55:00 +08:00
|
|
|
if (text_tool->image == image)
|
|
|
|
return;
|
2004-02-09 06:09:57 +08:00
|
|
|
|
2004-03-19 04:55:00 +08:00
|
|
|
if (text_tool->image)
|
2004-02-09 06:09:57 +08:00
|
|
|
{
|
2004-03-19 04:55:00 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (text_tool->image,
|
|
|
|
gimp_text_tool_layer_changed,
|
|
|
|
text_tool);
|
2004-03-13 08:47:31 +08:00
|
|
|
|
2004-03-19 04:55:00 +08:00
|
|
|
g_object_remove_weak_pointer (G_OBJECT (text_tool->image),
|
|
|
|
(gpointer *) &text_tool->image);
|
|
|
|
text_tool->image = NULL;
|
|
|
|
}
|
2004-02-09 06:09:57 +08:00
|
|
|
|
2004-03-19 04:55:00 +08:00
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
GimpToolOptions *options;
|
2004-02-09 06:09:57 +08:00
|
|
|
|
2004-03-19 04:55:00 +08:00
|
|
|
text_tool->image = image;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (text_tool->image),
|
|
|
|
(gpointer *) &text_tool->image);
|
2004-03-13 11:57:01 +08:00
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect_object (text_tool->image, "active-layer-changed",
|
2004-03-13 08:47:31 +08:00
|
|
|
G_CALLBACK (gimp_text_tool_layer_changed),
|
|
|
|
text_tool, 0);
|
2004-03-19 04:55:00 +08:00
|
|
|
|
|
|
|
options = GIMP_TOOL (text_tool)->tool_info->tool_options;
|
|
|
|
gimp_size_entry_set_resolution (GIMP_TEXT_OPTIONS (options)->size_entry,
|
|
|
|
0, image->yresolution, FALSE);
|
2004-03-13 08:47:31 +08:00
|
|
|
}
|
2004-03-19 04:55:00 +08:00
|
|
|
}
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_text_tool_set_drawable (GimpTextTool *text_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gboolean confirm)
|
2004-03-19 04:55:00 +08:00
|
|
|
{
|
2004-03-20 00:29:36 +08:00
|
|
|
GimpImage *image = NULL;
|
2004-03-13 08:47:31 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
if (text_tool->confirm_dialog)
|
|
|
|
gtk_widget_destroy (text_tool->confirm_dialog);
|
2004-03-13 11:19:53 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
if (drawable)
|
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2004-03-13 11:19:53 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_set_image (text_tool, image);
|
2004-03-16 08:16:52 +08:00
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
if (drawable && GIMP_IS_LAYER (drawable))
|
|
|
|
{
|
|
|
|
if (GIMP_IS_TEXT_LAYER (drawable) && GIMP_TEXT_LAYER (drawable)->text)
|
2004-03-19 04:55:00 +08:00
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
|
2004-03-20 00:29:36 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (layer == text_tool->layer && layer->text == text_tool->text)
|
|
|
|
return TRUE;
|
2004-03-20 00:29:36 +08:00
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
if (layer->modified)
|
2004-03-20 00:29:36 +08:00
|
|
|
{
|
|
|
|
if (confirm)
|
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (text_tool, layer, NULL);
|
2004-03-20 00:29:36 +08:00
|
|
|
gimp_text_tool_confirm_dialog (text_tool);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (text_tool, layer, layer->text);
|
2004-03-20 00:29:36 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-19 04:55:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 22:32:47 +08:00
|
|
|
gimp_text_tool_connect (text_tool, NULL, NULL);
|
2004-03-20 03:26:18 +08:00
|
|
|
text_tool->layer = NULL;
|
|
|
|
|
2004-03-20 00:29:36 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_tool_set_layer (GimpTextTool *text_tool,
|
|
|
|
GimpLayer *layer)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_TEXT_TOOL (text_tool));
|
|
|
|
g_return_if_fail (layer == NULL || GIMP_IS_LAYER (layer));
|
|
|
|
|
2004-03-22 23:19:19 +08:00
|
|
|
if (gimp_text_tool_set_drawable (text_tool, GIMP_DRAWABLE (layer), TRUE))
|
|
|
|
gimp_text_tool_editor (text_tool);
|
2004-01-14 03:08:16 +08:00
|
|
|
}
|