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. If the @str is 765 * external data, you may need to escape it with g_markup_escape_text() or 766 * g_markup_printf_escaped(): 767 * |[<!-- language="C" --> 768 * const char *format = "<span style=\"italic\">\%s</span>"; 769 * char *markup; 770 * 771 * markup = g_markup_printf_escaped (format, str); 772 * gtk_label_set_markup (GTK_LABEL (label), markup); 773 * g_free (markup); 774 * ]| 775 * 776 * Params: 777 * str = a markup string (see [Pango markup format][PangoMarkupFormat]) 778 */ 779 public void setMarkup(string str) 780 { 781 gtk_label_set_markup(gtkLabel, Str.toStringz(str)); 782 } 783 784 /** 785 * Parses @str which is marked up with the 786 * [Pango text markup language][PangoMarkupFormat], 787 * setting the label’s text and attribute list based on the parse results. 788 * If characters in @str are preceded by an underscore, they are underlined 789 * indicating that they represent a keyboard accelerator called a mnemonic. 790 * 791 * The mnemonic key can be used to activate another widget, chosen 792 * automatically, or explicitly using gtk_label_set_mnemonic_widget(). 793 * 794 * Params: 795 * str = a markup string (see 796 * [Pango markup format][PangoMarkupFormat]) 797 */ 798 public void setMarkupWithMnemonic(string str) 799 { 800 gtk_label_set_markup_with_mnemonic(gtkLabel, Str.toStringz(str)); 801 } 802 803 /** 804 * Sets the desired maximum width in characters of @label to @n_chars. 805 * 806 * Params: 807 * nChars = the new desired maximum width, in characters. 808 * 809 * Since: 2.6 810 */ 811 public void setMaxWidthChars(int nChars) 812 { 813 gtk_label_set_max_width_chars(gtkLabel, nChars); 814 } 815 816 /** 817 * If the label has been set so that it has an mnemonic key (using 818 * i.e. gtk_label_set_markup_with_mnemonic(), 819 * gtk_label_set_text_with_mnemonic(), gtk_label_new_with_mnemonic() 820 * or the “use_underline” property) the label can be associated with a 821 * widget that is the target of the mnemonic. When the label is inside 822 * a widget (like a #GtkButton or a #GtkNotebook tab) it is 823 * automatically associated with the correct widget, but sometimes 824 * (i.e. when the target is a #GtkEntry next to the label) you need to 825 * set it explicitly using this function. 826 * 827 * The target widget will be accelerated by emitting the 828 * GtkWidget::mnemonic-activate signal on it. The default handler for 829 * this signal will activate the widget if there are no mnemonic collisions 830 * and toggle focus between the colliding widgets otherwise. 831 * 832 * Params: 833 * widget = the target #GtkWidget 834 */ 835 public void setMnemonicWidget(Widget widget) 836 { 837 gtk_label_set_mnemonic_widget(gtkLabel, (widget is null) ? null : widget.getWidgetStruct()); 838 } 839 840 /** 841 * The pattern of underlines you want under the existing text within the 842 * #GtkLabel widget. For example if the current text of the label says 843 * “FooBarBaz” passing a pattern of “___ ___” will underline 844 * “Foo” and “Baz” but not “Bar”. 845 * 846 * Params: 847 * pattern = The pattern as described above. 848 */ 849 public void setPattern(string pattern) 850 { 851 gtk_label_set_pattern(gtkLabel, Str.toStringz(pattern)); 852 } 853 854 /** 855 * Selectable labels allow the user to select text from the label, for 856 * copy-and-paste. 857 * 858 * Params: 859 * setting = %TRUE to allow selecting text in the label 860 */ 861 public void setSelectable(bool setting) 862 { 863 gtk_label_set_selectable(gtkLabel, setting); 864 } 865 866 /** 867 * Sets whether the label is in single line mode. 868 * 869 * Params: 870 * singleLineMode = %TRUE if the label should be in single line mode 871 * 872 * Since: 2.6 873 */ 874 public void setSingleLineMode(bool singleLineMode) 875 { 876 gtk_label_set_single_line_mode(gtkLabel, singleLineMode); 877 } 878 879 /** 880 * Sets the text within the #GtkLabel widget. It overwrites any text that 881 * was there before. 882 * 883 * This will also clear any previously set mnemonic accelerators. 884 * 885 * Params: 886 * str = The text you want to set 887 */ 888 public void setText(string str) 889 { 890 gtk_label_set_text(gtkLabel, Str.toStringz(str)); 891 } 892 893 /** 894 * Sets the label’s text from the string @str. 895 * If characters in @str are preceded by an underscore, they are underlined 896 * indicating that they represent a keyboard accelerator called a mnemonic. 897 * The mnemonic key can be used to activate another widget, chosen 898 * automatically, or explicitly using gtk_label_set_mnemonic_widget(). 899 * 900 * Params: 901 * str = a string 902 */ 903 public void setTextWithMnemonic(string str) 904 { 905 gtk_label_set_text_with_mnemonic(gtkLabel, Str.toStringz(str)); 906 } 907 908 /** 909 * Sets whether the label should keep track of clicked 910 * links (and use a different color for them). 911 * 912 * Params: 913 * trackLinks = %TRUE to track visited links 914 * 915 * Since: 2.18 916 */ 917 public void setTrackVisitedLinks(bool trackLinks) 918 { 919 gtk_label_set_track_visited_links(gtkLabel, trackLinks); 920 } 921 922 /** 923 * Sets whether the text of the label contains markup in 924 * [Pango’s text markup language][PangoMarkupFormat]. 925 * See gtk_label_set_markup(). 926 * 927 * Params: 928 * setting = %TRUE if the label’s text should be parsed for markup. 929 */ 930 public void setUseMarkup(bool setting) 931 { 932 gtk_label_set_use_markup(gtkLabel, setting); 933 } 934 935 /** 936 * If true, an underline in the text indicates the next character should be 937 * used for the mnemonic accelerator key. 938 * 939 * Params: 940 * setting = %TRUE if underlines in the text indicate mnemonics 941 */ 942 public void setUseUnderline(bool setting) 943 { 944 gtk_label_set_use_underline(gtkLabel, setting); 945 } 946 947 /** 948 * Sets the desired width in characters of @label to @n_chars. 949 * 950 * Params: 951 * nChars = the new desired width, in characters. 952 * 953 * Since: 2.6 954 */ 955 public void setWidthChars(int nChars) 956 { 957 gtk_label_set_width_chars(gtkLabel, nChars); 958 } 959 960 /** 961 * Sets the #GtkLabel:xalign property for @label. 962 * 963 * Params: 964 * xalign = the new xalign value, between 0 and 1 965 * 966 * Since: 3.16 967 */ 968 public void setXalign(float xalign) 969 { 970 gtk_label_set_xalign(gtkLabel, xalign); 971 } 972 973 /** 974 * Sets the #GtkLabel:yalign property for @label. 975 * 976 * Params: 977 * yalign = the new yalign value, between 0 and 1 978 * 979 * Since: 3.16 980 */ 981 public void setYalign(float yalign) 982 { 983 gtk_label_set_yalign(gtkLabel, yalign); 984 } 985 986 int[string] connectedSignals; 987 988 void delegate(Label)[] onActivateCurrentLinkListeners; 989 /** 990 * A [keybinding signal][GtkBindingSignal] 991 * which gets emitted when the user activates a link in the label. 992 * 993 * Applications may also emit the signal with g_signal_emit_by_name() 994 * if they need to control activation of URIs programmatically. 995 * 996 * The default bindings for this signal are all forms of the Enter key. 997 * 998 * Since: 2.18 999 */ 1000 void addOnActivateCurrentLink(void delegate(Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1001 { 1002 if ( "activate-current-link" !in connectedSignals ) 1003 { 1004 Signals.connectData( 1005 this, 1006 "activate-current-link", 1007 cast(GCallback)&callBackActivateCurrentLink, 1008 cast(void*)this, 1009 null, 1010 connectFlags); 1011 connectedSignals["activate-current-link"] = 1; 1012 } 1013 onActivateCurrentLinkListeners ~= dlg; 1014 } 1015 extern(C) static void callBackActivateCurrentLink(GtkLabel* labelStruct, Label _label) 1016 { 1017 foreach ( void delegate(Label) dlg; _label.onActivateCurrentLinkListeners ) 1018 { 1019 dlg(_label); 1020 } 1021 } 1022 1023 bool delegate(string, Label)[] onActivateLinkListeners; 1024 /** 1025 * The signal which gets emitted to activate a URI. 1026 * Applications may connect to it to override the default behaviour, 1027 * which is to call gtk_show_uri(). 1028 * 1029 * Params: 1030 * uri = the URI that is activated 1031 * 1032 * Return: %TRUE if the link has been activated 1033 * 1034 * Since: 2.18 1035 */ 1036 void addOnActivateLink(bool delegate(string, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1037 { 1038 if ( "activate-link" !in connectedSignals ) 1039 { 1040 Signals.connectData( 1041 this, 1042 "activate-link", 1043 cast(GCallback)&callBackActivateLink, 1044 cast(void*)this, 1045 null, 1046 connectFlags); 1047 connectedSignals["activate-link"] = 1; 1048 } 1049 onActivateLinkListeners ~= dlg; 1050 } 1051 extern(C) static int callBackActivateLink(GtkLabel* labelStruct, char* uri, Label _label) 1052 { 1053 foreach ( bool delegate(string, Label) dlg; _label.onActivateLinkListeners ) 1054 { 1055 if ( dlg(Str.toString(uri), _label) ) 1056 { 1057 return 1; 1058 } 1059 } 1060 1061 return 0; 1062 } 1063 1064 void delegate(Label)[] onCopyClipboardListeners; 1065 /** 1066 * The ::copy-clipboard signal is a 1067 * [keybinding signal][GtkBindingSignal] 1068 * which gets emitted to copy the selection to the clipboard. 1069 * 1070 * The default binding for this signal is Ctrl-c. 1071 */ 1072 void addOnCopyClipboard(void delegate(Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1073 { 1074 if ( "copy-clipboard" !in connectedSignals ) 1075 { 1076 Signals.connectData( 1077 this, 1078 "copy-clipboard", 1079 cast(GCallback)&callBackCopyClipboard, 1080 cast(void*)this, 1081 null, 1082 connectFlags); 1083 connectedSignals["copy-clipboard"] = 1; 1084 } 1085 onCopyClipboardListeners ~= dlg; 1086 } 1087 extern(C) static void callBackCopyClipboard(GtkLabel* labelStruct, Label _label) 1088 { 1089 foreach ( void delegate(Label) dlg; _label.onCopyClipboardListeners ) 1090 { 1091 dlg(_label); 1092 } 1093 } 1094 1095 void delegate(GtkMovementStep, int, bool, Label)[] onMoveCursorListeners; 1096 /** 1097 * The ::move-cursor signal is a 1098 * [keybinding signal][GtkBindingSignal] 1099 * which gets emitted when the user initiates a cursor movement. 1100 * If the cursor is not visible in @entry, this signal causes 1101 * the viewport to be moved instead. 1102 * 1103 * Applications should not connect to it, but may emit it with 1104 * g_signal_emit_by_name() if they need to control the cursor 1105 * programmatically. 1106 * 1107 * The default bindings for this signal come in two variants, 1108 * the variant with the Shift modifier extends the selection, 1109 * the variant without the Shift modifer does not. 1110 * There are too many key combinations to list them all here. 1111 * - Arrow keys move by individual characters/lines 1112 * - Ctrl-arrow key combinations move by words/paragraphs 1113 * - Home/End keys move to the ends of the buffer 1114 * 1115 * Params: 1116 * step = the granularity of the move, as a #GtkMovementStep 1117 * count = the number of @step units to move 1118 * extendSelection = %TRUE if the move should extend the selection 1119 */ 1120 void addOnMoveCursor(void delegate(GtkMovementStep, int, bool, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1121 { 1122 if ( "move-cursor" !in connectedSignals ) 1123 { 1124 Signals.connectData( 1125 this, 1126 "move-cursor", 1127 cast(GCallback)&callBackMoveCursor, 1128 cast(void*)this, 1129 null, 1130 connectFlags); 1131 connectedSignals["move-cursor"] = 1; 1132 } 1133 onMoveCursorListeners ~= dlg; 1134 } 1135 extern(C) static void callBackMoveCursor(GtkLabel* labelStruct, GtkMovementStep step, int count, bool extendSelection, Label _label) 1136 { 1137 foreach ( void delegate(GtkMovementStep, int, bool, Label) dlg; _label.onMoveCursorListeners ) 1138 { 1139 dlg(step, count, extendSelection, _label); 1140 } 1141 } 1142 1143 void delegate(Menu, Label)[] onPopulatePopupListeners; 1144 /** 1145 * The ::populate-popup signal gets emitted before showing the 1146 * context menu of the label. Note that only selectable labels 1147 * have context menus. 1148 * 1149 * If you need to add items to the context menu, connect 1150 * to this signal and append your menuitems to the @menu. 1151 * 1152 * Params: 1153 * menu = the menu that is being populated 1154 */ 1155 void addOnPopulatePopup(void delegate(Menu, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1156 { 1157 if ( "populate-popup" !in connectedSignals ) 1158 { 1159 Signals.connectData( 1160 this, 1161 "populate-popup", 1162 cast(GCallback)&callBackPopulatePopup, 1163 cast(void*)this, 1164 null, 1165 connectFlags); 1166 connectedSignals["populate-popup"] = 1; 1167 } 1168 onPopulatePopupListeners ~= dlg; 1169 } 1170 extern(C) static void callBackPopulatePopup(GtkLabel* labelStruct, GtkMenu* menu, Label _label) 1171 { 1172 foreach ( void delegate(Menu, Label) dlg; _label.onPopulatePopupListeners ) 1173 { 1174 dlg(ObjectG.getDObject!(Menu)(menu), _label); 1175 } 1176 } 1177 }