gtkentry.c 297 KB
Newer Older
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Cody Russell's avatar
Cody Russell committed
2
/* GTK - The GIMP Toolkit
Elliot Lee's avatar
Elliot Lee committed
3
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 5 6
 * Copyright (C) 2004-2006 Christian Hammond
 * Copyright (C) 2008 Cody Russell
 * Copyright (C) 2008 Red Hat, Inc.
Elliot Lee's avatar
Elliot Lee committed
7 8
 *
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
10 11 12 13 14 15
 * 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
16
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19 20 21
 * 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
22
 */
23 24

/*
25
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
26 27
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
28
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 30
 */

31
#include "config.h"
32 33

#include <math.h>
Elliot Lee's avatar
Elliot Lee committed
34
#include <string.h>
Owen Taylor's avatar
Owen Taylor committed
35

Elliot Lee's avatar
Elliot Lee committed
36
#include "gdk/gdkkeysyms.h"
37
#include "gtkalignment.h"
Owen Taylor's avatar
Owen Taylor committed
38
#include "gtkbindings.h"
39
#include "gtkcelleditable.h"
Owen Taylor's avatar
Owen Taylor committed
40
#include "gtkclipboard.h"
Owen Taylor's avatar
Owen Taylor committed
41
#include "gtkdnd.h"
Elliot Lee's avatar
Elliot Lee committed
42
#include "gtkentry.h"
43
#include "gtkentrybuffer.h"
44
#include "gtkimagemenuitem.h"
45
#include "gtkimcontextsimple.h"
46
#include "gtkimmulticontext.h"
Owen Taylor's avatar
Owen Taylor committed
47
#include "gtkintl.h"
48
#include "gtklabel.h"
Elliot Lee's avatar
Elliot Lee committed
49
#include "gtkmain.h"
50
#include "gtkmarshalers.h"
Owen Taylor's avatar
Owen Taylor committed
51 52
#include "gtkmenu.h"
#include "gtkmenuitem.h"
53
#include "gtkseparatormenuitem.h"
Elliot Lee's avatar
Elliot Lee committed
54
#include "gtkselection.h"
55
#include "gtksettings.h"
56
#include "gtkspinbutton.h"
57
#include "gtkstock.h"
58
#include "gtktextutil.h"
59
#include "gtkwindow.h"
60 61
#include "gtktreeview.h"
#include "gtktreeselection.h"
62
#include "gtkprivate.h"
63 64
#include "gtkentryprivate.h"
#include "gtkcelllayout.h"
65 66 67
#include "gtktooltip.h"
#include "gtkiconfactory.h"
#include "gtkicontheme.h"
68
#include "gtkalias.h"
69 70

#define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
71

Elliot Lee's avatar
Elliot Lee committed
72 73
#define MIN_ENTRY_WIDTH  150
#define DRAW_TIMEOUT     20
74
#define COMPLETION_TIMEOUT 300
75
#define PASSWORD_HINT_MAX 8
Elliot Lee's avatar
Elliot Lee committed
76

77 78 79 80 81 82
#define MAX_ICONS 2

#define IS_VALID_ICON_POSITION(pos)               \
  ((pos) == GTK_ENTRY_ICON_PRIMARY ||                   \
   (pos) == GTK_ENTRY_ICON_SECONDARY)

83 84
static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
static GQuark          quark_inner_border   = 0;
85
static GQuark          quark_password_hint  = 0;
86
static GQuark          quark_cursor_hadjustment = 0;
87
static GQuark          quark_capslock_feedback = 0;
88

89 90 91 92
typedef struct _GtkEntryPrivate GtkEntryPrivate;

#define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
typedef struct
{
  GdkWindow *window;
  gchar *tooltip;
  guint insensitive    : 1;
  guint nonactivatable : 1;
  guint prelight       : 1;
  guint in_drag        : 1;
  guint pressed        : 1;

  GtkImageType  storage_type;
  GdkPixbuf    *pixbuf;
  gchar        *stock_id;
  gchar        *icon_name;
  GIcon        *gicon;

  GtkTargetList *target_list;
  GdkDragAction actions;
} EntryIconInfo;

113 114
struct _GtkEntryPrivate 
{
115 116
  GtkEntryBuffer* buffer;

117
  gfloat xalign;
118
  gint insert_pos;
119
  guint blink_time;  /* time in msec the cursor has blinked since last user event */
120 121 122 123
  guint interior_focus          : 1;
  guint real_changed            : 1;
  guint invisible_char_set      : 1;
  guint caps_lock_warning       : 1;
124
  guint caps_lock_warning_shown : 1;
125 126 127
  guint change_count            : 8;
  guint progress_pulse_mode     : 1;
  guint progress_pulse_way_back : 1;
128 129 130

  gint focus_width;
  GtkShadowType shadow_type;
131 132 133 134

  gdouble progress_fraction;
  gdouble progress_pulse_fraction;
  gdouble progress_pulse_current;
135 136 137 138 139

  EntryIconInfo *icons[MAX_ICONS];
  gint icon_margin;
  gint start_x;
  gint start_y;
140 141

  gchar *im_module;
142 143 144
};

typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
145

146 147
struct _GtkEntryPasswordHint
{
148 149
  gint position;      /* Position (in text) of the last password hint */
  guint source_id;    /* Timeout source id */
150 151
};

152 153 154 155 156 157 158 159 160
typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;

struct _GtkEntryCapslockFeedback
{
  GtkWidget *entry;
  GtkWidget *window;
  GtkWidget *label;
};

Owen Taylor's avatar
Owen Taylor committed
161 162
enum {
  ACTIVATE,
163
  POPULATE_POPUP,
Owen Taylor's avatar
Owen Taylor committed
164 165 166
  MOVE_CURSOR,
  INSERT_AT_CURSOR,
  DELETE_FROM_CURSOR,
167
  BACKSPACE,
Owen Taylor's avatar
Owen Taylor committed
168 169 170 171
  CUT_CLIPBOARD,
  COPY_CLIPBOARD,
  PASTE_CLIPBOARD,
  TOGGLE_OVERWRITE,
172 173
  ICON_PRESS,
  ICON_RELEASE,
174
  PREEDIT_CHANGED,
Owen Taylor's avatar
Owen Taylor committed
175 176 177
  LAST_SIGNAL
};

178
enum {
Havoc Pennington's avatar
Havoc Pennington committed
179
  PROP_0,
180
  PROP_BUFFER,
181 182
  PROP_CURSOR_POSITION,
  PROP_SELECTION_BOUND,
Havoc Pennington's avatar
Havoc Pennington committed
183 184 185
  PROP_EDITABLE,
  PROP_MAX_LENGTH,
  PROP_VISIBILITY,
186
  PROP_HAS_FRAME,
187
  PROP_INNER_BORDER,
188
  PROP_INVISIBLE_CHAR,
189
  PROP_ACTIVATES_DEFAULT,
190
  PROP_WIDTH_CHARS,
191
  PROP_SCROLL_OFFSET,
192
  PROP_TEXT,
193
  PROP_XALIGN,
194
  PROP_TRUNCATE_MULTILINE,
Tim Janik's avatar
Tim Janik committed
195 196
  PROP_SHADOW_TYPE,
  PROP_OVERWRITE_MODE,
197
  PROP_TEXT_LENGTH,
198
  PROP_INVISIBLE_CHAR_SET,
199 200
  PROP_CAPS_LOCK_WARNING,
  PROP_PROGRESS_FRACTION,
201 202 203 204 205 206 207 208 209 210 211 212 213 214
  PROP_PROGRESS_PULSE_STEP,
  PROP_PIXBUF_PRIMARY,
  PROP_PIXBUF_SECONDARY,
  PROP_STOCK_PRIMARY,
  PROP_STOCK_SECONDARY,
  PROP_ICON_NAME_PRIMARY,
  PROP_ICON_NAME_SECONDARY,
  PROP_GICON_PRIMARY,
  PROP_GICON_SECONDARY,
  PROP_STORAGE_TYPE_PRIMARY,
  PROP_STORAGE_TYPE_SECONDARY,
  PROP_ACTIVATABLE_PRIMARY,
  PROP_ACTIVATABLE_SECONDARY,
  PROP_SENSITIVE_PRIMARY,
215
  PROP_SENSITIVE_SECONDARY,
216 217 218 219
  PROP_TOOLTIP_TEXT_PRIMARY,
  PROP_TOOLTIP_TEXT_SECONDARY,
  PROP_TOOLTIP_MARKUP_PRIMARY,
  PROP_TOOLTIP_MARKUP_SECONDARY,
220 221
  PROP_IM_MODULE,
  PROP_EDITING_CANCELED
222 223
};

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

Owen Taylor's avatar
Owen Taylor committed
226 227 228 229 230
typedef enum {
  CURSOR_STANDARD,
  CURSOR_DND
} CursorType;

231 232 233 234 235 236 237
typedef enum
{
  DISPLAY_NORMAL,       /* The entry text is being shown */
  DISPLAY_INVISIBLE,    /* In invisible mode, text replaced by (eg) bullets */
  DISPLAY_BLANK         /* In invisible mode, nothing shown at all */
} DisplayMode;

Owen Taylor's avatar
Owen Taylor committed
238 239
/* GObject, GtkObject methods
 */
240 241
static void   gtk_entry_editable_init        (GtkEditableClass     *iface);
static void   gtk_entry_cell_editable_init   (GtkCellEditableIface *iface);
242 243 244 245 246 247 248 249
static void   gtk_entry_set_property         (GObject          *object,
                                              guint             prop_id,
                                              const GValue     *value,
                                              GParamSpec       *pspec);
static void   gtk_entry_get_property         (GObject          *object,
                                              guint             prop_id,
                                              GValue           *value,
                                              GParamSpec       *pspec);
250
static void   gtk_entry_finalize             (GObject          *object);
251
static void   gtk_entry_destroy              (GtkObject        *object);
252
static void   gtk_entry_dispose              (GObject          *object);
Owen Taylor's avatar
Owen Taylor committed
253 254 255

/* GtkWidget methods
 */
256 257
static void   gtk_entry_realize              (GtkWidget        *widget);
static void   gtk_entry_unrealize            (GtkWidget        *widget);
258 259
static void   gtk_entry_map                  (GtkWidget        *widget);
static void   gtk_entry_unmap                (GtkWidget        *widget);
260 261 262 263
static void   gtk_entry_size_request         (GtkWidget        *widget,
					      GtkRequisition   *requisition);
static void   gtk_entry_size_allocate        (GtkWidget        *widget,
					      GtkAllocation    *allocation);
264
static void   gtk_entry_draw_frame           (GtkWidget        *widget,
265
                                              GdkEventExpose   *event);
266 267
static void   gtk_entry_draw_progress        (GtkWidget        *widget,
                                              GdkEventExpose   *event);
268 269 270 271 272 273
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);
274 275 276 277
static gint   gtk_entry_enter_notify         (GtkWidget        *widget,
                                              GdkEventCrossing *event);
static gint   gtk_entry_leave_notify         (GtkWidget        *widget,
                                              GdkEventCrossing *event);
278 279 280 281
static gint   gtk_entry_motion_notify        (GtkWidget        *widget,
					      GdkEventMotion   *event);
static gint   gtk_entry_key_press            (GtkWidget        *widget,
					      GdkEventKey      *event);
282 283
static gint   gtk_entry_key_release          (GtkWidget        *widget,
					      GdkEventKey      *event);
284 285 286 287
static gint   gtk_entry_focus_in             (GtkWidget        *widget,
					      GdkEventFocus    *event);
static gint   gtk_entry_focus_out            (GtkWidget        *widget,
					      GdkEventFocus    *event);
288
static void   gtk_entry_grab_focus           (GtkWidget        *widget);
289 290
static void   gtk_entry_style_set            (GtkWidget        *widget,
					      GtkStyle         *previous_style);
291 292 293 294 295
static gboolean gtk_entry_query_tooltip      (GtkWidget        *widget,
                                              gint              x,
                                              gint              y,
                                              gboolean          keyboard_tip,
                                              GtkTooltip       *tooltip);
296 297 298 299
static void   gtk_entry_direction_changed    (GtkWidget        *widget,
					      GtkTextDirection  previous_dir);
static void   gtk_entry_state_changed        (GtkWidget        *widget,
					      GtkStateType      previous_state);
300 301
static void   gtk_entry_screen_changed       (GtkWidget        *widget,
					      GdkScreen        *old_screen);
Owen Taylor's avatar
Owen Taylor committed
302

303 304 305 306 307
static gboolean gtk_entry_drag_drop          (GtkWidget        *widget,
                                              GdkDragContext   *context,
                                              gint              x,
                                              gint              y,
                                              guint             time);
Owen Taylor's avatar
Owen Taylor committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
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);
330 331 332 333 334
static void     gtk_entry_drag_begin         (GtkWidget        *widget,
                                              GdkDragContext   *context);
static void     gtk_entry_drag_end           (GtkWidget        *widget,
                                              GdkDragContext   *context);

Owen Taylor's avatar
Owen Taylor committed
335

Owen Taylor's avatar
Owen Taylor committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
/* 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);

358 359 360 361 362
/* GtkCellEditable method implementations
 */
static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
				     GdkEvent        *event);

Owen Taylor's avatar
Owen Taylor committed
363 364
/* Default signal handlers
 */
365
static void gtk_entry_real_insert_text   (GtkEditable     *editable,
366 367 368
					  const gchar     *new_text,
					  gint             new_text_length,
					  gint            *position);
369
static void gtk_entry_real_delete_text   (GtkEditable     *editable,
370 371 372 373 374 375 376 377 378 379 380
					  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);
381
static void gtk_entry_backspace          (GtkEntry        *entry);
382 383 384 385
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);
386
static void gtk_entry_select_all         (GtkEntry        *entry);
387
static void gtk_entry_real_activate      (GtkEntry        *entry);
388 389 390 391 392 393 394
static gboolean gtk_entry_popup_menu     (GtkWidget       *widget);

static void keymap_direction_changed     (GdkKeymap       *keymap,
					  GtkEntry        *entry);
static void keymap_state_changed         (GdkKeymap       *keymap,
					  GtkEntry        *entry);
static void remove_capslock_feedback     (GtkEntry        *entry);
Owen Taylor's avatar
Owen Taylor committed
395 396 397

/* IM Context Callbacks
 */
398 399 400 401 402 403 404 405 406 407 408 409
static void     gtk_entry_commit_cb               (GtkIMContext *context,
						   const gchar  *str,
						   GtkEntry     *entry);
static void     gtk_entry_preedit_changed_cb      (GtkIMContext *context,
						   GtkEntry     *entry);
static gboolean gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
						   GtkEntry     *entry);
static gboolean gtk_entry_delete_surrounding_cb   (GtkIMContext *context,
						   gint          offset,
						   gint          n_chars,
						   GtkEntry     *entry);

Owen Taylor's avatar
Owen Taylor committed
410 411
/* Internal routines
 */
412 413
static void         gtk_entry_enter_text               (GtkEntry       *entry,
                                                        const gchar    *str);
414 415 416
static void         gtk_entry_set_positions            (GtkEntry       *entry,
							gint            current_pos,
							gint            selection_bound);
Owen Taylor's avatar
Owen Taylor committed
417
static void         gtk_entry_draw_text                (GtkEntry       *entry);
Owen Taylor's avatar
Owen Taylor committed
418 419
static void         gtk_entry_draw_cursor              (GtkEntry       *entry,
							CursorType      type);
420 421
static PangoLayout *gtk_entry_ensure_layout            (GtkEntry       *entry,
                                                        gboolean        include_preedit);
422
static void         gtk_entry_reset_layout             (GtkEntry       *entry);
Owen Taylor's avatar
Owen Taylor committed
423 424 425 426 427
static void         gtk_entry_queue_draw               (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
428
							CursorType      type,
Owen Taylor's avatar
Owen Taylor committed
429 430
							gint           *strong_x,
							gint           *weak_x);
431
static void         gtk_entry_adjust_scroll            (GtkEntry       *entry);
Owen Taylor's avatar
Owen Taylor committed
432 433 434
static gint         gtk_entry_move_visually            (GtkEntry       *editable,
							gint            start,
							gint            count);
435 436 437
static gint         gtk_entry_move_logically           (GtkEntry       *entry,
							gint            start,
							gint            count);
Owen Taylor's avatar
Owen Taylor committed
438
static gint         gtk_entry_move_forward_word        (GtkEntry       *entry,
439 440
							gint            start,
                                                        gboolean        allow_whitespace);
Owen Taylor's avatar
Owen Taylor committed
441
static gint         gtk_entry_move_backward_word       (GtkEntry       *entry,
442 443
							gint            start,
                                                        gboolean        allow_whitespace);
Owen Taylor's avatar
Owen Taylor committed
444 445 446 447 448 449
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 void         gtk_entry_paste                    (GtkEntry       *entry,
							GdkAtom         selection);
static void         gtk_entry_update_primary_selection (GtkEntry       *entry);
450
static void         gtk_entry_do_popup                 (GtkEntry       *entry,
Owen Taylor's avatar
Owen Taylor committed
451
							GdkEventButton *event);
452 453
static gboolean     gtk_entry_mnemonic_activate        (GtkWidget      *widget,
							gboolean        group_cycling);
454 455
static void         gtk_entry_check_cursor_blink       (GtkEntry       *entry);
static void         gtk_entry_pend_cursor_blink        (GtkEntry       *entry);
456
static void         gtk_entry_reset_blink_time         (GtkEntry       *entry);
457 458 459 460 461
static void         gtk_entry_get_text_area_size       (GtkEntry       *entry,
							gint           *x,
							gint           *y,
							gint           *width,
							gint           *height);
462 463 464 465 466
static void         get_text_area_size                 (GtkEntry       *entry,
							gint           *x,
							gint           *y,
							gint           *width,
							gint           *height);
467 468 469 470 471
static void         get_widget_window_size             (GtkEntry       *entry,
							gint           *x,
							gint           *y,
							gint           *width,
							gint           *height);
472 473 474 475
static void         gtk_entry_move_adjustments         (GtkEntry             *entry);
static void         gtk_entry_ensure_pixbuf            (GtkEntry             *entry,
                                                        GtkEntryIconPosition  icon_pos);

476

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
/* Completion */
static gint         gtk_entry_completion_timeout       (gpointer            data);
static gboolean     gtk_entry_completion_key_press     (GtkWidget          *widget,
							GdkEventKey        *event,
							gpointer            user_data);
static void         gtk_entry_completion_changed       (GtkWidget          *entry,
							gpointer            user_data);
static gboolean     check_completion_callback          (GtkEntryCompletion *completion);
static void         clear_completion_callback          (GtkEntry           *entry,
							GParamSpec         *pspec);
static gboolean     accept_completion_callback         (GtkEntry           *entry);
static void         completion_insert_text_callback    (GtkEntry           *entry,
							const gchar        *text,
							gint                length,
							gint                position,
							GtkEntryCompletion *completion);
static void         completion_changed                 (GtkEntryCompletion *completion,
							GParamSpec         *pspec,
							gpointer            data);
static void         disconnect_completion_signals      (GtkEntry           *entry,
							GtkEntryCompletion *completion);
static void         connect_completion_signals         (GtkEntry           *entry,
							GtkEntryCompletion *completion);

501 502 503
static void         begin_change                       (GtkEntry *entry);
static void         end_change                         (GtkEntry *entry);
static void         emit_changed                       (GtkEntry *entry);
504

505

506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
static void         buffer_inserted_text               (GtkEntryBuffer *buffer, 
                                                        guint           position,
                                                        const gchar    *chars,
                                                        guint           n_chars,
                                                        GtkEntry       *entry);
static void         buffer_deleted_text                (GtkEntryBuffer *buffer, 
                                                        guint           position,
                                                        guint           n_chars,
                                                        GtkEntry       *entry);
static void         buffer_notify_text                 (GtkEntryBuffer *buffer, 
                                                        GParamSpec     *spec,
                                                        GtkEntry       *entry);
static void         buffer_notify_length               (GtkEntryBuffer *buffer, 
                                                        GParamSpec     *spec,
                                                        GtkEntry       *entry);
static void         buffer_notify_max_length           (GtkEntryBuffer *buffer, 
                                                        GParamSpec     *spec,
                                                        GtkEntry       *entry);
static void         buffer_connect_signals             (GtkEntry       *entry);
static void         buffer_disconnect_signals          (GtkEntry       *entry);
526 527
static GtkEntryBuffer *get_buffer                      (GtkEntry       *entry);

528

Matthias Clasen's avatar
Matthias Clasen committed
529 530 531 532
G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
                                                gtk_entry_editable_init)
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
Matthias Clasen's avatar
Matthias Clasen committed
533
                                                gtk_entry_cell_editable_init))
Elliot Lee's avatar
Elliot Lee committed
534

Owen Taylor's avatar
Owen Taylor committed
535 536 537 538 539 540 541 542 543 544
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,
545
				"move-cursor", 3,
Manish Singh's avatar
Manish Singh committed
546
				G_TYPE_ENUM, step,
Owen Taylor's avatar
Owen Taylor committed
547
				G_TYPE_INT, count,
Manish Singh's avatar
Manish Singh committed
548
				G_TYPE_BOOLEAN, FALSE);
Owen Taylor's avatar
Owen Taylor committed
549 550 551

  /* Selection-extending version */
  gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
552
				"move-cursor", 3,
Manish Singh's avatar
Manish Singh committed
553
				G_TYPE_ENUM, step,
Owen Taylor's avatar
Owen Taylor committed
554
				G_TYPE_INT, count,
Manish Singh's avatar
Manish Singh committed
555
				G_TYPE_BOOLEAN, TRUE);
Owen Taylor's avatar
Owen Taylor committed
556 557
}

Elliot Lee's avatar
Elliot Lee committed
558 559 560
static void
gtk_entry_class_init (GtkEntryClass *class)
{
561
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
Elliot Lee's avatar
Elliot Lee committed
562
  GtkWidgetClass *widget_class;
563
  GtkObjectClass *gtk_object_class;
Owen Taylor's avatar
Owen Taylor committed
564
  GtkBindingSet *binding_set;
Elliot Lee's avatar
Elliot Lee committed
565 566

  widget_class = (GtkWidgetClass*) class;
567
  gtk_object_class = (GtkObjectClass *)class;
Elliot Lee's avatar
Elliot Lee committed
568

569
  gobject_class->dispose = gtk_entry_dispose;
570
  gobject_class->finalize = gtk_entry_finalize;
Havoc Pennington's avatar
Havoc Pennington committed
571 572
  gobject_class->set_property = gtk_entry_set_property;
  gobject_class->get_property = gtk_entry_get_property;
573

574 575
  widget_class->map = gtk_entry_map;
  widget_class->unmap = gtk_entry_unmap;
576 577 578 579 580
  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;
581 582
  widget_class->enter_notify_event = gtk_entry_enter_notify;
  widget_class->leave_notify_event = gtk_entry_leave_notify;
583 584 585 586
  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;
587
  widget_class->key_release_event = gtk_entry_key_release;
588 589
  widget_class->focus_in_event = gtk_entry_focus_in;
  widget_class->focus_out_event = gtk_entry_focus_out;
590
  widget_class->grab_focus = gtk_entry_grab_focus;
591
  widget_class->style_set = gtk_entry_style_set;
592 593 594
  widget_class->query_tooltip = gtk_entry_query_tooltip;
  widget_class->drag_begin = gtk_entry_drag_begin;
  widget_class->drag_end = gtk_entry_drag_end;
595 596
  widget_class->direction_changed = gtk_entry_direction_changed;
  widget_class->state_changed = gtk_entry_state_changed;
597
  widget_class->screen_changed = gtk_entry_screen_changed;
598
  widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
599

600
  widget_class->drag_drop = gtk_entry_drag_drop;
Owen Taylor's avatar
Owen Taylor committed
601 602 603 604 605 606
  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;

607
  widget_class->popup_menu = gtk_entry_popup_menu;
608

609 610
  gtk_object_class->destroy = gtk_entry_destroy;

611 612 613
  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;
614
  class->backspace = gtk_entry_backspace;
615 616 617 618
  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;
619
  class->activate = gtk_entry_real_activate;
620
  class->get_text_area_size = gtk_entry_get_text_area_size;
621
  
622
  quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
623
  quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
624
  quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
625
  quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
626

627 628 629 630
  g_object_class_override_property (gobject_class,
                                    PROP_EDITING_CANCELED,
                                    "editing-canceled");

631 632 633 634 635 636 637 638
  g_object_class_install_property (gobject_class,
                                   PROP_BUFFER,
                                   g_param_spec_object ("buffer",
                                                        P_("Text Buffer"),
                                                        P_("Text buffer object which actually stores entry text"),
                                                        GTK_TYPE_ENTRY_BUFFER,
                                                        GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));

Havoc Pennington's avatar
Havoc Pennington committed
639
  g_object_class_install_property (gobject_class,
640
                                   PROP_CURSOR_POSITION,
Matthias Clasen's avatar
x  
Matthias Clasen committed
641
                                   g_param_spec_int ("cursor-position",
642 643
                                                     P_("Cursor Position"),
                                                     P_("The current position of the insertion cursor in chars"),
Havoc Pennington's avatar
Havoc Pennington committed
644
                                                     0,
645
                                                     GTK_ENTRY_BUFFER_MAX_SIZE,
Havoc Pennington's avatar
Havoc Pennington committed
646
                                                     0,
647
                                                     GTK_PARAM_READABLE));
648 649 650
  
  g_object_class_install_property (gobject_class,
                                   PROP_SELECTION_BOUND,
Matthias Clasen's avatar
x  
Matthias Clasen committed
651
                                   g_param_spec_int ("selection-bound",
652 653
                                                     P_("Selection Bound"),
                                                     P_("The position of the opposite end of the selection from the cursor in chars"),
654
                                                     0,
655
                                                     GTK_ENTRY_BUFFER_MAX_SIZE,
656
                                                     0,
657
                                                     GTK_PARAM_READABLE));
Havoc Pennington's avatar
Havoc Pennington committed
658 659 660 661
  
  g_object_class_install_property (gobject_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
662 663
							 P_("Editable"),
							 P_("Whether the entry contents can be edited"),
Havoc Pennington's avatar
Havoc Pennington committed
664
                                                         TRUE,
665
							 GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
666 667 668
  
  g_object_class_install_property (gobject_class,
                                   PROP_MAX_LENGTH,
Matthias Clasen's avatar
x  
Matthias Clasen committed
669
                                   g_param_spec_int ("max-length",
670 671
                                                     P_("Maximum length"),
                                                     P_("Maximum number of characters for this entry. Zero if no maximum"),
672
                                                     0,
673
                                                     GTK_ENTRY_BUFFER_MAX_SIZE,
674
                                                     0,
675
                                                     GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
676 677 678
  g_object_class_install_property (gobject_class,
                                   PROP_VISIBILITY,
                                   g_param_spec_boolean ("visibility",
679 680
							 P_("Visibility"),
							 P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
Havoc Pennington's avatar
Havoc Pennington committed
681
                                                         TRUE,
682
							 GTK_PARAM_READWRITE));
683

Havoc Pennington's avatar
Havoc Pennington committed
684
  g_object_class_install_property (gobject_class,
685
                                   PROP_HAS_FRAME,
Matthias Clasen's avatar
x  
Matthias Clasen committed
686
                                   g_param_spec_boolean ("has-frame",
687 688
							 P_("Has Frame"),
							 P_("FALSE removes outside bevel from entry"),
689
                                                         TRUE,
690
							 GTK_PARAM_READWRITE));
691

692 693 694 695
  g_object_class_install_property (gobject_class,
                                   PROP_INNER_BORDER,
                                   g_param_spec_boxed ("inner-border",
                                                       P_("Inner Border"),
696
                                                       P_("Border between text and frame. Overrides the inner-border style property"),
697 698 699
                                                       GTK_TYPE_BORDER,
                                                       GTK_PARAM_READWRITE));

Morten Welinder's avatar
Morten Welinder committed
700
  g_object_class_install_property (gobject_class,
Havoc Pennington's avatar
Havoc Pennington committed
701
                                   PROP_INVISIBLE_CHAR,
Matthias Clasen's avatar
x  
Matthias Clasen committed
702
                                   g_param_spec_unichar ("invisible-char",
703 704
							 P_("Invisible character"),
							 P_("The character to use when masking entry contents (in \"password mode\")"),
705
							 '*',
706
							 GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
707

708 709
  g_object_class_install_property (gobject_class,
                                   PROP_ACTIVATES_DEFAULT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
710
                                   g_param_spec_boolean ("activates-default",
711 712
							 P_("Activates default"),
							 P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
713
                                                         FALSE,
714
							 GTK_PARAM_READWRITE));
715 716
  g_object_class_install_property (gobject_class,
                                   PROP_WIDTH_CHARS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
717
                                   g_param_spec_int ("width-chars",
718 719
                                                     P_("Width in chars"),
                                                     P_("Number of characters to leave space for in the entry"),
720 721 722
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
723
                                                     GTK_PARAM_READWRITE));
724

725 726
  g_object_class_install_property (gobject_class,
                                   PROP_SCROLL_OFFSET,
Matthias Clasen's avatar
x  
Matthias Clasen committed
727
                                   g_param_spec_int ("scroll-offset",
728 729
                                                     P_("Scroll offset"),
                                                     P_("Number of pixels of the entry scrolled off the screen to the left"),
730 731 732
                                                     0,
                                                     G_MAXINT,
                                                     0,
733
                                                     GTK_PARAM_READABLE));
734 735 736 737

  g_object_class_install_property (gobject_class,
                                   PROP_TEXT,
                                   g_param_spec_string ("text",
738 739
							P_("Text"),
							P_("The contents of the entry"),
740
							"",
741
							GTK_PARAM_READWRITE));
742

743 744 745 746 747 748 749 750
  /**
   * GtkEntry:xalign:
   *
   * The horizontal alignment, from 0 (left) to 1 (right). 
   * Reversed for RTL layouts.
   * 
   * Since: 2.4
   */
751 752 753 754
  g_object_class_install_property (gobject_class,
                                   PROP_XALIGN,
                                   g_param_spec_float ("xalign",
						       P_("X align"),
755
						       P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
756 757 758
						       0.0,
						       1.0,
						       0.0,
759
						       GTK_PARAM_READWRITE));
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775

  /**
   * GtkEntry:truncate-multiline:
   *
   * When %TRUE, pasted multi-line text is truncated to the first line.
   *
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TRUNCATE_MULTILINE,
                                   g_param_spec_boolean ("truncate-multiline",
                                                         P_("Truncate multiline"),
                                                         P_("Whether to truncate multiline pastes to one line."),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));

776 777 778
  /**
   * GtkEntry:shadow-type:
   *
779 780
   * Which kind of shadow to draw around the entry when 
   * #GtkEntry:has-frame is set to %TRUE.
781 782 783 784 785 786 787 788 789 790 791 792
   *
   * Since: 2.12
   */
  g_object_class_install_property (gobject_class,
                                   PROP_SHADOW_TYPE,
                                   g_param_spec_enum ("shadow-type",
                                                      P_("Shadow type"),
                                                      P_("Which kind of shadow to draw around the entry when has-frame is set"),
                                                      GTK_TYPE_SHADOW_TYPE,
                                                      GTK_SHADOW_IN,
                                                      GTK_PARAM_READWRITE));

Tim Janik's avatar
Tim Janik committed
793 794 795 796 797
  /**
   * GtkEntry:overwrite-mode:
   *
   * If text is overwritten when typing in the #GtkEntry.
   *
798
   * Since: 2.14
Tim Janik's avatar
Tim Janik committed
799 800 801 802 803 804 805 806
   */
  g_object_class_install_property (gobject_class,
                                   PROP_OVERWRITE_MODE,
                                   g_param_spec_boolean ("overwrite-mode",
                                                         P_("Overwrite mode"),
                                                         P_("Whether new text overwrites existing text"),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));
807

Tim Janik's avatar
Tim Janik committed
808 809 810 811 812
  /**
   * GtkEntry:text-length:
   *
   * The length of the text in the #GtkEntry.
   *
813
   * Since: 2.14
Tim Janik's avatar
Tim Janik committed
814 815 816 817 818 819 820 821 822 823
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TEXT_LENGTH,
                                   g_param_spec_uint ("text-length",
                                                      P_("Text length"),
                                                      P_("Length of the text currently in the entry"),
                                                      0, 
                                                      G_MAXUINT16,
                                                      0,
                                                      GTK_PARAM_READABLE));
824 825 826 827 828 829 830 831 832 833 834 835 836 837
  /**
   * GtkEntry:invisible-char-set:
   *
   * Whether the invisible char has been set for the #GtkEntry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_INVISIBLE_CHAR_SET,
                                   g_param_spec_boolean ("invisible-char-set",
                                                         P_("Invisible char set"),
                                                         P_("Whether the invisible char has been set"),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));
Tim Janik's avatar
Tim Janik committed
838

839 840 841
  /**
   * GtkEntry:caps-lock-warning
   *
842
   * Whether password entries will show a warning when Caps Lock is on.
843 844 845 846
   *
   * Note that the warning is shown using a secondary icon, and thus
   * does not work if you are using the secondary icon position for some 
   * other purpose.
847 848 849 850 851 852 853
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_CAPS_LOCK_WARNING,
                                   g_param_spec_boolean ("caps-lock-warning",
                                                         P_("Caps Lock warning"),
854
                                                         P_("Whether password entries will show a warning when Caps Lock is on"),
855 856 857
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));

858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
  /**
   * GtkEntry:progress-fraction:
   *
   * The current fraction of the task that's been completed.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_PROGRESS_FRACTION,
                                   g_param_spec_double ("progress-fraction",
                                                        P_("Progress Fraction"),
                                                        P_("The current fraction of the task that's been completed"),
                                                        0.0,
                                                        1.0,
                                                        0.0,
                                                        GTK_PARAM_READWRITE));

  /**
   * GtkEntry:progress-pulse-step:
   *
   * The fraction of total entry width to move the progress
   * bouncing block for each call to gtk_entry_progress_pulse().
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_PROGRESS_PULSE_STEP,
                                   g_param_spec_double ("progress-pulse-step",
                                                        P_("Progress Pulse Step"),
                                                        P_("The fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse()"),
                                                        0.0,
                                                        1.0,
                                                        0.1,
                                                        GTK_PARAM_READWRITE));

893
  /**
894
   * GtkEntry:primary-icon-pixbuf:
895 896 897 898 899 900 901
   *
   * A pixbuf to use as the primary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_PIXBUF_PRIMARY,
902
                                   g_param_spec_object ("primary-icon-pixbuf",
903 904 905 906 907 908
                                                        P_("Primary pixbuf"),
                                                        P_("Primary pixbuf for the entry"),
                                                        GDK_TYPE_PIXBUF,
                                                        GTK_PARAM_READWRITE));
  
  /**
909
   * GtkEntry:secondary-icon-pixbuf:
910 911 912 913 914 915 916
   *
   * An pixbuf to use as the secondary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_PIXBUF_SECONDARY,
917
                                   g_param_spec_object ("secondary-icon-pixbuf",
918 919 920 921 922 923
                                                        P_("Secondary pixbuf"),
                                                        P_("Secondary pixbuf for the entry"),
                                                        GDK_TYPE_PIXBUF,
                                                        GTK_PARAM_READWRITE));

  /**
924
   * GtkEntry:primary-icon-stock:
925 926 927 928 929 930 931
   *
   * The stock id to use for the primary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_STOCK_PRIMARY,
932
                                   g_param_spec_string ("primary-icon-stock",
933 934 935
                                                        P_("Primary stock ID"),
                                                        P_("Stock ID for primary icon"),
                                                        NULL,
936
                                                        GTK_PARAM_READWRITE));
937 938

  /**
939
   * GtkEntry:secondary-icon-stock:
940 941 942 943 944 945 946
   *
   * The stock id to use for the secondary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_STOCK_SECONDARY,
947
                                   g_param_spec_string ("secondary-icon-stock",
948 949 950
                                                        P_("Secondary stock ID"),
                                                        P_("Stock ID for secondary icon"),
                                                        NULL,
951
                                                        GTK_PARAM_READWRITE));
952 953
  
  /**
954
   * GtkEntry:primary-icon-name:
955 956 957 958 959 960 961
   *
   * The icon name to use for the primary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ICON_NAME_PRIMARY,
962
                                   g_param_spec_string ("primary-icon-name",
963 964 965
                                                        P_("Primary icon name"),
                                                        P_("Icon name for primary icon"),
                                                        NULL,
966
                                                        GTK_PARAM_READWRITE));
967 968
  
  /**
969
   * GtkEntry:secondary-icon-name:
970 971 972 973 974 975 976
   *
   * The icon name to use for the secondary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ICON_NAME_SECONDARY,
977
                                   g_param_spec_string ("secondary-icon-name",
978 979 980
                                                        P_("Secondary icon name"),
                                                        P_("Icon name for secondary icon"),
                                                        NULL,
981
                                                        GTK_PARAM_READWRITE));
982 983
  
  /**
984
   * GtkEntry:primary-icon-gicon:
985 986 987 988 989 990 991
   *
   * The #GIcon to use for the primary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_GICON_PRIMARY,
992
                                   g_param_spec_object ("primary-icon-gicon",
993 994 995 996 997 998
                                                        P_("Primary GIcon"),
                                                        P_("GIcon for primary icon"),
                                                        G_TYPE_ICON,
                                                        GTK_PARAM_READWRITE));
  
  /**
999
   * GtkEntry:secondary-icon-gicon:
1000 1001 1002 1003 1004 1005 1006
   *
   * The #GIcon to use for the secondary icon for the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_GICON_SECONDARY,
1007
                                   g_param_spec_object ("secondary-icon-gicon",
1008 1009 1010 1011 1012 1013
                                                        P_("Secondary GIcon"),
                                                        P_("GIcon for secondary icon"),
                                                        G_TYPE_ICON,
                                                        GTK_PARAM_READWRITE));
  
  /**
1014
   * GtkEntry:primary-icon-storage-type:
1015 1016 1017 1018 1019 1020 1021
   *
   * The representation which is used for the primary icon of the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_STORAGE_TYPE_PRIMARY,
1022
                                   g_param_spec_enum ("primary-icon-storage-type",
1023 1024 1025 1026 1027 1028 1029
                                                      P_("Primary storage type"),
                                                      P_("The representation being used for primary icon"),
                                                      GTK_TYPE_IMAGE_TYPE,
                                                      GTK_IMAGE_EMPTY,
                                                      GTK_PARAM_READABLE));
  
  /**
1030
   * GtkEntry:secondary-icon-storage-type:
1031 1032 1033 1034 1035 1036 1037
   *
   * The representation which is used for the secondary icon of the entry.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_STORAGE_TYPE_SECONDARY,
1038
                                   g_param_spec_enum ("secondary-icon-storage-type",
1039 1040 1041 1042 1043 1044 1045
                                                      P_("Secondary storage type"),
                                                      P_("The representation being used for secondary icon"),
                                                      GTK_TYPE_IMAGE_TYPE,
                                                      GTK_IMAGE_EMPTY,
                                                      GTK_PARAM_READABLE));
  
  /**
1046
   * GtkEntry:primary-icon-activatable:
1047 1048 1049
   *
   * Whether the primary icon is activatable.
   *
1050
   * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release 
Matthias Clasen's avatar
Matthias Clasen committed
1051 1052 1053 1054
   * signals only on sensitive, activatable icons. 
   *
   * Sensitive, but non-activatable icons can be used for purely 
   * informational purposes.
1055 1056 1057 1058 1059
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ACTIVATABLE_PRIMARY,
1060
                                   g_param_spec_boolean ("primary-icon-activatable",
1061 1062 1063 1064 1065 1066
                                                         P_("Primary icon activatable"),
                                                         P_("Whether the primary icon is activatable"),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));
  
  /**
1067
   * GtkEntry:secondary-icon-activatable:
1068 1069 1070
   *
   * Whether the secondary icon is activatable.
   *
1071
   * GTK+ emits the #GtkEntry::icon-press and #GtkEntry::icon-release 
Matthias Clasen's avatar
Matthias Clasen committed
1072 1073 1074 1075
   * signals only on sensitive, activatable icons.
   *
   * Sensitive, but non-activatable icons can be used for purely 
   * informational purposes.
1076 1077 1078 1079 1080
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ACTIVATABLE_SECONDARY,
1081
                                   g_param_spec_boolean ("secondary-icon-activatable",
1082 1083 1084 1085 1086 1087 1088
                                                         P_("Secondary icon activatable"),
                                                         P_("Whether the secondary icon is activatable"),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));
  
  
  /**
1089
   * GtkEntry:primary-icon-sensitive:
1090 1091 1092
   *
   * Whether the primary icon is sensitive.
   *
Matthias Clasen's avatar
Matthias Clasen committed
1093
   * An insensitive icon appears grayed out. GTK+ does not emit the 
1094
   * #GtkEntry::icon-press and #GtkEntry::icon-release signals and 
Matthias Clasen's avatar
Matthias Clasen committed
1095
   * does not allow DND from insensitive icons.
1096
   *
Matthias Clasen's avatar
Matthias Clasen committed
1097 1098 1099
   * An icon should be set insensitive if the action that would trigger
   * when clicked is currently not available.
   * 
1100 1101 1102 1103
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_SENSITIVE_PRIMARY,
1104
                                   g_param_spec_boolean ("primary-icon-sensitive",
1105
                                                         P_("Primary icon sensitive"),
1106 1107 1108 1109 1110
                                                         P_("Whether the primary icon is sensitive"),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
  
  /**
1111
   * GtkEntry:secondary-icon-sensitive:
1112 1113 1114
   *
   * Whether the secondary icon is sensitive.
   *
Matthias Clasen's avatar
Matthias Clasen committed
1115
   * An insensitive icon appears grayed out. GTK+ does not emit the 
1116
   * #GtkEntry::icon-press and #GtkEntry::icon-release signals and 
Matthias Clasen's avatar
Matthias Clasen committed
1117 1118 1119 1120
   * does not allow DND from insensitive icons.
   *
   * An icon should be set insensitive if the action that would trigger
   * when clicked is currently not available.
1121 1122 1123 1124 1125
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_SENSITIVE_SECONDARY,
1126
                                   g_param_spec_boolean ("secondary-icon-sensitive",
1127
                                                         P_("Secondary icon sensitive"),
1128 1129 1130 1131
                                                         P_("Whether the secondary icon is sensitive"),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
  
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 1201 1202 1203
  /**
   * GtkEntry:primary-icon-tooltip-text:
   * 
   * The contents of the tooltip on the primary icon.
   *
   * Also see gtk_entry_set_icon_tooltip_text().
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TOOLTIP_TEXT_PRIMARY,
                                   g_param_spec_string ("primary-icon-tooltip-text",
                                                        P_("Primary icon tooltip text"),
                                                        P_("The contents of the tooltip on the primary icon"),                              
                                                        NULL,
                                                        GTK_PARAM_READWRITE));
  
  /**
   * GtkEntry:secondary-icon-tooltip-text:
   * 
   * The contents of the tooltip on the secondary icon.
   *
   * Also see gtk_entry_set_icon_tooltip_text().
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TOOLTIP_TEXT_SECONDARY,
                                   g_param_spec_string ("secondary-icon-tooltip-text",
                                                        P_("Secondary icon tooltip text"),
                                                        P_("The contents of the tooltip on the secondary icon"),                              
                                                        NULL,
                                                        GTK_PARAM_READWRITE));

  /**
   * GtkEntry:primary-icon-tooltip-markup:
   * 
   * The contents of the tooltip on the primary icon, which is marked up
   * with the <link linkend="PangoMarkupFormat">Pango text markup 
   * language</link>.
   *
   * Also see gtk_entry_set_icon_tooltip_markup().
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TOOLTIP_MARKUP_PRIMARY,
                                   g_param_spec_string ("primary-icon-tooltip-markup",
                                                        P_("Primary icon tooltip markup"),
                                                        P_("The contents of the tooltip on the primary icon"),                              
                                                        NULL,
                                                        GTK_PARAM_READWRITE));

  /**
   * GtkEntry:secondary-icon-tooltip-markup:
   * 
   * The contents of the tooltip on the secondary icon, which is marked up
   * with the <link linkend="PangoMarkupFormat">Pango text markup 
   * language</link>.
   *
   * Also see gtk_entry_set_icon_tooltip_markup().
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TOOLTIP_MARKUP_SECONDARY,
                                   g_param_spec_string ("secondary-icon-tooltip-markup",
                                                        P_("Secondary icon tooltip markup"),
                                                        P_("The contents of the tooltip on the secondary icon"),                              
                                                        NULL,
                                                        GTK_PARAM_READWRITE));

1204 1205 1206
  /**
   * GtkEntry:im-module:
   *
1207 1208
   * Which IM (input method) module should be used for this entry. 
   * See #GtkIMContext.
1209 1210
   * 
   * Setting this to a non-%NULL value overrides the
1211 1212
   * system-wide IM module setting. See the GtkSettings 
   * #GtkSettings:gtk-im-module property.
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
   *
   * Since: 2.16
   */  
  g_object_class_install_property (gobject_class,
                                   PROP_IM_MODULE,
                                   g_param_spec_string ("im-module",
                                                        P_("IM module"),
                                                        P_("Which IM module should be used"),
                                                        NULL,
                                                        GTK_PARAM_READWRITE));

1224
  /**
1225
   * GtkEntry:icon-prelight:
1226 1227 1228 1229 1230 1231 1232
   *
   * The prelight style property determines whether activatable
   * icons prelight on mouseover.
   *
   * Since: 2.16
   */
  gtk_widget_class_install_style_property (widget_class,
1233 1234
                                           g_param_spec_boolean ("icon-prelight",
                                                                 P_("Icon Prelight"),
1235 1236 1237
                                                                 P_("Whether activatable icons should prelight when hovered"),
                                                                 TRUE,
                                                                 GTK_PARAM_READABLE));
1238 1239

  /**
1240
   * GtkEntry:progress-border:
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
   *
   * The border around the progress bar in the entry.
   *
   * Since: 2.16
   */
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_boxed ("progress-border",
                                                               P_("Progress Border"),
                                                               P_("Border around the progress bar"),
                                                               GTK_TYPE_BORDER,
                                                               GTK_PARAM_READABLE));
1252
  
1253
  /**
1254
   * GtkEntry:invisible-char:
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
   *
   * The invisible character is used when masking entry contents (in
   * \"password mode\")"). When it is not explicitly set with the
   * #GtkEntry::invisible-char property, GTK+ determines the character
   * to use from a list of possible candidates, depending on availability
   * in the current font.
   *
   * This style property allows the theme to prepend a character
   * to the list of candidates.
   *
1265
   * Since: 2.18
1266 1267 1268 1269 1270 1271 1272 1273
   */
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_unichar ("invisible-char",
					    		         P_("Invisible character"),
							         P_("The character to use when masking entry contents (in \"password mode\")"),
							         0,
							         GTK_PARAM_READABLE));
  
Matthias Clasen's avatar
Matthias Clasen committed
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
  /**
   * GtkEntry::populate-popup:
   * @entry: The entry on which the signal is emitted
   * @menu: the menu that is being populated
   *
   * The ::populate-popup signal gets emitted before showing the 
   * context menu of the entry. 
   *
   * If you need to add items to the context menu, connect
   * to this signal and append your menuitems to the @menu.
   */
1285
  signals[POPULATE_POPUP] =
1286
    g_signal_new (I_("populate-popup"),
Manish Singh's avatar
Manish Singh committed
1287 1288 1289 1290 1291 1292 1293
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
		  NULL, NULL,
		  _gtk_marshal_VOID__OBJECT,
		  G_TYPE_NONE, 1,
		  GTK_TYPE_MENU);
1294
  
Owen Taylor's avatar
Owen Taylor committed
1295 1296
 /* Action signals */
  
Matthias Clasen's avatar
Matthias Clasen committed
1297 1298 1299 1300 1301 1302 1303 1304
  /**
   * GtkEntry::activate:
   * @entry: The entry on which the signal is emitted
   *
   * A  <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user activates the entry.
   * 
   * Applications should not connect to it, but may emit it with
1305
   * g_signal_emit_by_name() if they need to control activation 
Matthias Clasen's avatar
Matthias Clasen committed
1306 1307 1308 1309
   * programmatically.
   *
   * The default bindings for this signal are all forms of the Enter key.
   */
Owen Taylor's avatar
Owen Taylor committed
1310
  signals[ACTIVATE] =
1311
    g_signal_new (I_("activate"),
Manish Singh's avatar
Manish Singh committed
1312 1313 1314 1315 1316 1317
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, activate),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
Owen Taylor's avatar
Owen Taylor committed
1318 1319
  widget_class->activate_signal = signals[ACTIVATE];

Matthias Clasen's avatar
Matthias Clasen committed
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
  /**
   * GtkEntry::move-cursor:
   * @entry: the object which received the signal
   * @step: the granularity of the move, as a #GtkMovementStep
   * @count: the number of @step units to move
   * @extend_selection: %TRUE if the move should extend the selection
   *
   * The ::move-cursor signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user initiates a cursor movement.
   * If the cursor is not visible in @entry, this signal causes
   * the viewport to be moved instead.
   *
   * Applications should not connect to it, but may emit it with
1334
   * g_signal_emit_by_name() if they need to control the cursor
Matthias Clasen's avatar
Matthias Clasen committed
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
   * programmatically.
   *
   * The default bindings for this signal come in two variants,
   * the variant with the Shift modifier extends the selection,
   * the variant without the Shift modifer does not.
   * There are too many key combinations to list them all here.
   * <itemizedlist>
   * <listitem>Arrow keys move by individual characters/lines</listitem>
   * <listitem>Ctrl-arrow key combinations move by words/paragraphs</listitem>
   * <listitem>Home/End keys move to the ends of the buffer</listitem>
   * </itemizedlist>
   */
Owen Taylor's avatar
Owen Taylor committed
1347
  signals[MOVE_CURSOR] = 
1348
    g_signal_new (I_("move-cursor"),
Manish Singh's avatar
Manish Singh committed
1349 1350 1351 1352 1353 1354 1355 1356 1357
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
		  NULL, NULL,
		  _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
		  G_TYPE_NONE, 3,
		  GTK_TYPE_MOVEMENT_STEP,
		  G_TYPE_INT,
		  G_TYPE_BOOLEAN);
Owen Taylor's avatar
Owen Taylor committed
1358

Matthias Clasen's avatar
Matthias Clasen committed
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
  /**
   * GtkEntry::insert-at-cursor:
   * @entry: the object which received the signal
   * @string: the string to insert
   *
   * The ::insert-at-cursor signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user initiates the insertion of a
   * fixed string at the cursor.
   *
   * This signal has no default bindings.
   */
Owen Taylor's avatar
Owen Taylor committed
1371
  signals[INSERT_AT_CURSOR] = 
1372
    g_signal_new (I_("insert-at-cursor"),
Manish Singh's avatar
Manish Singh committed
1373 1374 1375 1376 1377 1378 1379
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
		  NULL, NULL,
		  _gtk_marshal_VOID__STRING,
		  G_TYPE_NONE, 1,
		  G_TYPE_STRING);
Owen Taylor's avatar
Owen Taylor committed
1380

Matthias Clasen's avatar
Matthias Clasen committed
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
  /**
   * GtkEntry::delete-from-cursor:
   * @entry: the object which received the signal
   * @type: the granularity of the deletion, as a #GtkDeleteType
   * @count: the number of @type units to delete
   *
   * The ::delete-from-cursor signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user initiates a text deletion.
   *
   * If the @type is %GTK_DELETE_CHARS, GTK+ deletes the selection
   * if there is one, otherwise it deletes the requested number
   * of characters.
   *
   * The default bindings for this signal are
   * Delete for deleting a character and Ctrl-Delete for
   * deleting a word.
   */
Owen Taylor's avatar
Owen Taylor committed
1399
  signals[DELETE_FROM_CURSOR] = 
1400
    g_signal_new (I_("delete-from-cursor"),
Manish Singh's avatar
Manish Singh committed
1401 1402 1403 1404 1405 1406 1407 1408
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
		  NULL, NULL,
		  _gtk_marshal_VOID__ENUM_INT,
		  G_TYPE_NONE, 2,
		  GTK_TYPE_DELETE_TYPE,
		  G_TYPE_INT);
Owen Taylor's avatar
Owen Taylor committed
1409

Matthias Clasen's avatar
Matthias Clasen committed
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
  /**
   * GtkEntry::backspace:
   * @entry: the object which received the signal
   *
   * The ::backspace signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user asks for it.
   *
   * The default bindings for this signal are
   * Backspace and Shift-Backspace.
   */
1421
  signals[BACKSPACE] =
1422
    g_signal_new (I_("backspace"),
1423 1424 1425 1426 1427 1428 1429
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, backspace),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

Matthias Clasen's avatar
Matthias Clasen committed
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
  /**
   * GtkEntry::cut-clipboard:
   * @entry: the object which received the signal
   *
   * The ::cut-clipboard signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted to cut the selection to the clipboard.
   *
   * The default bindings for this signal are
   * Ctrl-x and Shift-Delete.
   */
Owen Taylor's avatar
Owen Taylor committed
1441
  signals[CUT_CLIPBOARD] =
1442
    g_signal_new (I_("cut-clipboard"),
Manish Singh's avatar
Manish Singh committed
1443 1444 1445 1446 1447 1448
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
Owen Taylor's avatar
Owen Taylor committed
1449

Matthias Clasen's avatar
Matthias Clasen committed
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
  /**
   * GtkEntry::copy-clipboard:
   * @entry: the object which received the signal
   *
   * The ::copy-clipboard signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted to copy the selection to the clipboard.
   *
   * The default bindings for this signal are
   * Ctrl-c and Ctrl-Insert.
   */
Owen Taylor's avatar
Owen Taylor committed
1461
  signals[COPY_CLIPBOARD] =
1462
    g_signal_new (I_("copy-clipboard"),
Manish Singh's avatar
Manish Singh committed
1463 1464 1465 1466 1467 1468
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
Owen Taylor's avatar
Owen Taylor committed
1469

Matthias Clasen's avatar
Matthias Clasen committed
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
  /**
   * GtkEntry::paste-clipboard:
   * @entry: the object which received the signal
   *
   * The ::paste-clipboard signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted to paste the contents of the clipboard
   * into the text view.
   *
   * The default bindings for this signal are
   * Ctrl-v and Shift-Insert.
   */
Owen Taylor's avatar
Owen Taylor committed
1482
  signals[PASTE_CLIPBOARD] =
1483
    g_signal_new (I_("paste-clipboard"),
Manish Singh's avatar
Manish Singh committed
1484 1485 1486 1487 1488 1489
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
Owen Taylor's avatar
Owen Taylor committed
1490

Matthias Clasen's avatar
Matthias Clasen committed
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
  /**
   * GtkEntry::toggle-overwrite:
   * @entry: the object which received the signal
   *
   * The ::toggle-overwrite signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted to toggle the overwrite mode of the entry.
   *
   * The default bindings for this signal is Insert.
   */
Owen Taylor's avatar
Owen Taylor committed
1501
  signals[TOGGLE_OVERWRITE] =
1502
    g_signal_new (I_("toggle-overwrite"),
Manish Singh's avatar
Manish Singh committed
1503 1504 1505 1506