1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
//
// Event.cs
//
// Author:
// Stephane Delcroix <stephane@delcroix.org>
//
// Copyright 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace Clutter
{
public class Event : GLib.IWrapper
{
private IntPtr raw;
public Event (IntPtr raw)
{
this.raw = raw;
}
public IntPtr Handle {
get { return raw; }
}
[DllImport ("libclutter-win32-1.0-0.dll")]
static extern IntPtr gdk_event_get_type ();
public static GLib.GType GType {
get { return new GLib.GType (gdk_event_get_type ()); }
}
[StructLayout (LayoutKind.Sequential)]
private struct NativeStruct
{
public EventType type;
public int time;
public EventFlags flags;
public IntPtr stage;
public IntPtr source;
}
private NativeStruct Native {
get { return (NativeStruct)Marshal.PtrToStructure (raw, typeof (NativeStruct)); }
}
public EventType Type {
get { return Native.type; }
set {
NativeStruct native = Native;
native.type = value;
Marshal.StructureToPtr (native, raw, false);
}
}
public int Time {
get { return Native.time; }
set {
NativeStruct native = Native;
native.time = value;
Marshal.StructureToPtr (native, raw, false);
}
}
public EventFlags Flags {
get { return Native.flags; }
set {
NativeStruct native = Native;
native.flags = value;
Marshal.StructureToPtr (native, raw, false);
}
}
public Stage Stage {
get { return GLib.Object.GetObject (Native.stage, false) as Stage; }
set {
NativeStruct native = Native;
native.stage = value == null ? IntPtr.Zero : value.Handle;
Marshal.StructureToPtr (native, raw, false);
}
}
public Actor Source {
get { return GLib.Object.GetObject (Native.source, false) as Actor; }
set {
NativeStruct native = Native;
native.source = value == null ? IntPtr.Zero : value.Handle;
Marshal.StructureToPtr (native, raw, false);
}
}
public static Event New (IntPtr raw)
{
return GetEvent (raw);
}
public static Event GetEvent (IntPtr raw)
{
if (raw == IntPtr.Zero) {
return null;
}
NativeStruct native = (NativeStruct)Marshal.PtrToStructure (raw, typeof (NativeStruct));
switch (native.type) {
case EventType.KeyPress:
case EventType.KeyRelease:
return new KeyEvent (raw);
case EventType.ButtonPress:
case EventType.ButtonRelease:
return new ButtonEvent (raw);
case EventType.Motion:
return new MotionEvent (raw);
case EventType.Enter:
case EventType.Leave:
return new CrossingEvent (raw);
case EventType.Scroll:
return new ScrollEvent (raw);
case EventType.StageState:
return new StageStateEvent (raw);
case EventType.DestroyNotify:
case EventType.ClientMessage:
case EventType.Delete:
case EventType.Nothing:
default:
return new Clutter.Event (raw);
}
}
}
}
|