5 // Moonlight List (moonlight-list@lists.ximian.com)
7 // Copyright 2007 Novell, Inc.
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Globalization
;
31 using System
.Reflection
;
32 using System
.Runtime
.InteropServices
;
34 using System
.Windows
.Markup
;
38 internal delegate IntPtr
DownloaderCreateStateFunc (IntPtr dl
);
39 internal delegate void DownloaderDestroyStateFunc (IntPtr state
);
40 internal delegate void DownloaderOpenFunc (IntPtr state
, string verb
, string uri
, bool custom_header_support
, bool disable_cache
);
41 internal delegate void DownloaderSendFunc (IntPtr state
);
42 internal delegate void DownloaderAbortFunc (IntPtr state
);
43 internal delegate void DownloaderHeaderFunc (IntPtr state
, string header
, string value);
44 internal delegate void DownloaderBodyFunc (IntPtr state
, IntPtr body
, int length
);
45 internal delegate IntPtr
DownloaderCreateWebRequestFunc (string method
, string uri
, IntPtr context
);
46 internal delegate void DownloaderSetResponseHeaderCallbackFunc (IntPtr native
, DownloaderResponseHeaderCallback callback
, IntPtr context
);
47 internal delegate IntPtr
DownloaderGetResponseFunc (IntPtr native
);
49 internal delegate void DownloaderResponseHeaderCallback (IntPtr context
, string header
, string value);
51 internal delegate Size
MeasureOverrideCallback (Size availableSize
);
52 internal delegate Size
ArrangeOverrideCallback (Size finalSize
);
53 internal delegate void LoadedCallback (IntPtr fwe_ptr
);
55 internal delegate void ApplyDefaultStyleCallback (IntPtr fwe_ptr
, IntPtr type_info_ptr
);
56 internal delegate IntPtr
GetDefaultTemplateCallback (IntPtr fwe_ptr
);
57 internal delegate void ApplyStyleCallback (IntPtr fwe_ptr
, IntPtr style_ptr
);
58 internal delegate void ConvertKeyframeValueCallback (Mono
.Kind kind
, IntPtr property
, IntPtr original
, out Value converted
);
59 internal delegate ManagedStreamCallbacks
GetResourceCallback (string resourceBase
, string name
);
61 // Used in databinding to interact with managed objects
62 internal delegate Value
GetValueCallback ();
63 internal delegate void SetValueCallback (IntPtr
value);
65 internal delegate IntPtr
CreateCustomXamlElementCallback (string xmlns
, string name
);
66 internal delegate void SetCustomXamlAttributeCallback (IntPtr target
, string name
, string value);
67 internal delegate void XamlHookupEventCallback (IntPtr target
, string name
, string value);
68 internal delegate void UnmanagedEventHandler (IntPtr sender
, IntPtr calldata
, IntPtr closure
);
70 internal delegate void PlainEvent (IntPtr target
);
72 internal delegate void HttpHeaderHandler (string name
, string value);
73 internal delegate void AsyncResponseAvailableHandler (IntPtr response
, IntPtr context
);
74 internal delegate void UnmanagedPropertyChangeHandler (IntPtr dependency_object
, IntPtr propertyChangedArgs
, ref MoonError error
, IntPtr closure
);
76 internal delegate void TickCallHandler (IntPtr handle
);
79 internal delegate void InvokeDelegate (IntPtr obj_handle
, IntPtr method_handle
,
80 [MarshalAs (UnmanagedType
.LPStr
)] string name
,
81 [MarshalAs (UnmanagedType
.LPArray
, SizeParamIndex
= 4)]
84 ref Value return_value
);
86 internal delegate void SetPropertyDelegate (IntPtr obj_handle
, string name
, ref Value
value);
87 internal delegate void GetPropertyDelegate (IntPtr obj_handle
, string name
, ref Value
value);
88 internal delegate void EventHandlerDelegate (IntPtr obj_handle
, IntPtr event_handle
, IntPtr scriptable_obj
, IntPtr closure
);
90 internal delegate uint DownloaderResponseStartedDelegate (IntPtr native
, IntPtr context
);
91 internal delegate uint DownloaderResponseAvailableDelegate (IntPtr native
, IntPtr context
, IntPtr data
, uint length
);
92 internal delegate uint DownloaderResponseFinishedDelegate (IntPtr native
, IntPtr context
, [MarshalAs (UnmanagedType
.U1
)] bool success
, IntPtr data
);
93 internal delegate void HeaderVisitor (IntPtr context
, IntPtr name
, IntPtr val
);
95 internal delegate void DomEventCallback (IntPtr context
, string name
, int client_x
, int client_y
, int offset_x
, int offset_y
,
96 [MarshalAs (UnmanagedType
.Bool
)] bool alt_key
, // glib gboolean is a gint (i.e. 4 bytes just like the FX bool)
97 [MarshalAs (UnmanagedType
.Bool
)] bool ctrl_key
,
98 [MarshalAs (UnmanagedType
.Bool
)] bool shift_key
,
99 int /* System.Windows.Browser.MouseButtons */ mouse_button
,
104 internal delegate bool ImageUriFunc (int level
, int posx
, int posy
, IntPtr uri
, IntPtr ignore
);
106 internal static partial class NativeMethods
{
109 * Don't add any P/Invokes here.
111 * Add annotations (@GeneratePInvoke) to your C/C++ methods to generate the P/Invokes.
112 * If the generator gets parameters wrong, you can add a @MarshalAs=<whatever> to override.
115 internal static Exception
CreateManagedException (MoonError err
)
117 string msg
= err
.Message
;
120 if (err
.GCHandlePtr
!= IntPtr
.Zero
) {
121 // We need to get this before calling Dispose.
122 ex
= err
.GCHandle
.Target
as Exception
;
127 switch (err
.Number
) {
130 return new Exception (msg
);
132 return new ArgumentException (msg
);
134 return new ArgumentNullException (msg
);
136 return new ArgumentOutOfRangeException (msg
);
138 return new InvalidOperationException (msg
);
140 return new XamlParseException (err
.LineNumber
, err
.CharPosition
, msg
);
142 return new UnauthorizedAccessException (msg
);
144 return new ExecutionEngineException (msg
);
148 return new Exception (msg
);