~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.Gtk/Xwt.GtkBackend/WindowFrameBackend.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// WindowFrameBa.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2011 Xamarin Inc
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using Xwt.Backends;
 
28
using Xwt.Engine;
 
29
using Xwt.Drawing;
 
30
 
 
31
namespace Xwt.GtkBackend
 
32
{
 
33
        public class WindowFrameBackend: IWindowFrameBackend
 
34
        {
 
35
                Gtk.Window window;
 
36
                IWindowFrameEventSink eventSink;
 
37
                WindowFrame frontend;
 
38
                Size requestedSize;
 
39
                bool positionSet;
 
40
 
 
41
                public WindowFrameBackend ()
 
42
                {
 
43
                }
 
44
                
 
45
                public Gtk.Window Window {
 
46
                        get { return window; }
 
47
                        set { window = value; }
 
48
                }
 
49
                
 
50
                protected WindowFrame Frontend {
 
51
                        get { return frontend; }
 
52
                }
 
53
                
 
54
                void IBackend.InitializeBackend (object frontend)
 
55
                {
 
56
                        this.frontend = (WindowFrame) frontend;
 
57
                }
 
58
 
 
59
                public virtual void ReplaceChild (Gtk.Widget oldWidget, Gtk.Widget newWidget)
 
60
                {
 
61
                        throw new NotSupportedException ();
 
62
                }
 
63
                
 
64
                #region IWindowFrameBackend implementation
 
65
                void IWindowFrameBackend.Initialize (IWindowFrameEventSink eventSink)
 
66
                {
 
67
                        this.eventSink = eventSink;
 
68
                        Initialize ();
 
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 };
 
77
                                }
 
78
                        };
 
79
                }
 
80
                
 
81
                public virtual void Initialize ()
 
82
                {
 
83
                }
 
84
                
 
85
                public virtual void Dispose ()
 
86
                {
 
87
                        Window.Destroy ();
 
88
                }
 
89
                
 
90
                public IWindowFrameEventSink EventSink {
 
91
                        get { return eventSink; }
 
92
                }
 
93
 
 
94
                public void Move (double x, double y)
 
95
                {
 
96
                        positionSet = true;
 
97
                        Window.Move ((int)x, (int)y);
 
98
                        Toolkit.Invoke (delegate {
 
99
                                EventSink.OnBoundsChanged (Bounds);
 
100
                        });
 
101
                }
 
102
 
 
103
                public void Resize (double width, double height)
 
104
                {
 
105
                        requestedSize = new Size (width, height);
 
106
                        Window.Resize ((int)width, (int)height);
 
107
                        Window.SetDefaultSize ((int)width, (int)height);
 
108
                }
 
109
 
 
110
                public Rectangle Bounds {
 
111
                        get {
 
112
                                int w, h, x, y;
 
113
                                Window.GetPosition (out x, out y);
 
114
                                Window.GetSize (out w, out h);
 
115
                                return new Rectangle (x, y, w, h);
 
116
                        }
 
117
                        set {
 
118
                                positionSet = true;
 
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);
 
125
                                });
 
126
                        }
 
127
                }
 
128
 
 
129
                bool IWindowFrameBackend.Visible {
 
130
                        get {
 
131
                                return window.Visible;
 
132
                        }
 
133
                        set {
 
134
                                if (value)
 
135
                                        SetDefaultPosition ();
 
136
                                window.Visible = value;
 
137
                        }
 
138
                }
 
139
 
 
140
                protected void SetDefaultPosition ()
 
141
                {
 
142
                        if (!positionSet) {
 
143
                                if (window.TransientFor != null)
 
144
                                        window.SetPosition (Gtk.WindowPosition.CenterOnParent);
 
145
                                else
 
146
                                        window.SetPosition (Gtk.WindowPosition.Center);
 
147
                                positionSet = true;
 
148
                        }
 
149
                }
 
150
 
 
151
                string IWindowFrameBackend.Title {
 
152
                        get { return Window.Title; }
 
153
                        set { Window.Title = value; }
 
154
                }
 
155
 
 
156
                bool IWindowFrameBackend.Decorated {
 
157
                        get {
 
158
                                return Window.Decorated;
 
159
                        }
 
160
                        set {
 
161
                                Window.Decorated = value;
 
162
                        }
 
163
                }
 
164
 
 
165
                bool IWindowFrameBackend.ShowInTaskbar {
 
166
                        get {
 
167
                                return !Window.SkipTaskbarHint;
 
168
                        }
 
169
                        set {
 
170
                                Window.SkipTaskbarHint = !value;
 
171
                        }
 
172
                }
 
173
 
 
174
                void IWindowFrameBackend.SetTransientFor (IWindowFrameBackend window)
 
175
                {
 
176
                        Window.TransientFor = ((WindowFrameBackend)window).Window;
 
177
                }
 
178
 
 
179
                public bool Resizable {
 
180
                        get {
 
181
                                return Window.Resizable;
 
182
                        }
 
183
                        set {
 
184
                                Window.Resizable = value;
 
185
                        }
 
186
                }
 
187
 
 
188
                public void SetIcon(object backendImage)
 
189
                {
 
190
                        Window.Icon = backendImage as Gdk.Pixbuf;
 
191
                }
 
192
                #endregion
 
193
 
 
194
                public virtual void EnableEvent (object ev)
 
195
                {
 
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;
 
202
                                }
 
203
                        }
 
204
                }
 
205
 
 
206
                public virtual void DisableEvent (object ev)
 
207
                {
 
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;
 
214
                                }
 
215
                        }
 
216
                }
 
217
 
 
218
                void HandleWidgetSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
 
219
                {
 
220
                        Toolkit.Invoke (delegate {
 
221
                                EventSink.OnBoundsChanged (Bounds);
 
222
                        });
 
223
                }
 
224
 
 
225
                void HandleCloseRequested (object o, Gtk.DeleteEventArgs args)
 
226
                {
 
227
                        Toolkit.Invoke(delegate {
 
228
                                args.RetVal = EventSink.OnCloseRequested ();
 
229
                        });
 
230
                }
 
231
 
 
232
                public void Present ()
 
233
                {
 
234
                        if (Platform.IsMac)
 
235
                                GtkWorkarounds.GrabDesktopFocus ();
 
236
                        Window.Present ();
 
237
                }
 
238
 
 
239
                public virtual Size ImplicitMinSize {
 
240
                        get { return new Size (0,0); }
 
241
                }
 
242
        }
 
243
}
 
244