gtkentry.c 114 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* 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
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * 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
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * 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/. 
 */

Elliot Lee's avatar
Elliot Lee committed
27
#include <string.h>
Owen Taylor's avatar
Owen Taylor committed
28 29 30

#include <pango/pango.h>

Elliot Lee's avatar
Elliot Lee committed
31
#include "gdk/gdkkeysyms.h"
Owen Taylor's avatar
Owen Taylor committed
32
#include "gtkbindings.h"
33
#include "gtkcelleditable.h"
Owen Taylor's avatar
Owen Taylor committed
34
#include "gtkclipboard.h"
Owen Taylor's avatar
Owen Taylor committed
35
#include "gtkdnd.h"
Elliot Lee's avatar
Elliot Lee committed
36
#include "gtkentry.h"
37
#include "gtkimmulticontext.h"
Owen Taylor's avatar
Owen Taylor committed
38
#include "gtkintl.h"
Elliot Lee's avatar
Elliot Lee committed
39
#include "gtkmain.h"
Owen Taylor's avatar
Owen Taylor committed
40 41
#include "gtkmenu.h"
#include "gtkmenuitem.h"
42
#include "gtkseparatormenuitem.h"
Elliot Lee's avatar
Elliot Lee committed
43
#include "gtkselection.h"
44
#include "gtksettings.h"
Elliot Lee's avatar
Elliot Lee committed
45
#include "gtksignal.h"
46
#include "gtkwindow.h"
47

Elliot Lee's avatar
Elliot Lee committed
48 49 50 51
#define MIN_ENTRY_WIDTH  150
#define DRAW_TIMEOUT     20
#define INNER_BORDER     2

52 53 54 55 56 57
/* Initial size of buffer, in bytes */
#define MIN_SIZE 16

/* Maximum size of text buffer, in bytes */
#define MAX_SIZE G_MAXUSHORT

Owen Taylor's avatar
Owen Taylor committed
58 59
enum {
  ACTIVATE,
60
  POPULATE_POPUP,
Owen Taylor's avatar
Owen Taylor committed
61 62 63 64 65 66 67 68 69 70
  MOVE_CURSOR,
  INSERT_AT_CURSOR,
  DELETE_FROM_CURSOR,
  CUT_CLIPBOARD,
  COPY_CLIPBOARD,
  PASTE_CLIPBOARD,
  TOGGLE_OVERWRITE,
  LAST_SIGNAL
};

71
enum {
Havoc Pennington's avatar
Havoc Pennington committed
72
  PROP_0,
73 74
  PROP_CURSOR_POSITION,
  PROP_SELECTION_BOUND,
Havoc Pennington's avatar
Havoc Pennington committed
75 76 77
  PROP_EDITABLE,
  PROP_MAX_LENGTH,
  PROP_VISIBILITY,
78
  PROP_HAS_FRAME,
79
  PROP_INVISIBLE_CHAR,
80
  PROP_ACTIVATES_DEFAULT,
81
  PROP_WIDTH_CHARS,
82 83
  PROP_SCROLL_OFFSET,
  PROP_TEXT
84 85
};

Owen Taylor's avatar
Owen Taylor committed
86
static guint signals[LAST_SIGNAL] = { 0 };
87

Owen Taylor's avatar
Owen Taylor committed
88 89 90 91 92 93 94 95 96 97 98 99 100
typedef enum {
  CURSOR_STANDARD,
  CURSOR_DND
} CursorType;

static GtkTargetEntry target_table[] = {
  { "UTF8_STRING",   0, 0 },
  { "COMPOUND_TEXT", 0, 0 },
  { "TEXT",          0, 0 },
  { "text/plain",    0, 0 },
  { "STRING",        0, 0 }
};

Owen Taylor's avatar
Owen Taylor committed
101 102
/* GObject, GtkObject methods
 */
103 104 105
static void   gtk_entry_class_init           (GtkEntryClass        *klass);
static void   gtk_entry_editable_init        (GtkEditableClass     *iface);
static void   gtk_entry_cell_editable_init   (GtkCellEditableIface *iface);
106
static void   gtk_entry_init                 (GtkEntry         *entry);
Havoc Pennington's avatar
Havoc Pennington committed
107 108 109
static void   gtk_entry_set_property (GObject         *object,
				      guint            prop_id,
				      const GValue    *value,
110
				      GParamSpec      *pspec);
Havoc Pennington's avatar
Havoc Pennington committed
111 112 113
static void   gtk_entry_get_property (GObject         *object,
				      guint            prop_id,
				      GValue          *value,
114
				      GParamSpec      *pspec);
115
static void   gtk_entry_finalize             (GObject          *object);
Owen Taylor's avatar
Owen Taylor committed
116 117 118

/* GtkWidget methods
 */
119 120 121 122 123 124
static void   gtk_entry_realize              (GtkWidget        *widget);
static void   gtk_entry_unrealize            (GtkWidget        *widget);
static void   gtk_entry_size_request         (GtkWidget        *widget,
					      GtkRequisition   *requisition);
static void   gtk_entry_size_allocate        (GtkWidget        *widget,
					      GtkAllocation    *allocation);
Owen Taylor's avatar
Owen Taylor committed
125
static void   gtk_entry_draw_focus           (GtkWidget        *widget);
126 127 128 129 130 131 132 133 134 135 136 137 138 139
static gint   gtk_entry_expose               (GtkWidget        *widget,
					      GdkEventExpose   *event);
static gint   gtk_entry_button_press         (GtkWidget        *widget,
					      GdkEventButton   *event);
static gint   gtk_entry_button_release       (GtkWidget        *widget,
					      GdkEventButton   *event);
static gint   gtk_entry_motion_notify        (GtkWidget        *widget,
					      GdkEventMotion   *event);
static gint   gtk_entry_key_press            (GtkWidget        *widget,
					      GdkEventKey      *event);
static gint   gtk_entry_focus_in             (GtkWidget        *widget,
					      GdkEventFocus    *event);
static gint   gtk_entry_focus_out            (GtkWidget        *widget,
					      GdkEventFocus    *event);
140
static void   gtk_entry_grab_focus           (GtkWidget        *widget);
141 142 143 144 145 146
static void   gtk_entry_style_set            (GtkWidget        *widget,
					      GtkStyle         *previous_style);
static void   gtk_entry_direction_changed    (GtkWidget        *widget,
					      GtkTextDirection  previous_dir);
static void   gtk_entry_state_changed        (GtkWidget        *widget,
					      GtkStateType      previous_state);
Owen Taylor's avatar
Owen Taylor committed
147

148 149 150 151 152
static gboolean gtk_entry_drag_drop          (GtkWidget        *widget,
                                              GdkDragContext   *context,
                                              gint              x,
                                              gint              y,
                                              guint             time);
Owen Taylor's avatar
Owen Taylor committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
static gboolean gtk_entry_drag_motion        (GtkWidget        *widget,
					      GdkDragContext   *context,
					      gint              x,
					      gint              y,
					      guint             time);
static void     gtk_entry_drag_leave         (GtkWidget        *widget,
					      GdkDragContext   *context,
					      guint             time);
static void     gtk_entry_drag_data_received (GtkWidget        *widget,
					      GdkDragContext   *context,
					      gint              x,
					      gint              y,
					      GtkSelectionData *selection_data,
					      guint             info,
					      guint             time);
static void     gtk_entry_drag_data_get      (GtkWidget        *widget,
					      GdkDragContext   *context,
					      GtkSelectionData *selection_data,
					      guint             info,
					      guint             time);
static void     gtk_entry_drag_data_delete   (GtkWidget        *widget,
					      GdkDragContext   *context);

Owen Taylor's avatar
Owen Taylor committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
/* GtkEditable method implementations
 */
static void     gtk_entry_insert_text          (GtkEditable *editable,
						const gchar *new_text,
						gint         new_text_length,
						gint        *position);
static void     gtk_entry_delete_text          (GtkEditable *editable,
						gint         start_pos,
						gint         end_pos);
static gchar *  gtk_entry_get_chars            (GtkEditable *editable,
						gint         start_pos,
						gint         end_pos);
static void     gtk_entry_real_set_position    (GtkEditable *editable,
						gint         position);
static gint     gtk_entry_get_position         (GtkEditable *editable);
static void     gtk_entry_set_selection_bounds (GtkEditable *editable,
						gint         start,
						gint         end);
static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
						gint        *start,
						gint        *end);

198 199 200 201 202
/* GtkCellEditable method implementations
 */
static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
				     GdkEvent        *event);

Owen Taylor's avatar
Owen Taylor committed
203 204
/* Default signal handlers
 */
205
static void gtk_entry_real_insert_text   (GtkEditable     *editable,
206 207 208
					  const gchar     *new_text,
					  gint             new_text_length,
					  gint            *position);
209
static void gtk_entry_real_delete_text   (GtkEditable     *editable,
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
					  gint             start_pos,
					  gint             end_pos);
static void gtk_entry_move_cursor        (GtkEntry        *entry,
					  GtkMovementStep  step,
					  gint             count,
					  gboolean         extend_selection);
static void gtk_entry_insert_at_cursor   (GtkEntry        *entry,
					  const gchar     *str);
static void gtk_entry_delete_from_cursor (GtkEntry        *entry,
					  GtkDeleteType    type,
					  gint             count);
static void gtk_entry_cut_clipboard      (GtkEntry        *entry);
static void gtk_entry_copy_clipboard     (GtkEntry        *entry);
static void gtk_entry_paste_clipboard    (GtkEntry        *entry);
static void gtk_entry_toggle_overwrite   (GtkEntry        *entry);
225
static void gtk_entry_select_all         (GtkEntry        *entry);
226
static void gtk_entry_real_activate      (GtkEntry        *entry);
227
static void gtk_entry_popup_menu         (GtkWidget      *widget);
Owen Taylor's avatar
Owen Taylor committed
228

229 230
static void gtk_entry_keymap_direction_changed (GdkKeymap *keymap,
						GtkEntry  *entry);
Owen Taylor's avatar
Owen Taylor committed
231 232
/* IM Context Callbacks
 */
233 234 235
static void gtk_entry_commit_cb           (GtkIMContext      *context,
					   const gchar       *str,
					   GtkEntry          *entry);
Owen Taylor's avatar
Owen Taylor committed
236 237 238 239
static void gtk_entry_preedit_changed_cb  (GtkIMContext      *context,
					   GtkEntry          *entry);
/* Internal routines
 */
240 241 242
static void         gtk_entry_set_positions            (GtkEntry       *entry,
							gint            current_pos,
							gint            selection_bound);
Owen Taylor's avatar
Owen Taylor committed
243
static void         gtk_entry_draw_text                (GtkEntry       *entry);
Owen Taylor's avatar
Owen Taylor committed
244 245
static void         gtk_entry_draw_cursor              (GtkEntry       *entry,
							CursorType      type);
246 247
static PangoLayout *gtk_entry_ensure_layout            (GtkEntry       *entry,
                                                        gboolean        include_preedit);
Owen Taylor's avatar
Owen Taylor committed
248 249 250 251 252 253
static void         gtk_entry_queue_draw               (GtkEntry       *entry);
static void         gtk_entry_reset_im_context         (GtkEntry       *entry);
static void         gtk_entry_recompute                (GtkEntry       *entry);
static gint         gtk_entry_find_position            (GtkEntry       *entry,
							gint            x);
static void         gtk_entry_get_cursor_locations     (GtkEntry       *entry,
Owen Taylor's avatar
Owen Taylor committed
254
							CursorType      type,
Owen Taylor's avatar
Owen Taylor committed
255 256 257 258 259 260
							gint           *strong_x,
							gint           *weak_x);
static void         gtk_entry_adjust_scroll            (GtkEntry       *entry);
static gint         gtk_entry_move_visually            (GtkEntry       *editable,
							gint            start,
							gint            count);
261 262 263
static gint         gtk_entry_move_logically           (GtkEntry       *entry,
							gint            start,
							gint            count);
Owen Taylor's avatar
Owen Taylor committed
264 265 266 267 268 269 270 271 272 273 274 275 276
static gint         gtk_entry_move_forward_word        (GtkEntry       *entry,
							gint            start);
static gint         gtk_entry_move_backward_word       (GtkEntry       *entry,
							gint            start);
static void         gtk_entry_delete_whitespace        (GtkEntry       *entry);
static void         gtk_entry_select_word              (GtkEntry       *entry);
static void         gtk_entry_select_line              (GtkEntry       *entry);
static char *       gtk_entry_get_public_chars         (GtkEntry       *entry,
							gint            start,
							gint            end);
static void         gtk_entry_paste                    (GtkEntry       *entry,
							GdkAtom         selection);
static void         gtk_entry_update_primary_selection (GtkEntry       *entry);
277
static void         gtk_entry_do_popup                 (GtkEntry       *entry,
Owen Taylor's avatar
Owen Taylor committed
278
							GdkEventButton *event);
279 280
static gboolean     gtk_entry_mnemonic_activate        (GtkWidget      *widget,
							gboolean        group_cycling);
281 282
static void         gtk_entry_check_cursor_blink       (GtkEntry       *entry);
static void         gtk_entry_pend_cursor_blink        (GtkEntry       *entry);
283

Elliot Lee's avatar
Elliot Lee committed
284 285
static GtkWidgetClass *parent_class = NULL;

286
GtkType
287
gtk_entry_get_type (void)
Elliot Lee's avatar
Elliot Lee committed
288
{
289
  static GtkType entry_type = 0;
Elliot Lee's avatar
Elliot Lee committed
290 291 292

  if (!entry_type)
    {
293
      static const GtkTypeInfo entry_info =
Elliot Lee's avatar
Elliot Lee committed
294 295 296 297 298 299
      {
	"GtkEntry",
	sizeof (GtkEntry),
	sizeof (GtkEntryClass),
	(GtkClassInitFunc) gtk_entry_class_init,
	(GtkObjectInitFunc) gtk_entry_init,
300 301
	/* reserved_1 */ NULL,
	/* reserved_2 */ NULL,
302
        (GtkClassInitFunc) NULL,
Elliot Lee's avatar
Elliot Lee committed
303
      };
Owen Taylor's avatar
Owen Taylor committed
304 305 306 307 308 309 310
      
      static const GInterfaceInfo editable_info =
      {
	(GInterfaceInitFunc) gtk_entry_editable_init,	 /* interface_init */
	NULL,			                         /* interface_finalize */
	NULL			                         /* interface_data */
      };
Elliot Lee's avatar
Elliot Lee committed
311

312 313 314 315 316 317 318
      static const GInterfaceInfo cell_editable_info =
      {
	(GInterfaceInitFunc) gtk_entry_cell_editable_init,    /* interface_init */
	NULL,                                                 /* interface_finalize */
	NULL                                                  /* interface_data */
      };
      
Owen Taylor's avatar
Owen Taylor committed
319 320 321 322
      entry_type = gtk_type_unique (GTK_TYPE_WIDGET, &entry_info);
      g_type_add_interface_static (entry_type,
				   GTK_TYPE_EDITABLE,
				   &editable_info);
323 324 325
      g_type_add_interface_static (entry_type,
				   GTK_TYPE_CELL_EDITABLE,
				   &cell_editable_info);
Elliot Lee's avatar
Elliot Lee committed
326 327 328 329 330
    }

  return entry_type;
}

Owen Taylor's avatar
Owen Taylor committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
static void
add_move_binding (GtkBindingSet  *binding_set,
		  guint           keyval,
		  guint           modmask,
		  GtkMovementStep step,
		  gint            count)
{
  g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
  
  gtk_binding_entry_add_signal (binding_set, keyval, modmask,
				"move_cursor", 3,
				GTK_TYPE_ENUM, step,
				G_TYPE_INT, count,
                                G_TYPE_BOOLEAN, FALSE);

  /* Selection-extending version */
  gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
				"move_cursor", 3,
				GTK_TYPE_ENUM, step,
				G_TYPE_INT, count,
                                G_TYPE_BOOLEAN, TRUE);
}

Elliot Lee's avatar
Elliot Lee committed
354 355 356
static void
gtk_entry_class_init (GtkEntryClass *class)
{
357
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
Elliot Lee's avatar
Elliot Lee committed
358 359
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;
Owen Taylor's avatar
Owen Taylor committed
360
  GtkBindingSet *binding_set;
Elliot Lee's avatar
Elliot Lee committed
361 362 363

  object_class = (GtkObjectClass*) class;
  widget_class = (GtkWidgetClass*) class;
Owen Taylor's avatar
Owen Taylor committed
364
  parent_class = gtk_type_class (GTK_TYPE_WIDGET);
Elliot Lee's avatar
Elliot Lee committed
365

366
  gobject_class->finalize = gtk_entry_finalize;
Havoc Pennington's avatar
Havoc Pennington committed
367 368
  gobject_class->set_property = gtk_entry_set_property;
  gobject_class->get_property = gtk_entry_get_property;
369 370 371 372 373 374 375 376 377 378 379 380

  widget_class->realize = gtk_entry_realize;
  widget_class->unrealize = gtk_entry_unrealize;
  widget_class->size_request = gtk_entry_size_request;
  widget_class->size_allocate = gtk_entry_size_allocate;
  widget_class->expose_event = gtk_entry_expose;
  widget_class->button_press_event = gtk_entry_button_press;
  widget_class->button_release_event = gtk_entry_button_release;
  widget_class->motion_notify_event = gtk_entry_motion_notify;
  widget_class->key_press_event = gtk_entry_key_press;
  widget_class->focus_in_event = gtk_entry_focus_in;
  widget_class->focus_out_event = gtk_entry_focus_out;
381
  widget_class->grab_focus = gtk_entry_grab_focus;
382 383 384
  widget_class->style_set = gtk_entry_style_set;
  widget_class->direction_changed = gtk_entry_direction_changed;
  widget_class->state_changed = gtk_entry_state_changed;
385
  widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
386

387
  widget_class->drag_drop = gtk_entry_drag_drop;
Owen Taylor's avatar
Owen Taylor committed
388 389 390 391 392 393
  widget_class->drag_motion = gtk_entry_drag_motion;
  widget_class->drag_leave = gtk_entry_drag_leave;
  widget_class->drag_data_received = gtk_entry_drag_data_received;
  widget_class->drag_data_get = gtk_entry_drag_data_get;
  widget_class->drag_data_delete = gtk_entry_drag_data_delete;

394
  widget_class->popup_menu = gtk_entry_popup_menu;
395

396 397 398 399 400 401 402
  class->move_cursor = gtk_entry_move_cursor;
  class->insert_at_cursor = gtk_entry_insert_at_cursor;
  class->delete_from_cursor = gtk_entry_delete_from_cursor;
  class->cut_clipboard = gtk_entry_cut_clipboard;
  class->copy_clipboard = gtk_entry_copy_clipboard;
  class->paste_clipboard = gtk_entry_paste_clipboard;
  class->toggle_overwrite = gtk_entry_toggle_overwrite;
403 404
  class->activate = gtk_entry_real_activate;
  
Havoc Pennington's avatar
Havoc Pennington committed
405
  g_object_class_install_property (gobject_class,
406 407 408 409
                                   PROP_CURSOR_POSITION,
                                   g_param_spec_int ("cursor_position",
                                                     _("Cursor Position"),
                                                     _("The current position of the insertion cursor in chars."),
Havoc Pennington's avatar
Havoc Pennington committed
410 411 412
                                                     0,
                                                     G_MAXINT,
                                                     0,
413 414 415 416 417 418 419 420 421 422 423
                                                     G_PARAM_READABLE));
  
  g_object_class_install_property (gobject_class,
                                   PROP_SELECTION_BOUND,
                                   g_param_spec_int ("selection_bound",
                                                     _("Selection Bound"),
                                                     _("The position of the opposite end of the selection from the cursor in chars."),
                                                     0,
                                                     G_MAXINT,
                                                     0,
                                                     G_PARAM_READABLE));
Havoc Pennington's avatar
Havoc Pennington committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
  
  g_object_class_install_property (gobject_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
							 _("Editable"),
							 _("Whether the entry contents can be edited"),
                                                         TRUE,
							 G_PARAM_READABLE | G_PARAM_WRITABLE));
  
  g_object_class_install_property (gobject_class,
                                   PROP_MAX_LENGTH,
                                   g_param_spec_int ("max_length",
                                                     _("Maximum length"),
                                                     _("Maximum number of characters for this entry"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));
  g_object_class_install_property (gobject_class,
                                   PROP_VISIBILITY,
                                   g_param_spec_boolean ("visibility",
							 _("Visibility"),
							 _("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
                                                         TRUE,
							 G_PARAM_READABLE | G_PARAM_WRITABLE));
449

Havoc Pennington's avatar
Havoc Pennington committed
450
  g_object_class_install_property (gobject_class,
451 452 453 454 455 456 457 458
                                   PROP_HAS_FRAME,
                                   g_param_spec_boolean ("has_frame",
							 _("Has Frame"),
							 _("FALSE removes outside bevel from entry."),
                                                         TRUE,
							 G_PARAM_READABLE | G_PARAM_WRITABLE));

    g_object_class_install_property (gobject_class,
Havoc Pennington's avatar
Havoc Pennington committed
459
                                   PROP_INVISIBLE_CHAR,
460 461 462 463 464
                                   g_param_spec_unichar ("invisible_char",
							 _("Invisible character"),
							 _("The character to use when masking entry contents (in \"password mode\")"),
							 '*',
							 G_PARAM_READABLE | G_PARAM_WRITABLE));
Havoc Pennington's avatar
Havoc Pennington committed
465

466 467 468 469 470 471 472
  g_object_class_install_property (gobject_class,
                                   PROP_ACTIVATES_DEFAULT,
                                   g_param_spec_boolean ("activates_default",
							 _("Activates default"),
							 _("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed."),
                                                         FALSE,
							 G_PARAM_READABLE | G_PARAM_WRITABLE));
473 474 475 476 477 478 479 480 481
  g_object_class_install_property (gobject_class,
                                   PROP_WIDTH_CHARS,
                                   g_param_spec_int ("width_chars",
                                                     _("Width in chars"),
                                                     _("Number of characters to leave space for in the entry."),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));
482

483 484 485 486 487 488 489 490 491
  g_object_class_install_property (gobject_class,
                                   PROP_SCROLL_OFFSET,
                                   g_param_spec_int ("scroll_offset",
                                                     _("Scroll offset"),
                                                     _("Number of pixels of the entry scrolled off the screen to the left"),
                                                     0,
                                                     G_MAXINT,
                                                     0,
                                                     G_PARAM_READABLE));
492 493 494 495 496 497 498 499

  g_object_class_install_property (gobject_class,
                                   PROP_TEXT,
                                   g_param_spec_string ("text",
							_("Text"),
							_("The contents of the entry"),
							"",
							G_PARAM_READABLE | G_PARAM_WRITABLE));
500
  
501 502 503 504
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_boxed ("cursor_color",
							       _("Cursor color"),
							       _("Color with which to draw insertion cursor"),
505
							       GDK_TYPE_COLOR,
506 507
							       G_PARAM_READABLE));

508 509 510 511 512 513 514 515
  signals[POPULATE_POPUP] =
    gtk_signal_new ("populate_popup",
		    GTK_RUN_LAST,
		    GTK_CLASS_TYPE (object_class),
		    GTK_SIGNAL_OFFSET (GtkEntryClass, populate_popup),
		    gtk_marshal_VOID__OBJECT,
		    GTK_TYPE_NONE, 1, GTK_TYPE_MENU);
  
Owen Taylor's avatar
Owen Taylor committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
 /* Action signals */
  
  signals[ACTIVATE] =
    gtk_signal_new ("activate",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    GTK_CLASS_TYPE (object_class),
		    GTK_SIGNAL_OFFSET (GtkEntryClass, activate),
		    gtk_marshal_VOID__VOID,
		    GTK_TYPE_NONE, 0);
  widget_class->activate_signal = signals[ACTIVATE];

  signals[MOVE_CURSOR] = 
      gtk_signal_new ("move_cursor",
                      GTK_RUN_LAST | GTK_RUN_ACTION,
                      GTK_CLASS_TYPE (object_class),
531
                      GTK_SIGNAL_OFFSET (GtkEntryClass, move_cursor),
Owen Taylor's avatar
Owen Taylor committed
532 533 534 535 536 537 538
                      gtk_marshal_VOID__ENUM_INT_BOOLEAN,
                      GTK_TYPE_NONE, 3, GTK_TYPE_MOVEMENT_STEP, GTK_TYPE_INT, GTK_TYPE_BOOL);

  signals[INSERT_AT_CURSOR] = 
      gtk_signal_new ("insert_at_cursor",
                      GTK_RUN_LAST | GTK_RUN_ACTION,
                      GTK_CLASS_TYPE (object_class),
539
                      GTK_SIGNAL_OFFSET (GtkEntryClass, insert_at_cursor),
Owen Taylor's avatar
Owen Taylor committed
540 541 542 543 544 545 546
                      gtk_marshal_VOID__STRING,
                      GTK_TYPE_NONE, 1, GTK_TYPE_STRING);

  signals[DELETE_FROM_CURSOR] = 
      gtk_signal_new ("delete_from_cursor",
                      GTK_RUN_LAST | GTK_RUN_ACTION,
                      GTK_CLASS_TYPE (object_class),
547
                      GTK_SIGNAL_OFFSET (GtkEntryClass, delete_from_cursor),
Owen Taylor's avatar
Owen Taylor committed
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
                      gtk_marshal_VOID__ENUM_INT,
                      GTK_TYPE_NONE, 2, GTK_TYPE_DELETE_TYPE, GTK_TYPE_INT);

  signals[CUT_CLIPBOARD] =
    gtk_signal_new ("cut_clipboard",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    GTK_CLASS_TYPE (object_class),
                    GTK_SIGNAL_OFFSET (GtkEntryClass, cut_clipboard),
                    gtk_marshal_VOID__VOID,
                    GTK_TYPE_NONE, 0);

  signals[COPY_CLIPBOARD] =
    gtk_signal_new ("copy_clipboard",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    GTK_CLASS_TYPE (object_class),
                    GTK_SIGNAL_OFFSET (GtkEntryClass, copy_clipboard),
                    gtk_marshal_VOID__VOID,
                    GTK_TYPE_NONE, 0);

  signals[PASTE_CLIPBOARD] =
    gtk_signal_new ("paste_clipboard",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    GTK_CLASS_TYPE (object_class),
                    GTK_SIGNAL_OFFSET (GtkEntryClass, paste_clipboard),
                    gtk_marshal_VOID__VOID,
                    GTK_TYPE_NONE, 0);

  signals[TOGGLE_OVERWRITE] =
    gtk_signal_new ("toggle_overwrite",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    GTK_CLASS_TYPE (object_class),
                    GTK_SIGNAL_OFFSET (GtkEntryClass, toggle_overwrite),
                    gtk_marshal_VOID__VOID,
                    GTK_TYPE_NONE, 0);

  /*
   * Key bindings
   */

  binding_set = gtk_binding_set_by_class (class);

  /* Moving the insertion point */
  add_move_binding (binding_set, GDK_Right, 0,
591
		    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
Owen Taylor's avatar
Owen Taylor committed
592 593
  
  add_move_binding (binding_set, GDK_Left, 0,
594
		    GTK_MOVEMENT_VISUAL_POSITIONS, -1);
Owen Taylor's avatar
Owen Taylor committed
595

596 597 598 599 600 601
  add_move_binding (binding_set, GDK_KP_Right, 0,
		    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
  
  add_move_binding (binding_set, GDK_KP_Left, 0,
		    GTK_MOVEMENT_VISUAL_POSITIONS, -1);
  
Owen Taylor's avatar
Owen Taylor committed
602
  add_move_binding (binding_set, GDK_f, GDK_CONTROL_MASK,
603
		    GTK_MOVEMENT_LOGICAL_POSITIONS, 1);
Owen Taylor's avatar
Owen Taylor committed
604 605
  
  add_move_binding (binding_set, GDK_b, GDK_CONTROL_MASK,
606
		    GTK_MOVEMENT_LOGICAL_POSITIONS, -1);
Owen Taylor's avatar
Owen Taylor committed
607 608 609 610 611 612
  
  add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_WORDS, 1);

  add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_WORDS, -1);
613 614 615 616 617 618

  add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_WORDS, 1);

  add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_WORDS, -1);
Owen Taylor's avatar
Owen Taylor committed
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
  
  add_move_binding (binding_set, GDK_a, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_PARAGRAPH_ENDS, -1);

  add_move_binding (binding_set, GDK_e, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_PARAGRAPH_ENDS, 1);

  add_move_binding (binding_set, GDK_f, GDK_MOD1_MASK,
		    GTK_MOVEMENT_WORDS, 1);

  add_move_binding (binding_set, GDK_b, GDK_MOD1_MASK,
		    GTK_MOVEMENT_WORDS, -1);

  add_move_binding (binding_set, GDK_Home, 0,
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);

  add_move_binding (binding_set, GDK_End, 0,
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
637 638 639 640 641 642

  add_move_binding (binding_set, GDK_KP_Home, 0,
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);

  add_move_binding (binding_set, GDK_KP_End, 0,
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
Owen Taylor's avatar
Owen Taylor committed
643 644 645 646 647 648 649
  
  add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_BUFFER_ENDS, -1);

  add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_BUFFER_ENDS, 1);

650 651 652 653 654 655 656 657 658 659 660 661 662 663
  add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_BUFFER_ENDS, -1);

  add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
		    GTK_MOVEMENT_BUFFER_ENDS, 1);

  /* Activate */

  gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
				"activate", 0);

  gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
				"activate", 0);
  
Owen Taylor's avatar
Owen Taylor committed
664 665 666 667 668 669
  /* Deleting text */
  gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_CHARS,
				GTK_TYPE_INT, 1);

670 671 672 673 674
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_CHARS,
				GTK_TYPE_INT, 1);
  
Owen Taylor's avatar
Owen Taylor committed
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
  gtk_binding_entry_add_signal (binding_set, GDK_d, GDK_CONTROL_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_CHARS,
				GTK_TYPE_INT, 1);

  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_CHARS,
				GTK_TYPE_INT, -1);

  gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
				GTK_TYPE_INT, 1);

690 691 692 693 694
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
				GTK_TYPE_INT, 1);
  
Owen Taylor's avatar
Owen Taylor committed
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
  gtk_binding_entry_add_signal (binding_set, GDK_d, GDK_MOD1_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
				GTK_TYPE_INT, 1);

  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
				GTK_TYPE_INT, -1);

  gtk_binding_entry_add_signal (binding_set, GDK_k, GDK_CONTROL_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
				GTK_TYPE_INT, 1);

  gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_PARAGRAPHS,
				GTK_TYPE_INT, 1);

  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_MOD1_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
				GTK_TYPE_INT, 1);
719 720 721 722
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_MOD1_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
				GTK_TYPE_INT, 1);
Owen Taylor's avatar
Owen Taylor committed
723 724 725
  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_MOD1_MASK,
				"insert_at_cursor", 1,
				GTK_TYPE_STRING, " ");
726 727 728 729
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_MOD1_MASK,
				"insert_at_cursor", 1,
				GTK_TYPE_STRING, " ");
  
Owen Taylor's avatar
Owen Taylor committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
  gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_MOD1_MASK,
				"delete_from_cursor", 2,
				GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
				GTK_TYPE_INT, 1);
  
  /* Cut/copy/paste */

  gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
				"cut_clipboard", 0);

  gtk_binding_entry_add_signal (binding_set, GDK_w, GDK_CONTROL_MASK,
				"cut_clipboard", 0);
  
  gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
				"copy_clipboard", 0);
  
  gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
				"paste_clipboard", 0);
Elliot Lee's avatar
Elliot Lee committed
748

Owen Taylor's avatar
Owen Taylor committed
749 750 751 752 753 754
  gtk_binding_entry_add_signal (binding_set, GDK_y, GDK_CONTROL_MASK,
				"paste_clipboard", 0);

  /* Overwrite */
  gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
				"toggle_overwrite", 0);
755 756
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
				"toggle_overwrite", 0);
Owen Taylor's avatar
Owen Taylor committed
757
}
758

Owen Taylor's avatar
Owen Taylor committed
759 760 761
static void
gtk_entry_editable_init (GtkEditableClass *iface)
{
762 763 764 765
  iface->do_insert_text = gtk_entry_insert_text;
  iface->do_delete_text = gtk_entry_delete_text;
  iface->insert_text = gtk_entry_real_insert_text;
  iface->delete_text = gtk_entry_real_delete_text;
Owen Taylor's avatar
Owen Taylor committed
766 767 768 769 770
  iface->get_chars = gtk_entry_get_chars;
  iface->set_selection_bounds = gtk_entry_set_selection_bounds;
  iface->get_selection_bounds = gtk_entry_get_selection_bounds;
  iface->set_position = gtk_entry_real_set_position;
  iface->get_position = gtk_entry_get_position;
Elliot Lee's avatar
Elliot Lee committed
771 772
}

773 774 775 776 777 778
static void
gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
{
  iface->start_editing = gtk_entry_start_editing;
}

779 780 781 782 783
static void
gtk_entry_set_property (GObject         *object,
                        guint            prop_id,
                        const GValue    *value,
                        GParamSpec      *pspec)
784
{
Owen Taylor's avatar
Owen Taylor committed
785
  GtkEntry *entry = GTK_ENTRY (object);
786

Havoc Pennington's avatar
Havoc Pennington committed
787
  switch (prop_id)
788
    {
Havoc Pennington's avatar
Havoc Pennington committed
789
    case PROP_EDITABLE:
Owen Taylor's avatar
Owen Taylor committed
790
      {
Havoc Pennington's avatar
Havoc Pennington committed
791 792 793
        gboolean new_value = g_value_get_boolean (value);

      	if (new_value != entry->editable)
Owen Taylor's avatar
Owen Taylor committed
794 795 796 797 798 799
	  {
	    entry->editable = new_value;
	    gtk_entry_queue_draw (entry);
	  }
      }
      break;
Havoc Pennington's avatar
Havoc Pennington committed
800 801 802

    case PROP_MAX_LENGTH:
      gtk_entry_set_max_length (entry, g_value_get_int (value));
803
      break;
Havoc Pennington's avatar
Havoc Pennington committed
804 805 806
      
    case PROP_VISIBILITY:
      gtk_entry_set_visibility (entry, g_value_get_boolean (value));
807
      break;
Havoc Pennington's avatar
Havoc Pennington committed
808

809 810 811 812
    case PROP_HAS_FRAME:
      gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
      break;

Havoc Pennington's avatar
Havoc Pennington committed
813
    case PROP_INVISIBLE_CHAR:
814
      gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
815
      break;
Havoc Pennington's avatar
Havoc Pennington committed
816

817 818 819
    case PROP_ACTIVATES_DEFAULT:
      gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
      break;
820 821 822 823

    case PROP_WIDTH_CHARS:
      gtk_entry_set_width_chars (entry, g_value_get_int (value));
      break;
824

825 826 827 828
    case PROP_TEXT:
      gtk_entry_set_text (entry, g_value_get_string (value));
      break;

829
    case PROP_SCROLL_OFFSET:
830
    case PROP_CURSOR_POSITION:
831
    default:
Havoc Pennington's avatar
Havoc Pennington committed
832
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
833 834 835 836
      break;
    }
}

837 838 839 840 841
static void
gtk_entry_get_property (GObject         *object,
                        guint            prop_id,
                        GValue          *value,
                        GParamSpec      *pspec)
842 843 844 845 846
{
  GtkEntry *entry;

  entry = GTK_ENTRY (object);

Havoc Pennington's avatar
Havoc Pennington committed
847
  switch (prop_id)
848
    {
849
    case PROP_CURSOR_POSITION:
Havoc Pennington's avatar
Havoc Pennington committed
850
      g_value_set_int (value, entry->current_pos);
Owen Taylor's avatar
Owen Taylor committed
851
      break;
852 853 854
    case PROP_SELECTION_BOUND:
      g_value_set_int (value, entry->selection_bound);
      break;
Havoc Pennington's avatar
Havoc Pennington committed
855 856
    case PROP_EDITABLE:
      g_value_set_boolean (value, entry->editable);
Owen Taylor's avatar
Owen Taylor committed
857
      break;
Havoc Pennington's avatar
Havoc Pennington committed
858 859
    case PROP_MAX_LENGTH:
      g_value_set_int (value, entry->text_max_length); 
860
      break;
Havoc Pennington's avatar
Havoc Pennington committed
861 862
    case PROP_VISIBILITY:
      g_value_set_boolean (value, entry->visible);
863
      break;
864 865 866
    case PROP_HAS_FRAME:
      g_value_set_boolean (value, entry->has_frame);
      break;
Havoc Pennington's avatar
Havoc Pennington committed
867
    case PROP_INVISIBLE_CHAR:
868
      g_value_set_uint (value, entry->invisible_char);
869
      break;
870 871 872
    case PROP_ACTIVATES_DEFAULT:
      g_value_set_boolean (value, entry->activates_default);
      break;
873 874 875
    case PROP_WIDTH_CHARS:
      g_value_set_int (value, entry->width_chars);
      break;
876 877 878
    case PROP_SCROLL_OFFSET:
      g_value_set_int (value, entry->scroll_offset);
      break;
879 880 881
    case PROP_TEXT:
      g_value_set_string (value, gtk_entry_get_text (entry));
      break;
882
      
883
    default:
Havoc Pennington's avatar
Havoc Pennington committed
884
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
885 886 887 888
      break;
    }
}

Elliot Lee's avatar
Elliot Lee committed
889 890 891 892 893
static void
gtk_entry_init (GtkEntry *entry)
{
  GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);

894 895 896
  entry->text_size = MIN_SIZE;
  entry->text = g_malloc (entry->text_size);
  entry->text[0] = '\0';
Owen Taylor's avatar
Owen Taylor committed
897 898 899

  entry->editable = TRUE;
  entry->visible = TRUE;
900
  entry->invisible_char = '*';
Owen Taylor's avatar
Owen Taylor committed
901
  entry->dnd_position = -1;
902
  entry->width_chars = -1;
903
  entry->is_cell_renderer = FALSE;
904
  entry->has_frame = TRUE;
905
  
Owen Taylor's avatar
Owen Taylor committed
906
  gtk_drag_dest_set (GTK_WIDGET (entry),
907
                     GTK_DEST_DEFAULT_HIGHLIGHT,
Owen Taylor's avatar
Owen Taylor committed
908 909 910
                     target_table, G_N_ELEMENTS (target_table),
                     GDK_ACTION_COPY | GDK_ACTION_MOVE);

911 912 913 914 915
  /* This object is completely private. No external entity can gain a reference
   * to it; so we create it here and destroy it in finalize().
   */
  entry->im_context = gtk_im_multicontext_new ();
  
916 917 918 919
  g_signal_connect (G_OBJECT (entry->im_context), "commit",
		    G_CALLBACK (gtk_entry_commit_cb), entry);
  g_signal_connect (G_OBJECT (entry->im_context), "preedit_changed",
		    G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
Elliot Lee's avatar
Elliot Lee committed
920 921 922
}

static void
923
gtk_entry_finalize (GObject *object)
Elliot Lee's avatar
Elliot Lee committed
924 925 926 927 928 929 930
{
  GtkEntry *entry;

  g_return_if_fail (GTK_IS_ENTRY (object));

  entry = GTK_ENTRY (object);

Owen Taylor's avatar
Owen Taylor committed
931 932
  if (entry->cached_layout)
    g_object_unref (G_OBJECT (entry->cached_layout));
Owen Taylor's avatar
Owen Taylor committed
933

934
  g_object_unref (G_OBJECT (entry->im_context));
935

936 937
  if (entry->blink_timeout)
    g_source_remove (entry->blink_timeout);
Owen Taylor's avatar
Owen Taylor committed
938 939 940

  if (entry->recompute_idle)
    g_source_remove (entry->recompute_idle);
Elliot Lee's avatar
Elliot Lee committed
941

942
  entry->text_size = 0;
943

Elliot Lee's avatar
Elliot Lee committed
944 945 946 947
  if (entry->text)
    g_free (entry->text);
  entry->text = NULL;

948
  G_OBJECT_CLASS (parent_class)->finalize (object);
Elliot Lee's avatar
Elliot Lee committed
949 950
}

951 952 953 954
static void
gtk_entry_realize_cursor_gc (GtkEntry *entry)
{
  GdkColor *cursor_color;
955
  GdkColor red = {0, 0xffff, 0x0000, 0x0000};
956 957 958 959 960 961
  
  if (entry->cursor_gc)
    gdk_gc_unref (entry->cursor_gc);

  gtk_widget_style_get (GTK_WIDGET (entry), "cursor_color", &cursor_color, NULL);
      entry->cursor_gc = gdk_gc_new (entry->text_area);
962 963
  if (cursor_color)
    gdk_gc_set_rgb_fg_color (entry->cursor_gc, cursor_color);
964
  else
965
    gdk_gc_set_rgb_fg_color (entry->cursor_gc, &red);
966 967
}

Elliot Lee's avatar
Elliot Lee committed
968 969 970 971
static void
gtk_entry_realize (GtkWidget *widget)
{
  GtkEntry *entry;
972
  GtkEditable *editable;
973
  GtkRequisition requisition;
Elliot Lee's avatar
Elliot Lee committed
974 975 976 977 978 979 980
  GdkWindowAttr attributes;
  gint attributes_mask;

  g_return_if_fail (GTK_IS_ENTRY (widget));

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
  entry = GTK_ENTRY (widget);
981
  editable = GTK_EDITABLE (widget);
982 983

  gtk_widget_get_child_requisition (widget, &requisition);
984
  
Elliot Lee's avatar
Elliot Lee committed
985 986
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
987
  attributes.y = widget->allocation.y + (widget->allocation.height -
988
					 requisition.height) / 2;
Elliot Lee's avatar
Elliot Lee committed
989
  attributes.width = widget->allocation.width;
990
  attributes.height = requisition.height;
Elliot Lee's avatar
Elliot Lee committed
991 992 993 994 995 996 997 998 999
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = gtk_widget_get_events (widget);
  attributes.event_mask |= (GDK_EXPOSURE_MASK |
			    GDK_BUTTON_PRESS_MASK |
			    GDK_BUTTON_RELEASE_MASK |
			    GDK_BUTTON1_MOTION_MASK |
			    GDK_BUTTON3_MOTION_MASK |
1000 1001 1002
			    GDK_POINTER_MOTION_HINT_MASK |
                            GDK_ENTER_NOTIFY_MASK |
			    GDK_LEAVE_NOTIFY_MASK);
Elliot Lee's avatar
Elliot Lee committed
1003 1004
  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

1005
  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
Elliot Lee's avatar
Elliot Lee committed
1006 1007
  gdk_window_set_user_data (widget->window, entry);

1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
  if (entry->has_frame)
    {
      attributes.x = widget->style->xthickness;
      attributes.y = widget->style->ythickness;
    }
  else
    {
      attributes.x = 0;
      attributes.y = 0;
    }
  
Elliot Lee's avatar
Elliot Lee committed
1019
  attributes.width = widget->allocation.width - attributes.x * 2;
1020
  attributes.height = requisition.height - attributes.y * 2;
Owen Taylor's avatar
Owen Taylor committed
1021
  attributes.cursor = gdk_cursor_new (GDK_XTERM);
1022
  attributes_mask |= GDK_WA_CURSOR;
Elliot Lee's avatar
Elliot Lee committed
1023 1024 1025 1026

  entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
  gdk_window_set_user_data (entry->text_area, entry);

1027
  gdk_cursor_destroy (attributes.cursor);
1028

Elliot Lee's avatar
Elliot Lee committed
1029 1030
  widget->style = gtk_style_attach (widget->style, widget->window);

1031 1032
  gtk_entry_realize_cursor_gc (entry);

1033 1034
  gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
  gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
Elliot Lee's avatar
Elliot Lee committed
1035 1036

  gdk_window_show (entry->text_area);
1037

1038
  gtk_im_context_set_client_window (entry->im_context, entry->text_area);
1039

Owen Taylor's avatar
Owen Taylor committed
1040
  gtk_entry_adjust_scroll (entry);
Elliot Lee's avatar
Elliot Lee committed
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
}

static void
gtk_entry_unrealize (GtkWidget *widget)
{
  GtkEntry *entry;

  g_return_if_fail (GTK_IS_ENTRY (widget));

  entry = GTK_ENTRY (widget);

1052 1053
  gtk_im_context_set_client_window (entry->im_context, entry->text_area);
  
Elliot Lee's avatar
Elliot Lee committed
1054 1055 1056 1057
  if (entry->text_area)
    {
      gdk_window_set_user_data (entry->text_area, NULL);
      gdk_window_destroy (entry->text_area);
1058
      entry->text_area = NULL;
Elliot Lee's avatar
Elliot Lee committed
1059
    }
1060

1061 1062 1063 1064 1065 1066
  if (entry->cursor_gc)
    {
      gdk_gc_unref (entry->cursor_gc);
      entry->cursor_gc = NULL;
    }

Owen Taylor's avatar
Owen Taylor committed
1067
  if (entry->popup_menu)
1068 1069 1070 1071
    {
      gtk_widget_destroy (entry->popup_menu);
      entry->popup_menu = NULL;
    }
Owen Taylor's avatar
Owen Taylor committed
1072

1073 1074
  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
Elliot Lee's avatar
Elliot Lee committed
1075 1076 1077 1078 1079 1080
}

static void
gtk_entry_size_request (GtkWidget      *widget,
			GtkRequisition *requisition)
{
1081
  GtkEntry *entry;
1082
  PangoFontMetrics *metrics;
1083
  gint xborder, yborder;
1084
  PangoContext *context;
1085
  
Elliot Lee's avatar
Elliot Lee committed
1086 1087 1088
  g_return_if_fail (GTK_IS_ENTRY (widget));
  g_return_if_fail (requisition != NULL);

1089
  entry = GTK_ENTRY (widget);
1090
  
1091
  context = gtk_widget_get_pango_context (widget);
1092 1093 1094
  metrics = pango_context_get_metrics (context,
				       widget->style->font_desc,
				       pango_context_get_language (context));
1095

1096 1097
  entry->ascent = pango_font_metrics_get_ascent (metrics);
  entry->descent = pango_font_metrics_get_descent (metrics);
1098 1099 1100

  xborder = INNER_BORDER;
  yborder = INNER_BORDER;
1101
  
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
  if (entry->has_frame)
    {
      xborder += widget->style->xthickness;
      yborder += widget->style->ythickness;
    }
  else
    {
      /* add 1 pixel to draw focus rect in widget->window */
      xborder += 1;
      yborder += 1;
    }
1113 1114 1115 1116 1117

  if (entry->width_chars < 0)
    requisition->width = MIN_ENTRY_WIDTH + xborder * 2;
  else
    {
1118 1119
      gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
      requisition->width = PANGO_PIXELS (char_width) * entry->width_chars + xborder * 2;
1120 1121
    }
    
1122 1123 1124
  requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2;

  pango_font_metrics_unref (metrics);
Elliot Lee's avatar
Elliot Lee committed
1125 1126
}

1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
static void
get_borders (GtkEntry *entry,
             gint     *xborder,
             gint     *yborder)
{
  GtkWidget *widget;

  widget = GTK_WIDGET (entry);
  
  if (entry->has_frame)
    {
      if (xborder)
        *xborder = widget->style->xthickness;
      if (yborder)
        *yborder = widget->style->ythickness;
    }
  else
    {
      /* 1 pixel for focus rect */
      if (xborder)
        *xborder = 1;
      if (yborder)
        *yborder = 1;
    }
}

static void
get_text_area_size (GtkEntry *entry,
                    gint     *x,
                    gint     *y,
                    gint     *width,
                    gint     *height)
{
  gint xborder, yborder;
  GtkRequisition requisition;
  GtkWidget *widget;

  widget = GTK_WIDGET (entry);
  
  gtk_widget_get_child_requisition (widget, &requisition);

  get_borders (entry, &xborder, &yborder);

  if (x)
    *x = xborder;

  if (y)
    *y = yborder;
  
  if (width)
    *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;

  if (height)
    *height = requisition.height - yborder * 2;
}

static void
get_widget_window_size (GtkEntry *entry,
                        gint     *x,
                        gint     *y,
                        gint     *width,
                        gint     *height)
{
  GtkRequisition requisition;
  GtkWidget *widget;  

  widget = GTK_WIDGET (entry);
      
  gtk_widget_get_child_requisition (widget, &requisition);

  if (x)
    *x = widget->allocation.x;

  if (y)
1201 1202 1203 1204 1205 1206
    {
      if (entry->is_cell_renderer)
	*y = widget->allocation.y;
      else
	*y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
    }
1207 1208 1209 1210 1211

  if (width)
    *width = widget->allocation.width;

  if (height)
1212 1213 1214 1215 1216 1217
    {
      if (entry->is_cell_renderer)
	*height = widget->allocation.height;
      else
	*height = requisition.height;
    }
1218 1219
}

Elliot Lee's avatar
Elliot Lee committed
1220 1221 1222 1223 1224
static void
gtk_entry_size_allocate (GtkWidget     *widget,
			 GtkAllocation *allocation)
{
  GtkEntry *entry;
1225
  GtkEditable *editable;
1226
  
Elliot Lee's avatar
Elliot Lee committed
1227 1228 1229 1230 1231
  g_return_if_fail (GTK_IS_ENTRY (widget));
  g_return_if_fail (allocation != NULL);

  widget->allocation = *allocation;
  entry = GTK_ENTRY (widget);
1232
  editable = GTK_EDITABLE (widget);
1233
  
Elliot Lee's avatar
Elliot Lee committed
1234 1235
  if (GTK_WIDGET_REALIZED (widget))
    {
1236 1237 1238 1239
      /* We call gtk_widget_get_child_requisition, since we want (for
       * backwards compatibility reasons) the realization here to
       * be affected by the usize of the entry, if set
       */
1240 1241 1242 1243
      gint x, y, width, height;

      get_widget_window_size (entry, &x, &y, &width, &height);
      
Elliot Lee's avatar
Elliot Lee committed
1244
      gdk_window_move_resize (widget->window,
1245 1246 1247 1248
                              x, y, width, height);   

      get_text_area_size (entry, &x, &y, &width, &height);
      
Elliot Lee's avatar
Elliot Lee committed
1249
      gdk_window_move_resize (entry->text_area,
1250
                              x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
1251

Owen Taylor's avatar
Owen Taylor committed
1252
      gtk_entry_recompute (entry);
Elliot Lee's avatar
Elliot Lee committed
1253 1254 1255
    }
}

Owen Taylor's avatar
Owen Taylor committed
1256 1257
static void
gtk_entry_draw_focus (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
1258
{
Owen Taylor's avatar
Owen Taylor committed
1259
  gint width, height;
1260
  GtkEntry *entry;
1261
  gboolean interior_focus;
1262
  
Owen Taylor's avatar
Owen Taylor committed
1263
  g_return_if_fail (GTK_IS_ENTRY (widget));
Elliot Lee's avatar
Elliot Lee committed
1264

1265 1266
  gtk_widget_style_get (widget, "interior_focus", &interior_focus, NULL);

1267 1268
  entry = GTK_ENTRY (widget);
  
Owen Taylor's avatar
Owen Taylor committed
1269
  if (GTK_WIDGET_DRAWABLE (widget))
1270 1271 1272 1273
    {      
      if (entry->has_frame)
        {
          gint x = 0, y = 0;
Elliot Lee's avatar
Elliot Lee committed
1274

1275 1276
          gdk_window_get_size (widget->window, &width, &height);

1277
          if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
1278 1279 1280 1281 1282 1283
            {
              x += 1;
              y += 1;
              width -= 2;
              height -= 2;
            }
Elliot Lee's avatar
Elliot Lee committed
1284

1285 1286 1287 1288 1289 1290 1291 1292
          gtk_paint_shadow (widget->style, widget->window,
                            GTK_STATE_NORMAL, GTK_SHADOW_IN,
                            NULL, widget, "entry",
                            x, y, width, height);
        }
      else
        gdk_window_clear (widget->window);
        
1293
      if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
1294 1295 1296 1297 1298 1299
        {
          gdk_window_get_size (widget->window, &width, &height);
          gtk_paint_focus (widget->style, widget->window, 
                           NULL, widget, "entry",
                           0, 0, width - 1, height - 1);
        }
Owen Taylor's avatar
Owen Taylor committed
1300 1301 1302 1303 1304 1305
    }
}

static gint
gtk_entry_expose (GtkWidget      *widget,
		  GdkEventExpose *event)
Elliot Lee's avatar
Elliot Lee committed
1306 1307 1308 1309 1310 1311
{
  GtkEntry *entry;

  g_return_val_if_fail (GTK_IS_ENTRY (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

Owen Taylor's avatar
Owen Taylor committed
1312 1313 1314
  entry = GTK_ENTRY (widget);

  if (widget->window == event->window)
1315
    gtk_entry_draw_focus (widget);
Owen Taylor's avatar
Owen Taylor committed
1316 1317 1318
  else if (entry->text_area == event->window)
    {
      gtk_entry_draw_text (GTK_ENTRY (widget));
Owen Taylor's avatar
Owen Taylor committed
1319 1320 1321

      if ((entry->visible || entry->invisible_char != 0) &&
	  GTK_WIDGET_HAS_FOCUS (widget) &&
1322
	  entry->selection_bound == entry->current_pos && entry->cursor_visible)
Owen Taylor's avatar
Owen Taylor committed
1323 1324 1325 1326
	gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);

      if (entry->dnd_position != -1)
	gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
Owen Taylor's avatar
Owen Taylor committed
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
    }

  return FALSE;
}

static gint
gtk_entry_button_press (GtkWidget      *widget,
			GdkEventButton *event)
{
  GtkEntry *entry = GTK_ENTRY (widget);
  GtkEditable *editable = GTK_EDITABLE (widget);
  gint tmp_pos;
Owen Taylor's avatar
Owen Taylor committed
1339
  gint sel_start, sel_end;
1340

Elliot Lee's avatar
Elliot Lee committed
1341
  entry = GTK_ENTRY (widget);
1342 1343
  editable = GTK_EDITABLE (widget);
  
Owen Taylor's avatar
Owen Taylor committed
1344 1345
  if (event->window != entry->text_area ||
      (entry->button && event->button != entry->button))
1346
    return FALSE;
1347 1348 1349

  entry->button = event->button;
  
Elliot Lee's avatar
Elliot Lee committed
1350
  if (!GTK_WIDGET_HAS_FOCUS (widget))
1351 1352 1353 1354 1355
    {
      entry->in_click = TRUE;
      gtk_widget_grab_focus (widget);
      entry->in_click = FALSE;
    }
Owen Taylor's avatar
Owen Taylor committed
1356 1357 1358
  
  tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
    
Elliot Lee's avatar
Elliot Lee committed
1359 1360
  if (event->button == 1)
    {
1361 1362 1363 1364
      gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
      
      if (event->state & GDK_SHIFT_MASK)
	{
1365 1366
	  gtk_entry_reset_im_context (entry);
	  
1367 1368 1369 1370 1371 1372
	  if (!have_selection) /* select from the current position to the clicked position */
	    sel_start = sel_end = entry->current_pos;
	  
	  if (tmp_pos > sel_start && tmp_pos < sel_end)
	    {
	      /* Truncate current selection */
1373
	      gtk_entry_set_positions (entry, tmp_pos, -1);
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
	    }
	  else
	    {
	      gboolean extend_to_left;
	      gint start, end;

	      /* Figure out what click selects and extend current selection */
	      switch (event->type)
		{
		case GDK_BUTTON_PRESS:
1384
		  gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
		  break;
		  
		case GDK_2BUTTON_PRESS:
		  gtk_entry_select_word (entry);
		  break;
		  
		case GDK_3BUTTON_PRESS:
		  gtk_entry_select_line (entry);
		  break;

		default:
		  break;
		}

	      start = MIN (entry->current_pos, entry->selection_bound);
	      start = MIN (sel_start, start);
	      
	      end = MAX (entry->current_pos, entry->selection_bound);
	      end = MAX (sel_end, end);

	      if (tmp_pos == sel_start || tmp_pos == sel_end)
		extend_to_left = (tmp_pos == start);
	      else
		extend_to_left = (end == sel_end);
	      
	      if (extend_to_left)
1411
		gtk_entry_set_positions (entry, start, end);
1412
	      else
1413
		gtk_entry_set_positions (entry, end, start);
1414 1415 1416 1417
	    }
	}
      else /* no shift key */
	switch (event->type)
Elliot Lee's avatar
Elliot Lee committed
1418 1419
	{
	case GDK_BUTTON_PRESS:
1420
	  if (have_selection && tmp_pos >= sel_start && tmp_pos <= sel_end)
Owen Taylor's avatar
Owen Taylor committed
1421 1422 1423 1424
	    {
	      /* Click inside the selection - we'll either start a drag, or
	       * clear the selection
	       */
Owen Taylor's avatar
Owen Taylor committed
1425

Owen Taylor's avatar
Owen Taylor committed
1426 1427 1428 1429 1430
	      entry->in_drag = TRUE;
	      entry->drag_start_x = event->x + entry->scroll_offset;
	      entry->drag_start_y = event->y + entry->scroll_offset;
	    }
	  else
1431
	    gtk_editable_set_position (editable, tmp_pos);
Owen Taylor's avatar
Owen Taylor committed
1432
	  
Elliot Lee's avatar
Elliot Lee committed
1433 1434
	  break;

1435
 
Elliot Lee's avatar
Elliot Lee committed
1436
	case GDK_2BUTTON_PRESS:
1437 1438 1439 1440 1441
	  /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before 
	   * receiving a GDK_2BUTTON_PRESS so we need to reset
 	   * entry->in_drag which may have been set above
           */
	  entry->in_drag = FALSE;
Owen Taylor's avatar
Owen Taylor committed
1442
	  gtk_entry_select_word (entry);
Elliot Lee's avatar
Elliot Lee committed
1443
	  break;
1444
	
Elliot Lee's avatar
Elliot Lee committed
1445
	case GDK_3BUTTON_PRESS:
1446 1447 1448 1449 1450
	  /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
	   * receiving a GDK_3BUTTON_PRESS so we need to reset
	   * entry->in_drag which may have been set above
	   */
	  entry->in_drag = FALSE;
Owen Taylor's avatar
Owen Taylor committed
1451
	  gtk_entry_select_line (entry);
Elliot Lee's avatar
Elliot Lee committed
1452 1453 1454 1455 1456
	  break;

	default:
	  break;
	}
Owen Taylor's avatar
Owen Taylor committed
1457 1458

      return TRUE;
Elliot Lee's avatar
Elliot Lee committed
1459
    }
Owen Taylor's avatar
Owen Taylor committed
1460
  else if (event->button == 2 && event->type == GDK_BUTTON_PRESS && entry->editable)
Elliot Lee's avatar
Elliot Lee committed
1461
    {
Owen Taylor's avatar
Owen Taylor committed
1462 1463
      gtk_editable_select_region (editable, tmp_pos, tmp_pos);
      gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
1464

Owen Taylor's avatar
Owen Taylor committed
1465 1466 1467 1468
      return TRUE;
    }
  else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
    {
1469
      gtk_entry_do_popup (entry, event);
Owen Taylor's avatar
Owen Taylor committed
1470
      entry->button = 0;	/* Don't wait for release, since the menu will gtk_grab_add */
Owen Taylor's avatar
Owen Taylor committed
1471 1472

      return TRUE;
Elliot Lee's avatar
Elliot Lee committed
1473 1474 1475 1476 1477 1478 1479 1480 1481
    }

  return FALSE;
}

static gint
gtk_entry_button_release (GtkWidget      *widget,
			  GdkEventButton *event)
{
Owen Taylor's avatar
Owen Taylor committed
1482
  GtkEntry *entry = GTK_ENTRY (widget);
1483

Owen Taylor's avatar
Owen Taylor committed
1484
  if (event->window != entry->text_area || entry->button != event->button)
1485 1486
    return FALSE;

Owen Taylor's avatar
Owen Taylor committed
1487 1488 1489 1490
  if (entry->in_drag)
    {
      gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);

1491
      gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
Owen Taylor's avatar
Owen Taylor committed
1492 1493 1494 1495

      entry->in_drag = 0;
    }
  
1496 1497
  entry->button = 0;
  
Owen Taylor's avatar
Owen Taylor committed
1498 1499
  gtk_entry_update_primary_selection (entry);
	      
1500
  return TRUE;
Elliot Lee's avatar
Elliot Lee committed
1501 1502 1503 1504 1505 1506
}

static gint
gtk_entry_motion_notify (GtkWidget      *widget,
			 GdkEventMotion *event)
{
Owen Taylor's avatar
Owen Taylor committed
1507 1508
  GtkEntry *entry = GTK_ENTRY (widget);
  gint tmp_pos;
Elliot Lee's avatar
Elliot Lee committed
1509

Owen Taylor's avatar
Owen Taylor committed
1510
  if (event->window != entry->text_area || entry->button != 1)
1511 1512
    return FALSE;

Elliot Lee's avatar
Elliot Lee committed
1513
  if (event->is_hint || (entry->text_area != event->window))
Owen Taylor's avatar
Owen Taylor committed
1514
    gdk_window_get_pointer (entry->text_area, NULL, NULL, NULL);
Elliot Lee's avatar
Elliot Lee committed
1515

Owen Taylor's avatar
Owen Taylor committed
1516 1517 1518 1519 1520 1521 1522 1523
  if (entry->in_drag)
    {
      if (gtk_drag_check_threshold (widget,
				    entry->drag_start_x, entry->drag_start_y,
				    event->x + entry->scroll_offset, event->y))
	{
	  GdkDragContext *context;
	  GtkTargetList *target_list = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table));
1524
	  guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
Owen Taylor's avatar
Owen Taylor committed
1525
	  
1526
	  context = gtk_drag_begin (widget, target_list, actions,
Owen Taylor's avatar
Owen Taylor committed
1527
			  entry->button, (GdkEvent *)event);
Elliot Lee's avatar
Elliot Lee committed
1528

Owen Taylor's avatar
Owen Taylor committed
1529