~ubuntu-branches/ubuntu/natty/banshee/natty-201104090814

« back to all changes in this revision

Viewing changes to src/Hyena/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-12-21 13:22:57 UTC
  • mfrom: (6.3.13 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221132257-r93dkoybpwo0ww35
Tags: 1.9.1-1ubuntu1
* Merge from Debian experimental, remaining changes:
  + Disable notification area by default
  + Disable boo and karma extensions
  + Enable and recommend u1ms and soundmenu extensions
  + Move desktop file for Meego UI to /usr/share/une/applications

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
using Cairo;
31
31
using Hyena.Gui;
 
32
using Hyena.Gui.Theming;
32
33
 
33
34
namespace Hyena.Gui.Canvas
34
35
{
48
49
 
49
50
        private bool EnsureLayout ()
50
51
        {
51
 
            if (layout != null) {
52
 
                return true;
53
 
            }
54
 
 
55
 
            Gtk.Widget widget = Manager == null ? null : Manager.Host as Gtk.Widget;
56
 
            if (widget == null || widget.GdkWindow == null || !widget.IsRealized) {
57
 
                return false;
58
 
            }
59
 
 
60
 
            using (var cr = Gdk.CairoHelper.Create (widget.GdkWindow)) {
61
 
                layout = CairoExtensions.CreateLayout (widget, cr);
62
 
                font_desc = layout.FontDescription;
63
 
            }
64
 
 
 
52
            layout = Manager.Host.PangoLayout;
 
53
            font_desc = Manager.Host.FontDescription;
65
54
            return layout != null;
66
55
        }
67
56
 
75
64
 
76
65
            int text_w, text_h;
77
66
 
78
 
            TextWrap wrap = TextWrap;
79
 
            layout.Width = wrap == TextWrap.None ? -1 : (int)(Pango.Scale.PangoScale * (available.Width - Margin.X));
80
 
            layout.Wrap = GetPangoWrapMode (wrap);
81
 
            font_desc.Weight = GetPangoFontWeight (FontWeight);
82
 
            layout.SingleParagraphMode = wrap == TextWrap.None;
83
 
            layout.Ellipsize = EllipsizeMode;
84
 
            
85
67
            // Update layout
86
 
            UpdateLayoutText (GetText ());
 
68
            UpdateLayout (GetText (), available.Width - Margin.X, null, false);
87
69
 
88
70
            layout.GetPixelSize (out text_w, out text_h);
89
71
 
93
75
            }
94
76
 
95
77
            //DesiredSize = new Size (width, text_h);
96
 
            var size = new Size (width, text_h);
 
78
            var size = DesiredSize = new Size (width, text_h);
97
79
 
98
80
            // Hack, as this prevents the TextBlock from
99
81
            // being flexible in a Vertical StackPanel
106
88
            return size;
107
89
        }
108
90
 
109
 
        private void UpdateLayoutText (string text)
 
91
        private void UpdateLayout (string text, double width, double? height, bool forceWidth)
110
92
        {
111
 
            if (text == last_text) {
112
 
                return;
113
 
            }
114
 
 
115
 
            last_formatted_text = GetFormattedText (text) ?? "";
116
 
            last_text = text;
117
 
 
118
 
            if (TextWrap == TextWrap.None && last_formatted_text.IndexOfAny (lfcr) >= 0) {
119
 
                last_formatted_text = last_formatted_text.Replace ("\r\n", "\x20").Replace ('\n', '\x20').Replace ('\r', '\x20');
120
 
            }
 
93
            if (text != last_text) {
 
94
                last_formatted_text = GetFormattedText (text) ?? "";
 
95
                last_text = text;
 
96
 
 
97
                if (TextWrap == TextWrap.None && last_formatted_text.IndexOfAny (lfcr) >= 0) {
 
98
                    last_formatted_text = last_formatted_text.Replace ("\r\n", "\x20").Replace ('\n', '\x20').Replace ('\r', '\x20');
 
99
                }
 
100
            }
 
101
 
 
102
            TextWrap wrap = TextWrap;
 
103
            layout.Width = wrap != TextWrap.None || forceWidth ? (int)(Pango.Scale.PangoScale * width) : -1;
 
104
            layout.Wrap = GetPangoWrapMode (wrap);
 
105
            if (height != null && wrap != TextWrap.None) {
 
106
                layout.SetHeight ((int)(Pango.Scale.PangoScale * height.Value));
 
107
            }
 
108
            font_desc.Weight = GetPangoFontWeight (FontWeight);
 
109
            layout.SingleParagraphMode = wrap == TextWrap.None;
 
110
            layout.Ellipsize = EllipsizeMode;
121
111
 
122
112
            if (UseMarkup) {
123
113
                layout.SetMarkup (last_formatted_text);
150
140
                return;
151
141
            }
152
142
 
153
 
            //int layout_width = TextWrap == TextWrap.None ? -1 : (int)(Pango.Scale.PangoScale * RenderSize.Width);
154
 
            int layout_width = (int)(Pango.Scale.PangoScale * RenderSize.Width);
155
 
            if (layout.Width != layout_width) {
156
 
                layout.Width = layout_width;
157
 
            }
 
143
            UpdateLayout (GetText (), RenderSize.Width, RenderSize.Height, true);
158
144
 
159
145
            int text_width, text_height;
160
 
            if (TextWrap != TextWrap.None) {
161
 
                layout.SetHeight ((int)(Pango.Scale.PangoScale * RenderSize.Height));
162
 
            }
 
146
 
163
147
            layout.GetPixelSize (out text_width, out text_height);
164
148
 
165
149
            if (layout.IsEllipsized || text_width > RenderSize.Width || text_height > RenderSize.Height) {
193
177
            text_alloc = new_alloc;
194
178
        }
195
179
 
196
 
        protected override void ClippedRender (Context cr)
 
180
        protected override void ClippedRender (Hyena.Data.Gui.CellContext context)
197
181
        {
198
182
            if (!EnsureLayout ()) {
199
183
                return;
200
184
            }
201
185
 
 
186
            var cr = context.Context;
 
187
            Foreground = new Brush (context.Theme.Colors.GetWidgetColor (
 
188
                context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, context.State));
 
189
 
202
190
            Brush foreground = Foreground;
203
191
            if (!foreground.IsValid) {
204
192
                return;
215
203
 
216
204
            cr.MoveTo (text_alloc.X, text_alloc.Y);
217
205
            Foreground.Apply (cr);
218
 
            UpdateLayoutText (GetText ());
 
206
            UpdateLayout (GetText (), RenderSize.Width, RenderSize.Height, true);
219
207
            Pango.CairoHelper.ShowLayout (cr, layout);
220
208
            cr.Fill ();
221
209