5
// Michael Hutchinson <mhutch@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
28
using System.Runtime.InteropServices;
31
namespace Mono.TextEditor
33
public static class GtkGestures
35
const int GDK_GESTURE_MAGNIFY = 37;
36
const int GDK_GESTURE_ROTATE = 38;
37
const int GDK_GESTURE_SWIPE = 39;
39
[DllImport (PangoUtil.LIBGDK)]
40
static extern bool gdk_quartz_supports_gesture_events ();
42
static bool isSupported;
48
isSupported = gdk_quartz_supports_gesture_events ();
49
Console.WriteLine (isSupported);
50
} catch (EntryPointNotFoundException) {
55
public static bool IsSupported { get { return isSupported; } }
57
public static void AddGestureMagnifyHandler (this Gtk.Widget widget, EventHandler<GestureMagnifyEventArgs> handler)
60
throw new NotSupportedException ();
61
var signal = GLib.Signal.Lookup (widget, "gesture-magnify-event", typeof(GestureMagnifyEventArgs));
62
signal.AddDelegate (new EventHandler<GestureMagnifyEventArgs> (handler));
65
public static void AddGestureRotateHandler (this Gtk.Widget widget, EventHandler<GestureRotateEventArgs> handler)
68
throw new NotSupportedException ();
69
var signal = GLib.Signal.Lookup (widget, "gesture-rotate-event", typeof(GestureRotateEventArgs));
70
signal.AddDelegate (new EventHandler<GestureRotateEventArgs> (handler));
73
public static void AddGestureSwipeHandler (this Gtk.Widget widget, EventHandler<GestureSwipeEventArgs> handler)
76
throw new NotSupportedException ();
77
var signal = GLib.Signal.Lookup (widget, "gesture-swipe-event", typeof(GestureSwipeEventArgs));
78
signal.AddDelegate (new EventHandler<GestureSwipeEventArgs> (handler));
82
public unsafe class GestureMagnifyEventArgs : GLib.SignalArgs
84
//have to force pack=4, or Mono aligns doubles to 8 bytes
85
[StructLayout (LayoutKind.Sequential, Pack=4)]
86
struct GdkEventGestureMagnify
88
public Gdk.EventType type;
90
public sbyte send_event;
94
public double magnification;
96
public double x_root, y_root;
99
// I tried to mimic the GTK# pattern of having a subclassed Event object on the EventArgs, but I gave up on
100
// figuring out how to get GTK# to marshal the event to a custom GestureMagnifyEvent class. Instead we just
101
// lift all the accessors up to the args class and dereference the handle directly.
102
GdkEventGestureMagnify *evt {
104
var handle = ((Event)Args[0]).Handle;
105
return (GdkEventGestureMagnify *) handle;
109
public Gdk.Window Window {
111
return (Gdk.Window) GLib.Object.GetObject (evt->window);
115
public Device Device {
117
return (Device) GLib.Object.GetObject (evt->device);
121
public uint Time { get { return evt->time; } }
122
public double X { get { return evt->x; } }
123
public double Y { get { return evt->y; } }
124
public ModifierType State { get { return (ModifierType) evt->state; } }
125
public double Magnification { get { return evt->magnification; } }
126
public double XRoot { get { return evt->x_root; } }
127
public double YRoot { get { return evt->y_root; } }
130
public unsafe class GestureRotateEventArgs : GLib.SignalArgs
132
[StructLayout (LayoutKind.Sequential, Pack=4)]
133
struct GdkEventGestureRotate
135
public Gdk.EventType type;
136
public IntPtr window;
137
public sbyte send_event;
141
public double rotation;
142
public IntPtr device;
143
public double x_root, y_root;
146
GdkEventGestureRotate *evt {
148
var handle = ((Event)Args[0]).Handle;
149
return (GdkEventGestureRotate *) handle;
153
public Gdk.Window Window {
155
return (Gdk.Window) GLib.Object.GetObject (evt->window);
159
public Device Device {
161
return (Device) GLib.Object.GetObject (evt->device);
165
public uint Time { get { return evt->time; } }
166
public double X { get { return evt->x; } }
167
public double Y { get { return evt->y; } }
168
public ModifierType State { get { return (ModifierType) evt->state; } }
169
public double Rotation { get { return evt->rotation; } }
170
public double XRoot { get { return evt->x_root; } }
171
public double YRoot { get { return evt->y_root; } }
174
public unsafe class GestureSwipeEventArgs : GLib.SignalArgs
176
[StructLayout (LayoutKind.Sequential, Pack=4)]
177
struct GdkEventGestureSwipe
179
public Gdk.EventType type;
180
public IntPtr window;
181
public sbyte send_event;
185
public double delta_x, delta_y;
186
public IntPtr device;
187
public double x_root, y_root;
190
GdkEventGestureSwipe *evt {
192
var handle = ((Event)Args[0]).Handle;
193
return (GdkEventGestureSwipe *) handle;
197
public Gdk.Window Window {
199
return (Gdk.Window) GLib.Object.GetObject (evt->window);
203
public Device Device {
205
return (Device) GLib.Object.GetObject (evt->device);
209
public uint Time { get { return evt->time; } }
210
public double X { get { return evt->x; } }
211
public double Y { get { return evt->y; } }
212
public ModifierType State { get { return (ModifierType) evt->state; } }
213
public double DeltaX { get { return evt->delta_x; } }
214
public double DeltaY { get { return evt->delta_y; } }
215
public double XRoot { get { return evt->x_root; } }
216
public double YRoot { get { return evt->y_root; } }
222
GdkEventGestureMagnify *v = (GdkEventGestureMagnify *)0;
223
Console.WriteLine ("type {0}", (int)&(v->type));
224
Console.WriteLine ("window {0}", (int)&(v->window));
225
Console.WriteLine ("send_event {0}", (int)&(v->send_event));
226
Console.WriteLine ("time {0}", (int)&(v->time));
227
Console.WriteLine ("x {0}", (int)&(v->x));
228
Console.WriteLine ("y {0}", (int)&(v->y));
229
Console.WriteLine ("state {0}", (int)&(v->state));
230
Console.WriteLine ("magnification {0}", (int)&(v->magnification));
231
Console.WriteLine ("x_root {0}", (int)&(v->x_root));
232
Console.WriteLine ("y_root {0}", (int)&(v->y_root));
235
// gcc -m32 test.c `pkg-config --cflags gtk+-2.0`
238
int main (int argc, char* argv)
240
GdkEventGestureMagnify *v = (GdkEventGestureMagnify *)0;
241
printf ("type %d\n", (int)&(v->type));
242
printf ("window %d\n", (int)&(v->window));
243
printf ("send_event %d\n", (int)&(v->send_event));
244
printf ("time %d\n", (int)&(v->time));
245
printf ("x %d\n", (int)&(v->x));
246
printf ("y %d\n", (int)&(v->y));
247
printf ("state %d\n", (int)&(v->state));
248
printf ("magnification %d\n", (int)&(v->magnification));
249
printf ("x_root %d\n", (int)&(v->x_root));
250
printf ("y_root %d\n", (int)&(v->y_root));