gtklabel.c 192 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Elliot Lee's avatar
Elliot Lee committed
2 3 4
 * 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
 * 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
Owen Taylor's avatar
Owen Taylor committed
11
 * 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
Owen Taylor's avatar
Owen Taylor committed
15 16
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Elliot Lee's avatar
Elliot Lee committed
17
 */
18 19

/*
20
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
21 22
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
23
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
24 25
 */

26
#include "config.h"
27

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

Elliot Lee's avatar
Elliot Lee committed
31
#include "gtklabel.h"
32
#include "gtkaccellabel.h"
33
#include "gtkdnd.h"
34
#include "gtkmainprivate.h"
35
#include "gtkmarshalers.h"
36
#include "gtkpango.h"
37
#include "gtkwindow.h"
38
#include "gtkclipboard.h"
39
#include "gtkimagemenuitem.h"
40
#include "gtkintl.h"
41
#include "gtkseparatormenuitem.h"
42
#include "gtktextutil.h"
43
#include "gtkmenuitem.h"
44
#include "gtkmenushellprivate.h"
45
#include "gtknotebook.h"
46
#include "gtkstock.h"
47
#include "gtkbindings.h"
48
#include "gtkbuildable.h"
49 50 51
#include "gtkimage.h"
#include "gtkshow.h"
#include "gtktooltip.h"
52
#include "gtkprivate.h"
53
#include "gtktypebuiltins.h"
54

55
#include "a11y/gtklabelaccessible.h"
56

Chun-wei Fan's avatar
Chun-wei Fan committed
57 58 59 60 61
/* this is in case rint() is not provided by the compiler, 
 * such as in the case of C89 compilers, like MSVC
 */
#include "fallback-c89.c"

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
/**
 * SECTION:gtklabel
 * @Short_description: A widget that displays a small to medium amount of text
 * @Title: GtkLabel
 *
 * The #GtkLabel widget displays a small amount of text. As the name
 * implies, most labels are used to label another widget such as a
 * #GtkButton, a #GtkMenuItem, or a #GtkOptionMenu.
 *
 * <refsect2 id="GtkLabel-BUILDER-UI">
 * <title>GtkLabel as GtkBuildable</title>
 * <para>
 * The GtkLabel implementation of the GtkBuildable interface supports a
 * custom &lt;attributes&gt; element, which supports any number of &lt;attribute&gt;
 * elements. the &lt;attribute&gt; element has attributes named name, value,
 * start and end and allows you to specify #PangoAttribute values for this label.
 *
 * <example>
 * <title>A UI definition fragment specifying Pango attributes</title>
 * <programlisting><![CDATA[
 * <object class="GtkLabel">
 *   <attributes>
 *     <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
 *     <attribute name="background" value="red" start="5" end="10"/>"
 *   </attributes>
 * </object>
 * ]]></programlisting>
 * </example>
 * The start and end attributes specify the range of characters to which the
 * Pango attribute applies. If start and end are not specified, the attribute is
 * applied to the whole text. Note that specifying ranges does not make much
 * sense with translatable attributes. Use markup embedded in the translatable
 * content instead.
 * </para>
 * </refsect2>
 * <refsect2>
 * <title>Mnemonics</title>
 * <para>
 * Labels may contain <firstterm>mnemonics</firstterm>. Mnemonics are
 * underlined characters in the label, used for keyboard navigation.
 * Mnemonics are created by providing a string with an underscore before
 * the mnemonic character, such as <literal>"_File"</literal>, to the
 * functions gtk_label_new_with_mnemonic() or
 * gtk_label_set_text_with_mnemonic().
 *
 * Mnemonics automatically activate any activatable widget the label is
 * inside, such as a #GtkButton; if the label is not inside the
 * mnemonic's target widget, you have to tell the label about the target
 * using gtk_label_set_mnemonic_widget(). Here's a simple example where
 * the label is inside a button:
 *
 * <informalexample>
 * <programlisting>
 *   // Pressing Alt+H will activate this button
 *   button = gtk_button_new (<!-- -->);
 *   label = gtk_label_new_with_mnemonic ("_Hello");
 *   gtk_container_add (GTK_CONTAINER (button), label);
 * </programlisting>
 * </informalexample>
 *
 * There's a convenience function to create buttons with a mnemonic label
 * already inside:
 *
 * <informalexample>
 * <programlisting>
 *   // Pressing Alt+H will activate this button
 *   button = gtk_button_new_with_mnemonic ("_Hello");
 * </programlisting>
 * </informalexample>
 *
 * To create a mnemonic for a widget alongside the label, such as a
 * #GtkEntry, you have to point the label at the entry with
 * gtk_label_set_mnemonic_widget():
 *
 * <informalexample>
 * <programlisting>
 *   // Pressing Alt+H will focus the entry
 *   entry = gtk_entry_new (<!-- -->);
 *   label = gtk_label_new_with_mnemonic ("_Hello");
 *   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
 * </programlisting>
 * </informalexample>
 * </para>
 * </refsect2>
 * <refsect2>
 * <title>Markup (styled text)</title>
 * <para>
 * To make it easy to format text in a label (changing colors, fonts,
 * etc.), label text can be provided in a simple <link
 * linkend="PangoMarkupFormat">markup format</link>.
 * Here's how to create a label with a small font:
 *
 * <informalexample>
 * <programlisting>
 *   label = gtk_label_new (NULL);
 *   gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
 * </programlisting>
 * </informalexample>
 *
 * (See <link
 * linkend="PangoMarkupFormat">complete documentation</link> of available
 * tags in the Pango manual.)
 *
 * The markup passed to gtk_label_set_markup() must be valid; for example,
 * literal &lt;, &gt; and &amp; characters must be escaped as \&lt;,
 * \gt;, and \&amp;. If you pass text obtained from the user, file,
 * or a network to gtk_label_set_markup(), you'll want to escape it with
 * g_markup_escape_text() or g_markup_printf_escaped().
 *
 * Markup strings are just a convenient way to set the #PangoAttrList on
 * a label; gtk_label_set_attributes() may be a simpler way to set
 * attributes in some cases. Be careful though; #PangoAttrList tends to
 * cause internationalization problems, unless you're applying attributes
 * to the entire string (i.e. unless you set the range of each attribute
 * to [0, %G_MAXINT)). The reason is that specifying the start_index and
 * end_index for a #PangoAttribute requires knowledge of the exact string
 * being displayed, so translations will cause problems.
 * </para>
 * </refsect2>
 * <refsect2>
 * <title>Selectable labels</title>
 * Labels can be made selectable with gtk_label_set_selectable().
 * Selectable labels allow the user to copy the label contents to
 * the clipboard. Only labels that contain useful-to-copy information
 * &mdash; such as error messages &mdash; should be made selectable.
 * </refsect2>
 * <refsect2 id="label-text-layout">
 * <title>Text layout</title>
 * <para>
 * A label can contain any number of paragraphs, but will have
 * performance problems if it contains more than a small number.
 * Paragraphs are separated by newlines or other paragraph separators
 * understood by Pango.
 *
 * Labels can automatically wrap text if you call
 * gtk_label_set_line_wrap().
 *
 * gtk_label_set_justify() sets how the lines in a label align
 * with one another. If you want to set how the label as a whole
 * aligns in its available space, see gtk_misc_set_alignment().
 *
 * The #GtkLabel:width-chars and #GtkLabel:max-width-chars properties
 * can be used to control the size allocation of ellipsized or wrapped
 * labels. For ellipsizing labels, if either is specified (and less
 * than the actual text size), it is used as the minimum width, and the actual
 * text size is used as the natural width of the label. For wrapping labels,
 * width-chars is used as the minimum width, if specified, and max-width-chars
 * is used as the natural width. Even if max-width-chars specified, wrapping
 * labels will be rewrapped to use all of the available width.
 *
 * <note><para>
 * Note that the interpretation of #GtkLabel:width-chars and
 * #GtkLabel:max-width-chars has changed a bit with the introduction of
 * <link linkend="geometry-management">width-for-height geometry management.</link>
 * </para></note>
 * </para>
 * </refsect2>
 * <refsect2>
 * <title>Links</title>
 * <para>
 * Since 2.18, GTK+ supports markup for clickable hyperlinks in addition
 * to regular Pango markup. The markup for links is borrowed from HTML, using the
 * <tag>a</tag> with href and title attributes. GTK+ renders links similar to the
 * way they appear in web browsers, with colored, underlined text. The title
 * attribute is displayed as a tooltip on the link. An example looks like this:
 *
 * <informalexample><programlisting>
 * gtk_label_set_markup (label, "Go to the <a href="http://www.gtk.org" title="&lt;i&gt;Our&lt;/i&gt; website">GTK+ website</a> for more...");
 * </programlisting></informalexample>
 *
 * It is possible to implement custom handling for links and their tooltips with
 * the #GtkLabel::activate-link signal and the gtk_label_get_current_uri() function.
 * </para>
 * </refsect2>
 */

238
struct _GtkLabelPrivate
239
{
240 241 242 243 244 245 246
  GtkLabelSelectionInfo *select_info;
  GtkWidget *mnemonic_widget;
  GtkWindow *mnemonic_window;

  PangoAttrList *attrs;
  PangoAttrList *effective_attrs;
  PangoLayout   *layout;
247

248 249 250
  gchar   *label;
  gchar   *text;

251 252
  gdouble  angle;

253
  guint    mnemonics_visible  : 1;
254 255 256 257 258 259 260 261 262 263 264
  guint    jtype              : 2;
  guint    wrap               : 1;
  guint    use_underline      : 1;
  guint    use_markup         : 1;
  guint    ellipsize          : 3;
  guint    single_line_mode   : 1;
  guint    have_transform     : 1;
  guint    in_click           : 1;
  guint    wrap_mode          : 3;
  guint    pattern_set        : 1;
  guint    track_links        : 1;
265 266 267 268 269 270

  guint    mnemonic_keyval;

  gint     width_chars;
  gint     max_width_chars;
};
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

/* Notes about the handling of links:
 *
 * Links share the GtkLabelSelectionInfo struct with selectable labels.
 * There are some new fields for links. The links field contains the list
 * of GtkLabelLink structs that describe the links which are embedded in
 * the label. The active_link field points to the link under the mouse
 * pointer. For keyboard navigation, the 'focus' link is determined by
 * finding the link which contains the selection_anchor position.
 * The link_clicked field is used with button press and release events
 * to ensure that pressing inside a link and releasing outside of it
 * does not activate the link.
 *
 * Links are rendered with the link-color/visited-link-color colors
 * that are determined by the style and with an underline. When the mouse
 * pointer is over a link, the pointer is changed to indicate the link,
 * and the background behind the link is rendered with the base[PRELIGHT]
 * color. While a button is pressed over a link, the background is rendered
 * with the base[ACTIVE] color.
 *
 * Labels with links accept keyboard focus, and it is possible to move
 * the focus between the embedded links using Tab/Shift-Tab. The focus
 * is indicated by a focus rectangle that is drawn around the link text.
 * Pressing Enter activates the focussed link, and there is a suitable
 * context menu for links that can be opened with the Menu key. Pressing
 * Control-C copies the link URI to the clipboard.
 *
 * In selectable labels with links, link functionality is only available
 * when the selection is empty.
 */
typedef struct
{
  gchar *uri;
  gchar *title;     /* the title attribute, used as tooltip */
  gboolean visited; /* get set when the link is activated; this flag
                     * gets preserved over later set_markup() calls
                     */
  gint start;       /* position of the link in the PangoLayout */
  gint end;
} GtkLabelLink;
311

312 313 314 315 316
struct _GtkLabelSelectionInfo
{
  GdkWindow *window;
  gint selection_anchor;
  gint selection_end;
317
  GtkWidget *popup_menu;
318 319 320 321

  GList *links;
  GtkLabelLink *active_link;

322 323 324
  gint drag_start_x;
  gint drag_start_y;

325
  guint in_drag      : 1;
326
  guint select_words : 1;
327 328
  guint selectable   : 1;
  guint link_clicked : 1;
329
};
Elliot Lee's avatar
Elliot Lee committed
330

331 332 333 334
enum {
  MOVE_CURSOR,
  COPY_CLIPBOARD,
  POPULATE_POPUP,
335
  ACTIVATE_LINK,
336
  ACTIVATE_CURRENT_LINK,
337 338
  LAST_SIGNAL
};
339

340
enum {
341 342 343 344 345 346 347 348
  PROP_0,
  PROP_LABEL,
  PROP_ATTRIBUTES,
  PROP_USE_MARKUP,
  PROP_USE_UNDERLINE,
  PROP_JUSTIFY,
  PROP_PATTERN,
  PROP_WRAP,
349
  PROP_WRAP_MODE,
350
  PROP_SELECTABLE,
351
  PROP_MNEMONIC_KEYVAL,
352 353
  PROP_MNEMONIC_WIDGET,
  PROP_CURSOR_POSITION,
354
  PROP_SELECTION_BOUND,
355
  PROP_ELLIPSIZE,
356
  PROP_WIDTH_CHARS,
357
  PROP_SINGLE_LINE_MODE,
358
  PROP_ANGLE,
359 360
  PROP_MAX_WIDTH_CHARS,
  PROP_TRACK_VISITED_LINKS
361 362
};

363 364 365
/* When rotating ellipsizable text we want the natural size to request 
 * more to ensure the label wont ever ellipsize in an allocation of full natural size.
 * */
366
#define ROTATION_ELLIPSIZE_PADDING 2
367

368 369
static guint signals[LAST_SIGNAL] = { 0 };

370 371 372
static const GdkColor default_link_color = { 0, 0, 0, 0xeeee };
static const GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };

373 374 375
static void gtk_label_set_property      (GObject          *object,
					 guint             prop_id,
					 const GValue     *value,
376
					 GParamSpec       *pspec);
377 378 379
static void gtk_label_get_property      (GObject          *object,
					 guint             prop_id,
					 GValue           *value,
380
					 GParamSpec       *pspec);
381
static void gtk_label_finalize          (GObject          *object);
382
static void gtk_label_destroy           (GtkWidget        *widget);
383 384
static void gtk_label_size_allocate     (GtkWidget        *widget,
                                         GtkAllocation    *allocation);
Havoc Pennington's avatar
Havoc Pennington committed
385 386
static void gtk_label_state_changed     (GtkWidget        *widget,
                                         GtkStateType      state);
387
static void gtk_label_style_updated     (GtkWidget        *widget);
388 389
static void gtk_label_direction_changed (GtkWidget        *widget,
					 GtkTextDirection  previous_dir);
Benjamin Otte's avatar
Benjamin Otte committed
390 391
static gint gtk_label_draw              (GtkWidget        *widget,
                                         cairo_t          *cr);
392 393
static gboolean gtk_label_focus         (GtkWidget         *widget,
                                         GtkDirectionType   direction);
Elliot Lee's avatar
Elliot Lee committed
394

395 396 397 398
static void gtk_label_realize           (GtkWidget        *widget);
static void gtk_label_unrealize         (GtkWidget        *widget);
static void gtk_label_map               (GtkWidget        *widget);
static void gtk_label_unmap             (GtkWidget        *widget);
Federico Mena Quintero's avatar
Federico Mena Quintero committed
399 400 401 402 403 404 405

static gboolean gtk_label_button_press      (GtkWidget        *widget,
					     GdkEventButton   *event);
static gboolean gtk_label_button_release    (GtkWidget        *widget,
					     GdkEventButton   *event);
static gboolean gtk_label_motion            (GtkWidget        *widget,
					     GdkEventMotion   *event);
406 407 408
static gboolean gtk_label_leave_notify      (GtkWidget        *widget,
                                             GdkEventCrossing *event);

409
static void     gtk_label_grab_focus        (GtkWidget        *widget);
410

411 412 413 414 415
static gboolean gtk_label_query_tooltip     (GtkWidget        *widget,
                                             gint              x,
                                             gint              y,
                                             gboolean          keyboard_tip,
                                             GtkTooltip       *tooltip);
416 417 418 419 420 421 422 423 424 425 426 427 428 429

static void gtk_label_set_text_internal          (GtkLabel      *label,
						  gchar         *str);
static void gtk_label_set_label_internal         (GtkLabel      *label,
						  gchar         *str);
static void gtk_label_set_use_markup_internal    (GtkLabel      *label,
						  gboolean       val);
static void gtk_label_set_use_underline_internal (GtkLabel      *label,
						  gboolean       val);
static void gtk_label_set_attributes_internal    (GtkLabel      *label,
						  PangoAttrList *attrs);
static void gtk_label_set_uline_text_internal    (GtkLabel      *label,
						  const gchar   *str);
static void gtk_label_set_pattern_internal       (GtkLabel      *label,
430 431
				                  const gchar   *pattern,
                                                  gboolean       is_mnemonic);
432
static void gtk_label_set_markup_internal        (GtkLabel      *label,
433 434 435
						  const gchar   *str,
						  gboolean       with_uline);
static void gtk_label_recalculate                (GtkLabel      *label);
436 437
static void gtk_label_hierarchy_changed          (GtkWidget     *widget,
						  GtkWidget     *old_toplevel);
438 439
static void gtk_label_screen_changed             (GtkWidget     *widget,
						  GdkScreen     *old_screen);
440
static gboolean gtk_label_popup_menu             (GtkWidget     *widget);
441

442 443
static void gtk_label_create_window       (GtkLabel *label);
static void gtk_label_destroy_window      (GtkLabel *label);
444 445 446
static void gtk_label_ensure_select_info  (GtkLabel *label);
static void gtk_label_clear_select_info   (GtkLabel *label);
static void gtk_label_update_cursor       (GtkLabel *label);
447
static void gtk_label_clear_layout        (GtkLabel *label);
448
static void gtk_label_ensure_layout       (GtkLabel *label);
449 450 451 452
static void gtk_label_select_region_index (GtkLabel *label,
                                           gint      anchor_index,
                                           gint      end_index);

453

454 455 456 457
static gboolean gtk_label_mnemonic_activate (GtkWidget         *widget,
					     gboolean           group_cycling);
static void     gtk_label_setup_mnemonic    (GtkLabel          *label,
					     guint              last_key);
458 459 460 461 462 463
static void     gtk_label_drag_data_get     (GtkWidget         *widget,
					     GdkDragContext    *context,
					     GtkSelectionData  *selection_data,
					     guint              info,
					     guint              time);

464 465 466 467 468 469 470 471 472 473 474 475 476 477
static void     gtk_label_buildable_interface_init     (GtkBuildableIface *iface);
static gboolean gtk_label_buildable_custom_tag_start   (GtkBuildable     *buildable,
							GtkBuilder       *builder,
							GObject          *child,
							const gchar      *tagname,
							GMarkupParser    *parser,
							gpointer         *data);

static void     gtk_label_buildable_custom_finished    (GtkBuildable     *buildable,
							GtkBuilder       *builder,
							GObject          *child,
							const gchar      *tagname,
							gpointer          user_data);

478

479
static void connect_mnemonics_visible_notify    (GtkLabel   *label);
480 481 482 483
static gboolean      separate_uline_pattern     (const gchar  *str,
                                                 guint        *accel_key,
                                                 gchar       **new_str,
                                                 gchar       **pattern);
484 485


486
/* For selectable labels: */
487 488 489 490 491 492 493 494 495 496 497 498
static void gtk_label_move_cursor        (GtkLabel        *label,
					  GtkMovementStep  step,
					  gint             count,
					  gboolean         extend_selection);
static void gtk_label_copy_clipboard     (GtkLabel        *label);
static void gtk_label_select_all         (GtkLabel        *label);
static void gtk_label_do_popup           (GtkLabel        *label,
					  GdkEventButton  *event);
static gint gtk_label_move_forward_word  (GtkLabel        *label,
					  gint             start);
static gint gtk_label_move_backward_word (GtkLabel        *label,
					  gint             start);
499

500 501 502
/* For links: */
static void          gtk_label_rescan_links     (GtkLabel  *label);
static void          gtk_label_clear_links      (GtkLabel  *label);
503 504 505
static gboolean      gtk_label_activate_link    (GtkLabel    *label,
                                                 const gchar *uri);
static void          gtk_label_activate_current_link (GtkLabel *label);
506 507 508 509
static GtkLabelLink *gtk_label_get_current_link (GtkLabel  *label);
static void          gtk_label_get_link_colors  (GtkWidget  *widget,
                                                 GdkColor  **link_color,
                                                 GdkColor  **visited_link_color);
510 511
static void          emit_activate_link         (GtkLabel     *label,
                                                 GtkLabelLink *link);
512

513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
static GtkSizeRequestMode gtk_label_get_request_mode                (GtkWidget           *widget);
static void               gtk_label_get_preferred_width             (GtkWidget           *widget,
                                                                     gint                *minimum_size,
                                                                     gint                *natural_size);
static void               gtk_label_get_preferred_height            (GtkWidget           *widget,
                                                                     gint                *minimum_size,
                                                                     gint                *natural_size);
static void               gtk_label_get_preferred_width_for_height  (GtkWidget           *widget,
                                                                     gint                 height,
                                                                     gint                *minimum_width,
                                                                     gint                *natural_width);
static void               gtk_label_get_preferred_height_for_width  (GtkWidget           *widget,
                                                                     gint                 width,
                                                                     gint                *minimum_height,
                                                                     gint                *natural_height);
528

529 530 531 532
static GtkBuildableIface *buildable_parent_iface = NULL;

G_DEFINE_TYPE_WITH_CODE (GtkLabel, gtk_label, GTK_TYPE_MISC,
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
533
						gtk_label_buildable_interface_init))
Elliot Lee's avatar
Elliot Lee committed
534

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,
547
				G_TYPE_INT, count,
Manish Singh's avatar
Manish Singh committed
548
				G_TYPE_BOOLEAN, FALSE);
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,
554
				G_TYPE_INT, count,
Manish Singh's avatar
Manish Singh committed
555
				G_TYPE_BOOLEAN, TRUE);
556 557
}

558
static void
Elliot Lee's avatar
Elliot Lee committed
559 560
gtk_label_class_init (GtkLabelClass *class)
{
561
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
562
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
563
  GtkBindingSet *binding_set;
564

565 566
  gobject_class->set_property = gtk_label_set_property;
  gobject_class->get_property = gtk_label_get_property;
567
  gobject_class->finalize = gtk_label_finalize;
568

569
  widget_class->destroy = gtk_label_destroy;
570
  widget_class->size_allocate = gtk_label_size_allocate;
Havoc Pennington's avatar
Havoc Pennington committed
571
  widget_class->state_changed = gtk_label_state_changed;
572
  widget_class->style_updated = gtk_label_style_updated;
573
  widget_class->query_tooltip = gtk_label_query_tooltip;
574
  widget_class->direction_changed = gtk_label_direction_changed;
Benjamin Otte's avatar
Benjamin Otte committed
575
  widget_class->draw = gtk_label_draw;
576 577 578 579 580 581 582
  widget_class->realize = gtk_label_realize;
  widget_class->unrealize = gtk_label_unrealize;
  widget_class->map = gtk_label_map;
  widget_class->unmap = gtk_label_unmap;
  widget_class->button_press_event = gtk_label_button_press;
  widget_class->button_release_event = gtk_label_button_release;
  widget_class->motion_notify_event = gtk_label_motion;
583
  widget_class->leave_notify_event = gtk_label_leave_notify;
584
  widget_class->hierarchy_changed = gtk_label_hierarchy_changed;
585
  widget_class->screen_changed = gtk_label_screen_changed;
586
  widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
587
  widget_class->drag_data_get = gtk_label_drag_data_get;
588
  widget_class->grab_focus = gtk_label_grab_focus;
589 590
  widget_class->popup_menu = gtk_label_popup_menu;
  widget_class->focus = gtk_label_focus;
591 592 593 594 595
  widget_class->get_request_mode = gtk_label_get_request_mode;
  widget_class->get_preferred_width = gtk_label_get_preferred_width;
  widget_class->get_preferred_height = gtk_label_get_preferred_height;
  widget_class->get_preferred_width_for_height = gtk_label_get_preferred_width_for_height;
  widget_class->get_preferred_height_for_width = gtk_label_get_preferred_height_for_width;
596 597 598

  class->move_cursor = gtk_label_move_cursor;
  class->copy_clipboard = gtk_label_copy_clipboard;
599 600
  class->activate_link = gtk_label_activate_link;

Matthias Clasen's avatar
Matthias Clasen committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614
  /**
   * GtkLabel::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
615
   * g_signal_emit_by_name() if they need to control the cursor
Matthias Clasen's avatar
Matthias Clasen committed
616 617 618 619 620 621 622 623 624 625 626 627
   * 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>
   */
628
  signals[MOVE_CURSOR] = 
629
    g_signal_new (I_("move-cursor"),
Manish Singh's avatar
Manish Singh committed
630 631 632 633 634 635 636 637 638
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkLabelClass, move_cursor),
		  NULL, NULL,
		  _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
		  G_TYPE_NONE, 3,
		  GTK_TYPE_MOVEMENT_STEP,
		  G_TYPE_INT,
		  G_TYPE_BOOLEAN);
Matthias Clasen's avatar
Matthias Clasen committed
639 640 641 642 643 644 645 646 647 648 649

   /**
   * GtkLabel::copy-clipboard:
   * @label: 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 binding for this signal is Ctrl-c.
   */ 
650
  signals[COPY_CLIPBOARD] =
651
    g_signal_new (I_("copy-clipboard"),
Manish Singh's avatar
Manish Singh committed
652 653 654 655 656 657
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkLabelClass, copy_clipboard),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
658
  
Matthias Clasen's avatar
Matthias Clasen committed
659 660 661 662 663 664 665 666 667 668 669 670
  /**
   * GtkLabel::populate-popup:
   * @label: The label 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 label. Note that only selectable labels
   * have context menus.
   *
   * If you need to add items to the context menu, connect
   * to this signal and append your menuitems to the @menu.
   */
671
  signals[POPULATE_POPUP] =
672
    g_signal_new (I_("populate-popup"),
Manish Singh's avatar
Manish Singh committed
673 674 675 676 677 678 679 680
		  G_OBJECT_CLASS_TYPE (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkLabelClass, populate_popup),
		  NULL, NULL,
		  _gtk_marshal_VOID__OBJECT,
		  G_TYPE_NONE, 1,
		  GTK_TYPE_MENU);

681
    /**
682 683
     * GtkLabel::activate-current-link:
     * @label: The label on which the signal was emitted
684
     *
685
     * A <link linkend="keybinding-signals">keybinding signal</link>
686 687 688 689 690 691 692
     * which gets emitted when the user activates a link in the label.
     *
     * Applications may also emit the signal with g_signal_emit_by_name()
     * if they need to control activation of URIs programmatically.
     *
     * The default bindings for this signal are all forms of the Enter key.
     *
693 694 695 696
     * Since: 2.18
     */
    signals[ACTIVATE_CURRENT_LINK] =
      g_signal_new_class_handler ("activate-current-link",
697
                                  G_TYPE_FROM_CLASS (gobject_class),
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
                                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                                  G_CALLBACK (gtk_label_activate_current_link),
                                  NULL, NULL,
                                  _gtk_marshal_VOID__VOID,
                                  G_TYPE_NONE, 0);

    /**
     * GtkLabel::activate-link:
     * @label: The label on which the signal was emitted
     * @uri: the URI that is activated
     *
     * The signal which gets emitted to activate a URI.
     * Applications may connect to it to override the default behaviour,
     * which is to call gtk_show_uri().
     *
713 714 715 716 717 718
     * Returns: %TRUE if the link has been activated
     *
     * Since: 2.18
     */
    signals[ACTIVATE_LINK] =
      g_signal_new ("activate-link",
719
                    G_TYPE_FROM_CLASS (gobject_class),
720
                    G_SIGNAL_RUN_LAST,
721 722
                    G_STRUCT_OFFSET (GtkLabelClass, activate_link),
                    _gtk_boolean_handled_accumulator, NULL,
723 724
                    _gtk_marshal_BOOLEAN__STRING,
                    G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
725

Manish Singh's avatar
Manish Singh committed
726
  g_object_class_install_property (gobject_class,
727 728
                                   PROP_LABEL,
                                   g_param_spec_string ("label",
729 730
                                                        P_("Label"),
                                                        P_("The text of the label"),
731
                                                        "",
732
                                                        GTK_PARAM_READWRITE));
733 734 735
  g_object_class_install_property (gobject_class,
				   PROP_ATTRIBUTES,
				   g_param_spec_boxed ("attributes",
736 737
						       P_("Attributes"),
						       P_("A list of style attributes to apply to the text of the label"),
738
						       PANGO_TYPE_ATTR_LIST,
739
						       GTK_PARAM_READWRITE));
740 741
  g_object_class_install_property (gobject_class,
                                   PROP_USE_MARKUP,
Matthias Clasen's avatar
x  
Matthias Clasen committed
742
                                   g_param_spec_boolean ("use-markup",
743 744
							 P_("Use markup"),
							 P_("The text of the label includes XML markup. See pango_parse_markup()"),
745
                                                        FALSE,
746
                                                        GTK_PARAM_READWRITE));
747 748
  g_object_class_install_property (gobject_class,
                                   PROP_USE_UNDERLINE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
749
                                   g_param_spec_boolean ("use-underline",
750 751
							 P_("Use underline"),
							 P_("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
752
                                                        FALSE,
753
                                                        GTK_PARAM_READWRITE));
754 755 756 757

  g_object_class_install_property (gobject_class,
				   PROP_JUSTIFY,
                                   g_param_spec_enum ("justify",
758 759
                                                      P_("Justification"),
                                                      P_("The alignment of the lines in the text of the label relative to each other. This does NOT affect the alignment of the label within its allocation. See GtkMisc::xalign for that"),
760 761
						      GTK_TYPE_JUSTIFICATION,
						      GTK_JUSTIFY_LEFT,
762
                                                      GTK_PARAM_READWRITE));
763 764 765 766

  g_object_class_install_property (gobject_class,
                                   PROP_PATTERN,
                                   g_param_spec_string ("pattern",
767 768
                                                        P_("Pattern"),
                                                        P_("A string with _ characters in positions correspond to characters in the text to underline"),
769
                                                        NULL,
770
                                                        GTK_PARAM_WRITABLE));
771 772 773 774

  g_object_class_install_property (gobject_class,
                                   PROP_WRAP,
                                   g_param_spec_boolean ("wrap",
775 776
                                                        P_("Line wrap"),
                                                        P_("If set, wrap lines if the text becomes too wide"),
777
                                                        FALSE,
778
                                                        GTK_PARAM_READWRITE));
779 780 781
  /**
   * GtkLabel:wrap-mode:
   *
782 783 784
   * If line wrapping is on (see the #GtkLabel:wrap property) this controls 
   * how the line wrapping is done. The default is %PANGO_WRAP_WORD, which 
   * means wrap on word boundaries.
785 786 787 788 789 790 791 792 793 794 795
   *
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
                                   PROP_WRAP_MODE,
                                   g_param_spec_enum ("wrap-mode",
						      P_("Line wrap mode"),
						      P_("If wrap is set, controls how linewrapping is done"),
						      PANGO_TYPE_WRAP_MODE,
						      PANGO_WRAP_WORD,
						      GTK_PARAM_READWRITE));
796 797 798
  g_object_class_install_property (gobject_class,
                                   PROP_SELECTABLE,
                                   g_param_spec_boolean ("selectable",
799 800
                                                        P_("Selectable"),
                                                        P_("Whether the label text can be selected with the mouse"),
801
                                                        FALSE,
802
                                                        GTK_PARAM_READWRITE));
803
  g_object_class_install_property (gobject_class,
804
                                   PROP_MNEMONIC_KEYVAL,
Matthias Clasen's avatar
x  
Matthias Clasen committed
805
                                   g_param_spec_uint ("mnemonic-keyval",
806 807
						      P_("Mnemonic key"),
						      P_("The mnemonic accelerator key for this label"),
808 809
						      0,
						      G_MAXUINT,
810
						      GDK_KEY_VoidSymbol,
811
						      GTK_PARAM_READABLE));
812 813
  g_object_class_install_property (gobject_class,
                                   PROP_MNEMONIC_WIDGET,
Matthias Clasen's avatar
x  
Matthias Clasen committed
814
                                   g_param_spec_object ("mnemonic-widget",
815 816
							P_("Mnemonic widget"),
							P_("The widget to be activated when the label's mnemonic "
Soren Sandmann's avatar
Soren Sandmann committed
817
							  "key is pressed"),
818
							GTK_TYPE_WIDGET,
819
							GTK_PARAM_READWRITE));
820

821 822
  g_object_class_install_property (gobject_class,
                                   PROP_CURSOR_POSITION,
Matthias Clasen's avatar
x  
Matthias Clasen committed
823
                                   g_param_spec_int ("cursor-position",
824 825
                                                     P_("Cursor Position"),
                                                     P_("The current position of the insertion cursor in chars"),
826 827 828
                                                     0,
                                                     G_MAXINT,
                                                     0,
829
                                                     GTK_PARAM_READABLE));
830 831 832
  
  g_object_class_install_property (gobject_class,
                                   PROP_SELECTION_BOUND,
Matthias Clasen's avatar
x  
Matthias Clasen committed
833
                                   g_param_spec_int ("selection-bound",
834 835
                                                     P_("Selection Bound"),
                                                     P_("The position of the opposite end of the selection from the cursor in chars"),
836 837 838
                                                     0,
                                                     G_MAXINT,
                                                     0,
839
                                                     GTK_PARAM_READABLE));
840
  
841 842 843
  /**
   * GtkLabel:ellipsize:
   *
844 845 846
   * The preferred place to ellipsize the string, if the label does 
   * not have enough room to display the entire string, specified as a 
   * #PangoEllisizeMode. 
847
   *
848 849 850 851 852 853 854
   * Note that setting this property to a value other than 
   * %PANGO_ELLIPSIZE_NONE has the side-effect that the label requests 
   * only enough space to display the ellipsis "...". In particular, this 
   * means that ellipsizing labels do not work well in notebook tabs, unless 
   * the tab's #GtkNotebook:tab-expand property is set to %TRUE. Other ways
   * to set a label's width are gtk_widget_set_size_request() and
   * gtk_label_set_width_chars().
855 856 857
   *
   * Since: 2.6
   */
858 859 860 861
  g_object_class_install_property (gobject_class,
				   PROP_ELLIPSIZE,
                                   g_param_spec_enum ("ellipsize",
                                                      P_("Ellipsize"),
862
                                                      P_("The preferred place to ellipsize the string, if the label does not have enough room to display the entire string"),
863 864
						      PANGO_TYPE_ELLIPSIZE_MODE,
						      PANGO_ELLIPSIZE_NONE,
865
                                                      GTK_PARAM_READWRITE));
866 867 868

  /**
   * GtkLabel:width-chars:
869
   *
870
   * The desired width of the label, in characters. If this property is set to
871 872 873 874 875
   * -1, the width will be calculated automatically.
   *
   * See the section on <link linkend="label-text-layout">text layout</link>
   * for details of how #GtkLabel:width-chars and #GtkLabel:max-width-chars
   * determine the width of ellipsized and wrapped labels.
876
   *
877 878 879 880
   * Since: 2.6
   **/
  g_object_class_install_property (gobject_class,
                                   PROP_WIDTH_CHARS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
881
                                   g_param_spec_int ("width-chars",
Matthias Clasen's avatar
Matthias Clasen committed
882
                                                     P_("Width In Characters"),
883 884 885 886
                                                     P_("The desired width of the label, in characters"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
887
                                                     GTK_PARAM_READWRITE));
888
  
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
  /**
   * GtkLabel:single-line-mode:
   * 
   * Whether the label is in single line mode. In single line mode,
   * the height of the label does not depend on the actual text, it
   * is always set to ascent + descent of the font. This can be an
   * advantage in situations where resizing the label because of text 
   * changes would be distracting, e.g. in a statusbar.
   *
   * Since: 2.6
   **/
  g_object_class_install_property (gobject_class,
                                   PROP_SINGLE_LINE_MODE,
                                   g_param_spec_boolean ("single-line-mode",
                                                        P_("Single Line Mode"),
                                                        P_("Whether the label is in single line mode"),
                                                        FALSE,
906
                                                        GTK_PARAM_READWRITE));
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925

  /**
   * GtkLabel:angle:
   * 
   * The angle that the baseline of the label makes with the horizontal,
   * in degrees, measured counterclockwise. An angle of 90 reads from
   * from bottom to top, an angle of 270, from top to bottom. Ignored
   * if the label is selectable, wrapped, or ellipsized.
   *
   * Since: 2.6
   **/
  g_object_class_install_property (gobject_class,
                                   PROP_ANGLE,
                                   g_param_spec_double ("angle",
							P_("Angle"),
							P_("Angle at which the label is rotated"),
							0.0,
							360.0,
							0.0, 
926
							GTK_PARAM_READWRITE));
927
  
928 929 930
  /**
   * GtkLabel:max-width-chars:
   * 
931
   * The desired maximum width of the label, in characters. If this property 
932 933 934 935 936 937
   * is set to -1, the width will be calculated automatically.
   *
   * See the section on <link linkend="label-text-layout">text layout</link>
   * for details of how #GtkLabel:width-chars and #GtkLabel:max-width-chars
   * determine the width of ellipsized and wrapped labels.
   *
938 939 940 941
   * Since: 2.6
   **/
  g_object_class_install_property (gobject_class,
                                   PROP_MAX_WIDTH_CHARS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
942
                                   g_param_spec_int ("max-width-chars",
943 944
                                                     P_("Maximum Width In Characters"),
                                                     P_("The desired maximum width of the label, in characters"),
945 946 947
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
948
                                                     GTK_PARAM_READWRITE));
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965

  /**
   * GtkLabel:track-visited-links:
   *
   * Set this property to %TRUE to make the label track which links
   * have been clicked. It will then apply the ::visited-link-color
   * color, instead of ::link-color.
   *
   * Since: 2.18
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TRACK_VISITED_LINKS,
                                   g_param_spec_boolean ("track-visited-links",
                                                         P_("Track visited links"),
                                                         P_("Whether visited links should be tracked"),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
966 967 968 969 970 971 972
  /*
   * Key bindings
   */

  binding_set = gtk_binding_set_by_class (class);

  /* Moving the insertion point */
973
  add_move_binding (binding_set, GDK_KEY_Right, 0,
974 975
		    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
  
976
  add_move_binding (binding_set, GDK_KEY_Left, 0,
977 978
		    GTK_MOVEMENT_VISUAL_POSITIONS, -1);

979
  add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
980 981
		    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
  
982
  add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
983 984
		    GTK_MOVEMENT_VISUAL_POSITIONS, -1);
  
985
  add_move_binding (binding_set, GDK_KEY_f, GDK_CONTROL_MASK,
986 987
		    GTK_MOVEMENT_LOGICAL_POSITIONS, 1);
  
988
  add_move_binding (binding_set, GDK_KEY_b, GDK_CONTROL_MASK,
989 990
		    GTK_MOVEMENT_LOGICAL_POSITIONS, -1);
  
991
  add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
992 993
		    GTK_MOVEMENT_WORDS, 1);

994
  add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
995 996
		    GTK_MOVEMENT_WORDS, -1);

997
  add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
998 999
		    GTK_MOVEMENT_WORDS, 1);

1000
  add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1001 1002
		    GTK_MOVEMENT_WORDS, -1);

1003
  /* select all */
1004
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1005
				"move-cursor", 3,
1006 1007 1008 1009
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, -1,
				G_TYPE_BOOLEAN, FALSE);

1010
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1011
				"move-cursor", 3,
1012 1013 1014 1015
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 1,
				G_TYPE_BOOLEAN, TRUE);

1016
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1017
				"move-cursor", 3,
1018 1019 1020 1021
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, -1,
				G_TYPE_BOOLEAN, FALSE);

1022
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1023
				"move-cursor", 3,
1024 1025 1026 1027 1028
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 1,
				G_TYPE_BOOLEAN, TRUE);

  /* unselect all */
1029
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1030
				"move-cursor", 3,
1031 1032 1033 1034
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 0,
				G_TYPE_BOOLEAN, FALSE);

1035
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1036
				"move-cursor", 3,
1037 1038 1039
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 0,
				G_TYPE_BOOLEAN, FALSE);
1040

1041
  add_move_binding (binding_set, GDK_KEY_f, GDK_MOD1_MASK,
1042 1043
		    GTK_MOVEMENT_WORDS, 1);

1044
  add_move_binding (binding_set, GDK_KEY_b, GDK_MOD1_MASK,
1045 1046
		    GTK_MOVEMENT_WORDS, -1);

1047
  add_move_binding (binding_set, GDK_KEY_Home, 0,
1048 1049
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);

1050
  add_move_binding (binding_set, GDK_KEY_End, 0,
1051 1052
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);

1053
  add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1054 1055
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);

1056
  add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1057 1058
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
  
1059
  add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1060 1061
		    GTK_MOVEMENT_BUFFER_ENDS, -1);

1062
  add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1063 1064
		    GTK_MOVEMENT_BUFFER_ENDS, 1);

1065
  add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1066 1067
		    GTK_MOVEMENT_BUFFER_ENDS, -1);

1068
  add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1069 1070 1071
		    GTK_MOVEMENT_BUFFER_ENDS, 1);

  /* copy */
1072
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1073
				"copy-clipboard", 0);
1074

1075
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1076
				"activate-current-link", 0);
1077
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1078
				"activate-current-link", 0);
1079
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1080
				"activate-current-link", 0);
1081

1082
  g_type_class_add_private (class, sizeof (GtkLabelPrivate));
1083 1084

  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LABEL_ACCESSIBLE);
Elliot Lee's avatar
Elliot Lee committed
1085 1086
}

1087 1088 1089 1090
static void 
gtk_label_set_property (GObject      *object,
			guint         prop_id,
			const GValue *value,
1091
			GParamSpec   *pspec)
1092
{
1093
  GtkLabel *label = GTK_LABEL (object);
1094

1095
  switch (prop_id)
1096
    {
1097
    case PROP_LABEL:
1098
      gtk_label_set_label (label, g_value_get_string (value));
1099 1100 1101 1102 1103
      break;
    case PROP_ATTRIBUTES:
      gtk_label_set_attributes (label, g_value_get_boxed (value));
      break;
    case PROP_USE_MARKUP:
1104
      gtk_label_set_use_markup (label, g_value_get_boolean (value));
1105
      break;
1106
    case PROP_USE_UNDERLINE:
1107
      gtk_label_set_use_underline (label, g_value_get_boolean (value));
1108
      break;
1109 1110
    case PROP_JUSTIFY:
      gtk_label_set_justify (label, g_value_get_enum (value));
1111
      break;
1112 1113 1114 1115 1116 1117
    case PROP_PATTERN:
      gtk_label_set_pattern (label, g_value_get_string (value));
      break;
    case PROP_WRAP:
      gtk_label_set_line_wrap (label, g_value_get_boolean (value));
      break;	  
1118 1119 1120
    case PROP_WRAP_MODE:
      gtk_label_set_line_wrap_mode (label, g_value_get_enum (value));
      break;	  
1121 1122
    case PROP_SELECTABLE:
      gtk_label_set_selectable (label, g_value_get_boolean (value));
1123
      break;	  
1124 1125 1126
    case PROP_MNEMONIC_WIDGET:
      gtk_label_set_mnemonic_widget (label, (GtkWidget*) g_value_get_object (value));
      break;
1127 1128 1129
    case PROP_ELLIPSIZE:
      gtk_label_set_ellipsize (label, g_value_get_enum (value));
      break;
1130 1131 1132
    case PROP_WIDTH_CHARS:
      gtk_label_set_width_chars (label, g_value_get_int (value));
      break;
1133 1134 1135
    case PROP_SINGLE_LINE_MODE:
      gtk_label_set_single_line_mode (label, g_value_get_boolean (value));
      break;	  
1136 1137
    case PROP_ANGLE:
      gtk_label_set_angle (label, g_value_get_double (value));
1138 1139 1140 1141
      break;
    case PROP_MAX_WIDTH_CHARS:
      gtk_label_set_max_width_chars (label, g_value_get_int (value));
      break;
1142 1143 1144
    case PROP_TRACK_VISITED_LINKS:
      gtk_label_set_track_visited_links (label, g_value_get_boolean (value));
      break;
Tim Janik's avatar
Tim Janik committed
1145
    default:
1146
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Tim Janik's avatar
Tim Janik committed
1147
      break;
1148 1149 1150
    }
}

1151 1152 1153 1154
static void 
gtk_label_get_property (GObject     *object,
			guint        prop_id,
			GValue      *value,
1155
			GParamSpec  *pspec)
1156
{
1157
  GtkLabel *label = GTK_LABEL (object);
1158
  GtkLabelPrivate *priv = label->priv;
1159

1160
  switch (prop_id)
1161
    {
1162
    case PROP_LABEL:
1163
      g_value_set_string (value, priv->label);
1164 1165
      break;
    case PROP_ATTRIBUTES:
1166
      g_value_set_boxed (value, priv->attrs);
1167 1168
      break;
    case PROP_USE_MARKUP:
1169
      g_value_set_boolean (value, priv->use_markup);
1170 1171
      break;
    case PROP_USE_UNDERLINE:
1172
      g_value_set_boolean (value, priv->use_underline);
1173
      break;
1174
    case PROP_JUSTIFY:
1175
      g_value_set_enum (value, priv->jtype);
1176
      break;
1177
    case PROP_WRAP:
1178
      g_value_set_boolean (value, priv->wrap);
1179
      break;
1180
    case PROP_WRAP_MODE:
1181
      g_value_set_enum (value, priv->wrap_mode);
1182
      break;
1183 1184 1185
    case PROP_SELECTABLE:
      g_value_set_boolean (value, gtk_label_get_selectable (label));
      break;
1186
    case PROP_MNEMONIC_KEYVAL:
1187
      g_value_set_uint (value, priv->mnemonic_keyval);
1188
      break;
1189
    case PROP_MNEMONIC_WIDGET:
1190
      g_value_set_object (value, (GObject*) priv->mnemonic_widget);
1191
      break;
1192
    case PROP_CURSOR_POSITION:
1193
      g_value_set_int (value, _gtk_label_get_cursor_position (label));
1194 1195
      break;
    case PROP_SELECTION_BOUND:
1196
      g_value_set_int (value, _gtk_label_get_selection_bound (label));
1197
      break;
1198
    case PROP_ELLIPSIZE:
1199
      g_value_set_enum (value, priv->ellipsize);
1200
      break;
1201
    case PROP_WIDTH_CHARS:
1202
      g_value_set_int (value, gtk_label_get_width_chars (label));
1203
      break;
1204 1205 1206
    case PROP_SINGLE_LINE_MODE:
      g_value_set_boolean (value, gtk_label_get_single_line_mode (label));
      break;
1207