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
30
namespace Xwt.GtkBackend
32
public class FrameBackend: WidgetBackend, IFrameBackend
34
Gtk.Alignment paddingAlign;
38
public FrameBackend ()
40
Widget = new Gtk.Frame ();
44
protected new Gtk.Bin Widget {
45
get { return (Gtk.Bin)base.Widget; }
46
set { base.Widget = value; }
49
protected new IFrameEventSink EventSink {
50
get { return (IFrameEventSink)base.EventSink; }
53
#region IFrameBackend implementation
55
public void SetContent (IWidgetBackend child)
57
Gtk.Bin parent = paddingAlign != null ? paddingAlign : Widget;
59
var w = GetWidget (child);
60
if (parent.Child != null)
61
parent.Remove (parent.Child);
67
public void SetFrameType (FrameType type)
69
Frame f = (Frame) Frontend;
72
case FrameType.Custom:
73
if (!(Widget is HeaderBox)) {
74
HeaderBox box = new HeaderBox ();
76
box.DrawBackground = UsingCustomBackgroundColor;
77
box.SetMargins ((int)f.Margin.Top, (int)f.Margin.Bottom, (int)f.Margin.Left, (int)f.Margin.Right);
78
box.SetPadding ((int)f.Padding.Top, (int)f.Padding.Bottom, (int)f.Padding.Left, (int)f.Padding.Right);
79
if (borderColor != null)
80
box.SetBorderColor (borderColor.Value);
81
var c = paddingAlign != null ? paddingAlign.Child : Widget.Child;
83
((Gtk.Container)c.Parent).Remove (c);
87
if (paddingAlign != null) {
88
paddingAlign.Destroy ();
93
case FrameType.WidgetBox:
94
if (!(Widget is Gtk.Frame)) {
98
Gtk.Frame gf = new Gtk.Frame ();
99
if (!string.IsNullOrEmpty (label))
101
if (f.Padding.HorizontalSpacing != 0 || f.Padding.VerticalSpacing != 0) {
102
paddingAlign = new Gtk.Alignment (0, 0, 1, 1);
103
paddingAlign.Show ();
104
UreatePaddingAlign (f.Padding.Top, f.Padding.Bottom, f.Padding.Left, f.Padding.Right);
106
paddingAlign.Add (c);
107
gf.Add (paddingAlign);
119
void UreatePaddingAlign (double top, double bottom, double left, double right)
121
paddingAlign.TopPadding = (uint) top;
122
paddingAlign.BottomPadding = (uint) bottom;
123
paddingAlign.LeftPadding = (uint) left;
124
paddingAlign.RightPadding = (uint) right;
127
public void SetBorderSize (double left, double right, double top, double bottom)
129
HeaderBox hb = Widget as HeaderBox;
131
hb.SetMargins ((int)top, (int)bottom, (int)left, (int)right);
135
public void SetPadding (double left, double right, double top, double bottom)
137
if (Widget is HeaderBox) {
138
HeaderBox hb = (HeaderBox) Widget;
139
hb.SetPadding ((int)top, (int)bottom, (int)left, (int)right);
143
if (left == 0 && right == 0 && top == 0 && bottom == 0 && paddingAlign == null)
146
if (paddingAlign == null) {
147
paddingAlign = new Gtk.Alignment (0, 0, 1, 1);
148
paddingAlign.Show ();
149
var c = Widget.Child;
152
paddingAlign.Add (c);
154
Widget.Add (paddingAlign);
156
UreatePaddingAlign (top, bottom, left, right);
159
public Color BorderColor {
161
if (borderColor == null)
162
return Util.ToXwtColor (Widget.Style.Dark (Gtk.StateType.Normal));
164
return borderColor.Value;
168
HeaderBox hb = Widget as HeaderBox;
170
hb.SetBorderColor (value);
174
public override Color BackgroundColor {
176
return base.BackgroundColor;
179
base.BackgroundColor = value;
180
if (Widget is HeaderBox)
181
((HeaderBox)Widget).DrawBackground = true;
185
public string Label {
191
if (Widget is Gtk.Frame)
192
((Gtk.Frame)Widget).Label = value;