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