~ubuntu-branches/ubuntu/utopic/monodevelop/utopic

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.Mac/Xwt.Mac/LabelBackend.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-10-10 14:50:04 UTC
  • mfrom: (10.3.4)
  • Revision ID: package-import@ubuntu.com-20131010145004-80l130sny21b17sb
Tags: 4.0.12+dfsg-1
* [5dcb6e1] Fix debian/watch for new source tarball name format
* [5c68cb5] Refresh list of files removed by get-orig-source to 
  reflect 4.0.12
* [96d60a0] Imported Upstream version 4.0.12+dfsg
* [b989752] Refresh debian/patches/no_appmenu to ensure it applies
* [2a4c351] Ensure every assembly in external/ is cleaned properly
* [92762f7] Add more excluded Mac-specific modulerefs
* [bc698ba] Add symlinks to NUnit assemblies (Closes: #714246)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
using System;
28
28
using MonoMac.AppKit;
29
29
using Xwt.Backends;
 
30
using MonoMac.Foundation;
 
31
using MonoMac.ObjCRuntime;
30
32
 
31
33
namespace Xwt.Mac
32
34
{
33
 
        public class LabelBackend: ViewBackend<NSTextField,IWidgetEventSink>, ILabelBackend
 
35
        public class LabelBackend: ViewBackend<NSView,IWidgetEventSink>, ILabelBackend
34
36
        {
35
37
                public LabelBackend ()
36
 
                        : this (new TextFieldView ())
 
38
                        : this (new CustomAlignedContainer (new TextFieldView ()))
37
39
                {
38
40
                }
39
41
 
43
45
                        Widget.Editable = false;
44
46
                        Widget.Bezeled = false;
45
47
                        Widget.DrawsBackground = false;
46
 
                        Widget.SizeToFit ();
 
48
                }
 
49
 
 
50
                protected override void OnSizeToFit ()
 
51
                {
 
52
                        Container.SizeToFit ();
 
53
                }
 
54
 
 
55
                CustomAlignedContainer Container {
 
56
                        get { return (CustomAlignedContainer)base.Widget; }
 
57
                }
 
58
 
 
59
                public new NSTextField Widget {
 
60
                        get { return (NSTextField) Container.Child; }
47
61
                }
48
62
 
49
63
                public virtual string Text {
52
66
                        }
53
67
                        set {
54
68
                                Widget.StringValue = value;
55
 
                                Widget.SizeToFit ();
 
69
                                ResetFittingSize ();
56
70
                        }
57
71
                }
58
72
 
 
73
                public void SetFormattedText (FormattedText text)
 
74
                {
 
75
                        Widget.AttributedStringValue = text.ToAttributedString ();
 
76
                }
 
77
 
59
78
                public Xwt.Drawing.Color TextColor {
60
79
                        get { return Widget.TextColor.ToXwtColor (); }
61
80
                        set { Widget.TextColor = value.ToNSColor (); }
63
82
                
64
83
                public Alignment TextAlignment {
65
84
                        get {
66
 
                                switch (Widget.Alignment) {
67
 
                                case NSTextAlignment.Left: return Alignment.Start;
68
 
                                case NSTextAlignment.Center: return Alignment.Center;
69
 
                                case NSTextAlignment.Right: return Alignment.End;
70
 
                                }
71
 
                                return Alignment.Start;
 
85
                                return Widget.Alignment.ToAlignment ();
72
86
                        }
73
87
                        set {
74
 
                                switch (value) {
75
 
                                case Alignment.Start: Widget.Alignment = NSTextAlignment.Left; break;
76
 
                                case Alignment.Center: Widget.Alignment = NSTextAlignment.Center; break;
77
 
                                case Alignment.End: Widget.Alignment = NSTextAlignment.Right; break;
78
 
                                }
 
88
                                Widget.Alignment = value.ToNSTextAlignment ();
79
89
                        }
80
90
                }
81
91
                
139
149
                        }
140
150
                }
141
151
        }
 
152
 
 
153
        sealed class CustomAlignedContainer: NSView, IViewObject
 
154
        {
 
155
                public NSView Child;
 
156
 
 
157
                public CustomAlignedContainer (NSView child)
 
158
                {
 
159
                        Child = child;
 
160
                        AddSubview (child);
 
161
                        UpdateTextFieldFrame ();
 
162
                }
 
163
 
 
164
                public ViewBackend Backend { get; set; }
 
165
 
 
166
                public NSView View {
 
167
                        get { return this; }
 
168
                }
 
169
 
 
170
                static readonly Selector sizeToFitSel = new Selector ("sizeToFit");
 
171
 
 
172
                public void SizeToFit ()
 
173
                {
 
174
                        if (Child.RespondsToSelector (sizeToFitSel))
 
175
                                Messaging.void_objc_msgSend (Child.Handle, sizeToFitSel.Handle);
 
176
                        else
 
177
                                throw new NotSupportedException ();
 
178
                        Frame = new System.Drawing.RectangleF (Frame.X, Frame.Y, Child.Frame.Width, Child.Frame.Height);
 
179
                }
 
180
 
 
181
                bool expandVertically;
 
182
                public bool ExpandVertically {
 
183
                        get {
 
184
                                return expandVertically;
 
185
                        }
 
186
                        set {
 
187
                                expandVertically = value;
 
188
                                UpdateTextFieldFrame ();
 
189
                        }
 
190
                }
 
191
 
 
192
                public override void SetFrameSize (System.Drawing.SizeF newSize)
 
193
                {
 
194
                        base.SetFrameSize (newSize);
 
195
                        UpdateTextFieldFrame ();
 
196
                }
 
197
 
 
198
                void UpdateTextFieldFrame ()
 
199
                {
 
200
                        if (expandVertically)
 
201
                                Child.Frame = Frame;
 
202
                        else
 
203
                                Child.Frame = new System.Drawing.RectangleF (0, (Frame.Height - Child.Frame.Height) / 2, Frame.Width, Child.Frame.Height);
 
204
                }
 
205
        }
142
206
        
143
207
        class TextFieldView: NSTextField, IViewObject
144
208
        {
145
 
                public Widget Frontend { get; set; }
 
209
                public ViewBackend Backend { get; set; }
146
210
                public NSView View {
147
211
                        get { return this; }
148
212
                }