1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Label; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Menu; 32 private import gtk.Misc; 33 private import gtk.Widget; 34 public import gtkc.gdktypes; 35 private import gtkc.gtk; 36 public import gtkc.gtktypes; 37 private import pango.PgAttributeList; 38 private import pango.PgLayout; 39 40 41 /** 42 * The #GtkLabel widget displays a small amount of text. As the name 43 * implies, most labels are used to label another widget such as a 44 * #GtkButton, a #GtkMenuItem, or a #GtkComboBox. 45 * 46 * # CSS nodes 47 * 48 * |[<!-- language="plain" --> 49 * label 50 * ├── [selection] 51 * ├── [link] 52 * ┊ 53 * ╰── [link] 54 * ]| 55 * 56 * GtkLabel has a single CSS node with the name label. A wide variety 57 * of style classes may be applied to labels, such as .title, .subtitle, 58 * .dim-label, etc. In the #GtkShortcutsWindow, labels are used wth the 59 * .keycap style class. 60 * 61 * If the label has a selection, it gets a subnode with name selection. 62 * 63 * If the label has links, there is one subnode per link. These subnodes 64 * carry the link or visited state depending on whether they have been 65 * visited. 66 * 67 * # GtkLabel as GtkBuildable 68 * 69 * The GtkLabel implementation of the GtkBuildable interface supports a 70 * custom <attributes> element, which supports any number of <attribute> 71 * elements. The <attribute> element has attributes named “name“, “value“, 72 * “start“ and “end“ and allows you to specify #PangoAttribute values for 73 * this label. 74 * 75 * An example of a UI definition fragment specifying Pango attributes: 76 * |[ 77 * <object class="GtkLabel"> 78 * <attributes> 79 * <attribute name="weight" value="PANGO_WEIGHT_BOLD"/> 80 * <attribute name="background" value="red" start="5" end="10"/>" 81 * </attributes> 82 * </object> 83 * ]| 84 * 85 * The start and end attributes specify the range of characters to which the 86 * Pango attribute applies. If start and end are not specified, the attribute is 87 * applied to the whole text. Note that specifying ranges does not make much 88 * sense with translatable attributes. Use markup embedded in the translatable 89 * content instead. 90 * 91 * # Mnemonics 92 * 93 * Labels may contain “mnemonics”. Mnemonics are 94 * underlined characters in the label, used for keyboard navigation. 95 * Mnemonics are created by providing a string with an underscore before 96 * the mnemonic character, such as `"_File"`, to the 97 * functions gtk_label_new_with_mnemonic() or 98 * gtk_label_set_text_with_mnemonic(). 99 * 100 * Mnemonics automatically activate any activatable widget the label is 101 * inside, such as a #GtkButton; if the label is not inside the 102 * mnemonic’s target widget, you have to tell the label about the target 103 * using gtk_label_set_mnemonic_widget(). Here’s a simple example where 104 * the label is inside a button: 105 * 106 * |[<!-- language="C" --> 107 * // Pressing Alt+H will activate this button 108 * button = gtk_button_new (); 109 * label = gtk_label_new_with_mnemonic ("_Hello"); 110 * gtk_container_add (GTK_CONTAINER (button), label); 111 * ]| 112 * 113 * There’s a convenience function to create buttons with a mnemonic label 114 * already inside: 115 * 116 * |[<!-- language="C" --> 117 * // Pressing Alt+H will activate this button 118 * button = gtk_button_new_with_mnemonic ("_Hello"); 119 * ]| 120 * 121 * To create a mnemonic for a widget alongside the label, such as a 122 * #GtkEntry, you have to point the label at the entry with 123 * gtk_label_set_mnemonic_widget(): 124 * 125 * |[<!-- language="C" --> 126 * // Pressing Alt+H will focus the entry 127 * entry = gtk_entry_new (); 128 * label = gtk_label_new_with_mnemonic ("_Hello"); 129 * gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); 130 * ]| 131 * 132 * # Markup (styled text) 133 * 134 * To make it easy to format text in a label (changing colors, 135 * fonts, etc.), label text can be provided in a simple 136 * [markup format][PangoMarkupFormat]. 137 * 138 * Here’s how to create a label with a small font: 139 * |[<!-- language="C" --> 140 * label = gtk_label_new (NULL); 141 * gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>"); 142 * ]| 143 * 144 * (See [complete documentation][PangoMarkupFormat] of available 145 * tags in the Pango manual.) 146 * 147 * The markup passed to gtk_label_set_markup() must be valid; for example, 148 * literal <, > and & characters must be escaped as <, >, and &. 149 * If you pass text obtained from the user, file, or a network to 150 * gtk_label_set_markup(), you’ll want to escape it with 151 * g_markup_escape_text() or g_markup_printf_escaped(). 152 * 153 * Markup strings are just a convenient way to set the #PangoAttrList on 154 * a label; gtk_label_set_attributes() may be a simpler way to set 155 * attributes in some cases. Be careful though; #PangoAttrList tends to 156 * cause internationalization problems, unless you’re applying attributes 157 * to the entire string (i.e. unless you set the range of each attribute 158 * to [0, %G_MAXINT)). The reason is that specifying the start_index and 159 * end_index for a #PangoAttribute requires knowledge of the exact string 160 * being displayed, so translations will cause problems. 161 * 162 * # Selectable labels 163 * 164 * Labels can be made selectable with gtk_label_set_selectable(). 165 * Selectable labels allow the user to copy the label contents to 166 * the clipboard. Only labels that contain useful-to-copy information 167 * — such as error messages — should be made selectable. 168 * 169 * # Text layout # {#label-text-layout} 170 * 171 * A label can contain any number of paragraphs, but will have 172 * performance problems if it contains more than a small number. 173 * Paragraphs are separated by newlines or other paragraph separators 174 * understood by Pango. 175 * 176 * Labels can automatically wrap text if you call 177 * gtk_label_set_line_wrap(). 178 * 179 * gtk_label_set_justify() sets how the lines in a label align 180 * with one another. If you want to set how the label as a whole 181 * aligns in its available space, see the #GtkWidget:halign and 182 * #GtkWidget:valign properties. 183 * 184 * The #GtkLabel:width-chars and #GtkLabel:max-width-chars properties 185 * can be used to control the size allocation of ellipsized or wrapped 186 * labels. For ellipsizing labels, if either is specified (and less 187 * than the actual text size), it is used as the minimum width, and the actual 188 * text size is used as the natural width of the label. For wrapping labels, 189 * width-chars is used as the minimum width, if specified, and max-width-chars 190 * is used as the natural width. Even if max-width-chars specified, wrapping 191 * labels will be rewrapped to use all of the available width. 192 * 193 * Note that the interpretation of #GtkLabel:width-chars and 194 * #GtkLabel:max-width-chars has changed a bit with the introduction of 195 * [width-for-height geometry management.][geometry-management] 196 * 197 * # Links 198 * 199 * Since 2.18, GTK+ supports markup for clickable hyperlinks in addition 200 * to regular Pango markup. The markup for links is borrowed from HTML, 201 * using the `<a>` with “href“ and “title“ attributes. GTK+ renders links 202 * similar to the way they appear in web browsers, with colored, underlined 203 * text. The “title“ attribute is displayed as a tooltip on the link. 204 * 205 * An example looks like this: 206 * 207 * |[<!-- language="C" --> 208 * const gchar *text = 209 * "Go to the" 210 * "<a href=\"http://www.gtk.org title="<i>Our</i> website\">" 211 * "GTK+ website</a> for more..."; 212 * gtk_label_set_markup (label, text); 213 * ]| 214 * 215 * It is possible to implement custom handling for links and their tooltips with 216 * the #GtkLabel::activate-link signal and the gtk_label_get_current_uri() function. 217 */ 218 public class Label : Misc 219 { 220 /** the main Gtk struct */ 221 protected GtkLabel* gtkLabel; 222 223 /** Get the main Gtk struct */ 224 public GtkLabel* getLabelStruct() 225 { 226 return gtkLabel; 227 } 228 229 /** the main Gtk struct as a void* */ 230 protected override void* getStruct() 231 { 232 return cast(void*)gtkLabel; 233 } 234 235 protected override void setStruct(GObject* obj) 236 { 237 gtkLabel = cast(GtkLabel*)obj; 238 super.setStruct(obj); 239 } 240 241 /** 242 * Sets our main struct and passes it to the parent class. 243 */ 244 public this (GtkLabel* gtkLabel, bool ownedRef = false) 245 { 246 this.gtkLabel = gtkLabel; 247 super(cast(GtkMisc*)gtkLabel, ownedRef); 248 } 249 250 /** 251 * Creates a new GtkLabel, containing the text in str. 252 * If characters in str are preceded by an underscore, they are 253 * underlined. If you need a literal underscore character in a label, use 254 * '__' (two underscores). The first underlined character represents a 255 * keyboard accelerator called a mnemonic. The mnemonic key can be used 256 * to activate another widget, chosen automatically, or explicitly using 257 * setMnemonicWidget(). 258 * 259 * If setMnemonicWidget() is not called, then the first activatable ancestor of the Label 260 * will be chosen as the mnemonic widget. For instance, if the 261 * label is inside a button or menu item, the button or menu item will 262 * automatically become the mnemonic widget and be activated by 263 * the mnemonic. 264 * Params: 265 * str = The text of the label, with an underscore in front of the 266 * mnemonic character 267 * mnemonic = when false uses the literal text passed in without mnemonic 268 * Throws: ConstructionException GTK+ fails to create the object. 269 */ 270 public this (string str, bool mnemonic=true) 271 { 272 GtkLabel* p; 273 274 if ( mnemonic ) 275 { 276 // GtkWidget* gtk_label_new_with_mnemonic (const gchar *str); 277 p = cast(GtkLabel*)gtk_label_new_with_mnemonic(Str.toStringz(str)); 278 } 279 else 280 { 281 // GtkWidget* gtk_label_new (const gchar *str); 282 p = cast(GtkLabel*)gtk_label_new(Str.toStringz(str)); 283 } 284 285 if(p is null) 286 { 287 throw new ConstructionException("null returned by gtk_label_new"); 288 } 289 290 this(p); 291 } 292 293 /** 294 */ 295 296 /** */ 297 public static GType getType() 298 { 299 return gtk_label_get_type(); 300 } 301 302 /** 303 * Gets the angle of rotation for the label. See 304 * gtk_label_set_angle(). 305 * 306 * Return: the angle of rotation for the label 307 * 308 * Since: 2.6 309 */ 310 public double getAngle() 311 { 312 return gtk_label_get_angle(gtkLabel); 313 } 314 315 /** 316 * Gets the attribute list that was set on the label using 317 * gtk_label_set_attributes(), if any. This function does 318 * not reflect attributes that come from the labels markup 319 * (see gtk_label_set_markup()). If you want to get the 320 * effective attributes for the label, use 321 * pango_layout_get_attribute (gtk_label_get_layout (label)). 322 * 323 * Return: the attribute list, or %NULL 324 * if none was set. 325 */ 326 public PgAttributeList getAttributes() 327 { 328 auto p = gtk_label_get_attributes(gtkLabel); 329 330 if(p is null) 331 { 332 return null; 333 } 334 335 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) p); 336 } 337 338 /** 339 * Returns the URI for the currently active link in the label. 340 * The active link is the one under the mouse pointer or, in a 341 * selectable label, the link in which the text cursor is currently 342 * positioned. 343 * 344 * This function is intended for use in a #GtkLabel::activate-link handler 345 * or for use in a #GtkWidget::query-tooltip handler. 346 * 347 * Return: the currently active URI. The string is owned by GTK+ and must 348 * not be freed or modified. 349 * 350 * Since: 2.18 351 */ 352 public string getCurrentUri() 353 { 354 return Str.toString(gtk_label_get_current_uri(gtkLabel)); 355 } 356 357 /** 358 * Returns the ellipsizing position of the label. See gtk_label_set_ellipsize(). 359 * 360 * Return: #PangoEllipsizeMode 361 * 362 * Since: 2.6 363 */ 364 public PangoEllipsizeMode getEllipsize() 365 { 366 return gtk_label_get_ellipsize(gtkLabel); 367 } 368 369 /** 370 * Returns the justification of the label. See gtk_label_set_justify(). 371 * 372 * Return: #GtkJustification 373 */ 374 public GtkJustification getJustify() 375 { 376 return gtk_label_get_justify(gtkLabel); 377 } 378 379 /** 380 * Fetches the text from a label widget including any embedded 381 * underlines indicating mnemonics and Pango markup. (See 382 * gtk_label_get_text()). 383 * 384 * Return: the text of the label widget. This string is 385 * owned by the widget and must not be modified or freed. 386 */ 387 public string getLabel() 388 { 389 return Str.toString(gtk_label_get_label(gtkLabel)); 390 } 391 392 /** 393 * Gets the #PangoLayout used to display the label. 394 * The layout is useful to e.g. convert text positions to 395 * pixel positions, in combination with gtk_label_get_layout_offsets(). 396 * The returned layout is owned by the @label so need not be 397 * freed by the caller. The @label is free to recreate its layout at 398 * any time, so it should be considered read-only. 399 * 400 * Return: the #PangoLayout for this label 401 */ 402 public PgLayout getLayout() 403 { 404 auto p = gtk_label_get_layout(gtkLabel); 405 406 if(p is null) 407 { 408 return null; 409 } 410 411 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p); 412 } 413 414 /** 415 * Obtains the coordinates where the label will draw the #PangoLayout 416 * representing the text in the label; useful to convert mouse events 417 * into coordinates inside the #PangoLayout, e.g. to take some action 418 * if some part of the label is clicked. Of course you will need to 419 * create a #GtkEventBox to receive the events, and pack the label 420 * inside it, since labels are windowless (they return %FALSE from 421 * gtk_widget_get_has_window()). Remember 422 * when using the #PangoLayout functions you need to convert to 423 * and from pixels using PANGO_PIXELS() or #PANGO_SCALE. 424 * 425 * Params: 426 * x = location to store X offset of layout, or %NULL 427 * y = location to store Y offset of layout, or %NULL 428 */ 429 public void getLayoutOffsets(out int x, out int y) 430 { 431 gtk_label_get_layout_offsets(gtkLabel, &x, &y); 432 } 433 434 /** 435 * Returns whether lines in the label are automatically wrapped. 436 * See gtk_label_set_line_wrap(). 437 * 438 * Return: %TRUE if the lines of the label are automatically wrapped. 439 */ 440 public bool getLineWrap() 441 { 442 return gtk_label_get_line_wrap(gtkLabel) != 0; 443 } 444 445 /** 446 * Returns line wrap mode used by the label. See gtk_label_set_line_wrap_mode(). 447 * 448 * Return: %TRUE if the lines of the label are automatically wrapped. 449 * 450 * Since: 2.10 451 */ 452 public PangoWrapMode getLineWrapMode() 453 { 454 return gtk_label_get_line_wrap_mode(gtkLabel); 455 } 456 457 /** 458 * Gets the number of lines to which an ellipsized, wrapping 459 * label should be limited. See gtk_label_set_lines(). 460 * 461 * Return: The number of lines 462 * 463 * Since: 3.10 464 */ 465 public int getLines() 466 { 467 return gtk_label_get_lines(gtkLabel); 468 } 469 470 /** 471 * Retrieves the desired maximum width of @label, in characters. See 472 * gtk_label_set_width_chars(). 473 * 474 * Return: the maximum width of the label in characters. 475 * 476 * Since: 2.6 477 */ 478 public int getMaxWidthChars() 479 { 480 return gtk_label_get_max_width_chars(gtkLabel); 481 } 482 483 /** 484 * If the label has been set so that it has an mnemonic key this function 485 * returns the keyval used for the mnemonic accelerator. If there is no 486 * mnemonic set up it returns #GDK_KEY_VoidSymbol. 487 * 488 * Return: GDK keyval usable for accelerators, or #GDK_KEY_VoidSymbol 489 */ 490 public uint getMnemonicKeyval() 491 { 492 return gtk_label_get_mnemonic_keyval(gtkLabel); 493 } 494 495 /** 496 * Retrieves the target of the mnemonic (keyboard shortcut) of this 497 * label. See gtk_label_set_mnemonic_widget(). 498 * 499 * Return: the target of the label’s mnemonic, 500 * or %NULL if none has been set and the default algorithm will be used. 501 */ 502 public Widget getMnemonicWidget() 503 { 504 auto p = gtk_label_get_mnemonic_widget(gtkLabel); 505 506 if(p is null) 507 { 508 return null; 509 } 510 511 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 512 } 513 514 /** 515 * Gets the value set by gtk_label_set_selectable(). 516 * 517 * Return: %TRUE if the user can copy text from the label 518 */ 519 public bool getSelectable() 520 { 521 return gtk_label_get_selectable(gtkLabel) != 0; 522 } 523 524 /** 525 * Gets the selected range of characters in the label, returning %TRUE 526 * if there’s a selection. 527 * 528 * Params: 529 * start = return location for start of selection, as a character offset 530 * end = return location for end of selection, as a character offset 531 * 532 * Return: %TRUE if selection is non-empty 533 */ 534 public bool getSelectionBounds(out int start, out int end) 535 { 536 return gtk_label_get_selection_bounds(gtkLabel, &start, &end) != 0; 537 } 538 539 /** 540 * Returns whether the label is in single line mode. 541 * 542 * Return: %TRUE when the label is in single line mode. 543 * 544 * Since: 2.6 545 */ 546 public bool getSingleLineMode() 547 { 548 return gtk_label_get_single_line_mode(gtkLabel) != 0; 549 } 550 551 /** 552 * Fetches the text from a label widget, as displayed on the 553 * screen. This does not include any embedded underlines 554 * indicating mnemonics or Pango markup. (See gtk_label_get_label()) 555 * 556 * Return: the text in the label widget. This is the internal 557 * string used by the label, and must not be modified. 558 */ 559 public string getText() 560 { 561 return Str.toString(gtk_label_get_text(gtkLabel)); 562 } 563 564 /** 565 * Returns whether the label is currently keeping track 566 * of clicked links. 567 * 568 * Return: %TRUE if clicked links are remembered 569 * 570 * Since: 2.18 571 */ 572 public bool getTrackVisitedLinks() 573 { 574 return gtk_label_get_track_visited_links(gtkLabel) != 0; 575 } 576 577 /** 578 * Returns whether the label’s text is interpreted as marked up with 579 * the [Pango text markup language][PangoMarkupFormat]. 580 * See gtk_label_set_use_markup (). 581 * 582 * Return: %TRUE if the label’s text will be parsed for markup. 583 */ 584 public bool getUseMarkup() 585 { 586 return gtk_label_get_use_markup(gtkLabel) != 0; 587 } 588 589 /** 590 * Returns whether an embedded underline in the label indicates a 591 * mnemonic. See gtk_label_set_use_underline(). 592 * 593 * Return: %TRUE whether an embedded underline in the label indicates 594 * the mnemonic accelerator keys. 595 */ 596 public bool getUseUnderline() 597 { 598 return gtk_label_get_use_underline(gtkLabel) != 0; 599 } 600 601 /** 602 * Retrieves the desired width of @label, in characters. See 603 * gtk_label_set_width_chars(). 604 * 605 * Return: the width of the label in characters. 606 * 607 * Since: 2.6 608 */ 609 public int getWidthChars() 610 { 611 return gtk_label_get_width_chars(gtkLabel); 612 } 613 614 /** 615 * Gets the #GtkLabel:xalign property for @label. 616 * 617 * Return: the xalign property 618 * 619 * Since: 3.16 620 */ 621 public float getXalign() 622 { 623 return gtk_label_get_xalign(gtkLabel); 624 } 625 626 /** 627 * Gets the #GtkLabel:yalign property for @label. 628 * 629 * Return: the yalign property 630 * 631 * Since: 3.16 632 */ 633 public float getYalign() 634 { 635 return gtk_label_get_yalign(gtkLabel); 636 } 637 638 /** 639 * Selects a range of characters in the label, if the label is selectable. 640 * See gtk_label_set_selectable(). If the label is not selectable, 641 * this function has no effect. If @start_offset or 642 * @end_offset are -1, then the end of the label will be substituted. 643 * 644 * Params: 645 * startOffset = start offset (in characters not bytes) 646 * endOffset = end offset (in characters not bytes) 647 */ 648 public void selectRegion(int startOffset, int endOffset) 649 { 650 gtk_label_select_region(gtkLabel, startOffset, endOffset); 651 } 652 653 /** 654 * Sets the angle of rotation for the label. An angle of 90 reads from 655 * from bottom to top, an angle of 270, from top to bottom. The angle 656 * setting for the label is ignored if the label is selectable, 657 * wrapped, or ellipsized. 658 * 659 * Params: 660 * angle = the angle that the baseline of the label makes with 661 * the horizontal, in degrees, measured counterclockwise 662 * 663 * Since: 2.6 664 */ 665 public void setAngle(double angle) 666 { 667 gtk_label_set_angle(gtkLabel, angle); 668 } 669 670 /** 671 * Sets a #PangoAttrList; the attributes in the list are applied to the 672 * label text. 673 * 674 * The attributes set with this function will be applied 675 * and merged with any other attributes previously effected by way 676 * of the #GtkLabel:use-underline or #GtkLabel:use-markup properties. 677 * While it is not recommended to mix markup strings with manually set 678 * attributes, if you must; know that the attributes will be applied 679 * to the label after the markup string is parsed. 680 * 681 * Params: 682 * attrs = a #PangoAttrList, or %NULL 683 */ 684 public void setAttributes(PgAttributeList attrs) 685 { 686 gtk_label_set_attributes(gtkLabel, (attrs is null) ? null : attrs.getPgAttributeListStruct()); 687 } 688 689 /** 690 * Sets the mode used to ellipsize (add an ellipsis: "...") to the text 691 * if there is not enough space to render the entire string. 692 * 693 * Params: 694 * mode = a #PangoEllipsizeMode 695 * 696 * Since: 2.6 697 */ 698 public void setEllipsize(PangoEllipsizeMode mode) 699 { 700 gtk_label_set_ellipsize(gtkLabel, mode); 701 } 702 703 /** 704 * Sets the alignment of the lines in the text of the label relative to 705 * each other. %GTK_JUSTIFY_LEFT is the default value when the widget is 706 * first created with gtk_label_new(). If you instead want to set the 707 * alignment of the label as a whole, use gtk_widget_set_halign() instead. 708 * gtk_label_set_justify() has no effect on labels containing only a 709 * single line. 710 * 711 * Params: 712 * jtype = a #GtkJustification 713 */ 714 public void setJustify(GtkJustification jtype) 715 { 716 gtk_label_set_justify(gtkLabel, jtype); 717 } 718 719 /** 720 * Sets the text of the label. The label is interpreted as 721 * including embedded underlines and/or Pango markup depending 722 * on the values of the #GtkLabel:use-underline and 723 * #GtkLabel:use-markup properties. 724 * 725 * Params: 726 * str = the new text to set for the label 727 */ 728 public void setLabel(string str) 729 { 730 gtk_label_set_label(gtkLabel, Str.toStringz(str)); 731 } 732 733 /** 734 * Toggles line wrapping within the #GtkLabel widget. %TRUE makes it break 735 * lines if text exceeds the widget’s size. %FALSE lets the text get cut off 736 * by the edge of the widget if it exceeds the widget size. 737 * 738 * Note that setting line wrapping to %TRUE does not make the label 739 * wrap at its parent container’s width, because GTK+ widgets 740 * conceptually can’t make their requisition depend on the parent 741 * container’s size. For a label that wraps at a specific position, 742 * set the label’s width using gtk_widget_set_size_request(). 743 * 744 * Params: 745 * wrap = the setting 746 */ 747 public void setLineWrap(bool wrap) 748 { 749 gtk_label_set_line_wrap(gtkLabel, wrap); 750 } 751 752 /** 753 * If line wrapping is on (see gtk_label_set_line_wrap()) this controls how 754 * the line wrapping is done. The default is %PANGO_WRAP_WORD which means 755 * wrap on word boundaries. 756 * 757 * Params: 758 * wrapMode = the line wrapping mode 759 * 760 * Since: 2.10 761 */ 762 public void setLineWrapMode(PangoWrapMode wrapMode) 763 { 764 gtk_label_set_line_wrap_mode(gtkLabel, wrapMode); 765 } 766 767 /** 768 * Sets the number of lines to which an ellipsized, wrapping label 769 * should be limited. This has no effect if the label is not wrapping 770 * or ellipsized. Set this to -1 if you don’t want to limit the 771 * number of lines. 772 * 773 * Params: 774 * lines = the desired number of lines, or -1 775 * 776 * Since: 3.10 777 */ 778 public void setLines(int lines) 779 { 780 gtk_label_set_lines(gtkLabel, lines); 781 } 782 783 /** 784 * Parses @str which is marked up with the 785 * [Pango text markup language][PangoMarkupFormat], setting the 786 * label’s text and attribute list based on the parse results. 787 * 788 * If the @str is external data, you may need to escape it with 789 * g_markup_escape_text() or g_markup_printf_escaped(): 790 * 791 * |[<!-- language="C" --> 792 * const char *format = "<span style=\"italic\">\%s</span>"; 793 * char *markup; 794 * 795 * markup = g_markup_printf_escaped (format, str); 796 * gtk_label_set_markup (GTK_LABEL (label), markup); 797 * g_free (markup); 798 * ]| 799 * 800 * This function will set the #GtkLabel:use-markup property to %TRUE as 801 * a side effect. 802 * 803 * If you set the label contents using the #GtkLabel:label property you 804 * should also ensure that you set the #GtkLabel:use-markup property 805 * accordingly. 806 * 807 * See also: gtk_label_set_text() 808 * 809 * Params: 810 * str = a markup string (see [Pango markup format][PangoMarkupFormat]) 811 */ 812 public void setMarkup(string str) 813 { 814 gtk_label_set_markup(gtkLabel, Str.toStringz(str)); 815 } 816 817 /** 818 * Parses @str which is marked up with the 819 * [Pango text markup language][PangoMarkupFormat], 820 * setting the label’s text and attribute list based on the parse results. 821 * If characters in @str are preceded by an underscore, they are underlined 822 * indicating that they represent a keyboard accelerator called a mnemonic. 823 * 824 * The mnemonic key can be used to activate another widget, chosen 825 * automatically, or explicitly using gtk_label_set_mnemonic_widget(). 826 * 827 * Params: 828 * str = a markup string (see 829 * [Pango markup format][PangoMarkupFormat]) 830 */ 831 public void setMarkupWithMnemonic(string str) 832 { 833 gtk_label_set_markup_with_mnemonic(gtkLabel, Str.toStringz(str)); 834 } 835 836 /** 837 * Sets the desired maximum width in characters of @label to @n_chars. 838 * 839 * Params: 840 * nChars = the new desired maximum width, in characters. 841 * 842 * Since: 2.6 843 */ 844 public void setMaxWidthChars(int nChars) 845 { 846 gtk_label_set_max_width_chars(gtkLabel, nChars); 847 } 848 849 /** 850 * If the label has been set so that it has an mnemonic key (using 851 * i.e. gtk_label_set_markup_with_mnemonic(), 852 * gtk_label_set_text_with_mnemonic(), gtk_label_new_with_mnemonic() 853 * or the “use_underline” property) the label can be associated with a 854 * widget that is the target of the mnemonic. When the label is inside 855 * a widget (like a #GtkButton or a #GtkNotebook tab) it is 856 * automatically associated with the correct widget, but sometimes 857 * (i.e. when the target is a #GtkEntry next to the label) you need to 858 * set it explicitly using this function. 859 * 860 * The target widget will be accelerated by emitting the 861 * GtkWidget::mnemonic-activate signal on it. The default handler for 862 * this signal will activate the widget if there are no mnemonic collisions 863 * and toggle focus between the colliding widgets otherwise. 864 * 865 * Params: 866 * widget = the target #GtkWidget 867 */ 868 public void setMnemonicWidget(Widget widget) 869 { 870 gtk_label_set_mnemonic_widget(gtkLabel, (widget is null) ? null : widget.getWidgetStruct()); 871 } 872 873 /** 874 * The pattern of underlines you want under the existing text within the 875 * #GtkLabel widget. For example if the current text of the label says 876 * “FooBarBaz” passing a pattern of “___ ___” will underline 877 * “Foo” and “Baz” but not “Bar”. 878 * 879 * Params: 880 * pattern = The pattern as described above. 881 */ 882 public void setPattern(string pattern) 883 { 884 gtk_label_set_pattern(gtkLabel, Str.toStringz(pattern)); 885 } 886 887 /** 888 * Selectable labels allow the user to select text from the label, for 889 * copy-and-paste. 890 * 891 * Params: 892 * setting = %TRUE to allow selecting text in the label 893 */ 894 public void setSelectable(bool setting) 895 { 896 gtk_label_set_selectable(gtkLabel, setting); 897 } 898 899 /** 900 * Sets whether the label is in single line mode. 901 * 902 * Params: 903 * singleLineMode = %TRUE if the label should be in single line mode 904 * 905 * Since: 2.6 906 */ 907 public void setSingleLineMode(bool singleLineMode) 908 { 909 gtk_label_set_single_line_mode(gtkLabel, singleLineMode); 910 } 911 912 /** 913 * Sets the text within the #GtkLabel widget. It overwrites any text that 914 * was there before. 915 * 916 * This function will clear any previously set mnemonic accelerators, and 917 * set the #GtkLabel:use-underline property to %FALSE as a side effect. 918 * 919 * This function will set the #GtkLabel:use-markup property to %FALSE 920 * as a side effect. 921 * 922 * See also: gtk_label_set_markup() 923 * 924 * Params: 925 * str = The text you want to set 926 */ 927 public void setText(string str) 928 { 929 gtk_label_set_text(gtkLabel, Str.toStringz(str)); 930 } 931 932 /** 933 * Sets the label’s text from the string @str. 934 * If characters in @str are preceded by an underscore, they are underlined 935 * indicating that they represent a keyboard accelerator called a mnemonic. 936 * The mnemonic key can be used to activate another widget, chosen 937 * automatically, or explicitly using gtk_label_set_mnemonic_widget(). 938 * 939 * Params: 940 * str = a string 941 */ 942 public void setTextWithMnemonic(string str) 943 { 944 gtk_label_set_text_with_mnemonic(gtkLabel, Str.toStringz(str)); 945 } 946 947 /** 948 * Sets whether the label should keep track of clicked 949 * links (and use a different color for them). 950 * 951 * Params: 952 * trackLinks = %TRUE to track visited links 953 * 954 * Since: 2.18 955 */ 956 public void setTrackVisitedLinks(bool trackLinks) 957 { 958 gtk_label_set_track_visited_links(gtkLabel, trackLinks); 959 } 960 961 /** 962 * Sets whether the text of the label contains markup in 963 * [Pango’s text markup language][PangoMarkupFormat]. 964 * See gtk_label_set_markup(). 965 * 966 * Params: 967 * setting = %TRUE if the label’s text should be parsed for markup. 968 */ 969 public void setUseMarkup(bool setting) 970 { 971 gtk_label_set_use_markup(gtkLabel, setting); 972 } 973 974 /** 975 * If true, an underline in the text indicates the next character should be 976 * used for the mnemonic accelerator key. 977 * 978 * Params: 979 * setting = %TRUE if underlines in the text indicate mnemonics 980 */ 981 public void setUseUnderline(bool setting) 982 { 983 gtk_label_set_use_underline(gtkLabel, setting); 984 } 985 986 /** 987 * Sets the desired width in characters of @label to @n_chars. 988 * 989 * Params: 990 * nChars = the new desired width, in characters. 991 * 992 * Since: 2.6 993 */ 994 public void setWidthChars(int nChars) 995 { 996 gtk_label_set_width_chars(gtkLabel, nChars); 997 } 998 999 /** 1000 * Sets the #GtkLabel:xalign property for @label. 1001 * 1002 * Params: 1003 * xalign = the new xalign value, between 0 and 1 1004 * 1005 * Since: 3.16 1006 */ 1007 public void setXalign(float xalign) 1008 { 1009 gtk_label_set_xalign(gtkLabel, xalign); 1010 } 1011 1012 /** 1013 * Sets the #GtkLabel:yalign property for @label. 1014 * 1015 * Params: 1016 * yalign = the new yalign value, between 0 and 1 1017 * 1018 * Since: 3.16 1019 */ 1020 public void setYalign(float yalign) 1021 { 1022 gtk_label_set_yalign(gtkLabel, yalign); 1023 } 1024 1025 int[string] connectedSignals; 1026 1027 void delegate(Label)[] onActivateCurrentLinkListeners; 1028 /** 1029 * A [keybinding signal][GtkBindingSignal] 1030 * which gets emitted when the user activates a link in the label. 1031 * 1032 * Applications may also emit the signal with g_signal_emit_by_name() 1033 * if they need to control activation of URIs programmatically. 1034 * 1035 * The default bindings for this signal are all forms of the Enter key. 1036 * 1037 * Since: 2.18 1038 */ 1039 void addOnActivateCurrentLink(void delegate(Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1040 { 1041 if ( "activate-current-link" !in connectedSignals ) 1042 { 1043 Signals.connectData( 1044 this, 1045 "activate-current-link", 1046 cast(GCallback)&callBackActivateCurrentLink, 1047 cast(void*)this, 1048 null, 1049 connectFlags); 1050 connectedSignals["activate-current-link"] = 1; 1051 } 1052 onActivateCurrentLinkListeners ~= dlg; 1053 } 1054 extern(C) static void callBackActivateCurrentLink(GtkLabel* labelStruct, Label _label) 1055 { 1056 foreach ( void delegate(Label) dlg; _label.onActivateCurrentLinkListeners ) 1057 { 1058 dlg(_label); 1059 } 1060 } 1061 1062 bool delegate(string, Label)[] onActivateLinkListeners; 1063 /** 1064 * The signal which gets emitted to activate a URI. 1065 * Applications may connect to it to override the default behaviour, 1066 * which is to call gtk_show_uri(). 1067 * 1068 * Params: 1069 * uri = the URI that is activated 1070 * 1071 * Return: %TRUE if the link has been activated 1072 * 1073 * Since: 2.18 1074 */ 1075 void addOnActivateLink(bool delegate(string, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1076 { 1077 if ( "activate-link" !in connectedSignals ) 1078 { 1079 Signals.connectData( 1080 this, 1081 "activate-link", 1082 cast(GCallback)&callBackActivateLink, 1083 cast(void*)this, 1084 null, 1085 connectFlags); 1086 connectedSignals["activate-link"] = 1; 1087 } 1088 onActivateLinkListeners ~= dlg; 1089 } 1090 extern(C) static int callBackActivateLink(GtkLabel* labelStruct, char* uri, Label _label) 1091 { 1092 foreach ( bool delegate(string, Label) dlg; _label.onActivateLinkListeners ) 1093 { 1094 if ( dlg(Str.toString(uri), _label) ) 1095 { 1096 return 1; 1097 } 1098 } 1099 1100 return 0; 1101 } 1102 1103 void delegate(Label)[] onCopyClipboardListeners; 1104 /** 1105 * The ::copy-clipboard signal is a 1106 * [keybinding signal][GtkBindingSignal] 1107 * which gets emitted to copy the selection to the clipboard. 1108 * 1109 * The default binding for this signal is Ctrl-c. 1110 */ 1111 void addOnCopyClipboard(void delegate(Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1112 { 1113 if ( "copy-clipboard" !in connectedSignals ) 1114 { 1115 Signals.connectData( 1116 this, 1117 "copy-clipboard", 1118 cast(GCallback)&callBackCopyClipboard, 1119 cast(void*)this, 1120 null, 1121 connectFlags); 1122 connectedSignals["copy-clipboard"] = 1; 1123 } 1124 onCopyClipboardListeners ~= dlg; 1125 } 1126 extern(C) static void callBackCopyClipboard(GtkLabel* labelStruct, Label _label) 1127 { 1128 foreach ( void delegate(Label) dlg; _label.onCopyClipboardListeners ) 1129 { 1130 dlg(_label); 1131 } 1132 } 1133 1134 void delegate(GtkMovementStep, int, bool, Label)[] onMoveCursorListeners; 1135 /** 1136 * The ::move-cursor signal is a 1137 * [keybinding signal][GtkBindingSignal] 1138 * which gets emitted when the user initiates a cursor movement. 1139 * If the cursor is not visible in @entry, this signal causes 1140 * the viewport to be moved instead. 1141 * 1142 * Applications should not connect to it, but may emit it with 1143 * g_signal_emit_by_name() if they need to control the cursor 1144 * programmatically. 1145 * 1146 * The default bindings for this signal come in two variants, 1147 * the variant with the Shift modifier extends the selection, 1148 * the variant without the Shift modifer does not. 1149 * There are too many key combinations to list them all here. 1150 * - Arrow keys move by individual characters/lines 1151 * - Ctrl-arrow key combinations move by words/paragraphs 1152 * - Home/End keys move to the ends of the buffer 1153 * 1154 * Params: 1155 * step = the granularity of the move, as a #GtkMovementStep 1156 * count = the number of @step units to move 1157 * extendSelection = %TRUE if the move should extend the selection 1158 */ 1159 void addOnMoveCursor(void delegate(GtkMovementStep, int, bool, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1160 { 1161 if ( "move-cursor" !in connectedSignals ) 1162 { 1163 Signals.connectData( 1164 this, 1165 "move-cursor", 1166 cast(GCallback)&callBackMoveCursor, 1167 cast(void*)this, 1168 null, 1169 connectFlags); 1170 connectedSignals["move-cursor"] = 1; 1171 } 1172 onMoveCursorListeners ~= dlg; 1173 } 1174 extern(C) static void callBackMoveCursor(GtkLabel* labelStruct, GtkMovementStep step, int count, bool extendSelection, Label _label) 1175 { 1176 foreach ( void delegate(GtkMovementStep, int, bool, Label) dlg; _label.onMoveCursorListeners ) 1177 { 1178 dlg(step, count, extendSelection, _label); 1179 } 1180 } 1181 1182 void delegate(Menu, Label)[] onPopulatePopupListeners; 1183 /** 1184 * The ::populate-popup signal gets emitted before showing the 1185 * context menu of the label. Note that only selectable labels 1186 * have context menus. 1187 * 1188 * If you need to add items to the context menu, connect 1189 * to this signal and append your menuitems to the @menu. 1190 * 1191 * Params: 1192 * menu = the menu that is being populated 1193 */ 1194 void addOnPopulatePopup(void delegate(Menu, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1195 { 1196 if ( "populate-popup" !in connectedSignals ) 1197 { 1198 Signals.connectData( 1199 this, 1200 "populate-popup", 1201 cast(GCallback)&callBackPopulatePopup, 1202 cast(void*)this, 1203 null, 1204 connectFlags); 1205 connectedSignals["populate-popup"] = 1; 1206 } 1207 onPopulatePopupListeners ~= dlg; 1208 } 1209 extern(C) static void callBackPopulatePopup(GtkLabel* labelStruct, GtkMenu* menu, Label _label) 1210 { 1211 foreach ( void delegate(Menu, Label) dlg; _label.onPopulatePopupListeners ) 1212 { 1213 dlg(ObjectG.getDObject!(Menu)(menu), _label); 1214 } 1215 } 1216 }