[cairo-commit] pycairo/cairo cairogtkmodule.c,1.9,1.10

Steve Chaplin commit at pdx.freedesktop.org
Wed Mar 16 03:03:21 PST 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv24036/cairo

Modified Files:
	cairogtkmodule.c 
Log Message:
SC 2005/03/16

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- cairogtkmodule.c	12 Mar 2005 10:28:18 -0000	1.9
+++ cairogtkmodule.c	16 Mar 2005 11:03:19 -0000	1.10
@@ -45,24 +45,66 @@
 #define PyGdkDrawable_Type (*_PyGdkDrawable_Type)
 static PyTypeObject *_PyGdkPixbuf_Type;
 #define PyGdkPixbuf_Type (*_PyGdkPixbuf_Type)
+static PyTypeObject *_PyGdkPixmap_Type;
+#define PyGdkPixmap_Type (*_PyGdkPixmap_Type)
+static PyTypeObject *_PyGdkVisual_Type;
+#define PyGdkVisual_Type (*_PyGdkVisual_Type)
+static PyTypeObject *_PyGdkWindow_Type;
+#define PyGdkWindow_Type (*_PyGdkWindow_Type)
+
+static PyObject *
+set_target_drawable(PyObject *self, PyObject *args)
+{
+    PyCairoContext *py_ctx;
+    PyGObject   *py_drawable;
+    GdkDrawable *gdk_drawable;
+    gint x_offset, y_offset;
+
+    if (!PyArg_ParseTuple(args, "O!O!:set_target_drawable",
+			  &PyCairoContext_Type, &py_ctx,
+			  &PyGdkDrawable_Type, &py_drawable))
+	return NULL;
+
+    if (GDK_IS_WINDOW(py_drawable->obj)) { /* GdkWindow */
+	gdk_window_get_internal_paint_info(GDK_WINDOW(py_drawable->obj),
+					   &gdk_drawable,
+					   &x_offset, &y_offset);
+    } else {                               /* GdkPixmap */
+	gdk_drawable = GDK_DRAWABLE(py_drawable->obj);
+	x_offset = y_offset = 0;
+    }
+
+    cairo_set_target_drawable(py_ctx->ctx,
+			      GDK_DRAWABLE_XDISPLAY(gdk_drawable),
+			      GDK_DRAWABLE_XID(gdk_drawable));
+    if (pycairo_check_status(cairo_status(py_ctx->ctx)))
+	return NULL;
+    cairo_translate(py_ctx->ctx, -x_offset, -y_offset);
+    if (pycairo_check_status(cairo_status(py_ctx->ctx)))
+	return NULL;
+
+    Py_RETURN_NONE;
+}
 
 static PyObject *
 surface_create_for_drawable(PyObject *self, PyObject *args)
 {
-    PyGObject *drawable;
+    PyGObject *py_drawable;
+    GdkDrawable *gdk_drawable;
     cairo_format_t format = CAIRO_FORMAT_ARGB32;
     cairo_surface_t *surface;
 
     if (!PyArg_ParseTuple(args, "O!|i:surface_create_for_drawable",
-			  &PyGdkDrawable_Type, &drawable, &format))
+			  &PyGdkDrawable_Type, &py_drawable, &format))
 	return NULL;
 
-    surface = cairo_xlib_surface_create
-	(GDK_DRAWABLE_XDISPLAY(GDK_DRAWABLE(drawable->obj)),
-	 GDK_DRAWABLE_XID(GDK_DRAWABLE(drawable->obj)),
-	 GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(GDK_DRAWABLE(drawable->obj))),
+    gdk_drawable = GDK_DRAWABLE(py_drawable->obj);
+    surface = cairo_xlib_surface_create  /* deprecated */
+	(GDK_DRAWABLE_XDISPLAY(gdk_drawable),
+	 GDK_DRAWABLE_XID(gdk_drawable),
+	 GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(gdk_drawable)),
 	 format,
-	 GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(GDK_DRAWABLE(drawable->obj))));
+	 GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdk_drawable)));
     if (!surface)
 	return PyErr_NoMemory();
 
@@ -70,38 +112,79 @@
 }
 
 static PyObject *
-set_target_drawable(PyObject *self, PyObject *args)
+surface_create_for_pixmap(PyObject *self, PyObject *args)
 {
-    PyCairoContext *context;
-    PyGObject *drawable;
-    GdkDrawable *real_drawable;
-    gint x_offset, y_offset;
+    PyGObject *py_pixmap;
+    GdkDrawable *gdk_pixmap;
+    cairo_format_t format;
+    cairo_surface_t *surface;
 
-    if (!PyArg_ParseTuple(args, "O!O!:set_target_drawable",
-			  &PyCairoContext_Type, &context,
-			  &PyGdkDrawable_Type, &drawable))
+    if (!PyArg_ParseTuple(args, "O!i:surface_create_for_pixmap",
+			  &PyGdkPixmap_Type, &py_pixmap, &format))
 	return NULL;
 
-    if (GDK_IS_WINDOW(drawable->obj)) {
-	gdk_window_get_internal_paint_info(GDK_WINDOW(drawable->obj),
-					   &real_drawable,
-					   &x_offset, &y_offset);
-    } else {
-	real_drawable = GDK_DRAWABLE(drawable->obj);
-	x_offset = 0;
-	y_offset = 0;
-    }
+    gdk_pixmap = GDK_PIXMAP(py_pixmap->obj);
 
-    cairo_set_target_drawable(context->ctx,
-			      GDK_DRAWABLE_XDISPLAY(real_drawable),
-			      GDK_DRAWABLE_XID(real_drawable));
-    if (pycairo_check_status(cairo_status(context->ctx)))
+    surface = cairo_xlib_surface_create_for_pixmap
+	(GDK_PIXMAP_XDISPLAY(gdk_pixmap),
+	 GDK_PIXMAP_XID(gdk_pixmap),
+	 format);
+    if (!surface)
+	return PyErr_NoMemory();
+
+    return pycairo_surface_wrap(surface);
+}
+
+static PyObject *
+surface_create_for_pixmap_with_visual(PyObject *self, PyObject *args)
+{
+    PyGObject *py_pixmap, *py_visual;
+    GdkDrawable *gdk_pixmap;
+    GdkVisual *gdk_visual;
+    cairo_surface_t *surface;
+
+    if (!PyArg_ParseTuple(args, "O!O!:surface_create_for_pixmap_with_visual",
+			  &PyGdkPixmap_Type, &py_pixmap,
+			  &PyGdkVisual_Type, &py_visual))
 	return NULL;
-    cairo_translate(context->ctx, -x_offset, -y_offset);
-    if (pycairo_check_status(cairo_status(context->ctx)))
+
+    gdk_pixmap = GDK_PIXMAP(py_pixmap->obj);
+    gdk_visual = GDK_VISUAL(py_visual->obj);
+
+    surface = cairo_xlib_surface_create_for_pixmap_with_visual
+	(GDK_PIXMAP_XDISPLAY(gdk_pixmap),
+	 GDK_PIXMAP_XID(gdk_pixmap),
+	 GDK_VISUAL_XVISUAL(gdk_visual));
+    if (!surface)
+	return PyErr_NoMemory();
+
+    return pycairo_surface_wrap(surface);
+}
+
+static PyObject *
+surface_create_for_window_with_visual(PyObject *self, PyObject *args)
+{
+    PyGObject *py_window, *py_visual;
+    GdkVisual *gdk_visual;
+    GdkWindow *gdk_window;
+    cairo_surface_t *surface;
+
+    if (!PyArg_ParseTuple(args, "O!O!:surface_create_for_window_with_visual",
+			  &PyGdkWindow_Type, &py_window,
+			  &PyGdkVisual_Type, &py_visual))
 	return NULL;
 
-    Py_RETURN_NONE;
+    gdk_window = GDK_WINDOW(py_window->obj);
+    gdk_visual = GDK_VISUAL(py_visual->obj);
+
+    surface = cairo_xlib_surface_create_for_window_with_visual
+	(GDK_WINDOW_XDISPLAY(gdk_window),
+	 GDK_WINDOW_XID(gdk_window),
+	 GDK_VISUAL_XVISUAL(gdk_visual));
+    if (!surface)
+	return PyErr_NoMemory();
+
+    return pycairo_surface_wrap(surface);
 }
 
 static PyObject *
@@ -147,11 +230,18 @@
 }
 
 static PyMethodDef cairogtk_functions[] = {
+    { "set_target_drawable", (PyCFunction)set_target_drawable, METH_VARARGS },
+    /* deprecated */
     { "surface_create_for_drawable", (PyCFunction)surface_create_for_drawable,
       METH_VARARGS },
-    { "set_target_drawable", (PyCFunction)set_target_drawable, METH_VARARGS },
     { "surface_create_for_pixbuf", (PyCFunction)surface_create_for_pixbuf,
       METH_VARARGS },
+    { "surface_create_for_pixmap", (PyCFunction)surface_create_for_pixmap,
+      METH_VARARGS },
+    { "surface_create_for_pixmap_with_visual", (PyCFunction)surface_create_for_pixmap_with_visual,
+      METH_VARARGS },
+    { "surface_create_for_window_with_visual", (PyCFunction)surface_create_for_window_with_visual,
+      METH_VARARGS },
     { NULL, NULL, 0 }
 };
 
@@ -167,5 +257,8 @@
 
     mod = PyImport_ImportModule("gtk.gdk");
     _PyGdkDrawable_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "Drawable");
-    _PyGdkPixbuf_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "Pixbuf");
+    _PyGdkPixbuf_Type   = (PyTypeObject *)PyObject_GetAttrString(mod, "Pixbuf");
+    _PyGdkPixmap_Type   = (PyTypeObject *)PyObject_GetAttrString(mod, "Pixmap");
+    _PyGdkVisual_Type   = (PyTypeObject *)PyObject_GetAttrString(mod, "Visual");
+    _PyGdkWindow_Type   = (PyTypeObject *)PyObject_GetAttrString(mod, "Window");
 }




More information about the cairo-commit mailing list