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
31
namespace Xwt.GtkBackend
33
public class WindowFrameBackend: IWindowFrameBackend
36
IWindowFrameEventSink eventSink;
41
public WindowFrameBackend ()
45
public Gtk.Window Window {
46
get { return window; }
47
set { window = value; }
50
protected WindowFrame Frontend {
51
get { return frontend; }
54
void IBackend.InitializeBackend (object frontend)
56
this.frontend = (WindowFrame) frontend;
59
public virtual void ReplaceChild (Gtk.Widget oldWidget, Gtk.Widget newWidget)
61
throw new NotSupportedException ();
64
#region IWindowFrameBackend implementation
65
void IWindowFrameBackend.Initialize (IWindowFrameEventSink eventSink)
67
this.eventSink = eventSink;
69
Window.SizeRequested += delegate(object o, Gtk.SizeRequestedArgs args) {
70
if (!Window.Resizable) {
71
int w = args.Requisition.Width, h = args.Requisition.Height;
72
if (w < (int) requestedSize.Width)
73
w = (int) requestedSize.Width;
74
if (h < (int) requestedSize.Height)
75
h = (int) requestedSize.Height;
76
args.Requisition = new Gtk.Requisition () { Width = w, Height = h };
81
public virtual void Initialize ()
85
public virtual void Dispose ()
90
public IWindowFrameEventSink EventSink {
91
get { return eventSink; }
94
public void Move (double x, double y)
97
Window.Move ((int)x, (int)y);
98
Toolkit.Invoke (delegate {
99
EventSink.OnBoundsChanged (Bounds);
103
public void Resize (double width, double height)
105
requestedSize = new Size (width, height);
106
Window.Resize ((int)width, (int)height);
107
Window.SetDefaultSize ((int)width, (int)height);
110
public Rectangle Bounds {
113
Window.GetPosition (out x, out y);
114
Window.GetSize (out w, out h);
115
return new Rectangle (x, y, w, h);
119
requestedSize = value.Size;
120
Window.Move ((int)value.X, (int)value.Y);
121
Window.Resize ((int)value.Width, (int)value.Height);
122
Window.SetDefaultSize ((int)value.Width, (int)value.Height);
123
Toolkit.Invoke (delegate {
124
EventSink.OnBoundsChanged (Bounds);
129
bool IWindowFrameBackend.Visible {
131
return window.Visible;
135
SetDefaultPosition ();
136
window.Visible = value;
140
protected void SetDefaultPosition ()
143
if (window.TransientFor != null)
144
window.SetPosition (Gtk.WindowPosition.CenterOnParent);
146
window.SetPosition (Gtk.WindowPosition.Center);
151
string IWindowFrameBackend.Title {
152
get { return Window.Title; }
153
set { Window.Title = value; }
156
bool IWindowFrameBackend.Decorated {
158
return Window.Decorated;
161
Window.Decorated = value;
165
bool IWindowFrameBackend.ShowInTaskbar {
167
return !Window.SkipTaskbarHint;
170
Window.SkipTaskbarHint = !value;
174
void IWindowFrameBackend.SetTransientFor (IWindowFrameBackend window)
176
Window.TransientFor = ((WindowFrameBackend)window).Window;
179
public bool Resizable {
181
return Window.Resizable;
184
Window.Resizable = value;
188
public void SetIcon(object backendImage)
190
Window.Icon = backendImage as Gdk.Pixbuf;
194
public virtual void EnableEvent (object ev)
196
if (ev is WindowFrameEvent) {
197
switch ((WindowFrameEvent)ev) {
198
case WindowFrameEvent.BoundsChanged:
199
Window.SizeAllocated += HandleWidgetSizeAllocated; break;
200
case WindowFrameEvent.CloseRequested:
201
Window.DeleteEvent += HandleCloseRequested; break;
206
public virtual void DisableEvent (object ev)
208
if (ev is WindowFrameEvent) {
209
switch ((WindowFrameEvent)ev) {
210
case WindowFrameEvent.BoundsChanged:
211
Window.SizeAllocated -= HandleWidgetSizeAllocated; break;
212
case WindowFrameEvent.CloseRequested:
213
Window.DeleteEvent -= HandleCloseRequested; break;
218
void HandleWidgetSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
220
Toolkit.Invoke (delegate {
221
EventSink.OnBoundsChanged (Bounds);
225
void HandleCloseRequested (object o, Gtk.DeleteEventArgs args)
227
Toolkit.Invoke(delegate {
228
args.RetVal = EventSink.OnCloseRequested ();
232
public void Present ()
235
GtkWorkarounds.GrabDesktopFocus ();
239
public virtual Size ImplicitMinSize {
240
get { return new Size (0,0); }