gtk2/gtk/gtkoldeditable.c

858 lines
24 KiB
C
Raw Normal View History

Make parent_class static. Sun Nov 5 04:24:53 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkcellrenderertextpixbuf.c: Make parent_class static. Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch] gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c: Add support for positioning the cursor within the preedit string. Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtktextview.c: Check for bindings after passing events to im context filter. Mon Sep 18 11:50:51 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtktextlayout.c (add_preedit_attrs): Handle empty attribute lists properly. Sun Sep 17 10:08:16 2000 Owen Taylor <otaylor@redhat.com> * gtk/queryimmodules.c (main): Return non-zero exit status if errors were encountered querying any modules. Sat Sep 16 14:01:52 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtk.h: include gtkmodule.h gtkoldeditable.h, don't include gtkthemes.h. * gtk/testgtk.c gtk/testtext.c: Set environment variables to point * gtk/Makefile.am: Add new .c and .h files, build gtk-query-immodules and use it to create a gtk.immodules file for use of test programs. * gtk/gtkpreview.c: remove extra blank line. Sat Sep 16 13:21:04 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkimcontextsimple.c (gtk_im_context_simple_add_table): Add the ability to add extra tables beyond the default one, and also the ability to have compose sequences that are prefixes of other compose sequences. * gtk/gtkimcontextsimple.c: Export a preedit string which consists of possible candidates for keystrokes that have been entered but not yet committed. * gtk/gtkimcontext.[ch] gtk/immulticontext.[ch] gtk/gtkimcontextsimple.[ch]: add gtk_im_context_reset() * gtk/gtkmulticontext.[ch] (gtk_im_multicontext_append_menuitems): Add a function to add input-method switching menu items to a menu. * gtk/gtkimmulticontext.[ch]: Properly handly set_client_window when switching input methods. * gtk/gtkimcontextsimple.[ch]: Change the format of the compose table to allow compose tables of different lengths / sequence. Sat Sep 16 13:05:48 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkimmodule.[ch]: Support routines for loading GtkIMContext implementations dynamically at runtime. * gtk/queryimmodules.c: Program to query the available input modules and write the results into a file. * gtk/gtkrc.[ch] (gtk_rc_get_im_module_file): Add extra config options "im_module_file" (cache file for input method modules), and "im_module_path" - path to look for modules when generating cache file. This doesn't scale. Sat Sep 16 13:09:06 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkthemes.[ch] gtk/gtkmodule.[ch]: Move most of the generic code from gtkthemes into a new abstraction GtkModule which has the logic for implementing a loadable module which implements a number of GObject types. Sat Sep 16 13:07:13 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkeditable.[ch]: Convert GtkEditable from a class into an interface * gtk/gtkoldeditable.[ch]: Move the old editable implementation into here, so legacy widgets can still rely on the implemenation. GtkOldEditable exports GtkEditable. Make selection handling code use new text conversion functions (and handle UTF-8 as a side-effect). Use GtkClipboard for CLIPBOARD. * gtk/gtktext.[ch] gtk/gtkcombo.c gtk/gtkspinbutton.c: Adopt to match above changes. * gtk/gtkentry.[ch]: Implement GtkEditable directly, avoid GtkOldEditable implementation. Restructure to reduce number of places that modify state directly. Move to GtkBindingSet. Display the preedit string. Queue recomputation of PangoLayout and scroll position to improve effiency of doing complex changes naively. Add a menu with cut/copy/paste and input method selection. Thu Sep 14 22:11:05 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtktextlayout.[ch]: Add gtk_text_layout_set_preedit_string() to set preedit string and attributes; display preedit string by inserting string and attributes at cursor when creating the GtkTextLineDisplay. * gtk/gtktextlayout.c: Move all conversions between byte positions in PangoLayout and GtkTextIter into new functions line_display_iter_to_index/index_to_iter that properly handle the preedit string. * gtk/gtktextmark.[ch]: Restore gtk_text_mark_get_name, modify it to return const char * (eventually will end up as GCONST char *, most likely.) * gtk/gtktextview.[ch]: Handle the preedit string, call gtk_im_context_reset() as necessary, add a menu to switch input methods. * gtk/gtktextlayout.[ch]: Remove useless gtk_text_layout_get_log_attrs() function.
2000-11-12 03:43:24 +00:00
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include <ctype.h>
#include <string.h>
#include "gdk/gdkkeysyms.h"
#include "gdk/gdki18n.h"
#include "gtkclipboard.h"
#include "gtkoldeditable.h"
#include "gtkmain.h"
#include "gtkselection.h"
#include "gtksignal.h"
#define MIN_EDITABLE_WIDTH 150
#define DRAW_TIMEOUT 20
#define INNER_BORDER 2
enum {
CHANGED,
INSERT_TEXT,
DELETE_TEXT,
/* Binding actions */
ACTIVATE,
SET_EDITABLE,
MOVE_CURSOR,
MOVE_WORD,
MOVE_PAGE,
MOVE_TO_ROW,
MOVE_TO_COLUMN,
KILL_CHAR,
KILL_WORD,
KILL_LINE,
CUT_CLIPBOARD,
COPY_CLIPBOARD,
PASTE_CLIPBOARD,
LAST_SIGNAL
};
enum {
ARG_0,
ARG_TEXT_POSITION,
ARG_EDITABLE
};
/* values for selection info */
enum {
TARGET_STRING,
TARGET_TEXT,
TARGET_COMPOUND_TEXT
};
static void gtk_old_editable_class_init (GtkOldEditableClass *klass);
static void gtk_old_editable_editable_init (GtkEditableClass *iface);
static void gtk_old_editable_init (GtkOldEditable *editable);
static void gtk_old_editable_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void gtk_old_editable_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void *gtk_old_editable_get_public_chars (GtkOldEditable *old_editable,
gint start,
gint end);
static gint gtk_old_editable_selection_clear (GtkWidget *widget,
GdkEventSelection *event);
static void gtk_old_editable_selection_get (GtkWidget *widget,
GtkSelectionData *selection_data,
guint info,
guint time);
static void gtk_old_editable_selection_received (GtkWidget *widget,
GtkSelectionData *selection_data,
guint time);
static void gtk_old_editable_set_selection (GtkOldEditable *old_editable,
gint start,
gint end);
static void gtk_old_editable_real_set_editable (GtkOldEditable *old_editable,
gboolean is_editable);
static void gtk_old_editable_real_cut_clipboard (GtkOldEditable *old_editable);
static void gtk_old_editable_real_copy_clipboard (GtkOldEditable *old_editable);
static void gtk_old_editable_real_paste_clipboard (GtkOldEditable *old_editable);
static void gtk_old_editable_insert_text (GtkEditable *editable,
const gchar *new_text,
gint new_text_length,
gint *position);
static void gtk_old_editable_delete_text (GtkEditable *editable,
gint start_pos,
gint end_pos);
static gchar * gtk_old_editable_get_chars (GtkEditable *editable,
gint start,
gint end);
static void gtk_old_editable_set_selection_bounds (GtkEditable *editable,
gint start,
gint end);
static gboolean gtk_old_editable_get_selection_bounds (GtkEditable *editable,
gint *start,
gint *end);
static void gtk_old_editable_set_position (GtkEditable *editable,
gint position);
static gint gtk_old_editable_get_position (GtkEditable *editable);
static GtkWidgetClass *parent_class = NULL;
static guint editable_signals[LAST_SIGNAL] = { 0 };
GtkType
gtk_old_editable_get_type (void)
{
static GtkType old_editable_type = 0;
if (!old_editable_type)
{
static const GtkTypeInfo old_editable_info =
{
"GtkOldEditable",
sizeof (GtkOldEditable),
sizeof (GtkOldEditableClass),
(GtkClassInitFunc) gtk_old_editable_class_init,
(GtkObjectInitFunc) gtk_old_editable_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
static const GInterfaceInfo editable_info =
{
(GInterfaceInitFunc) gtk_old_editable_editable_init, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
old_editable_type = gtk_type_unique (GTK_TYPE_WIDGET, &old_editable_info);
g_type_add_interface_static (old_editable_type,
GTK_TYPE_EDITABLE,
&editable_info);
}
return old_editable_type;
}
static void
gtk_old_editable_class_init (GtkOldEditableClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
parent_class = gtk_type_class (GTK_TYPE_WIDGET);
doh, this was broken beyond believe. Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
2000-12-13 01:34:41 +00:00
object_class->set_arg = gtk_old_editable_set_arg;
object_class->get_arg = gtk_old_editable_get_arg;
widget_class->selection_clear_event = gtk_old_editable_selection_clear;
widget_class->selection_received = gtk_old_editable_selection_received;
widget_class->selection_get = gtk_old_editable_selection_get;
class->insert_text = NULL;
class->delete_text = NULL;
class->activate = NULL;
class->set_editable = gtk_old_editable_real_set_editable;
class->move_cursor = NULL;
class->move_word = NULL;
class->move_page = NULL;
class->move_to_row = NULL;
class->move_to_column = NULL;
class->kill_char = NULL;
class->kill_word = NULL;
class->kill_line = NULL;
class->cut_clipboard = gtk_old_editable_real_cut_clipboard;
class->copy_clipboard = gtk_old_editable_real_copy_clipboard;
class->paste_clipboard = gtk_old_editable_real_paste_clipboard;
class->update_text = NULL;
class->get_chars = NULL;
class->set_selection = NULL;
class->set_position = NULL;
Make parent_class static. Sun Nov 5 04:24:53 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkcellrenderertextpixbuf.c: Make parent_class static. Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch] gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c: Add support for positioning the cursor within the preedit string. Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtktextview.c: Check for bindings after passing events to im context filter. Mon Sep 18 11:50:51 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtktextlayout.c (add_preedit_attrs): Handle empty attribute lists properly. Sun Sep 17 10:08:16 2000 Owen Taylor <otaylor@redhat.com> * gtk/queryimmodules.c (main): Return non-zero exit status if errors were encountered querying any modules. Sat Sep 16 14:01:52 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtk.h: include gtkmodule.h gtkoldeditable.h, don't include gtkthemes.h. * gtk/testgtk.c gtk/testtext.c: Set environment variables to point * gtk/Makefile.am: Add new .c and .h files, build gtk-query-immodules and use it to create a gtk.immodules file for use of test programs. * gtk/gtkpreview.c: remove extra blank line. Sat Sep 16 13:21:04 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkimcontextsimple.c (gtk_im_context_simple_add_table): Add the ability to add extra tables beyond the default one, and also the ability to have compose sequences that are prefixes of other compose sequences. * gtk/gtkimcontextsimple.c: Export a preedit string which consists of possible candidates for keystrokes that have been entered but not yet committed. * gtk/gtkimcontext.[ch] gtk/immulticontext.[ch] gtk/gtkimcontextsimple.[ch]: add gtk_im_context_reset() * gtk/gtkmulticontext.[ch] (gtk_im_multicontext_append_menuitems): Add a function to add input-method switching menu items to a menu. * gtk/gtkimmulticontext.[ch]: Properly handly set_client_window when switching input methods. * gtk/gtkimcontextsimple.[ch]: Change the format of the compose table to allow compose tables of different lengths / sequence. Sat Sep 16 13:05:48 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkimmodule.[ch]: Support routines for loading GtkIMContext implementations dynamically at runtime. * gtk/queryimmodules.c: Program to query the available input modules and write the results into a file. * gtk/gtkrc.[ch] (gtk_rc_get_im_module_file): Add extra config options "im_module_file" (cache file for input method modules), and "im_module_path" - path to look for modules when generating cache file. This doesn't scale. Sat Sep 16 13:09:06 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkthemes.[ch] gtk/gtkmodule.[ch]: Move most of the generic code from gtkthemes into a new abstraction GtkModule which has the logic for implementing a loadable module which implements a number of GObject types. Sat Sep 16 13:07:13 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtkeditable.[ch]: Convert GtkEditable from a class into an interface * gtk/gtkoldeditable.[ch]: Move the old editable implementation into here, so legacy widgets can still rely on the implemenation. GtkOldEditable exports GtkEditable. Make selection handling code use new text conversion functions (and handle UTF-8 as a side-effect). Use GtkClipboard for CLIPBOARD. * gtk/gtktext.[ch] gtk/gtkcombo.c gtk/gtkspinbutton.c: Adopt to match above changes. * gtk/gtkentry.[ch]: Implement GtkEditable directly, avoid GtkOldEditable implementation. Restructure to reduce number of places that modify state directly. Move to GtkBindingSet. Display the preedit string. Queue recomputation of PangoLayout and scroll position to improve effiency of doing complex changes naively. Add a menu with cut/copy/paste and input method selection. Thu Sep 14 22:11:05 2000 Owen Taylor <otaylor@redhat.com> * gtk/gtktextlayout.[ch]: Add gtk_text_layout_set_preedit_string() to set preedit string and attributes; display preedit string by inserting string and attributes at cursor when creating the GtkTextLineDisplay. * gtk/gtktextlayout.c: Move all conversions between byte positions in PangoLayout and GtkTextIter into new functions line_display_iter_to_index/index_to_iter that properly handle the preedit string. * gtk/gtktextmark.[ch]: Restore gtk_text_mark_get_name, modify it to return const char * (eventually will end up as GCONST char *, most likely.) * gtk/gtktextview.[ch]: Handle the preedit string, call gtk_im_context_reset() as necessary, add a menu to switch input methods. * gtk/gtktextlayout.[ch]: Remove useless gtk_text_layout_get_log_attrs() function.
2000-11-12 03:43:24 +00:00
editable_signals[CHANGED] =
gtk_signal_new ("changed",
GTK_RUN_LAST,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, changed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
editable_signals[INSERT_TEXT] =
gtk_signal_new ("insert_text",
GTK_RUN_LAST,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, insert_text),
gtk_marshal_NONE__POINTER_INT_POINTER,
GTK_TYPE_NONE,
3,
GTK_TYPE_STRING,
GTK_TYPE_INT,
GTK_TYPE_POINTER);
editable_signals[DELETE_TEXT] =
gtk_signal_new ("delete_text",
GTK_RUN_LAST,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, delete_text),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE,
2,
GTK_TYPE_INT,
GTK_TYPE_INT);
editable_signals[ACTIVATE] =
gtk_signal_new ("activate",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, activate),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
widget_class->activate_signal = editable_signals[ACTIVATE];
editable_signals[SET_EDITABLE] =
gtk_signal_new ("set-editable",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, set_editable),
gtk_marshal_NONE__BOOL,
GTK_TYPE_NONE, 1,
GTK_TYPE_BOOL);
editable_signals[MOVE_CURSOR] =
gtk_signal_new ("move_cursor",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, move_cursor),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2,
GTK_TYPE_INT,
GTK_TYPE_INT);
editable_signals[MOVE_WORD] =
gtk_signal_new ("move_word",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, move_word),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
editable_signals[MOVE_PAGE] =
gtk_signal_new ("move_page",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, move_page),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2,
GTK_TYPE_INT,
GTK_TYPE_INT);
editable_signals[MOVE_TO_ROW] =
gtk_signal_new ("move_to_row",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, move_to_row),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
editable_signals[MOVE_TO_COLUMN] =
gtk_signal_new ("move_to_column",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, move_to_column),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
editable_signals[KILL_CHAR] =
gtk_signal_new ("kill_char",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, kill_char),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
editable_signals[KILL_WORD] =
gtk_signal_new ("kill_word",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, kill_word),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
editable_signals[KILL_LINE] =
gtk_signal_new ("kill_line",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, kill_line),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1,
GTK_TYPE_INT);
editable_signals[CUT_CLIPBOARD] =
gtk_signal_new ("cut_clipboard",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, cut_clipboard),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
editable_signals[COPY_CLIPBOARD] =
gtk_signal_new ("copy_clipboard",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, copy_clipboard),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
editable_signals[PASTE_CLIPBOARD] =
gtk_signal_new ("paste_clipboard",
GTK_RUN_LAST | GTK_RUN_ACTION,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkOldEditableClass, paste_clipboard),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_add_arg_type ("GtkOldEditable::text_position", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_TEXT_POSITION);
gtk_object_add_arg_type ("GtkOldEditable::editable", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE);
}
static void
gtk_old_editable_editable_init (GtkEditableClass *iface)
{
iface->insert_text = gtk_old_editable_insert_text;
iface->delete_text = gtk_old_editable_delete_text;
iface->get_chars = gtk_old_editable_get_chars;
iface->set_selection_bounds = gtk_old_editable_set_selection_bounds;
iface->get_selection_bounds = gtk_old_editable_get_selection_bounds;
iface->set_position = gtk_old_editable_set_position;
iface->get_position = gtk_old_editable_get_position;
}
static void
gtk_old_editable_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GtkEditable *editable = GTK_EDITABLE (object);
switch (arg_id)
{
case ARG_TEXT_POSITION:
gtk_editable_set_position (editable, GTK_VALUE_INT (*arg));
break;
case ARG_EDITABLE:
gtk_signal_emit (object, editable_signals[SET_EDITABLE],
GTK_VALUE_BOOL (*arg) != FALSE);
break;
default:
break;
}
}
static void
gtk_old_editable_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GtkOldEditable *old_editable;
old_editable = GTK_OLD_EDITABLE (object);
switch (arg_id)
{
case ARG_TEXT_POSITION:
GTK_VALUE_INT (*arg) = old_editable->current_pos;
break;
case ARG_EDITABLE:
GTK_VALUE_BOOL (*arg) = old_editable->editable;
break;
default:
arg->type = GTK_TYPE_INVALID;
break;
}
}
static void
gtk_old_editable_init (GtkOldEditable *old_editable)
{
static const GtkTargetEntry targets[] = {
{ "UTF8_STRING", 0, 0 },
{ "STRING", 0, 0 },
{ "TEXT", 0, 0 },
{ "COMPOUND_TEXT", 0, 0 }
};
GTK_WIDGET_SET_FLAGS (old_editable, GTK_CAN_FOCUS);
old_editable->selection_start_pos = 0;
old_editable->selection_end_pos = 0;
old_editable->has_selection = FALSE;
old_editable->editable = 1;
old_editable->visible = 1;
old_editable->clipboard_text = NULL;
#ifdef USE_XIM
old_editable->ic = NULL;
#endif
gtk_selection_add_targets (GTK_WIDGET (old_editable), GDK_SELECTION_PRIMARY,
targets, G_N_ELEMENTS (targets));
}
static void
gtk_old_editable_insert_text (GtkEditable *editable,
const gchar *new_text,
gint new_text_length,
gint *position)
{
gchar buf[64];
gchar *text;
gtk_widget_ref (GTK_WIDGET (editable));
if (new_text_length <= 63)
text = buf;
else
text = g_new (gchar, new_text_length + 1);
text[new_text_length] = '\0';
strncpy (text, new_text, new_text_length);
gtk_signal_emit (GTK_OBJECT (editable), editable_signals[INSERT_TEXT], text, new_text_length, position);
gtk_signal_emit (GTK_OBJECT (editable), editable_signals[CHANGED]);
if (new_text_length > 63)
g_free (text);
gtk_widget_unref (GTK_WIDGET (editable));
}
static void
gtk_old_editable_delete_text (GtkEditable *editable,
gint start_pos,
gint end_pos)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (editable);
gtk_widget_ref (GTK_WIDGET (old_editable));
gtk_signal_emit (GTK_OBJECT (old_editable), editable_signals[DELETE_TEXT], start_pos, end_pos);
gtk_signal_emit (GTK_OBJECT (old_editable), editable_signals[CHANGED]);
if (old_editable->selection_start_pos == old_editable->selection_end_pos &&
old_editable->has_selection)
gtk_old_editable_claim_selection (old_editable, FALSE, GDK_CURRENT_TIME);
gtk_widget_unref (GTK_WIDGET (old_editable));
}
static void
gtk_old_editable_update_text (GtkOldEditable *old_editable,
gint start_pos,
gint end_pos)
{
GtkOldEditableClass *klass = GTK_OLD_EDITABLE_GET_CLASS (old_editable);
klass->update_text (GTK_OLD_EDITABLE (old_editable), start_pos, end_pos);
}
static gchar *
gtk_old_editable_get_chars (GtkEditable *editable,
gint start,
gint end)
{
GtkOldEditableClass *klass = GTK_OLD_EDITABLE_GET_CLASS (editable);
return klass->get_chars (GTK_OLD_EDITABLE (editable), start, end);
}
/*
* Like gtk_editable_get_chars, but if the editable is not
* visible, return asterisks; also convert result to UTF-8.
*/
static void *
gtk_old_editable_get_public_chars (GtkOldEditable *old_editable,
gint start,
gint end)
{
gchar *str = NULL;
gchar *charset;
gboolean need_conversion = !g_get_charset (&charset);
if (old_editable->visible)
{
GError *error;
gchar *tmp = gtk_editable_get_chars (GTK_EDITABLE (old_editable), start, end);
if (need_conversion)
{
str = g_convert (tmp, -1,
"UTF-8", charset,
NULL, NULL, &error);
if (!str)
{
g_warning ("Cannot convert text from charset to UTF-8 %s: %s", charset, error->message);
g_error_free (error);
}
g_free (tmp);
}
else
str = tmp;
}
else
{
gint i;
gint nchars = end - start;
if (nchars < 0)
nchars = -nchars;
str = g_new (gchar, nchars + 1);
for (i = 0; i<nchars; i++)
str[i] = '*';
str[i] = '\0';
}
return str;
}
static void
gtk_old_editable_set_selection (GtkOldEditable *old_editable,
gint start_pos,
gint end_pos)
{
GtkOldEditableClass *klass = GTK_OLD_EDITABLE_GET_CLASS (old_editable);
klass->set_selection (old_editable, start_pos, end_pos);
}
static void
gtk_old_editable_set_position (GtkEditable *editable,
gint position)
{
GtkOldEditableClass *klass = GTK_OLD_EDITABLE_GET_CLASS (editable);
klass->set_position (GTK_OLD_EDITABLE (editable), position);
}
static gint
gtk_old_editable_get_position (GtkEditable *editable)
{
return GTK_OLD_EDITABLE (editable)->current_pos;
}
static gint
gtk_old_editable_selection_clear (GtkWidget *widget,
GdkEventSelection *event)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (widget);
/* Let the selection handling code know that the selection
* has been changed, since we've overriden the default handler */
if (!gtk_selection_clear (widget, event))
return FALSE;
if (old_editable->has_selection)
{
old_editable->has_selection = FALSE;
gtk_old_editable_update_text (old_editable, old_editable->selection_start_pos,
old_editable->selection_end_pos);
}
return TRUE;
}
static void
gtk_old_editable_selection_get (GtkWidget *widget,
GtkSelectionData *selection_data,
guint info,
guint time)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (widget);
gint selection_start_pos;
gint selection_end_pos;
gchar *str;
selection_start_pos = MIN (old_editable->selection_start_pos, old_editable->selection_end_pos);
selection_end_pos = MAX (old_editable->selection_start_pos, old_editable->selection_end_pos);
str = gtk_old_editable_get_public_chars (old_editable,
selection_start_pos,
selection_end_pos);
if (str)
{
gtk_selection_data_set_text (selection_data, str);
g_free (str);
}
}
static void
gtk_old_editable_paste_received (GtkOldEditable *old_editable,
const gchar *text,
gboolean is_clipboard)
{
const gchar *str = NULL;
gchar *charset;
gboolean need_conversion = FALSE;
if (text)
{
GError *error;
need_conversion = !g_get_charset (&charset);
if (need_conversion)
{
str = g_convert_with_fallback (text, -1,
charset, "UTF-8", NULL,
NULL, NULL, &error);
if (!str)
{
g_warning ("Cannot convert text from UTF-8 to %s: %s",
charset, error->message);
g_error_free (error);
return;
}
}
else
str = text;
}
if (str)
{
gboolean reselect;
gint old_pos;
gint tmp_pos;
reselect = FALSE;
if ((old_editable->selection_start_pos != old_editable->selection_end_pos) &&
(!old_editable->has_selection || is_clipboard))
{
reselect = TRUE;
/* Don't want to call gtk_editable_delete_selection here if we are going
* to reclaim the selection to avoid extra server traffic */
if (old_editable->has_selection)
{
gtk_editable_delete_text (GTK_EDITABLE (old_editable),
MIN (old_editable->selection_start_pos, old_editable->selection_end_pos),
MAX (old_editable->selection_start_pos, old_editable->selection_end_pos));
}
else
gtk_editable_delete_selection (GTK_EDITABLE (old_editable));
}
tmp_pos = old_pos = old_editable->current_pos;
gtk_editable_insert_text (GTK_EDITABLE (old_editable), str, -1, &tmp_pos);
if (reselect)
gtk_old_editable_set_selection (old_editable, old_pos, old_editable->current_pos);
if (str && str != text)
g_free ((gchar *) str);
}
}
static void
gtk_old_editable_selection_received (GtkWidget *widget,
GtkSelectionData *selection_data,
guint time)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (widget);
gchar *text = gtk_selection_data_get_text (selection_data);
if (!text)
{
/* If we asked for UTF8 and didn't get it, try text; if we asked
* for text and didn't get it, try string. If we asked for
* anything else and didn't get it, give up.
*/
if (selection_data->target == gdk_atom_intern ("UTF8_STRING", FALSE))
{
gtk_selection_convert (widget, GDK_SELECTION_PRIMARY,
gdk_atom_intern ("TEXT", FALSE),
time);
return;
}
else if (selection_data->target == gdk_atom_intern ("TEXT", FALSE))
{
gtk_selection_convert (widget, GDK_SELECTION_PRIMARY,
GDK_TARGET_STRING,
time);
return;
}
}
if (text)
{
gtk_old_editable_paste_received (old_editable, text, FALSE);
g_free (text);
}
}
static void
old_editable_text_received_cb (GtkClipboard *clipboard,
const gchar *text,
gpointer data)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (data);
gtk_old_editable_paste_received (old_editable, text, TRUE);
g_object_unref (G_OBJECT (old_editable));
}
void
gtk_old_editable_claim_selection (GtkOldEditable *old_editable,
gboolean claim,
guint32 time)
{
g_return_if_fail (old_editable != NULL);
g_return_if_fail (GTK_IS_OLD_EDITABLE (old_editable));
g_return_if_fail (GTK_WIDGET_REALIZED (old_editable));
old_editable->has_selection = FALSE;
if (claim)
{
if (gtk_selection_owner_set (GTK_WIDGET (old_editable), GDK_SELECTION_PRIMARY, time))
old_editable->has_selection = TRUE;
}
else
{
if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == GTK_WIDGET (old_editable)->window)
gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY, time);
}
}
static void
gtk_old_editable_set_selection_bounds (GtkEditable *editable,
gint start,
gint end)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (editable);
if (GTK_WIDGET_REALIZED (editable))
gtk_old_editable_claim_selection (old_editable, start != end, GDK_CURRENT_TIME);
gtk_old_editable_set_selection (old_editable, start, end);
}
static gboolean
gtk_old_editable_get_selection_bounds (GtkEditable *editable,
gint *start,
gint *end)
{
GtkOldEditable *old_editable = GTK_OLD_EDITABLE (editable);
*start = old_editable->selection_start_pos;
*end = old_editable->selection_end_pos;
return (old_editable->selection_start_pos != old_editable->selection_end_pos);
}
static void
gtk_old_editable_real_set_editable (GtkOldEditable *old_editable,
gboolean is_editable)
{
is_editable = is_editable != FALSE;
if (old_editable->editable != is_editable)
{
old_editable->editable = is_editable;
gtk_widget_queue_draw (GTK_WIDGET (old_editable));
}
}
static void
gtk_old_editable_real_cut_clipboard (GtkOldEditable *old_editable)
{
gtk_old_editable_real_copy_clipboard (old_editable);
gtk_editable_delete_selection (GTK_EDITABLE (old_editable));
}
static void
gtk_old_editable_real_copy_clipboard (GtkOldEditable *old_editable)
{
gint selection_start_pos;
gint selection_end_pos;
selection_start_pos = MIN (old_editable->selection_start_pos, old_editable->selection_end_pos);
selection_end_pos = MAX (old_editable->selection_start_pos, old_editable->selection_end_pos);
if (selection_start_pos != selection_end_pos)
{
gchar *text = gtk_old_editable_get_public_chars (old_editable,
selection_start_pos,
selection_end_pos);
if (text)
{
gtk_clipboard_set_text (gtk_clipboard_get (GDK_NONE), text, -1);
g_free (text);
}
}
}
static void
gtk_old_editable_real_paste_clipboard (GtkOldEditable *old_editable)
{
g_object_ref (G_OBJECT (old_editable));
gtk_clipboard_request_text (gtk_clipboard_get (GDK_NONE),
old_editable_text_received_cb, old_editable);
}
void
gtk_old_editable_changed (GtkOldEditable *old_editable)
{
g_return_if_fail (old_editable != NULL);
g_return_if_fail (GTK_IS_OLD_EDITABLE (old_editable));
gtk_signal_emit (GTK_OBJECT (old_editable), editable_signals[CHANGED]);
}