gtklabel.c 209 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
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.Free
Elliot Lee's avatar
Elliot Lee committed
16
 */
17 18

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

25
#include "config.h"
26

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

Elliot Lee's avatar
Elliot Lee committed
30
#include "gtklabel.h"
31
#include "gtklabelprivate.h"
32
#include "gtkaccellabel.h"
33 34
#include "gtkbindings.h"
#include "gtkbuildable.h"
35
#include "gtkbuilderprivate.h"
36
#include "gtkclipboard.h"
37
#include "gtkcssshadowsvalueprivate.h"
38
#include "gtkcssstylepropertyprivate.h"
39
#include "gtkdnd.h"
40
#include "gtkimage.h"
41
#include "gtkintl.h"
42
#include "gtkmain.h"
43
#include "gtkmarshalers.h"
44
#include "gtkmenuitem.h"
45
#include "gtkmenushellprivate.h"
46
#include "gtknotebook.h"
47 48 49
#include "gtkpango.h"
#include "gtkprivate.h"
#include "gtkseparatormenuitem.h"
50
#include "gtkshow.h"
51
#include "gtkstylecontextprivate.h"
52
#include "gtktextutil.h"
53
#include "gtktooltip.h"
54
#include "gtktypebuiltins.h"
55 56
#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
57 58
#include "gtkcssnodeprivate.h"
#include "gtkwidgetprivate.h"
59

60
#include "a11y/gtklabelaccessibleprivate.h"
61

Chun-wei Fan's avatar
Chun-wei Fan committed
62 63 64 65 66
/* 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"

67 68 69 70 71 72 73
/**
 * 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
74
 * #GtkButton, a #GtkMenuItem, or a #GtkComboBox.
75
 *
76 77
 * # CSS nodes
 *
78 79 80
 * GtkLabel has a single CSS node with the name label. A wide variety
 * of style classes may be applied to labels, such as .title, .subtitle,
 * .dim-label, etc.
81
 *
82
 * # GtkLabel as GtkBuildable
Matthias Clasen's avatar
Matthias Clasen committed
83
 *
84
 * The GtkLabel implementation of the GtkBuildable interface supports a
85 86 87 88
 * custom <attributes> element, which supports any number of <attribute>
 * elements. The <attribute> element has attributes named “name“, “value“,
 * “start“ and “end“ and allows you to specify #PangoAttribute values for
 * this label.
89
 *
Matthias Clasen's avatar
Matthias Clasen committed
90
 * An example of a UI definition fragment specifying Pango attributes:
91
 * |[
92 93 94 95 96 97
 * <object class="GtkLabel">
 *   <attributes>
 *     <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
 *     <attribute name="background" value="red" start="5" end="10"/>"
 *   </attributes>
 * </object>
98
 * ]|
Matthias Clasen's avatar
Matthias Clasen committed
99
 *
100 101 102 103 104
 * 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.
Matthias Clasen's avatar
Matthias Clasen committed
105
 *
106
 * # Mnemonics
Matthias Clasen's avatar
Matthias Clasen committed
107
 *
108
 * Labels may contain “mnemonics”. Mnemonics are
109 110
 * underlined characters in the label, used for keyboard navigation.
 * Mnemonics are created by providing a string with an underscore before
111
 * the mnemonic character, such as `"_File"`, to the
112 113 114 115 116
 * 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
117 118
 * 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
119 120
 * the label is inside a button:
 *
121
 * |[<!-- language="C" -->
122
 *   // Pressing Alt+H will activate this button
Matthias Clasen's avatar
Matthias Clasen committed
123
 *   button = gtk_button_new ();
124 125
 *   label = gtk_label_new_with_mnemonic ("_Hello");
 *   gtk_container_add (GTK_CONTAINER (button), label);
126
 * ]|
127
 *
128
 * There’s a convenience function to create buttons with a mnemonic label
129 130
 * already inside:
 *
131
 * |[<!-- language="C" -->
132
 *   // Pressing Alt+H will activate this button
133
 *   button = gtk_button_new_with_mnemonic ("_Hello");
134
 * ]|
135 136 137 138 139
 *
 * 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():
 *
140
 * |[<!-- language="C" -->
141
 *   // Pressing Alt+H will focus the entry
Matthias Clasen's avatar
Matthias Clasen committed
142
 *   entry = gtk_entry_new ();
143 144
 *   label = gtk_label_new_with_mnemonic ("_Hello");
 *   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
145
 * ]|
Matthias Clasen's avatar
Matthias Clasen committed
146
 *
147
 * # Markup (styled text)
Matthias Clasen's avatar
Matthias Clasen committed
148 149
 *
 * To make it easy to format text in a label (changing colors,
150 151
 * fonts, etc.), label text can be provided in a simple
 * [markup format][PangoMarkupFormat].
152
 *
153
 * Here’s how to create a label with a small font:
154
 * |[<!-- language="C" -->
155 156
 *   label = gtk_label_new (NULL);
 *   gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
157
 * ]|
158
 *
159
 * (See [complete documentation][PangoMarkupFormat] of available
160 161 162
 * tags in the Pango manual.)
 *
 * The markup passed to gtk_label_set_markup() must be valid; for example,
163 164 165
 * literal <, > and & 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
166 167 168 169 170
 * 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
171
 * cause internationalization problems, unless you’re applying attributes
172 173 174 175
 * 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.
Matthias Clasen's avatar
Matthias Clasen committed
176
 *
177
 * # Selectable labels
Matthias Clasen's avatar
Matthias Clasen committed
178
 *
179 180 181
 * 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
182
 * — such as error messages — should be made selectable.
Matthias Clasen's avatar
Matthias Clasen committed
183
 *
184
 * # Text layout # {#label-text-layout}
Matthias Clasen's avatar
Matthias Clasen committed
185
 *
186 187 188 189 190 191 192 193 194 195
 * 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
196 197
 * aligns in its available space, see the #GtkWidget::halign and
 * #GtkWidget:valign properties.
198 199 200 201 202 203 204 205 206 207 208 209
 *
 * 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 that the interpretation of #GtkLabel:width-chars and
 * #GtkLabel:max-width-chars has changed a bit with the introduction of
210
 * [width-for-height geometry management.][geometry-management]
Matthias Clasen's avatar
Matthias Clasen committed
211
 *
212
 * # Links
Matthias Clasen's avatar
Matthias Clasen committed
213
 *
214
 * Since 2.18, GTK+ supports markup for clickable hyperlinks in addition
215 216 217 218
 * to regular Pango markup. The markup for links is borrowed from HTML,
 * using the `<a>` 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.
219
 *
Matthias Clasen's avatar
Matthias Clasen committed
220
 * An example looks like this:
221
 *
222
 * |[<!-- language="C" -->
223 224 225 226 227
 * const gchar *text =
 * "Go to the"
 * "<a href=\"http://www.gtk.org title="&lt;i&gt;Our&lt;/i&gt; website\">"
 * "GTK+ website</a> for more...";
 * gtk_label_set_markup (label, text);
228
 * ]|
229 230 231 232 233
 *
 * 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.
 */

234
struct _GtkLabelPrivate
235
{
236 237 238 239 240
  GtkLabelSelectionInfo *select_info;
  GtkWidget *mnemonic_widget;
  GtkWindow *mnemonic_window;

  PangoAttrList *attrs;
Benjamin Otte's avatar
Benjamin Otte committed
241
  PangoAttrList *markup_attrs;
242
  PangoLayout   *layout;
243

244 245 246
  GtkGesture    *drag_gesture;
  GtkGesture    *multipress_gesture;

247 248 249
  gchar   *label;
  gchar   *text;

250
  gdouble  angle;
251 252
  gfloat   xalign;
  gfloat   yalign;
253

254
  guint    mnemonics_visible  : 1;
255 256 257 258 259 260 261 262 263 264 265
  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;
266 267 268 269 270

  guint    mnemonic_keyval;

  gint     width_chars;
  gint     max_width_chars;
271
  gint     lines;
272
};
273 274 275 276 277 278 279

/* 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
280
 * pointer. For keyboard navigation, the “focus” link is determined by
281 282 283 284 285
 * 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.
 *
286 287 288
 * Links are rendered with the #GTK_STATE_FLAG_LINK/#GTK_STATE_FLAG_VISITED
 * state flags. When the mouse pointer is over a link, the pointer is changed
 * to indicate the link.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
 *
 * 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;
310

311 312 313 314 315
struct _GtkLabelSelectionInfo
{
  GdkWindow *window;
  gint selection_anchor;
  gint selection_end;
316
  GtkWidget *popup_menu;
317
  GtkCssNode *selection_node;
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
  PROP_MAX_WIDTH_CHARS,
360
  PROP_TRACK_VISITED_LINKS,
361 362
  PROP_LINES,
  PROP_XALIGN,
363 364
  PROP_YALIGN,
  NUM_PROPERTIES
365 366
};

367 368
static GParamSpec *label_props[NUM_PROPERTIES] = { NULL, };

369 370 371
/* 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.
 * */
372
#define ROTATION_ELLIPSIZE_PADDING 2
373

374 375
static guint signals[LAST_SIGNAL] = { 0 };

376 377 378 379 380 381
static GQuark quark_shortcuts_connected;
static GQuark quark_mnemonic_menu;
static GQuark quark_mnemonics_visible_connected;
static GQuark quark_gtk_signal;
static GQuark quark_link;

382 383 384
static void gtk_label_set_property      (GObject          *object,
					 guint             prop_id,
					 const GValue     *value,
385
					 GParamSpec       *pspec);
386 387 388
static void gtk_label_get_property      (GObject          *object,
					 guint             prop_id,
					 GValue           *value,
389
					 GParamSpec       *pspec);
390
static void gtk_label_finalize          (GObject          *object);
391
static void gtk_label_destroy           (GtkWidget        *widget);
392 393
static void gtk_label_size_allocate     (GtkWidget        *widget,
                                         GtkAllocation    *allocation);
394 395
static void gtk_label_state_flags_changed   (GtkWidget        *widget,
                                             GtkStateFlags     prev_state);
396
static void gtk_label_style_updated     (GtkWidget        *widget);
397
static gboolean gtk_label_draw          (GtkWidget        *widget,
Benjamin Otte's avatar
Benjamin Otte committed
398
                                         cairo_t          *cr);
399 400
static gboolean gtk_label_focus         (GtkWidget         *widget,
                                         GtkDirectionType   direction);
Elliot Lee's avatar
Elliot Lee committed
401

402 403 404 405
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
406 407 408

static gboolean gtk_label_motion            (GtkWidget        *widget,
					     GdkEventMotion   *event);
409 410 411
static gboolean gtk_label_leave_notify      (GtkWidget        *widget,
                                             GdkEventCrossing *event);

412
static void     gtk_label_grab_focus        (GtkWidget        *widget);
413

414 415 416 417 418
static gboolean gtk_label_query_tooltip     (GtkWidget        *widget,
                                             gint              x,
                                             gint              y,
                                             gboolean          keyboard_tip,
                                             GtkTooltip       *tooltip);
419 420 421 422 423

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

443 444
static void gtk_label_create_window       (GtkLabel *label);
static void gtk_label_destroy_window      (GtkLabel *label);
445 446 447
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);
448
static void gtk_label_clear_layout        (GtkLabel *label);
449
static void gtk_label_ensure_layout       (GtkLabel *label);
450 451 452 453
static void gtk_label_select_region_index (GtkLabel *label,
                                           gint      anchor_index,
                                           gint      end_index);

454

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

465 466 467 468 469 470 471 472 473 474 475 476 477 478
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);

479

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


487
/* For selectable labels: */
488 489 490 491 492 493 494 495 496 497 498 499
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);
500

501 502
/* For links: */
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
static GtkLabelLink *gtk_label_get_current_link (GtkLabel  *label);
507 508
static void          emit_activate_link         (GtkLabel     *label,
                                                 GtkLabelLink *link);
509

510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
/* Event controller callbacks */
static void   gtk_label_multipress_gesture_pressed  (GtkGestureMultiPress *gesture,
                                                     gint                  n_press,
                                                     gdouble               x,
                                                     gdouble               y,
                                                     GtkLabel             *label);
static void   gtk_label_multipress_gesture_released (GtkGestureMultiPress *gesture,
                                                     gint                  n_press,
                                                     gdouble               x,
                                                     gdouble               y,
                                                     GtkLabel             *label);
static void   gtk_label_drag_gesture_begin          (GtkGestureDrag *gesture,
                                                     gdouble         start_x,
                                                     gdouble         start_y,
                                                     GtkLabel       *label);
static void   gtk_label_drag_gesture_update         (GtkGestureDrag *gesture,
                                                     gdouble         offset_x,
                                                     gdouble         offset_y,
                                                     GtkLabel       *label);

530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
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);
545 546 547 548 549 550
static void    gtk_label_get_preferred_height_and_baseline_for_width (GtkWidget          *widget,
								      gint                width,
								      gint               *minimum_height,
								      gint               *natural_height,
								      gint               *minimum_baseline,
								      gint               *natural_baseline);
551

552 553
static GtkBuildableIface *buildable_parent_iface = NULL;

Matthias Clasen's avatar
Matthias Clasen committed
554
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
555
G_DEFINE_TYPE_WITH_CODE (GtkLabel, gtk_label, GTK_TYPE_MISC,
556
                         G_ADD_PRIVATE (GtkLabel)
Matthias Clasen's avatar
Matthias Clasen committed
557 558 559
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                gtk_label_buildable_interface_init))
G_GNUC_END_IGNORE_DEPRECATIONS
Elliot Lee's avatar
Elliot Lee committed
560

561 562 563 564 565 566 567 568 569 570
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,
571
				"move-cursor", 3,
Manish Singh's avatar
Manish Singh committed
572
				G_TYPE_ENUM, step,
573
				G_TYPE_INT, count,
Manish Singh's avatar
Manish Singh committed
574
				G_TYPE_BOOLEAN, FALSE);
575 576 577

  /* Selection-extending version */
  gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
578
				"move-cursor", 3,
Manish Singh's avatar
Manish Singh committed
579
				G_TYPE_ENUM, step,
580
				G_TYPE_INT, count,
Manish Singh's avatar
Manish Singh committed
581
				G_TYPE_BOOLEAN, TRUE);
582 583
}

584
static void
Elliot Lee's avatar
Elliot Lee committed
585 586
gtk_label_class_init (GtkLabelClass *class)
{
587
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
588
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
589
  GtkBindingSet *binding_set;
590

591 592
  gobject_class->set_property = gtk_label_set_property;
  gobject_class->get_property = gtk_label_get_property;
593
  gobject_class->finalize = gtk_label_finalize;
594

595
  widget_class->destroy = gtk_label_destroy;
596
  widget_class->size_allocate = gtk_label_size_allocate;
597
  widget_class->state_flags_changed = gtk_label_state_flags_changed;
598
  widget_class->style_updated = gtk_label_style_updated;
599
  widget_class->query_tooltip = gtk_label_query_tooltip;
Benjamin Otte's avatar
Benjamin Otte committed
600
  widget_class->draw = gtk_label_draw;
601 602 603 604 605
  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->motion_notify_event = gtk_label_motion;
606
  widget_class->leave_notify_event = gtk_label_leave_notify;
607
  widget_class->hierarchy_changed = gtk_label_hierarchy_changed;
608
  widget_class->screen_changed = gtk_label_screen_changed;
609
  widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
610
  widget_class->drag_data_get = gtk_label_drag_data_get;
611
  widget_class->grab_focus = gtk_label_grab_focus;
612 613
  widget_class->popup_menu = gtk_label_popup_menu;
  widget_class->focus = gtk_label_focus;
614 615 616 617 618
  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;
619
  widget_class->get_preferred_height_and_baseline_for_width = gtk_label_get_preferred_height_and_baseline_for_width;
620 621 622

  class->move_cursor = gtk_label_move_cursor;
  class->copy_clipboard = gtk_label_copy_clipboard;
623 624
  class->activate_link = gtk_label_activate_link;

Matthias Clasen's avatar
Matthias Clasen committed
625 626 627 628 629 630 631 632
  /**
   * 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
633
   * [keybinding signal][GtkBindingSignal]
Matthias Clasen's avatar
Matthias Clasen committed
634 635 636 637 638
   * 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
639
   * g_signal_emit_by_name() if they need to control the cursor
Matthias Clasen's avatar
Matthias Clasen committed
640 641 642 643 644 645
   * 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.
646 647 648
   * - Arrow keys move by individual characters/lines
   * - Ctrl-arrow key combinations move by words/paragraphs
   * - Home/End keys move to the ends of the buffer
Matthias Clasen's avatar
Matthias Clasen committed
649
   */
650
  signals[MOVE_CURSOR] = 
651
    g_signal_new (I_("move-cursor"),
Manish Singh's avatar
Manish Singh committed
652 653 654 655 656 657 658 659 660
		  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
661 662 663 664 665 666

   /**
   * GtkLabel::copy-clipboard:
   * @label: the object which received the signal
   *
   * The ::copy-clipboard signal is a
667
   * [keybinding signal][GtkBindingSignal]
Matthias Clasen's avatar
Matthias Clasen committed
668 669 670 671
   * which gets emitted to copy the selection to the clipboard.
   *
   * The default binding for this signal is Ctrl-c.
   */ 
672
  signals[COPY_CLIPBOARD] =
673
    g_signal_new (I_("copy-clipboard"),
Manish Singh's avatar
Manish Singh committed
674 675 676 677 678 679
		  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);
680
  
Matthias Clasen's avatar
Matthias Clasen committed
681 682 683 684 685 686 687 688 689 690 691 692
  /**
   * 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.
   */
693
  signals[POPULATE_POPUP] =
694
    g_signal_new (I_("populate-popup"),
Manish Singh's avatar
Manish Singh committed
695 696 697 698 699 700 701 702
		  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);

703
    /**
704 705
     * GtkLabel::activate-current-link:
     * @label: The label on which the signal was emitted
706
     *
707
     * A [keybinding signal][GtkBindingSignal]
708 709 710 711 712 713 714
     * 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.
     *
715 716 717
     * Since: 2.18
     */
    signals[ACTIVATE_CURRENT_LINK] =
718
      g_signal_new_class_handler (I_("activate-current-link"),
719
                                  G_TYPE_FROM_CLASS (gobject_class),
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
                                  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().
     *
735 736 737 738 739
     * Returns: %TRUE if the link has been activated
     *
     * Since: 2.18
     */
    signals[ACTIVATE_LINK] =
740
      g_signal_new (I_("activate-link"),
741
                    G_TYPE_FROM_CLASS (gobject_class),
742
                    G_SIGNAL_RUN_LAST,
743 744
                    G_STRUCT_OFFSET (GtkLabelClass, activate_link),
                    _gtk_boolean_handled_accumulator, NULL,
745 746
                    _gtk_marshal_BOOLEAN__STRING,
                    G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
747

748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
  /**
   * GtkLabel:label:
   *
   * The contents of the label.
   *
   * If the string contains [Pango XML markup][PangoMarkupFormat], you will
   * have to set the #GtkLabel:use-markup property to %TRUE in order for the
   * label to display the markup attributes. See also gtk_label_set_markup()
   * for a convenience function that sets both this property and the
   * #GtkLabel:use-markup property at the same time.
   *
   * If the string contains underlines acting as mnemonics, you will have to
   * set the #GtkLabel:use-underline property to %TRUE in order for the label
   * to display them.
   */
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
  label_props[PROP_LABEL] =
      g_param_spec_string ("label",
                           P_("Label"),
                           P_("The text of the label"),
                           "",
                           GTK_PARAM_READWRITE);

  label_props[PROP_ATTRIBUTES] =
      g_param_spec_boxed ("attributes",
                          P_("Attributes"),
                          P_("A list of style attributes to apply to the text of the label"),
                          PANGO_TYPE_ATTR_LIST,
                          GTK_PARAM_READWRITE);

  label_props[PROP_USE_MARKUP] =
      g_param_spec_boolean ("use-markup",
                            P_("Use markup"),
                            P_("The text of the label includes XML markup. See pango_parse_markup()"),
                            FALSE,
                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

  label_props[PROP_USE_UNDERLINE] =
      g_param_spec_boolean ("use-underline",
                            P_("Use underline"),
                            P_("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
                            FALSE,
                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

  label_props[PROP_JUSTIFY] =
      g_param_spec_enum ("justify",
                         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 GtkLabel:xalign for that"),
                         GTK_TYPE_JUSTIFICATION,
                         GTK_JUSTIFY_LEFT,
                         GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
798

799 800 801 802 803 804 805 806 807 808
  /**
   * GtkLabel:xalign:
   *
   * The xalign property determines the horizontal aligment of the label text
   * inside the labels size allocation. Compare this to #GtkWidget:halign,
   * which determines how the labels size allocation is positioned in the
   * space available for the label.
   *
   * Since: 3.16
   */
809 810 811 812 813 814 815
  label_props[PROP_XALIGN] =
      g_param_spec_float ("xalign",
                          P_("X align"),
                          P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
                          0.0, 1.0,
                          0.5,
                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
816 817 818 819 820 821 822 823 824 825 826

  /**
   * GtkLabel:yalign:
   *
   * The yalign property determines the vertical aligment of the label text
   * inside the labels size allocation. Compare this to #GtkWidget:valign,
   * which determines how the labels size allocation is positioned in the
   * space available for the label.
   *
   * Since: 3.16
   */
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
  label_props[PROP_YALIGN] =
      g_param_spec_float ("yalign",
                          P_("Y align"),
                          P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
                          0.0, 1.0,
                          0.5,
                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

  label_props[PROP_PATTERN] =
      g_param_spec_string ("pattern",
                           P_("Pattern"),
                           P_("A string with _ characters in positions correspond to characters in the text to underline"),
                           NULL,
                           GTK_PARAM_WRITABLE);

  label_props[PROP_WRAP] =
      g_param_spec_boolean ("wrap",
                            P_("Line wrap"),
                            P_("If set, wrap lines if the text becomes too wide"),
                            FALSE,
                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
848

849 850 851
  /**
   * GtkLabel:wrap-mode:
   *
852 853
   * 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
854
   * means wrap on word boundaries.
855 856 857
   *
   * Since: 2.10
   */
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 893 894 895 896 897 898 899 900 901 902 903
  label_props[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|G_PARAM_EXPLICIT_NOTIFY);

  label_props[PROP_SELECTABLE] =
      g_param_spec_boolean ("selectable",
                            P_("Selectable"),
                            P_("Whether the label text can be selected with the mouse"),
                            FALSE,
                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

  label_props[PROP_MNEMONIC_KEYVAL] =
      g_param_spec_uint ("mnemonic-keyval",
                         P_("Mnemonic key"),
                         P_("The mnemonic accelerator key for this label"),
                         0, G_MAXUINT,
                         GDK_KEY_VoidSymbol,
                         GTK_PARAM_READABLE);

  label_props[PROP_MNEMONIC_WIDGET] =
      g_param_spec_object ("mnemonic-widget",
                           P_("Mnemonic widget"),
                           P_("The widget to be activated when the label's mnemonic key is pressed"),
                           GTK_TYPE_WIDGET,
                           GTK_PARAM_READWRITE);

  label_props[PROP_CURSOR_POSITION] =
      g_param_spec_int ("cursor-position",
                        P_("Cursor Position"),
                        P_("The current position of the insertion cursor in chars"),
                        0, G_MAXINT,
                        0,
                        GTK_PARAM_READABLE);

  label_props[PROP_SELECTION_BOUND] =
      g_param_spec_int ("selection-bound",
                        P_("Selection Bound"),
                        P_("The position of the opposite end of the selection from the cursor in chars"),
                        0, G_MAXINT,
                        0,
                        GTK_PARAM_READABLE);

904 905 906
  /**
   * GtkLabel:ellipsize:
   *
907 908 909
   * The preferred place to ellipsize the string, if the label does
   * not have enough room to display the entire string, specified as a
   * #PangoEllipsizeMode.
910
   *
911 912 913 914
   * 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
915
   * the #GtkNotebook tab-expand child property is set to %TRUE. Other ways
916 917
   * to set a label's width are gtk_widget_set_size_request() and
   * gtk_label_set_width_chars().
918 919 920
   *
   * Since: 2.6
   */
921 922 923 924 925 926 927
  label_props[PROP_ELLIPSIZE] =
      g_param_spec_enum ("ellipsize",
                         P_("Ellipsize"),
                         P_("The preferred place to ellipsize the string, if the label does not have enough room to display the entire string"),
                         PANGO_TYPE_ELLIPSIZE_MODE,
                         PANGO_ELLIPSIZE_NONE,
                         GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
928 929 930

  /**
   * GtkLabel:width-chars:
931
   *
932
   * The desired width of the label, in characters. If this property is set to
933 934
   * -1, the width will be calculated automatically.
   *
935
   * See the section on [text layout][label-text-layout]
936 937
   * for details of how #GtkLabel:width-chars and #GtkLabel:max-width-chars
   * determine the width of ellipsized and wrapped labels.
938
   *
939 940
   * Since: 2.6
   **/
941 942 943 944 945 946 947 948
  label_props[PROP_WIDTH_CHARS] =
      g_param_spec_int ("width-chars",
                        P_("Width In Characters"),
                        P_("The desired width of the label, in characters"),
                        -1, G_MAXINT,
                        -1,
                        GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

949 950
  /**
   * GtkLabel:single-line-mode:
951
   *
952 953 954
   * 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
955
   * advantage in situations where resizing the label because of text
956 957 958 959
   * changes would be distracting, e.g. in a statusbar.
   *
   * Since: 2.6
   **/
960 961 962 963 964 965
  label_props[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,
                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
966 967 968 969 970 971 972 973 974 975 976

  /**
   * 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
   **/
977 978 979 980 981 982 983 984
  label_props[PROP_ANGLE] =
      g_param_spec_double ("angle",
                           P_("Angle"),
                           P_("Angle at which the label is rotated"),
                           0.0, 360.0,
                           0.0,
                           GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

985 986
  /**
   * GtkLabel:max-width-chars:
987 988
   *
   * The desired maximum width of the label, in characters. If this property
989 990
   * is set to -1, the width will be calculated automatically.
   *
991
   * See the section on [text layout][label-text-layout]
992 993 994
   * for details of how #GtkLabel:width-chars and #GtkLabel:max-width-chars
   * determine the width of ellipsized and wrapped labels.
   *
995 996
   * Since: 2.6
   **/
997 998 999 1000 1001 1002 1003
  label_props[PROP_MAX_WIDTH_CHARS] =
      g_param_spec_int ("max-width-chars",
                        P_("Maximum Width In Characters"),
                        P_("The desired maximum width of the label, in characters"),
                        -1, G_MAXINT,
                        -1,
                        GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
1004 1005 1006 1007 1008

  /**
   * GtkLabel:track-visited-links:
   *
   * Set this property to %TRUE to make the label track which links
1009 1010
   * have been visited. It will then apply the #GTK_STATE_FLAG_VISITED
   * when rendering this link, in addition to #GTK_STATE_FLAG_LINK.
1011 1012 1013
   *
   * Since: 2.18
   */
1014 1015 1016 1017 1018 1019
  label_props[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|G_PARAM_EXPLICIT_NOTIFY);
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

  /**
   * GtkLabel:lines:
   *
   * The number of lines to which an ellipsized, wrapping label
   * should be limited. This property has no effect if the
   * label is not wrapping or ellipsized. Set this property to
   * -1 if you don't want to limit the number of lines.
   *
   * Since: 3.10
   */
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
  label_props[PROP_LINES] =
      g_param_spec_int ("lines",
                        P_("Number of lines"),
                        P_("The desired number of lines, when ellipsizing a wrapping label"),
                        -1, G_MAXINT,
                        -1,
                        GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);

  g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);

1041 1042 1043 1044 1045 1046
  /*
   * Key bindings
   */
  binding_set = gtk_binding_set_by_class (class);

  /* Moving the insertion point */
1047
  add_move_binding (binding_set, GDK_KEY_Right, 0,
1048
		    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1049

1050
  add_move_binding (binding_set, GDK_KEY_Left, 0,
1051 1052
		    GTK_MOVEMENT_VISUAL_POSITIONS, -1);

1053
  add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1054 1055
		    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
  
1056
  add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1057 1058
		    GTK_MOVEMENT_VISUAL_POSITIONS, -1);
  
1059
  add_move_binding (binding_set, GDK_KEY_f, GDK_CONTROL_MASK,
1060 1061
		    GTK_MOVEMENT_LOGICAL_POSITIONS, 1);
  
1062
  add_move_binding (binding_set, GDK_KEY_b, GDK_CONTROL_MASK,
1063 1064
		    GTK_MOVEMENT_LOGICAL_POSITIONS, -1);
  
1065
  add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
1066 1067
		    GTK_MOVEMENT_WORDS, 1);

1068
  add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
1069 1070
		    GTK_MOVEMENT_WORDS, -1);

1071
  add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
1072 1073
		    GTK_MOVEMENT_WORDS, 1);

1074
  add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
1075 1076
		    GTK_MOVEMENT_WORDS, -1);

1077
  /* select all */
1078
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1079
				"move-cursor", 3,
1080 1081 1082 1083
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, -1,
				G_TYPE_BOOLEAN, FALSE);

1084
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1085
				"move-cursor", 3,
1086 1087 1088 1089
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 1,
				G_TYPE_BOOLEAN, TRUE);

1090
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1091
				"move-cursor", 3,
1092 1093 1094 1095
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, -1,
				G_TYPE_BOOLEAN, FALSE);

1096
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
1097
				"move-cursor", 3,
1098 1099 1100 1101 1102
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 1,
				G_TYPE_BOOLEAN, TRUE);

  /* unselect all */
1103
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
1104
				"move-cursor", 3,
1105 1106 1107 1108
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 0,
				G_TYPE_BOOLEAN, FALSE);

1109
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
1110
				"move-cursor", 3,
1111 1112 1113
				G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
				G_TYPE_INT, 0,
				G_TYPE_BOOLEAN, FALSE);
1114

1115
  add_move_binding (binding_set, GDK_KEY_f, GDK_MOD1_MASK,
1116 1117
		    GTK_MOVEMENT_WORDS, 1);

1118
  add_move_binding (binding_set, GDK_KEY_b, GDK_MOD1_MASK,
1119 1120
		    GTK_MOVEMENT_WORDS, -1);

1121
  add_move_binding (binding_set, GDK_KEY_Home, 0,
1122 1123
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);

1124
  add_move_binding (binding_set, GDK_KEY_End, 0,
1125 1126
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);

1127
  add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1128 1129
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);

1130
  add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1131 1132
		    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
  
1133
  add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
1134 1135
		    GTK_MOVEMENT_BUFFER_ENDS, -1);

1136
  add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
1137 1138
		    GTK_MOVEMENT_BUFFER_ENDS, 1);

1139
  add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
1140 1141
		    GTK_MOVEMENT_BUFFER_ENDS, -1);

1142
  add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
1143 1144 1145
		    GTK_MOVEMENT_BUFFER_ENDS, 1);

  /* copy */
1146
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
1147
				"copy-clipboard", 0);
1148

1149
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1150
				"activate-current-link", 0);
1151
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1152
				"activate-current-link", 0);
1153
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1154
				"activate-current-link", 0);
1155

1156
  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LABEL_ACCESSIBLE);
1157

1158 1159
  gtk_widget_class_set_css_name (widget_class, "label");

1160 1161 1162 1163 1164
  quark_shortcuts_connected = g_quark_from_static_string ("gtk-label-shortcuts-connected");
  quark_mnemonic_menu = g_quark_from_static_string ("gtk-mnemonic-menu");
  quark_mnemonics_visible_connected = g_quark_from_static_string ("gtk-label-mnemonics-visible-connected");
  quark_gtk_signal = g_quark_from_static_string ("gtk-signal");
  quark_link = g_quark_from_static_string ("link");
Elliot Lee's avatar
Elliot Lee committed
1165 1166
}

1167 1168 1169 1170
static void 
gtk_label_set_property (GObject      *object,
			guint         prop_id,
			const GValue *value,
1171
			GParamSpec   *pspec)
1172
{
1173
  GtkLabel *label = GTK_LABEL (object);
1174

1175
  switch (prop_id)
1176
    {
1177
    case PROP_LABEL:
1178
      gtk_label_set_label (label, g_value_get_string (value));
1179 1180 1181 1182 1183
      break;
    case PROP_ATTRIBUTES:
      gtk_label_set_attributes (label, g_value_get_boxed (value));
      break;
    case PROP_USE_MARKUP:
1184
      gtk_label_set_use_markup (label, g_value_get_boolean (value));
1185
      break;
1186
    case PROP_USE_UNDERLINE:
1187
      gtk_label_set_use_underline (label, g_value_get_boolean (value));
1188
      break;
1189 1190
    case PROP_JUSTIFY:
      gtk_label_set_justify (label, g_value_get_enum (value));