1 // Copyright (c) 2005 VMware, Inc.
3 // This is a translation of http://git.gnome.org/browse/meld/tree/meld/ui/wraplabel.py,
4 // which in turn is a translation of WrapLabel from libview.
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // Python translation from wrapLabel.{cc|h} by Gian Mario Tagliaretti
25 // Vala translation from wraplabel.py by Zbigniew Jędrzejewski-Szmek
27 public class WrapLabel : Gtk.Label {
28 private int _wrap_width;
30 public WrapLabel(string? text = null) {
32 var layout = get_layout();
33 layout.set_wrap(Pango.WrapMode.WORD_CHAR);
36 this.set_alignment(0, 0);
39 public override void size_request(out Gtk.Requisition requisition) {
41 var layout = get_layout();
42 layout.get_pixel_size(out width, out height);
43 requisition.width = 0;
44 requisition.height = height;
47 public override void size_allocate(Gdk.Rectangle allocation) {
48 base.size_allocate (allocation);
49 this._set_wrap_width(allocation.width);
52 public new void set_text(string str) {
54 this._set_wrap_width(this._wrap_width);
57 public new void set_markup(string str) {
59 this._set_wrap_width(this._wrap_width);
62 private void _set_wrap_width(int width) {
66 var layout = get_layout();
67 layout.set_width(width * Pango.SCALE);
68 if (_wrap_width != width) {
69 this._wrap_width = width;