7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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.Reflection;
31 using System.Runtime.InteropServices;
39 //Use [DllImport("libgdk-win32-2.0-0.dll")] for Win32
40 [DllImport("libgdk-x11-2.0.so")]
41 internal static extern IntPtr gdk_x11_drawable_get_xdisplay (IntPtr raw);
43 [DllImport("libgdk-x11-2.0.so")]
44 internal static extern IntPtr gdk_x11_drawable_get_xid (IntPtr raw);
46 [DllImport("libgdk-x11-2.0.so")]
47 internal static extern IntPtr gdk_drawable_get_visual (IntPtr raw);
49 [DllImport("libgdk-x11-2.0.so")]
50 internal static extern IntPtr gdk_x11_visual_get_xvisual (IntPtr raw);
52 [DllImport("libgdk-x11-2.0.so")]
53 internal static extern IntPtr gdk_cairo_create (IntPtr raw);
55 public static Cairo.Context CreateDrawable (Gdk.Drawable drawable)
57 IntPtr x_drawable = IntPtr.Zero;
58 int x_off = 0, y_off = 0;
61 ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);
63 bool is_gdk_window = drawable is Gdk.Window;
65 ((Gdk.Window) drawable).GetInternalPaintInfo(out drawable,
66 out x_off, out y_off);
68 x_drawable = drawable.Handle;
69 IntPtr visual = gdk_drawable_get_visual(x_drawable);
71 IntPtr Xdisplay = gdk_x11_drawable_get_xdisplay(x_drawable);
72 IntPtr Xvisual = gdk_x11_visual_get_xvisual(visual);
73 IntPtr Xdrawable = gdk_x11_drawable_get_xid (x_drawable);
75 Cairo.XlibSurface s = new Cairo.XlibSurface (Xdisplay,
80 Cairo.Context g = new Cairo.Context (s);
82 // this can be safely removed now, just keep it for a bit more
83 //Cairo.Context g = new Cairo.Context (
84 // gdk_cairo_create (x_drawable ));
87 g.Translate (-(double)x_off,-(double)y_off);