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