5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33
public class LabelBackend: ViewBackend<NSTextField,IWidgetEventSink>, ILabelBackend
35
public LabelBackend ()
36
: this (new TextFieldView ())
40
protected LabelBackend (IViewObject viewObject)
42
ViewObject = viewObject;
43
Widget.Editable = false;
44
Widget.Bezeled = false;
45
Widget.DrawsBackground = false;
49
public virtual string Text {
51
return Widget.StringValue;
54
Widget.StringValue = value;
59
public Xwt.Drawing.Color TextColor {
60
get { return Widget.TextColor.ToXwtColor (); }
61
set { Widget.TextColor = value.ToNSColor (); }
64
public Alignment TextAlignment {
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;
71
return Alignment.Start;
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;
82
public EllipsizeMode Ellipsize {
84
switch (Widget.Cell.LineBreakMode) {
85
case NSLineBreakMode.TruncatingHead: return Xwt.EllipsizeMode.Start;
86
case NSLineBreakMode.TruncatingMiddle: return Xwt.EllipsizeMode.Middle;
87
case NSLineBreakMode.TruncatingTail: return Xwt.EllipsizeMode.End;
88
default: return Xwt.EllipsizeMode.None;
93
case Xwt.EllipsizeMode.None: Widget.Cell.LineBreakMode = NSLineBreakMode.Clipping; break;
94
case Xwt.EllipsizeMode.Start: Widget.Cell.LineBreakMode = NSLineBreakMode.TruncatingHead; break;
95
case Xwt.EllipsizeMode.Middle: Widget.Cell.LineBreakMode = NSLineBreakMode.TruncatingMiddle; break;
96
case Xwt.EllipsizeMode.End: Widget.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; break;
101
public override Xwt.Drawing.Color BackgroundColor {
102
get { return Widget.BackgroundColor.ToXwtColor (); }
104
Widget.BackgroundColor = value.ToNSColor ();
105
Widget.DrawsBackground = true;
109
// FIXME: technically not possible if we keep NSTextField
110
// as the backend because it's one-line only
111
public WrapMode Wrap {
113
if (!Widget.Cell.Wraps)
114
return WrapMode.None;
115
switch (Widget.Cell.LineBreakMode) {
116
case NSLineBreakMode.ByWordWrapping:
117
return WrapMode.Word;
118
case NSLineBreakMode.CharWrapping:
119
return WrapMode.Character;
121
return WrapMode.None;
125
if (value == WrapMode.None) {
126
Widget.Cell.Wraps = false;
128
Widget.Cell.Wraps = true;
131
case WrapMode.WordAndCharacter:
132
Widget.Cell.LineBreakMode = NSLineBreakMode.ByWordWrapping;
134
case WrapMode.Character:
135
Widget.Cell.LineBreakMode = NSLineBreakMode.CharWrapping;
143
class TextFieldView: NSTextField, IViewObject
145
public Widget Frontend { get; set; }