5
// Lluis Sanchez <lluis@xamarin.com>
6
// Eric Maupin <ermau@xamarin.com>
8
// Copyright (c) 2011-2012 Xamarin Inc
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:
17
// The above copyright notice and this permission notice shall be included in
18
// all copies or substantial portions of the Software.
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
29
using System.Reflection;
34
namespace Xwt.Backends
36
public abstract class EngineBackend
39
/// Initializes the application.
41
public virtual void InitializeApplication ()
46
/// Runs the main GUI loop
48
public abstract void RunApplication ();
51
/// Exits the main GUI loop
53
public abstract void ExitApplication ();
56
/// Asynchronously invokes <paramref name="action"/> on the engine UI thread.
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);
63
/// Begins invoking <paramref name="action"/> on a timer period of <paramref name="timeSpan"/>.
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);
73
/// Cancels an invoke timer started from <see cref="TimerInvoke"/>.
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);
80
/// Gets a reference to the native widget wrapped by an XWT widget
83
/// The native widget.
88
public abstract object GetNativeWidget (Widget w);
91
/// Gets a reference to the image object wrapped by an XWT Image
96
/// <param name='image'>
99
public virtual object GetNativeImage (Image image)
101
return WidgetRegistry.GetBackend (image);
104
public virtual void ShowWebBrowser (NavigateToUrlEventArgs e)
106
if (!e.Handled && e.Uri != null) {
107
System.Diagnostics.Process.Start (e.Uri.ToString ());
113
/// Dispatches pending events in the UI event queue
115
public abstract void DispatchPendingEvents ();
118
/// Gets the backend for a native window.
121
/// The backend for the window.
123
/// <param name='nativeWindow'>
124
/// A native window reference.
126
public abstract IWindowFrameBackend GetBackendForWindow (object nativeWindow);
129
/// Gets the native parent window of a widget
132
/// The native parent window.
138
/// This method is used by XWT to get the window of a widget, when the widget is
139
/// embedded in a native application
141
public virtual object GetNativeParentWindow (Widget w)
147
/// Gets a value indicating whether this <see cref="Xwt.Backends.EngineBackend"/> handles size negotiation on its own
150
/// <c>true</c> if the engine backend handles size negotiation; otherwise, <c>false</c>.
152
public virtual bool HandlesSizeNegotiation {
153
get { return false; }
157
/// Registers a callback to be invoked just before the execution returns to the main loop
159
/// <param name='action'>
160
/// Callback to execute
163
/// The default implementation does the invocation using InvokeAsync.
165
public virtual void InvokeBeforeMainLoop (Action action)
167
InvokeAsync (action);
171
/// Determines whether a widget has a native parent widget
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
177
public abstract bool HasNativeParent (Widget w);