~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor/Gui/GtkGestures.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-06-22 20:35:35 UTC
  • mfrom: (10.3.2)
  • Revision ID: package-import@ubuntu.com-20120622203535-zrozwvcf6kfk6l6i
Tags: 3.0.3.2+dfsg-1
* [3fd89ae] Imported Upstream version 3.0.3.2+dfsg
* [379a680] Remove old patches we haven't used for ages from git.
* [d71161d] Remove correct_paths_in_monodevelop-core-addins.pc.patch.
  Upstream claim to have fixed this by moving assembly install locations.
* [15dbfb9] Fix install location for MonoDevelop.Gettext.dll.config.
* [26eb434] Fix install location for MonoDevelop.SourceEditor2.dll.config.
* [4169974] Upstream commit 53282c9 which finally reconciles the 
  MonoDevelop.Gettext.dll install location with the 
  monodevelop-core-addins.pc location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// GtkGestures.cs
 
3
//
 
4
// Author:
 
5
//       Michael Hutchinson <mhutch@xamarin.com>
 
6
//
 
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
 
8
//
 
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:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Runtime.InteropServices;
 
29
using Gdk;
 
30
 
 
31
namespace Mono.TextEditor
 
32
{
 
33
        public static class GtkGestures
 
34
        {
 
35
                const int GDK_GESTURE_MAGNIFY = 37;
 
36
                const int GDK_GESTURE_ROTATE  = 38;
 
37
                const int GDK_GESTURE_SWIPE   = 39;
 
38
 
 
39
                [DllImport (PangoUtil.LIBGDK)]
 
40
                static extern bool gdk_quartz_supports_gesture_events ();
 
41
 
 
42
                static bool isSupported;
 
43
 
 
44
                static GtkGestures ()
 
45
                {
 
46
                        if (Platform.IsMac) {
 
47
                                try {
 
48
                                        isSupported = gdk_quartz_supports_gesture_events ();
 
49
                                        Console.WriteLine (isSupported);
 
50
                                } catch (EntryPointNotFoundException) {
 
51
                                }
 
52
                        }
 
53
                }
 
54
 
 
55
                public static bool IsSupported { get { return isSupported; } }
 
56
 
 
57
                public static void AddGestureMagnifyHandler (this Gtk.Widget widget, EventHandler<GestureMagnifyEventArgs> handler)
 
58
                {
 
59
                        if (!isSupported)
 
60
                                throw new NotSupportedException ();
 
61
                        var signal = GLib.Signal.Lookup (widget, "gesture-magnify-event", typeof(GestureMagnifyEventArgs));
 
62
                        signal.AddDelegate (new EventHandler<GestureMagnifyEventArgs> (handler));
 
63
                }
 
64
 
 
65
                public static void AddGestureRotateHandler (this Gtk.Widget widget, EventHandler<GestureRotateEventArgs> handler)
 
66
                {
 
67
                        if (!isSupported)
 
68
                                throw new NotSupportedException ();
 
69
                        var signal = GLib.Signal.Lookup (widget, "gesture-rotate-event", typeof(GestureRotateEventArgs));
 
70
                        signal.AddDelegate (new EventHandler<GestureRotateEventArgs> (handler));
 
71
                }
 
72
 
 
73
                public static void AddGestureSwipeHandler (this Gtk.Widget widget, EventHandler<GestureSwipeEventArgs> handler)
 
74
                {
 
75
                        if (!isSupported)
 
76
                                throw new NotSupportedException ();
 
77
                        var signal = GLib.Signal.Lookup (widget, "gesture-swipe-event", typeof(GestureSwipeEventArgs));
 
78
                        signal.AddDelegate (new EventHandler<GestureSwipeEventArgs> (handler));
 
79
                }
 
80
        }
 
81
 
 
82
        public unsafe class GestureMagnifyEventArgs : GLib.SignalArgs
 
83
        {
 
84
                //have to force pack=4, or Mono aligns doubles to 8 bytes
 
85
                [StructLayout (LayoutKind.Sequential, Pack=4)]
 
86
                struct GdkEventGestureMagnify
 
87
                {
 
88
                        public Gdk.EventType type;
 
89
                        public IntPtr window;
 
90
                        public sbyte send_event;
 
91
                        public uint time;
 
92
                        public double x, y;
 
93
                        public uint state;
 
94
                        public double magnification;
 
95
                        public IntPtr device;
 
96
                        public double x_root, y_root;
 
97
                }
 
98
 
 
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 {
 
103
                        get {
 
104
                                var handle = ((Event)Args[0]).Handle;
 
105
                                return (GdkEventGestureMagnify *) handle;
 
106
                        }
 
107
                }
 
108
 
 
109
                public Gdk.Window Window {
 
110
                        get {
 
111
                                return (Gdk.Window) GLib.Object.GetObject (evt->window);
 
112
                        }
 
113
                }
 
114
 
 
115
                public Device Device {
 
116
                        get {
 
117
                                return (Device) GLib.Object.GetObject (evt->device);
 
118
                        }
 
119
                }
 
120
 
 
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; } }
 
128
        }
 
129
 
 
130
        public unsafe class GestureRotateEventArgs : GLib.SignalArgs
 
131
        {
 
132
                [StructLayout (LayoutKind.Sequential, Pack=4)]
 
133
                struct GdkEventGestureRotate
 
134
                {
 
135
                        public Gdk.EventType type;
 
136
                        public IntPtr window;
 
137
                        public sbyte send_event;
 
138
                        public uint time;
 
139
                        public double x, y;
 
140
                        public uint state;
 
141
                        public double rotation;
 
142
                        public IntPtr device;
 
143
                        public double x_root, y_root;
 
144
                }
 
145
 
 
146
                GdkEventGestureRotate *evt {
 
147
                        get {
 
148
                                var handle = ((Event)Args[0]).Handle;
 
149
                                return (GdkEventGestureRotate *) handle;
 
150
                        }
 
151
                }
 
152
 
 
153
                public Gdk.Window Window {
 
154
                        get {
 
155
                                return (Gdk.Window) GLib.Object.GetObject (evt->window);
 
156
                        }
 
157
                }
 
158
 
 
159
                public Device Device {
 
160
                        get {
 
161
                                return (Device) GLib.Object.GetObject (evt->device);
 
162
                        }
 
163
                }
 
164
 
 
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; } }
 
172
        }
 
173
 
 
174
        public unsafe class GestureSwipeEventArgs : GLib.SignalArgs
 
175
        {
 
176
                [StructLayout (LayoutKind.Sequential, Pack=4)]
 
177
                struct GdkEventGestureSwipe
 
178
                {
 
179
                        public Gdk.EventType type;
 
180
                        public IntPtr window;
 
181
                        public sbyte send_event;
 
182
                        public uint time;
 
183
                        public double x, y;
 
184
                        public uint state;
 
185
                        public double delta_x, delta_y;
 
186
                        public IntPtr device;
 
187
                        public double x_root, y_root;
 
188
                }
 
189
 
 
190
                GdkEventGestureSwipe *evt {
 
191
                        get {
 
192
                                var handle = ((Event)Args[0]).Handle;
 
193
                                return (GdkEventGestureSwipe *) handle;
 
194
                        }
 
195
                }
 
196
 
 
197
                public Gdk.Window Window {
 
198
                        get {
 
199
                                return (Gdk.Window) GLib.Object.GetObject (evt->window);
 
200
                        }
 
201
                }
 
202
 
 
203
                public Device Device {
 
204
                        get {
 
205
                                return (Device) GLib.Object.GetObject (evt->device);
 
206
                        }
 
207
                }
 
208
 
 
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; } }
 
217
        }
 
218
 
 
219
        /*
 
220
        void PrintOffsets ()
 
221
        {
 
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));
 
233
        }
 
234
 
 
235
        // gcc -m32 test.c `pkg-config --cflags gtk+-2.0`
 
236
        #include <gtk/gtk.h>
 
237
 
 
238
        int main (int argc, char* argv)
 
239
        {
 
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));
 
251
        }
 
252
        */
 
253
}