]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtklabel.sgml
fix markup
[~andy/gtk] / docs / reference / gtk / tmpl / gtklabel.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkLabel
3
4 <!-- ##### SECTION Short_Description ##### -->
5 A widget that displays a small to medium amount of text
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 The #GtkLabel widget displays a small amount of text. As the name
10 implies, most labels are used to label another widget such as a
11 #GtkButton, a #GtkMenuItem, or a #GtkOptionMenu.
12 </para>
13
14 <refsect2 id="GtkLabel-BUILDER-UI">
15 <title>GtkLabel as GtkBuildable</title>
16 <para>
17 The GtkLabel implementation of the GtkBuildable interface supports a 
18 custom &lt;attributes&gt; element, which supports any number of &lt;attribute&gt;
19 elements. the &lt;attribute&gt; element has attributes named name, value,
20 start and end and allows you to specify #PangoAttribute values for this label.
21 </para>
22 <example>
23 <title>A UI definition fragment specifying Pango attributes</title>
24 <programlisting><![CDATA[
25 <object class="GtkLabel">
26   <attributes>
27     <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
28     <attribute name="background" value="red" start="5" end="10"/>"
29   </attributes>
30 </object>
31 ]]></programlisting>
32 </example>
33 <para>
34 The start and end attributes specify the range of characters to which the
35 Pango attribute applies. If start and end are not specified, the attribute is
36 applied to the whole text. Note that specifying ranges does not make much
37 sense with translatable attributes. Use markup embedded in the translatable
38 content instead.
39 </para>
40 </refsect2>
41
42
43 <refsect2>
44 <title>Mnemonics</title>
45
46 <para>
47 Labels may contain <firstterm>mnemonics</firstterm>. Mnemonics are
48 underlined characters in the label, used for keyboard navigation.
49 Mnemonics are created by providing a string with an underscore before
50 the mnemonic character, such as <literal>"_File"</literal>, to the
51 functions gtk_label_new_with_mnemonic() or
52 gtk_label_set_text_with_mnemonic().
53 </para>
54
55 <para>
56 Mnemonics automatically activate any activatable widget the label is
57 inside, such as a #GtkButton; if the label is not inside the
58 mnemonic's target widget, you have to tell the label about the target
59 using gtk_label_set_mnemonic_widget(). Here's a simple example where
60 the label is inside a button:
61
62 <informalexample>
63 <programlisting>
64   /* Pressing Alt+H will activate this button */
65   button = gtk_button_new (<!-- -->);
66   label = gtk_label_new_with_mnemonic ("_Hello");
67   gtk_container_add (GTK_CONTAINER (button), label);
68 </programlisting>
69 </informalexample>
70 There's a convenience function to create buttons with a mnemonic label 
71 already inside:
72
73 <informalexample>
74 <programlisting>
75   /* Pressing Alt+H will activate this button */
76   button = gtk_button_new_with_mnemonic ("_Hello");
77 </programlisting>
78 </informalexample>
79
80 To create a mnemonic for a widget alongside the label, such as a 
81 #GtkEntry, you have to point the label at the entry with 
82 gtk_label_set_mnemonic_widget():
83 <informalexample>
84 <programlisting>
85   /* Pressing Alt+H will focus the entry */
86   entry = gtk_entry_new (<!-- -->);
87   label = gtk_label_new_with_mnemonic ("_Hello");
88   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
89 </programlisting>
90 </informalexample>
91
92 </para>
93
94 </refsect2>
95
96 <refsect2>
97 <title>Markup (styled text)</title>
98
99 <para>
100 To make it easy to format text in a label (changing colors, fonts,
101 etc.), label text can be provided in a simple <link
102 linkend="PangoMarkupFormat">markup format</link>.
103 Here's how to create a label with a small font:
104 <informalexample>
105 <programlisting>
106   label = gtk_label_new (NULL);
107   gtk_label_set_markup (GTK_LABEL (label), "&lt;small&gt;Small text&lt;/small&gt;");
108 </programlisting>
109 </informalexample>
110 (See <link
111 linkend="PangoMarkupFormat">complete documentation</link> of available
112 tags in the Pango manual.)
113 </para>
114 <para>
115 The markup passed to gtk_label_set_markup() must be valid; for example,
116 literal &lt;/&gt;/&amp; characters must be escaped as &amp;lt;,
117 &amp;gt;, and &amp;amp;. If you pass text obtained from the user, file,
118 or a network to gtk_label_set_markup(), you'll want to escape it with
119 g_markup_escape_text() or g_markup_printf_escaped().
120 </para>
121 <para>
122 Markup strings are just a convenient way to set the #PangoAttrList on
123 a label; gtk_label_set_attributes() may be a simpler way to set
124 attributes in some cases. Be careful though; #PangoAttrList tends to
125 cause internationalization problems, unless you're applying attributes
126 to the entire string (i.e. unless you set the range of each attribute
127 to [0, G_MAXINT)). The reason is that specifying the start_index and
128 end_index for a #PangoAttribute requires knowledge of the exact string
129 being displayed, so translations will cause problems.
130 </para>
131 </refsect2>
132
133 <refsect2>
134 <title>Selectable labels</title>
135
136 <para>
137 Labels can be made selectable with gtk_label_set_selectable(). 
138 Selectable labels allow the user to copy the label contents to 
139 the clipboard. Only labels that contain useful-to-copy information
140 &mdash; such as error messages &mdash; should be made selectable.
141 </para>
142 </refsect2>
143
144 <refsect2>
145 <title>Text layout</title>
146
147 <para>
148 A label can contain any number of paragraphs, but will have
149 performance problems if it contains more than a small number.
150 Paragraphs are separated by newlines or other paragraph separators
151 understood by Pango.
152 </para>
153 <para>
154 Labels can automatically wrap text if you call
155 gtk_label_set_line_wrap().
156 </para>
157 <para>
158 gtk_label_set_justify() sets how the lines in a label align 
159 with one another. If you want to set how the label as a whole 
160 aligns in its available space, see gtk_misc_set_alignment().
161 </para>
162
163 </refsect2>
164
165 <!-- ##### SECTION See_Also ##### -->
166 <para>
167
168 </para>
169
170 <!-- ##### SECTION Stability_Level ##### -->
171
172
173 <!-- ##### STRUCT GtkLabel ##### -->
174 <para>
175 This should not be accessed directly.  Use the accessor functions as
176 described below.
177 </para>
178
179
180 <!-- ##### SIGNAL GtkLabel::copy-clipboard ##### -->
181 <para>
182
183 </para>
184
185 @label: the object which received the signal.
186
187 <!-- ##### SIGNAL GtkLabel::move-cursor ##### -->
188 <para>
189
190 </para>
191
192 @label: the object which received the signal.
193 @arg1: 
194 @arg2: 
195 @arg3: 
196
197 <!-- ##### SIGNAL GtkLabel::populate-popup ##### -->
198 <para>
199
200 </para>
201
202 @label: the object which received the signal.
203 @arg1: 
204
205 <!-- ##### ARG GtkLabel:angle ##### -->
206 <para>
207
208 </para>
209
210 <!-- ##### ARG GtkLabel:attributes ##### -->
211 <para>
212
213 </para>
214
215 <!-- ##### ARG GtkLabel:cursor-position ##### -->
216 <para>
217
218 </para>
219
220 <!-- ##### ARG GtkLabel:ellipsize ##### -->
221 <para>
222
223 </para>
224
225 <!-- ##### ARG GtkLabel:justify ##### -->
226 <para>
227
228 </para>
229
230 <!-- ##### ARG GtkLabel:label ##### -->
231 <para>
232
233 </para>
234
235 <!-- ##### ARG GtkLabel:max-width-chars ##### -->
236 <para>
237
238 </para>
239
240 <!-- ##### ARG GtkLabel:mnemonic-keyval ##### -->
241 <para>
242
243 </para>
244
245 <!-- ##### ARG GtkLabel:mnemonic-widget ##### -->
246 <para>
247
248 </para>
249
250 <!-- ##### ARG GtkLabel:pattern ##### -->
251 <para>
252
253 </para>
254
255 <!-- ##### ARG GtkLabel:selectable ##### -->
256 <para>
257
258 </para>
259
260 <!-- ##### ARG GtkLabel:selection-bound ##### -->
261 <para>
262
263 </para>
264
265 <!-- ##### ARG GtkLabel:single-line-mode ##### -->
266 <para>
267
268 </para>
269
270 <!-- ##### ARG GtkLabel:use-markup ##### -->
271 <para>
272
273 </para>
274
275 <!-- ##### ARG GtkLabel:use-underline ##### -->
276 <para>
277
278 </para>
279
280 <!-- ##### ARG GtkLabel:width-chars ##### -->
281 <para>
282
283 </para>
284
285 <!-- ##### ARG GtkLabel:wrap ##### -->
286 <para>
287
288 </para>
289
290 <!-- ##### ARG GtkLabel:wrap-mode ##### -->
291 <para>
292
293 </para>
294
295 <!-- ##### FUNCTION gtk_label_new ##### -->
296 <para>
297
298 </para>
299
300 @str: 
301 @Returns: 
302
303
304 <!-- ##### FUNCTION gtk_label_set_text ##### -->
305 <para>
306
307 </para>
308
309 @label: 
310 @str: 
311
312
313 <!-- ##### FUNCTION gtk_label_set_attributes ##### -->
314 <para>
315
316 </para>
317
318 @label: 
319 @attrs: 
320
321
322 <!-- ##### FUNCTION gtk_label_set_markup ##### -->
323 <para>
324
325 </para>
326
327 @label: 
328 @str: 
329
330
331 <!-- ##### FUNCTION gtk_label_set_markup_with_mnemonic ##### -->
332 <para>
333
334 </para>
335
336 @label: 
337 @str: 
338
339
340 <!-- ##### FUNCTION gtk_label_set_pattern ##### -->
341 <para>
342 The pattern of underlines you want under the existing text within the
343 #GtkLabel widget.  For example if the current text of the label says
344 &quot;FooBarBaz&quot; passing a pattern of &quot;___   ___&quot; will underline
345 &quot;Foo&quot; and &quot;Baz&quot; but not &quot;Bar&quot;.
346 </para>
347
348 @label: The #GtkLabel you want to set the pattern to.
349 @pattern: The pattern as described above.
350
351
352 <!-- ##### FUNCTION gtk_label_set_justify ##### -->
353 <para>
354
355 </para>
356
357 @label: 
358 @jtype: 
359
360
361 <!-- ##### FUNCTION gtk_label_set_ellipsize ##### -->
362 <para>
363
364 </para>
365
366 @label: 
367 @mode: 
368
369
370 <!-- ##### FUNCTION gtk_label_set_width_chars ##### -->
371 <para>
372
373 </para>
374
375 @label: 
376 @n_chars: 
377
378
379 <!-- ##### FUNCTION gtk_label_set_max_width_chars ##### -->
380 <para>
381
382 </para>
383
384 @label: 
385 @n_chars: 
386
387
388 <!-- ##### FUNCTION gtk_label_get ##### -->
389 <para>
390 Gets the current string of text within the #GtkLabel and writes it to
391 the given @str argument.  It does not make a copy of this string so you
392 must not write to it.
393 </para>
394
395 @label: The #GtkLabel widget you want to get the text from.
396 @str: The reference to the pointer you want to point to the text.
397
398
399 <!-- ##### FUNCTION gtk_label_parse_uline ##### -->
400 <para>
401 Parses the given string for underscores and converts the next
402 character to an underlined character.  The last character that
403 was underlined will have its lower-cased accelerator keyval returned  (i.e.
404 &quot;_File&quot; would return the keyval for &quot;f&quot;.  This is
405 probably only used within the GTK+ library itself for menu items and such.
406 </para>
407
408 @label: The #GtkLabel you want to affect.
409 @string: The string you want to parse for underlines.
410 @Returns: The lowercase keyval of the last character underlined.
411
412
413 <!-- ##### FUNCTION gtk_label_set_line_wrap ##### -->
414 <para>
415
416 </para>
417
418 @label: 
419 @wrap: 
420
421
422 <!-- ##### FUNCTION gtk_label_set_line_wrap_mode ##### -->
423 <para>
424
425 </para>
426
427 @label: 
428 @wrap_mode: 
429
430
431 <!-- ##### MACRO gtk_label_set ##### -->
432 <para>
433 Aliases gtk_label_set_text().  Probably used for backward compatibility with
434 GTK+ 1.0.x.
435 </para>
436
437
438
439 <!-- ##### FUNCTION gtk_label_get_layout_offsets ##### -->
440 <para>
441
442 </para>
443
444 @label: 
445 @x: 
446 @y: 
447
448
449 <!-- ##### FUNCTION gtk_label_get_mnemonic_keyval ##### -->
450 <para>
451
452 </para>
453
454 @label: 
455 @Returns: 
456
457
458 <!-- ##### FUNCTION gtk_label_get_selectable ##### -->
459 <para>
460
461 </para>
462
463 @label: 
464 @Returns: 
465
466
467 <!-- ##### FUNCTION gtk_label_get_text ##### -->
468 <para>
469
470 </para>
471
472 @label: 
473 @Returns: 
474
475
476 <!-- ##### FUNCTION gtk_label_new_with_mnemonic ##### -->
477 <para>
478
479 </para>
480
481 @str: 
482 @Returns: 
483
484
485 <!-- ##### FUNCTION gtk_label_select_region ##### -->
486 <para>
487
488 </para>
489
490 @label: 
491 @start_offset: 
492 @end_offset: 
493
494
495 <!-- ##### FUNCTION gtk_label_set_mnemonic_widget ##### -->
496 <para>
497
498 </para>
499
500 @label: 
501 @widget: 
502
503
504 <!-- ##### FUNCTION gtk_label_set_selectable ##### -->
505 <para>
506
507 </para>
508
509 @label: 
510 @setting: 
511
512
513 <!-- ##### FUNCTION gtk_label_set_text_with_mnemonic ##### -->
514 <para>
515
516 </para>
517
518 @label: 
519 @str: 
520
521
522 <!-- ##### FUNCTION gtk_label_get_attributes ##### -->
523 <para>
524
525 </para>
526
527 @label: 
528 @Returns: 
529
530
531 <!-- ##### FUNCTION gtk_label_get_justify ##### -->
532 <para>
533
534 </para>
535
536 @label: 
537 @Returns: 
538
539
540 <!-- ##### FUNCTION gtk_label_get_ellipsize ##### -->
541 <para>
542
543 </para>
544
545 @label: 
546 @Returns: 
547
548
549 <!-- ##### FUNCTION gtk_label_get_width_chars ##### -->
550 <para>
551
552 </para>
553
554 @label: 
555 @Returns: 
556
557
558 <!-- ##### FUNCTION gtk_label_get_max_width_chars ##### -->
559 <para>
560
561 </para>
562
563 @label: 
564 @Returns: 
565
566
567 <!-- ##### FUNCTION gtk_label_get_label ##### -->
568 <para>
569
570 </para>
571
572 @label: 
573 @Returns: 
574
575
576 <!-- ##### FUNCTION gtk_label_get_layout ##### -->
577 <para>
578
579 </para>
580
581 @label: 
582 @Returns: 
583
584
585 <!-- ##### FUNCTION gtk_label_get_line_wrap ##### -->
586 <para>
587
588 </para>
589
590 @label: 
591 @Returns: 
592
593
594 <!-- ##### FUNCTION gtk_label_get_line_wrap_mode ##### -->
595 <para>
596
597 </para>
598
599 @label: 
600 @Returns: 
601
602
603 <!-- ##### FUNCTION gtk_label_get_mnemonic_widget ##### -->
604 <para>
605
606 </para>
607
608 @label: 
609 @Returns: 
610
611
612 <!-- ##### FUNCTION gtk_label_get_selection_bounds ##### -->
613 <para>
614
615 </para>
616
617 @label: 
618 @start: 
619 @end: 
620 @Returns: 
621
622
623 <!-- ##### FUNCTION gtk_label_get_use_markup ##### -->
624 <para>
625
626 </para>
627
628 @label: 
629 @Returns: 
630
631
632 <!-- ##### FUNCTION gtk_label_get_use_underline ##### -->
633 <para>
634
635 </para>
636
637 @label: 
638 @Returns: 
639
640
641 <!-- ##### FUNCTION gtk_label_get_single_line_mode ##### -->
642 <para>
643
644 </para>
645
646 @label: 
647 @Returns: 
648
649
650 <!-- ##### FUNCTION gtk_label_get_angle ##### -->
651 <para>
652
653 </para>
654
655 @label: 
656 @Returns: 
657
658
659 <!-- ##### FUNCTION gtk_label_set_label ##### -->
660 <para>
661
662 </para>
663
664 @label: 
665 @str: 
666
667
668 <!-- ##### FUNCTION gtk_label_set_use_markup ##### -->
669 <para>
670
671 </para>
672
673 @label: 
674 @setting: 
675
676
677 <!-- ##### FUNCTION gtk_label_set_use_underline ##### -->
678 <para>
679
680 </para>
681
682 @label: 
683 @setting: 
684
685
686 <!-- ##### FUNCTION gtk_label_set_single_line_mode ##### -->
687 <para>
688
689 </para>
690
691 @label: 
692 @single_line_mode: 
693
694
695 <!-- ##### FUNCTION gtk_label_set_angle ##### -->
696 <para>
697
698 </para>
699
700 @label: 
701 @angle: 
702
703