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

« back to all changes in this revision

Viewing changes to external/xwt/Xwt/Xwt.Backends/EngineBackend.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
// EngineBackend.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
//       Eric Maupin <ermau@xamarin.com>
 
7
// 
 
8
// Copyright (c) 2011-2012 Xamarin Inc
 
9
// 
 
10
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
11
// of this software and associated documentation files (the "Software"), to deal
 
12
// in the Software without restriction, including without limitation the rights
 
13
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
14
// copies of the Software, and to permit persons to whom the Software is
 
15
// furnished to do so, subject to the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be included in
 
18
// all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
21
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
22
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
23
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
24
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
25
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
26
// THE SOFTWARE.
 
27
 
 
28
using System;
 
29
using System.Reflection;
 
30
using System.IO;
 
31
using Xwt.Drawing;
 
32
using Xwt.Engine;
 
33
 
 
34
namespace Xwt.Backends
 
35
{
 
36
        public abstract class EngineBackend
 
37
        {
 
38
                /// <summary>
 
39
                /// Initializes the application.
 
40
                /// </summary>
 
41
                public virtual void InitializeApplication ()
 
42
                {
 
43
                }
 
44
                
 
45
                /// <summary>
 
46
                /// Runs the main GUI loop
 
47
                /// </summary>
 
48
                public abstract void RunApplication ();
 
49
                
 
50
                /// <summary>
 
51
                /// Exits the main GUI loop
 
52
                /// </summary>
 
53
                public abstract void ExitApplication ();
 
54
                
 
55
                /// <summary>
 
56
                /// Asynchronously invokes <paramref name="action"/> on the engine UI thread.
 
57
                /// </summary>
 
58
                /// <param name="action">The action to invoke.</param>
 
59
                /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
 
60
                public abstract void InvokeAsync (Action action);
 
61
 
 
62
                /// <summary>
 
63
                /// Begins invoking <paramref name="action"/> on a timer period of <paramref name="timeSpan"/>.
 
64
                /// </summary>
 
65
                /// <param name="action">The function to invoke. Returning <c>false</c> stops the timer.</param>
 
66
                /// <param name="timeSpan">The period before the initial invoke and between subsequent invokes.</param>
 
67
                /// <returns>An identifying object that can be used to cancel the timer with <seealso cref="CancelTimerInvoke"/>.</returns>
 
68
                /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
 
69
                /// <seealso cref="CancelTimerInvoke"/>
 
70
                public abstract object TimerInvoke (Func<bool> action, TimeSpan timeSpan);
 
71
 
 
72
                /// <summary>
 
73
                /// Cancels an invoke timer started from <see cref="TimerInvoke"/>.
 
74
                /// </summary>
 
75
                /// <param name="id">The unique object returned from <see cref="TimerInvoke"/>.</param>
 
76
                /// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception>
 
77
                public abstract void CancelTimerInvoke (object id);
 
78
                
 
79
                /// <summary>
 
80
                /// Gets a reference to the native widget wrapped by an XWT widget
 
81
                /// </summary>
 
82
                /// <returns>
 
83
                /// The native widget.
 
84
                /// </returns>
 
85
                /// <param name='w'>
 
86
                /// A widget
 
87
                /// </param>
 
88
                public abstract object GetNativeWidget (Widget w);
 
89
                
 
90
                /// <summary>
 
91
                /// Gets a reference to the image object wrapped by an XWT Image
 
92
                /// </summary>
 
93
                /// <returns>
 
94
                /// The native image.
 
95
                /// </returns>
 
96
                /// <param name='image'>
 
97
                /// An image.
 
98
                /// </param>
 
99
                public virtual object GetNativeImage (Image image)
 
100
                {
 
101
                        return WidgetRegistry.GetBackend (image);
 
102
                }
 
103
 
 
104
                public virtual void ShowWebBrowser (NavigateToUrlEventArgs e)
 
105
                {
 
106
                        if (!e.Handled && e.Uri != null) {
 
107
                                System.Diagnostics.Process.Start (e.Uri.ToString ());
 
108
                                e.SetHandled ();
 
109
                        }
 
110
                }
 
111
 
 
112
                /// <summary>
 
113
                /// Dispatches pending events in the UI event queue
 
114
                /// </summary>
 
115
                public abstract void DispatchPendingEvents ();
 
116
                
 
117
                /// <summary>
 
118
                /// Gets the backend for a native window.
 
119
                /// </summary>
 
120
                /// <returns>
 
121
                /// The backend for the window.
 
122
                /// </returns>
 
123
                /// <param name='nativeWindow'>
 
124
                /// A native window reference.
 
125
                /// </param>
 
126
                public abstract IWindowFrameBackend GetBackendForWindow (object nativeWindow);
 
127
                
 
128
                /// <summary>
 
129
                /// Gets the native parent window of a widget
 
130
                /// </summary>
 
131
                /// <returns>
 
132
                /// The native parent window.
 
133
                /// </returns>
 
134
                /// <param name='w'>
 
135
                /// A widget
 
136
                /// </param>
 
137
                /// <remarks>
 
138
                /// This method is used by XWT to get the window of a widget, when the widget is
 
139
                /// embedded in a native application
 
140
                /// </remarks>
 
141
                public virtual object GetNativeParentWindow (Widget w)
 
142
                {
 
143
                        return null;
 
144
                }
 
145
                
 
146
                /// <summary>
 
147
                /// Gets a value indicating whether this <see cref="Xwt.Backends.EngineBackend"/> handles size negotiation on its own
 
148
                /// </summary>
 
149
                /// <value>
 
150
                /// <c>true</c> if the engine backend handles size negotiation; otherwise, <c>false</c>.
 
151
                /// </value>
 
152
                public virtual bool HandlesSizeNegotiation {
 
153
                        get { return false; }
 
154
                }
 
155
 
 
156
                /// <summary>
 
157
                /// Registers a callback to be invoked just before the execution returns to the main loop
 
158
                /// </summary>
 
159
                /// <param name='action'>
 
160
                /// Callback to execute
 
161
                /// </param>
 
162
                /// <remarks>
 
163
                /// The default implementation does the invocation using InvokeAsync.
 
164
                /// </remarks>                  
 
165
                public virtual void InvokeBeforeMainLoop (Action action)
 
166
                {
 
167
                        InvokeAsync (action);
 
168
                }
 
169
 
 
170
                /// <summary>
 
171
                /// Determines whether a widget has a native parent widget
 
172
                /// </summary>
 
173
                /// <returns><c>true</c> if the widget has native parent; otherwise, <c>false</c>.</returns>
 
174
                /// <param name="w">The widget.</param>
 
175
                /// <remarks>This funciton is used to determine if a widget is a child of another non-XWT widget
 
176
                /// </remarks>
 
177
                public abstract bool HasNativeParent (Widget w);
 
178
        }
 
179
}
 
180