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